v8 10.2.154 (node 18.16.0)
V8 is Google's open source JavaScript engine
Loading...
Searching...
No Matches
v8-embedder-heap.h
Go to the documentation of this file.
1// Copyright 2021 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_EMBEDDER_HEAP_H_
6#define INCLUDE_V8_EMBEDDER_HEAP_H_
7
8#include <stddef.h>
9#include <stdint.h>
10
11#include <utility>
12#include <vector>
13
14#include "cppgc/common.h"
15#include "v8-local-handle.h" // NOLINT(build/include_directory)
16#include "v8-traced-handle.h" // NOLINT(build/include_directory)
17#include "v8config.h" // NOLINT(build/include_directory)
18
19namespace v8 {
20
21class Data;
22class Isolate;
23class Value;
24
25namespace internal {
26class LocalEmbedderHeapTracer;
27} // namespace internal
28
33 public:
34 virtual ~EmbedderRootsHandler() = default;
35
51 virtual bool IsRoot(const v8::TracedReference<v8::Value>& handle) = 0;
52
62 virtual void ResetRoot(const v8::TracedReference<v8::Value>& handle) = 0;
63};
64
73 public:
75
76 enum TraceFlags : uint64_t {
77 kNoFlags = 0,
78 kReduceMemory = 1 << 0,
79 kForced = 1 << 2,
80 };
81
86 public:
87 virtual ~TracedGlobalHandleVisitor() = default;
88 virtual void VisitTracedReference(const TracedReference<Value>& handle) {}
89 };
90
95 struct TraceSummary {
100 double time = 0.0;
101
106 size_t allocated_size = 0;
107 };
108
109 virtual ~EmbedderHeapTracer() = default;
110
116
121 void SetStackStart(void* stack_start);
122
130 const std::vector<std::pair<void*, void*>>& embedder_fields) = 0;
131
133
137 virtual void TracePrologue(TraceFlags flags) {}
138
149 virtual bool AdvanceTracing(double deadline_in_ms) = 0;
150
151 /*
152 * Returns true if there no more tracing work to be done (see AdvanceTracing)
153 * and false otherwise.
154 */
155 virtual bool IsTracingDone() = 0;
156
164 virtual void TraceEpilogue(TraceSummary* trace_summary) {}
165
170 virtual void EnterFinalPause(EmbedderStackState stack_state) = 0;
171
172 /*
173 * Called by the embedder to request immediate finalization of the currently
174 * running tracing phase that has been started with TracePrologue and not
175 * yet finished with TraceEpilogue.
176 *
177 * Will be a noop when currently not in tracing.
178 *
179 * This is an experimental feature.
180 */
182
187 const v8::TracedReference<v8::Value>& handle);
188
193 const v8::TracedReference<v8::Value>& handle);
194
195 /*
196 * Called by the embedder to signal newly allocated or freed memory. Not bound
197 * to tracing phases. Embedders should trade off when increments are reported
198 * as V8 may consult global heuristics on whether to trigger garbage
199 * collection on this change.
200 */
201 void IncreaseAllocatedSize(size_t bytes);
202 void DecreaseAllocatedSize(size_t bytes);
203
204 /*
205 * Returns the v8::Isolate this tracer is attached too and |nullptr| if it
206 * is not attached to any v8::Isolate.
207 */
208 v8::Isolate* isolate() const { return isolate_; }
209
210 protected:
211 v8::Isolate* isolate_ = nullptr;
212
213 friend class internal::LocalEmbedderHeapTracer;
214};
215
216} // namespace v8
217
218#endif // INCLUDE_V8_EMBEDDER_HEAP_H_
virtual void VisitTracedReference(const TracedReference< Value > &handle)
virtual void ResetHandleInNonTracingGC(const v8::TracedReference< v8::Value > &handle)
virtual bool IsTracingDone()=0
v8::Isolate * isolate() const
virtual void RegisterV8References(const std::vector< std::pair< void *, void * > > &embedder_fields)=0
virtual bool IsRootForNonTracingGC(const v8::TracedReference< v8::Value > &handle)
void RegisterEmbedderReference(const BasicTracedReference< v8::Data > &ref)
virtual void TraceEpilogue(TraceSummary *trace_summary)
virtual void EnterFinalPause(EmbedderStackState stack_state)=0
void IterateTracedGlobalHandles(TracedGlobalHandleVisitor *visitor)
void DecreaseAllocatedSize(size_t bytes)
void IncreaseAllocatedSize(size_t bytes)
virtual ~EmbedderHeapTracer()=default
void SetStackStart(void *stack_start)
virtual void TracePrologue(TraceFlags flags)
virtual bool AdvanceTracing(double deadline_in_ms)=0
virtual ~EmbedderRootsHandler()=default
virtual bool IsRoot(const v8::TracedReference< v8::Value > &handle)=0
virtual void ResetRoot(const v8::TracedReference< v8::Value > &handle)=0
EmbedderStackState
Definition common.h:16
#define V8_EXPORT
Definition v8config.h:578