1 // -Xcomp -Xms16M -Xmx16M -XX:+AlwaysPreTouch -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -XX:-UseOnStackReplacement -XX:CompileOnly='Example1.ivanov' -XX:CompileCommand=dontinline,Example1.blackhole
 2 class Example1_ivanov {
 3     // Ivanov suggest to make this happen first.
 4     // we don't need to create JVMState for the cloning Allocate.
 5     public void ivanov(boolean cond) {
 6         Object x = new Object();
 7 
 8         if (cond) {
 9             blackhole(x);
10         }
11     }
12 
13     static void blackhole(Object x) {}
14 
15     public void test1(boolean cond) {
16         ivanov(cond);
17     }
18 
19     public static void main(String[] args)  {
20         Example1_ivanov kase = new Example1_ivanov();
21         // Epsilon Test:
22         // By setting the maximal heap and use EpsilonGC, let's see how long and how many iterations the program can sustain.
23         // if PEA manages to reduce allocation rate, we expect the program to stay longer.
24         // Roman commented it with a resonable doubt: "or your code slow down the program..."
25         // 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...
26         long iterations = 0;
27         try {
28             while (true) {
29                 kase.test1(0 == (iterations & 0xf));
30                 iterations++;
31             }
32         } finally {
33             System.err.println("Epsilon Test: " + iterations);
34         }
35     }
36 }