From ebb23b943468cfac5b434dd479cfae34d8efcd8a Mon Sep 17 00:00:00 2001 From: Michael Lippautz Date: Wed, 12 Jan 2022 17:28:40 +0100 Subject: [PATCH] heap: Fix race on a field used for stress marking mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The field is updated on the main thread and read on threads using LocalHeap to possibly trigger GC in fuzzing configurations. Bug: chromium:1286699 Change-Id: I15330b7542358ce1a2307a1f258655126b252c03 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3383776 Reviewed-by: Dominik Inführ Commit-Queue: Michael Lippautz Cr-Commit-Position: refs/heads/main@{#78591} --- src/heap/heap.cc | 6 ++++-- src/heap/heap.h | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/heap/heap.cc b/src/heap/heap.cc index f329929535..22ac69295f 100644 --- a/src/heap/heap.cc +++ b/src/heap/heap.cc @@ -5414,8 +5414,10 @@ Heap::IncrementalMarkingLimit Heap::IncrementalMarkingLimitReached() { max_marking_limit_reached_ = std::max(max_marking_limit_reached_, current_percent); } - } else if (current_percent >= stress_marking_percentage_) { - stress_marking_percentage_ = NextStressMarkingLimit(); + } else if (current_percent >= + stress_marking_percentage_.load(std::memory_order_relaxed)) { + stress_marking_percentage_.store(NextStressMarkingLimit(), + std::memory_order_relaxed); return IncrementalMarkingLimit::kHardLimit; } } diff --git a/src/heap/heap.h b/src/heap/heap.h index cd1e4fa4a3..ceb6e9d05c 100644 --- a/src/heap/heap.h +++ b/src/heap/heap.h @@ -2290,10 +2290,10 @@ class Heap { // Starts marking when stress_marking_percentage_% of the marking start limit // is reached. - int stress_marking_percentage_ = 0; + std::atomic stress_marking_percentage_{0}; - // Observer that causes more frequent checks for reached incremental marking - // limit. + // Observer that causes more frequent checks for reached incremental + // marking limit. AllocationObserver* stress_marking_observer_ = nullptr; // Observer that can cause early scavenge start.