RFR: 8375643: G1: Convert G1RegionMarkStatsCache to use Atomic<T>
Aleksey Shipilev
shade at openjdk.org
Tue Jan 20 10:25:21 UTC 2026
On Tue, 20 Jan 2026 10:16:18 GMT, Aleksey Shipilev <shade 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
>
> 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.
Actually, what _are_ the atomicity requirements here? Is this code supposed to be called on same region stats by multiple threads? Or is this single threaded?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/29303#discussion_r2707705008
More information about the hotspot-gc-dev
mailing list