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

Kim Barrett kbarrett at openjdk.org
Fri Jan 9 12:51:47 UTC 2026


On Fri, 9 Jan 2026 12:30:36 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:

>> src/hotspot/share/runtime/atomic.hpp line 273:
>> 
>>> 271:   bool compare_set(T compare_value, T new_value,
>>> 272:                    atomic_memory_order order = memory_order_conservative) {
>>> 273:     return AtomicAccess::cmpxchg(value_ptr(), compare_value, new_value, order) == compare_value;
>> 
>> I think I would prefer both this and (especially) the translated case be
>> 
>> return compare_exchange(compare_value, new_value, order) == compare_value;
>> 
>> rather than duplicating some of the respective `compare_exchange`
>> implementations. I won't block for this though.
>
> Thanks. For non-translated version, I agree with the simplification.
> 
> For translated case: I actually thought it is a good thing to avoid calling `recover()` on return value, because it did not need to? Does it save anything, really?

I missed that detail about the translated case, and agree with that rationale.

Note that `decay` and `recover` are typically type interpretation conversions,
probably with no code generation involved. But that doesn't change the
conceptual argument for the current proposed code.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/29135#discussion_r2676072972


More information about the hotspot-dev mailing list