[wasm][gc] Use acquire-release semantics for ref count
TSan reports errors if one thread changes the ref count using relaxed semantics, then another thread frees the code object. Acquire-release semantics fix this, as they impose an ordering between the memory accesses of different threads. R=mstarzinger@chromium.org Bug: v8:8217, v8:9200 Change-Id: I30ce150154e6459c2c64e16be603f29187af1dcd Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1594553 Commit-Queue: Clemens Hammacher <clemensh@chromium.org> Reviewed-by: Michael Starzinger <mstarzinger@chromium.org> Cr-Commit-Position: refs/heads/master@{#61205}
This commit is contained in:
parent
9a69ae3d6e
commit
02ebf5879f
@ -148,7 +148,7 @@ class V8_EXPORT_PRIVATE WasmCode final {
|
||||
~WasmCode();
|
||||
|
||||
void IncRef() {
|
||||
int old_val = ref_count_.fetch_add(1, std::memory_order_relaxed);
|
||||
int old_val = ref_count_.fetch_add(1, std::memory_order_acq_rel);
|
||||
DCHECK_LE(1, old_val);
|
||||
DCHECK_GT(kMaxInt, old_val);
|
||||
USE(old_val);
|
||||
@ -157,12 +157,12 @@ class V8_EXPORT_PRIVATE WasmCode final {
|
||||
// Decrement the ref count. Returns whether this code becomes dead and needs
|
||||
// to be freed.
|
||||
V8_WARN_UNUSED_RESULT bool DecRef() {
|
||||
int old_count = ref_count_.load(std::memory_order_relaxed);
|
||||
int old_count = ref_count_.load(std::memory_order_acquire);
|
||||
while (true) {
|
||||
DCHECK_LE(1, old_count);
|
||||
if (V8_UNLIKELY(old_count == 1)) return DecRefOnPotentiallyDeadCode();
|
||||
if (ref_count_.compare_exchange_weak(old_count, old_count - 1,
|
||||
std::memory_order_relaxed)) {
|
||||
std::memory_order_acq_rel)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -172,7 +172,7 @@ class V8_EXPORT_PRIVATE WasmCode final {
|
||||
// might still be C++ references. Returns whether this drops the last
|
||||
// reference and the code needs to be freed.
|
||||
V8_WARN_UNUSED_RESULT bool DecRefOnDeadCode() {
|
||||
return ref_count_.fetch_sub(1, std::memory_order_relaxed) == 1;
|
||||
return ref_count_.fetch_sub(1, std::memory_order_acq_rel) == 1;
|
||||
}
|
||||
|
||||
// Decrement the ref count on a set of {WasmCode} objects, potentially
|
||||
|
Loading…
Reference in New Issue
Block a user