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#if V8_CC_MSVC
19#include <intrin.h> // _AddressOfReturnAddress()
20#endif
21
25namespace cppgc {
26
27class AllocationHandle;
28class HeapHandle;
29
35namespace internal {
36class Heap;
37} // namespace internal
38
43 public:
44#if V8_CC_MSVC
45 StackStartMarker() : stack_start_(_AddressOfReturnAddress()) {}
46#else
47 StackStartMarker() : stack_start_(__builtin_frame_address(0)) {}
48#endif
49 void* stack_start() const { return stack_start_; }
50
51 private:
52 void* stack_start_;
53};
54
56 public:
61
65 enum class StackSupport : uint8_t {
69 kSupportsConservativeStackScan,
74 kNoConservativeStackScan,
75 };
76
80 enum class MarkingType : uint8_t {
85 kAtomic,
90 kIncremental,
94 kIncrementalAndConcurrent
95 };
96
100 enum class SweepingType : uint8_t {
104 kAtomic,
109 kIncremental,
114 kIncrementalAndConcurrent
115 };
116
127 size_t initial_heap_size_bytes = 0;
128 };
129
134 struct HeapOptions {
140 static HeapOptions Default() { return {}; }
141
147 std::vector<std::unique_ptr<CustomSpaceBase>> custom_spaces;
148
157 StackSupport stack_support = StackSupport::kSupportsConservativeStackScan;
158
162 MarkingType marking_support = MarkingType::kIncrementalAndConcurrent;
163
167 SweepingType sweeping_support = SweepingType::kIncrementalAndConcurrent;
168
174
179 std::optional<StackStartMarker> stack_start_marker = std::nullopt;
180 };
188 static std::unique_ptr<Heap> Create(
189 std::shared_ptr<Platform> platform,
190 HeapOptions options = HeapOptions::Default());
191
192 virtual ~Heap() = default;
193
204 const char* source, const char* reason,
205 StackState stack_state = StackState::kMayContainHeapPointers);
206
211 AllocationHandle& GetAllocationHandle();
212
218
219 private:
220 Heap() = default;
221
222 friend class internal::Heap;
223};
224
225} // namespace cppgc
226
227#endif // INCLUDE_CPPGC_HEAP_H_
Definition: heap-handle.h:21
Definition: heap.h:55
static std::unique_ptr< Heap > Create(std::shared_ptr< Platform > platform, HeapOptions options=HeapOptions::Default())
MarkingType
Definition: heap.h:80
HeapHandle & GetHeapHandle()
StackSupport
Definition: heap.h:65
SweepingType
Definition: heap.h:100
void ForceGarbageCollectionSlow(const char *source, const char *reason, StackState stack_state=StackState::kMayContainHeapPointers)
AllocationHandle & GetAllocationHandle()
virtual ~Heap()=default
Definition: heap.h:42
void * stack_start() const
Definition: heap.h:49
StackStartMarker()
Definition: heap.h:47
Definition: allocation.h:38
EmbedderStackState
Definition: common.h:15
Definition: heap.h:134
std::vector< std::unique_ptr< CustomSpaceBase > > custom_spaces
Definition: heap.h:147
static HeapOptions Default()
Definition: heap.h:140
ResourceConstraints resource_constraints
Definition: heap.h:173
Definition: heap.h:120
#define V8_EXPORT
Definition: v8config.h:867