| OLD | NEW |
| (Empty) |
| 1 // Copyright 2017 the V8 project authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "src/heap/heap-inl.h" | |
| 6 #include "src/heap/spaces-inl.h" | |
| 7 #include "src/isolate.h" | |
| 8 #include "test/unittests/test-utils.h" | |
| 9 | |
| 10 namespace v8 { | |
| 11 namespace internal { | |
| 12 | |
| 13 typedef TestWithIsolate SpacesTest; | |
| 14 | |
| 15 TEST_F(SpacesTest, CompactionSpaceMerge) { | |
| 16 Heap* heap = i_isolate()->heap(); | |
| 17 OldSpace* old_space = heap->old_space(); | |
| 18 EXPECT_TRUE(old_space != NULL); | |
| 19 | |
| 20 CompactionSpace* compaction_space = | |
| 21 new CompactionSpace(heap, OLD_SPACE, NOT_EXECUTABLE); | |
| 22 EXPECT_TRUE(compaction_space != NULL); | |
| 23 EXPECT_TRUE(compaction_space->SetUp()); | |
| 24 | |
| 25 // Cannot loop until "Available()" since we initially have 0 bytes available | |
| 26 // and would thus neither grow, nor be able to allocate an object. | |
| 27 const int kNumObjects = 10; | |
| 28 const int kNumObjectsPerPage = | |
| 29 compaction_space->AreaSize() / kMaxRegularHeapObjectSize; | |
| 30 const int kExpectedPages = | |
| 31 (kNumObjects + kNumObjectsPerPage - 1) / kNumObjectsPerPage; | |
| 32 for (int i = 0; i < kNumObjects; i++) { | |
| 33 HeapObject* object = | |
| 34 compaction_space->AllocateRawUnaligned(kMaxRegularHeapObjectSize) | |
| 35 .ToObjectChecked(); | |
| 36 heap->CreateFillerObjectAt(object->address(), kMaxRegularHeapObjectSize, | |
| 37 ClearRecordedSlots::kNo); | |
| 38 } | |
| 39 int pages_in_old_space = old_space->CountTotalPages(); | |
| 40 int pages_in_compaction_space = compaction_space->CountTotalPages(); | |
| 41 EXPECT_EQ(kExpectedPages, pages_in_compaction_space); | |
| 42 old_space->MergeCompactionSpace(compaction_space); | |
| 43 EXPECT_EQ(pages_in_old_space + pages_in_compaction_space, | |
| 44 old_space->CountTotalPages()); | |
| 45 | |
| 46 delete compaction_space; | |
| 47 } | |
| 48 | |
| 49 } // namespace internal | |
| 50 } // namespace v8 | |
| OLD | NEW |