Commit ce336fdb authored by Michael Lippautz's avatar Michael Lippautz Committed by Commit Bot

cppgc: Fix {Weak}CrossThreadPersistent destruction

Bug: chromium:1056170
Change-Id: I89dd887a75a475f998d950e86f35c7fe2af5d67f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2743887Reviewed-by: 's avatarOmer Katz <omerkatz@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73307}
parent 0defc528
...@@ -192,10 +192,17 @@ class BasicCrossThreadPersistent final : public PersistentBase, ...@@ -192,10 +192,17 @@ class BasicCrossThreadPersistent final : public PersistentBase,
const void* old_value = GetValue(); const void* old_value = GetValue();
if (IsValid(old_value)) { if (IsValid(old_value)) {
PersistentRegionLock guard; PersistentRegionLock guard;
CrossThreadPersistentRegion& region = old_value = GetValue();
this->GetPersistentRegion(old_value); // The fast path check (IsValid()) does not acquire the lock. Reload
region.FreeNode(GetNode()); // the value to ensure the reference has not been cleared.
SetNode(nullptr); if (IsValid(old_value)) {
CrossThreadPersistentRegion& region =
this->GetPersistentRegion(old_value);
region.FreeNode(GetNode());
SetNode(nullptr);
} else {
CPPGC_DCHECK(!GetNode());
}
} }
SetValue(nullptr); SetValue(nullptr);
} }
...@@ -277,15 +284,22 @@ class BasicCrossThreadPersistent final : public PersistentBase, ...@@ -277,15 +284,22 @@ class BasicCrossThreadPersistent final : public PersistentBase,
const void* old_value = GetValue(); const void* old_value = GetValue();
if (IsValid(old_value)) { if (IsValid(old_value)) {
PersistentRegionLock guard; PersistentRegionLock guard;
CrossThreadPersistentRegion& region = old_value = GetValue();
this->GetPersistentRegion(old_value); // The fast path check (IsValid()) does not acquire the lock. Reload
if (IsValid(ptr) && (&region == &this->GetPersistentRegion(ptr))) { // the value to ensure the reference has not been cleared.
SetValue(ptr); if (IsValid(old_value)) {
this->CheckPointer(ptr); CrossThreadPersistentRegion& region =
return; this->GetPersistentRegion(old_value);
if (IsValid(ptr) && (&region == &this->GetPersistentRegion(ptr))) {
SetValue(ptr);
this->CheckPointer(ptr);
return;
}
region.FreeNode(GetNode());
SetNode(nullptr);
} else {
CPPGC_DCHECK(!GetNode());
} }
region.FreeNode(GetNode());
SetNode(nullptr);
} }
SetValue(ptr); SetValue(ptr);
if (!IsValid(ptr)) return; if (!IsValid(ptr)) return;
......
...@@ -99,6 +99,7 @@ class V8_EXPORT PersistentRegion final { ...@@ -99,6 +99,7 @@ class V8_EXPORT PersistentRegion final {
} }
void FreeNode(PersistentNode* node) { void FreeNode(PersistentNode* node) {
CPPGC_DCHECK(node);
CPPGC_DCHECK(node->IsUsed()); CPPGC_DCHECK(node->IsUsed());
node->InitializeAsFreeNode(free_list_head_); node->InitializeAsFreeNode(free_list_head_);
free_list_head_ = node; free_list_head_ = node;
......
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