v8 12.4.254 (node 22.4.1)
V8 is Google's open source JavaScript engine
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 HeapHandle;
23} // namespace cppgc
24
25namespace v8 {
26
27class Object;
28
29namespace internal {
30class CppHeap;
31} // namespace internal
32
34
39struct WrapperDescriptor final {
45 using InternalFieldIndex = int;
46
51 static constexpr uint16_t kUnknownEmbedderId = UINT16_MAX;
52
59
64
69
77};
78
81 std::vector<std::unique_ptr<cppgc::CustomSpaceBase>> custom_spaces,
82 WrapperDescriptor wrapper_descriptor)
83 : custom_spaces(std::move(custom_spaces)),
84 wrapper_descriptor(wrapper_descriptor) {}
85
88
89 std::vector<std::unique_ptr<cppgc::CustomSpaceBase>> custom_spaces;
95 cppgc::Heap::MarkingType marking_support =
101 cppgc::Heap::SweepingType sweeping_support =
103};
104
113 public:
114 static std::unique_ptr<CppHeap> Create(v8::Platform* platform,
115 const CppHeapCreateParams& params);
116
117 virtual ~CppHeap() = default;
118
123 cppgc::AllocationHandle& GetAllocationHandle();
124
130
137 void Terminate();
138
147
155 std::vector<cppgc::CustomSpaceIndex> custom_spaces,
156 std::unique_ptr<CustomSpaceStatisticsReceiver> receiver);
157
164
171
178 cppgc::EmbedderStackState stack_state);
179
184
185 private:
186 CppHeap() = default;
187
188 friend class internal::CppHeap;
189};
190
191class JSVisitor : public cppgc::Visitor {
192 public:
194 ~JSVisitor() override = default;
195
196 void Trace(const TracedReferenceBase& ref) {
197 if (ref.IsEmptyThreadSafe()) return;
198 Visit(ref);
199 }
200
201 protected:
203
204 virtual void Visit(const TracedReferenceBase& ref) {}
205};
206
213 public:
223 virtual void AllocatedBytes(cppgc::CustomSpaceIndex space_index,
224 size_t bytes) = 0;
225};
226
227} // namespace v8
228
229namespace cppgc {
230
231template <typename T>
232struct TraceTrait<v8::TracedReference<T>> {
234 return {nullptr, Trace};
235 }
236
237 static void Trace(Visitor* visitor, const void* self) {
238 static_cast<v8::JSVisitor*>(visitor)->Trace(
239 *static_cast<const v8::TracedReference<T>*>(self));
240 }
241};
242
243} // namespace cppgc
244
245#endif // INCLUDE_V8_CPPGC_H_
MarkingType
Definition heap.h:60
SweepingType
Definition heap.h:80
virtual void Visit(const void *self, TraceDescriptor)
Definition visitor.h:354
virtual ~CppHeap()=default
cppgc::HeapHandle & GetHeapHandle()
void EnableDetachedGarbageCollectionsForTesting()
cppgc::HeapStatistics CollectStatistics(cppgc::HeapStatistics::DetailLevel detail_level)
void CollectGarbageInYoungGenerationForTesting(cppgc::EmbedderStackState stack_state)
void CollectGarbageForTesting(cppgc::EmbedderStackState stack_state)
void Terminate()
v8::WrapperDescriptor wrapper_descriptor() const
void CollectCustomSpaceStatisticsAtLastGC(std::vector< cppgc::CustomSpaceIndex > custom_spaces, std::unique_ptr< CustomSpaceStatisticsReceiver > receiver)
cppgc::AllocationHandle & GetAllocationHandle()
static std::unique_ptr< CppHeap > Create(v8::Platform *platform, const CppHeapCreateParams &params)
virtual void AllocatedBytes(cppgc::CustomSpaceIndex space_index, size_t bytes)=0
virtual ~CustomSpaceStatisticsReceiver()=default
void Trace(const TracedReferenceBase &ref)
Definition v8-cppgc.h:196
~JSVisitor() override=default
virtual void Visit(const TracedReferenceBase &ref)
Definition v8-cppgc.h:204
JSVisitor(cppgc::Visitor::Key key)
Definition v8-cppgc.h:193
EmbedderStackState
Definition common.h:15
static void Trace(Visitor *visitor, const void *self)
Definition v8-cppgc.h:237
static cppgc::TraceDescriptor GetTraceDescriptor(const void *self)
Definition v8-cppgc.h:233
static void Trace(Visitor *visitor, const void *self)
Definition trace-trait.h:97
WrapperDescriptor wrapper_descriptor
Definition v8-cppgc.h:90
CppHeapCreateParams(const CppHeapCreateParams &)=delete
CppHeapCreateParams & operator=(const CppHeapCreateParams &)=delete
CppHeapCreateParams(std::vector< std::unique_ptr< cppgc::CustomSpaceBase > > custom_spaces, WrapperDescriptor wrapper_descriptor)
Definition v8-cppgc.h:80
std::vector< std::unique_ptr< cppgc::CustomSpaceBase > > custom_spaces
Definition v8-cppgc.h:89
static constexpr uint16_t kUnknownEmbedderId
Definition v8-cppgc.h:51
InternalFieldIndex wrappable_type_index
Definition v8-cppgc.h:63
InternalFieldIndex wrappable_instance_index
Definition v8-cppgc.h:68
constexpr WrapperDescriptor(InternalFieldIndex wrappable_type_index, InternalFieldIndex wrappable_instance_index, uint16_t embedder_id_for_garbage_collected)
Definition v8-cppgc.h:53
uint16_t embedder_id_for_garbage_collected
Definition v8-cppgc.h:76
#define V8_EXPORT
Definition v8config.h:753