From c3360ff51155bdd62b758c163351f57f4b410606 Mon Sep 17 00:00:00 2001 From: Thomas Schatzl Date: Mon, 26 Jan 2026 09:17:01 +0000 Subject: [PATCH] 8375983: G1: Convert G1ConcurrentRefineStats to use Atomic Reviewed-by: kbarrett, iwalulya --- .../share/gc/g1/g1ConcurrentRefine.cpp | 1 + .../share/gc/g1/g1ConcurrentRefineStats.cpp | 32 +++-- .../share/gc/g1/g1ConcurrentRefineStats.hpp | 68 +++++----- .../gc/g1/g1ConcurrentRefineStats.inline.hpp | 118 ++++++++++++++++++ .../gc/g1/g1ConcurrentRefineSweepTask.cpp | 1 + .../gc/g1/g1ConcurrentRefineSweepTask.hpp | 2 +- .../share/gc/g1/g1ConcurrentRefineThread.cpp | 2 +- .../share/gc/g1/g1ConcurrentRefineThread.hpp | 1 - src/hotspot/share/gc/g1/g1Policy.cpp | 2 +- .../share/gc/g1/g1YoungGCPreEvacuateTasks.cpp | 1 - 10 files changed, 177 insertions(+), 51 deletions(-) create mode 100644 src/hotspot/share/gc/g1/g1ConcurrentRefineStats.inline.hpp diff --git a/src/hotspot/share/gc/g1/g1ConcurrentRefine.cpp b/src/hotspot/share/gc/g1/g1ConcurrentRefine.cpp index ed6a9ad4292..8546e6e2d64 100644 --- a/src/hotspot/share/gc/g1/g1ConcurrentRefine.cpp +++ b/src/hotspot/share/gc/g1/g1ConcurrentRefine.cpp @@ -28,6 +28,7 @@ #include "gc/g1/g1CollectedHeap.inline.hpp" #include "gc/g1/g1CollectionSet.hpp" #include "gc/g1/g1ConcurrentRefine.hpp" +#include "gc/g1/g1ConcurrentRefineStats.inline.hpp" #include "gc/g1/g1ConcurrentRefineSweepTask.hpp" #include "gc/g1/g1ConcurrentRefineThread.hpp" #include "gc/g1/g1HeapRegion.inline.hpp" diff --git a/src/hotspot/share/gc/g1/g1ConcurrentRefineStats.cpp b/src/hotspot/share/gc/g1/g1ConcurrentRefineStats.cpp index 83a09c55a3f..5160d5ed036 100644 --- a/src/hotspot/share/gc/g1/g1ConcurrentRefineStats.cpp +++ b/src/hotspot/share/gc/g1/g1ConcurrentRefineStats.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -22,7 +22,7 @@ * */ -#include "gc/g1/g1ConcurrentRefineStats.hpp" +#include "gc/g1/g1ConcurrentRefineStats.inline.hpp" #include "runtime/atomicAccess.hpp" #include "runtime/timer.hpp" @@ -39,19 +39,27 @@ G1ConcurrentRefineStats::G1ConcurrentRefineStats() : {} void G1ConcurrentRefineStats::add_atomic(G1ConcurrentRefineStats* other) { - AtomicAccess::add(&_sweep_duration, other->_sweep_duration, memory_order_relaxed); - AtomicAccess::add(&_yield_during_sweep_duration, other->_yield_during_sweep_duration, memory_order_relaxed); + _sweep_duration.add_then_fetch(other->_sweep_duration.load_relaxed(), memory_order_relaxed); + _yield_during_sweep_duration.add_then_fetch(other->yield_during_sweep_duration(), memory_order_relaxed); - AtomicAccess::add(&_cards_scanned, other->_cards_scanned, memory_order_relaxed); - AtomicAccess::add(&_cards_clean, other->_cards_clean, memory_order_relaxed); - AtomicAccess::add(&_cards_not_parsable, other->_cards_not_parsable, memory_order_relaxed); - AtomicAccess::add(&_cards_already_refer_to_cset, other->_cards_already_refer_to_cset, memory_order_relaxed); - AtomicAccess::add(&_cards_refer_to_cset, other->_cards_refer_to_cset, memory_order_relaxed); - AtomicAccess::add(&_cards_no_cross_region, other->_cards_no_cross_region, memory_order_relaxed); + _cards_scanned.add_then_fetch(other->cards_scanned(), memory_order_relaxed); + _cards_clean.add_then_fetch(other->cards_clean(), memory_order_relaxed); + _cards_not_parsable.add_then_fetch(other->cards_not_parsable(), memory_order_relaxed); + _cards_already_refer_to_cset.add_then_fetch(other->cards_already_refer_to_cset(), memory_order_relaxed); + _cards_refer_to_cset.add_then_fetch(other->cards_refer_to_cset(), memory_order_relaxed); + _cards_no_cross_region.add_then_fetch(other->cards_no_cross_region(), memory_order_relaxed); - AtomicAccess::add(&_refine_duration, other->_refine_duration, memory_order_relaxed); + _refine_duration.add_then_fetch(other->refine_duration(), memory_order_relaxed); } void G1ConcurrentRefineStats::reset() { - *this = G1ConcurrentRefineStats(); + _sweep_duration.store_relaxed(0); + _yield_during_sweep_duration.store_relaxed(0); + _cards_scanned.store_relaxed(0); + _cards_clean.store_relaxed(0); + _cards_not_parsable.store_relaxed(0); + _cards_already_refer_to_cset.store_relaxed(0); + _cards_refer_to_cset.store_relaxed(0); + _cards_no_cross_region.store_relaxed(0); + _refine_duration.store_relaxed(0); } diff --git a/src/hotspot/share/gc/g1/g1ConcurrentRefineStats.hpp b/src/hotspot/share/gc/g1/g1ConcurrentRefineStats.hpp index ce22f4317df..5f57c56ba6c 100644 --- a/src/hotspot/share/gc/g1/g1ConcurrentRefineStats.hpp +++ b/src/hotspot/share/gc/g1/g1ConcurrentRefineStats.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,61 +26,61 @@ #define SHARE_GC_G1_G1CONCURRENTREFINESTATS_HPP #include "memory/allocation.hpp" +#include "runtime/atomic.hpp" #include "utilities/globalDefinitions.hpp" -#include "utilities/ticks.hpp" // Collection of statistics for concurrent refinement processing. // Used for collecting per-thread statistics and for summaries over a // collection of threads. class G1ConcurrentRefineStats : public CHeapObj { - jlong _sweep_duration; // Time spent sweeping the table finding non-clean cards - // and refining them. - jlong _yield_during_sweep_duration; // Time spent yielding during the sweep (not doing the sweep). + Atomic _sweep_duration; // Time spent sweeping the table finding non-clean cards + // and refining them. + Atomic _yield_during_sweep_duration; // Time spent yielding during the sweep (not doing the sweep). - size_t _cards_scanned; // Total number of cards scanned. - size_t _cards_clean; // Number of cards found clean. - size_t _cards_not_parsable; // Number of cards we could not parse and left unrefined. - size_t _cards_already_refer_to_cset;// Number of cards marked found to be already young. - size_t _cards_refer_to_cset; // Number of dirty cards that were recently found to contain a to-cset reference. - size_t _cards_no_cross_region; // Number of dirty cards that were dirtied, but then cleaned again by the mutator. + Atomic _cards_scanned; // Total number of cards scanned. + Atomic _cards_clean; // Number of cards found clean. + Atomic _cards_not_parsable; // Number of cards we could not parse and left unrefined. + Atomic _cards_already_refer_to_cset;// Number of cards marked found to be already young. + Atomic _cards_refer_to_cset; // Number of dirty cards that were recently found to contain a to-cset reference. + Atomic _cards_no_cross_region; // Number of dirty cards that were dirtied, but then cleaned again by the mutator. - jlong _refine_duration; // Time spent during actual refinement. + Atomic _refine_duration; // Time spent during actual refinement. public: G1ConcurrentRefineStats(); // Time spent performing sweeping the refinement table (includes actual refinement, // but not yield time). - jlong sweep_duration() const { return _sweep_duration - _yield_during_sweep_duration; } - jlong yield_during_sweep_duration() const { return _yield_during_sweep_duration; } - jlong refine_duration() const { return _refine_duration; } + inline jlong sweep_duration() const; + inline jlong yield_during_sweep_duration() const; + inline jlong refine_duration() const; // Number of refined cards. - size_t refined_cards() const { return cards_not_clean(); } + inline size_t refined_cards() const; - size_t cards_scanned() const { return _cards_scanned; } - size_t cards_clean() const { return _cards_clean; } - size_t cards_not_clean() const { return _cards_scanned - _cards_clean; } - size_t cards_not_parsable() const { return _cards_not_parsable; } - size_t cards_already_refer_to_cset() const { return _cards_already_refer_to_cset; } - size_t cards_refer_to_cset() const { return _cards_refer_to_cset; } - size_t cards_no_cross_region() const { return _cards_no_cross_region; } + inline size_t cards_scanned() const; + inline size_t cards_clean() const; + inline size_t cards_not_clean() const; + inline size_t cards_not_parsable() const; + inline size_t cards_already_refer_to_cset() const; + inline size_t cards_refer_to_cset() const; + inline size_t cards_no_cross_region() const; // Number of cards that were marked dirty and in need of refinement. This includes cards recently // found to refer to the collection set as they originally were dirty. - size_t cards_pending() const { return cards_not_clean() - _cards_already_refer_to_cset; } + inline size_t cards_pending() const; - size_t cards_to_cset() const { return _cards_already_refer_to_cset + _cards_refer_to_cset; } + inline size_t cards_to_cset() const; - void inc_sweep_time(jlong t) { _sweep_duration += t; } - void inc_yield_during_sweep_duration(jlong t) { _yield_during_sweep_duration += t; } - void inc_refine_duration(jlong t) { _refine_duration += t; } + inline void inc_sweep_time(jlong t); + inline void inc_yield_during_sweep_duration(jlong t); + inline void inc_refine_duration(jlong t); - void inc_cards_scanned(size_t increment) { _cards_scanned += increment; } - void inc_cards_clean(size_t increment) { _cards_clean += increment; } - void inc_cards_not_parsable() { _cards_not_parsable++; } - void inc_cards_already_refer_to_cset() { _cards_already_refer_to_cset++; } - void inc_cards_refer_to_cset() { _cards_refer_to_cset++; } - void inc_cards_no_cross_region() { _cards_no_cross_region++; } + inline void inc_cards_scanned(size_t increment); + inline void inc_cards_clean(size_t increment); + inline void inc_cards_not_parsable(); + inline void inc_cards_already_refer_to_cset(); + inline void inc_cards_refer_to_cset(); + inline void inc_cards_no_cross_region(); void add_atomic(G1ConcurrentRefineStats* other); diff --git a/src/hotspot/share/gc/g1/g1ConcurrentRefineStats.inline.hpp b/src/hotspot/share/gc/g1/g1ConcurrentRefineStats.inline.hpp new file mode 100644 index 00000000000..5460dc35bba --- /dev/null +++ b/src/hotspot/share/gc/g1/g1ConcurrentRefineStats.inline.hpp @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE.inline See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +#ifndef SHARE_GC_G1_G1CONCURRENTREFINESTATS_INLINE_HPP +#define SHARE_GC_G1_G1CONCURRENTREFINESTATS_INLINE_HPP + +#include "gc/g1/g1ConcurrentRefineStats.hpp" + +inline jlong G1ConcurrentRefineStats::sweep_duration() const { + return _sweep_duration.load_relaxed() - yield_during_sweep_duration(); +} + +inline jlong G1ConcurrentRefineStats::yield_during_sweep_duration() const { + return _yield_during_sweep_duration.load_relaxed(); +} + +inline jlong G1ConcurrentRefineStats::refine_duration() const { + return _refine_duration.load_relaxed(); +} + +inline size_t G1ConcurrentRefineStats::refined_cards() const { + return cards_not_clean(); +} + +inline size_t G1ConcurrentRefineStats::cards_scanned() const { + return _cards_scanned.load_relaxed(); +} + +inline size_t G1ConcurrentRefineStats::cards_clean() const { + return _cards_clean.load_relaxed(); +} + +inline size_t G1ConcurrentRefineStats::cards_not_clean() const { + return cards_scanned() - cards_clean(); +} + +inline size_t G1ConcurrentRefineStats::cards_not_parsable() const { + return _cards_not_parsable.load_relaxed(); +} + +inline size_t G1ConcurrentRefineStats::cards_already_refer_to_cset() const { + return _cards_already_refer_to_cset.load_relaxed(); +} + +inline size_t G1ConcurrentRefineStats::cards_refer_to_cset() const { + return _cards_refer_to_cset.load_relaxed(); +} + +inline size_t G1ConcurrentRefineStats::cards_no_cross_region() const { + return _cards_no_cross_region.load_relaxed(); +} + +inline size_t G1ConcurrentRefineStats::cards_pending() const { + return cards_not_clean() - cards_already_refer_to_cset(); +} + +inline size_t G1ConcurrentRefineStats::cards_to_cset() const { + return cards_already_refer_to_cset() + cards_refer_to_cset(); +} + +inline void G1ConcurrentRefineStats::inc_sweep_time(jlong t) { + _sweep_duration.store_relaxed(_sweep_duration.load_relaxed() + t); +} + +inline void G1ConcurrentRefineStats::inc_yield_during_sweep_duration(jlong t) { + _yield_during_sweep_duration.store_relaxed(yield_during_sweep_duration() + t); +} + +inline void G1ConcurrentRefineStats::inc_refine_duration(jlong t) { + _refine_duration.store_relaxed(refine_duration() + t); +} + +inline void G1ConcurrentRefineStats::inc_cards_scanned(size_t increment) { + _cards_scanned.store_relaxed(cards_scanned() + increment); +} + +inline void G1ConcurrentRefineStats::inc_cards_clean(size_t increment) { + _cards_clean.store_relaxed(cards_clean() + increment); +} + +inline void G1ConcurrentRefineStats::inc_cards_not_parsable() { + _cards_not_parsable.store_relaxed(cards_not_parsable() + 1); +} + +inline void G1ConcurrentRefineStats::inc_cards_already_refer_to_cset() { + _cards_already_refer_to_cset.store_relaxed(cards_already_refer_to_cset() + 1); +} + +inline void G1ConcurrentRefineStats::inc_cards_refer_to_cset() { + _cards_refer_to_cset.store_relaxed(cards_refer_to_cset() + 1); +} + +inline void G1ConcurrentRefineStats::inc_cards_no_cross_region() { + _cards_no_cross_region.store_relaxed(cards_no_cross_region() + 1); +} + +#endif // SHARE_GC_G1_G1CONCURRENTREFINESTATS_INLINE_HPP diff --git a/src/hotspot/share/gc/g1/g1ConcurrentRefineSweepTask.cpp b/src/hotspot/share/gc/g1/g1ConcurrentRefineSweepTask.cpp index ca5bc9ebe5f..ce944f2254d 100644 --- a/src/hotspot/share/gc/g1/g1ConcurrentRefineSweepTask.cpp +++ b/src/hotspot/share/gc/g1/g1ConcurrentRefineSweepTask.cpp @@ -24,6 +24,7 @@ #include "gc/g1/g1CardTableClaimTable.inline.hpp" #include "gc/g1/g1CollectedHeap.inline.hpp" +#include "gc/g1/g1ConcurrentRefineStats.inline.hpp" #include "gc/g1/g1ConcurrentRefineSweepTask.hpp" class G1RefineRegionClosure : public G1HeapRegionClosure { diff --git a/src/hotspot/share/gc/g1/g1ConcurrentRefineSweepTask.hpp b/src/hotspot/share/gc/g1/g1ConcurrentRefineSweepTask.hpp index bf24c5ae850..827b9a3c402 100644 --- a/src/hotspot/share/gc/g1/g1ConcurrentRefineSweepTask.hpp +++ b/src/hotspot/share/gc/g1/g1ConcurrentRefineSweepTask.hpp @@ -25,10 +25,10 @@ #ifndef SHARE_GC_G1_G1CONCURRENTREFINESWEEPTASK_HPP #define SHARE_GC_G1_G1CONCURRENTREFINESWEEPTASK_HPP -#include "gc/g1/g1ConcurrentRefineStats.hpp" #include "gc/shared/workerThread.hpp" class G1CardTableClaimTable; +class G1ConcurrentRefineStats; class G1ConcurrentRefineSweepTask : public WorkerTask { G1CardTableClaimTable* _scan_state; diff --git a/src/hotspot/share/gc/g1/g1ConcurrentRefineThread.cpp b/src/hotspot/share/gc/g1/g1ConcurrentRefineThread.cpp index eccfe466d48..6b51e5eef62 100644 --- a/src/hotspot/share/gc/g1/g1ConcurrentRefineThread.cpp +++ b/src/hotspot/share/gc/g1/g1ConcurrentRefineThread.cpp @@ -26,7 +26,7 @@ #include "gc/g1/g1CardTableClaimTable.inline.hpp" #include "gc/g1/g1CollectedHeap.inline.hpp" #include "gc/g1/g1ConcurrentRefine.hpp" -#include "gc/g1/g1ConcurrentRefineStats.hpp" +#include "gc/g1/g1ConcurrentRefineStats.inline.hpp" #include "gc/g1/g1ConcurrentRefineSweepTask.hpp" #include "gc/g1/g1ConcurrentRefineThread.hpp" #include "gc/shared/gcTraceTime.inline.hpp" diff --git a/src/hotspot/share/gc/g1/g1ConcurrentRefineThread.hpp b/src/hotspot/share/gc/g1/g1ConcurrentRefineThread.hpp index 7cdc001d348..2ecbdc668eb 100644 --- a/src/hotspot/share/gc/g1/g1ConcurrentRefineThread.hpp +++ b/src/hotspot/share/gc/g1/g1ConcurrentRefineThread.hpp @@ -25,7 +25,6 @@ #ifndef SHARE_GC_G1_G1CONCURRENTREFINETHREAD_HPP #define SHARE_GC_G1_G1CONCURRENTREFINETHREAD_HPP -#include "gc/g1/g1ConcurrentRefineStats.hpp" #include "gc/shared/concurrentGCThread.hpp" #include "runtime/mutex.hpp" #include "utilities/globalDefinitions.hpp" diff --git a/src/hotspot/share/gc/g1/g1Policy.cpp b/src/hotspot/share/gc/g1/g1Policy.cpp index 8818b477aae..1d0b29c303e 100644 --- a/src/hotspot/share/gc/g1/g1Policy.cpp +++ b/src/hotspot/share/gc/g1/g1Policy.cpp @@ -32,7 +32,7 @@ #include "gc/g1/g1ConcurrentMark.hpp" #include "gc/g1/g1ConcurrentMarkThread.inline.hpp" #include "gc/g1/g1ConcurrentRefine.hpp" -#include "gc/g1/g1ConcurrentRefineStats.hpp" +#include "gc/g1/g1ConcurrentRefineStats.inline.hpp" #include "gc/g1/g1GCPhaseTimes.hpp" #include "gc/g1/g1HeapRegion.inline.hpp" #include "gc/g1/g1HeapRegionRemSet.inline.hpp" diff --git a/src/hotspot/share/gc/g1/g1YoungGCPreEvacuateTasks.cpp b/src/hotspot/share/gc/g1/g1YoungGCPreEvacuateTasks.cpp index b11213ddeb3..c0870b7a726 100644 --- a/src/hotspot/share/gc/g1/g1YoungGCPreEvacuateTasks.cpp +++ b/src/hotspot/share/gc/g1/g1YoungGCPreEvacuateTasks.cpp @@ -23,7 +23,6 @@ */ #include "gc/g1/g1CollectedHeap.inline.hpp" -#include "gc/g1/g1ConcurrentRefineStats.hpp" #include "gc/g1/g1RegionPinCache.inline.hpp" #include "gc/g1/g1ThreadLocalData.hpp" #include "gc/g1/g1YoungGCPreEvacuateTasks.hpp"