From 5f1355b0851d95a53a760fa045e16d9bde3d1a04 Mon Sep 17 00:00:00 2001 From: Thomas Schatzl Date: Mon, 29 Jun 2026 08:45:26 +0000 Subject: [PATCH] 8387322: G1: G1CSetCandidateGroupList::_num_regions should be Atomic Reviewed-by: stefank --- src/hotspot/share/gc/g1/g1CollectionSetCandidates.cpp | 10 +++++----- src/hotspot/share/gc/g1/g1CollectionSetCandidates.hpp | 5 +++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/hotspot/share/gc/g1/g1CollectionSetCandidates.cpp b/src/hotspot/share/gc/g1/g1CollectionSetCandidates.cpp index 3637d477229..ac1b29a6bd7 100644 --- a/src/hotspot/share/gc/g1/g1CollectionSetCandidates.cpp +++ b/src/hotspot/share/gc/g1/g1CollectionSetCandidates.cpp @@ -134,7 +134,7 @@ void G1CSetCandidateGroupList::append(G1CSetCandidateGroup* group) { assert(group->length() > 0, "Do not add empty groups"); assert(!_groups.contains(group), "Already added to list"); _groups.append(group); - _num_regions += group->length(); + _num_regions.store_relaxed(num_regions() + group->length()); } G1CSetCandidateGroup* G1CSetCandidateGroupList::at(uint index) { @@ -147,7 +147,7 @@ void G1CSetCandidateGroupList::clear(bool uninstall_group_cardset) { delete gr; } _groups.clear(); - _num_regions = 0; + _num_regions.store_relaxed(0); } void G1CSetCandidateGroupList::prepare_for_scan() { @@ -156,9 +156,9 @@ void G1CSetCandidateGroupList::prepare_for_scan() { } } -void G1CSetCandidateGroupList::remove_selected(uint count, uint num_regions) { +void G1CSetCandidateGroupList::remove_selected(uint count, uint num_regions_to_remove) { _groups.remove_till(count); - _num_regions -= num_regions; + _num_regions.store_relaxed(num_regions() - num_regions_to_remove); } void G1CSetCandidateGroupList::remove(G1CSetCandidateGroupList* other) { @@ -172,7 +172,7 @@ void G1CSetCandidateGroupList::remove(G1CSetCandidateGroupList* other) { // Create a list from scratch, copying over the elements from the candidate // list not in the other list. Finally deallocate and overwrite the old list. int new_length = _groups.length() - other->length(); - _num_regions = num_regions() - other->num_regions(); + _num_regions.store_relaxed(num_regions() - other->num_regions()); GrowableArray new_list(new_length, mtGC); uint other_idx = 0; diff --git a/src/hotspot/share/gc/g1/g1CollectionSetCandidates.hpp b/src/hotspot/share/gc/g1/g1CollectionSetCandidates.hpp index 8a2235cf89c..a70f9e395b6 100644 --- a/src/hotspot/share/gc/g1/g1CollectionSetCandidates.hpp +++ b/src/hotspot/share/gc/g1/g1CollectionSetCandidates.hpp @@ -29,6 +29,7 @@ #include "gc/g1/g1CollectionSetCandidates.hpp" #include "gc/shared/gc_globals.hpp" #include "memory/allocation.hpp" +#include "runtime/atomic.hpp" #include "runtime/globals.hpp" #include "utilities/growableArray.hpp" @@ -147,7 +148,7 @@ using G1CSetCandidateGroupListIterator = GrowableArrayIterator _groups; - volatile uint _num_regions; + Atomic _num_regions; public: G1CSetCandidateGroupList(); @@ -163,7 +164,7 @@ public: uint length() const { return (uint)_groups.length(); } - uint num_regions() const { return _num_regions; } + uint num_regions() const { return _num_regions.load_relaxed(); } void remove_selected(uint count, uint num_regions);