Class lifecycle in the VM memory:
----------------------
Load Loading
Verify verification |
Prepare preparation | connect to linking
Resolution resolution |
Initialize Initialization
Use Using
Unloading
------------------------
The parsing sequence is not certain. It can be started after the initialization phase and can be bound at runtime.
Class initialization:
1. New getstatic putstatic (except final) invokestatic
2. Use the java. Lang. Reflect package method to perform reflection research on classes
3. initialize subclass to trigger parent class initialization (for example, a defined constant when the parent interface is used)
4. Start the VM and run the main class (including the main method)
Passive reference, initialization method not triggered:
1. Reference static fields of the parent class through subclass
2. Reference classes through array Definitions
3. constants are stored in the constant pool of the call class during compilation. Essentially, they are not directly referenced to tables that define constants.
========================================================== ==========
Load
1. Get the binary byte stream zip jar war applet proxy jsp db that defines this class by using the permission name of a class
2. Convert the static storage structure represented by this byte stream to the data structure during running in the method area.
3. Generate a java. Lang. Class Object that represents the class in the Java heap, which serves as the access entry to the data in the method area.
Verify
1. Verify that the file format is correctly parsed and stored in the Method Area
2. semantic verification of metadata verification, in line with Java language specifications
3. bytecode verification data flow and control flow analysis halting problem 1.6-XX:-usesplitverifier turn off Optimization
4. symbol reference verification symbol reference full qualified name, symbol description, accessibility-xverify: None
Preparation
Formally allocate memory for class variables and set the class variable initial value to be allocated in the method area.
Note that the instance variables and objects are allocated to the heap together.
The final constant will be assigned a value. The other values are the initial values 0, false...
Analysis
1. Class or interface Parsing
2. Field Parsing
3. Class Method Parsing
4. Interface Method Parsing
Initialization
Execution class constructor <clinit>
1. Collect values of all class variables and static blocks in sequence
2. The virtual opportunity ensures that the parent class is called first <clinit>
3. Virtual opportunity ensures that a class is locked and synchronized under multiple threads.
========================================================== ==========
Class Loader
1. Check the uniqueness of the class and the loader.
2. Parents Delegation Model
Start the Class Loader Bootstrap classloader
Extension classloader
ApplicationProgramClass Loader application classloader
User classloader
Except the top-level start class loader, all other class loaders have their own parent class loaders,
Parent-child relationship uses combination to reuse the parent LoaderCode, Preferentially calls the parent class loader to load the class
3. Non-parent Delegation Model
Forward compatibility, override loadclass ()
Thread context class loader thread context classloader JNDI JDBC JCE
Program dynamics, hot replacement of hotswap Codes
Osgi, a net-structured Class Loader
1. Delegate the class starting with Java. * to the parent class loader for loading.
2. Otherwise, assign the classes in the delegate list to the parent class loader for loading.
3. Otherwise, delegate the classes in the import list to the bundle class loader of the export class.
4. Otherwise, find the classpath of the current bundle and load it with your own class loader.
5. Otherwise, check whether the class is in its fragment bundle. If it is in, assign it to the class loader of the fragment bundle.
6. Otherwise, find the bundle in the dynamic import list and assign it to the corresponding bundle classloader for loading.
7. Otherwise, the Class search fails.