Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1577)

Unified Diff: Source/heap/tests/HeapTest.cpp

Issue 16042013: [oilpan] Resurrect a loop-back persistent handle in RefCountedHeapAllocated (Closed) Base URL: svn://svn.chromium.org/blink/branches/oilpan
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/heap/Heap.h ('k') | Source/wtf/RefCounted.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/heap/tests/HeapTest.cpp
diff --git a/Source/heap/tests/HeapTest.cpp b/Source/heap/tests/HeapTest.cpp
index c1bd56f8db226ecb9217606d9af3223584053420..76e9b95c7f88a27f048ad451422d65d98973dbd4 100644
--- a/Source/heap/tests/HeapTest.cpp
+++ b/Source/heap/tests/HeapTest.cpp
@@ -348,6 +348,8 @@ public:
static void refCountedHeapAllocatedTest()
{
+ RefCountedAndHeapAllocated::s_destructorCalls = 0;
+ RefCountedAndHeapAllocated2::s_destructorCalls = 0;
{
RefPtr<RefCountedAndHeapAllocated> o1 = RefCountedAndHeapAllocated::create();
RefPtr<RefCountedAndHeapAllocated> o2 = RefCountedAndHeapAllocated::create();
@@ -367,6 +369,50 @@ public:
ASSERT_EQ(2, RefCountedAndHeapAllocated2::s_destructorCalls);
}
+ static void refCountedHeapAllocatedWithHandlesTest()
+ {
+ RefCountedAndHeapAllocated::s_destructorCalls = 0;
+ RefCountedAndHeapAllocated2::s_destructorCalls = 0;
+ {
+ HandleScope scope;
+ Handle<RefCountedAndHeapAllocated> handle1;
+ Handle<RefCountedAndHeapAllocated> handle2;
+ {
+ RefPtr<RefCountedAndHeapAllocated> object1 = RefCountedAndHeapAllocated::create();
+ RefPtr<RefCountedAndHeapAllocated> object2 = RefCountedAndHeapAllocated::create();
+ handle1 = Handle<RefCountedAndHeapAllocated>(object1.get());
+ handle2 = Handle<RefCountedAndHeapAllocated>(object2.get());
+ void* objects[2] = { object1.get(), object2.get() };
+ RefCountedHeapAllocatedHandleVisitor visitor(2, objects);
+ PersistentBase::visitRoots(&visitor);
+ ASSERT_TRUE(visitor.validate());
+
+ Heap::collectGarbage();
+ ASSERT_EQ(0, RefCountedAndHeapAllocated::s_destructorCalls);
+ }
+ Heap::collectGarbage();
+ ASSERT_EQ(0, RefCountedAndHeapAllocated::s_destructorCalls);
+
+ // At this point, the reference counts of object1 and object2 are 0.
+ // Only handle1 and handle2 keep references to object1 and object2.
Mads Ager (google) 2013/05/29 13:47:54 Maybe check that PersistentBase::visitRoots does n
+
+ {
+ RefPtr<RefCountedAndHeapAllocated> object1 = adoptRef(handle1.raw());
+ RefPtr<RefCountedAndHeapAllocated> object2 = adoptRef(handle2.raw());
+ handle1 = Handle<RefCountedAndHeapAllocated>(object1.get());
Mads Ager (google) 2013/05/29 13:47:54 These lines are just reassigning the same value to
haraken 2013/05/29 14:52:16 Good catch! I verified that PersistentBase::visitR
+ handle2 = Handle<RefCountedAndHeapAllocated>(object2.get());
+
+ Heap::collectGarbage();
+ ASSERT_EQ(0, RefCountedAndHeapAllocated::s_destructorCalls);
+ }
+
+ Heap::collectGarbage();
+ ASSERT_EQ(0, RefCountedAndHeapAllocated::s_destructorCalls);
+ }
+ Heap::collectGarbage();
+ ASSERT_EQ(2, RefCountedAndHeapAllocated::s_destructorCalls);
+ }
+
static void markTest();
static void deepTest();
static void wideTest();
@@ -584,6 +630,11 @@ TEST(heap, RefCountedHeapAllocated)
HeapTester::refCountedHeapAllocatedTest();
}
+TEST(heap, RefCountedHeapAllocatedWithHandles)
+{
+ HeapTester::refCountedHeapAllocatedWithHandlesTest();
+}
+
TEST(heap, Mark)
{
HeapTester::markTest();
« no previous file with comments | « Source/heap/Heap.h ('k') | Source/wtf/RefCounted.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698