Commit bf72abd4 authored by Michael Lippautz's avatar Michael Lippautz Committed by V8 LUCI CQ

cppgc: Avoid using process global mutex for HeapRegistry

Marking holds the process wide mutex for synchronizing CrossThread*
references. In addition, marking may also create temporary copies of
Member references for concurrent tracing (snapshot).

Provide HeapRegistry with its own mutex to avoid a deadlock with
Member checking during marking.

Bug: chromium:1056170
Change-Id: I31d922ec1a476942e29d8d4fa7d864a015f428cc
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2904211
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Commit-Queue: Omer Katz <omerkatz@chromium.org>
Auto-Submit: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: 's avatarOmer Katz <omerkatz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#74646}
parent dd851156
......@@ -19,6 +19,8 @@ v8::base::LazyMutex g_process_mutex = LAZY_MUTEX_INITIALIZER;
namespace {
v8::base::LazyMutex g_heap_registry_mutex = LAZY_MUTEX_INITIALIZER;
HeapRegistry::Storage& GetHeapRegistryStorage() {
static v8::base::LazyInstance<HeapRegistry::Storage>::type heap_registry =
LAZY_INSTANCE_INITIALIZER;
......@@ -29,7 +31,7 @@ HeapRegistry::Storage& GetHeapRegistryStorage() {
// static
void HeapRegistry::RegisterHeap(HeapBase& heap) {
v8::base::MutexGuard guard(g_process_mutex.Pointer());
v8::base::MutexGuard guard(g_heap_registry_mutex.Pointer());
auto& storage = GetHeapRegistryStorage();
DCHECK_EQ(storage.end(), std::find(storage.begin(), storage.end(), &heap));
......@@ -38,7 +40,7 @@ void HeapRegistry::RegisterHeap(HeapBase& heap) {
// static
void HeapRegistry::UnregisterHeap(HeapBase& heap) {
v8::base::MutexGuard guard(g_process_mutex.Pointer());
v8::base::MutexGuard guard(g_heap_registry_mutex.Pointer());
auto& storage = GetHeapRegistryStorage();
const auto pos = std::find(storage.begin(), storage.end(), &heap);
......@@ -48,7 +50,7 @@ void HeapRegistry::UnregisterHeap(HeapBase& heap) {
// static
HeapBase* HeapRegistry::TryFromManagedPointer(const void* needle) {
v8::base::MutexGuard guard(g_process_mutex.Pointer());
v8::base::MutexGuard guard(g_heap_registry_mutex.Pointer());
for (auto* heap : GetHeapRegistryStorage()) {
const auto address =
......
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