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

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

Issue 1190863003: Oilpan: Allocation should be allowed in pre-finalizers (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 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 | « no previous file | Source/platform/heap/ThreadState.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/heap/HeapTest.cpp
diff --git a/Source/platform/heap/HeapTest.cpp b/Source/platform/heap/HeapTest.cpp
index 2b7c7bf243e5e9e46495205c16c421f7360469f8..d31058a26d4c83d2b8702e372d55b31eee5c8167 100644
--- a/Source/platform/heap/HeapTest.cpp
+++ b/Source/platform/heap/HeapTest.cpp
@@ -1597,6 +1597,31 @@ private:
Persistent<IntWrapper>* m_wrapper;
};
+class PreFinalizationAllocator : public GarbageCollectedFinalized<PreFinalizationAllocator> {
+ USING_PRE_FINALIZER(PreFinalizationAllocator, dispose);
+public:
+ PreFinalizationAllocator(Persistent<IntWrapper>* wrapper)
+ : m_wrapper(wrapper)
+ {
+ ThreadState::current()->registerPreFinalizer(*this);
+ }
+
+ void dispose()
+ {
+ for (int i = 0; i < 10; ++i)
+ *m_wrapper = IntWrapper::create(42);
+ for (int i = 0; i < 512; ++i)
+ new OneKiloByteObject();
+ for (int i = 0; i < 32; ++i)
+ LargeHeapObject::create();
+ }
+
+ DEFINE_INLINE_TRACE() { }
+
+private:
+ Persistent<IntWrapper>* m_wrapper;
+};
+
TEST(HeapTest, Transition)
{
{
@@ -4298,6 +4323,35 @@ TEST(HeapTest, AllocationDuringFinalization)
wrapper.clear();
Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWithSweep, Heap::ForcedGC);
+ // The 42 IntWrappers were the ones allocated in ~FinalizationAllocator
+ // and the ones allocated in LargeHeapObject.
+ EXPECT_EQ(42, IntWrapper::s_destructorCalls);
+ EXPECT_EQ(512, OneKiloByteObject::s_destructorCalls);
+ EXPECT_EQ(32, LargeHeapObject::s_destructorCalls);
+}
+
+TEST(HeapTest, AllocationDuringPrefinalizer)
+{
+ clearOutOldGarbage();
+ IntWrapper::s_destructorCalls = 0;
+ OneKiloByteObject::s_destructorCalls = 0;
+ LargeHeapObject::s_destructorCalls = 0;
+
+ Persistent<IntWrapper> wrapper;
+ new PreFinalizationAllocator(&wrapper);
+
+ Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWithSweep, Heap::ForcedGC);
+ EXPECT_EQ(0, IntWrapper::s_destructorCalls);
+ EXPECT_EQ(0, OneKiloByteObject::s_destructorCalls);
+ EXPECT_EQ(0, LargeHeapObject::s_destructorCalls);
+ // Check that the wrapper allocated during finalization is not
+ // swept away and zapped later in the same sweeping phase.
+ EXPECT_EQ(42, wrapper->value());
+
+ wrapper.clear();
+ Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWithSweep, Heap::ForcedGC);
+ // The 42 IntWrappers were the ones allocated in the pre-finalizer
+ // of PreFinalizationAllocator and the ones allocated in LargeHeapObject.
EXPECT_EQ(42, IntWrapper::s_destructorCalls);
EXPECT_EQ(512, OneKiloByteObject::s_destructorCalls);
EXPECT_EQ(32, LargeHeapObject::s_destructorCalls);
« no previous file with comments | « no previous file | Source/platform/heap/ThreadState.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698