Skip to content

Instantly share code, notes, and snippets.

@navyxliu
Created October 19, 2022 21:24
Show Gist options
  • Save navyxliu/9c325d5c445899c02a0d115c6ca90a79 to your computer and use it in GitHub Desktop.
Save navyxliu/9c325d5c445899c02a0d115c6ca90a79 to your computer and use it in GitHub Desktop.
PEA_C2_Example1
// -Xcomp -Xms16M -Xmx16M -XX:+AlwaysPreTouch -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -XX:-UseOnStackReplacement -XX:CompileOnly='Example1.ivanov' -XX:CompileCommand=dontinline,Example1.blackhole
class Example1 {
private Object _cache;
public void foo(boolean cond) {
Object x = new Object();
if (cond) {
_cache = x;
}
}
// Ivanov suggest to make this happen first.
// we don't need to create JVMState for the cloning Allocate.
public void ivanov(boolean cond) {
Object x = new Object();
if (cond) {
blackhole(x);
}
}
static void blackhole(Object x) {}
public void test1(boolean cond) {
//foo(cond);
ivanov(cond);
}
public static void main(String[] args) {
Example1 kase = new Example1();
// 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.test1(0 == (iterations & 0xf));
iterations++;
}
} finally {
System.err.println("Epsilon Test: " + iterations);
}
}
}
@navyxliu
Copy link
Author

the source code of my experimental PEA: https://github.com/navyxliu/jdk/tree/PEA_parser

@merykitty
Copy link

I believe that JMH has prof:gc to acquire the allocation rate per iteration, maybe you can somehow use it for allocation rate of PEA. Thanks.

@navyxliu
Copy link
Author

I believe that JMH has prof:gc to acquire the allocation rate per iteration, maybe you can somehow use it for allocation rate of PEA. Thanks.

yes, I will convert this to a JMH. thanks!

@navyxliu
Copy link
Author

This is a developing story.
if you are still interested, please follow it up -> Example2

@navyxliu
Copy link
Author

The following code creates a phi node to merge 2 objects.
I believe RAM of JDK-8289943 can make the NonEscape object be replace in

    public Object merge_node(boolean cond) {
        Object x = new Object();

        if (cond) {
            _cache = x;
        }
        return x;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment