"Java Virtual Machine Learning" java code running process

1. Java file conversion

When we save the java file, the compiler first compiles it into a class file, and then converts the class file into a bytecode file through the Java virtual machine

img

2. How does the Java virtual machine run Java files

First, the java file is loaded into the java virtual machine, and then the virtual machine stores the class meta information in the method area of ​​the virtual machine.

img

The bytecode file needs to be translated into machine instructions during execution. There are two translation methods:

  1. just-in-time compilation
  2. explain execution

Interpretation: Convert bytecode instructions into machine instructions line by line.

Just-in-time compilation: Compile all bytecodes in the method into machine code in units of methods.

Just-in-time compilation takes a long time to compile, but runs fast. The interpreted execution compile time is short, but the operation is slow.

The HotSpot virtual machine adopts a mixed mode. First, the bytecode is interpreted and executed, and the hotspot code that is repeatedly executed is compiled in real time with the method as the code.

3. Twenty-eighth law of hot data

Just-in-time compilation is also based on the fact that the program conforms to the 28th law, 20% of the code takes up 80% of the resources

For code that does not take up much resources, it can be run by interpretation and execution; for a small number of hot codes, it can be converted into machine code for execution by just-in-time compilation to reduce resource consumption.

Guess you like

Origin blog.csdn.net/JAVAlife2021/article/details/130535585