1 class WrongBCIAfterMotion { 2 static int counter; 3 4 private int id; 5 6 public WrongBCIAfterMotion(int id) { 7 this.id = id; 8 } 9 10 static void blackhole(Object obj) { 11 } 12 13 public static void main(String[] args) { 14 final int n = 300_000; 15 16 for (int i =0; i<n;++i) { 17 /* 18 * PEA moves AllocateNode from 8 to 24. however, there's memory side-effect in between. 19 * PEA is using the JVMState including bci=8. 20 * This is wrong under -XX:-UseTLAB and -XX:OptimizeALot. 21 * 22 8: new #8 // class WrongBCIAfterMotion 23 11: dup 24 12: getstatic #14 // Field counter:I 25 15: dup 26 16: iconst_1 27 17: iadd 28 18: putstatic #14 // Field counter:I 29 21: invokespecial #17 // Method "<init>":(I)V 30 24: invokestatic #20 // Method blackhole:(Ljava/lang/Object;)V 31 */ 32 blackhole(new WrongBCIAfterMotion(counter++)); 33 } 34 35 if (counter != n) { 36 throw new RuntimeException("Wrong result"); 37 } 38 } 39 }