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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/platform/heap/ThreadState.h » ('j') | Source/platform/heap/ThreadState.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 1579 matching lines...) Expand 10 before | Expand all | Expand 10 after
1590 for (int i = 0; i < 32; ++i) 1590 for (int i = 0; i < 32; ++i)
1591 LargeHeapObject::create(); 1591 LargeHeapObject::create();
1592 } 1592 }
1593 1593
1594 DEFINE_INLINE_TRACE() { } 1594 DEFINE_INLINE_TRACE() { }
1595 1595
1596 private: 1596 private:
1597 Persistent<IntWrapper>* m_wrapper; 1597 Persistent<IntWrapper>* m_wrapper;
1598 }; 1598 };
1599 1599
1600 class PreFinalizationAllocator : public GarbageCollectedFinalized<PreFinalizatio nAllocator> {
1601 USING_PRE_FINALIZER(PreFinalizationAllocator, dispose);
1602 public:
1603 PreFinalizationAllocator(Persistent<IntWrapper>* wrapper)
1604 : m_wrapper(wrapper)
1605 {
1606 ThreadState::current()->registerPreFinalizer(*this);
1607 }
1608
1609 void dispose()
1610 {
1611 for (int i = 0; i < 10; ++i)
1612 *m_wrapper = IntWrapper::create(42);
1613 for (int i = 0; i < 512; ++i)
1614 new OneKiloByteObject();
1615 for (int i = 0; i < 32; ++i)
1616 LargeHeapObject::create();
1617 }
1618
1619 DEFINE_INLINE_TRACE() { }
1620
1621 private:
1622 Persistent<IntWrapper>* m_wrapper;
1623 };
1624
1600 TEST(HeapTest, Transition) 1625 TEST(HeapTest, Transition)
1601 { 1626 {
1602 { 1627 {
1603 RefPtrWillBePersistent<TransitionRefCounted> refCounted = TransitionRefC ounted::create(); 1628 RefPtrWillBePersistent<TransitionRefCounted> refCounted = TransitionRefC ounted::create();
1604 EXPECT_EQ(1, TransitionRefCounted::s_aliveCount); 1629 EXPECT_EQ(1, TransitionRefCounted::s_aliveCount);
1605 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GC WithSweep, Heap::ForcedGC); 1630 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GC WithSweep, Heap::ForcedGC);
1606 EXPECT_EQ(1, TransitionRefCounted::s_aliveCount); 1631 EXPECT_EQ(1, TransitionRefCounted::s_aliveCount);
1607 } 1632 }
1608 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith Sweep, Heap::ForcedGC); 1633 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith Sweep, Heap::ForcedGC);
1609 EXPECT_EQ(0, TransitionRefCounted::s_aliveCount); 1634 EXPECT_EQ(0, TransitionRefCounted::s_aliveCount);
(...skipping 2686 matching lines...) Expand 10 before | Expand all | Expand 10 after
4296 // swept away and zapped later in the same sweeping phase. 4321 // swept away and zapped later in the same sweeping phase.
4297 EXPECT_EQ(42, wrapper->value()); 4322 EXPECT_EQ(42, wrapper->value());
4298 4323
4299 wrapper.clear(); 4324 wrapper.clear();
4300 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith Sweep, Heap::ForcedGC); 4325 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith Sweep, Heap::ForcedGC);
4301 EXPECT_EQ(42, IntWrapper::s_destructorCalls); 4326 EXPECT_EQ(42, IntWrapper::s_destructorCalls);
4302 EXPECT_EQ(512, OneKiloByteObject::s_destructorCalls); 4327 EXPECT_EQ(512, OneKiloByteObject::s_destructorCalls);
4303 EXPECT_EQ(32, LargeHeapObject::s_destructorCalls); 4328 EXPECT_EQ(32, LargeHeapObject::s_destructorCalls);
4304 } 4329 }
4305 4330
4331 TEST(HeapTest, AllocationDuringPrefinalizer)
4332 {
4333 clearOutOldGarbage();
4334 IntWrapper::s_destructorCalls = 0;
4335 OneKiloByteObject::s_destructorCalls = 0;
4336 LargeHeapObject::s_destructorCalls = 0;
4337
4338 Persistent<IntWrapper> wrapper;
4339 new PreFinalizationAllocator(&wrapper);
4340
4341 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith Sweep, Heap::ForcedGC);
4342 EXPECT_EQ(0, IntWrapper::s_destructorCalls);
4343 EXPECT_EQ(0, OneKiloByteObject::s_destructorCalls);
4344 EXPECT_EQ(0, LargeHeapObject::s_destructorCalls);
4345 // Check that the wrapper allocated during finalization is not
4346 // swept away and zapped later in the same sweeping phase.
4347 EXPECT_EQ(42, wrapper->value());
4348
4349 wrapper.clear();
4350 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith Sweep, Heap::ForcedGC);
4351 EXPECT_EQ(42, IntWrapper::s_destructorCalls);
sof 2015/06/18 12:18:03 Could you add a comment where the 42 IntWrappers c
haraken 2015/06/18 16:30:13 Done.
4352 EXPECT_EQ(512, OneKiloByteObject::s_destructorCalls);
4353 EXPECT_EQ(32, LargeHeapObject::s_destructorCalls);
4354 }
4355
4306 class SimpleClassWithDestructor { 4356 class SimpleClassWithDestructor {
4307 public: 4357 public:
4308 SimpleClassWithDestructor() { } 4358 SimpleClassWithDestructor() { }
4309 ~SimpleClassWithDestructor() 4359 ~SimpleClassWithDestructor()
4310 { 4360 {
4311 s_wasDestructed = true; 4361 s_wasDestructed = true;
4312 } 4362 }
4313 static bool s_wasDestructed; 4363 static bool s_wasDestructed;
4314 }; 4364 };
4315 4365
(...skipping 1808 matching lines...) Expand 10 before | Expand all | Expand 10 after
6124 { 6174 {
6125 Persistent<ClassWithMember> object = ClassWithMember::create(); 6175 Persistent<ClassWithMember> object = ClassWithMember::create();
6126 EXPECT_EQ(0, object->traceCount()); 6176 EXPECT_EQ(0, object->traceCount());
6127 TestMixinAllocatingObject* mixin = TestMixinAllocatingObject::create(object. get()); 6177 TestMixinAllocatingObject* mixin = TestMixinAllocatingObject::create(object. get());
6128 EXPECT_TRUE(mixin); 6178 EXPECT_TRUE(mixin);
6129 EXPECT_GT(object->traceCount(), 0); 6179 EXPECT_GT(object->traceCount(), 0);
6130 EXPECT_GT(mixin->traceCount(), 0); 6180 EXPECT_GT(mixin->traceCount(), 0);
6131 } 6181 }
6132 6182
6133 } // namespace blink 6183 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | Source/platform/heap/ThreadState.h » ('j') | Source/platform/heap/ThreadState.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698