RFR: 8375974: G1: Convert G1FullCollector to use Atomic<T>

Kim Barrett kbarrett at openjdk.org
Wed Jan 21 16:51:08 UTC 2026


On Wed, 21 Jan 2026 11:34:33 GMT, Thomas Schatzl <tschatzl at openjdk.org> wrote:

> Hi all,
> 
>   please review this change to convert `G1FullCollector` to use `Atomic<T>`.
> 
> Testing: gha
> 
> Thanks,
>   Thomas

Changes requested by kbarrett (Reviewer).

src/hotspot/share/gc/g1/g1FullCollector.cpp line 140:

> 138:   for (uint j = 0; j < heap->max_num_regions(); j++) {
> 139:     _live_stats[j].clear();
> 140:     _compaction_tops[j].store_relaxed(nullptr);

We haven't constructed any objects here yet, so technically this is UB.  Better is something like

::new (&_compaction_tops[j]) Atomic<HeapWord*>{}

src/hotspot/share/gc/g1/g1FullCollector.inline.hpp line 66:

> 64: 
> 65: void G1FullCollector::set_compaction_top(G1HeapRegion* r, HeapWord* value) {
> 66:   _compaction_tops[r->hrm_index()].store_relaxed(value);

We seem to only be doing relaxed load/store.  What is the concurrent usage model here that
needs atomics?

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

PR Review: https://git.openjdk.org/jdk/pull/29342#pullrequestreview-3688280858
PR Review Comment: https://git.openjdk.org/jdk/pull/29342#discussion_r2713431501
PR Review Comment: https://git.openjdk.org/jdk/pull/29342#discussion_r2713447533


More information about the hotspot-gc-dev mailing list