| 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef HEAP_HEAP_UTILS_H_ |
| 6 | #define HEAP_HEAP_UTILS_H_ |
| 7 | |
| 8 | #include "src/api-inl.h" |
| 9 | #include "src/heap/heap.h" |
| 10 | |
| 11 | namespace v8 { |
| 12 | namespace internal { |
| 13 | namespace heap { |
| 14 | |
| 15 | void SealCurrentObjects(Heap* heap); |
| 16 | |
| 17 | int FixedArrayLenFromSize(int size); |
| 18 | |
| 19 | // Fill a page with fixed arrays leaving remainder behind. The function does |
| 20 | // not create additional fillers and assumes that the space has just been |
| 21 | // sealed. |
| 22 | std::vector<Handle<FixedArray>> FillOldSpacePageWithFixedArrays(Heap* heap, |
| 23 | int remainder); |
| 24 | |
| 25 | std::vector<Handle<FixedArray>> CreatePadding( |
| 26 | Heap* heap, int padding_size, AllocationType allocation, |
| 27 | int object_size = kMaxRegularHeapObjectSize); |
| 28 | |
| 29 | void AllocateAllButNBytes( |
| 30 | v8::internal::NewSpace* space, int , |
| 31 | std::vector<Handle<FixedArray>>* out_handles = nullptr); |
| 32 | |
| 33 | void FillCurrentPage(v8::internal::NewSpace* space, |
| 34 | std::vector<Handle<FixedArray>>* out_handles = nullptr); |
| 35 | |
| 36 | // Helper function that simulates a full new-space in the heap. |
| 37 | bool FillUpOnePage(v8::internal::NewSpace* space, |
| 38 | std::vector<Handle<FixedArray>>* out_handles = nullptr); |
| 39 | |
| 40 | void SimulateFullSpace(v8::internal::NewSpace* space, |
| 41 | std::vector<Handle<FixedArray>>* out_handles = nullptr); |
| 42 | |
| 43 | // Helper function that simulates many incremental marking steps until |
| 44 | // marking is completed. |
| 45 | void SimulateIncrementalMarking(i::Heap* heap, bool force_completion = true); |
| 46 | |
| 47 | // Helper function that simulates a full old-space in the heap. |
| 48 | void SimulateFullSpace(v8::internal::PagedSpace* space); |
| 49 | |
| 50 | void AbandonCurrentlyFreeMemory(PagedSpace* space); |
| 51 | |
| 52 | void GcAndSweep(Heap* heap, AllocationSpace space); |
| 53 | |
| 54 | void ForceEvacuationCandidate(Page* page); |
| 55 | |
| 56 | void InvokeScavenge(); |
| 57 | |
| 58 | void InvokeMarkSweep(); |
| 59 | |
| 60 | template <typename GlobalOrPersistent> |
| 61 | bool InYoungGeneration(v8::Isolate* isolate, const GlobalOrPersistent& global) { |
| 62 | v8::HandleScope scope(isolate); |
| 63 | auto tmp = global.Get(isolate); |
| 64 | return i::Heap::InYoungGeneration(*v8::Utils::OpenHandle(*tmp)); |
| 65 | } |
| 66 | |
| 67 | } // namespace heap |
| 68 | } // namespace internal |
| 69 | } // namespace v8 |
| 70 | |
| 71 | #endif // HEAP_HEAP_UTILS_H_ |
| 72 | |