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
37 std::vector<std::unique_ptr<cppgc::CustomSpaceBase>> custom_spaces)
38 : custom_spaces(std::move(custom_spaces)) {}
39
42
43 std::vector<std::unique_ptr<cppgc::CustomSpaceBase>> custom_spaces;
48 cppgc::Heap::MarkingType marking_support =
54 cppgc::Heap::SweepingType sweeping_support =
56};
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 void Terminate();
91
100
108 std::vector<cppgc::CustomSpaceIndex> custom_spaces,
109 std::unique_ptr<CustomSpaceStatisticsReceiver> receiver);
110
117
124
131 cppgc::EmbedderStackState stack_state);
132
133 private:
134 CppHeap() = default;
135
136 friend class internal::CppHeap;
137};
138
139class JSVisitor : public cppgc::Visitor {
140 public:
142 ~JSVisitor() override = default;
143
144 void Trace(const TracedReferenceBase& ref) {
145 if (ref.IsEmptyThreadSafe()) return;
146 Visit(ref);
147 }
148
149 protected:
151
152 virtual void Visit(const TracedReferenceBase& ref) {}
153};
154
161 public:
171 virtual void AllocatedBytes(cppgc::CustomSpaceIndex space_index,
172 size_t bytes) = 0;
173};
174
175} // namespace v8
176
177namespace cppgc {
178
179template <typename T>
180struct TraceTrait<v8::TracedReference<T>> {
182 return {nullptr, Trace};
183 }
184
185 static void Trace(Visitor* visitor, const void* self) {
186 static_cast<v8::JSVisitor*>(visitor)->Trace(
187 *static_cast<const v8::TracedReference<T>*>(self));
188 }
189};
190
191} // namespace cppgc
192
193#endif // INCLUDE_V8_CPPGC_H_
Definition: heap-handle.h:21
MarkingType
Definition: heap.h:60
SweepingType
Definition: heap.h:80
Definition: visitor.h:58
Definition: visitor.h:56
virtual void Visit(const void *self, TraceDescriptor)
Definition: visitor.h:354
Visitor(Key)
Definition: visitor.h:64
Definition: v8-cppgc.h:65
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()
cppgc::HeapStatistics CollectStatistics(cppgc::HeapStatistics::DetailLevel detail_level)
void Terminate()
cppgc::HeapHandle & GetHeapHandle()
cppgc::AllocationHandle & GetAllocationHandle()
Definition: v8-cppgc.h:160
virtual void AllocatedBytes(cppgc::CustomSpaceIndex space_index, size_t bytes)=0
virtual ~CustomSpaceStatisticsReceiver()=default
Definition: v8-cppgc.h:139
JSVisitor(cppgc::Visitor::Key key)
Definition: v8-cppgc.h:141
~JSVisitor() override=default
virtual void Visit(const TracedReferenceBase &ref)
Definition: v8-cppgc.h:152
void Trace(const TracedReferenceBase &ref)
Definition: v8-cppgc.h:144
Definition: v8-platform.h:1058
Definition: v8-traced-handle.h:54
bool IsEmptyThreadSafe() const
Definition: v8-traced-handle.h:77
Definition: v8-traced-handle.h:165
Definition: allocation.h:38
EmbedderStackState
Definition: common.h:15
Definition: libplatform.h:15
Definition: custom-space.h:15
Definition: heap-statistics.h:19
DetailLevel
Definition: heap-statistics.h:28
Definition: trace-trait.h:44
static cppgc::TraceDescriptor GetTraceDescriptor(const void *self)
Definition: v8-cppgc.h:181
static void Trace(Visitor *visitor, const void *self)
Definition: v8-cppgc.h:185
Definition: trace-trait.h:105
static void Trace(Visitor *visitor, const void *self)
Definition: trace-trait.h:97
Definition: v8-cppgc.h:35
std::vector< std::unique_ptr< cppgc::CustomSpaceBase > > custom_spaces
Definition: v8-cppgc.h:43
CppHeapCreateParams(const CppHeapCreateParams &)=delete
CppHeapCreateParams(std::vector< std::unique_ptr< cppgc::CustomSpaceBase > > custom_spaces)
Definition: v8-cppgc.h:36
CppHeapCreateParams & operator=(const CppHeapCreateParams &)=delete
#define V8_EXPORT
Definition: v8config.h:793