Home  >  Article  >  Java  >  What is the process of jvm class loading

What is the process of jvm class loading

coldplay.xixi
coldplay.xixiOriginal
2020-08-12 15:08:123158browse

The process of jvm class loading: first perform the loading; then verify that the information contained in the byte stream of the Class file meets the requirements of the current virtual machine; then prepare to allocate memory for the static variables of the class and initialize it to the system's Initial value; finally parsed and initialized.

What is the process of jvm class loading

jvm class loading process:

1. Loading

The jvm does these three things when loading:

1) Obtain the binary byte stream of a class through the fully qualified name of the class

2) Convert the static byte stream of this class The storage structure is converted into a runtime data structure in the method area

3) Generate a java.lang.Class object representing the class in the memory heap as the access entrance to the data of the class

2. Verification

The three steps of verification, preparation, and analysis can be regarded as a connection process, connecting the bytecode of the class to the running status of the JVM

Verification is to ensure that the information contained in the byte stream of the Class file meets the requirements of the current virtual machine and will not threaten the security of the jvm

Verification mainly includes verification in the following aspects:

1) Verification of file format, verifying whether the byte stream conforms to the specifications of the Class file and whether it can be processed by the current version of the virtual machine

2) Metadata verification, performing semantic analysis on the information described by the bytecode, Ensure compliance with Java language specifications

 3) Bytecode verification passes data flow and control flow analysis to determine that the semantics are legal and logical

 4) Symbol reference verification This check is performed during parsing Stage occurs

3. Prepare, allocate memory for the static variables of the class, and initialize it to the initial value of the system. For variables modified by final static,

is directly assigned to the user-defined value. As in the following example: the initial value after the preparation phase is 0 instead of 7

public static int a=7

4. Parsing

Parsing is to convert the symbol reference in the constant pool into a direct reference (such as a physical memory address pointer)

5. Initialization

At the initialization stage, the jvm really starts Execute the java code defined in the class

1) The initialization phase is the process of executing the class constructor () method. The class constructor() method is generated by the compiler automatically collecting the assignment actions of all class variables in the class and merging the statements in the static statement block (static block).

2) When initializing a class, if it is found that its parent class has not been initialized, you need to trigger the initialization of its parent class first.

3) The virtual machine ensures that the () method of a class is correctly locked and synchronized in a multi-threaded environment.

What is the process of jvm class loading

Related learning recommendations:
java basic tutorial

The above is the detailed content of What is the process of jvm class loading. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn