Loading...
Searching...
No Matches
heap.h
Go to the documentation of this file.
1// Copyright 2020 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 INCLUDE_CPPGC_HEAP_H_
6#define INCLUDE_CPPGC_HEAP_H_
7
8#include <cstddef>
9#include <cstdint>
10#include <memory>
11#include <vector>
12
13#include "cppgc/common.h"
14#include "cppgc/custom-space.h"
15#include "cppgc/platform.h"
16#include "v8config.h" // NOLINT(build/include_directory)
17
18// TODO(540324230): Remove once embedders migrate to StackStartScope.
19#if V8_CC_MSVC
20#include <intrin.h> // _AddressOfReturnAddress()
21#endif
22
26namespace cppgc {
27
28class AllocationHandle;
29class HeapHandle;
30
36namespace internal {
37class Heap;
38} // namespace internal
39
45 public:
46#if V8_CC_MSVC
47 StackStartMarker() : stack_start_(_AddressOfReturnAddress()) {}
48#else
49 StackStartMarker() : stack_start_(__builtin_frame_address(0)) {}
50#endif
51 void* stack_start() const { return stack_start_; }
52
53 private:
54 void* stack_start_;
55};
56
58 public:
63
67 enum class StackSupport : uint8_t {
71 kSupportsConservativeStackScan,
76 kNoConservativeStackScan,
77 };
78
82 enum class MarkingType : uint8_t {
87 kAtomic,
92 kIncremental,
96 kIncrementalAndConcurrent
97 };
98
102 enum class SweepingType : uint8_t {
106 kAtomic,
111 kIncremental,
116 kIncrementalAndConcurrent
117 };
118
129 size_t initial_heap_size_bytes = 0;
130 };
131
136 struct HeapOptions {
142 static HeapOptions Default() { return {}; }
143
149 std::vector<std::unique_ptr<CustomSpaceBase>> custom_spaces;
150
159 StackSupport stack_support = StackSupport::kSupportsConservativeStackScan;
160
164 MarkingType marking_support = MarkingType::kIncrementalAndConcurrent;
165
169 SweepingType sweeping_support = SweepingType::kIncrementalAndConcurrent;
170
176
181 std::optional<StackStartMarker> stack_start_marker = std::nullopt;
182
186 AllocationSampler* allocation_sampler = nullptr;
187 };
195 static std::unique_ptr<Heap> Create(
196 std::shared_ptr<Platform> platform,
197 HeapOptions options = HeapOptions::Default());
198
199 virtual ~Heap() = default;
200
211 const char* source, const char* reason,
212 StackState stack_state = StackState::kMayContainHeapPointers);
213
218 AllocationHandle& GetAllocationHandle();
219
225
226 private:
227 Heap() = default;
228
229 friend class internal::Heap;
230};
231
232} // namespace cppgc
233
234#endif // INCLUDE_CPPGC_HEAP_H_
Definition: platform.h:34
Definition: heap-handle.h:21
Definition: heap.h:57
static std::unique_ptr< Heap > Create(std::shared_ptr< Platform > platform, HeapOptions options=HeapOptions::Default())
MarkingType
Definition: heap.h:82
HeapHandle & GetHeapHandle()
StackSupport
Definition: heap.h:67
SweepingType
Definition: heap.h:102
void ForceGarbageCollectionSlow(const char *source, const char *reason, StackState stack_state=StackState::kMayContainHeapPointers)
AllocationHandle & GetAllocationHandle()
virtual ~Heap()=default
Definition: heap.h:44
void * stack_start() const
Definition: heap.h:51
StackStartMarker()
Definition: heap.h:49
Definition: allocation.h:39
EmbedderStackState
Definition: common.h:20
Definition: heap.h:136
std::vector< std::unique_ptr< CustomSpaceBase > > custom_spaces
Definition: heap.h:149
static HeapOptions Default()
Definition: heap.h:142
ResourceConstraints resource_constraints
Definition: heap.h:175
Definition: heap.h:122
#define V8_EXPORT
Definition: v8config.h:874