Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What does the loading process of the Java class include

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Most people don't understand the knowledge points of this article "What is included in the loading process of Java classes", so Xiaobian summarizes the following contents for everyone. The contents are detailed, the steps are clear, and they have certain reference value. I hope everyone can gain something after reading this article. Let's take a look at this article "What is included in the loading process of Java classes".

Class loading process mainly includes loading, validation, preparation, parsing, initialization, use, unloading seven aspects.

I. Loading

During the loading phase, the virtual machine does three main things:

1. Gets the stream of binary bytes that define a class by its fully qualified name.

2. Translate 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 Java heap as an access point to the method area data.

II. Verification

The validation phase ensures that the byte stream of the Class file contains information that conforms to JVM specifications and does not harm the JVM. If the validation fails, a java.lang.VerifyError exception or a subclass thereof is thrown. The validation process is divided into four phases:

1. File format validation: Verify that byte stream files conform to Class file format specifications and can be processed correctly by the current virtual machine.

2. Metadata validation: semantic analysis is performed on the information described by bytecode to ensure that the information described conforms to the specification of Java language.

Bytecode verification: mainly analyzes the data flow and control flow to ensure that the method of the verified class will not harm the virtual machine during operation.

4. Symbolic reference validation: Symbolic reference validation occurs when the virtual machine converts a symbolic reference to a direct reference, which occurs during the parse phase.

III. Preparation

The preparation phase allocates memory for variables and sets initialization of class variables. Only variables of the class (statically modified variables) are assigned at this stage, not instance variables of the class. For variables that are not final, the JVM sets them to "zero" instead of the value of their assignment statement:

pirvate static int size = 12;

So at this stage, the value of size is 0, not 12. Class variables modified by final will be assigned real values.

IV. Analysis

Resolution is the process of replacing symbolic references in the constant pool with direct references. It mainly includes four types of reference resolution. Class or interface resolution, field resolution, method resolution, interface method resolution.

V. Initialization

In the preparation phase, class variables are initialized once, and in this phase class variables and other resources are initialized according to the programmer's plan through the program. These resources have static{} blocks, constructors, initializations of parent classes, etc.

As for the use and unload phases, I won't explain too much here. The use process is executed according to the behavior defined by the program, and the unload is completed by GC.

The above is the content of this article about "what is included in the loading process of Java classes". I believe everyone has a certain understanding. I hope the content shared by Xiaobian will help everyone. If you want to know more relevant knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report