Class loader in-depth parsing and phase decomposition

Class loading phase

  • In Java code,typetheloading.The connectionwithInitialize theThe process is all in the programDuring the period of runningcomplete
  • Provides greater flexibility and increases possibilities

loading

  • Load the class file of an existing disk’s class into memory

The connection

  • The processing, verification, and verification of bytecode
  • Symbolic references between classes are converted to direct references

Initialize the

  • Assign to static variables

The JVM specification imposes constraints on the class-loading phase, but the specifics depend on the JVM environment at run time.

End-of-life situations

  • System.exit()
  • The program completes correctly
  • The execution is terminated due to an exception or error
  • The Java virtual machine process was terminated due to an operating system error. Procedure

Class loading, linking, and initialization

loading

Find and load the binary data for the class

The connection

Segmentation process

  • Validation: Ensures that the required classes are correct

    Make sure no tampering, correct

  • Preparation: Allocates memory for static variables of the class and initializes them to default values

    During the preparation phase, no specific value is assigned to the variable. In the following code, a is initialized to the default value 0 during the preparation phase

    class Test{
    	public static int a = 1;
    }
    Copy the code
  • Parse: Convert symbolic references to classes into direct references

    • Symbolic reference: can be understood as an indirect reference, such as a method of one class referring to another class
    • Direct reference: Refers a method directly to the target object’s memory as a pointer

Initialize the

Assign correct initial values to static variables of the class

use

The program normally uses classes, the usual phase of dealing with

uninstall

Unmount a class from memory, which is unusable, but can also be reloaded into memory. For example the OSGI

Class loading flowchart

The end product of class loading

The loading end product of a Class is an in-memory Class object that encapsulates the Class’s data structure in the method area and provides Java developers with an interface to access the data structure in the method area