Commit b2e05eb5 authored by Omer Katz's avatar Omer Katz Committed by V8 LUCI CQ

cppgc: Fix race in RegisterWeakReferenceIfNeeded

As an optimization, RegisterWeakReferenceIfNeeded checks whether the
target object is marked, and only registers it if it's not marked.
The target object may still be under construction, in which case
checking the mark bit will race with allocating the object.

Bug: chromium:1056170, chromium:1232339
Change-Id: I0a41afba7f48f288f708441176f89509a81ebb09
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3048171
Commit-Queue: Omer Katz <omerkatz@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75879}
parent 1e7effd1
......@@ -229,8 +229,10 @@ void MarkingStateBase::RegisterWeakReferenceIfNeeded(const void* object,
// Filter out already marked values. The write barrier for WeakMember
// ensures that any newly set value after this point is kept alive and does
// not require the callback.
if (HeapObjectHeader::FromObject(desc.base_object_payload)
.IsMarked<AccessMode::kAtomic>())
const HeapObjectHeader& header =
HeapObjectHeader::FromObject(desc.base_object_payload);
if (!header.IsInConstruction<AccessMode::kAtomic>() &&
header.IsMarked<AccessMode::kAtomic>())
return;
RegisterWeakCallback(weak_callback, parameter);
}
......
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