heap-utils.h 3 KB
Newer Older
1 2 3 4 5 6 7
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef HEAP_HEAP_UTILS_H_
#define HEAP_HEAP_UTILS_H_

8
#include "src/api/api-inl.h"
9 10 11 12 13 14
#include "src/heap/heap.h"

namespace v8 {
namespace internal {
namespace heap {

15
class V8_NODISCARD TemporaryEmbedderHeapTracerScope {
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
 public:
  TemporaryEmbedderHeapTracerScope(v8::Isolate* isolate,
                                   v8::EmbedderHeapTracer* tracer)
      : isolate_(isolate) {
    isolate_->SetEmbedderHeapTracer(tracer);
  }

  ~TemporaryEmbedderHeapTracerScope() {
    isolate_->SetEmbedderHeapTracer(nullptr);
  }

 private:
  v8::Isolate* const isolate_;
};

31 32 33 34
void SealCurrentObjects(Heap* heap);

int FixedArrayLenFromSize(int size);

35 36 37 38 39 40
// Fill a page with fixed arrays leaving remainder behind. The function does
// not create additional fillers and assumes that the space has just been
// sealed.
std::vector<Handle<FixedArray>> FillOldSpacePageWithFixedArrays(Heap* heap,
                                                                int remainder);

41
std::vector<Handle<FixedArray>> CreatePadding(
42
    Heap* heap, int padding_size, AllocationType allocation,
43
    int object_size = kMaxRegularHeapObjectSize);
44

45 46 47 48
bool FillCurrentPage(v8::internal::NewSpace* space,
                     std::vector<Handle<FixedArray>>* out_handles = nullptr);

bool FillCurrentPageButNBytes(
49 50 51 52 53 54 55 56 57 58 59 60 61 62
    v8::internal::NewSpace* space, int extra_bytes,
    std::vector<Handle<FixedArray>>* out_handles = nullptr);

// Helper function that simulates a full new-space in the heap.
void SimulateFullSpace(v8::internal::NewSpace* space,
                       std::vector<Handle<FixedArray>>* out_handles = nullptr);

// Helper function that simulates many incremental marking steps until
// marking is completed.
void SimulateIncrementalMarking(i::Heap* heap, bool force_completion = true);

// Helper function that simulates a full old-space in the heap.
void SimulateFullSpace(v8::internal::PagedSpace* space);

63 64 65 66
void AbandonCurrentlyFreeMemory(PagedSpace* space);

void GcAndSweep(Heap* heap, AllocationSpace space);

67 68
void ForceEvacuationCandidate(Page* page);

69
void InvokeScavenge(Isolate* isolate = nullptr);
70

71
void InvokeMarkSweep(Isolate* isolate = nullptr);
72

73 74 75 76
void GrowNewSpace(Heap* heap);

void GrowNewSpaceToMaximumCapacity(Heap* heap);

77
template <typename GlobalOrPersistent>
78
bool InYoungGeneration(v8::Isolate* isolate, const GlobalOrPersistent& global) {
79 80
  v8::HandleScope scope(isolate);
  auto tmp = global.Get(isolate);
81
  return i::Heap::InYoungGeneration(*v8::Utils::OpenHandle(*tmp));
82 83
}

84 85 86 87 88 89 90 91 92 93
bool InCorrectGeneration(HeapObject object);

template <typename GlobalOrPersistent>
bool InCorrectGeneration(v8::Isolate* isolate,
                         const GlobalOrPersistent& global) {
  v8::HandleScope scope(isolate);
  auto tmp = global.Get(isolate);
  return InCorrectGeneration(*v8::Utils::OpenHandle(*tmp));
}

94 95 96 97 98
}  // namespace heap
}  // namespace internal
}  // namespace v8

#endif  // HEAP_HEAP_UTILS_H_