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
21namespace cppgc {
22
23class AllocationHandle;
24class HeapHandle;
25
31namespace internal {
32class Heap;
33} // namespace internal
34
39 public:
40 StackStartMarker() : stack_start_(__builtin_frame_address(0)) {}
41 void* stack_start() const { return stack_start_; }
42
43 private:
44 void* stack_start_;
45};
46
48 public:
53
57 enum class StackSupport : uint8_t {
61 kSupportsConservativeStackScan,
66 kNoConservativeStackScan,
67 };
68
72 enum class MarkingType : uint8_t {
77 kAtomic,
82 kIncremental,
86 kIncrementalAndConcurrent
87 };
88
92 enum class SweepingType : uint8_t {
96 kAtomic,
101 kIncremental,
106 kIncrementalAndConcurrent
107 };
108
119 size_t initial_heap_size_bytes = 0;
120 };
121
126 struct HeapOptions {
132 static HeapOptions Default() { return {}; }
133
139 std::vector<std::unique_ptr<CustomSpaceBase>> custom_spaces;
140
149 StackSupport stack_support = StackSupport::kSupportsConservativeStackScan;
150
154 MarkingType marking_support = MarkingType::kIncrementalAndConcurrent;
155
159 SweepingType sweeping_support = SweepingType::kIncrementalAndConcurrent;
160
166
171 std::optional<StackStartMarker> stack_start_marker = std::nullopt;
172 };
180 static std::unique_ptr<Heap> Create(
181 std::shared_ptr<Platform> platform,
182 HeapOptions options = HeapOptions::Default());
183
184 virtual ~Heap() = default;
185
196 const char* source, const char* reason,
197 StackState stack_state = StackState::kMayContainHeapPointers);
198
203 AllocationHandle& GetAllocationHandle();
204
210
211 private:
212 Heap() = default;
213
214 friend class internal::Heap;
215};
216
217} // namespace cppgc
218
219#endif // INCLUDE_CPPGC_HEAP_H_
Definition: heap-handle.h:21
Definition: heap.h:47
static std::unique_ptr< Heap > Create(std::shared_ptr< Platform > platform, HeapOptions options=HeapOptions::Default())
MarkingType
Definition: heap.h:72
HeapHandle & GetHeapHandle()
StackSupport
Definition: heap.h:57
SweepingType
Definition: heap.h:92
void ForceGarbageCollectionSlow(const char *source, const char *reason, StackState stack_state=StackState::kMayContainHeapPointers)
AllocationHandle & GetAllocationHandle()
virtual ~Heap()=default
Definition: heap.h:38
void * stack_start() const
Definition: heap.h:41
StackStartMarker()
Definition: heap.h:40
Definition: allocation.h:38
EmbedderStackState
Definition: common.h:15
Definition: heap.h:126
std::vector< std::unique_ptr< CustomSpaceBase > > custom_spaces
Definition: heap.h:139
static HeapOptions Default()
Definition: heap.h:132
ResourceConstraints resource_constraints
Definition: heap.h:165
Definition: heap.h:112
#define V8_EXPORT
Definition: v8config.h:854