In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "what is the loading process of the class". Interested friends may wish to take a look at it. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what is the class loading process?"
The function of class loading subsystem
ClassLoader is only responsible for loading the class file, and it is up to Execution Engine to decide whether it can run or not.
The loading process of the class
1. Load:
Get the binary byte stream that defines this class through the fully qualified name of a class
Convert the static storage structure represented by this byte stream into the runtime data structure of the method area
Generate a java.lang.Class object representing this class in memory as an access entry for all kinds of data of this class in the method area
Note: how do array classes create loads?
2. Link:
Authentication (Verify):
The purpose is to ensure that the byte stream of the Class file contains information that meets the requirements of the current virtual machine, ensures the correctness of the loaded classes, and will not endanger the security of the virtual machine itself.
It mainly includes four kinds of verification, file format verification, metadata verification, bytecode verification, symbol reference verification.
Prepare (Prepare):
Allocate memory for the class variable and set the default initial value of the class variable, that is, the zero value.
Static decorated with final is not included here, because final is allocated at compile time, and the preparation phase is explicitly initialized
Instead of initializing the instance variables, the class variables are assigned in the method area, and the instance variables are assigned to the Java heap along with the object.
See LoadClass.java
Parsing (Resolve):
The process of converting symbolic references within a constant pool to direct references.
In fact, parsing operations are often accompanied by JVM after initialization.
A symbolic reference is a set of symbols that describe the referenced target. The literal form of symbolic references is clearly defined in the Class file format of the java virtual machine specification.
In the parsing phase, jvm finds the corresponding address in the memory area according to the contents of the string, and then replaces the symbolic reference with pointers, handles, offsets, etc., which directly point to the target.
Parsing actions are mainly aimed at classes or interfaces, fields, class methods, interface methods, method types, and so on. It corresponds to CONSTANT_Class_info, CONSTANT_Fieldref_info, CONSTANT_Methodref_info and so on in the constant pool.
See Demo.java
3. Initialize:
The initialization phase is the process of executing the class constructor method ().
This method does not need to be defined and is the result of the combination of the assignment action of all class variables in the class automatically collected by the javac compiler and the statements in the static code block.
Instructions in the constructor method are executed in the order in which the statements appear in the source file.
() A constructor that is different from a class. (correlation: the constructor is () from a virtual machine perspective)
If the class has a parent class, JVM ensures that the parent class () is finished before the () execution of the subclass.
The virtual machine must ensure that the () method of a class is locked synchronously under multithreading.
At this point, I believe you have a deeper understanding of "what is the loading process of the class?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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: 267
*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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.