OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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 "test/cctest/heap/heap-utils.h" | 5 #include "test/cctest/heap/heap-utils.h" |
6 | 6 |
7 #include "src/factory.h" | 7 #include "src/factory.h" |
8 #include "src/heap/heap-inl.h" | 8 #include "src/heap/heap-inl.h" |
9 #include "src/heap/incremental-marking.h" | 9 #include "src/heap/incremental-marking.h" |
10 #include "src/heap/mark-compact.h" | 10 #include "src/heap/mark-compact.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 int allocate_memory; | 38 int allocate_memory; |
39 int length; | 39 int length; |
40 int free_memory = padding_size; | 40 int free_memory = padding_size; |
41 if (tenure == i::TENURED) { | 41 if (tenure == i::TENURED) { |
42 heap->old_space()->EmptyAllocationInfo(); | 42 heap->old_space()->EmptyAllocationInfo(); |
43 int overall_free_memory = static_cast<int>(heap->old_space()->Available()); | 43 int overall_free_memory = static_cast<int>(heap->old_space()->Available()); |
44 CHECK(padding_size <= overall_free_memory || overall_free_memory == 0); | 44 CHECK(padding_size <= overall_free_memory || overall_free_memory == 0); |
45 } else { | 45 } else { |
46 heap->new_space()->DisableInlineAllocationSteps(); | 46 heap->new_space()->DisableInlineAllocationSteps(); |
47 int overall_free_memory = | 47 int overall_free_memory = |
48 static_cast<int>(*heap->new_space()->allocation_limit_address() - | 48 static_cast<int>(heap->new_space()->limit() - heap->new_space()->top()); |
49 *heap->new_space()->allocation_top_address()); | |
50 CHECK(padding_size <= overall_free_memory || overall_free_memory == 0); | 49 CHECK(padding_size <= overall_free_memory || overall_free_memory == 0); |
51 } | 50 } |
52 while (free_memory > 0) { | 51 while (free_memory > 0) { |
53 if (free_memory > object_size) { | 52 if (free_memory > object_size) { |
54 allocate_memory = object_size; | 53 allocate_memory = object_size; |
55 length = FixedArrayLenFromSize(allocate_memory); | 54 length = FixedArrayLenFromSize(allocate_memory); |
56 } else { | 55 } else { |
57 allocate_memory = free_memory; | 56 allocate_memory = free_memory; |
58 length = FixedArrayLenFromSize(allocate_memory); | 57 length = FixedArrayLenFromSize(allocate_memory); |
59 if (length <= 0) { | 58 if (length <= 0) { |
60 // Not enough room to create another fixed array. Let's create a filler. | 59 // Not enough room to create another fixed array. Let's create a filler. |
61 if (free_memory > (2 * kPointerSize)) { | 60 if (free_memory > (2 * kPointerSize)) { |
62 heap->CreateFillerObjectAt( | 61 if (tenure == i::TENURED) { |
63 *heap->old_space()->allocation_top_address(), free_memory, | 62 heap->CreateFillerObjectAt(heap->old_space()->top(), free_memory, |
64 ClearRecordedSlots::kNo); | 63 ClearRecordedSlots::kNo); |
| 64 } else { |
| 65 heap->CreateFillerObjectAt(heap->new_space()->top(), free_memory, |
| 66 ClearRecordedSlots::kNo); |
| 67 } |
65 } | 68 } |
66 break; | 69 break; |
67 } | 70 } |
68 } | 71 } |
69 handles.push_back(isolate->factory()->NewFixedArray(length, tenure)); | 72 handles.push_back(isolate->factory()->NewFixedArray(length, tenure)); |
70 CHECK((tenure == NOT_TENURED && heap->InNewSpace(*handles.back())) || | 73 CHECK((tenure == NOT_TENURED && heap->InNewSpace(*handles.back())) || |
71 (tenure == TENURED && heap->InOldSpace(*handles.back()))); | 74 (tenure == TENURED && heap->InOldSpace(*handles.back()))); |
72 free_memory -= allocate_memory; | 75 free_memory -= allocate_memory; |
73 } | 76 } |
74 return handles; | 77 return handles; |
75 } | 78 } |
76 | 79 |
77 void AllocateAllButNBytes(v8::internal::NewSpace* space, int extra_bytes, | 80 void AllocateAllButNBytes(v8::internal::NewSpace* space, int extra_bytes, |
78 std::vector<Handle<FixedArray>>* out_handles) { | 81 std::vector<Handle<FixedArray>>* out_handles) { |
79 space->DisableInlineAllocationSteps(); | 82 space->DisableInlineAllocationSteps(); |
80 int space_remaining = static_cast<int>(*space->allocation_limit_address() - | 83 int space_remaining = static_cast<int>(space->limit() - space->top()); |
81 *space->allocation_top_address()); | |
82 CHECK(space_remaining >= extra_bytes); | 84 CHECK(space_remaining >= extra_bytes); |
83 int new_linear_size = space_remaining - extra_bytes; | 85 int new_linear_size = space_remaining - extra_bytes; |
84 if (new_linear_size == 0) return; | 86 if (new_linear_size == 0) return; |
85 std::vector<Handle<FixedArray>> handles = | 87 std::vector<Handle<FixedArray>> handles = |
86 heap::CreatePadding(space->heap(), new_linear_size, i::NOT_TENURED); | 88 heap::CreatePadding(space->heap(), new_linear_size, i::NOT_TENURED); |
87 if (out_handles != nullptr) | 89 if (out_handles != nullptr) |
88 out_handles->insert(out_handles->end(), handles.begin(), handles.end()); | 90 out_handles->insert(out_handles->end(), handles.begin(), handles.end()); |
89 } | 91 } |
90 | 92 |
91 void FillCurrentPage(v8::internal::NewSpace* space, | 93 void FillCurrentPage(v8::internal::NewSpace* space, |
92 std::vector<Handle<FixedArray>>* out_handles) { | 94 std::vector<Handle<FixedArray>>* out_handles) { |
93 heap::AllocateAllButNBytes(space, 0, out_handles); | 95 heap::AllocateAllButNBytes(space, 0, out_handles); |
94 } | 96 } |
95 | 97 |
96 bool FillUpOnePage(v8::internal::NewSpace* space, | 98 bool FillUpOnePage(v8::internal::NewSpace* space, |
97 std::vector<Handle<FixedArray>>* out_handles) { | 99 std::vector<Handle<FixedArray>>* out_handles) { |
98 space->DisableInlineAllocationSteps(); | 100 space->DisableInlineAllocationSteps(); |
99 int space_remaining = static_cast<int>(*space->allocation_limit_address() - | 101 int space_remaining = static_cast<int>(space->limit() - space->top()); |
100 *space->allocation_top_address()); | |
101 if (space_remaining == 0) return false; | 102 if (space_remaining == 0) return false; |
102 std::vector<Handle<FixedArray>> handles = | 103 std::vector<Handle<FixedArray>> handles = |
103 heap::CreatePadding(space->heap(), space_remaining, i::NOT_TENURED); | 104 heap::CreatePadding(space->heap(), space_remaining, i::NOT_TENURED); |
104 if (out_handles != nullptr) | 105 if (out_handles != nullptr) |
105 out_handles->insert(out_handles->end(), handles.begin(), handles.end()); | 106 out_handles->insert(out_handles->end(), handles.begin(), handles.end()); |
106 return true; | 107 return true; |
107 } | 108 } |
108 | 109 |
109 void SimulateFullSpace(v8::internal::NewSpace* space, | 110 void SimulateFullSpace(v8::internal::NewSpace* space, |
110 std::vector<Handle<FixedArray>>* out_handles) { | 111 std::vector<Handle<FixedArray>>* out_handles) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 } | 150 } |
150 } | 151 } |
151 | 152 |
152 void GcAndSweep(Heap* heap, AllocationSpace space) { | 153 void GcAndSweep(Heap* heap, AllocationSpace space) { |
153 heap->CollectGarbage(space); | 154 heap->CollectGarbage(space); |
154 if (heap->mark_compact_collector()->sweeping_in_progress()) { | 155 if (heap->mark_compact_collector()->sweeping_in_progress()) { |
155 heap->mark_compact_collector()->EnsureSweepingCompleted(); | 156 heap->mark_compact_collector()->EnsureSweepingCompleted(); |
156 } | 157 } |
157 } | 158 } |
158 | 159 |
| 160 void MakeSureNewSpaceTopIsNotDoubleAligned(i::Heap* heap) { |
| 161 intptr_t top = reinterpret_cast<intptr_t>(heap->new_space()->top()); |
| 162 if ((top & kDoubleAlignmentMaskTagged) == 0) { |
| 163 CreatePadding(heap, kDoubleSize / 2, NOT_TENURED); |
| 164 } |
| 165 } |
| 166 |
159 } // namespace heap | 167 } // namespace heap |
160 } // namespace internal | 168 } // namespace internal |
161 } // namespace v8 | 169 } // namespace v8 |
OLD | NEW |