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

Andrew Haley aph at openjdk.org
Wed Nov 19 19:42:11 UTC 2025


On Wed, 19 Nov 2025 16:41:06 GMT, Ruben <duke at openjdk.org> wrote:

>>> This barrier doesn't appear to be elided.
>> 
>> Please post your test case so I understand what is happening.
>
> import java.lang.invoke.MethodHandles;
> import java.lang.invoke.VarHandle;
> 
> public class Test {
>   int value;
> 
>   static final VarHandle handle;
>   static {
>     try {
>       handle = MethodHandles.lookup().findVarHandle(Test.class, "value", int.class);
>     } catch(Exception e) {
>       throw new RuntimeException(e);
>     }
>   }
> 
>   static void test(Test instance) {
>     handle.getAndAddAcquire(instance, 1);
>   }
> 
>   public static void main(String[] args) {
>     Test instance = new Test();
>     for (int i = 0; i < 5000000; i++) {
>       test(instance);
>     }
>     System.out.println(instance.value);
>   }
> }
> 
> 
> I'm running it as follows:
> 
> java -XX:-TieredCompilation -XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly -XX:+UseLSE -XX:CompileCommand=compileonly,Test::test Test
> 
> 
> The output includes:
> 
> 050
> 050 +   cmpxchgw R29 = [R10], R11, R13  # (int, weak) if [R10] == R11 then [R10] <-- R13csetw R29, EQ   # R29 <-- (EQ ? 1 : 0)
> 064
> 064 +   membar_acquire
>         dmb ishld
> 
> and
> 
>   0x0000ef1d383bee54:   casl    w8, w13, [x10]
>   0x0000ef1d383bee58:   cmp     w8, w11
>  ;; 0x1F1F1F1F1F1F1F1F
>   0x0000ef1d383bee5c:   mov     x8, #0x1f1f1f1f1f1f1f1f         // #2242545357980376863
>  ;; } cmpxchg
>   0x0000ef1d383bee60:   cset    w29, eq  // eq = none
>  ;; membar_acquire
>   0x0000ef1d383bee64:   dmb     ishld

Mmm, interesting. That one will take some extra digging.
It would be best to concentrate on eliminating trailing DMB from C1, and keep on until that job is done. That way you will "own" the whole thing. It will take several pull requests to do it, because there are a few cases that should be handled.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/26000#discussion_r2543315506


More information about the hotspot-compiler-dev mailing list