v8 13.6.233 (node 24.1.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
57
66 public:
67 static std::unique_ptr<CppHeap> Create(v8::Platform* platform,
68 const CppHeapCreateParams& params);
69
70 virtual ~CppHeap() = default;
71
76 cppgc::AllocationHandle& GetAllocationHandle();
77
83
90 V8_DEPRECATED("Terminate gets automatically called in the CppHeap destructor")
91 void Terminate();
92
100 cppgc::HeapStatistics::DetailLevel detail_level);
101
109 std::vector<cppgc::CustomSpaceIndex> custom_spaces,
110 std::unique_ptr<CustomSpaceStatisticsReceiver> receiver);
111
118
124 void CollectGarbageForTesting(cppgc::EmbedderStackState stack_state);
125
132 cppgc::EmbedderStackState stack_state);
133
134 private:
135 CppHeap() = default;
136
137 friend class internal::CppHeap;
138};
139
140class JSVisitor : public cppgc::Visitor {
141 public:
143 ~JSVisitor() override = default;
144
145 void Trace(const TracedReferenceBase& ref) {
146 if (ref.IsEmptyThreadSafe()) return;
147 Visit(ref);
148 }
149
150 protected:
152
153 virtual void Visit(const TracedReferenceBase& ref) {}
154};
155
162 public:
172 virtual void AllocatedBytes(cppgc::CustomSpaceIndex space_index,
173 size_t bytes) = 0;
174};
175
176} // namespace v8
177
178namespace cppgc {
179
180template <typename T>
181struct TraceTrait<v8::TracedReference<T>> {
183 return {nullptr, Trace};
184 }
185
186 static void Trace(Visitor* visitor, const void* self) {
187 static_cast<v8::JSVisitor*>(visitor)->Trace(
188 *static_cast<const v8::TracedReference<T>*>(self));
189 }
190};
191
192} // namespace cppgc
193
194#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:373
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)
friend class internal::CppHeap
Definition v8-cppgc.h:137
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:145
~JSVisitor() override=default
virtual void Visit(const TracedReferenceBase &ref)
Definition v8-cppgc.h:153
JSVisitor(cppgc::Visitor::Key key)
Definition v8-cppgc.h:142
static void Trace(Visitor *visitor, const void *self)
Definition v8-cppgc.h:186
static cppgc::TraceDescriptor GetTraceDescriptor(const void *self)
Definition v8-cppgc.h:182
CppHeapCreateParams(const CppHeapCreateParams &)=delete
cppgc::Heap::SweepingType sweeping_support
Definition v8-cppgc.h:54
CppHeapCreateParams & operator=(const CppHeapCreateParams &)=delete
cppgc::Heap::MarkingType marking_support
Definition v8-cppgc.h:48
CppHeapCreateParams(std::vector< std::unique_ptr< cppgc::CustomSpaceBase > > custom_spaces)
Definition v8-cppgc.h:36
std::vector< std::unique_ptr< cppgc::CustomSpaceBase > > custom_spaces
Definition v8-cppgc.h:43
#define V8_EXPORT
Definition v8config.h:800
#define V8_DEPRECATED(message)
Definition v8config.h:606