Search code examples
jvmjitjvm-hotspot

How to know how much time spent on compile a class or method in hotspot?


1, I want to know how much time spent on compile a class or method in hotspot during JIT (We got some timeout issue and we suspect it maybe caused by a long compilation time)? Is there any trace flag or other ways to trace this time?

2,BTW, if the method run on first time , then the compilation time would is 0 as there is totally no compilation process, right?


Solution

  • JVM flags: -XX:+PrintCompilation -XX:+UnlockDiagnosticVMOptions -XX:+PrintCompilation2

        289  425       4       java.time.LocalDate::until (116 bytes)
        292  360       3       java.time.ZoneId::of (85 bytes)   made not entrant
        293  426       4       java.time.LocalDate::from (68 bytes)
        293  386       3       java.time.LocalDate::from (68 bytes)   made not entrant
        293  426   size: 248(96) time: 0 inlined: 54 bytes
        297  425   size: 3688(2272) time: 8 inlined: 1092 bytes
         ^    ^          ^                ^          ^
         |    |          |                |          |
         |    |          compiled bytes   |          bytecodes inlined
         |    compilation ID              method compilation time (ms)
         timestamp (ms from JVM start)
    

    Note that

    • JIT compiler works in background while the application is running; it is unlikely to cause delays or timeouts.
    • There are typically multiple compiler threads; PrintCompilation output may appear interleaved.
    • A method may be (re)compiled multiple times with a different level of optimization.