| 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 17 matching lines...) Expand all Loading... |
| 28 int allocate_memory; | 28 int allocate_memory; |
| 29 int length; | 29 int length; |
| 30 int free_memory = padding_size; | 30 int free_memory = padding_size; |
| 31 if (tenure == i::TENURED) { | 31 if (tenure == i::TENURED) { |
| 32 heap->old_space()->EmptyAllocationInfo(); | 32 heap->old_space()->EmptyAllocationInfo(); |
| 33 int overall_free_memory = static_cast<int>(heap->old_space()->Available()); | 33 int overall_free_memory = static_cast<int>(heap->old_space()->Available()); |
| 34 CHECK(padding_size <= overall_free_memory || overall_free_memory == 0); | 34 CHECK(padding_size <= overall_free_memory || overall_free_memory == 0); |
| 35 } else { | 35 } else { |
| 36 heap->new_space()->DisableInlineAllocationSteps(); | 36 heap->new_space()->DisableInlineAllocationSteps(); |
| 37 int overall_free_memory = | 37 int overall_free_memory = |
| 38 static_cast<int>(*heap->new_space()->allocation_limit_address() - | 38 static_cast<int>(heap->new_space()->limit() - heap->new_space()->top()); |
| 39 *heap->new_space()->allocation_top_address()); | |
| 40 CHECK(padding_size <= overall_free_memory || overall_free_memory == 0); | 39 CHECK(padding_size <= overall_free_memory || overall_free_memory == 0); |
| 41 } | 40 } |
| 42 while (free_memory > 0) { | 41 while (free_memory > 0) { |
| 43 if (free_memory > object_size) { | 42 if (free_memory > object_size) { |
| 44 allocate_memory = object_size; | 43 allocate_memory = object_size; |
| 45 length = LenFromSize(allocate_memory); | 44 length = LenFromSize(allocate_memory); |
| 46 } else { | 45 } else { |
| 47 allocate_memory = free_memory; | 46 allocate_memory = free_memory; |
| 48 length = LenFromSize(allocate_memory); | 47 length = LenFromSize(allocate_memory); |
| 49 if (length <= 0) { | 48 if (length <= 0) { |
| 50 // Not enough room to create another fixed array. Let's create a filler. | 49 // Not enough room to create another fixed array. Let's create a filler. |
| 51 heap->CreateFillerObjectAt(*heap->old_space()->allocation_top_address(), | 50 if (tenure == i::TENURED) { |
| 52 free_memory, ClearRecordedSlots::kNo); | 51 heap->CreateFillerObjectAt(heap->old_space()->top(), free_memory, |
| 52 ClearRecordedSlots::kNo); |
| 53 } else { |
| 54 heap->CreateFillerObjectAt(heap->new_space()->top(), free_memory, |
| 55 ClearRecordedSlots::kNo); |
| 56 } |
| 53 break; | 57 break; |
| 54 } | 58 } |
| 55 } | 59 } |
| 56 handles.push_back(isolate->factory()->NewFixedArray(length, tenure)); | 60 handles.push_back(isolate->factory()->NewFixedArray(length, tenure)); |
| 57 CHECK((tenure == NOT_TENURED && heap->InNewSpace(*handles.back())) || | 61 CHECK((tenure == NOT_TENURED && heap->InNewSpace(*handles.back())) || |
| 58 (tenure == TENURED && heap->InOldSpace(*handles.back()))); | 62 (tenure == TENURED && heap->InOldSpace(*handles.back()))); |
| 59 free_memory -= allocate_memory; | 63 free_memory -= allocate_memory; |
| 60 } | 64 } |
| 61 return handles; | 65 return handles; |
| 62 } | 66 } |
| 63 | 67 |
| 64 | 68 |
| 65 // Helper function that simulates a full new-space in the heap. | 69 // Helper function that simulates a full new-space in the heap. |
| 66 static inline bool FillUpOnePage( | 70 static inline bool FillUpOnePage( |
| 67 v8::internal::NewSpace* space, | 71 v8::internal::NewSpace* space, |
| 68 std::vector<Handle<FixedArray>>* out_handles = nullptr) { | 72 std::vector<Handle<FixedArray>>* out_handles = nullptr) { |
| 69 space->DisableInlineAllocationSteps(); | 73 space->DisableInlineAllocationSteps(); |
| 70 int space_remaining = static_cast<int>(*space->allocation_limit_address() - | 74 int space_remaining = static_cast<int>(space->limit() - space->top()); |
| 71 *space->allocation_top_address()); | |
| 72 if (space_remaining == 0) return false; | 75 if (space_remaining == 0) return false; |
| 73 std::vector<Handle<FixedArray>> handles = | 76 std::vector<Handle<FixedArray>> handles = |
| 74 CreatePadding(space->heap(), space_remaining, i::NOT_TENURED); | 77 CreatePadding(space->heap(), space_remaining, i::NOT_TENURED); |
| 75 if (out_handles != nullptr) | 78 if (out_handles != nullptr) |
| 76 out_handles->insert(out_handles->end(), handles.begin(), handles.end()); | 79 out_handles->insert(out_handles->end(), handles.begin(), handles.end()); |
| 77 return true; | 80 return true; |
| 78 } | 81 } |
| 79 | 82 |
| 80 | 83 |
| 81 // Helper function that simulates a fill new-space in the heap. | 84 // Helper function that simulates a fill new-space in the heap. |
| 82 static inline void AllocateAllButNBytes( | 85 static inline void AllocateAllButNBytes( |
| 83 v8::internal::NewSpace* space, int extra_bytes, | 86 v8::internal::NewSpace* space, int extra_bytes, |
| 84 std::vector<Handle<FixedArray>>* out_handles = nullptr) { | 87 std::vector<Handle<FixedArray>>* out_handles = nullptr) { |
| 85 space->DisableInlineAllocationSteps(); | 88 space->DisableInlineAllocationSteps(); |
| 86 int space_remaining = static_cast<int>(*space->allocation_limit_address() - | 89 int space_remaining = static_cast<int>(space->limit() - space->top()); |
| 87 *space->allocation_top_address()); | |
| 88 CHECK(space_remaining >= extra_bytes); | 90 CHECK(space_remaining >= extra_bytes); |
| 89 int new_linear_size = space_remaining - extra_bytes; | 91 int new_linear_size = space_remaining - extra_bytes; |
| 90 if (new_linear_size == 0) return; | 92 if (new_linear_size == 0) return; |
| 91 std::vector<Handle<FixedArray>> handles = | 93 std::vector<Handle<FixedArray>> handles = |
| 92 CreatePadding(space->heap(), new_linear_size, i::NOT_TENURED); | 94 CreatePadding(space->heap(), new_linear_size, i::NOT_TENURED); |
| 93 if (out_handles != nullptr) | 95 if (out_handles != nullptr) |
| 94 out_handles->insert(out_handles->end(), handles.begin(), handles.end()); | 96 out_handles->insert(out_handles->end(), handles.begin(), handles.end()); |
| 95 } | 97 } |
| 96 | 98 |
| 97 static inline void FillCurrentPage( | 99 static inline void FillCurrentPage( |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 marking->FinalizeIncrementally(); | 141 marking->FinalizeIncrementally(); |
| 140 } | 142 } |
| 141 } | 143 } |
| 142 CHECK(marking->IsComplete()); | 144 CHECK(marking->IsComplete()); |
| 143 } | 145 } |
| 144 | 146 |
| 145 } // namespace internal | 147 } // namespace internal |
| 146 } // namespace v8 | 148 } // namespace v8 |
| 147 | 149 |
| 148 #endif // HEAP_UTILS_H_ | 150 #endif // HEAP_UTILS_H_ |
| OLD | NEW |