From a4072803b3de9eae5960411898d480e64c69a030 Mon Sep 17 00:00:00 2001 From: Ryan Macnak Date: Wed, 14 Feb 2024 22:56:49 +0000 Subject: [PATCH] [vm] Avoid data race during Dart_IsolateGroupHeapNewUsedMetric. Precise new-space usage requires looking at all the TLAB pointers and normally only occurs under a GC safepoint. For external queries coarsen the answer to capacity. TEST=g3 Bug: b/324221135 Change-Id: I0e83bbcddba21ddf539fb2afdedf2959cef2c078 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352682 Reviewed-by: Siva Annamalai Commit-Queue: Ryan Macnak --- runtime/vm/metrics.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/runtime/vm/metrics.cc b/runtime/vm/metrics.cc index 1fa5a80b416..59515fcf358 100644 --- a/runtime/vm/metrics.cc +++ b/runtime/vm/metrics.cc @@ -158,7 +158,10 @@ int64_t MetricHeapOldExternal::Value() const { int64_t MetricHeapNewUsed::Value() const { ASSERT(isolate_group() == IsolateGroup::Current()); - return isolate_group()->heap()->UsedInWords(Heap::kNew) * kWordSize; + // UsedInWords requires a safepoint to access all the TLAB pointers without a + // data race, so coarsen this metric to capacity. Preferable to locking during + // new-space allocation. + return isolate_group()->heap()->CapacityInWords(Heap::kNew) * kWordSize; } int64_t MetricHeapNewCapacity::Value() const {