Chromium Code Reviews| Index: test/cctest/test-mark-compact.cc |
| diff --git a/test/cctest/test-mark-compact.cc b/test/cctest/test-mark-compact.cc |
| index 4640599aab213370a4472381d97eea011ef1e480..2c30f1960124bf3541b1fc4213c61f749f1839bc 100644 |
| --- a/test/cctest/test-mark-compact.cc |
| +++ b/test/cctest/test-mark-compact.cc |
| @@ -313,7 +313,7 @@ static void WeakPointerCallback(v8::Isolate* isolate, |
| handle.Dispose(isolate); |
| } |
| -TEST(ObjectGroups) { |
| +TEST(ObjectGroupsOldApi) { |
| FLAG_incremental_marking = false; |
| InitializeVM(); |
| GlobalHandles* global_handles = Isolate::Current()->global_handles(); |
| @@ -426,6 +426,119 @@ TEST(ObjectGroups) { |
| CHECK_EQ(7, NumberOfWeakCalls); |
| } |
| +TEST(ObjectGroups) { |
| + FLAG_incremental_marking = false; |
| + InitializeVM(); |
| + GlobalHandles* global_handles = Isolate::Current()->global_handles(); |
|
Sven Panne
2013/04/10 10:58:52
Use CcTest::isolate().
marja
2013/04/10 13:14:51
Done.
|
| + |
| + NumberOfWeakCalls = 0; |
| + v8::HandleScope handle_scope(env->GetIsolate()); |
|
Sven Panne
2013/04/10 10:58:52
Same here.
marja
2013/04/10 13:14:51
Done.
|
| + |
| + Handle<Object> g1s1 = |
| + global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
|
Sven Panne
2013/04/10 10:58:52
Use CcTest::isolate()->heap(), perhaps store this
marja
2013/04/10 13:14:51
Done.
|
| + Handle<Object> g1s2 = |
| + global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
| + Handle<Object> g1c1 = |
| + global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
| + global_handles->MakeWeak(g1s1.location(), |
| + reinterpret_cast<void*>(1234), |
| + NULL, |
| + &WeakPointerCallback); |
| + global_handles->MakeWeak(g1s2.location(), |
| + reinterpret_cast<void*>(1234), |
| + NULL, |
| + &WeakPointerCallback); |
| + global_handles->MakeWeak(g1c1.location(), |
| + reinterpret_cast<void*>(1234), |
| + NULL, |
| + &WeakPointerCallback); |
| + |
| + Handle<Object> g2s1 = |
| + global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
| + Handle<Object> g2s2 = |
| + global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
| + Handle<Object> g2c1 = |
| + global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
| + global_handles->MakeWeak(g2s1.location(), |
| + reinterpret_cast<void*>(1234), |
| + NULL, |
| + &WeakPointerCallback); |
| + global_handles->MakeWeak(g2s2.location(), |
| + reinterpret_cast<void*>(1234), |
| + NULL, |
| + &WeakPointerCallback); |
| + global_handles->MakeWeak(g2c1.location(), |
| + reinterpret_cast<void*>(1234), |
| + NULL, |
| + &WeakPointerCallback); |
| + |
| + Handle<Object> root = global_handles->Create(*g1s1); // make a root. |
| + |
| + // Connect group 1 and 2, make a cycle. |
| + Handle<FixedArray>::cast(g1s2)->set(0, *g2s2); |
| + Handle<FixedArray>::cast(g2s1)->set(0, *g1s1); |
| + |
| + { |
| + Object** g1_children[] = { g1c1.location() }; |
| + Object** g2_children[] = { g2c1.location() }; |
| + global_handles->SetObjectGroupId(g1s1.location(), v8::UniqueId(1)); |
| + global_handles->SetObjectGroupId(g1s2.location(), v8::UniqueId(1)); |
| + global_handles->AddImplicitReferences( |
| + Handle<HeapObject>::cast(g1s1).location(), g1_children, 1); |
| + global_handles->SetObjectGroupId(g2s1.location(), v8::UniqueId(2)); |
| + global_handles->SetObjectGroupId(g2s2.location(), v8::UniqueId(2)); |
| + global_handles->AddImplicitReferences( |
| + Handle<HeapObject>::cast(g2s2).location(), g2_children, 1); |
| + } |
| + // Do a full GC |
| + HEAP->CollectGarbage(OLD_POINTER_SPACE); |
| + |
| + // All object should be alive. |
| + CHECK_EQ(0, NumberOfWeakCalls); |
| + |
| + // Weaken the root. |
| + global_handles->MakeWeak(root.location(), |
| + reinterpret_cast<void*>(1234), |
| + NULL, |
| + &WeakPointerCallback); |
| + // But make children strong roots---all the objects (except for children) |
| + // should be collectable now. |
| + global_handles->ClearWeakness(g1c1.location()); |
| + global_handles->ClearWeakness(g2c1.location()); |
| + |
| + // Groups are deleted, rebuild groups. |
| + { |
| + Object** g1_children[] = { g1c1.location() }; |
| + Object** g2_children[] = { g2c1.location() }; |
| + global_handles->SetObjectGroupId(g1s1.location(), v8::UniqueId(1)); |
| + global_handles->SetObjectGroupId(g1s2.location(), v8::UniqueId(1)); |
| + global_handles->AddImplicitReferences( |
| + Handle<HeapObject>::cast(g1s1).location(), g1_children, 1); |
| + global_handles->SetObjectGroupId(g2s1.location(), v8::UniqueId(2)); |
| + global_handles->SetObjectGroupId(g2s2.location(), v8::UniqueId(2)); |
| + global_handles->AddImplicitReferences( |
| + Handle<HeapObject>::cast(g2s2).location(), g2_children, 1); |
| + } |
| + |
| + HEAP->CollectGarbage(OLD_POINTER_SPACE); |
| + |
| + // All objects should be gone. 5 global handles in total. |
| + CHECK_EQ(5, NumberOfWeakCalls); |
| + |
| + // And now make children weak again and collect them. |
| + global_handles->MakeWeak(g1c1.location(), |
| + reinterpret_cast<void*>(1234), |
| + NULL, |
| + &WeakPointerCallback); |
| + global_handles->MakeWeak(g2c1.location(), |
| + reinterpret_cast<void*>(1234), |
| + NULL, |
| + &WeakPointerCallback); |
| + |
| + HEAP->CollectGarbage(OLD_POINTER_SPACE); |
| + CHECK_EQ(7, NumberOfWeakCalls); |
| +} |
| + |
| class TestRetainedObjectInfo : public v8::RetainedObjectInfo { |
| public: |
| @@ -451,7 +564,7 @@ class TestRetainedObjectInfo : public v8::RetainedObjectInfo { |
| }; |
| -TEST(EmptyObjectGroups) { |
| +TEST(EmptyObjectGroupsOldApi) { |
| InitializeVM(); |
| GlobalHandles* global_handles = Isolate::Current()->global_handles(); |