1 import java.util.*; 2 3 class Example3_2 { 4 //public static Integer zero = Integer.valueOf(0); 5 6 void bar(boolean cond, ArrayList<Integer> L) { 7 if(cond) { 8 L.add(0); 9 } 10 } 11 12 public void foo(boolean cond) { 13 var x = new ArrayList<Integer>(); 14 bar(cond, x); 15 return; 16 } 17 18 public static void main(String[] args) { 19 var kase = new Example3_2(); 20 // Epsilon Test: 21 // By setting the maximal heap and use EpsilonGC, let's see how long and how many iterations the program can sustain. 22 // if PEA manages to reduce allocation rate, we expect the program to stay longer. 23 // Roman commented it with a resonable doubt: "or your code slow down the program..." 24 // 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... 25 long iterations = 0; 26 try { 27 while (true) { 28 kase.foo(0 == (iterations & 0xf)); 29 iterations++; 30 } 31 } finally { 32 System.err.println("Epsilon Test: " + iterations); 33 } 34 } 35 }