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

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

Issue 1098953006: Oilpan: Support polymorphic objects in HeapVectorBackings (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 8 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/platform/heap/HeapTest.cpp
diff --git a/Source/platform/heap/HeapTest.cpp b/Source/platform/heap/HeapTest.cpp
index 2773f740f33aa9c1446351464be889b14a23a87f..6ab59b333557b5d238ebb0b8d90b1fe790308be8 100644
--- a/Source/platform/heap/HeapTest.cpp
+++ b/Source/platform/heap/HeapTest.cpp
@@ -3943,6 +3943,26 @@ public:
int InlinedVectorObject::s_destructorCalls = 0;
+class InlinedVectorObjectWithVtable {
+ ALLOW_ONLY_INLINE_ALLOCATION();
+public:
+ InlinedVectorObjectWithVtable()
+ {
+ }
+ ~InlinedVectorObjectWithVtable()
+ {
+ s_destructorCalls++;
+ }
+ virtual void virtualMethod() { }
+ DEFINE_INLINE_TRACE()
+ {
+ }
+
+ static int s_destructorCalls;
+};
+
+int InlinedVectorObjectWithVtable::s_destructorCalls = 0;
+
} // namespace blink
WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::InlinedVectorObject);
@@ -3975,6 +3995,32 @@ private:
HeapVector<InlinedVectorObject, 2> m_vector3;
};
+class InlinedVectorObjectWithVtableWrapper final : public GarbageCollectedFinalized<InlinedVectorObjectWithVtableWrapper> {
+public:
+ InlinedVectorObjectWithVtableWrapper()
+ {
+ InlinedVectorObjectWithVtable i1, i2;
+ m_vector1.append(i1);
+ m_vector1.append(i2);
+ m_vector2.append(i1);
+ m_vector2.append(i2); // This allocates an out-of-line buffer.
+ m_vector3.append(i1);
+ m_vector3.append(i2);
+ }
+
+ DEFINE_INLINE_TRACE()
+ {
+ visitor->trace(m_vector1);
+ visitor->trace(m_vector2);
+ visitor->trace(m_vector3);
+ }
+
+private:
+ HeapVector<InlinedVectorObjectWithVtable> m_vector1;
+ HeapVector<InlinedVectorObjectWithVtable, 1> m_vector2;
+ HeapVector<InlinedVectorObjectWithVtable, 2> m_vector3;
+};
+
TEST(HeapTest, VectorDestructors)
{
clearOutOldGarbage();
@@ -4022,6 +4068,49 @@ TEST(HeapTest, VectorDestructors)
EXPECT_LE(8, InlinedVectorObject::s_destructorCalls);
}
+TEST(HeapTest, VectorDestructorsWithVtable)
+{
+ clearOutOldGarbage();
+ InlinedVectorObjectWithVtable::s_destructorCalls = 0;
+ {
+ HeapVector<InlinedVectorObjectWithVtable> vector;
+ InlinedVectorObjectWithVtable i1, i2;
+ vector.append(i1);
+ vector.append(i2);
+ }
+ Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWithSweep, Heap::ForcedGC);
+ EXPECT_EQ(4, InlinedVectorObjectWithVtable::s_destructorCalls);
+
+ InlinedVectorObjectWithVtable::s_destructorCalls = 0;
+ {
+ HeapVector<InlinedVectorObjectWithVtable, 1> vector;
+ InlinedVectorObjectWithVtable i1, i2;
+ vector.append(i1);
+ vector.append(i2); // This allocates an out-of-line buffer.
+ }
+ Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWithSweep, Heap::ForcedGC);
+ EXPECT_EQ(5, InlinedVectorObjectWithVtable::s_destructorCalls);
+
+ InlinedVectorObjectWithVtable::s_destructorCalls = 0;
+ {
+ HeapVector<InlinedVectorObjectWithVtable, 2> vector;
+ InlinedVectorObjectWithVtable i1, i2;
+ vector.append(i1);
+ vector.append(i2);
+ }
+ Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWithSweep, Heap::ForcedGC);
+ EXPECT_EQ(4, InlinedVectorObjectWithVtable::s_destructorCalls);
+
+ InlinedVectorObjectWithVtable::s_destructorCalls = 0;
+ {
+ new InlinedVectorObjectWithVtableWrapper();
+ Heap::collectGarbage(ThreadState::HeapPointersOnStack, ThreadState::GCWithSweep, Heap::ForcedGC);
+ EXPECT_EQ(3, InlinedVectorObjectWithVtable::s_destructorCalls);
+ }
+ Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWithSweep, Heap::ForcedGC);
+ EXPECT_EQ(9, InlinedVectorObjectWithVtable::s_destructorCalls);
+}
+
template<typename Set>
void rawPtrInHashHelper()
{
« no previous file with comments | « Source/platform/heap/Heap.cpp ('k') | Source/wtf/Vector.h » ('j') | Source/wtf/Vector.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698