JVM virtual machine operating mechanism

JVM virtual machine operating mechanism

What is JVM?
A virtual machine is a software implementation of a physical machine. Java is used on a VM running WORA (Write Once Run Anywhere) concept developed. Java compiler for the Java file is compiled .class file, and then enter the .class file into the JVM, JVM will load and execute class files.


JVM basic concept of


(1) basic concepts:
JVM is a virtual computer executable Java code comprises a bytecode instruction set, a set of registers, a stack, a garbage collection, and heap storage method for a domain. JVM is running above the operating system, it has no direct interaction with the hardware.
(2) running process:
We all know that Java source file by the compiler, capable of producing the appropriate .Class file, which is byte code file, byte code file and the Java virtual machine interpreter, compiled into a specific machine code on the machine.
Is as follows
① Java source files -> compiler -> bytecode files
② bytecode file -> JVM -> machine code
for each platform interpreter is different, but the implementation of the virtual machine is the same, which is the reason why Java platform can cross, and when a program from running, then start the virtual machine is instantiated, the multiple programs will start multiple virtual machine instances. Or close the program exits, the virtual machine instance die, between a plurality of virtual machine instances data can not be shared.
(3) three JVM:
In JDK1.7 and earlier we use are Sun's HotSpot, but the Sun and BEA Systems have been acquired oracle, Jdk1.8 will use Sun's HotSpot and BEA's two JRockit JVM jdk1.8 formed the essence of the JVM.
How JVM work?
As shown in FIG architecture above, JVM is divided into three major subsystems:
A class loader subsystem
Java dynamic class loading subsystem is handled by the function class loader. When it is running, and the first reference to the class is not loaded when compiling, linking, and initialization class files.
1. Load
class loaded by this component. Boot Strap Class Loader, Extension Class Loader and Application Class Loader is contribute to the three class loader.
The above described class Delegation Hierarchy algorithm follows the loading class files.
2. Link
3. Initialize
This class is the last stage of loading, where all static variables will be given the original value, and perform a static block.
Second, the runtime data area
data area is divided into five main components run:
(1) the method area - all the class-level data will be stored here, comprises a static variable. Each JVM is only one way area, and it is a shared resource.
(2) heap area - all the instance variables and arrays and corresponding objects will be stored here. Each also has a JVM heap area. Since the method and heap memory area shared by multiple threads, so that the data stored in a non-thread safe.
(3) the stack area - for each thread will create a separate run-time stack. For each method call will generate an entry in stack memory called stack frame. All local variables are created in the stack memory. The stack area is thread-safe, because it is not a shared resource. Stack frame is divided into three sub-elements:
(. 4) PC register - each thread has a separate PC register, for storing the address of the instruction currently executing, upon instruction execution, PC register is updated to the next instruction.
(5) the native method stack - native method stack to save local method information. For each thread will create a separate native method stack.
Third, the execution engine
Assigned to the runtime data area of the byte code executed by the execution engine. The execution engine reads the byte code and execute it by one.
Interpreter - interpret the bytecode interpreter fast, but slow execution. The disadvantage is that the interpreter when a method is called multiple times, each time the need for new resolution.
--JIT JIT compiler compiler eliminates the disadvantages of the interpreter. Execution engine will use the help of an interpreter when converting byte code, but when it finds duplicate code, which uses JIT compiler, the compiler will compile the entire byte code and change it to native code. This code will be used directly in the local method call is repeated, thereby improving system performance.
Garbage collector: Collect and remove unreferenced objects. Garbage collection can be triggered by calling "System.gc ()", but can not guarantee execution. JVM's garbage collection object is created.
Java Native Interface (JNI): JNI to interact with the native method libraries, and provide the required execution engine local library.

Guess you like

Origin www.cnblogs.com/guoziyi/p/11589400.html