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 is the loading process of the Java class

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly explains "what is the loading process of Java classes". The explanation in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian and go deep into it slowly to study and learn "what is the loading process of Java classes" together.

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 stages

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.

Thank you for reading, the above is "Java class loading process is how" the content, after the study of this article, I believe we have a deeper understanding of Java class loading process is how this problem, the specific use of the situation also needs to be verified. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

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