Is there a way to find out from the JVM whether a particular method was compiled by JIT?

When writing microobjects, you can observe a large difference in runtime depending on whether the method was compiled or not. Is there a way to tell from within the program whether a particular method has been compiled? Alternatively, is there a way to request it or know how to warm it properly without additional information about, for example, flags passed to the JVM? Obviously, this will not necessarily be perfect (for example, there may be some condition that causes the JVM to return to the interpreted code), but this will certainly be an improvement.

+6
source share
2 answers

For the Sun / Oracle JVM, you can use the -XX:CompileThreshold=1000 setting -XX:CompileThreshold=1000 .

This is - as official documentation, official documentation defines:

Number of method calls / branches before compilation

Then just use the JVM warm up number.

You can also use -XX:-PrintCompilation along with -XX:CompileThreshold to receive a notification (in the console) when compiling a method.

+3
source

I am sure that you can enable logging, which will show when the JITCed methods. But I don't know anything from Java to say.

And keep in mind that JIT compilation is not an event, but a process. The method can be recompiled several times, since information about its characteristics becomes available.

Finally, note that “warming up” generally takes place. Although you can usually “warm up” one method reliably, it is much more difficult even with very modest use due to a number of factors.

(Although I don’t know for any reason why the ability to read some JITC status for a method cannot be added to the built-in debugging tools.)

Added:. Beware when snippets are used when testing code that the most external method that executes the entire loop often does not support JITC (depending on how JITC is implemented) because it never returns, and, therefore, the JITCed version can never be called. Therefore, you should always put the "meat" of the code in a comparative analysis in a separate method, which is called multiple times, instead of putting the loop and code to be tested with the same method.

+1
source

All Articles