Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: src/heap.cc

Issue 151019: Changed the global object representation (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 meta_map()->set_map(meta_map()); 1063 meta_map()->set_map(meta_map());
1064 1064
1065 obj = AllocatePartialMap(FIXED_ARRAY_TYPE, FixedArray::kHeaderSize); 1065 obj = AllocatePartialMap(FIXED_ARRAY_TYPE, FixedArray::kHeaderSize);
1066 if (obj->IsFailure()) return false; 1066 if (obj->IsFailure()) return false;
1067 fixed_array_map_ = Map::cast(obj); 1067 fixed_array_map_ = Map::cast(obj);
1068 1068
1069 obj = AllocatePartialMap(ODDBALL_TYPE, Oddball::kSize); 1069 obj = AllocatePartialMap(ODDBALL_TYPE, Oddball::kSize);
1070 if (obj->IsFailure()) return false; 1070 if (obj->IsFailure()) return false;
1071 oddball_map_ = Map::cast(obj); 1071 oddball_map_ = Map::cast(obj);
1072 1072
1073 obj = AllocatePartialMap(JS_GLOBAL_PROPERTY_CELL_TYPE,
1074 JSGlobalPropertyCell::kSize);
1075 if (obj->IsFailure()) return false;
1076 global_property_cell_map_ = Map::cast(obj);
1077
1073 // Allocate the empty array 1078 // Allocate the empty array
1074 obj = AllocateEmptyFixedArray(); 1079 obj = AllocateEmptyFixedArray();
1075 if (obj->IsFailure()) return false; 1080 if (obj->IsFailure()) return false;
1076 empty_fixed_array_ = FixedArray::cast(obj); 1081 empty_fixed_array_ = FixedArray::cast(obj);
1077 1082
1078 obj = Allocate(oddball_map(), OLD_DATA_SPACE); 1083 obj = Allocate(oddball_map(), OLD_DATA_SPACE);
1079 if (obj->IsFailure()) return false; 1084 if (obj->IsFailure()) return false;
1080 null_value_ = obj; 1085 null_value_ = obj;
1081 1086
1082 // Allocate the empty descriptor array. AllocateMap can now be used. 1087 // Allocate the empty descriptor array. AllocateMap can now be used.
1083 obj = AllocateEmptyFixedArray(); 1088 obj = AllocateEmptyFixedArray();
1084 if (obj->IsFailure()) return false; 1089 if (obj->IsFailure()) return false;
1085 // There is a check against empty_descriptor_array() in cast(). 1090 // There is a check against empty_descriptor_array() in cast().
1086 empty_descriptor_array_ = reinterpret_cast<DescriptorArray*>(obj); 1091 empty_descriptor_array_ = reinterpret_cast<DescriptorArray*>(obj);
1087 1092
1088 // Fix the instance_descriptors for the existing maps. 1093 // Fix the instance_descriptors for the existing maps.
1089 meta_map()->set_instance_descriptors(empty_descriptor_array()); 1094 meta_map()->set_instance_descriptors(empty_descriptor_array());
1090 meta_map()->set_code_cache(empty_fixed_array()); 1095 meta_map()->set_code_cache(empty_fixed_array());
1091 1096
1092 fixed_array_map()->set_instance_descriptors(empty_descriptor_array()); 1097 fixed_array_map()->set_instance_descriptors(empty_descriptor_array());
1093 fixed_array_map()->set_code_cache(empty_fixed_array()); 1098 fixed_array_map()->set_code_cache(empty_fixed_array());
1094 1099
1095 oddball_map()->set_instance_descriptors(empty_descriptor_array()); 1100 oddball_map()->set_instance_descriptors(empty_descriptor_array());
1096 oddball_map()->set_code_cache(empty_fixed_array()); 1101 oddball_map()->set_code_cache(empty_fixed_array());
1097 1102
1103 global_property_cell_map()->set_instance_descriptors(
1104 empty_descriptor_array());
1105 global_property_cell_map()->set_code_cache(empty_fixed_array());
1106
1098 // Fix prototype object for existing maps. 1107 // Fix prototype object for existing maps.
1099 meta_map()->set_prototype(null_value()); 1108 meta_map()->set_prototype(null_value());
1100 meta_map()->set_constructor(null_value()); 1109 meta_map()->set_constructor(null_value());
1101 1110
1102 fixed_array_map()->set_prototype(null_value()); 1111 fixed_array_map()->set_prototype(null_value());
1103 fixed_array_map()->set_constructor(null_value()); 1112 fixed_array_map()->set_constructor(null_value());
1104 oddball_map()->set_prototype(null_value()); 1113 oddball_map()->set_prototype(null_value());
1105 oddball_map()->set_constructor(null_value()); 1114 oddball_map()->set_constructor(null_value());
1106 1115
1116 global_property_cell_map()->set_prototype(null_value());
1117 global_property_cell_map()->set_constructor(null_value());
1118
1107 obj = AllocateMap(HEAP_NUMBER_TYPE, HeapNumber::kSize); 1119 obj = AllocateMap(HEAP_NUMBER_TYPE, HeapNumber::kSize);
1108 if (obj->IsFailure()) return false; 1120 if (obj->IsFailure()) return false;
1109 heap_number_map_ = Map::cast(obj); 1121 heap_number_map_ = Map::cast(obj);
1110 1122
1111 obj = AllocateMap(PROXY_TYPE, Proxy::kSize); 1123 obj = AllocateMap(PROXY_TYPE, Proxy::kSize);
1112 if (obj->IsFailure()) return false; 1124 if (obj->IsFailure()) return false;
1113 proxy_map_ = Map::cast(obj); 1125 proxy_map_ = Map::cast(obj);
1114 1126
1115 #define ALLOCATE_STRING_MAP(type, size, name) \ 1127 #define ALLOCATE_STRING_MAP(type, size, name) \
1116 obj = AllocateMap(type, size); \ 1128 obj = AllocateMap(type, size); \
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 STATIC_ASSERT(HeapNumber::kSize <= Page::kMaxHeapObjectSize); 1235 STATIC_ASSERT(HeapNumber::kSize <= Page::kMaxHeapObjectSize);
1224 ASSERT(allocation_allowed_ && gc_state_ == NOT_IN_GC); 1236 ASSERT(allocation_allowed_ && gc_state_ == NOT_IN_GC);
1225 Object* result = new_space_.AllocateRaw(HeapNumber::kSize); 1237 Object* result = new_space_.AllocateRaw(HeapNumber::kSize);
1226 if (result->IsFailure()) return result; 1238 if (result->IsFailure()) return result;
1227 HeapObject::cast(result)->set_map(heap_number_map()); 1239 HeapObject::cast(result)->set_map(heap_number_map());
1228 HeapNumber::cast(result)->set_value(value); 1240 HeapNumber::cast(result)->set_value(value);
1229 return result; 1241 return result;
1230 } 1242 }
1231 1243
1232 1244
1245 Object* Heap::AllocateJSGlobalPropertyCell(Object* value) {
1246 Object* result = AllocateRaw(JSGlobalPropertyCell::kSize,
1247 OLD_POINTER_SPACE,
1248 OLD_POINTER_SPACE);
1249 if (result->IsFailure()) return result;
1250 HeapObject::cast(result)->set_map(global_property_cell_map());
1251 JSGlobalPropertyCell::cast(result)->set_value(value);
1252 return result;
1253 }
1254
1255
1233 Object* Heap::CreateOddball(Map* map, 1256 Object* Heap::CreateOddball(Map* map,
1234 const char* to_string, 1257 const char* to_string,
1235 Object* to_number) { 1258 Object* to_number) {
1236 Object* result = Allocate(map, OLD_DATA_SPACE); 1259 Object* result = Allocate(map, OLD_DATA_SPACE);
1237 if (result->IsFailure()) return result; 1260 if (result->IsFailure()) return result;
1238 return Oddball::cast(result)->Initialize(to_string, to_number); 1261 return Oddball::cast(result)->Initialize(to_string, to_number);
1239 } 1262 }
1240 1263
1241 1264
1242 bool Heap::CreateApiObjects() { 1265 bool Heap::CreateApiObjects() {
(...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after
2027 Object* Heap::AllocateJSObject(JSFunction* constructor, 2050 Object* Heap::AllocateJSObject(JSFunction* constructor,
2028 PretenureFlag pretenure) { 2051 PretenureFlag pretenure) {
2029 // Allocate the initial map if absent. 2052 // Allocate the initial map if absent.
2030 if (!constructor->has_initial_map()) { 2053 if (!constructor->has_initial_map()) {
2031 Object* initial_map = AllocateInitialMap(constructor); 2054 Object* initial_map = AllocateInitialMap(constructor);
2032 if (initial_map->IsFailure()) return initial_map; 2055 if (initial_map->IsFailure()) return initial_map;
2033 constructor->set_initial_map(Map::cast(initial_map)); 2056 constructor->set_initial_map(Map::cast(initial_map));
2034 Map::cast(initial_map)->set_constructor(constructor); 2057 Map::cast(initial_map)->set_constructor(constructor);
2035 } 2058 }
2036 // Allocate the object based on the constructors initial map. 2059 // Allocate the object based on the constructors initial map.
2037 return AllocateJSObjectFromMap(constructor->initial_map(), pretenure); 2060 Object* result =
2061 AllocateJSObjectFromMap(constructor->initial_map(), pretenure);
2062 // Make sure result is NOT a JS global object if valid.
2063 ASSERT(result->IsFailure() || !result->IsJSGlobalObject());
2064 return result;
2065 }
2066
2067
2068 Object* Heap::AllocateJSGlobalObject(JSFunction* constructor) {
2069 ASSERT(constructor->has_initial_map());
2070 // Make sure no field properties are described in the initial map.
2071 // This guarantees us that normalizing the properties does not
2072 // require us to change property values to JSGlobalPropertyCells.
2073 ASSERT(constructor->initial_map()->NextFreePropertyIndex() == 0);
2074
2075 // Allocate the object based on the constructors initial map.
2076 Object* result = AllocateJSObjectFromMap(constructor->initial_map(), TENURED);
2077 if (result->IsFailure()) return result;
2078
2079 // Normalize the result.
2080 JSObject* global = JSObject::cast(result);
2081 result = global->NormalizeProperties(CLEAR_INOBJECT_PROPERTIES);
2082 if (result->IsFailure()) return result;
2083
2084 // Make sure result is a JS global object with properties in dictionary.
2085 ASSERT(global->IsJSGlobalObject());
2086 ASSERT(!global->HasFastProperties());
2087 return global;
2038 } 2088 }
2039 2089
2040 2090
2041 Object* Heap::CopyJSObject(JSObject* source) { 2091 Object* Heap::CopyJSObject(JSObject* source) {
2042 // Never used to copy functions. If functions need to be copied we 2092 // Never used to copy functions. If functions need to be copied we
2043 // have to be careful to clear the literals array. 2093 // have to be careful to clear the literals array.
2044 ASSERT(!source->IsJSFunction()); 2094 ASSERT(!source->IsJSFunction());
2045 2095
2046 // Make the clone. 2096 // Make the clone.
2047 Map* map = source->map(); 2097 Map* map = source->map();
(...skipping 1546 matching lines...) Expand 10 before | Expand all | Expand 10 after
3594 #ifdef DEBUG 3644 #ifdef DEBUG
3595 bool Heap::GarbageCollectionGreedyCheck() { 3645 bool Heap::GarbageCollectionGreedyCheck() {
3596 ASSERT(FLAG_gc_greedy); 3646 ASSERT(FLAG_gc_greedy);
3597 if (Bootstrapper::IsActive()) return true; 3647 if (Bootstrapper::IsActive()) return true;
3598 if (disallow_allocation_failure()) return true; 3648 if (disallow_allocation_failure()) return true;
3599 return CollectGarbage(0, NEW_SPACE); 3649 return CollectGarbage(0, NEW_SPACE);
3600 } 3650 }
3601 #endif 3651 #endif
3602 3652
3603 } } // namespace v8::internal 3653 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap.h ('k') | src/ia32/ic-ia32.cc » ('j') | test/cctest/test-api.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698