| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 13 matching lines...) Expand all Loading... |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #include <stdlib.h> | 28 #include <stdlib.h> |
| 29 | 29 |
| 30 #include "v8.h" | 30 #include "v8.h" |
| 31 | 31 |
| 32 #include "global-handles.h" | 32 #include "global-handles.h" |
| 33 #include "snapshot.h" | 33 #include "snapshot.h" |
| 34 #include "top.h" | |
| 35 #include "cctest.h" | 34 #include "cctest.h" |
| 36 | 35 |
| 37 using namespace v8::internal; | 36 using namespace v8::internal; |
| 38 | 37 |
| 39 static v8::Persistent<v8::Context> env; | 38 static v8::Persistent<v8::Context> env; |
| 40 | 39 |
| 41 static void InitializeVM() { | 40 static void InitializeVM() { |
| 42 if (env.IsEmpty()) env = v8::Context::New(); | 41 if (env.IsEmpty()) env = v8::Context::New(); |
| 43 v8::HandleScope scope; | 42 v8::HandleScope scope; |
| 44 env->Enter(); | 43 env->Enter(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 72 | 71 |
| 73 TEST(Promotion) { | 72 TEST(Promotion) { |
| 74 // This test requires compaction. If compaction is turned off, we | 73 // This test requires compaction. If compaction is turned off, we |
| 75 // skip the entire test. | 74 // skip the entire test. |
| 76 if (FLAG_never_compact) return; | 75 if (FLAG_never_compact) return; |
| 77 | 76 |
| 78 // Ensure that we get a compacting collection so that objects are promoted | 77 // Ensure that we get a compacting collection so that objects are promoted |
| 79 // from new space. | 78 // from new space. |
| 80 FLAG_gc_global = true; | 79 FLAG_gc_global = true; |
| 81 FLAG_always_compact = true; | 80 FLAG_always_compact = true; |
| 82 Heap::ConfigureHeap(2*256*KB, 8*MB, 8*MB); | 81 HEAP->ConfigureHeap(2*256*KB, 8*MB, 8*MB); |
| 83 | 82 |
| 84 InitializeVM(); | 83 InitializeVM(); |
| 85 | 84 |
| 86 v8::HandleScope sc; | 85 v8::HandleScope sc; |
| 87 | 86 |
| 88 // Allocate a fixed array in the new space. | 87 // Allocate a fixed array in the new space. |
| 89 int array_size = | 88 int array_size = |
| 90 (Heap::MaxObjectSizeInPagedSpace() - FixedArray::kHeaderSize) / | 89 (HEAP->MaxObjectSizeInPagedSpace() - FixedArray::kHeaderSize) / |
| 91 (kPointerSize * 4); | 90 (kPointerSize * 4); |
| 92 Object* obj = Heap::AllocateFixedArray(array_size)->ToObjectChecked(); | 91 Object* obj = HEAP->AllocateFixedArray(array_size)->ToObjectChecked(); |
| 93 | 92 |
| 94 Handle<FixedArray> array(FixedArray::cast(obj)); | 93 Handle<FixedArray> array(FixedArray::cast(obj)); |
| 95 | 94 |
| 96 // Array should be in the new space. | 95 // Array should be in the new space. |
| 97 CHECK(Heap::InSpace(*array, NEW_SPACE)); | 96 CHECK(HEAP->InSpace(*array, NEW_SPACE)); |
| 98 | 97 |
| 99 // Call the m-c collector, so array becomes an old object. | 98 // Call the m-c collector, so array becomes an old object. |
| 100 Heap::CollectGarbage(OLD_POINTER_SPACE); | 99 HEAP->CollectGarbage(OLD_POINTER_SPACE); |
| 101 | 100 |
| 102 // Array now sits in the old space | 101 // Array now sits in the old space |
| 103 CHECK(Heap::InSpace(*array, OLD_POINTER_SPACE)); | 102 CHECK(HEAP->InSpace(*array, OLD_POINTER_SPACE)); |
| 104 } | 103 } |
| 105 | 104 |
| 106 | 105 |
| 107 TEST(NoPromotion) { | 106 TEST(NoPromotion) { |
| 108 Heap::ConfigureHeap(2*256*KB, 8*MB, 8*MB); | 107 HEAP->ConfigureHeap(2*256*KB, 8*MB, 8*MB); |
| 109 | 108 |
| 110 // Test the situation that some objects in new space are promoted to | 109 // Test the situation that some objects in new space are promoted to |
| 111 // the old space | 110 // the old space |
| 112 InitializeVM(); | 111 InitializeVM(); |
| 113 | 112 |
| 114 v8::HandleScope sc; | 113 v8::HandleScope sc; |
| 115 | 114 |
| 116 // Do a mark compact GC to shrink the heap. | 115 // Do a mark compact GC to shrink the heap. |
| 117 Heap::CollectGarbage(OLD_POINTER_SPACE); | 116 HEAP->CollectGarbage(OLD_POINTER_SPACE); |
| 118 | 117 |
| 119 // Allocate a big Fixed array in the new space. | 118 // Allocate a big Fixed array in the new space. |
| 120 int max_size = | 119 int max_size = |
| 121 Min(Heap::MaxObjectSizeInPagedSpace(), Heap::MaxObjectSizeInNewSpace()); | 120 Min(HEAP->MaxObjectSizeInPagedSpace(), HEAP->MaxObjectSizeInNewSpace()); |
| 122 | 121 |
| 123 int length = (max_size - FixedArray::kHeaderSize) / (2*kPointerSize); | 122 int length = (max_size - FixedArray::kHeaderSize) / (2*kPointerSize); |
| 124 Object* obj = Heap::AllocateFixedArray(length)->ToObjectChecked(); | 123 Object* obj = i::Isolate::Current()->heap()->AllocateFixedArray(length)-> |
| 124 ToObjectChecked(); |
| 125 | 125 |
| 126 Handle<FixedArray> array(FixedArray::cast(obj)); | 126 Handle<FixedArray> array(FixedArray::cast(obj)); |
| 127 | 127 |
| 128 // Array still stays in the new space. | 128 // Array still stays in the new space. |
| 129 CHECK(Heap::InSpace(*array, NEW_SPACE)); | 129 CHECK(HEAP->InSpace(*array, NEW_SPACE)); |
| 130 | 130 |
| 131 // Allocate objects in the old space until out of memory. | 131 // Allocate objects in the old space until out of memory. |
| 132 FixedArray* host = *array; | 132 FixedArray* host = *array; |
| 133 while (true) { | 133 while (true) { |
| 134 Object* obj; | 134 Object* obj; |
| 135 { MaybeObject* maybe_obj = Heap::AllocateFixedArray(100, TENURED); | 135 { MaybeObject* maybe_obj = HEAP->AllocateFixedArray(100, TENURED); |
| 136 if (!maybe_obj->ToObject(&obj)) break; | 136 if (!maybe_obj->ToObject(&obj)) break; |
| 137 } | 137 } |
| 138 | 138 |
| 139 host->set(0, obj); | 139 host->set(0, obj); |
| 140 host = FixedArray::cast(obj); | 140 host = FixedArray::cast(obj); |
| 141 } | 141 } |
| 142 | 142 |
| 143 // Call mark compact GC, and it should pass. | 143 // Call mark compact GC, and it should pass. |
| 144 Heap::CollectGarbage(OLD_POINTER_SPACE); | 144 HEAP->CollectGarbage(OLD_POINTER_SPACE); |
| 145 | 145 |
| 146 // array should not be promoted because the old space is full. | 146 // array should not be promoted because the old space is full. |
| 147 CHECK(Heap::InSpace(*array, NEW_SPACE)); | 147 CHECK(HEAP->InSpace(*array, NEW_SPACE)); |
| 148 } | 148 } |
| 149 | 149 |
| 150 | 150 |
| 151 TEST(MarkCompactCollector) { | 151 TEST(MarkCompactCollector) { |
| 152 InitializeVM(); | 152 InitializeVM(); |
| 153 | 153 |
| 154 v8::HandleScope sc; | 154 v8::HandleScope sc; |
| 155 // call mark-compact when heap is empty | 155 // call mark-compact when heap is empty |
| 156 Heap::CollectGarbage(OLD_POINTER_SPACE); | 156 HEAP->CollectGarbage(OLD_POINTER_SPACE); |
| 157 | 157 |
| 158 // keep allocating garbage in new space until it fails | 158 // keep allocating garbage in new space until it fails |
| 159 const int ARRAY_SIZE = 100; | 159 const int ARRAY_SIZE = 100; |
| 160 Object* array; | 160 Object* array; |
| 161 MaybeObject* maybe_array; | 161 MaybeObject* maybe_array; |
| 162 do { | 162 do { |
| 163 maybe_array = Heap::AllocateFixedArray(ARRAY_SIZE); | 163 maybe_array = HEAP->AllocateFixedArray(ARRAY_SIZE); |
| 164 } while (maybe_array->ToObject(&array)); | 164 } while (maybe_array->ToObject(&array)); |
| 165 Heap::CollectGarbage(NEW_SPACE); | 165 HEAP->CollectGarbage(NEW_SPACE); |
| 166 | 166 |
| 167 array = Heap::AllocateFixedArray(ARRAY_SIZE)->ToObjectChecked(); | 167 array = HEAP->AllocateFixedArray(ARRAY_SIZE)->ToObjectChecked(); |
| 168 | 168 |
| 169 // keep allocating maps until it fails | 169 // keep allocating maps until it fails |
| 170 Object* mapp; | 170 Object* mapp; |
| 171 MaybeObject* maybe_mapp; | 171 MaybeObject* maybe_mapp; |
| 172 do { | 172 do { |
| 173 maybe_mapp = Heap::AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 173 maybe_mapp = HEAP->AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
| 174 } while (maybe_mapp->ToObject(&mapp)); | 174 } while (maybe_mapp->ToObject(&mapp)); |
| 175 Heap::CollectGarbage(MAP_SPACE); | 175 HEAP->CollectGarbage(MAP_SPACE); |
| 176 mapp = Heap::AllocateMap(JS_OBJECT_TYPE, | 176 mapp = HEAP->AllocateMap(JS_OBJECT_TYPE, |
| 177 JSObject::kHeaderSize)->ToObjectChecked(); | 177 JSObject::kHeaderSize)->ToObjectChecked(); |
| 178 | 178 |
| 179 // allocate a garbage | 179 // allocate a garbage |
| 180 String* func_name = | 180 String* func_name = |
| 181 String::cast(Heap::LookupAsciiSymbol("theFunction")->ToObjectChecked()); | 181 String::cast(HEAP->LookupAsciiSymbol("theFunction")->ToObjectChecked()); |
| 182 SharedFunctionInfo* function_share = SharedFunctionInfo::cast( | 182 SharedFunctionInfo* function_share = SharedFunctionInfo::cast( |
| 183 Heap::AllocateSharedFunctionInfo(func_name)->ToObjectChecked()); | 183 HEAP->AllocateSharedFunctionInfo(func_name)->ToObjectChecked()); |
| 184 JSFunction* function = JSFunction::cast( | 184 JSFunction* function = JSFunction::cast( |
| 185 Heap::AllocateFunction(*Top::function_map(), | 185 HEAP->AllocateFunction(*Isolate::Current()->function_map(), |
| 186 function_share, | 186 function_share, |
| 187 Heap::undefined_value())->ToObjectChecked()); | 187 HEAP->undefined_value())->ToObjectChecked()); |
| 188 Map* initial_map = | 188 Map* initial_map = |
| 189 Map::cast(Heap::AllocateMap(JS_OBJECT_TYPE, | 189 Map::cast(HEAP->AllocateMap(JS_OBJECT_TYPE, |
| 190 JSObject::kHeaderSize)->ToObjectChecked()); | 190 JSObject::kHeaderSize)->ToObjectChecked()); |
| 191 function->set_initial_map(initial_map); | 191 function->set_initial_map(initial_map); |
| 192 Top::context()->global()->SetProperty(func_name, | 192 Isolate::Current()->context()->global()->SetProperty( |
| 193 function, | 193 func_name, function, NONE, kNonStrictMode)->ToObjectChecked(); |
| 194 NONE, | |
| 195 kNonStrictMode)->ToObjectChecked(); | |
| 196 | 194 |
| 197 JSObject* obj = | 195 JSObject* obj = JSObject::cast( |
| 198 JSObject::cast(Heap::AllocateJSObject(function)->ToObjectChecked()); | 196 HEAP->AllocateJSObject(function)->ToObjectChecked()); |
| 199 Heap::CollectGarbage(OLD_POINTER_SPACE); | 197 HEAP->CollectGarbage(OLD_POINTER_SPACE); |
| 200 | 198 |
| 201 func_name = | 199 func_name = |
| 202 String::cast(Heap::LookupAsciiSymbol("theFunction")->ToObjectChecked()); | 200 String::cast(HEAP->LookupAsciiSymbol("theFunction")->ToObjectChecked()); |
| 203 CHECK(Top::context()->global()->HasLocalProperty(func_name)); | 201 CHECK(Isolate::Current()->context()->global()->HasLocalProperty(func_name)); |
| 204 Object* func_value = | 202 Object* func_value = Isolate::Current()->context()->global()-> |
| 205 Top::context()->global()->GetProperty(func_name)->ToObjectChecked(); | 203 GetProperty(func_name)->ToObjectChecked(); |
| 206 CHECK(func_value->IsJSFunction()); | 204 CHECK(func_value->IsJSFunction()); |
| 207 function = JSFunction::cast(func_value); | 205 function = JSFunction::cast(func_value); |
| 208 | 206 |
| 209 obj = JSObject::cast(Heap::AllocateJSObject(function)->ToObjectChecked()); | 207 obj = JSObject::cast(HEAP->AllocateJSObject(function)->ToObjectChecked()); |
| 210 String* obj_name = | 208 String* obj_name = |
| 211 String::cast(Heap::LookupAsciiSymbol("theObject")->ToObjectChecked()); | 209 String::cast(HEAP->LookupAsciiSymbol("theObject")->ToObjectChecked()); |
| 212 Top::context()->global()->SetProperty(obj_name, | 210 Isolate::Current()->context()->global()->SetProperty( |
| 213 obj, | 211 obj_name, obj, NONE, kNonStrictMode)->ToObjectChecked(); |
| 214 NONE, | |
| 215 kNonStrictMode)->ToObjectChecked(); | |
| 216 String* prop_name = | 212 String* prop_name = |
| 217 String::cast(Heap::LookupAsciiSymbol("theSlot")->ToObjectChecked()); | 213 String::cast(HEAP->LookupAsciiSymbol("theSlot")->ToObjectChecked()); |
| 218 obj->SetProperty(prop_name, | 214 obj->SetProperty(prop_name, |
| 219 Smi::FromInt(23), | 215 Smi::FromInt(23), |
| 220 NONE, | 216 NONE, |
| 221 kNonStrictMode)->ToObjectChecked(); | 217 kNonStrictMode)->ToObjectChecked(); |
| 222 | 218 |
| 223 Heap::CollectGarbage(OLD_POINTER_SPACE); | 219 HEAP->CollectGarbage(OLD_POINTER_SPACE); |
| 224 | 220 |
| 225 obj_name = | 221 obj_name = |
| 226 String::cast(Heap::LookupAsciiSymbol("theObject")->ToObjectChecked()); | 222 String::cast(HEAP->LookupAsciiSymbol("theObject")->ToObjectChecked()); |
| 227 CHECK(Top::context()->global()->HasLocalProperty(obj_name)); | 223 CHECK(Isolate::Current()->context()->global()->HasLocalProperty(obj_name)); |
| 228 CHECK(Top::context()->global()-> | 224 CHECK(Isolate::Current()->context()->global()-> |
| 229 GetProperty(obj_name)->ToObjectChecked()->IsJSObject()); | 225 GetProperty(obj_name)->ToObjectChecked()->IsJSObject()); |
| 230 obj = JSObject::cast( | 226 obj = JSObject::cast(Isolate::Current()->context()->global()-> |
| 231 Top::context()->global()->GetProperty(obj_name)->ToObjectChecked()); | 227 GetProperty(obj_name)->ToObjectChecked()); |
| 232 prop_name = | 228 prop_name = |
| 233 String::cast(Heap::LookupAsciiSymbol("theSlot")->ToObjectChecked()); | 229 String::cast(HEAP->LookupAsciiSymbol("theSlot")->ToObjectChecked()); |
| 234 CHECK(obj->GetProperty(prop_name)->ToObjectChecked() == Smi::FromInt(23)); | 230 CHECK(obj->GetProperty(prop_name) == Smi::FromInt(23)); |
| 235 } | 231 } |
| 236 | 232 |
| 237 | 233 |
| 238 // TODO(gc): compaction of map space is temporary removed from GC. | 234 // TODO(gc): compaction of map space is temporary removed from GC. |
| 239 #if 0 | 235 #if 0 |
| 240 static Handle<Map> CreateMap() { | 236 static Handle<Map> CreateMap() { |
| 241 return Factory::NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 237 return FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
| 242 } | 238 } |
| 243 | 239 |
| 244 | 240 |
| 245 TEST(MapCompact) { | 241 TEST(MapCompact) { |
| 246 FLAG_max_map_space_pages = 16; | 242 FLAG_max_map_space_pages = 16; |
| 247 InitializeVM(); | 243 InitializeVM(); |
| 248 | 244 |
| 249 { | 245 { |
| 250 v8::HandleScope sc; | 246 v8::HandleScope sc; |
| 251 // keep allocating maps while pointers are still encodable and thus | 247 // keep allocating maps while pointers are still encodable and thus |
| 252 // mark compact is permitted. | 248 // mark compact is permitted. |
| 253 Handle<JSObject> root = Factory::NewJSObjectFromMap(CreateMap()); | 249 Handle<JSObject> root = FACTORY->NewJSObjectFromMap(CreateMap()); |
| 254 do { | 250 do { |
| 255 Handle<Map> map = CreateMap(); | 251 Handle<Map> map = CreateMap(); |
| 256 map->set_prototype(*root); | 252 map->set_prototype(*root); |
| 257 root = Factory::NewJSObjectFromMap(map); | 253 root = FACTORY->NewJSObjectFromMap(map); |
| 258 } while (Heap::map_space()->MapPointersEncodable()); | 254 } while (HEAP->map_space()->MapPointersEncodable()); |
| 259 } | 255 } |
| 260 // Now, as we don't have any handles to just allocated maps, we should | 256 // Now, as we don't have any handles to just allocated maps, we should |
| 261 // be able to trigger map compaction. | 257 // be able to trigger map compaction. |
| 262 // To give an additional chance to fail, try to force compaction which | 258 // To give an additional chance to fail, try to force compaction which |
| 263 // should be impossible right now. | 259 // should be impossible right now. |
| 264 Heap::CollectAllGarbage(Heap::kForceCompactionMask); | 260 HEAP->CollectAllGarbage(Heap::kForceCompactionMask); |
| 265 // And now map pointers should be encodable again. | 261 // And now map pointers should be encodable again. |
| 266 CHECK(Heap::map_space()->MapPointersEncodable()); | 262 CHECK(HEAP->map_space()->MapPointersEncodable()); |
| 267 } | 263 } |
| 268 #endif | 264 #endif |
| 269 | 265 |
| 270 static int gc_starts = 0; | 266 static int gc_starts = 0; |
| 271 static int gc_ends = 0; | 267 static int gc_ends = 0; |
| 272 | 268 |
| 273 static void GCPrologueCallbackFunc() { | 269 static void GCPrologueCallbackFunc() { |
| 274 CHECK(gc_starts == gc_ends); | 270 CHECK(gc_starts == gc_ends); |
| 275 gc_starts++; | 271 gc_starts++; |
| 276 } | 272 } |
| 277 | 273 |
| 278 | 274 |
| 279 static void GCEpilogueCallbackFunc() { | 275 static void GCEpilogueCallbackFunc() { |
| 280 CHECK(gc_starts == gc_ends + 1); | 276 CHECK(gc_starts == gc_ends + 1); |
| 281 gc_ends++; | 277 gc_ends++; |
| 282 } | 278 } |
| 283 | 279 |
| 284 | 280 |
| 285 TEST(GCCallback) { | 281 TEST(GCCallback) { |
| 286 InitializeVM(); | 282 InitializeVM(); |
| 287 | 283 |
| 288 Heap::SetGlobalGCPrologueCallback(&GCPrologueCallbackFunc); | 284 HEAP->SetGlobalGCPrologueCallback(&GCPrologueCallbackFunc); |
| 289 Heap::SetGlobalGCEpilogueCallback(&GCEpilogueCallbackFunc); | 285 HEAP->SetGlobalGCEpilogueCallback(&GCEpilogueCallbackFunc); |
| 290 | 286 |
| 291 // Scavenge does not call GC callback functions. | 287 // Scavenge does not call GC callback functions. |
| 292 Heap::PerformScavenge(); | 288 HEAP->PerformScavenge(); |
| 293 | 289 |
| 294 CHECK_EQ(0, gc_starts); | 290 CHECK_EQ(0, gc_starts); |
| 295 CHECK_EQ(gc_ends, gc_starts); | 291 CHECK_EQ(gc_ends, gc_starts); |
| 296 | 292 |
| 297 Heap::CollectGarbage(OLD_POINTER_SPACE); | 293 HEAP->CollectGarbage(OLD_POINTER_SPACE); |
| 298 CHECK_EQ(1, gc_starts); | 294 CHECK_EQ(1, gc_starts); |
| 299 CHECK_EQ(gc_ends, gc_starts); | 295 CHECK_EQ(gc_ends, gc_starts); |
| 300 } | 296 } |
| 301 | 297 |
| 302 | 298 |
| 303 static int NumberOfWeakCalls = 0; | 299 static int NumberOfWeakCalls = 0; |
| 304 static void WeakPointerCallback(v8::Persistent<v8::Value> handle, void* id) { | 300 static void WeakPointerCallback(v8::Persistent<v8::Value> handle, void* id) { |
| 305 ASSERT(id == reinterpret_cast<void*>(1234)); | 301 ASSERT(id == reinterpret_cast<void*>(1234)); |
| 306 NumberOfWeakCalls++; | 302 NumberOfWeakCalls++; |
| 307 handle.Dispose(); | 303 handle.Dispose(); |
| 308 } | 304 } |
| 309 | 305 |
| 310 TEST(ObjectGroups) { | 306 TEST(ObjectGroups) { |
| 307 GlobalHandles* global_handles = Isolate::Current()->global_handles(); |
| 311 InitializeVM(); | 308 InitializeVM(); |
| 312 | 309 |
| 313 NumberOfWeakCalls = 0; | 310 NumberOfWeakCalls = 0; |
| 314 v8::HandleScope handle_scope; | 311 v8::HandleScope handle_scope; |
| 315 | 312 |
| 316 Handle<Object> g1s1 = | 313 Handle<Object> g1s1 = |
| 317 GlobalHandles::Create(Heap::AllocateFixedArray(1)->ToObjectChecked()); | 314 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
| 318 Handle<Object> g1s2 = | 315 Handle<Object> g1s2 = |
| 319 GlobalHandles::Create(Heap::AllocateFixedArray(1)->ToObjectChecked()); | 316 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
| 320 Handle<Object> g1c1 = | 317 Handle<Object> g1c1 = |
| 321 GlobalHandles::Create(Heap::AllocateFixedArray(1)->ToObjectChecked()); | 318 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
| 322 GlobalHandles::MakeWeak(g1s1.location(), | 319 global_handles->MakeWeak(g1s1.location(), |
| 323 reinterpret_cast<void*>(1234), | 320 reinterpret_cast<void*>(1234), |
| 324 &WeakPointerCallback); | 321 &WeakPointerCallback); |
| 325 GlobalHandles::MakeWeak(g1s2.location(), | 322 global_handles->MakeWeak(g1s2.location(), |
| 326 reinterpret_cast<void*>(1234), | 323 reinterpret_cast<void*>(1234), |
| 327 &WeakPointerCallback); | 324 &WeakPointerCallback); |
| 328 GlobalHandles::MakeWeak(g1c1.location(), | 325 global_handles->MakeWeak(g1c1.location(), |
| 329 reinterpret_cast<void*>(1234), | 326 reinterpret_cast<void*>(1234), |
| 330 &WeakPointerCallback); | 327 &WeakPointerCallback); |
| 331 | 328 |
| 332 Handle<Object> g2s1 = | 329 Handle<Object> g2s1 = |
| 333 GlobalHandles::Create(Heap::AllocateFixedArray(1)->ToObjectChecked()); | 330 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
| 334 Handle<Object> g2s2 = | 331 Handle<Object> g2s2 = |
| 335 GlobalHandles::Create(Heap::AllocateFixedArray(1)->ToObjectChecked()); | 332 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
| 336 Handle<Object> g2c1 = | 333 Handle<Object> g2c1 = |
| 337 GlobalHandles::Create(Heap::AllocateFixedArray(1)->ToObjectChecked()); | 334 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
| 338 GlobalHandles::MakeWeak(g2s1.location(), | 335 global_handles->MakeWeak(g2s1.location(), |
| 339 reinterpret_cast<void*>(1234), | 336 reinterpret_cast<void*>(1234), |
| 340 &WeakPointerCallback); | 337 &WeakPointerCallback); |
| 341 GlobalHandles::MakeWeak(g2s2.location(), | 338 global_handles->MakeWeak(g2s2.location(), |
| 342 reinterpret_cast<void*>(1234), | 339 reinterpret_cast<void*>(1234), |
| 343 &WeakPointerCallback); | 340 &WeakPointerCallback); |
| 344 GlobalHandles::MakeWeak(g2c1.location(), | 341 global_handles->MakeWeak(g2c1.location(), |
| 345 reinterpret_cast<void*>(1234), | 342 reinterpret_cast<void*>(1234), |
| 346 &WeakPointerCallback); | 343 &WeakPointerCallback); |
| 347 | 344 |
| 348 Handle<Object> root = GlobalHandles::Create(*g1s1); // make a root. | 345 Handle<Object> root = global_handles->Create(*g1s1); // make a root. |
| 349 | 346 |
| 350 // Connect group 1 and 2, make a cycle. | 347 // Connect group 1 and 2, make a cycle. |
| 351 Handle<FixedArray>::cast(g1s2)->set(0, *g2s2); | 348 Handle<FixedArray>::cast(g1s2)->set(0, *g2s2); |
| 352 Handle<FixedArray>::cast(g2s1)->set(0, *g1s1); | 349 Handle<FixedArray>::cast(g2s1)->set(0, *g1s1); |
| 353 | 350 |
| 354 { | 351 { |
| 355 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; | 352 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; |
| 356 Object** g1_children[] = { g1c1.location() }; | 353 Object** g1_children[] = { g1c1.location() }; |
| 357 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; | 354 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; |
| 358 Object** g2_children[] = { g2c1.location() }; | 355 Object** g2_children[] = { g2c1.location() }; |
| 359 GlobalHandles::AddObjectGroup(g1_objects, 2, NULL); | 356 global_handles->AddObjectGroup(g1_objects, 2, NULL); |
| 360 GlobalHandles::AddImplicitReferences(HeapObject::cast(*g1s1), | 357 global_handles->AddImplicitReferences(HeapObject::cast(*g1s1), |
| 361 g1_children, 1); | 358 g1_children, 1); |
| 362 GlobalHandles::AddObjectGroup(g2_objects, 2, NULL); | 359 global_handles->AddObjectGroup(g2_objects, 2, NULL); |
| 363 GlobalHandles::AddImplicitReferences(HeapObject::cast(*g2s2), | 360 global_handles->AddImplicitReferences(HeapObject::cast(*g2s2), |
| 364 g2_children, 1); | 361 g2_children, 1); |
| 365 } | 362 } |
| 366 // Do a full GC | 363 // Do a full GC |
| 367 Heap::CollectGarbage(OLD_POINTER_SPACE); | 364 HEAP->CollectGarbage(OLD_POINTER_SPACE); |
| 368 | 365 |
| 369 // All object should be alive. | 366 // All object should be alive. |
| 370 CHECK_EQ(0, NumberOfWeakCalls); | 367 CHECK_EQ(0, NumberOfWeakCalls); |
| 371 | 368 |
| 372 // Weaken the root. | 369 // Weaken the root. |
| 373 GlobalHandles::MakeWeak(root.location(), | 370 global_handles->MakeWeak(root.location(), |
| 374 reinterpret_cast<void*>(1234), | 371 reinterpret_cast<void*>(1234), |
| 375 &WeakPointerCallback); | 372 &WeakPointerCallback); |
| 376 // But make children strong roots---all the objects (except for children) | 373 // But make children strong roots---all the objects (except for children) |
| 377 // should be collectable now. | 374 // should be collectable now. |
| 378 GlobalHandles::ClearWeakness(g1c1.location()); | 375 global_handles->ClearWeakness(g1c1.location()); |
| 379 GlobalHandles::ClearWeakness(g2c1.location()); | 376 global_handles->ClearWeakness(g2c1.location()); |
| 380 | 377 |
| 381 // Groups are deleted, rebuild groups. | 378 // Groups are deleted, rebuild groups. |
| 382 { | 379 { |
| 383 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; | 380 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; |
| 384 Object** g1_children[] = { g1c1.location() }; | 381 Object** g1_children[] = { g1c1.location() }; |
| 385 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; | 382 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; |
| 386 Object** g2_children[] = { g2c1.location() }; | 383 Object** g2_children[] = { g2c1.location() }; |
| 387 GlobalHandles::AddObjectGroup(g1_objects, 2, NULL); | 384 global_handles->AddObjectGroup(g1_objects, 2, NULL); |
| 388 GlobalHandles::AddImplicitReferences(HeapObject::cast(*g1s1), | 385 global_handles->AddImplicitReferences(HeapObject::cast(*g1s1), |
| 389 g1_children, 1); | 386 g1_children, 1); |
| 390 GlobalHandles::AddObjectGroup(g2_objects, 2, NULL); | 387 global_handles->AddObjectGroup(g2_objects, 2, NULL); |
| 391 GlobalHandles::AddImplicitReferences(HeapObject::cast(*g2s2), | 388 global_handles->AddImplicitReferences(HeapObject::cast(*g2s2), |
| 392 g2_children, 1); | 389 g2_children, 1); |
| 393 } | 390 } |
| 394 | 391 |
| 395 Heap::CollectGarbage(OLD_POINTER_SPACE); | 392 HEAP->CollectGarbage(OLD_POINTER_SPACE); |
| 396 | 393 |
| 397 // All objects should be gone. 5 global handles in total. | 394 // All objects should be gone. 5 global handles in total. |
| 398 CHECK_EQ(5, NumberOfWeakCalls); | 395 CHECK_EQ(5, NumberOfWeakCalls); |
| 399 | 396 |
| 400 // And now make children weak again and collect them. | 397 // And now make children weak again and collect them. |
| 401 GlobalHandles::MakeWeak(g1c1.location(), | 398 global_handles->MakeWeak(g1c1.location(), |
| 402 reinterpret_cast<void*>(1234), | 399 reinterpret_cast<void*>(1234), |
| 403 &WeakPointerCallback); | 400 &WeakPointerCallback); |
| 404 GlobalHandles::MakeWeak(g2c1.location(), | 401 global_handles->MakeWeak(g2c1.location(), |
| 405 reinterpret_cast<void*>(1234), | 402 reinterpret_cast<void*>(1234), |
| 406 &WeakPointerCallback); | 403 &WeakPointerCallback); |
| 407 | 404 |
| 408 Heap::CollectGarbage(OLD_POINTER_SPACE); | 405 HEAP->CollectGarbage(OLD_POINTER_SPACE); |
| 409 CHECK_EQ(7, NumberOfWeakCalls); | 406 CHECK_EQ(7, NumberOfWeakCalls); |
| 410 } | 407 } |
| OLD | NEW |