| 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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 TEST(ObjectGroups) { | 301 TEST(ObjectGroups) { |
| 302 GlobalHandles* global_handles = Isolate::Current()->global_handles(); | 302 GlobalHandles* global_handles = Isolate::Current()->global_handles(); |
| 303 InitializeVM(); | 303 InitializeVM(); |
| 304 | 304 |
| 305 NumberOfWeakCalls = 0; | 305 NumberOfWeakCalls = 0; |
| 306 v8::HandleScope handle_scope; | 306 v8::HandleScope handle_scope; |
| 307 | 307 |
| 308 Handle<Object> g1s1 = | 308 Handle<Object> g1s1 = |
| 309 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); | 309 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
| 310 Handle<Object> g1s2 = | 310 Handle<Object> g1s2 = |
| 311 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); | 311 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
| 312 Handle<Object> g1c1 = | 312 Handle<Object> g1c1 = |
| 313 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); | 313 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
| 314 global_handles->MakeWeak(g1s1.location(), | 314 global_handles->MakeWeak(g1s1.location(), |
| 315 reinterpret_cast<void*>(1234), | 315 reinterpret_cast<void*>(1234), |
| 316 &WeakPointerCallback); | 316 &WeakPointerCallback); |
| 317 global_handles->MakeWeak(g1s2.location(), | 317 global_handles->MakeWeak(g1s2.location(), |
| 318 reinterpret_cast<void*>(1234), | 318 reinterpret_cast<void*>(1234), |
| 319 &WeakPointerCallback); | 319 &WeakPointerCallback); |
| 320 global_handles->MakeWeak(g1c1.location(), | 320 global_handles->MakeWeak(g1c1.location(), |
| 321 reinterpret_cast<void*>(1234), | 321 reinterpret_cast<void*>(1234), |
| 322 &WeakPointerCallback); | 322 &WeakPointerCallback); |
| 323 | 323 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 342 // Connect group 1 and 2, make a cycle. | 342 // Connect group 1 and 2, make a cycle. |
| 343 Handle<FixedArray>::cast(g1s2)->set(0, *g2s2); | 343 Handle<FixedArray>::cast(g1s2)->set(0, *g2s2); |
| 344 Handle<FixedArray>::cast(g2s1)->set(0, *g1s1); | 344 Handle<FixedArray>::cast(g2s1)->set(0, *g1s1); |
| 345 | 345 |
| 346 { | 346 { |
| 347 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; | 347 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; |
| 348 Object** g1_children[] = { g1c1.location() }; | 348 Object** g1_children[] = { g1c1.location() }; |
| 349 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; | 349 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; |
| 350 Object** g2_children[] = { g2c1.location() }; | 350 Object** g2_children[] = { g2c1.location() }; |
| 351 global_handles->AddObjectGroup(g1_objects, 2, NULL); | 351 global_handles->AddObjectGroup(g1_objects, 2, NULL); |
| 352 global_handles->AddImplicitReferences(HeapObject::cast(*g1s1), | 352 global_handles->AddImplicitReferences( |
| 353 g1_children, 1); | 353 Handle<HeapObject>::cast(g1s1).location(), g1_children, 1); |
| 354 global_handles->AddObjectGroup(g2_objects, 2, NULL); | 354 global_handles->AddObjectGroup(g2_objects, 2, NULL); |
| 355 global_handles->AddImplicitReferences(HeapObject::cast(*g2s2), | 355 global_handles->AddImplicitReferences( |
| 356 g2_children, 1); | 356 Handle<HeapObject>::cast(g2s2).location(), g2_children, 1); |
| 357 } | 357 } |
| 358 // Do a full GC | 358 // Do a full GC |
| 359 HEAP->CollectGarbage(OLD_POINTER_SPACE); | 359 HEAP->CollectGarbage(OLD_POINTER_SPACE); |
| 360 | 360 |
| 361 // All object should be alive. | 361 // All object should be alive. |
| 362 CHECK_EQ(0, NumberOfWeakCalls); | 362 CHECK_EQ(0, NumberOfWeakCalls); |
| 363 | 363 |
| 364 // Weaken the root. | 364 // Weaken the root. |
| 365 global_handles->MakeWeak(root.location(), | 365 global_handles->MakeWeak(root.location(), |
| 366 reinterpret_cast<void*>(1234), | 366 reinterpret_cast<void*>(1234), |
| 367 &WeakPointerCallback); | 367 &WeakPointerCallback); |
| 368 // But make children strong roots---all the objects (except for children) | 368 // But make children strong roots---all the objects (except for children) |
| 369 // should be collectable now. | 369 // should be collectable now. |
| 370 global_handles->ClearWeakness(g1c1.location()); | 370 global_handles->ClearWeakness(g1c1.location()); |
| 371 global_handles->ClearWeakness(g2c1.location()); | 371 global_handles->ClearWeakness(g2c1.location()); |
| 372 | 372 |
| 373 // Groups are deleted, rebuild groups. | 373 // Groups are deleted, rebuild groups. |
| 374 { | 374 { |
| 375 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; | 375 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; |
| 376 Object** g1_children[] = { g1c1.location() }; | 376 Object** g1_children[] = { g1c1.location() }; |
| 377 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; | 377 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; |
| 378 Object** g2_children[] = { g2c1.location() }; | 378 Object** g2_children[] = { g2c1.location() }; |
| 379 global_handles->AddObjectGroup(g1_objects, 2, NULL); | 379 global_handles->AddObjectGroup(g1_objects, 2, NULL); |
| 380 global_handles->AddImplicitReferences(HeapObject::cast(*g1s1), | 380 global_handles->AddImplicitReferences( |
| 381 g1_children, 1); | 381 Handle<HeapObject>::cast(g1s1).location(), g1_children, 1); |
| 382 global_handles->AddObjectGroup(g2_objects, 2, NULL); | 382 global_handles->AddObjectGroup(g2_objects, 2, NULL); |
| 383 global_handles->AddImplicitReferences(HeapObject::cast(*g2s2), | 383 global_handles->AddImplicitReferences( |
| 384 g2_children, 1); | 384 Handle<HeapObject>::cast(g2s2).location(), g2_children, 1); |
| 385 } | 385 } |
| 386 | 386 |
| 387 HEAP->CollectGarbage(OLD_POINTER_SPACE); | 387 HEAP->CollectGarbage(OLD_POINTER_SPACE); |
| 388 | 388 |
| 389 // All objects should be gone. 5 global handles in total. | 389 // All objects should be gone. 5 global handles in total. |
| 390 CHECK_EQ(5, NumberOfWeakCalls); | 390 CHECK_EQ(5, NumberOfWeakCalls); |
| 391 | 391 |
| 392 // And now make children weak again and collect them. | 392 // And now make children weak again and collect them. |
| 393 global_handles->MakeWeak(g1c1.location(), | 393 global_handles->MakeWeak(g1c1.location(), |
| 394 reinterpret_cast<void*>(1234), | 394 reinterpret_cast<void*>(1234), |
| 395 &WeakPointerCallback); | 395 &WeakPointerCallback); |
| 396 global_handles->MakeWeak(g2c1.location(), | 396 global_handles->MakeWeak(g2c1.location(), |
| 397 reinterpret_cast<void*>(1234), | 397 reinterpret_cast<void*>(1234), |
| 398 &WeakPointerCallback); | 398 &WeakPointerCallback); |
| 399 | 399 |
| 400 HEAP->CollectGarbage(OLD_POINTER_SPACE); | 400 HEAP->CollectGarbage(OLD_POINTER_SPACE); |
| 401 CHECK_EQ(7, NumberOfWeakCalls); | 401 CHECK_EQ(7, NumberOfWeakCalls); |
| 402 } | 402 } |
| OLD | NEW |