Chromium Code Reviews| Index: test/cctest/test-spaces.cc |
| diff --git a/test/cctest/test-spaces.cc b/test/cctest/test-spaces.cc |
| index 520a0bd877f9588244fb889c563aecf352c40df7..2fbfd8a3c26982701137f7637e8c6758305f3774 100644 |
| --- a/test/cctest/test-spaces.cc |
| +++ b/test/cctest/test-spaces.cc |
| @@ -441,6 +441,83 @@ TEST(CompactionSpace) { |
| } |
| +TEST(CompactionSpaceUsingExternal) { |
|
Hannes Payer (out of office)
2015/08/27 18:30:40
CompactionSpaceUsingExternalMemory
Michael Lippautz
2015/08/27 18:37:48
Done.
|
| + const int kObjectSize = 512; |
| + |
| + Isolate* isolate = CcTest::i_isolate(); |
| + Heap* heap = isolate->heap(); |
| + MemoryAllocator* allocator = new MemoryAllocator(isolate); |
| + CHECK(allocator != nullptr); |
| + CHECK(allocator->SetUp(heap->MaxReserved(), heap->MaxExecutableSize())); |
| + TestMemoryAllocatorScope test_scope(isolate, 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()); |
| + |
| + // The linear allocation area already counts as used bytes, making |
| + // exact testing impossible. |
| + heap->DisableInlineAllocation(); |
| + |
| + // Test: |
| + // * Allocate a backing store in old_space. |
| + // * Compute the number num_rest_objects of kObjectSize objects that fit into |
| + // of available memory. |
| + // kNumRestObjects. |
| + // * Add the rest of available memory to the compaction space. |
| + // * Allocate kNumRestObjects in the compaction space. |
| + // * Allocate one object more. |
| + // * Merge the compaction space and compare the expected number of pages. |
| + |
| + // Allocate a single object in old_space to initialize a backing page. |
| + old_space->AllocateRawUnaligned(kObjectSize).ToObjectChecked(); |
| + // Compute the number of objects that fit into the rest in old_space. |
| + intptr_t rest = old_space->Available(); |
| + CHECK_GT(rest, 0); |
| + intptr_t num_rest_objects = rest / kObjectSize; |
| + // After allocating num_rest_objects in compaction_space we allocate a bit |
| + // more. |
| + const intptr_t kAdditionalCompactionMemory = kObjectSize; |
| + // We expect a single old_space page. |
| + const intptr_t kExpectedInitialOldSpacePages = 1; |
| + // We expect a single additional page in compaction space because we mostly |
| + // use external memory. |
| + const intptr_t kExpectedCompactionPages = 1; |
| + // We expect two pages to be reachable from old_space in the end. |
| + const intptr_t kExpectedOldSpacePagesAfterMerge = 2; |
| + |
| + Object* chunk = old_space->AllocateRawUnaligned(rest).ToObjectChecked(); |
| + CHECK_EQ(old_space->CountTotalPages(), kExpectedInitialOldSpacePages); |
| + CHECK(chunk != nullptr); |
| + CHECK(chunk->IsHeapObject()); |
| + |
| + CHECK_EQ(compaction_space->CountTotalPages(), 0); |
| + CHECK_EQ(compaction_space->Capacity(), 0); |
| + // Make the rest of memory available for compaction. |
| + compaction_space->AddExternalMemory(HeapObject::cast(chunk)->address(), rest); |
| + CHECK_EQ(compaction_space->CountTotalPages(), 0); |
| + CHECK_EQ(compaction_space->Capacity(), rest); |
| + while (num_rest_objects-- > 0) { |
| + compaction_space->AllocateRawUnaligned(kObjectSize).ToObjectChecked(); |
| + } |
| + // We only used external memory so far. |
| + CHECK_EQ(compaction_space->CountTotalPages(), 0); |
| + // Additional allocation. |
| + compaction_space->AllocateRawUnaligned(kAdditionalCompactionMemory) |
| + .ToObjectChecked(); |
| + // Now the compaction space shouldve also acquired a page. |
| + CHECK_EQ(compaction_space->CountTotalPages(), kExpectedCompactionPages); |
| + |
| + old_space->MergeCompactionSpace(compaction_space); |
| + CHECK_EQ(old_space->CountTotalPages(), kExpectedOldSpacePagesAfterMerge); |
| +} |
| + |
| + |
| TEST(LargeObjectSpace) { |
| v8::V8::Initialize(); |