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

Kim Barrett kbarrett at openjdk.org
Wed Sep 24 05:39:37 UTC 2025


On Wed, 24 Sep 2025 05:32:38 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
> 
> Testing: mach5 tier1-6, GHA sanity tests

The implementation of `Atomic<T>` leans heavily on `AtomicAccess`. But note
that some of the `Atomic<T>` function names differ from the corresponding
`AtomicAccess` function names. Without the `AtomicAccess::` prefix, the names
from that class are in some cases subtle and easy to overlook, which is not a
benefit when dealing with the complexities of lock-free code.

This PR includes gtests for the new type. These gtests only test functional
behavior, not concurrent access behavior.

This PR also includes conversions for a few uses. This provides examples of
what the new code will look like. It also provides some additional testing for
this change. The plan is that other uses of the `volatile` + `AtomicAccess`
idiom will be converted incrementally. It is expected that there will be some
remaining direct uses of `AtomicAccess`, in places where conversion to
`Atomic<T>` isn't appropriate. An example is the `BitMap::par_xxx` suite of
functions.

This PR contains a sequence of commits, each covering different aspects of the
change. It might help to focus on particular commits when reviewing.

The HotSpot Style Guide needs to be updated for JDK-8367014 and for this
change. That will be done in a followup.

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

PR Comment: https://git.openjdk.org/jdk/pull/27462#issuecomment-3326608037


More information about the hotspot-dev mailing list