JVM basic structure and life cycle

JVM basic structure and life cycle

The Java virtual machine is a virtual computer that executes Java bytecode. It has an independent operating mechanism, and the Java bytecode it runs may not be compiled from the Java language. The various languages ​​of the JVM platform can share the cross-platform, excellent garbage collector, and reliable just-in-time compiler brought by the Java virtual machine.

JVM simple architecture
Insert picture description here
JVM complete architecture
Insert picture description here

The role of the Java virtual machine:

  • The Java virtual machine is the operating environment of the binary bytecode, which is responsible for loading the bytecode into it, and interpreting/compiling it into the execution of machine instructions on the corresponding platform. For each Java instruction, there are detailed definitions in the Java Virtual Machine specification, such as how to fetch the operands, how to process the operands, and where to place the processing results.

JVM features:

  • Compile once, run everywhere
  • Automatic memory management
  • Automatic garbage collection function

JVM architecture model : The instruction stream input by the Java compiler is basically a stack-based instruction set architecture.

Features of stack-based architecture:

  • Simpler design and implementation, suitable for resource-constrained systems;
  • Avoid the problem of register allocation: use the zero address instruction method to allocate.
  • Most of the instructions in the instruction stream are zero-address instructions, and their execution depends on the operation stack. The instruction set is smaller and the compiler is easy to implement.
  • No need for hardware support, better portability, better cross-platform

Compile and run the program
Insert picture description here
JVM life cycle

Start of the virtual machine

  • The startup of the Java virtual machine is accomplished by creating an initial class by the bootstrap class loader, which is specified by the specific implementation of the virtual machine.

Execution of the virtual machine

  • A running Java virtual machine has a clear task: execute Java programs.
  • It runs when the program starts, and it stops when the program ends.
  • When executing a so-called Java program, what is really being executed is a process called the Java Virtual Machine.

Exit of the virtual machine

  • The program execution ends normally.
  • The program encountered an exception or error during execution and terminated abnormally.
  • The Java virtual machine process is terminated due to an error in the operating system.
  • A thread calls the exit method of the Runtime class or the system class, or the halt method of the Runtime class, and the Java security manager also allows this exit or halt operation.
  • In addition, the JNI (Java Native Interface) specification describes the exit of the Java virtual machine when the JNI Invocation API is used to load or unload the Java virtual machine.

Guess you like

Origin blog.csdn.net/qq_33626996/article/details/112153709