RFR: 8365799: AArch64: Remove trailing DMB from cmpxchgptr for LSE [v2]

Samuel Chee duke at openjdk.org
Wed Aug 20 14:36:53 UTC 2025


On Tue, 19 Aug 2025 15:58:52 GMT, Samuel Chee <duke at openjdk.org> wrote:

>> According to the Java SE 24 API, CompareAndExchange has the memory semantics as given by VarHandle.compareAndExchange, which has the following effects [1]:
>> 
>>> Atomically sets the value of a variable to the newValue with the
>>> memory semantics of setVolatile if the variable's current value,
>>> referred to as the witness value, == the expectedValue, as accessed
>>> with the memory semantics of getVolatile.
>> 
>> Thus, the store-release due to setVolatile only occurs if the compare is successful. Since CASAL already satisfies these requirements, the DMB does not need to occur to ensure memory ordering in case the compare fails and a store-release does not happen.
>> 
>> Therefore, we can remove the DMB from cmpxchgptr when LSE is enabled. We also rename it to cmpxchgptr_barrier to indicate that this method provides trailing barrier semantics (via either LSE CASAL or a DMB).
>> 
>> The unused cmpxchgw is removed.
>> 
>> [1] https://docs.oracle.com/en/java/javase/24/docs/api/java.base/java/lang/invoke/VarHandle.html#compareAndExchange(java.lang.Object...)
>
> Samuel Chee has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Merge master fix
>   
>   Change-Id: I74d44f711de208395bce47595fecd801564bcb54

You're right, it is a little inaccurate to use the Java API to determine what `cmpxchgptr` does. Although the original intent to remove the membar is still functionality correct.

Although looking into it more, it seems that `cmpxchgptr` can now be removed completely. The recent PR https://github.com/openjdk/jdk/pull/26594 removed two of its call sites, and the only other existing one is within `MacroAssembler::cmpxchg_obj_header` - a method which never gets called to.

So I propose:
- We close this pr
- Open new one which removes the methods `MacroAssembler::cmpxchg_obj_header`, `MacroAssembler::cmpxchgptr` and `MacroAssembler::cmpxchgw` completely since they are no longer called to from anywhere.

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

PR Comment: https://git.openjdk.org/jdk/pull/26845#issuecomment-3206680482


More information about the hotspot-dev mailing list