This article mainly introduces the architecture of the Java virtual machine and the role of the program operation.
In the Java virtual machine specification, a virtual machine behavior is described in accordance with a subsystem, memory area, data type, and several terms of instructions. as the picture shows:
Method area
heap
Java stack
PC register
Local square stack
Class loader subsystem
Execute engine
Local method interface
Runtime data area
local
Method library
Java virtual machine internal architecture
Each virtual machine has a class loader subsystem that loads classes or interfaces based on a given list;
Each virtual machine has an execution engine that is responsible for executing instructions included in the method of loading classes;
Memory is the foundation of any program, and the Java virtual machine will manage all things that need to be saved to several "runtime data area". The description of the specification is abstract, and the designer is determined by the designer. Memory can be divided into two concepts according to functions: shared areas and private areas.
The shared area is shared by all threads in the program. Each Java virtual machine instance has a method area and a heap, which is shared by all threads from the virtual machine instance. When a virtual machine loads a Class file, it resolves the type information from the binary data contained in this class file, and then puts these type information in the method area. When the program runs, the virtual opportunity puts all the objects created at runtime in the stack.
The private area is a thread private, and other threads cannot be accessed. When a new thread is created, you will get your own PC register and a Java stack. When the Java method is executed, the PC register indicates the next execution, while the Java stack is stored in the thread Java method (non-local method) ) Call status - including local variables and parameters, return values, etc., the state of the local method call, and in accordance with the specific implementation, it is also possible to be other storage regions.
The Java Stack consists of many stack frames, and a stack frame contains a call status of a Java method. That is, when a Java method is called, the virtual machine is pressed into a new stack frame to the stack; the method returns, pops up from the stack and abandoned.
The above is the architecture of the Java virtual machine, providing a reference for anti-compilation, optimization code!
references:
[1] "Deeper Java Virtual Machine" second edition
[2] Java virtual machine specification