RFR: 8374878: Add Atomic<T>::compare_set
Aleksey Shipilev
shade at openjdk.org
Fri Jan 9 09:55:01 UTC 2026
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.
Java atomics already have this distinction; 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.
-------------
Commit messages:
- Indenting is a bit off
- Fix
Changes: https://git.openjdk.org/jdk/pull/29135/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=29135&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8374878
Stats: 55 lines in 7 files changed: 42 ins; 1 del; 12 mod
Patch: https://git.openjdk.org/jdk/pull/29135.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/29135/head:pull/29135
PR: https://git.openjdk.org/jdk/pull/29135
More information about the hotspot-dev
mailing list