Created
December 14, 2022 22:01
-
-
Save navyxliu/35444b76f12cc2ed17a3d4d1e5fac26d to your computer and use it in GitHub Desktop.
Example3_2.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
class Example3_2 { | |
void bar(boolean cond, ArrayList<Integer> L) { | |
if(cond) { | |
L.add(1); // can't inline java.util.ArrayList::add (23 bytes) low call site frequency | |
} | |
} | |
public void foo(boolean cond) { | |
var x = new ArrayList<Integer>(); | |
bar(cond, x); | |
return; | |
} | |
public static void main(String[] args) { | |
var kase = new Example3_2(); | |
// Epsilon Test: | |
// By setting the maximal heap and use EpsilonGC, let's see how long and how many iterations the program can sustain. | |
// if PEA manages to reduce allocation rate, we expect the program to stay longer. | |
// Roman commented it with a resonable doubt: "or your code slow down the program..." | |
// 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... | |
long iterations = 0; | |
try { | |
while (true) { | |
kase.foo(0 == (iterations & 0xf)); | |
iterations++; | |
} | |
} finally { | |
System.err.println("Epsilon Test: " + iterations); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment