当前位置:网站首页>Introduction to JVM class loading
Introduction to JVM class loading
2022-08-05 00:44:00 【xmh - sxh - 1314】
Class loading and initialization is done only once
1, Loading (requires the support of the class loader): In this stage, a java.lang.Class object representing this class will be generated in memory as the entry for various data of this class in the method area.Note that this does not necessarily have to be obtained from a Class file. It can be read from a ZIP package (such as from a jar package and a war package), calculated at runtime (dynamic proxy), or generated by otherFile generation (such as converting JSP files into corresponding Class classes).
2, Verification: The main purpose of this stage is to ensure whether the information contained in the byte stream of the Class file meets the requirements of the current virtual machine, and will not endanger the security of the virtual machine itself.
3, preparation (all default values): The preparation phase is the phase in which memory is formally allocated for class variables and the initial value of the class variable (usually the zero value of the data type) is set, and the memory used by these variables will beAllocate 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 in the Java heap along with the object when the object is instantiated.
4, parsing: The parsing phase is a process in which the virtual machine replaces the symbolic references in the constant pool with direct references.
5. Initialization: The process of executing the class constructor clinit() method, which is formed by the compiler automatically collecting the assignments of all class variables in the class and combining the statements in the static statement block
The class initialization phase is the last step in the class loading process. At this stage, the Java program code (or bytecode) defined in the class is actually executed.In the preparation phase, the variable has been assigned the initial value required by the system, and in the initialization phase, class variables and other resources are initialized according to the subjective plan made by the programmer through the program.
Note the following:
1. The order in which the compiler collects is determined by the order in which the statements appear in the source file,
In the static statement block, only the variables defined before the static statement block can be accessed, and the variables defined after it can be assigned values in the previous static statement block, but cannot be accessed. The code is explained as follows:
Copy code
public class Test{
static{
i=0;//Assignment to variables can be compiled and passed
sout(i); //The compiler will prompt an illegal forward reference
} }
static int i = 1;
}
Copy code
2. The order in which the initialization methods are executed. The virtual machine ensures that the initialization method of the parent class has been executed before the initialization method of the subclass is executed.
3. The virtual machine ensures that a class's clinit() method is properly locked and synchronized in a multithreaded environment
4. When accessing a static field of a java class, only the class that actually declares this field will be initialized
Active reference to the class (initialization occurs)
new an object of a class
Calling static members (except final constants) and static methods of a class
When called by reflection
Start the class where the main method is located
The virtual machine ensures that the initialization method of the parent class has been executed before the initialization method of the subclass is executed,
Passive reference to class (no initialization occurs)
Referencing constants does not trigger class initialization: constants are stored in the constant pool of the calling class at compile time
Class references via arrays will not trigger initialization
When accessing a static field (static variable), only the class that actually declares the field will be initialized (subclass)
Classloader:
1. Function: Load the bytecode file into the memory, convert the static data into the runtime data structure of the method area, and generate a Class object in the heap as the access entry for the method of the class data in the method area
p>Hierarchy (tree structure)
2.ClassLoader related methods:
3, proxy for class loader
边栏推荐
- leetcode:269. 火星词典
- 如何用 Solidity 创建一个“Hello World”智能合约
- 2022 The Third J Question Journey
- Inter-process communication and inter-thread communication
- E - Many Operations (按位考虑 + dp思想记录操作后的结果
- GCC:编译时库路径和运行时库路径
- Pytorch usage and tricks
- Software Testing Interview Questions: What's the Key to a Good Test Plan?
- Software Testing Interview Questions: What do test cases usually include?
- Software Testing Interview Questions: What aspects should be considered when designing test cases, i.e. what aspects should different test cases test against?
猜你喜欢
随机推荐
Raw and scan of gorm
[230] Execute command error after connecting to Redis MISCONF Redis is configured to save RDB snapshots
Software testing interview questions: What are the seven-layer network protocols?
Theory of Software Fundamentals
oracle create user
"WEB Security Penetration Testing" (28) Burp Collaborator-dnslog out-band technology
国内网站用香港服务器会被封吗?
软件测试面试题:软件都有多少种分类?
软件测试面试题:黑盒测试、白盒测试以及单元测试、集成测试、系统测试、验收测试的区别与联系?
B站7月榜单丨飞瓜数据B站UP主排行榜发布!
2022牛客多校训练第二场 J题 Link with Arithmetic Progression
2022杭电多校 第三场 B题 Boss Rush
ora-01105 ora-03175
More than 2022 cattle school training topic Link with the second L Level Editor I
node uses redis
【无标题】
电赛必备技能___定时ADC+DMA+串口通信
JVM类加载简介
Software Testing Interview Questions: What aspects should be considered when designing test cases, i.e. what aspects should different test cases test against?
软件测试面试题:负载测试、容量测试、强度测试的区别?