当前位置:网站首页>JVM -- class loading process and runtime data area
JVM -- class loading process and runtime data area
2022-07-04 07:28:00 【Mingvvv】
List of articles
Compile and decompile
compile
javac -eancoding utf-8 ./Test.java
Specify the encoding format , Generate Test.class Bytecode file , Not easy for developers to interpret
Bytecode files are JVM Identify and run , If it is necessary to facilitate developers to view the corresponding contents of the compiled bytecode file , You can use the following instructions
Decompile
javap -p -v ./Test.class > ./Test.txt
View all instruction information of class file , Bytecode will compile the assembly into a convenient format .
Class loading
load | link | initialization |
---|---|---|
verification ⇨ Get ready ⇨ analysis |
Class file -> Byte stream -> Class loader
load
- Store the compiled bytecode file in the method area
- Create a in the heap java.lang.Class The object of , To serve as an access to data in the method area
link
verification
Verify the file format of bytecode file 、 data 、 Whether the symbol reference is correct
Get ready
Allocate memory for static variables of a class
analysis
Turn symbolic references into direct references .
Symbol references are stored in the running time pool .
Symbol references in class There are only some descriptions in the document , You need to open up a piece of its corresponding real physical memory in the virtual machine
Class loader
loader | function | |
---|---|---|
BootStrap Classloader | ⇨ | load $JAVA_HOME/jre/lib/rt.jar All in class perhaps -Xbootclasspath Option specified jar package , |
ExtClassLoader | ⇨ | load Java Some of the extensions in the platform jar package , Include $JAVA_HOME/jre/lib/*.jar or -Djava.ext.dirs Under the specified directory jar package |
AppClassLoader | ⇨ | load classpath Specified in the jar Package and -Djava.class.path The classes in the specified directory and jar package |
Custom ClassLoader | ⇨ | adopt java.lang.ClassLoader Custom loading of subclasses class , It belongs to the application customized according to its own needs ClassLoader, Such as tomcat,jboss Will be based on j2ee Norms are self actualized ClassLoader |
example
public class Test
{
public static void main(String[] args) {
//classpath Class loader under AppClassLoader
System.out.println(new Test().getClass().getClassLoader());
//ExtClassLoader
System.out.println(new Test().getClass().getClassLoader().getParent());
//BootStrap Classloader c Language implementation ,java It cannot be displayed on the level
System.out.println(new Test().getClass().getClassLoader().getParent().getParent());
}
}
Print the results
sun.misc.Launcher$AppClassLoader@18b4aac2
sun.misc.Launcher$ExtClassLoader@39a054a5
null
Parent delegate mechanism
If the current loader has a parent loader , Delegate to the parent loader to find the class object , Up to the top floor . This class does not exist in the parent class , You have to find and load it yourself , If you can't find this class , Then return to ClassNotFoundException Type error .
Run time data area
Method area
Save the type information that has been loaded by the virtual machine 、 Constant 、 Static variables 、 Timely compiled code cache and other data .
The method area is created when the virtual machine starts , All threads share , Life cycle and java Process bound .
The runtime constant pool is in the method area
Pile up
Store object information , Thread sharing
Java Stack
Java Stack frames are stored one by one , Each stack frame corresponds to a called method , Include local variable table in stack frame 、 The stack of operands 、 Dynamic links 、 Method and some additional information . When a thread executes a method , A corresponding stack frame will be created , And stack the established stack frame . When the method is finished , Then the stack frame will be out of the stack . So we know , The stack frame corresponding to the method currently executed by the thread must be located Java The top of the stack .
Dynamic links : A reference to the runtime constant pool of the class to which the current method belongs . Symbolic references are converted to direct references during initialization or first use . Symbolic reference refers to the compilation process , Referenced variables 、 Method 、 Classes and other information have not been loaded into the virtual machine , Therefore, it can only be stored in class In the constant pool of files . Dynamic linking is to convert these symbolic references into direct references that can be called .
The stack of operands : During the instruction , The copied constants or variables in the fields of the local variable table or object instance will be written to the operand stack , Then stack the elements in the stack to the local variable table or return them to the method caller with the calculation .
Method return address : Store the value of the program counter calling the method . Method execution , The address of the next instruction of the caller of the method will be returned .
Native Method Stack
The local method stack serves to execute local methods . stay JVM Specification , There is no mandatory requirement for the implementation method and data structure of local method stack , Virtual machines are free to implement it . stay HotSopt In the virtual machine, the local method stack and Java Stack as one .
Program counter
Also called PC register , Save the address of the instruction currently executed by the program ( It can also be said that the address of the storage unit where the next instruction is stored ), When CPU When an instruction needs to be executed , You need to get the address of the storage unit where the current instruction to be executed is from the program counter , And then get the instructions according to the obtained address , After getting the order , The program counter will automatically add 1 Or get the address of the next instruction according to the transfer pointer , So circular , Until all instructions have been executed .
Because a CPU Only one instruction can be processed at a time , Therefore, the implementation of multithreading is essentially to switch frequently between multiple threads to achieve parallel implementation . By recording the address of the next instruction of the current thread , Thus, when switching back to the current thread JVM Be able to know what instructions to execute .
边栏推荐
- [thread pool]
- Write a thread pool by hand, and take you to learn the implementation principle of ThreadPoolExecutor thread pool
- 电脑通过Putty远程连接树莓派
- Master-slave replication principle of MySQL database
- Life planning (flag)
- BasicVSR++: Improving Video Super-Resolutionwith Enhanced Propagation and Alignment
- BibTex中参考文献种类
- Splicing plain text into JSON strings - easy language method
- [Chongqing Guangdong education] National Open University spring 2019 770 real estate appraisal reference questions
- MYCAT middleware installation and use
猜你喜欢
[kubernetes series] kubesphere is installed on kubernetes
BasicVSR++: Improving Video Super-Resolutionwith Enhanced Propagation and Alignment
用于压缩视频感知增强的多目标网络自适应时空融合
提升复杂场景三维重建精度 | 基于PaddleSeg分割无人机遥感影像
电脑通过Putty远程连接树莓派
Knowledge payment applet dream vending machine V2
Recursive Fusion and Deformable Spatiotemporal Attention for Video Compression Artifact Reduction
Zephyr 学习笔记2,Scheduling
Recursive Fusion and Deformable Spatiotemporal Attention for Video Compression Artifact Reduction
Vulhub vulnerability recurrence 76_ XXL-JOB
随机推荐
The IP bound to the socket is inaddr_ The meaning of any htonl (inaddr_any) (0.0.0.0 all addresses, uncertain addresses, arbitrary addresses)
Used on windows Bat file startup project
Transition technology from IPv4 to IPv6
Crawler (III) crawling house prices in Tianjin
Finishing (III) - Exercise 2
BasicVSR++: Improving Video Super-Resolutionwith Enhanced Propagation and Alignment
The number of patent applications in China has again surpassed that of the United States and Japan, ranking first in the world for 11 consecutive years
Vulhub vulnerability recurrence 77_ zabbix
The crackdown on Huawei prompted made in China to join forces to fight back, and another enterprise announced to invest 100 billion in R & D
In the era of low code development, is it still needed?
Pangu open source: multi support and promotion, the wave of chip industry
[real case] how to deal with the failure of message consumption?
NLP-文献阅读总结
Improve the accuracy of 3D reconstruction of complex scenes | segmentation of UAV Remote Sensing Images Based on paddleseg
Types of references in BibTex
Research on an endogenous data security interaction protocol oriented to dual platform and dual chain architecture
Mysql database - function constraint multi table query transaction
Four sets of APIs for queues
Zephyr 學習筆記2,Scheduling
Paddleocr prompt error: can not import AVX core while this file exists: xxx\paddle\fluid\core_ avx