Reputation: 41
There are flags available that provide log information on methods that have been compiled. Where is the information on methods that didn't get compiled and why they didn't get compiled? Being able to see how the hotspot compiler makes its decisions and the reasons for it not compiling certain methods would give me a better understanding of the JVM, and allow me to write better code and possibly optimize some of my methods. Anybody have any thoughts on this subject?
Upvotes: 4
Views: 396
Reputation: 24060
The answer is that methods may not be compiled if they've not been executed enough times. The native code cache is limited, and so compiling every method is counterproductive; you could end up with a number of methods that have been compiled but then the important ones no longer fit in the cache size.
The exact numbers vary from release to release, but if you run Java with -XX:+PrintFlagsFinal
then you'll see all of the settings that you can tweak, including Tier3CompileThreshold
(which has the value 2000) Tier4CompileThreshold
(which has the value 15000). So if you don't call your method more than 2000 times it'll just use the interpreter to go through it.
If you're wanting to perform profiling under JIT conditions then you need to perform a significant number of loops calling the methods in order to see the benefit, or use a profiling harness such as JMH to do the profiling properly.
Upvotes: 1
Reputation: 24375
As per: http://blog.headius.com/2009/01/my-favorite-hotspot-jvm-flags.html
-XX:+PrintCompilation prints out the name of each Java method Hotspot decides to JIT compile. The list will usually show a bunch of core Java class methods initially, and then turn to methods in your application.
My personal belief is this is just going to suck a lot of your time. If you code using best practices and some common sense and then if performance is a problem, profile. You should do fine.
Upvotes: 3