1 // -Xcomp -Xms16M -Xmx16M -XX:+AlwaysPreTouch -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -XX:-UseOnStackReplacement -XX:CompileOnly='Example2.foo' -XX:CompileCommand=dontinline,Example2.blackhole 2 class Example2 { 3 private Object _cache; 4 public Object foo(boolean cond) { 5 Object x = new Object(); 6 7 blackhole(); 8 9 if (cond) { 10 _cache = x; 11 } 12 return x; 13 } 14 15 public static void blackhole() {} 16 17 public static void main(String[] args) { 18 Example2 kase = new Example2(); 19 // Epsilon Test: 20 // By setting the maximal heap and use EpsilonGC, let's see how long and how many iterations the program can sustain. 21 // if PEA manages to reduce allocation rate, we expect the program to stay longer. 22 // Roman commented it with a resonable doubt: "or your code slow down the program..." 23 // That's why I suggest to observe iterations. It turns out not trivial because inner OOME will implode hotspot. We don't have a chance to execute the final statement... 24 long iterations = 0; 25 try { 26 while (true) { 27 kase.foo(0 == (iterations & 0xf)); 28 iterations++; 29 } 30 } finally { 31 System.err.println("Epsilon Test: " + iterations); 32 } 33 } 34 }