Does Java jit compiler compiles its code every time it runs?

后端 未结 1 600
隐瞒了意图╮
隐瞒了意图╮ 2021-01-15 23:50

I am new to java and struggling to understand the following: Does jit compiles everytime we run the code? (I know jit optimizes that code which is run frequently but I am as

相关标签:
1条回答
  • 2021-01-16 00:21

    The JIT doesn't remember anything from a previous run.

    This means it may compile code every time you run it. The JIT can even re-compile code while it is running to either optimise it further or optimise it differently if it detect how the code is used have changed.

    Code which is not considered hot will not be compiled as this is likely to be more expensive than just running it with the interpreter.

    When you have tiered compilation (on by default in Java 8) it will compile moderately hot code a little, recompile it more and more as you run it more. It can go through multiple stages.

    If you want to see what is being compiled add -XX:+PrintCompilation on the command line.

    0 讨论(0)
提交回复
热议问题