Integrated: 8374878: Add Atomic<T>::compare_set

Aleksey Shipilev shade at openjdk.org
Sun Jan 11 20:41:13 UTC 2026


On Fri, 9 Jan 2026 09:47:18 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:

> Following up on [JDK-8367013](https://bugs.openjdk.org/browse/JDK-8367013) improvement, there is an opportunity to rewrite some of our low-level `cas(oldv, newv) == oldv` patterns to more straight-forward compare-and-set helper method. This is useful when you do not actually care about the result that used to be in memory or that is currently in memory, you only care if CAS succeeded or not.
> 
> Java atomics already have this duality; arguably due to historical timeline of having compare-and-set before introducing compare-and-exchange.
> 
> Found this when converting Epsilon to Atomic<T> ([JDK-8374876](https://bugs.openjdk.org/browse/JDK-8374876)), where this method would simplify the code a bit. I looked around current uses of `compare_exchange` and rewrote them to `compare_set` to show what simplifications are possible.
> 
> Additional testing:
>  - [x] Linux x86_64 server fastdebug, `all`

This pull request has now been integrated.

Changeset: 33689485
Author:    Aleksey Shipilev <shade at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/336894857bfc9f610da55e6180dd7b668bf67752
Stats:     56 lines in 8 files changed: 42 ins; 1 del; 13 mod

8374878: Add Atomic<T>::compare_set

Reviewed-by: kbarrett, stefank

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

PR: https://git.openjdk.org/jdk/pull/29135


More information about the hotspot-dev mailing list