| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 CHECK_EQ(original_address, current_address); | 70 CHECK_EQ(original_address, current_address); |
| 71 DeleteArray(mem); | 71 DeleteArray(mem); |
| 72 } | 72 } |
| 73 | 73 |
| 74 | 74 |
| 75 TEST(Promotion) { | 75 TEST(Promotion) { |
| 76 // This test requires compaction. If compaction is turned off, we | 76 // This test requires compaction. If compaction is turned off, we |
| 77 // skip the entire test. | 77 // skip the entire test. |
| 78 if (FLAG_never_compact) return; | 78 if (FLAG_never_compact) return; |
| 79 | 79 |
| 80 CcTest::InitializeVM(); |
| 81 |
| 80 // Ensure that we get a compacting collection so that objects are promoted | 82 // Ensure that we get a compacting collection so that objects are promoted |
| 81 // from new space. | 83 // from new space. |
| 82 FLAG_gc_global = true; | 84 FLAG_gc_global = true; |
| 83 FLAG_always_compact = true; | 85 FLAG_always_compact = true; |
| 84 HEAP->ConfigureHeap(2*256*KB, 8*MB, 8*MB); | 86 Heap* heap = CcTest::heap(); |
| 85 | 87 heap->ConfigureHeap(2*256*KB, 8*MB, 8*MB); |
| 86 CcTest::InitializeVM(); | |
| 87 | 88 |
| 88 v8::HandleScope sc(CcTest::isolate()); | 89 v8::HandleScope sc(CcTest::isolate()); |
| 89 | 90 |
| 90 // Allocate a fixed array in the new space. | 91 // Allocate a fixed array in the new space. |
| 91 int array_size = | 92 int array_size = |
| 92 (Page::kMaxNonCodeHeapObjectSize - FixedArray::kHeaderSize) / | 93 (Page::kMaxNonCodeHeapObjectSize - FixedArray::kHeaderSize) / |
| 93 (kPointerSize * 4); | 94 (kPointerSize * 4); |
| 94 Object* obj = HEAP->AllocateFixedArray(array_size)->ToObjectChecked(); | 95 Object* obj = heap->AllocateFixedArray(array_size)->ToObjectChecked(); |
| 95 | 96 |
| 96 Handle<FixedArray> array(FixedArray::cast(obj)); | 97 Handle<FixedArray> array(FixedArray::cast(obj)); |
| 97 | 98 |
| 98 // Array should be in the new space. | 99 // Array should be in the new space. |
| 99 CHECK(HEAP->InSpace(*array, NEW_SPACE)); | 100 CHECK(heap->InSpace(*array, NEW_SPACE)); |
| 100 | 101 |
| 101 // Call the m-c collector, so array becomes an old object. | 102 // Call the m-c collector, so array becomes an old object. |
| 102 HEAP->CollectGarbage(OLD_POINTER_SPACE); | 103 heap->CollectGarbage(OLD_POINTER_SPACE); |
| 103 | 104 |
| 104 // Array now sits in the old space | 105 // Array now sits in the old space |
| 105 CHECK(HEAP->InSpace(*array, OLD_POINTER_SPACE)); | 106 CHECK(heap->InSpace(*array, OLD_POINTER_SPACE)); |
| 106 } | 107 } |
| 107 | 108 |
| 108 | 109 |
| 109 TEST(NoPromotion) { | 110 TEST(NoPromotion) { |
| 110 HEAP->ConfigureHeap(2*256*KB, 8*MB, 8*MB); | |
| 111 | |
| 112 // Test the situation that some objects in new space are promoted to | 111 // Test the situation that some objects in new space are promoted to |
| 113 // the old space | 112 // the old space |
| 114 CcTest::InitializeVM(); | 113 CcTest::InitializeVM(); |
| 115 | 114 |
| 115 CcTest::heap()->ConfigureHeap(2*256*KB, 8*MB, 8*MB); |
| 116 |
| 116 v8::HandleScope sc(CcTest::isolate()); | 117 v8::HandleScope sc(CcTest::isolate()); |
| 117 | 118 |
| 118 // Do a mark compact GC to shrink the heap. | 119 // Do a mark compact GC to shrink the heap. |
| 119 HEAP->CollectGarbage(OLD_POINTER_SPACE); | 120 CcTest::heap()->CollectGarbage(OLD_POINTER_SPACE); |
| 120 | 121 |
| 121 // Allocate a big Fixed array in the new space. | 122 // Allocate a big Fixed array in the new space. |
| 122 int length = (Page::kMaxNonCodeHeapObjectSize - | 123 int length = (Page::kMaxNonCodeHeapObjectSize - |
| 123 FixedArray::kHeaderSize) / (2 * kPointerSize); | 124 FixedArray::kHeaderSize) / (2 * kPointerSize); |
| 124 Object* obj = i::Isolate::Current()->heap()->AllocateFixedArray(length)-> | 125 Object* obj = CcTest::heap()->AllocateFixedArray(length)-> |
| 125 ToObjectChecked(); | 126 ToObjectChecked(); |
| 126 | 127 |
| 127 Handle<FixedArray> array(FixedArray::cast(obj)); | 128 Handle<FixedArray> array(FixedArray::cast(obj)); |
| 128 | 129 |
| 129 // Array still stays in the new space. | 130 // Array still stays in the new space. |
| 130 CHECK(HEAP->InSpace(*array, NEW_SPACE)); | 131 CHECK(CcTest::heap()->InSpace(*array, NEW_SPACE)); |
| 131 | 132 |
| 132 // Allocate objects in the old space until out of memory. | 133 // Allocate objects in the old space until out of memory. |
| 133 FixedArray* host = *array; | 134 FixedArray* host = *array; |
| 134 while (true) { | 135 while (true) { |
| 135 Object* obj; | 136 Object* obj; |
| 136 { MaybeObject* maybe_obj = HEAP->AllocateFixedArray(100, TENURED); | 137 { MaybeObject* maybe_obj = CcTest::heap()->AllocateFixedArray(100, TENURED); |
| 137 if (!maybe_obj->ToObject(&obj)) break; | 138 if (!maybe_obj->ToObject(&obj)) break; |
| 138 } | 139 } |
| 139 | 140 |
| 140 host->set(0, obj); | 141 host->set(0, obj); |
| 141 host = FixedArray::cast(obj); | 142 host = FixedArray::cast(obj); |
| 142 } | 143 } |
| 143 | 144 |
| 144 // Call mark compact GC, and it should pass. | 145 // Call mark compact GC, and it should pass. |
| 145 HEAP->CollectGarbage(OLD_POINTER_SPACE); | 146 CcTest::heap()->CollectGarbage(OLD_POINTER_SPACE); |
| 146 } | 147 } |
| 147 | 148 |
| 148 | 149 |
| 149 TEST(MarkCompactCollector) { | 150 TEST(MarkCompactCollector) { |
| 150 FLAG_incremental_marking = false; | 151 FLAG_incremental_marking = false; |
| 151 CcTest::InitializeVM(); | 152 CcTest::InitializeVM(); |
| 152 Isolate* isolate = Isolate::Current(); | 153 Isolate* isolate = CcTest::i_isolate(); |
| 153 Heap* heap = isolate->heap(); | 154 Heap* heap = isolate->heap(); |
| 154 | 155 |
| 155 v8::HandleScope sc(CcTest::isolate()); | 156 v8::HandleScope sc(CcTest::isolate()); |
| 157 Handle<GlobalObject> global(isolate->context()->global_object()); |
| 156 | 158 |
| 157 // call mark-compact when heap is empty | 159 // call mark-compact when heap is empty |
| 158 heap->CollectGarbage(OLD_POINTER_SPACE, "trigger 1"); | 160 heap->CollectGarbage(OLD_POINTER_SPACE, "trigger 1"); |
| 159 | 161 |
| 160 // keep allocating garbage in new space until it fails | 162 // keep allocating garbage in new space until it fails |
| 161 const int ARRAY_SIZE = 100; | 163 const int ARRAY_SIZE = 100; |
| 162 Object* array; | 164 Object* array; |
| 163 MaybeObject* maybe_array; | 165 MaybeObject* maybe_array; |
| 164 do { | 166 do { |
| 165 maybe_array = heap->AllocateFixedArray(ARRAY_SIZE); | 167 maybe_array = heap->AllocateFixedArray(ARRAY_SIZE); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 184 SharedFunctionInfo* function_share = SharedFunctionInfo::cast( | 186 SharedFunctionInfo* function_share = SharedFunctionInfo::cast( |
| 185 heap->AllocateSharedFunctionInfo(func_name)->ToObjectChecked()); | 187 heap->AllocateSharedFunctionInfo(func_name)->ToObjectChecked()); |
| 186 JSFunction* function = JSFunction::cast( | 188 JSFunction* function = JSFunction::cast( |
| 187 heap->AllocateFunction(*isolate->function_map(), | 189 heap->AllocateFunction(*isolate->function_map(), |
| 188 function_share, | 190 function_share, |
| 189 heap->undefined_value())->ToObjectChecked()); | 191 heap->undefined_value())->ToObjectChecked()); |
| 190 Map* initial_map = | 192 Map* initial_map = |
| 191 Map::cast(heap->AllocateMap(JS_OBJECT_TYPE, | 193 Map::cast(heap->AllocateMap(JS_OBJECT_TYPE, |
| 192 JSObject::kHeaderSize)->ToObjectChecked()); | 194 JSObject::kHeaderSize)->ToObjectChecked()); |
| 193 function->set_initial_map(initial_map); | 195 function->set_initial_map(initial_map); |
| 194 isolate->context()->global_object()->SetProperty( | 196 JSReceiver::SetProperty( |
| 195 func_name, function, NONE, kNonStrictMode)->ToObjectChecked(); | 197 global, handle(func_name), handle(function), NONE, kNonStrictMode); |
| 196 | 198 |
| 197 JSObject* obj = JSObject::cast( | 199 JSObject* obj = JSObject::cast( |
| 198 heap->AllocateJSObject(function)->ToObjectChecked()); | 200 heap->AllocateJSObject(function)->ToObjectChecked()); |
| 199 heap->CollectGarbage(OLD_POINTER_SPACE, "trigger 4"); | 201 heap->CollectGarbage(OLD_POINTER_SPACE, "trigger 4"); |
| 200 | 202 |
| 201 func_name = String::cast( | 203 func_name = String::cast( |
| 202 heap->InternalizeUtf8String("theFunction")->ToObjectChecked()); | 204 heap->InternalizeUtf8String("theFunction")->ToObjectChecked()); |
| 203 CHECK(isolate->context()->global_object()->HasLocalProperty(func_name)); | 205 CHECK(JSReceiver::HasLocalProperty(global, handle(func_name))); |
| 204 Object* func_value = isolate->context()->global_object()-> | 206 Object* func_value = isolate->context()->global_object()-> |
| 205 GetProperty(func_name)->ToObjectChecked(); | 207 GetProperty(func_name)->ToObjectChecked(); |
| 206 CHECK(func_value->IsJSFunction()); | 208 CHECK(func_value->IsJSFunction()); |
| 207 function = JSFunction::cast(func_value); | 209 function = JSFunction::cast(func_value); |
| 208 | 210 |
| 209 obj = JSObject::cast(heap->AllocateJSObject(function)->ToObjectChecked()); | 211 obj = JSObject::cast(heap->AllocateJSObject(function)->ToObjectChecked()); |
| 210 String* obj_name = | 212 String* obj_name = |
| 211 String::cast(heap->InternalizeUtf8String("theObject")->ToObjectChecked()); | 213 String::cast(heap->InternalizeUtf8String("theObject")->ToObjectChecked()); |
| 212 isolate->context()->global_object()->SetProperty( | 214 JSReceiver::SetProperty( |
| 213 obj_name, obj, NONE, kNonStrictMode)->ToObjectChecked(); | 215 global, handle(obj_name), handle(obj), NONE, kNonStrictMode); |
| 214 String* prop_name = | 216 String* prop_name = |
| 215 String::cast(heap->InternalizeUtf8String("theSlot")->ToObjectChecked()); | 217 String::cast(heap->InternalizeUtf8String("theSlot")->ToObjectChecked()); |
| 216 obj->SetProperty(prop_name, | 218 Handle<Smi> twenty_three(Smi::FromInt(23), isolate); |
| 217 Smi::FromInt(23), | 219 JSReceiver::SetProperty( |
| 218 NONE, | 220 handle(obj), handle(prop_name), twenty_three, NONE, kNonStrictMode); |
| 219 kNonStrictMode)->ToObjectChecked(); | |
| 220 | 221 |
| 221 heap->CollectGarbage(OLD_POINTER_SPACE, "trigger 5"); | 222 heap->CollectGarbage(OLD_POINTER_SPACE, "trigger 5"); |
| 222 | 223 |
| 223 obj_name = | 224 obj_name = |
| 224 String::cast(heap->InternalizeUtf8String("theObject")->ToObjectChecked()); | 225 String::cast(heap->InternalizeUtf8String("theObject")->ToObjectChecked()); |
| 225 CHECK(isolate->context()->global_object()->HasLocalProperty(obj_name)); | 226 CHECK(JSReceiver::HasLocalProperty(global, handle(obj_name))); |
| 226 CHECK(isolate->context()->global_object()-> | 227 CHECK(isolate->context()->global_object()-> |
| 227 GetProperty(obj_name)->ToObjectChecked()->IsJSObject()); | 228 GetProperty(obj_name)->ToObjectChecked()->IsJSObject()); |
| 228 obj = JSObject::cast(isolate->context()->global_object()-> | 229 obj = JSObject::cast(isolate->context()->global_object()-> |
| 229 GetProperty(obj_name)->ToObjectChecked()); | 230 GetProperty(obj_name)->ToObjectChecked()); |
| 230 prop_name = | 231 prop_name = |
| 231 String::cast(heap->InternalizeUtf8String("theSlot")->ToObjectChecked()); | 232 String::cast(heap->InternalizeUtf8String("theSlot")->ToObjectChecked()); |
| 232 CHECK(obj->GetProperty(prop_name) == Smi::FromInt(23)); | 233 CHECK(obj->GetProperty(prop_name) == Smi::FromInt(23)); |
| 233 } | 234 } |
| 234 | 235 |
| 235 | 236 |
| 236 // TODO(1600): compaction of map space is temporary removed from GC. | 237 // TODO(1600): compaction of map space is temporary removed from GC. |
| 237 #if 0 | 238 #if 0 |
| 238 static Handle<Map> CreateMap(Isolate* isolate) { | 239 static Handle<Map> CreateMap(Isolate* isolate) { |
| 239 return isolate->factory()->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 240 return isolate->factory()->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
| 240 } | 241 } |
| 241 | 242 |
| 242 | 243 |
| 243 TEST(MapCompact) { | 244 TEST(MapCompact) { |
| 244 FLAG_max_map_space_pages = 16; | 245 FLAG_max_map_space_pages = 16; |
| 245 CcTest::InitializeVM(); | 246 CcTest::InitializeVM(); |
| 246 Isolate* isolate = Isolate::Current(); | 247 Isolate* isolate = CcTest::i_isolate(); |
| 247 Factory* factory = isolate->factory(); | 248 Factory* factory = isolate->factory(); |
| 248 | 249 |
| 249 { | 250 { |
| 250 v8::HandleScope sc; | 251 v8::HandleScope sc; |
| 251 // keep allocating maps while pointers are still encodable and thus | 252 // keep allocating maps while pointers are still encodable and thus |
| 252 // mark compact is permitted. | 253 // mark compact is permitted. |
| 253 Handle<JSObject> root = factory->NewJSObjectFromMap(CreateMap()); | 254 Handle<JSObject> root = factory->NewJSObjectFromMap(CreateMap()); |
| 254 do { | 255 do { |
| 255 Handle<Map> map = CreateMap(); | 256 Handle<Map> map = CreateMap(); |
| 256 map->set_prototype(*root); | 257 map->set_prototype(*root); |
| 257 root = factory->NewJSObjectFromMap(map); | 258 root = factory->NewJSObjectFromMap(map); |
| 258 } while (HEAP->map_space()->MapPointersEncodable()); | 259 } while (CcTest::heap()->map_space()->MapPointersEncodable()); |
| 259 } | 260 } |
| 260 // Now, as we don't have any handles to just allocated maps, we should | 261 // Now, as we don't have any handles to just allocated maps, we should |
| 261 // be able to trigger map compaction. | 262 // be able to trigger map compaction. |
| 262 // To give an additional chance to fail, try to force compaction which | 263 // To give an additional chance to fail, try to force compaction which |
| 263 // should be impossible right now. | 264 // should be impossible right now. |
| 264 HEAP->CollectAllGarbage(Heap::kForceCompactionMask); | 265 CcTest::heap()->CollectAllGarbage(Heap::kForceCompactionMask); |
| 265 // And now map pointers should be encodable again. | 266 // And now map pointers should be encodable again. |
| 266 CHECK(HEAP->map_space()->MapPointersEncodable()); | 267 CHECK(CcTest::heap()->map_space()->MapPointersEncodable()); |
| 267 } | 268 } |
| 268 #endif | 269 #endif |
| 269 | 270 |
| 270 static int gc_starts = 0; | |
| 271 static int gc_ends = 0; | |
| 272 | |
| 273 static void GCPrologueCallbackFunc() { | |
| 274 CHECK(gc_starts == gc_ends); | |
| 275 gc_starts++; | |
| 276 } | |
| 277 | |
| 278 | |
| 279 static void GCEpilogueCallbackFunc() { | |
| 280 CHECK(gc_starts == gc_ends + 1); | |
| 281 gc_ends++; | |
| 282 } | |
| 283 | |
| 284 | |
| 285 TEST(GCCallback) { | |
| 286 i::FLAG_stress_compaction = false; | |
| 287 CcTest::InitializeVM(); | |
| 288 | |
| 289 HEAP->SetGlobalGCPrologueCallback(&GCPrologueCallbackFunc); | |
| 290 HEAP->SetGlobalGCEpilogueCallback(&GCEpilogueCallbackFunc); | |
| 291 | |
| 292 // Scavenge does not call GC callback functions. | |
| 293 HEAP->PerformScavenge(); | |
| 294 | |
| 295 CHECK_EQ(0, gc_starts); | |
| 296 CHECK_EQ(gc_ends, gc_starts); | |
| 297 | |
| 298 HEAP->CollectGarbage(OLD_POINTER_SPACE); | |
| 299 CHECK_EQ(1, gc_starts); | |
| 300 CHECK_EQ(gc_ends, gc_starts); | |
| 301 } | |
| 302 | |
| 303 | 271 |
| 304 static int NumberOfWeakCalls = 0; | 272 static int NumberOfWeakCalls = 0; |
| 305 static void WeakPointerCallback(v8::Isolate* isolate, | 273 static void WeakPointerCallback(v8::Isolate* isolate, |
| 306 v8::Persistent<v8::Value>* handle, | 274 v8::Persistent<v8::Value>* handle, |
| 307 void* id) { | 275 void* id) { |
| 308 ASSERT(id == reinterpret_cast<void*>(1234)); | 276 ASSERT(id == reinterpret_cast<void*>(1234)); |
| 309 NumberOfWeakCalls++; | 277 NumberOfWeakCalls++; |
| 310 handle->Dispose(); | 278 handle->Dispose(); |
| 311 } | 279 } |
| 312 | 280 |
| 313 | 281 |
| 314 TEST(ObjectGroups) { | 282 TEST(ObjectGroups) { |
| 315 FLAG_incremental_marking = false; | 283 FLAG_incremental_marking = false; |
| 316 CcTest::InitializeVM(); | 284 CcTest::InitializeVM(); |
| 317 GlobalHandles* global_handles = Isolate::Current()->global_handles(); | 285 GlobalHandles* global_handles = CcTest::i_isolate()->global_handles(); |
| 318 | 286 Heap* heap = CcTest::heap(); |
| 319 NumberOfWeakCalls = 0; | 287 NumberOfWeakCalls = 0; |
| 320 v8::HandleScope handle_scope(CcTest::isolate()); | 288 v8::HandleScope handle_scope(CcTest::isolate()); |
| 321 | 289 |
| 322 Handle<Object> g1s1 = | 290 Handle<Object> g1s1 = |
| 323 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); | 291 global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); |
| 324 Handle<Object> g1s2 = | 292 Handle<Object> g1s2 = |
| 325 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); | 293 global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); |
| 326 Handle<Object> g1c1 = | 294 Handle<Object> g1c1 = |
| 327 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); | 295 global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); |
| 328 global_handles->MakeWeak(g1s1.location(), | 296 global_handles->MakeWeak(g1s1.location(), |
| 329 reinterpret_cast<void*>(1234), | 297 reinterpret_cast<void*>(1234), |
| 330 &WeakPointerCallback); | 298 &WeakPointerCallback); |
| 331 global_handles->MakeWeak(g1s2.location(), | 299 global_handles->MakeWeak(g1s2.location(), |
| 332 reinterpret_cast<void*>(1234), | 300 reinterpret_cast<void*>(1234), |
| 333 &WeakPointerCallback); | 301 &WeakPointerCallback); |
| 334 global_handles->MakeWeak(g1c1.location(), | 302 global_handles->MakeWeak(g1c1.location(), |
| 335 reinterpret_cast<void*>(1234), | 303 reinterpret_cast<void*>(1234), |
| 336 &WeakPointerCallback); | 304 &WeakPointerCallback); |
| 337 | 305 |
| 338 Handle<Object> g2s1 = | 306 Handle<Object> g2s1 = |
| 339 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); | 307 global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); |
| 340 Handle<Object> g2s2 = | 308 Handle<Object> g2s2 = |
| 341 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); | 309 global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); |
| 342 Handle<Object> g2c1 = | 310 Handle<Object> g2c1 = |
| 343 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); | 311 global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); |
| 344 global_handles->MakeWeak(g2s1.location(), | 312 global_handles->MakeWeak(g2s1.location(), |
| 345 reinterpret_cast<void*>(1234), | 313 reinterpret_cast<void*>(1234), |
| 346 &WeakPointerCallback); | 314 &WeakPointerCallback); |
| 347 global_handles->MakeWeak(g2s2.location(), | 315 global_handles->MakeWeak(g2s2.location(), |
| 348 reinterpret_cast<void*>(1234), | 316 reinterpret_cast<void*>(1234), |
| 349 &WeakPointerCallback); | 317 &WeakPointerCallback); |
| 350 global_handles->MakeWeak(g2c1.location(), | 318 global_handles->MakeWeak(g2c1.location(), |
| 351 reinterpret_cast<void*>(1234), | 319 reinterpret_cast<void*>(1234), |
| 352 &WeakPointerCallback); | 320 &WeakPointerCallback); |
| 353 | 321 |
| 354 Handle<Object> root = global_handles->Create(*g1s1); // make a root. | 322 Handle<Object> root = global_handles->Create(*g1s1); // make a root. |
| 355 | 323 |
| 356 // Connect group 1 and 2, make a cycle. | 324 // Connect group 1 and 2, make a cycle. |
| 357 Handle<FixedArray>::cast(g1s2)->set(0, *g2s2); | 325 Handle<FixedArray>::cast(g1s2)->set(0, *g2s2); |
| 358 Handle<FixedArray>::cast(g2s1)->set(0, *g1s1); | 326 Handle<FixedArray>::cast(g2s1)->set(0, *g1s1); |
| 359 | 327 |
| 360 { | 328 { |
| 361 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; | 329 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; |
| 362 Object** g1_children[] = { g1c1.location() }; | 330 Object** g1_children[] = { g1c1.location() }; |
| 363 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; | 331 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; |
| 364 Object** g2_children[] = { g2c1.location() }; | 332 Object** g2_children[] = { g2c1.location() }; |
| 365 global_handles->AddObjectGroup(g1_objects, 2, NULL); | 333 global_handles->AddObjectGroup(g1_objects, 2, NULL); |
| 366 global_handles->AddImplicitReferences( | 334 global_handles->AddImplicitReferences( |
| 367 Handle<HeapObject>::cast(g1s1).location(), g1_children, 1); | 335 Handle<HeapObject>::cast(g1s1).location(), g1_children, 1); |
| 368 global_handles->AddObjectGroup(g2_objects, 2, NULL); | 336 global_handles->AddObjectGroup(g2_objects, 2, NULL); |
| 369 global_handles->AddImplicitReferences( | 337 global_handles->AddImplicitReferences( |
| 370 Handle<HeapObject>::cast(g2s1).location(), g2_children, 1); | 338 Handle<HeapObject>::cast(g2s1).location(), g2_children, 1); |
| 371 } | 339 } |
| 372 // Do a full GC | 340 // Do a full GC |
| 373 HEAP->CollectGarbage(OLD_POINTER_SPACE); | 341 heap->CollectGarbage(OLD_POINTER_SPACE); |
| 374 | 342 |
| 375 // All object should be alive. | 343 // All object should be alive. |
| 376 CHECK_EQ(0, NumberOfWeakCalls); | 344 CHECK_EQ(0, NumberOfWeakCalls); |
| 377 | 345 |
| 378 // Weaken the root. | 346 // Weaken the root. |
| 379 global_handles->MakeWeak(root.location(), | 347 global_handles->MakeWeak(root.location(), |
| 380 reinterpret_cast<void*>(1234), | 348 reinterpret_cast<void*>(1234), |
| 381 &WeakPointerCallback); | 349 &WeakPointerCallback); |
| 382 // But make children strong roots---all the objects (except for children) | 350 // But make children strong roots---all the objects (except for children) |
| 383 // should be collectable now. | 351 // should be collectable now. |
| 384 global_handles->ClearWeakness(g1c1.location()); | 352 global_handles->ClearWeakness(g1c1.location()); |
| 385 global_handles->ClearWeakness(g2c1.location()); | 353 global_handles->ClearWeakness(g2c1.location()); |
| 386 | 354 |
| 387 // Groups are deleted, rebuild groups. | 355 // Groups are deleted, rebuild groups. |
| 388 { | 356 { |
| 389 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; | 357 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; |
| 390 Object** g1_children[] = { g1c1.location() }; | 358 Object** g1_children[] = { g1c1.location() }; |
| 391 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; | 359 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; |
| 392 Object** g2_children[] = { g2c1.location() }; | 360 Object** g2_children[] = { g2c1.location() }; |
| 393 global_handles->AddObjectGroup(g1_objects, 2, NULL); | 361 global_handles->AddObjectGroup(g1_objects, 2, NULL); |
| 394 global_handles->AddImplicitReferences( | 362 global_handles->AddImplicitReferences( |
| 395 Handle<HeapObject>::cast(g1s1).location(), g1_children, 1); | 363 Handle<HeapObject>::cast(g1s1).location(), g1_children, 1); |
| 396 global_handles->AddObjectGroup(g2_objects, 2, NULL); | 364 global_handles->AddObjectGroup(g2_objects, 2, NULL); |
| 397 global_handles->AddImplicitReferences( | 365 global_handles->AddImplicitReferences( |
| 398 Handle<HeapObject>::cast(g2s1).location(), g2_children, 1); | 366 Handle<HeapObject>::cast(g2s1).location(), g2_children, 1); |
| 399 } | 367 } |
| 400 | 368 |
| 401 HEAP->CollectGarbage(OLD_POINTER_SPACE); | 369 heap->CollectGarbage(OLD_POINTER_SPACE); |
| 402 | 370 |
| 403 // All objects should be gone. 5 global handles in total. | 371 // All objects should be gone. 5 global handles in total. |
| 404 CHECK_EQ(5, NumberOfWeakCalls); | 372 CHECK_EQ(5, NumberOfWeakCalls); |
| 405 | 373 |
| 406 // And now make children weak again and collect them. | 374 // And now make children weak again and collect them. |
| 407 global_handles->MakeWeak(g1c1.location(), | 375 global_handles->MakeWeak(g1c1.location(), |
| 408 reinterpret_cast<void*>(1234), | 376 reinterpret_cast<void*>(1234), |
| 409 &WeakPointerCallback); | 377 &WeakPointerCallback); |
| 410 global_handles->MakeWeak(g2c1.location(), | 378 global_handles->MakeWeak(g2c1.location(), |
| 411 reinterpret_cast<void*>(1234), | 379 reinterpret_cast<void*>(1234), |
| 412 &WeakPointerCallback); | 380 &WeakPointerCallback); |
| 413 | 381 |
| 414 HEAP->CollectGarbage(OLD_POINTER_SPACE); | 382 heap->CollectGarbage(OLD_POINTER_SPACE); |
| 415 CHECK_EQ(7, NumberOfWeakCalls); | 383 CHECK_EQ(7, NumberOfWeakCalls); |
| 416 } | 384 } |
| 417 | 385 |
| 418 | 386 |
| 419 class TestRetainedObjectInfo : public v8::RetainedObjectInfo { | 387 class TestRetainedObjectInfo : public v8::RetainedObjectInfo { |
| 420 public: | 388 public: |
| 421 TestRetainedObjectInfo() : has_been_disposed_(false) {} | 389 TestRetainedObjectInfo() : has_been_disposed_(false) {} |
| 422 | 390 |
| 423 bool has_been_disposed() { return has_been_disposed_; } | 391 bool has_been_disposed() { return has_been_disposed_; } |
| 424 | 392 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 435 | 403 |
| 436 virtual const char* GetLabel() { return "whatever"; } | 404 virtual const char* GetLabel() { return "whatever"; } |
| 437 | 405 |
| 438 private: | 406 private: |
| 439 bool has_been_disposed_; | 407 bool has_been_disposed_; |
| 440 }; | 408 }; |
| 441 | 409 |
| 442 | 410 |
| 443 TEST(EmptyObjectGroups) { | 411 TEST(EmptyObjectGroups) { |
| 444 CcTest::InitializeVM(); | 412 CcTest::InitializeVM(); |
| 445 GlobalHandles* global_handles = Isolate::Current()->global_handles(); | 413 GlobalHandles* global_handles = CcTest::i_isolate()->global_handles(); |
| 446 | 414 |
| 447 v8::HandleScope handle_scope(CcTest::isolate()); | 415 v8::HandleScope handle_scope(CcTest::isolate()); |
| 448 | 416 |
| 449 Handle<Object> object = | 417 Handle<Object> object = global_handles->Create( |
| 450 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); | 418 CcTest::heap()->AllocateFixedArray(1)->ToObjectChecked()); |
| 451 | 419 |
| 452 TestRetainedObjectInfo info; | 420 TestRetainedObjectInfo info; |
| 453 global_handles->AddObjectGroup(NULL, 0, &info); | 421 global_handles->AddObjectGroup(NULL, 0, &info); |
| 454 ASSERT(info.has_been_disposed()); | 422 ASSERT(info.has_been_disposed()); |
| 455 | 423 |
| 456 global_handles->AddImplicitReferences( | 424 global_handles->AddImplicitReferences( |
| 457 Handle<HeapObject>::cast(object).location(), NULL, 0); | 425 Handle<HeapObject>::cast(object).location(), NULL, 0); |
| 458 } | 426 } |
| 459 | 427 |
| 460 | 428 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 | 550 |
| 583 | 551 |
| 584 TEST(RegressJoinThreadsOnIsolateDeinit) { | 552 TEST(RegressJoinThreadsOnIsolateDeinit) { |
| 585 intptr_t size_limit = ShortLivingIsolate() * 2; | 553 intptr_t size_limit = ShortLivingIsolate() * 2; |
| 586 for (int i = 0; i < 10; i++) { | 554 for (int i = 0; i < 10; i++) { |
| 587 CHECK_GT(size_limit, ShortLivingIsolate()); | 555 CHECK_GT(size_limit, ShortLivingIsolate()); |
| 588 } | 556 } |
| 589 } | 557 } |
| 590 | 558 |
| 591 #endif // __linux__ and !USE_SIMULATOR | 559 #endif // __linux__ and !USE_SIMULATOR |
| OLD | NEW |