Virtual Machine Loading Class Mechanism

Load--connect (verify, prepare, parse)--initialize--use--unload

   If and only if "initialization" in 5 cases: such as the new keyword, reflection, and the parent class is not initialized when a class is initialized, then initialize the parent class, the class of the main method, and the methodHandle method in JDK1.7.

   Loading:
       Loading does three things:

        1. Get the binary byte stream that defines this class through the fully qualified name of a class

        2. Convert the static storage structure represented by this byte stream into the runtime data structure of the method area

        3. Generate a java.lang.Class object representing various types in memory as the access entry for various data of this class in the method area

   verify: 

        File format validation, metadata validation, bytecode validation, symbol reference validation

   Prepare:

     Formally allocate memory for class variables and set variable initial values. The memory used by these variables will be allocated in the method area
   public static int value = 123;
        class variables refer to static variables, the value will be set to 0 in the preparation stage, and the value of 123 will be executed in the initialization stage

 Parse:

         The parsing phase is the process by which the virtual machine replaces symbolic references in the constant pool with direct references 

    initialization:

         The actual execution of the JAVA code,,,, <clinit>() method is generated by the compiler automatically collects the assignment action of all class variables in the class and the static statement block (static{}) statement. The order of collection is determined by the order of appearance.

   

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324944996&siteId=291194637