Last written 1. A preliminary understanding of the JVM-the JVM sequence, followed today to write the JVM's operating mechanism.
First, the JVM startup process
The Java platform includes the JVM and the Java language, where the JVM is also an application process running in the operating system, and it should have its own lifecycle and memory space. In general, the Java or JAVAC command execution process is probably as follows:
Input java (javac) command
Loading environment and configuration (looking for jvm.cfg based on current path and system version)
Locate and load JVM.DLL based on configuration
Initialize JVM to get JNIEnv interface
Find the Main method
Note in the loading environment and in the configuration first find the JRE path and then load Jvm.cfg, and then locate the calling system API to load JVM.dll, as for the specific code execution process can see csdn this article more complete.
Two
JVM Basic Structure
This basic structure I crawled from the Web to view this more clearly, as follows:
-
This method area typically holds the loaded class information: a constant pool of types, field, method information, method bytecode (string constants move the heap after JDK1.7). The
-
Java heap should be said to be the most closely related to the development of the program, which holds the system objects are stored in the heap, not like the stack is thread-private, this heap is all thread sharing, in particular, it is necessary to note that the GC has generational so the heap is also generational.
-
Java stack is said to be thread-private, the stack of space for the heap is generally relatively small so it is not possible to store large objects or quantities, each call method will create a frame and press the stack then allocate the stack space, but also have a PC register to save the next instruction address ( Local methods are different), there are multiple frames to follow the principle of advanced after, this frame holds the method of local variables, the operand stack (there is no register concept in Java), constant pool and other information, about the local variables here you need to remember the local variable table static method and instance method of the difference, for example:
- public staticint runstatic (int i,long lfloat f,object o,byte b) {}
- Local Variables table:int i,long l,float f,Object o,byte b
- public int runinstance(char- c, short s,boolean b) {}
- Local Variables table:reference this,char c,short s,boolean b
- Note: a minimum of 4 bytes ,int: N;float: n-bit;Object: the first place.
Heap, stack, method area interaction: About this interaction diagram I went straight to the video so look clearer, as follows
Come here first this time. Keep a record of every bit of drip!
2.JVM operating mechanism-JVM sequence