Skip to content

Instantly share code, notes, and snippets.

@blinky-z
Created August 31, 2022 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blinky-z/bd0143794421878ee10dd4846da59df3 to your computer and use it in GitHub Desktop.
Save blinky-z/bd0143794421878ee10dd4846da59df3 to your computer and use it in GitHub Desktop.
public class JmmVolatileConditionRead {
private static int x;
private static volatile boolean initialized;
public static void writer() {
x = 5; /* W1 */
initialized = true; /* W2 */
}
public static void reader1() {
boolean r1 = initialized; /* R1 */
if (r1) {
int r2 = x; /* R2 */
}
/*
x86:
0x000002239b45b5de: movsx esi,BYTE PTR [rsi+0x74] ;*getstatic initialized {reexecute=0 rethrow=0 return_oop=0}
; - jit_disassembly.JmmVolatileConditionRead::reader1@0 (line 14)
0x000002239b45b5e2: cmp esi,0x0
0x000002239b45b5e5: movabs rsi,0x223b7c037e0 ; {metadata(method data for {method} {0x00000223b7c032d8} 'reader1' '()V' in 'jit_disassembly/JmmVolatileConditionRead')}
0x000002239b45b5ef: movabs rdi,0x110
0x000002239b45b5f9: je 0x000002239b45b609
0x000002239b45b5ff: movabs rdi,0x120
0x000002239b45b609: mov rbx,QWORD PTR [rsi+rdi*1]
0x000002239b45b60d: lea rbx,[rbx+0x1]
0x000002239b45b611: mov QWORD PTR [rsi+rdi*1],rbx
0x000002239b45b615: je 0x000002239b45b628 ;*ifeq {reexecute=0 rethrow=0 return_oop=0}
; - jit_disassembly.JmmVolatileConditionRead::reader1@5 (line 15)
0x000002239b45b61b: movabs rsi,0x7114bd448 ; {oop(a 'java/lang/Class'{0x00000007114bd448} = 'jit_disassembly/JmmVolatileConditionRead')}
0x000002239b45b625: mov esi,DWORD PTR [rsi+0x70] ;*getstatic x {reexecute=0 rethrow=0 return_oop=0}
; - jit_disassembly.JmmVolatileConditionRead::reader1@8 (line 16)
ARM64:
0x0000ffff71966a0c: dmb ishld ;*getstatic initialized {reexecute=0 rethrow=0 return_oop=0}
; - jit_disassembly.JmmVolatileConditionRead::reader1@0 (line 14)
0x0000ffff71966a10: cmp w0, #0x0
0x0000ffff71966a14: mov x0, #0xa70 // #2672
; {metadata(method data for {method} {0x0000ffff70c003c8} 'reader1' '()V' in 'jit_disassembly/JmmVolatileConditionRead')}
0x0000ffff71966a18: movk x0, #0x70c0, lsl #16
0x0000ffff71966a1c: movk x0, #0xffff, lsl #32
0x0000ffff71966a20: mov x8, #0x140 // #320
0x0000ffff71966a24: mov x9, #0x150 // #336
0x0000ffff71966a28: csel x1, x8, x9, eq // eq = none
0x0000ffff71966a2c: ldr x2, [x0, x1]
0x0000ffff71966a30: add x2, x2, #0x1
0x0000ffff71966a34: str x2, [x0, x1]
0x0000ffff71966a38: b.eq 0x0000ffff71966a4c // b.none;*ifeq {reexecute=0 rethrow=0 return_oop=0}
; - jit_disassembly.JmmVolatileConditionRead::reader1@5 (line 15)
0x0000ffff71966a3c: mov x0, #0x89d0 // #35280
; {oop(a 'java/lang/Class'{0x00000000e4d189d0} = 'jit_disassembly/JmmVolatileConditionRead')}
0x0000ffff71966a40: movk x0, #0xe4d1, lsl #16
0x0000ffff71966a44: movk x0, #0x0, lsl #32
0x0000ffff71966a48: ldr w0, [x0, #112] ;*getstatic x {reexecute=0 rethrow=0 return_oop=0}
; - jit_disassembly.JmmVolatileConditionRead::reader1@8 (line 16)
*/
}
public static void reader2() {
if (initialized) { /* R1 */
int r2 = x; /* R2 */
}
/*
x86:
0x000002239b45b25e: movsx esi,BYTE PTR [rsi+0x74] ;*getstatic initialized {reexecute=0 rethrow=0 return_oop=0}
; - jit_disassembly.JmmVolatileConditionRead::reader2@0 (line 21)
0x000002239b45b262: cmp esi,0x0
0x000002239b45b265: movabs rsi,0x223b7c03930 ; {metadata(method data for {method} {0x00000223b7c03388} 'reader2' '()V' in 'jit_disassembly/JmmVolatileConditionRead')}
0x000002239b45b26f: movabs rdi,0x110
0x000002239b45b279: je 0x000002239b45b289
0x000002239b45b27f: movabs rdi,0x120
0x000002239b45b289: mov rbx,QWORD PTR [rsi+rdi*1]
0x000002239b45b28d: lea rbx,[rbx+0x1]
0x000002239b45b291: mov QWORD PTR [rsi+rdi*1],rbx
0x000002239b45b295: je 0x000002239b45b2a8 ;*ifeq {reexecute=0 rethrow=0 return_oop=0}
; - jit_disassembly.JmmVolatileConditionRead::reader2@3 (line 21)
0x000002239b45b29b: movabs rsi,0x7114bd448 ; {oop(a 'java/lang/Class'{0x00000007114bd448} = 'jit_disassembly/JmmVolatileConditionRead')}
0x000002239b45b2a5: mov esi,DWORD PTR [rsi+0x70] ;*getstatic x {reexecute=0 rethrow=0 return_oop=0}
; - jit_disassembly.JmmVolatileConditionRead::reader2@6 (line 22)
ARM64:
0x0000ffff7196620c: dmb ishld ;*getstatic initialized {reexecute=0 rethrow=0 return_oop=0}
; - jit_disassembly.JmmVolatileConditionRead::reader2@0 (line 39)
0x0000ffff71966210: cmp w0, #0x0
0x0000ffff71966214: mov x0, #0x790 // #1936
; {metadata(method data for {method} {0x0000ffff70c00478} 'reader2' '()V' in 'jit_disassembly/JmmVolatileConditionRead')}
0x0000ffff71966218: movk x0, #0x70c0, lsl #16
0x0000ffff7196621c: movk x0, #0xffff, lsl #32
0x0000ffff71966220: mov x8, #0x140 // #320
0x0000ffff71966224: mov x9, #0x150 // #336
0x0000ffff71966228: csel x1, x8, x9, eq // eq = none
0x0000ffff7196622c: ldr x2, [x0, x1]
0x0000ffff71966230: add x2, x2, #0x1
0x0000ffff71966234: str x2, [x0, x1]
0x0000ffff71966238: b.eq 0x0000ffff7196624c // b.none;*ifeq {reexecute=0 rethrow=0 return_oop=0}
; - jit_disassembly.JmmVolatileConditionRead::reader2@3 (line 39)
0x0000ffff7196623c: mov x0, #0x89d0 // #35280
; {oop(a 'java/lang/Class'{0x00000000e4d189d0} = 'jit_disassembly/JmmVolatileConditionRead')}
0x0000ffff71966240: movk x0, #0xe4d1, lsl #16
0x0000ffff71966244: movk x0, #0x0, lsl #32
0x0000ffff71966248: ldr w0, [x0, #112] ;*getstatic x {reexecute=0 rethrow=0 return_oop=0}
; - jit_disassembly.JmmVolatileConditionRead::reader2@6 (line 40)
*/
}
public static void main(String[] args) throws Exception {
// invoke JIT
for (int i = 0; i < 10000; i++) {
writer();
reader1();
reader2();
}
Thread.sleep(1000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment