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

Unified Diff: test/cctest/heap/test-spaces.cc

Issue 2793033004: Revert of [heap] Fix CompactionSpace test and move to unittests (Closed)
Patch Set: Created 3 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
« no previous file with comments | « src/heap/spaces.h ('k') | test/unittests/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/heap/test-spaces.cc
diff --git a/test/cctest/heap/test-spaces.cc b/test/cctest/heap/test-spaces.cc
index 63f962704801397ce98fd32fba9292b9168db112..ccee69efbc5b66f39b9f2830be9067ac80a18614 100644
--- a/test/cctest/heap/test-spaces.cc
+++ b/test/cctest/heap/test-spaces.cc
@@ -401,6 +401,53 @@
delete memory_allocator;
}
+
+TEST(CompactionSpace) {
+ Isolate* isolate = CcTest::i_isolate();
+ Heap* heap = isolate->heap();
+ MemoryAllocator* memory_allocator = new MemoryAllocator(isolate);
+ CHECK(memory_allocator != nullptr);
+ CHECK(memory_allocator->SetUp(heap->MaxReserved(), heap->MaxExecutableSize(),
+ 0));
+ TestMemoryAllocatorScope test_scope(isolate, memory_allocator);
+
+ CompactionSpace* compaction_space =
+ new CompactionSpace(heap, OLD_SPACE, NOT_EXECUTABLE);
+ CHECK(compaction_space != NULL);
+ CHECK(compaction_space->SetUp());
+
+ OldSpace* old_space = new OldSpace(heap, OLD_SPACE, NOT_EXECUTABLE);
+ CHECK(old_space != NULL);
+ CHECK(old_space->SetUp());
+
+ // Cannot loop until "Available()" since we initially have 0 bytes available
+ // and would thus neither grow, nor be able to allocate an object.
+ const int kNumObjects = 100;
+ const int kNumObjectsPerPage =
+ compaction_space->AreaSize() / kMaxRegularHeapObjectSize;
+ const int kExpectedPages =
+ (kNumObjects + kNumObjectsPerPage - 1) / kNumObjectsPerPage;
+ for (int i = 0; i < kNumObjects; i++) {
+ compaction_space->AllocateRawUnaligned(kMaxRegularHeapObjectSize)
+ .ToObjectChecked();
+ }
+ int pages_in_old_space = old_space->CountTotalPages();
+ int pages_in_compaction_space = compaction_space->CountTotalPages();
+ CHECK_EQ(pages_in_compaction_space, kExpectedPages);
+ CHECK_LE(pages_in_old_space, 1);
+
+ old_space->MergeCompactionSpace(compaction_space);
+ CHECK_EQ(old_space->CountTotalPages(),
+ pages_in_old_space + pages_in_compaction_space);
+
+ delete compaction_space;
+ delete old_space;
+
+ memory_allocator->TearDown();
+ delete memory_allocator;
+}
+
+
TEST(LargeObjectSpace) {
// This test does not initialize allocated objects, which confuses the
// incremental marker.
« no previous file with comments | « src/heap/spaces.h ('k') | test/unittests/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698