RFR: 8367013: Add Atomic<T> to package/replace idiom of volatile var plus AtomicAccess:: operations

Stefan Karlsson stefank at openjdk.org
Mon Sep 29 09:12:53 UTC 2025


On Sun, 28 Sep 2025 11:10:41 GMT, Kim Barrett <kbarrett at openjdk.org> wrote:

> Please review this change that adds the type Atomic<T>, to use as the type
> of a variable that is accessed (including writes) concurrently by multiple
> threads. This is intended to replace (most) uses of the current HotSpot idiom
> of declaring a variable volatile and accessing that variable using functions
> from the AtomicAccess class.
> https://github.com/openjdk/jdk/blame/528f93f8cb9f1fb9c19f31ab80c8a546f47beed2/doc/hotspot-style.md#L138-L147
> 
> This change replaces https://github.com/openjdk/jdk/pull/27462. Differences are
> 
> * Substantially restructured `Atomic<T>`, to be IDE friendly. It's
> operationally the same, with the same API, hence uses and gtests didn't need
> to change in that respect. Thanks to @stefank for raising this issue, and for
> some suggestions toward improvements.
> 
> * Changed how fetch_then_set for atomic translated types is handled, to avoid
> having the function there at all if it isn't usable, rather than just removing
> it via SFINAE, leaving an empty overload set.
> 
> * Added more gtests.
> 
> Testing: mach5 tier1-6, GHA sanity tests

The following isn't a strong request, but maybe more of stated preference and an inquiry what other HotSpot devs think about the proposed names:

1) The proposed `load_relaxed` is visually very similar to `load_release`. So much that I have to double check that the code is using one or the other. The same for `relaxed_store`.

2) I'm no sure about putting the word relaxed before the word store in `relaxed_store`. I understand why it was done for `release_store`, but not really for the relaxed version. The name is also harder to discover. I think I would try to look for a function prefixed with store and not relaxed when trying to remember the name.

So, I would prefer if we would have kept the load/store names.

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

PR Review: https://git.openjdk.org/jdk/pull/27539#pullrequestreview-3278691725


More information about the hotspot-dev mailing list