The class loading of the JVM is done through ClassLoader and its subclasses, and the hierarchy and loading order of the classes can be described as follows:
The process for each ClassLoader loading class is:
1. Check if this class is loaded (that is, if there is this class in the cache), if there is 8, if not to 2
2. If the parent ClassLoader does not exist (without the parent, the parent must be bootstrap), to 4
3. Request the parent ClassLoader to load, if successful to 8, unsuccessful to 5
4. Request that the JVM be loaded from bootstrap ClassLoader if successful to 8
5. Look for the class file (from the classpath associated with this classloader). If not found then to 7.
6. Load class from file to 8.
7. Throw classnotfoundexception.
8. Return to class.
Class execution mechanism
The JVM's instructions are to take the operand from the operand stack, which is the stack-based architecture that executes the class bytecode. After the thread is created, the program counter (PC) and stack (stack) are generated, and the program counter holds the offset of the next instruction to be executed in the method, and the stack frames are stored in each stack frame, and each stack frame corresponds to each call of each method, and the stack frame has a local variable area, an operand stack and a frame data area The local variables are used to store the local variables and parameters in the method, which are used to store the intermediate results produced during the execution of the method in the operand stack. The size of the local variable area and the operand stack, which the compiler determines at compile time, is stored in the class file. The size of the frame data area depends on the implementation, which is used to support constant pool parsing, normal method return, and exception dispatch mechanism.
The 32-bit hotspot requires 64-bit/8-byte alignment, and hotspot uses the Instanceoopdesc class to represent Java objects in C + + code, which inherits Oopdesc,oopdesc to preserve the Java class metadata information. Klass holds the actual data for Java class. Klass is a pair of needles used to describe objects on the GC heap, and it requires a specific Klass object to describe the size of an object, the number of fields, and the type of information that is not fixed.
Instanceoopdesc is used to represent Java objects, Instanceklass is used to describe it, and the hotspot does not expose Instanceklass to Java, and will create a corresponding Java.lang.Class object, the two hold a reference to each other, if you have some of the information is not fixed need to be described, so there are instanceklassklass, so it will be endless, So there's a klassklass as a terminator on this description chain.
A Klass diagram that accesses an object through a direct pointer:
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
JVM Tuning Series: (iii) class loading mechanism