From: mstarzinger@chromium.org Date: Thu, 8 Nov 2012 09:10:53 +0000 (+0000) Subject: Add a test case for object grouping in a scavenger GC X-Git-Tag: upstream/4.7.83~15717 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=db73b0af1625f614c373c09df5b7e31bcd9165d0;p=platform%2Fupstream%2Fv8.git Add a test case for object grouping in a scavenger GC BUG=v8:2077 TEST=cctest/test-api/ApiObjectGroupsCycleForScavenger Review URL: https://codereview.chromium.org/11312123 Patch from Kentaro Hara . git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12891 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc index a4dcc54..0fb12af 100644 --- a/test/cctest/test-api.cc +++ b/test/cctest/test-api.cc @@ -2543,6 +2543,97 @@ THREADED_TEST(ApiObjectGroupsCycle) { } +THREADED_TEST(ApiObjectGroupsCycleForScavenger) { + HandleScope scope; + LocalContext env; + + WeakCallCounter counter(1234); + + Persistent g1s1; + Persistent g1s2; + Persistent g2s1; + Persistent g2s2; + Persistent g3s1; + Persistent g3s2; + + { + HandleScope scope; + g1s1 = Persistent::New(Object::New()); + g1s2 = Persistent::New(Object::New()); + g1s1.MakeWeak(reinterpret_cast(&counter), &WeakPointerCallback); + g1s2.MakeWeak(reinterpret_cast(&counter), &WeakPointerCallback); + + g2s1 = Persistent::New(Object::New()); + g2s2 = Persistent::New(Object::New()); + g2s1.MakeWeak(reinterpret_cast(&counter), &WeakPointerCallback); + g2s2.MakeWeak(reinterpret_cast(&counter), &WeakPointerCallback); + + g3s1 = Persistent::New(Object::New()); + g3s2 = Persistent::New(Object::New()); + g3s1.MakeWeak(reinterpret_cast(&counter), &WeakPointerCallback); + g3s2.MakeWeak(reinterpret_cast(&counter), &WeakPointerCallback); + } + + // Make a root. + Persistent root = Persistent::New(g1s1); + root.MarkPartiallyDependent(); + + // Connect groups. We're building the following cycle: + // G1: { g1s1, g2s1 }, g1s1 implicitly references g2s1, ditto for other + // groups. + { + g1s1.MarkPartiallyDependent(); + g1s2.MarkPartiallyDependent(); + g2s1.MarkPartiallyDependent(); + g2s2.MarkPartiallyDependent(); + g3s1.MarkPartiallyDependent(); + g3s2.MarkPartiallyDependent(); + Persistent g1_objects[] = { g1s1, g1s2 }; + Persistent g2_objects[] = { g2s1, g2s2 }; + Persistent g3_objects[] = { g3s1, g3s2 }; + V8::AddObjectGroup(g1_objects, 2); + g1s1->Set(v8_str("x"), g2s1); + V8::AddObjectGroup(g2_objects, 2); + g2s1->Set(v8_str("x"), g3s1); + V8::AddObjectGroup(g3_objects, 2); + g3s1->Set(v8_str("x"), g1s1); + } + + HEAP->CollectGarbage(i::NEW_SPACE); + + // All objects should be alive. + CHECK_EQ(0, counter.NumberOfWeakCalls()); + + // Weaken the root. + root.MakeWeak(reinterpret_cast(&counter), &WeakPointerCallback); + root.MarkPartiallyDependent(); + + // Groups are deleted, rebuild groups. + { + g1s1.MarkPartiallyDependent(); + g1s2.MarkPartiallyDependent(); + g2s1.MarkPartiallyDependent(); + g2s2.MarkPartiallyDependent(); + g3s1.MarkPartiallyDependent(); + g3s2.MarkPartiallyDependent(); + Persistent g1_objects[] = { g1s1, g1s2 }; + Persistent g2_objects[] = { g2s1, g2s2 }; + Persistent g3_objects[] = { g3s1, g3s2 }; + V8::AddObjectGroup(g1_objects, 2); + g1s1->Set(v8_str("x"), g2s1); + V8::AddObjectGroup(g2_objects, 2); + g2s1->Set(v8_str("x"), g3s1); + V8::AddObjectGroup(g3_objects, 2); + g3s1->Set(v8_str("x"), g1s1); + } + + HEAP->CollectGarbage(i::NEW_SPACE); + + // All objects should be gone. 7 global handles in total. + CHECK_EQ(7, counter.NumberOfWeakCalls()); +} + + THREADED_TEST(ScriptException) { v8::HandleScope scope; LocalContext env;