| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef HEAP_UTILS_H_ | 5 #ifndef HEAP_UTILS_H_ |
| 6 #define HEAP_UTILS_H_ | 6 #define HEAP_UTILS_H_ |
| 7 | 7 |
| 8 #include "src/factory.h" | 8 #include "src/factory.h" |
| 9 #include "src/heap/heap-inl.h" | 9 #include "src/heap/heap-inl.h" |
| 10 #include "src/heap/incremental-marking.h" | 10 #include "src/heap/incremental-marking.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 handles.push_back(isolate->factory()->NewFixedArray(length, tenure)); | 56 handles.push_back(isolate->factory()->NewFixedArray(length, tenure)); |
| 57 CHECK((tenure == NOT_TENURED && heap->InNewSpace(*handles.back())) || | 57 CHECK((tenure == NOT_TENURED && heap->InNewSpace(*handles.back())) || |
| 58 (tenure == TENURED && heap->InOldSpace(*handles.back()))); | 58 (tenure == TENURED && heap->InOldSpace(*handles.back()))); |
| 59 free_memory -= allocate_memory; | 59 free_memory -= allocate_memory; |
| 60 } | 60 } |
| 61 return handles; | 61 return handles; |
| 62 } | 62 } |
| 63 | 63 |
| 64 | 64 |
| 65 // Helper function that simulates a full new-space in the heap. | 65 // Helper function that simulates a full new-space in the heap. |
| 66 static inline bool FillUpOnePage(v8::internal::NewSpace* space) { | 66 static inline bool FillUpOnePage( |
| 67 v8::internal::NewSpace* space, |
| 68 std::vector<Handle<FixedArray>>* out_handles = nullptr) { |
| 67 space->DisableInlineAllocationSteps(); | 69 space->DisableInlineAllocationSteps(); |
| 68 int space_remaining = static_cast<int>(*space->allocation_limit_address() - | 70 int space_remaining = static_cast<int>(*space->allocation_limit_address() - |
| 69 *space->allocation_top_address()); | 71 *space->allocation_top_address()); |
| 70 if (space_remaining == 0) return false; | 72 if (space_remaining == 0) return false; |
| 71 CreatePadding(space->heap(), space_remaining, i::NOT_TENURED); | 73 std::vector<Handle<FixedArray>> handles = |
| 74 CreatePadding(space->heap(), space_remaining, i::NOT_TENURED); |
| 75 if (out_handles != nullptr) |
| 76 out_handles->insert(out_handles->end(), handles.begin(), handles.end()); |
| 72 return true; | 77 return true; |
| 73 } | 78 } |
| 74 | 79 |
| 75 | 80 |
| 76 // Helper function that simulates a fill new-space in the heap. | 81 // Helper function that simulates a fill new-space in the heap. |
| 77 static inline void AllocateAllButNBytes(v8::internal::NewSpace* space, | 82 static inline void AllocateAllButNBytes( |
| 78 int extra_bytes) { | 83 v8::internal::NewSpace* space, int extra_bytes, |
| 84 std::vector<Handle<FixedArray>>* out_handles = nullptr) { |
| 79 space->DisableInlineAllocationSteps(); | 85 space->DisableInlineAllocationSteps(); |
| 80 int space_remaining = static_cast<int>(*space->allocation_limit_address() - | 86 int space_remaining = static_cast<int>(*space->allocation_limit_address() - |
| 81 *space->allocation_top_address()); | 87 *space->allocation_top_address()); |
| 82 CHECK(space_remaining >= extra_bytes); | 88 CHECK(space_remaining >= extra_bytes); |
| 83 int new_linear_size = space_remaining - extra_bytes; | 89 int new_linear_size = space_remaining - extra_bytes; |
| 84 if (new_linear_size == 0) return; | 90 if (new_linear_size == 0) return; |
| 85 CreatePadding(space->heap(), new_linear_size, i::NOT_TENURED); | 91 std::vector<Handle<FixedArray>> handles = |
| 92 CreatePadding(space->heap(), new_linear_size, i::NOT_TENURED); |
| 93 if (out_handles != nullptr) |
| 94 out_handles->insert(out_handles->end(), handles.begin(), handles.end()); |
| 86 } | 95 } |
| 87 | 96 |
| 88 | 97 static inline void FillCurrentPage( |
| 89 static inline void FillCurrentPage(v8::internal::NewSpace* space) { | 98 v8::internal::NewSpace* space, |
| 90 AllocateAllButNBytes(space, 0); | 99 std::vector<Handle<FixedArray>>* out_handles = nullptr) { |
| 100 AllocateAllButNBytes(space, 0, out_handles); |
| 91 } | 101 } |
| 92 | 102 |
| 93 | 103 static inline void SimulateFullSpace( |
| 94 static inline void SimulateFullSpace(v8::internal::NewSpace* space) { | 104 v8::internal::NewSpace* space, |
| 95 FillCurrentPage(space); | 105 std::vector<Handle<FixedArray>>* out_handles = nullptr) { |
| 96 while (FillUpOnePage(space)) { | 106 FillCurrentPage(space, out_handles); |
| 107 while (FillUpOnePage(space, out_handles) || space->AddFreshPage()) { |
| 97 } | 108 } |
| 98 } | 109 } |
| 99 | 110 |
| 100 | 111 |
| 101 // Helper function that simulates a full old-space in the heap. | 112 // Helper function that simulates a full old-space in the heap. |
| 102 static inline void SimulateFullSpace(v8::internal::PagedSpace* space) { | 113 static inline void SimulateFullSpace(v8::internal::PagedSpace* space) { |
| 103 space->EmptyAllocationInfo(); | 114 space->EmptyAllocationInfo(); |
| 104 space->ResetFreeList(); | 115 space->ResetFreeList(); |
| 105 space->ClearStats(); | 116 space->ClearStats(); |
| 106 } | 117 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 128 marking->FinalizeIncrementally(); | 139 marking->FinalizeIncrementally(); |
| 129 } | 140 } |
| 130 } | 141 } |
| 131 CHECK(marking->IsComplete()); | 142 CHECK(marking->IsComplete()); |
| 132 } | 143 } |
| 133 | 144 |
| 134 } // namespace internal | 145 } // namespace internal |
| 135 } // namespace v8 | 146 } // namespace v8 |
| 136 | 147 |
| 137 #endif // HEAP_UTILS_H_ | 148 #endif // HEAP_UTILS_H_ |
| OLD | NEW |