Commit cb802efb authored by Omer Katz's avatar Omer Katz Committed by Commit Bot

cppgc: Add TraceStrongly to Visitor

Align the library with the current blink implementation.
TraceStrongly takes a WeakMember and strongifies it so that the
referenced objects is retained.
This is used in blink during tracing of some weak collections.

Bug: chromium:1056170
Change-Id: I306f84fc37a856d309bccc7f544750abb2bdc7c9
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2479003
Commit-Queue: Omer Katz <omerkatz@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Auto-Submit: Omer Katz <omerkatz@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70561}
parent de914c75
...@@ -148,6 +148,18 @@ class V8_EXPORT Visitor { ...@@ -148,6 +148,18 @@ class V8_EXPORT Visitor {
VisitEphemeron(key, value_desc); VisitEphemeron(key, value_desc);
} }
/**
* Trace method that strongifies a WeakMember.
*
* \param weak_member WeakMember reference retaining an object.
*/
template <typename T>
void TraceStrongly(const WeakMember<T>& weak_member) {
const T* value = weak_member.GetRawAtomic();
CPPGC_DCHECK(value != kSentinelPointer);
Trace(value);
}
/** /**
* Registers a weak callback that is invoked during garbage collection. * Registers a weak callback that is invoked during garbage collection.
* *
......
...@@ -306,5 +306,18 @@ TEST_F(MarkingVisitorTest, MarkPersistentMixinInConstruction) { ...@@ -306,5 +306,18 @@ TEST_F(MarkingVisitorTest, MarkPersistentMixinInConstruction) {
EXPECT_FALSE(header.IsMarked()); EXPECT_FALSE(header.IsMarked());
} }
TEST_F(MarkingVisitorTest, StrongTracingMarksWeakMember) {
WeakMember<GCed> object(MakeGarbageCollected<GCed>(GetAllocationHandle()));
HeapObjectHeader& header = HeapObjectHeader::FromPayload(object);
TestMarkingVisitor visitor(GetMarker());
EXPECT_FALSE(header.IsMarked());
visitor.TraceStrongly(object);
EXPECT_TRUE(header.IsMarked());
}
} // namespace internal } // namespace internal
} // namespace cppgc } // namespace cppgc
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment