1 // -Xcomp -Xms16M -Xmx16M -XX:+AlwaysPreTouch -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -XX:-UseOnStackReplacement -XX:CompileOnly='Example2.foo' -XX:CompileCommand=dontinline,Example2.blackhole 2 class Example2_1 { 3 int value = 0; 4 5 public static Example2_1 foo(boolean cond) { 6 var x = new Example2_1(); 7 8 if (cond) { 9 x.value++; 10 } else { 11 x.value += 2; 12 } 13 return x; 14 } 15 16 public static int foo2(boolean cond) { 17 var x = new Example2_1(); 18 19 if (cond) { 20 x.value++; 21 } else { 22 x.value += 2; 23 } 24 return x.value; 25 } 26 27 28 public static void blackhole() {} 29 30 public static void main(String[] args) { 31 long iterations = 0; 32 try { 33 while (true) { 34 boolean cond = 0 == (iterations & 0xf); 35 Example2_1 obj = foo(cond); 36 int expected = cond ? 1 : 2; 37 if (obj.value != expected) { 38 throw new RuntimeException("wrong answer"); 39 } 40 int val = foo2(cond); 41 if (val != expected) { 42 throw new RuntimeException("wrong answer"); 43 } 44 iterations++; 45 } 46 } finally { 47 System.err.println("Epsilon Test: " + iterations); 48 } 49 } 50 }