Introduction to JVM
Components of the JVM
JVM composition diagram (widely circulated on the Internet), JVM is divided into four parts:
-
Class Loader (subsystem)
The role of the class loader is to load class files into memory, such as writing a HelloWord.java program, and then compiling it into HelloWorld.class file through javac. Class Loader is responsible for loading the HelloWorld.class file to the "run data area".
Note: Class Loader is only responsible for loading .class files, and Execution Engine is responsible for execution.
-
Execution Engine (Subsystem)
The execution engine is also called the interpreter, which is responsible for interpreting commands, executing instructions in class files, and interacting with the operating system.
-
Native Interface (component)
The native interface is mainly used to integrate different programming languages into Java. When Java was born, C/C++ was the mainstream programming language, and websites written in C++ in the past were later implemented in Java. But all the past code cannot be discarded, so it is necessary to write the interface in the new website and call the past C/C++ program. Specific implementation: Open up an area in the content and mark it as native, and load native libraies when Execution Engine executes. Common applications (related to hardware): drive printers through Java programs and manage production equipment through Java systems.
When using the native method, it is no longer restricted by the JVM, and it is prone to native heap OutOfMemory that the JVM cannot control.
-
Runtime data area (component, JVM memory)
The program starts running after it is completely loaded into the running data area.
JVM framework running process: Loader loads files → Executor processes data → Local interface interacts with heterogeneous systems.
java.exe puts the class file in the JVM to run. JVM loads the class file and processes the content of the class file, java.exe interprets or compiles the bytecode into machine instructions, and interacts with the computer when the instructions are executed.
The JVM delivers each bytecode that needs to be executed to the interpreter, the interpreter translates the bytecode into the corresponding machine code, and the interpreter executes the machine code (if it needs to interact with the OS, the interpreter will interact with the OS.).