5#ifndef INCLUDE_CPPGC_VISITOR_H_
6#define INCLUDE_CPPGC_VISITOR_H_
10#include "cppgc/custom-space.h"
11#include "cppgc/garbage-collected.h"
12#include "cppgc/internal/logging.h"
13#include "cppgc/internal/member-storage.h"
14#include "cppgc/internal/pointer-policies.h"
15#include "cppgc/liveness-broker.h"
16#include "cppgc/macros.h"
17#include "cppgc/member.h"
18#include "cppgc/sentinel-pointer.h"
19#include "cppgc/source-location.h"
20#include "cppgc/trace-trait.h"
21#include "cppgc/type-traits.h"
26template <
typename T,
typename WeaknessPolicy,
typename LocationPolicy,
27 typename CheckingPolicy>
29template <
typename T,
typename WeaknessPolicy,
typename LocationPolicy,
30 typename CheckingPolicy>
32class ConservativeTracingVisitor;
37using WeakCallback =
void (*)(
const LivenessBroker&,
const void*);
40
41
42
43template <
typename K,
typename V>
52 if (!broker.IsHeapObjectAlive(key)) value =
nullptr;
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
88
89
90
91
93 void Trace(
const Member<T>& member) {
94 const T* value = member.GetAtomic();
100
101
102
103
104 template <
typename T>
105 void Trace(
const WeakMember<T>& weak_member) {
106 static_assert(
sizeof(T),
"Pointee type must be fully defined.");
108 "T must be GarbageCollected or GarbageCollectedMixin type");
110 "Weak references to compactable objects are not allowed");
112 const T* value = weak_member.GetAtomic();
120 VisitWeak(value, TraceTrait<T>::GetTraceDescriptor(value),
121 &HandleWeak<WeakMember<T>>, &weak_member);
124#if defined(CPPGC_POINTER_COMPRESSION)
126
127
128
129
130 template <
typename T>
138 template <
typename T>
139 void TraceMultiple(
const subtle::UncompressedMember<T>* start, size_t len) {
140 static_assert(
sizeof(T),
"Pointee type must be fully defined.");
142 "T must be GarbageCollected or GarbageCollectedMixin type");
143 VisitMultipleUncompressedMember(start, len,
147 template <
typename T,
151 static_assert(
sizeof(
T),
"Pointee type must be fully defined.");
153 "T must be GarbageCollected or GarbageCollectedMixin type");
154#if defined(CPPGC_POINTER_COMPRESSION)
156 "Member and CompressedMember must be the same.");
163
164
165
166
167
168 template <
typename T>
180 template <
typename T>
201
202
203
204
205
212
213
214
215
216
217 template <
typename K,
typename V>
226
227
228
229
230
231
255
256
257
258
259
260
261
262
263
264
269 "garbage-collected types must use WeakMember and Member");
290
291
292
293
294 template <
typename T>
302
303
304
305
306 template <
typename T>
312
313
314
315
316
317
318
319 template <
typename T>
329
330
331
332
333
334
335 template <
typename T>
338 "Only references to objects allocated on compactable spaces "
339 "should be registered as movable slots.");
341 "Mixin types do not support compaction.");
346
347
348
349
350
354
355
356
357
358
359
360
361
362
363
364
365
373
374
392 const char*
it =
static_cast<
const char*>(
start);
403#if defined(CPPGC_POINTER_COMPRESSION)
408 const char*
it =
static_cast<
const char*>(
start);
438 template <
typename T>
440 static_assert(
sizeof(
T),
"Pointee type must be fully defined.");
442 "T must be GarbageCollected or GarbageCollectedMixin type");
456 template <
typename T,
typename WeaknessPolicy,
typename LocationPolicy,
457 typename CheckingPolicy>
463template <
typename K,
typename V>
465 visitor->TraceEphemeron(key, value);
474 virtual ~RootVisitor() =
default;
476 template <
typename AnyStrongPersistentType,
478 AnyStrongPersistentType::IsStrongPersistent::value>* =
nullptr>
479 void Trace(
const AnyStrongPersistentType& p) {
480 using PointeeType =
typename AnyStrongPersistentType::PointeeType;
481 const void* object = Extract(p);
485 VisitRoot(object,
TraceTrait<PointeeType>::GetTraceDescriptor(object),
489 template <
typename AnyWeakPersistentType,
491 !AnyWeakPersistentType::IsStrongPersistent::value>* =
nullptr>
492 void Trace(
const AnyWeakPersistentType& p) {
493 using PointeeType =
typename AnyWeakPersistentType::PointeeType;
495 "Weak references to compactable objects are not allowed");
496 const void* object = Extract(p);
500 VisitWeakRoot(object,
TraceTrait<PointeeType>::GetTraceDescriptor(object),
501 &HandleWeak<AnyWeakPersistentType>, &p, p.Location());
505 virtual void VisitRoot(
const void*,
TraceDescriptor, SourceLocation) {}
506 virtual void VisitWeakRoot(
const void* self,
TraceDescriptor, WeakCallback,
507 const void* weak_root, SourceLocation) {}
510 template <
typename AnyPersistentType>
511 static const void* Extract(AnyPersistentType& p) {
512 using PointeeType =
typename AnyPersistentType::PointeeType;
513 static_assert(
sizeof(PointeeType),
514 "Persistent's pointee type must be fully defined");
516 "Persistent's pointee type must be GarbageCollected or "
517 "GarbageCollectedMixin");
518 return p.GetFromGC();
521 template <
typename PointerType>
522 static void HandleWeak(
const LivenessBroker& info,
const void* object) {
523 const PointerType* weak =
static_cast<
const PointerType*>(object);
524 if (!info.IsHeapObjectAlive(weak->GetFromGC())) {
void Trace(const Member< T > &member)
virtual ~Visitor()=default
friend class internal::BasicPersistent
void TraceMultiple(const subtle::UncompressedMember< T > *start, size_t len)
friend class BasicCrossThreadPersistent
#define CPPGC_DCHECK(condition)
#define CPPGC_DISALLOW_NEW()
void ClearValueIfKeyIsDead(const LivenessBroker &broker)
void Trace(Visitor *visitor) const
EphemeronPair(K *k, V *v)
#define V8_WARN_UNUSED_RESULT