aarch64: C2 fast lock/unlock issues
Andrew Haley
aph at redhat.com
Wed Sep 2 14:29:37 UTC 2015
I'm rejecting this patch.
With biased locking there is path through the code with no barriers of
any kind.
This code:
for (int i = 0; i < 10000; i++) {
synchronized(this) { n++; }
}
generates this:
;; B5: # B17 B6 <- B4 B8 Loop: B5-B8 inner main of N92 Freq: 10082.5
0x000003ffa8496e90: ldr x10, [x19]
0x000003ffa8496e94: and x11, x10, #0x7
0x000003ffa8496e98: cmp x11, #0x5
0x000003ffa8496e9c: b.ne 0x000003ffa8496f74
;; B6: # B21 B7 <- B5 Freq: 10082.5
0x000003ffa8496ea0: ldr x11, [xesp,#176]
0x000003ffa8496ea4: mov xmethod, xthread
0x000003ffa8496ea8: orr xmethod, xmethod, x11
0x000003ffa8496eac: eor x13, xmethod, x10
0x000003ffa8496eb0: and x14, x13, #0xffffffffffffff87
0x000003ffa8496eb4: cbnz x14, 0x000003ffa8497098
;*monitorenter
; - Twiddle::run at 12 (line 7)
;; B7: # B19 B8 <- B18 B17 B6 B24 Freq: 10082.5
0x000003ffa8496eb8: ldr w11, [x19,#12] ;*getfield n
; - Twiddle::run at 15 (line 7)
0x000003ffa8496ebc: add w10, w11, #0x1
0x000003ffa8496ec0: add w12, w11, #0x4
0x000003ffa8496ec4: str w10, [x19,#12]
0x000003ffa8496ec8: str w12, [x19,#12]
0x000003ffa8496ecc: ldr x10, [x19]
0x000003ffa8496ed0: and x10, x10, #0x7
0x000003ffa8496ed4: cmp x10, #0x5
0x000003ffa8496ed8: b.ne 0x000003ffa8496ffc ;*aload_0
; - Twiddle::run at 9 (line 7)
;; B8: # B5 B9 <- B20 B19 B7 Freq: 10082.5
0x000003ffa8496edc: add w29, w29, #0x4 ;*iinc
; - Twiddle::run at 33 (line 6)
;; 0x270D
0x000003ffa8496ee0: mov wscratch1, #0x270d // #9997
0x000003ffa8496ee4: cmp w29, wscratch1
0x000003ffa8496ee8: b.lt 0x000003ffa8496e90 ;*if_icmpge
; - Twiddle::run at 6 (line 6)
So any other thread waiting for the counter to hit a value would not
see it. And we do not see the writes of other threads. This is
wrong.
(It's also, IIRC, why I rejected this approach before.)
Andrew.
More information about the hotspot-compiler-dev
mailing list