public class Inline {
public static void main(String[] args) throws Exception {
long upto = Long.parseLong(args[0]);
for(int i = 0; i < upto; i++) {
int x = inline1();
Thread.sleep(1);
}
}
public static int inline1() {
return inline2();
}
public static int inline2() {
return inline3();
}
public static int inline3() {
return 4;
}
}
This is a simple example I am using to see the effect of safepoints and counter decay on methods being compiled to assembly.
My understanding is that with a Thread.sleep
(or System.gc
) call, the method invocation / back-edge counter would be decremented and would never reach over the CompileThreshold
.
Thread.sleep()
should insert a safepoint and the methods shouldn't be compiled. However when I run the example above with -XX:+PrintCompilation
, I can see all the methods being compiled.
I am running the code as follows:
java -XX:+PrintCompilation Inline 10000
My Java version:
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)
Am I missing something?
From what I can tell, the information you link to in your comments is out of date. The "CompileThreshold is relative!" article is dated 2013, and is describing a version of Java available at that time.
If you look at the Java 8 and Java 9 OpenJDK source code, you will see that the counter decay code that was described in the article is no longer there. That would explain why you are not seeing the effect in Java 8.
(The place to look is "./jdk8u/hotspot/src/share/vm/runtime/safepoint.cpp" in the source tree.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With