RFR: 8360654: AArch64: Remove redundant dmb from C1 compareAndSet [v2]

Andrew Haley aph at openjdk.org
Fri Feb 13 09:28:19 UTC 2026


On Thu, 12 Feb 2026 16:01:03 GMT, Ruben <duke at openjdk.org> wrote:

>> This is a subsequently updated duplicate of the PR #26000 which was originally created by @spchee.
>> 
>> ===========
>> 
>> AtomicLong.CompareAndSet has the following assembly dump snippet which gets emitted from the intermediary LIRGenerator::atomic_cmpxchg:
>> 
>> 
>> ;; cmpxchg {
>>   0x0000e708d144cf60:   mov	x8, x2
>>   0x0000e708d144cf64:   casal	x8, x3, [x0]
>>   0x0000e708d144cf68:   cmp	x8, x2
>>  ;; 0x1F1F1F1F1F1F1F1F
>>   0x0000e708d144cf6c:   mov	x8, #0x1f1f1f1f1f1f1f1f
>>  ;; } cmpxchg
>>   0x0000e708d144cf70:   cset	x8, ne  // ne = any
>>   0x0000e708d144cf74:   dmb	ish
>> 
>> According to the Oracle Java Specification, AtomicLong.CompareAndSet [1] has the same memory effects as specified by VarHandle.compareAndSet which has the following effects: [2]
>> 
>>> 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.
>> 
>> Hence the release on the store 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 release does not happen.
>> 
>> Hence we move the DMB from both casl and casw (same logic applies to the non-long variant) into the non-LSE branch of cmpxchg.
>> 
>> This is also supported by C2 not having a DMB for the same respective method.
>> 
>> At the same time, move `membar` (non-LSE branch) from LIR_Assembler::atomic_op (for lir_xadd/lir_xchg) to atomic_xchgal[w] and atomic_addal[w] functions.
>> 
>> [1] https://docs.oracle.com/en/java/javase/24/docs/api/java.base/java/util/concurrent/atomic/AtomicLong.html#compareAndSet(long,long)
>> [2] https://docs.oracle.com/en/java/javase/24/docs/api/java.base/java/lang/invoke/VarHandle.html#compareAndSet(java.lang.Object...)
>
> Ruben has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains 12 additional commits since the last revision:
> 
>  - Address review comments
>  - Revert "Add cmpxchg_barrier helper"
>    
>    This reverts commit 092c92e904d3862b2772e8b229782b940e4dcbd1.
>  - Revert "Address review comments. Refine."
>    
>    This reverts commit 135123cb238ed2b603260cca4aa1280dab47c8d7.
>  - Revert "Add "/*with_barrier*/" comments"
>    
>    This reverts commit 6d9030d3181215de6240798d8a6254242ea29926.
>  - Merge from mainline
>  - Add "/*with_barrier*/" comments
>  - Address review comments. Refine.
>  - Merge from the main branch
>  - Add cmpxchg_barrier helper
>    
>    Change-Id: I17acf999140f0c1decb256de8291361c568a4ff8
>  - Add comment
>    
>    Signed-off-by: Samuel Chee <samche01 at arm.com>
>    Change-Id: I9793ed6ffdff6c044552d069af23620d178f2284
>  - ... and 2 more: https://git.openjdk.org/jdk/compare/ddd7b1e0...08ace3ee

Looks good, thanks.

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

Marked as reviewed by aph (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/29287#pullrequestreview-3796058931


More information about the hotspot-dev mailing list