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