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

醉酒当歌 提交于 2019-12-04 02:09:41

问题


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 asking about other than a "hot code")


回答1:


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.



来源:https://stackoverflow.com/questions/28588105/does-java-jit-compiler-compiles-its-code-every-time-it-runs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!