Well worth the compilation optimization

Reference link:

https://blog.csdn.net/liaodehong/article/details/51605457

https://www.cnblogs.com/insistence/p/5901457.html

(1) Hot spot compilation

In mainstream commercial JVMs (HotSpot, J9), Java programs are interpreters to step on, step on, move on, interpret, and execute. When the JVM determines that a method or a block of code is being executed particularly frequently, it identifies these codes as "hot spot code", then the JVM compiles these codes into machine codes relating to the local platform and performs various stages of optimization. The compiler that performs this task is called: Just In Time Compiler (JIT)

(Two) the process of the JIT compiler

When the JVM executes code, it does not immediately begin compiling the code. There are two main reasons for this:

If this code is executed only once, even once in the future, compiling it is essentially a waste of energy. Because translating code to Java bytecode is much faster than compiling that code and running the code.

If code calls a method or a loop frequently, that is, if this code is executed multiple times, it is of course very worthwhile to compile. Hence, the compiler has this ability to compromise of executing the interpreted code first and then distinguishing which methods are called frequently to ensure its own compilation. To put it simply: JIT works. We know that Java code is initially compiled into bytecode files by the compiler and the bytecode files are then passed to the JVM for interpretation and execution. Java itself can be said to be a half compiled and half interpreted language. Hot Spot VM uses JIT compilation technology which directly compiles bytecodes that are very often executed in machine instructions to improve performance. Therefore, when bytecode is compiled from JIT to machine code, it can also be compiled and executed. That is, at runtime, some of the code can be translated by JIT into target machine instructions (using the method as a translation unit, it is saved and the second execution does not need to be translated) and executed directly.

The second reason is optimization. When the JVM executes a method or loops multiple times, it understands the structure of the code better, and then the JVM makes appropriate tweaks as it compiles the code.

In mainstream commercial JVMs (HotSpot, J9), Java programs are interpreters to step on, step on, move on, interpret, and execute. When the JVM determines that a method or a block of code is being executed particularly frequently, it identifies these codes as "hot spot code", then the JVM compiles these codes into machine codes relating to the local platform and performs various stages of optimization. The compiler that performs this task is called: Just In Time Compiler (JIT)