cppgc: Deprecate (soon) cppgc::Visitor::Trace(T*)

We will provide a replacement for raw pointers in future which should
only be used by backing stores. Any other callsite must go through
Trace(BasicMember<>).

Bug: v8:13089
Change-Id: Ibdae439b44ad94bd7af2532855be941c5334db99
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3772328
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: Anton Bikineev <bikineev@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81833}
This commit is contained in:
Michael Lippautz 2022-07-19 19:36:03 +02:00 committed by V8 LUCI CQ
parent 1091597dc7
commit eb4e0241d7
4 changed files with 25 additions and 12 deletions

View File

@ -68,14 +68,9 @@ class V8_EXPORT Visitor {
* \param member Reference retaining an object.
*/
template <typename T>
V8_DEPRECATE_SOON("Do not use Trace() with raw pointers.")
void Trace(const T* t) {
static_assert(sizeof(T), "Pointee type must be fully defined.");
static_assert(internal::IsGarbageCollectedOrMixinType<T>::value,
"T must be GarbageCollected or GarbageCollectedMixin type");
if (!t) {
return;
}
Visit(t, TraceTrait<T>::GetTraceDescriptor(t));
TraceImpl(t);
}
/**
@ -87,7 +82,7 @@ class V8_EXPORT Visitor {
void Trace(const Member<T>& member) {
const T* value = member.GetRawAtomic();
CPPGC_DCHECK(value != kSentinelPointer);
Trace(value);
TraceImpl(value);
}
/**
@ -231,7 +226,7 @@ class V8_EXPORT Visitor {
void TraceStrongly(const WeakMember<T>& weak_member) {
const T* value = weak_member.GetRawAtomic();
CPPGC_DCHECK(value != kSentinelPointer);
Trace(value);
TraceImpl(value);
}
/**
@ -361,6 +356,17 @@ class V8_EXPORT Visitor {
&HandleWeak<WeakPersistent>, &p, loc);
}
template <typename T>
void TraceImpl(const T* t) {
static_assert(sizeof(T), "Pointee type must be fully defined.");
static_assert(internal::IsGarbageCollectedOrMixinType<T>::value,
"T must be GarbageCollected or GarbageCollectedMixin type");
if (!t) {
return;
}
Visit(t, TraceTrait<T>::GetTraceDescriptor(t));
}
#if V8_ENABLE_CHECKS
void CheckObjectNotInConstruction(const void* address);
#endif // V8_ENABLE_CHECKS

View File

@ -34,6 +34,11 @@ class VisitorBase : public cppgc::Visitor {
void TraceRootForTesting(const Persistent& p, const SourceLocation& loc) {
TraceRoot(p, loc);
}
template <typename T>
static void TraceRawForTesting(cppgc::Visitor* visitor, const T* t) {
visitor->TraceImpl(t);
}
};
// Regular visitor that additionally allows for conservative tracing.

View File

@ -31,7 +31,8 @@ struct CompactableGCed : public GarbageCollected<CompactableGCed> {
public:
~CompactableGCed() { ++g_destructor_callcount; }
void Trace(Visitor* visitor) const {
visitor->Trace(const_cast<const CompactableGCed*>(other));
VisitorBase::TraceRawForTesting(visitor,
const_cast<const CompactableGCed*>(other));
visitor->RegisterMovableReference(
const_cast<const CompactableGCed**>(&other));
}
@ -53,7 +54,8 @@ struct CompactableHolder
void Trace(Visitor* visitor) const {
for (int i = 0; i < kNumObjects; ++i) {
visitor->Trace(const_cast<const CompactableGCed*>(objects[i]));
VisitorBase::TraceRawForTesting(
visitor, const_cast<const CompactableGCed*>(objects[i]));
visitor->RegisterMovableReference(
const_cast<const CompactableGCed**>(&objects[i]));
}

View File

@ -373,7 +373,7 @@ class ObjectWithEphemeronPair final
// the main marking worklist empty. If recording the ephemeron pair doesn't
// as well, we will get a crash when destroying the marker.
visitor->Trace(ephemeron_pair_);
visitor->Trace(const_cast<const SimpleObject*>(ephemeron_pair_.key.Get()));
visitor->TraceStrongly(ephemeron_pair_.key);
}
private: