Loading...
Searching...
No Matches
v8-cppgc.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_V8_CPPGC_H_
6#define INCLUDE_V8_CPPGC_H_
7
8#include <cstdint>
9#include <memory>
10#include <vector>
11
12#include "cppgc/common.h"
13#include "cppgc/custom-space.h"
15#include "cppgc/visitor.h"
16#include "v8-internal.h" // NOLINT(build/include_directory)
17#include "v8-platform.h" // NOLINT(build/include_directory)
18#include "v8-traced-handle.h" // NOLINT(build/include_directory)
19
20namespace cppgc {
21class AllocationHandle;
22class AllocationSampler;
23class HeapHandle;
24} // namespace cppgc
25
26namespace v8 {
27
28class Object;
29
30namespace internal {
31class CppHeap;
32} // namespace internal
33
35
38 std::vector<std::unique_ptr<cppgc::CustomSpaceBase>> custom_spaces)
39 : custom_spaces(std::move(custom_spaces)) {}
40
43
44 std::vector<std::unique_ptr<cppgc::CustomSpaceBase>> custom_spaces;
49 cppgc::Heap::MarkingType marking_support =
55 cppgc::Heap::SweepingType sweeping_support =
62 V8_DEPRECATE_SOON("Use StackStartScope instead.")
63 std::optional<cppgc::StackStartMarker> stack_start_marker = std::nullopt;
67 cppgc::AllocationSampler* allocation_sampler = nullptr;
68};
69
78 public:
79 static std::unique_ptr<CppHeap> Create(v8::Platform* platform,
80 const CppHeapCreateParams& params);
81
82 virtual ~CppHeap() = default;
83
88 cppgc::AllocationHandle& GetAllocationHandle();
89
95
104
112 std::vector<cppgc::CustomSpaceIndex> custom_spaces,
113 std::unique_ptr<CustomSpaceStatisticsReceiver> receiver);
114
121
128
135 cppgc::EmbedderStackState stack_state);
136
153
158
159 private:
160 CppHeap() = default;
161
162 friend class internal::CppHeap;
163};
164
165class JSVisitor : public cppgc::Visitor {
166 public:
167 explicit JSVisitor(cppgc::Visitor::Key key) : cppgc::Visitor(key) {}
168 ~JSVisitor() override = default;
169
170 void Trace(const TracedReferenceBase& ref) {
171 if (ref.IsEmptyThreadSafe()) return;
172 Visit(ref);
173 }
174
175 protected:
177
178 virtual void Visit(const TracedReferenceBase& ref) {}
179};
180
187 public:
197 virtual void AllocatedBytes(cppgc::CustomSpaceIndex space_index,
198 size_t bytes) = 0;
199};
200
201} // namespace v8
202
203namespace cppgc {
204
205template <typename T>
206struct TraceTrait<v8::TracedReference<T>> {
208 return {nullptr, Trace};
209 }
210
211 static void Trace(Visitor* visitor, const void* self) {
212 static_cast<v8::JSVisitor*>(visitor)->Trace(
213 *static_cast<const v8::TracedReference<T>*>(self));
214 }
215};
216
217} // namespace cppgc
218
219#endif // INCLUDE_V8_CPPGC_H_
Definition: heap-handle.h:21
MarkingType
Definition: heap.h:82
SweepingType
Definition: heap.h:102
Definition: visitor.h:80
Definition: visitor.h:78
virtual void Visit(const void *self, TraceDescriptor)
Definition: visitor.h:382
Definition: v8-cppgc.h:77
void CollectCustomSpaceStatisticsAtLastGC(std::vector< cppgc::CustomSpaceIndex > custom_spaces, std::unique_ptr< CustomSpaceStatisticsReceiver > receiver)
void CollectGarbageForTesting(cppgc::EmbedderStackState stack_state)
void CollectGarbageInYoungGenerationForTesting(cppgc::EmbedderStackState stack_state)
virtual ~CppHeap()=default
static std::unique_ptr< CppHeap > Create(v8::Platform *platform, const CppHeapCreateParams &params)
void EnableDetachedGarbageCollectionsForTesting()
void FinishSweepingForTesting()
void SetForceIncrementalSweepingForTesting(bool value)
cppgc::HeapStatistics CollectStatistics(cppgc::HeapStatistics::DetailLevel detail_level)
cppgc::HeapHandle & GetHeapHandle()
cppgc::AllocationHandle & GetAllocationHandle()
Definition: v8-cppgc.h:186
virtual void AllocatedBytes(cppgc::CustomSpaceIndex space_index, size_t bytes)=0
virtual ~CustomSpaceStatisticsReceiver()=default
Definition: v8-cppgc.h:165
JSVisitor(cppgc::Visitor::Key key)
Definition: v8-cppgc.h:167
~JSVisitor() override=default
virtual void Visit(const TracedReferenceBase &ref)
Definition: v8-cppgc.h:178
void Trace(const TracedReferenceBase &ref)
Definition: v8-cppgc.h:170
Definition: v8-platform.h:1278
Definition: v8-traced-handle.h:54
bool IsEmptyThreadSafe() const
Definition: v8-traced-handle.h:77
Definition: v8-traced-handle.h:166
Definition: allocation.h:39
EmbedderStackState
Definition: common.h:20
Definition: libplatform.h:15
Definition: custom-space.h:15
Definition: heap-statistics.h:19
DetailLevel
Definition: heap-statistics.h:28
Definition: trace-trait.h:43
static cppgc::TraceDescriptor GetTraceDescriptor(const void *self)
Definition: v8-cppgc.h:207
static void Trace(Visitor *visitor, const void *self)
Definition: v8-cppgc.h:211
Definition: trace-trait.h:104
Definition: v8-cppgc.h:36
std::vector< std::unique_ptr< cppgc::CustomSpaceBase > > custom_spaces
Definition: v8-cppgc.h:44
CppHeapCreateParams(const CppHeapCreateParams &)=delete
CppHeapCreateParams(std::vector< std::unique_ptr< cppgc::CustomSpaceBase > > custom_spaces)
Definition: v8-cppgc.h:37
CppHeapCreateParams & operator=(const CppHeapCreateParams &)=delete
#define V8_EXPORT
Definition: v8config.h:875
#define V8_DEPRECATE_SOON(message)
Definition: v8config.h:632