当前位置:网站首页>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
边栏推荐
- [idea] idea configures sql formatting
- 2022杭电多校第三场 L题 Two Permutations
- ORA-01105 ORA-03175
- 电赛必备技能___定时ADC+DMA+串口通信
- BC(转)[js]js计算两个时间相差天数
- Matlab uses plotting method for data simulation and simulation
- Software testing interview questions: What are the three modules of LoadRunner?
- Memory Forensics Series 1
- 软件测试面试题:LoadRunner 分为哪三个模块?
- 国内网站用香港服务器会被封吗?
猜你喜欢
leetcode:266. 回文全排列
If capturable=False, state_steps should not be CUDA tensors
金九银十面试跳槽季;你准备好了吗?
"WEB Security Penetration Testing" (28) Burp Collaborator-dnslog out-band technology
MongoDB construction and basic operations
oracle创建用户以后的权限问题
QSunSync Qiniu cloud file synchronization tool, batch upload
JVM类加载简介
JUC线程池(一): FutureTask使用
Theory of Software Fundamentals
随机推荐
gorm joint table query - actual combat
2022 Hangzhou Electric Power Multi-School Session 3 K Question Taxi
[230] Execute command error after connecting to Redis MISCONF Redis is configured to save RDB snapshots
2022 Hangzhou Electric Multi-School 1004 Ball
软件测试面试题:软件验收测试的合格通过准则?
[idea] idea configures sql formatting
tiup status
2022 Multi-school Second Session K Question Link with Bracket Sequence I
oracle创建表空间
机器学习(公式推导与代码实现)--sklearn机器学习库
leetcode:269. 火星词典
tensor.nozero(), mask, [mask]
QSunSync 七牛云文件同步工具,批量上传
软件测试面试题:软件测试类型都有哪些?
GCC:编译时库路径和运行时库路径
Software testing interview questions: What are the seven-layer network protocols?
canvas 高斯模糊效果
MongoDB construction and basic operations
tiup status
软件测试面试题:BIOS, Fat, IDE, Sata, SCSI, Ntfs windows NT?