| 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" |
| 11 #include "src/heap/mark-compact.h" | 11 #include "src/heap/mark-compact.h" |
| 12 #include "src/isolate.h" | 12 #include "src/isolate.h" |
| 13 | 13 |
| 14 | 14 |
| 15 namespace v8 { | 15 namespace v8 { |
| 16 namespace internal { | 16 namespace internal { |
| 17 | 17 |
| 18 static int LenFromSize(int size) { | 18 static int LenFromSize(int size) { |
| 19 return (size - i::FixedArray::kHeaderSize) / i::kPointerSize; | 19 return (size - FixedArray::kHeaderSize) / kPointerSize; |
| 20 } | 20 } |
| 21 | 21 |
| 22 | 22 |
| 23 static inline void CreatePadding(i::Heap* heap, int padding_size, | 23 static inline std::vector<Handle<FixedArray>> CreatePadding( |
| 24 i::PretenureFlag tenure) { | 24 Heap* heap, int padding_size, PretenureFlag tenure, |
| 25 const int max_number_of_objects = 20; | 25 int object_size = Page::kMaxRegularHeapObjectSize) { |
| 26 v8::internal::Handle<v8::internal::FixedArray> | 26 std::vector<Handle<FixedArray>> handles; |
| 27 big_objects[max_number_of_objects]; | 27 Isolate* isolate = heap->isolate(); |
| 28 i::Isolate* isolate = heap->isolate(); | |
| 29 int allocate_memory; | 28 int allocate_memory; |
| 30 int length; | 29 int length; |
| 31 int free_memory = padding_size; | 30 int free_memory = padding_size; |
| 32 if (tenure == i::TENURED) { | 31 if (tenure == i::TENURED) { |
| 33 int current_free_memory = | 32 heap->old_space()->EmptyAllocationInfo(); |
| 34 static_cast<int>(*heap->old_space()->allocation_limit_address() - | 33 int overall_free_memory = static_cast<int>(heap->old_space()->Available()); |
| 35 *heap->old_space()->allocation_top_address()); | 34 CHECK(padding_size <= overall_free_memory || overall_free_memory == 0); |
| 36 CHECK(padding_size <= current_free_memory || current_free_memory == 0); | |
| 37 } else { | 35 } else { |
| 38 heap->new_space()->DisableInlineAllocationSteps(); | 36 heap->new_space()->DisableInlineAllocationSteps(); |
| 39 int current_free_memory = | 37 int overall_free_memory = |
| 40 static_cast<int>(*heap->new_space()->allocation_limit_address() - | 38 static_cast<int>(*heap->new_space()->allocation_limit_address() - |
| 41 *heap->new_space()->allocation_top_address()); | 39 *heap->new_space()->allocation_top_address()); |
| 42 CHECK(padding_size <= current_free_memory || current_free_memory == 0); | 40 CHECK(padding_size <= overall_free_memory || overall_free_memory == 0); |
| 43 } | 41 } |
| 44 for (int i = 0; i < max_number_of_objects && free_memory > 0; i++) { | 42 while (free_memory > 0) { |
| 45 if (free_memory > i::Page::kMaxRegularHeapObjectSize) { | 43 if (free_memory > object_size) { |
| 46 allocate_memory = i::Page::kMaxRegularHeapObjectSize; | 44 allocate_memory = object_size; |
| 47 length = LenFromSize(allocate_memory); | 45 length = LenFromSize(allocate_memory); |
| 48 } else { | 46 } else { |
| 49 allocate_memory = free_memory; | 47 allocate_memory = free_memory; |
| 50 length = LenFromSize(allocate_memory); | 48 length = LenFromSize(allocate_memory); |
| 51 if (length <= 0) { | 49 if (length <= 0) { |
| 52 // Not enough room to create another fixed array. Let's create a filler. | 50 // Not enough room to create another fixed array. Let's create a filler. |
| 53 heap->CreateFillerObjectAt(*heap->old_space()->allocation_top_address(), | 51 heap->CreateFillerObjectAt(*heap->old_space()->allocation_top_address(), |
| 54 free_memory); | 52 free_memory); |
| 55 break; | 53 break; |
| 56 } | 54 } |
| 57 } | 55 } |
| 58 big_objects[i] = isolate->factory()->NewFixedArray(length, tenure); | 56 handles.push_back(isolate->factory()->NewFixedArray(length, tenure)); |
| 59 CHECK((tenure == i::NOT_TENURED && heap->InNewSpace(*big_objects[i])) || | 57 CHECK((tenure == NOT_TENURED && heap->InNewSpace(*handles.back())) || |
| 60 (tenure == i::TENURED && heap->InOldSpace(*big_objects[i]))); | 58 (tenure == TENURED && heap->InOldSpace(*handles.back()))); |
| 61 free_memory -= allocate_memory; | 59 free_memory -= allocate_memory; |
| 62 } | 60 } |
| 61 return handles; |
| 63 } | 62 } |
| 64 | 63 |
| 65 | 64 |
| 66 // Helper function that simulates a full new-space in the heap. | 65 // Helper function that simulates a full new-space in the heap. |
| 67 static inline bool FillUpOnePage(v8::internal::NewSpace* space) { | 66 static inline bool FillUpOnePage(v8::internal::NewSpace* space) { |
| 68 space->DisableInlineAllocationSteps(); | 67 space->DisableInlineAllocationSteps(); |
| 69 int space_remaining = static_cast<int>(*space->allocation_limit_address() - | 68 int space_remaining = static_cast<int>(*space->allocation_limit_address() - |
| 70 *space->allocation_top_address()); | 69 *space->allocation_top_address()); |
| 71 if (space_remaining == 0) return false; | 70 if (space_remaining == 0) return false; |
| 72 CreatePadding(space->heap(), space_remaining, i::NOT_TENURED); | 71 CreatePadding(space->heap(), space_remaining, i::NOT_TENURED); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 marking->FinalizeIncrementally(); | 128 marking->FinalizeIncrementally(); |
| 130 } | 129 } |
| 131 } | 130 } |
| 132 CHECK(marking->IsComplete()); | 131 CHECK(marking->IsComplete()); |
| 133 } | 132 } |
| 134 | 133 |
| 135 } // namespace internal | 134 } // namespace internal |
| 136 } // namespace v8 | 135 } // namespace v8 |
| 137 | 136 |
| 138 #endif // HEAP_UTILS_H_ | 137 #endif // HEAP_UTILS_H_ |
| OLD | NEW |