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
11namespace v8 {
12namespace internal {
13namespace heap {
14
15void SealCurrentObjects(Heap* heap);
16
17int 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.
22std::vector<Handle<FixedArray>> FillOldSpacePageWithFixedArrays(Heap* heap,
23 int remainder);
24
25std::vector<Handle<FixedArray>> CreatePadding(
26 Heap* heap, int padding_size, AllocationType allocation,
27 int object_size = kMaxRegularHeapObjectSize);
28
29void AllocateAllButNBytes(
30 v8::internal::NewSpace* space, int extra_bytes,
31 std::vector<Handle<FixedArray>>* out_handles = nullptr);
32
33void 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.
37bool FillUpOnePage(v8::internal::NewSpace* space,
38 std::vector<Handle<FixedArray>>* out_handles = nullptr);
39
40void 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.
45void SimulateIncrementalMarking(i::Heap* heap, bool force_completion = true);
46
47// Helper function that simulates a full old-space in the heap.
48void SimulateFullSpace(v8::internal::PagedSpace* space);
49
50void AbandonCurrentlyFreeMemory(PagedSpace* space);
51
52void GcAndSweep(Heap* heap, AllocationSpace space);
53
54void ForceEvacuationCandidate(Page* page);
55
56void InvokeScavenge();
57
58void InvokeMarkSweep();
59
60template <typename GlobalOrPersistent>
61bool 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