5 #ifndef INCLUDE_CPPGC_VISITOR_H_
6 #define INCLUDE_CPPGC_VISITOR_H_
8 #include "cppgc/custom-space.h"
9 #include "cppgc/ephemeron-pair.h"
10 #include "cppgc/garbage-collected.h"
11 #include "cppgc/internal/logging.h"
12 #include "cppgc/internal/pointer-policies.h"
13 #include "cppgc/liveness-broker.h"
14 #include "cppgc/member.h"
15 #include "cppgc/source-location.h"
16 #include "cppgc/trace-trait.h"
17 #include "cppgc/type-traits.h"
22 template <
typename T,
typename WeaknessPolicy,
typename LocationPolicy,
23 typename CheckingPolicy>
25 template <
typename T,
typename WeaknessPolicy,
typename LocationPolicy,
26 typename CheckingPolicy>
28 class ConservativeTracingVisitor;
33 using WeakCallback =
void (*)(
const LivenessBroker&,
const void*);
71 static_assert(
sizeof(T),
"Pointee type must be fully defined.");
73 "T must be GarbageCollected or GarbageCollectedMixin type");
86 void Trace(
const Member<T>& member) {
87 const T* value = member.GetRawAtomic();
98 void Trace(
const WeakMember<T>& weak_member) {
99 static_assert(
sizeof(T),
"Pointee type must be fully defined.");
101 "T must be GarbageCollected or GarbageCollectedMixin type");
103 "Weak references to compactable objects are not allowed");
105 const T* value = weak_member.GetRawAtomic();
114 &HandleWeak<WeakMember<T>>
, &weak_member
);
123 template <
typename T>
130 CheckObjectNotInConstruction(&object);
141 template <
typename T,
void (T::*method)(
const LivenessBroker&)>
152 template <
typename K,
typename V>
154 TraceEphemeron(ephemeron_pair.key, &ephemeron_pair.value);
167 template <
typename K,
typename V>
169 const K* k = key.GetRawAtomic();
184 template <
typename T>
186 const T* value = weak_member.GetRawAtomic();
198 template <
typename T>
203 TraceTrait<T>::GetWeakTraceDescriptor(object)
, callback
,
213 template <
typename T>
216 "Only references to objects allocated on compactable spaces "
217 "should be registered as movable slots.");
218 static_assert(!IsGarbageCollectedMixinTypeV<T>,
219 "Mixin types do not support compaction.");
245 const void* parameter, TraceCallback callback, size_t deferred_size) {
253 const void* weak_member) {}
261 WeakCallback callback,
const void* data) {}
265 template <
typename T,
void (T::*method)(
const LivenessBroker&)>
266 static void WeakCallbackMethodDelegate(
const LivenessBroker& info,
270 (
const_cast<T*>(
static_cast<
const T*>(self))->*method)(info);
273 template <
typename PointerType>
274 static void HandleWeak(
const LivenessBroker& info,
const void* object) {
275 const PointerType* weak =
static_cast<
const PointerType*>(object);
278 const auto* raw = weak->Get();
279 if (!info.IsHeapObjectAlive(raw)) {
284 template <
typename Persistent,
285 std::enable_if_t<Persistent::IsStrongPersistent::value>* =
nullptr>
287 using PointeeType =
typename Persistent::PointeeType;
288 static_assert(
sizeof(PointeeType),
289 "Persistent's pointee type must be fully defined");
291 "Persistent's pointee type must be GarbageCollected or "
292 "GarbageCollectedMixin");
301 typename WeakPersistent,
302 std::enable_if_t<!WeakPersistent::IsStrongPersistent::value>* =
nullptr>
303 void TraceRoot(
const WeakPersistent& p,
const SourceLocation& loc) {
304 using PointeeType =
typename WeakPersistent::PointeeType;
305 static_assert(
sizeof(PointeeType),
306 "Persistent's pointee type must be fully defined");
308 "Persistent's pointee type must be GarbageCollected or "
309 "GarbageCollectedMixin");
311 "Weak references to compactable objects are not allowed");
313 &HandleWeak<WeakPersistent>
, &p
, loc
);
320 template <
typename T,
typename WeaknessPolicy,
typename LocationPolicy,
321 typename CheckingPolicy>
323 template <
typename T,
typename WeaknessPolicy,
typename LocationPolicy,
324 typename CheckingPolicy>
330 template <
typename T>
334 static_cast<
const Member<T>*>(self)->GetRawAtomic());