Home > Java > javaTutorial > body text

java--detailed explanation of the class loading process

php是最好的语言
Release: 2018-08-10 13:57:48
Original
2155 people have browsed it

1. Loading

1. Obtain 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 this class in the memory as an access entry for various data of this class in the method area.

2. Verification

1. File format verification

Verify whether the byte stream conforms to the Class file format specification and can be used by the current version Virtual machine processing.

2. Metadata verification

Perform

semantic analysis on the bytecode seconds information to ensure that the information described complies with the java language specificationrequirements.

3. Bytecode verification

Through data flow and control flow analysis,

determine that the program semantics are legal and logical. After the second round of verification of the data types in the metadata information, the class methods will be verified and analyzed at this stage to ensure that the methods of the verified class will not cause any events that endanger the security of the virtual machine during runtime. .

4. Symbol reference verification

Perform matching verification on information other than the

class itself (various symbol references in the constant pool), in order to ensure the parsing action It can be executed normally. If the symbol reference verification cannot be passed, an exception will be thrown.

3. Preparation

This is the stage of formally allocating memory for class variables and setting the initial values ​​of class variables. The memory used by these variables will be allocated in the method area.

At this time, memory allocation only includes class variables (variables modified by static), not instance variables. Instance variables will be allocated to the Java heap together with the object when the object is instantiated, and Initialization of a class variable does not assign the class variable to the final initialization value, but only assigns it to the zero value of the data type.

For example, public static int value=123; in the preparation phase, the value is only assigned to the zero value of int, which is 0, not 123 (123 will be assigned after the program is compiled)

4. Parsing

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

Symbol reference can be any form of literal, which may be different according to different virtual machines, but they can all be located at the target and are defined in the class file.

A direct reference is a pointer that can directly point to the target, a relative offset, or a handle that can indirectly locate the target.

5. Initialization

At the initialization stage, the execution of the defined java program code begins. In this phase, the programmer initializes class variables and other resources through a subjective plan made by the program.

The real assignment is performed at this stage, which is the public static int value=123 in the preparation stage; At this stage the value will now be assigned to 123

Related Recommended:

Detailed graphic explanation of the process of JVM loading a class

Analysis of loading order of classes in Java (commonly used in interview questions)

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!