Java class loading process

Source: Internet
Author: User

Class loading process

1. Loading

The load phase mainly completes three things, that is, through the fully qualified name of a class to obtain the definition of such a binary byte stream, the byte stream represented by the static storage structure into the runtime data structure of the method area, in the Java heap to generate a class object representing such, as the access to the method area of the data entry. This loading process is mainly implemented by the ClassLoader, which can be used by the user to customize the loading process of the class.

2. Verification

This phase is intended to ensure that the class file's byte stream contains information that meets the current virtual machine requirements and does not compromise the virtual machine itself. Includes four types of verification:

File format verification: based on byte stream validation, verify that the byte stream conforms to the class file format specification and can be processed by the current virtual machine.

Meta-data validation: Based on the storage structure validation of the method area, the semantic verification of the bytecode description information is made.

Bytecode verification: Data flow and control flow validation based on the storage structure validation of the method area.

Symbol Reference validation: The storage structure validation based on the method area, which occurs in the parsing, whether the symbolic reference can be successfully resolved to a direct reference.

3. Preparation

Allocating memory only for a class variable (that is, the static modified field variable) and setting the initial value of that class variable as a value of 0, which does not include the final decorated static, because final is allocated at compile time, and the instance variable is not assigned initialization. Class variables are allocated in the method area, and instance variables are assigned to the Java heap along with the objects.

4. Analysis

Parsing is essentially the process of replacing a symbolic reference in a constant pool with a direct reference. A symbolic reference is a set of symbols that describe a target, which can be any literal, whereas a direct reference is a pointer to a target, a relative offset, or a handle that is indirectly anchored to the target. There are class or interface parsing, field parsing, class method parsing, and interface method parsing.

It is important to note that if a field of the same name appears in both the interface and the parent class of a class, the compiler will generally refuse to compile.

5. Initialization

The initialization phase is still the initialization class variable and other resources, where the user's static field and static statement block assignment operations are performed. This process is the process of executing a class constructor method.

method is generated by a statement that collects assignment actions for all class variables in a class and statements from a static statement block, and the class constructor method differs from the instance constructor method, which does not show the method that calls the parent class, and the method of the parent class automatically executes the method of the subclass first. That is, the static statement blocks and static fields defined by the parent class are assigned the variable assignment action of the precedence child class.


Java class loading process

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: [email protected] and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.