| Index: Source/platform/heap/HeapTest.cpp
|
| diff --git a/Source/platform/heap/HeapTest.cpp b/Source/platform/heap/HeapTest.cpp
|
| index 44778f8909cd5c5ff70f625de72fc531c2f0fda1..f5423502b17e4977c5cd4b71a0a55a9affac76ad 100644
|
| --- a/Source/platform/heap/HeapTest.cpp
|
| +++ b/Source/platform/heap/HeapTest.cpp
|
| @@ -1903,6 +1903,37 @@ TEST(HeapTest, SimpleFinalization)
|
| EXPECT_EQ(1, SimpleFinalizedObject::s_destructorCalls);
|
| }
|
|
|
| +#if ENABLE(ASSERT) || defined(LEAK_SANITIZER) || defined(ADDRESS_SANITIZER)
|
| +TEST(HeapTest, FreelistReuse)
|
| +{
|
| + clearOutOldGarbage();
|
| +
|
| + for (int i = 0; i < 100; i++)
|
| + new IntWrapper(i);
|
| + IntWrapper* p1 = new IntWrapper(100);
|
| + Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWithSweep, Heap::ForcedGC);
|
| + // In non-production builds, we delay reusing freed memory for at least
|
| + // one GC cycle.
|
| + for (int i = 0; i < 100; i++) {
|
| + IntWrapper* p2 = new IntWrapper(i);
|
| + EXPECT_NE(p1, p2);
|
| + }
|
| +
|
| + Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWithSweep, Heap::ForcedGC);
|
| + Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWithSweep, Heap::ForcedGC);
|
| + // Now the freed memory in the first GC should be reused.
|
| + bool reusedMemoryFound = false;
|
| + for (int i = 0; i < 10000; i++) {
|
| + IntWrapper* p2 = new IntWrapper(i);
|
| + if (p1 == p2) {
|
| + reusedMemoryFound = true;
|
| + break;
|
| + }
|
| + }
|
| + EXPECT_TRUE(reusedMemoryFound);
|
| +}
|
| +#endif
|
| +
|
| #if ENABLE(LAZY_SWEEPING)
|
| TEST(HeapTest, LazySweepingPages)
|
| {
|
| @@ -1925,11 +1956,22 @@ TEST(HeapTest, LazySweepingLargeObjectPages)
|
| {
|
| clearOutOldGarbage();
|
|
|
| + // Create free lists that can be reused for IntWrappers created in
|
| + // LargeHeapObject::create().
|
| + Persistent<IntWrapper> p1 = new IntWrapper(1);
|
| + for (int i = 0; i < 100; i++) {
|
| + new IntWrapper(i);
|
| + }
|
| + Persistent<IntWrapper> p2 = new IntWrapper(2);
|
| + Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWithSweep, Heap::ForcedGC);
|
| + Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWithSweep, Heap::ForcedGC);
|
| +
|
| LargeHeapObject::s_destructorCalls = 0;
|
| EXPECT_EQ(0, LargeHeapObject::s_destructorCalls);
|
| for (int i = 0; i < 10; i++)
|
| LargeHeapObject::create();
|
| Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWithoutSweep, Heap::ForcedGC);
|
| + EXPECT_EQ(0, LargeHeapObject::s_destructorCalls);
|
| for (int i = 0; i < 10; i++) {
|
| LargeHeapObject::create();
|
| EXPECT_EQ(i + 1, LargeHeapObject::s_destructorCalls);
|
|
|