5#ifndef INCLUDE_CPPGC_VISITOR_H_
6#define INCLUDE_CPPGC_VISITOR_H_
23template <
typename T,
typename WeaknessPolicy,
typename LocationPolicy,
24 typename CheckingPolicy>
25class BasicCrossThreadPersistent;
26template <
typename T,
typename WeaknessPolicy,
typename LocationPolicy,
27 typename CheckingPolicy>
29class ConservativeTracingVisitor;
58 friend class internal::VisitorFactory;
72 static_assert(
sizeof(T),
"Pointee type must be fully defined.");
74 "T must be GarbageCollected or GarbageCollectedMixin type");
88 const T* value = member.GetRawAtomic();
100 static_assert(
sizeof(T),
"Pointee type must be fully defined.");
102 "T must be GarbageCollected or GarbageCollectedMixin type");
104 "Weak references to compactable objects are not allowed");
106 const T* value = weak_member.GetRawAtomic();
124 template <
typename T>
131 CheckObjectNotInConstruction(&
object);
142 template <
typename T,
void (T::*method)(const LivenessBroker&)>
144 RegisterWeakCallback(&WeakCallbackMethodDelegate<T, method>,
object);
153 template <
typename K,
typename V>
155 TraceEphemeron(ephemeron_pair.
key, &ephemeron_pair.
value);
156 RegisterWeakCallbackMethod<EphemeronPair<K, V>,
168 template <
typename KeyType,
typename ValueType>
171 const KeyType* key = weak_member_key.GetRawAtomic();
176 const ValueType* value = member_value->GetRawAtomic();
183 const void* key_base_object_payload =
187 VisitEphemeron(key_base_object_payload, value, value_desc);
201 template <
typename KeyType,
typename ValueType>
203 const ValueType* value) {
204 static_assert(!IsGarbageCollectedOrMixinTypeV<ValueType>,
205 "garbage-collected types must use WeakMember and Member");
206 const KeyType* key = weak_member_key.GetRawAtomic();
218 const void* key_base_object_payload =
222 VisitEphemeron(key_base_object_payload, value, value_desc);
230 template <
typename T>
232 const T* value = weak_member.GetRawAtomic();
244 template <
typename T>
259 template <
typename T>
262 "Only references to objects allocated on compactable spaces "
263 "should be registered as movable slots.");
264 static_assert(!IsGarbageCollectedMixinTypeV<T>,
265 "Mixin types do not support compaction.");
266 HandleMovableReference(
reinterpret_cast<const void**
>(slot));
291 const void* parameter,
TraceCallback callback,
size_t deferred_size) {
299 const void* weak_member) {}
311 template <
typename T,
void (T::*method)(const LivenessBroker&)>
312 static void WeakCallbackMethodDelegate(
const LivenessBroker& info,
316 (
const_cast<T*
>(
static_cast<const T*
>(self))->*method)(info);
319 template <
typename Po
interType>
320 static void HandleWeak(
const LivenessBroker& info,
const void*
object) {
321 const PointerType* weak =
static_cast<const PointerType*
>(object);
322 auto* raw_ptr = weak->GetFromGC();
324 if (raw_ptr == kSentinelPointer)
return;
325 if (!info.IsHeapObjectAlive(raw_ptr)) {
331 std::enable_if_t<Persistent::IsStrongPersistent::value>* =
nullptr>
332 void TraceRoot(
const Persistent& p,
const SourceLocation& loc) {
333 using PointeeType =
typename Persistent::PointeeType;
334 static_assert(
sizeof(PointeeType),
335 "Persistent's pointee type must be fully defined");
336 static_assert(internal::IsGarbageCollectedOrMixinType<PointeeType>::value,
337 "Persistent's pointee type must be GarbageCollected or "
338 "GarbageCollectedMixin");
339 auto* ptr = p.GetFromGC();
343 VisitRoot(ptr, TraceTrait<PointeeType>::GetTraceDescriptor(ptr), loc);
348 std::enable_if_t<!WeakPersistent::IsStrongPersistent::value>* =
nullptr>
349 void TraceRoot(
const WeakPersistent& p,
const SourceLocation& loc) {
350 using PointeeType =
typename WeakPersistent::PointeeType;
351 static_assert(
sizeof(PointeeType),
352 "Persistent's pointee type must be fully defined");
353 static_assert(internal::IsGarbageCollectedOrMixinType<PointeeType>::value,
354 "Persistent's pointee type must be GarbageCollected or "
355 "GarbageCollectedMixin");
356 static_assert(!internal::IsAllocatedOnCompactableSpace<PointeeType>::value,
357 "Weak references to compactable objects are not allowed");
358 auto* ptr = p.GetFromGC();
359 VisitWeakRoot(ptr, TraceTrait<PointeeType>::GetTraceDescriptor(ptr),
360 &HandleWeak<WeakPersistent>, &p, loc);
364 void CheckObjectNotInConstruction(
const void* address);
367 template <
typename T,
typename WeaknessPolicy,
typename LocationPolicy,
368 typename CheckingPolicy>
370 template <
typename T,
typename WeaknessPolicy,
typename LocationPolicy,
371 typename CheckingPolicy>
373 friend class internal::ConservativeTracingVisitor;
374 friend class internal::VisitorBase;
virtual V8_WARN_UNUSED_RESULT bool DeferTraceToMutatorThreadIfConcurrent(const void *parameter, TraceCallback callback, size_t deferred_size)
void Trace(const WeakMember< T > &weak_member)
void Trace(const EphemeronPair< K, V > &ephemeron_pair)
void RegisterMovableReference(const T **slot)
void TraceWeakContainer(const T *object, WeakCallback callback, const void *data)
void Trace(const Member< T > &member)
virtual void VisitEphemeron(const void *key, const void *value, TraceDescriptor value_desc)
virtual ~Visitor()=default
void TraceEphemeron(const WeakMember< KeyType > &weak_member_key, const ValueType *value)
void Trace(const T &object)
virtual void VisitRoot(const void *, TraceDescriptor, const SourceLocation &)
void RegisterWeakCallbackMethod(const T *object)
virtual void VisitWeak(const void *self, TraceDescriptor, WeakCallback, const void *weak_member)
virtual void VisitWeakRoot(const void *self, TraceDescriptor, WeakCallback, const void *weak_root, const SourceLocation &)
virtual void VisitWeakContainer(const void *self, TraceDescriptor strong_desc, TraceDescriptor weak_desc, WeakCallback callback, const void *data)
virtual void HandleMovableReference(const void **)
void TraceEphemeron(const WeakMember< KeyType > &weak_member_key, const Member< ValueType > *member_value)
void TraceStrongly(const WeakMember< T > &weak_member)
virtual void RegisterWeakCallback(WeakCallback callback, const void *data)
virtual void Visit(const void *self, TraceDescriptor)
#define CPPGC_DCHECK(condition)
internal::BasicPersistent< T, internal::WeakPersistentPolicy > WeakPersistent
void(*)(Visitor *visitor, const void *object) TraceCallback
void(*)(const LivenessBroker &, const void *) WeakCallback
constexpr internal::SentinelPointer kSentinelPointer
internal::BasicPersistent< T, internal::StrongPersistentPolicy > Persistent
const void * base_object_payload
#define V8_WARN_UNUSED_RESULT