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

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
Index: Source/heap/tests/HeapTest.cpp
diff --git a/Source/heap/tests/HeapTest.cpp b/Source/heap/tests/HeapTest.cpp
index c1bd56f8db226ecb9217606d9af3223584053420..c7776ee5438f151f38e4966f70df4a061ce64ec0 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,56 @@ 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.
+ void* objects[] = { };
+ RefCountedHeapAllocatedHandleVisitor visitor(0, objects);
+ PersistentBase::visitRoots(&visitor);
+ ASSERT_TRUE(visitor.validate());
+
+ {
+ RefPtr<RefCountedAndHeapAllocated> object1(handle1.raw());
+ RefPtr<RefCountedAndHeapAllocated> object2(handle2.raw());
+ 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);
+ }
+ Heap::collectGarbage();
+ ASSERT_EQ(2, RefCountedAndHeapAllocated::s_destructorCalls);
+ }
+
static void markTest();
static void deepTest();
static void wideTest();
@@ -584,6 +636,11 @@ TEST(heap, RefCountedHeapAllocated)
HeapTester::refCountedHeapAllocatedTest();
}
+TEST(heap, RefCountedHeapAllocatedWithHandles)
+{
+ HeapTester::refCountedHeapAllocatedWithHandlesTest();
+}
+
TEST(heap, Mark)
{
HeapTester::markTest();
« Source/heap/Heap.h ('K') | « Source/heap/Heap.h ('k') | Source/wtf/RefCounted.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698