<> Execution engine overview
The execution engine of the physical machine is built on the processor , cache , Instruction set , And operating system level . The execution engine of the virtual machine is practiced by the software itself , Capable of executing instruction set formats that are not directly supported by hardware .
The task of the execution engine is to execute bytecode instructions explain / compile 【 Backend compilation 】 Local machine instructions on the corresponding platform
<>Java The process of compiling and executing code
When Java When the virtual machine starts , According to predefined specifications , The bytecode is interpreted line by line , The contents of each bytecode file “ translate " Execute instructions for the local machine of the corresponding platform .
bytecode interpreter ： When executing, simulate the execution of bytecode through pure software code , The efficiency is very low
template interpreter ： Associate each bytecode with a template function , The machine code when the bytecode is executed is directly generated in the template function , So as to improve the performance of the interpreter .
Interpreter based execution has become synonymous with inefficiency .
However, the response speed of the interpreter is fast , It can explain the operation immediately
The virtual machine compiles the source code directly into the machine language related to the local machine platform （ Not implemented immediately ）,JIT The compiled machine language code is cached in the method area .
JVM The platform supports a real-time compilation technology , The purpose of real-time compilation is to prevent functions from being interpreted and executed , Instead, the function body is compiled into machine code , Every time a function executes , Just execute the compiled machine code .
<> Hotspot code and detection method
Method call counter , Back edge counter
Heat attenuation , That is, the number of times the method is called in a period of time , When a certain time limit is exceeded , The number of calls is still insufficient , The call counter of this method will be reduced by half . This period of time becomes the half decay period of this method .
-XX:-UseCounterDecay Heat attenuation can be turned off , such , As long as the system runs long enough , Most methods are compiled into native code .
-XX：CounterHalfLifeTime Parameter sets the time of the half decay period , The unit is seconds .
-Xint Interpreter only mode
-Xcomp Compiler only mode
-Xmixed Mixed mode
JIT Compile and divide C1 compiler ,C2 compiler ,C1 Fast time , The optimization is simple and reliable ,C2 Slow time, radical optimization .
JDK9 introduce AOT compiler （ Static advance compiler ）, Before the program runs , The bytecode is converted into machine code , And stored in the dynamic shared library generated by the branch