038. [rpm] with the JVM class loader boot process

From: https://blog.csdn.net/luanlouis/article/details/40043991

Step 1. The JVM memory configuration requirements for the JVM application specific memory size

The JVM starts in accordance with its configuration requirements, apply a memory and implemented in accordance with the JVM specification and the memory is divided into several regions.

All classes of definition information will be loaded into the method area.

 

 

 

Step 2. Create a boot class loader instance, the initial system is loaded into memory-based method area region;

After a good application JVM memory space, JVM will create a bootstrap class loader (Bootstrap Classloader) instances, the bootstrap class loader is using C ++ language.
Bootstrap class loader (Bootstrap Classloader) reads {JRE_HOME} jar package configuration and / lib under (basic system required to run the JVM virtual machine level class), the system is then loaded into the method area classes, such as java.lang.String, java.lang.Object and so on. 

 

 

Step 3. Create a launcher JVM instance Launcher, and obtain the class loader ClassLoader

In this case, JVM has been loaded in the virtual machine calls the class method area of sun.misc.Launcher static methods  getLauncher()to obtain  sun.misc.Launcher instances.

Launcher = sun.misc.Launcher.getLauncher of sun.misc.Launcher (); // Get Java launcher 
ClassLoader launcher.getClassLoader classLoader = ();           // get the class loader ClassLoader class loaded into memory to be used; 
// Returns  AppClassLoader  instance, AppClassLoader will ExtClassLoader as its parent loader.

 

sun.misc.Launcher using singleton design pattern , to ensure that only one instance of a JVM sun.misc.Launcher virtual machine. 
Launcher inside of which defines two class loader (ClassLoader), respectively, and sun.misc.Launcher.ExtClassLoader sun.misc.Launcher.AppClassLoader, 
two class loaders are referred to expand the class loader ( Extension ClassLoader) and application class loader (application ClassLoader).

 

Step 4. Use class loader to load the Main class ClassLoader

() Method returns AppClassLoader instance by launcher.getClassLoader, followed by AppClassLoader loaded when we write a class xxx.xxx.TestMain.

When AppClassLoader to load xxx.xxx.TestMain.class, will go to see the definition of the class, class file called a constant pool (Constant Pool) body structure to store the class of constant information. There are constant pool CONSTANT_CLASS_INFO type constant representing the class to use those declared in the class. .xxx.xxx.TestMain class to work properly, it must first be able to ensure that these class declared inside the loading. So AppClassLoader first of these classes are loaded into memory.

 

## parent class loader delegation model: --------

The method of JVM class information area region is divided in accordance with the class loader, each maintains its own class loader to load the class information; 
a class loader loads the corresponding class, accordingly the JVM heap (Heap) Create a corresponding Class <T>, the class information is used to access entry represents

 

Step 5. Using the main method Main class to run the program as a program entry

 

 

 

Step 6. The method of execution is completed, JVM destroyed, freeing memory

 

Guess you like

Origin www.cnblogs.com/badboyh2o/p/11267068.html