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

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

Issue 1176003002: Oilpan: Defer reusing freed memory for one GC cycle (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 | « Source/platform/heap/Heap.cpp ('k') | no next file » | 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 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);
« no previous file with comments | « Source/platform/heap/Heap.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698