v8 10.2.154 (node 18.16.0)
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
80 std::vector<std::unique_ptr<cppgc::CustomSpaceBase>> custom_spaces;
82};
83
88 public:
89 static std::unique_ptr<CppHeap> Create(v8::Platform* platform,
90 const CppHeapCreateParams& params);
91
92 virtual ~CppHeap() = default;
93
98 cppgc::AllocationHandle& GetAllocationHandle();
99
104 cppgc::HeapHandle& GetHeapHandle();
105
112 void Terminate();
113
122
130 std::vector<cppgc::CustomSpaceIndex> custom_spaces,
131 std::unique_ptr<CustomSpaceStatisticsReceiver> receiver);
132
139
146
153 cppgc::EmbedderStackState stack_state);
154
155 private:
156 CppHeap() = default;
157
158 friend class internal::CppHeap;
159};
160
161class JSVisitor : public cppgc::Visitor {
162 public:
164 ~JSVisitor() override = default;
165
166 void Trace(const TracedReferenceBase& ref) {
167 if (ref.IsEmptyThreadSafe()) return;
168 Visit(ref);
169 }
170
171 protected:
173
174 virtual void Visit(const TracedReferenceBase& ref) {}
175};
176
183 public:
193 virtual void AllocatedBytes(cppgc::CustomSpaceIndex space_index,
194 size_t bytes) = 0;
195};
196
197} // namespace v8
198
199namespace cppgc {
200
201template <typename T>
202struct TraceTrait<v8::TracedReference<T>> {
204 return {nullptr, Trace};
205 }
206
207 static void Trace(Visitor* visitor, const void* self) {
208 static_cast<v8::JSVisitor*>(visitor)->Trace(
209 *static_cast<const v8::TracedReference<T>*>(self));
210 }
211};
212
213} // namespace cppgc
214
215#endif // INCLUDE_V8_CPPGC_H_
virtual void Visit(const void *self, TraceDescriptor)
Definition visitor.h:297
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()
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:166
~JSVisitor() override=default
virtual void Visit(const TracedReferenceBase &ref)
Definition v8-cppgc.h:174
JSVisitor(cppgc::Visitor::Key key)
Definition v8-cppgc.h:163
EmbedderStackState
Definition common.h:16
static void Trace(Visitor *visitor, const void *self)
Definition v8-cppgc.h:207
static cppgc::TraceDescriptor GetTraceDescriptor(const void *self)
Definition v8-cppgc.h:203
static void Trace(Visitor *visitor, const void *self)
Definition trace-trait.h:85
WrapperDescriptor wrapper_descriptor
Definition v8-cppgc.h:81
std::vector< std::unique_ptr< cppgc::CustomSpaceBase > > custom_spaces
Definition v8-cppgc.h:80
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:578