RFR: 8375643: G1: Convert G1RegionMarkStatsCache to use Atomic<T>

Aleksey Shipilev shade at openjdk.org
Tue Jan 20 10:25:20 UTC 2026


On Mon, 19 Jan 2026 16:56:09 GMT, Thomas Schatzl <tschatzl at openjdk.org> wrote:

> Hi all,
> 
>   please review this change to make `G1RegionMarkStatsCache` use `Atomic<T>`.
> 
> The only unusual part is that I added two getters to that class to avoid the repeated `.load_relaxed()` typing.
> 
> Testing: gha
> 
> Thanks,
>   Thomas

Questions...

src/hotspot/share/gc/g1/g1RegionMarkStatsCache.hpp line 119:

> 117:   void add_live_words(uint region_idx, size_t live_words) {
> 118:     G1RegionMarkStatsCacheEntry* const cur = find_for_add(region_idx);
> 119:     cur->_stats._live_words.store_relaxed(cur->_stats.live_words() + live_words);

Is this just `add_then_fetch` with `memory_order_relaxed` then? Or are we trying to dodge some performance penalty avoiding the atomic RMW instructions? I suspect x86 still implicitly does CAS memory effects when doing `cmpxchg` on memory location; `memory_order_relaxed` would not help there.

src/hotspot/share/gc/g1/g1RegionMarkStatsCache.hpp line 124:

> 122:   void inc_incoming_refs(uint region_idx) {
> 123:     G1RegionMarkStatsCacheEntry* const cur = find_for_add(region_idx);
> 124:     cur->_stats._incoming_refs.store_relaxed(cur->_stats.incoming_refs() + 1u);

Same, `add_then_fetch`?

-------------

PR Review: https://git.openjdk.org/jdk/pull/29303#pullrequestreview-3681419236
PR Review Comment: https://git.openjdk.org/jdk/pull/29303#discussion_r2707686756
PR Review Comment: https://git.openjdk.org/jdk/pull/29303#discussion_r2707687279


More information about the hotspot-gc-dev mailing list