当前位置:网站首页>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 .
边栏推荐
- [kubernetes series] kubesphere is installed on kubernetes
- Recursive Fusion and Deformable Spatiotemporal Attention for Video Compression Artifact Reduction
- Flink memory model, network buffer, memory tuning, troubleshooting
- [freertos] freertos Learning notes (7) - written freertos bidirectionnel Link LIST / source analysis
- 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
- 2022-021ARTS:下半年开始
- BasicVSR++: Improving Video Super-Resolutionwith Enhanced Propagation and Alignment
- SQL foundation 9 [grouping data]
- Su Weijie, a member of Qingyuan Association and an assistant professor at the University of Pennsylvania, won the first Siam Youth Award for data science, focusing on privacy data protection, etc
- Boast about Devops
猜你喜欢
Zabbix agent主动模式的实现
Splicing plain text into JSON strings - easy language method
Recursive Fusion and Deformable Spatiotemporal Attention for Video Compression Artifact Reduction
Adaptive spatiotemporal fusion of multi-target networks for compressed video perception enhancement
The important role of host reinforcement concept in medical industry
CMS source code of multi wechat management system developed based on thinkphp6, with one click curd and other functions
Implementation of ZABBIX agent active mode
【森城市】GIS数据漫谈(一)
大学阶段总结
How to share the source code anti disclosure scheme
随机推荐
人生规划(Flag)
Electronic Association C language level 1 34, piecewise function
MySQL中的文本處理函數整理,收藏速查
Master-slave replication principle of MySQL database
How to input single quotation marks and double quotation marks in latex?
Experience installing VMware esxi 6.7 under VMware Workstation 16
Boosting the Performance of Video Compression Artifact Reduction with Reference Frame Proposals and
win10微软拼音输入法输入文字时候下方不出现中文提示
Transition technology from IPv4 to IPv6
Types of references in BibTex
Book list | as the technical support Party of the Winter Olympics, Alibaba cloud's technology is written in these books!
[freertos] freertos Learning notes (7) - written freertos bidirectionnel Link LIST / source analysis
2022 - 021arts: début du deuxième semestre
The frost peel off the purple dragon scale, and the xiariba people will talk about database SQL optimization and the principle of indexing (primary / secondary / clustered / non clustered)
Vulhub vulnerability recurrence 76_ XXL-JOB
Zephyr 學習筆記2,Scheduling
[untitled] notice on holding "2022 traditional fermented food and modern brewing technology"
How to send mail with Jianmu Ci
MySQL中的文本处理函数整理,收藏速查
果果带你写链表,小学生看了都说好