|
|
Does anyone know what is the best technique for detecting when JIT compiling occurs during a running application?
The best approach that I can think of is this: use CompilationMXBean.getTotalCompilationTime(). I tested it quickly just now, and it seems to work as advertised (I could see JIT compilation occurring at several distinct places in my application's lifecycle). Unfortunately, it suffers from these defects:
a) the time resolution of getTotalCompilationTime is milliseconds, so it is conceivable that a hot method got compiled, but that its compilation time was < 1 ms, which could mean that its compilation goes undetected (because it was not big enough to increase the ms count). Why oh why did Sun not use System.nanoTime here?
b) some platforms do not support this method (but you can call isCompilationTimeMonitoringSupported first to find out)
The only other approach that I have seen suggested is to run your JVM with the ?XX:+PrintCompilation option, and then redirect stdout to a stream that you capture, and then parse it looking for the compilation outputs.
This second approach also has defects:
a) XX options cannot be counted on
b) there is no documentation of or commitment to the output format, so if you assume a format and it changes, you will cease detecting compilation
c) it is much more of a pain to do
|
|