当前位置:网站首页>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 .
边栏推荐
- 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
- Pangu open source: multi support and promotion, the wave of chip industry
- Introduction to sap commerce cloud B2B organization function
- 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
- Industrial computer anti-virus
- Research on an endogenous data security interaction protocol oriented to dual platform and dual chain architecture
- Introduction to deep learning Ann neural network parameter optimization problem (SGD, momentum, adagrad, rmsprop, Adam)
- 大学阶段总结
猜你喜欢

Distributed transaction management DTM: the little helper behind "buy buy buy"

Text processing function sorting in mysql, quick search of collection

Four sets of APIs for queues

NLP-文献阅读总结

Implementation of ZABBIX agent active mode

果果带你写链表,小学生看了都说好

Experience installing VMware esxi 6.7 under VMware Workstation 16

What is the use of cloud redis? How to use cloud redis?
![[Valentine's day] - you can change your love and write down your lover's name](/img/ab/402872ad39f9dc58fd27dd6fc823ef.jpg)
[Valentine's day] - you can change your love and write down your lover's name

Rhcsa day 3
随机推荐
It's healthy to drink medicinal wine like this. Are you drinking it right
Crawler (III) crawling house prices in Tianjin
Introduction to rce in attack and defense world
Comparison between applet framework and platform compilation
Selenium driver ie common problem solving message: currently focused window has been closed
Chapter 1 programming problems
Valentine's Day is coming! Without 50W bride price, my girlfriend was forcibly dragged away...
Distributed transaction management DTM: the little helper behind "buy buy buy"
Unity 从Inspector界面打开资源管理器选择并记录文件路径
What is the use of cloud redis? How to use cloud redis?
The idea of implementing charts chart view in all swiftui versions (1.0-4.0) was born
Recursive Fusion and Deformable Spatiotemporal Attention for Video Compression Artifact Reduction
The important role of host reinforcement concept in medical industry
Boosting the Performance of Video Compression Artifact Reduction with Reference Frame Proposals and
How to send mail with Jianmu Ci
MySQL中的文本處理函數整理,收藏速查
电脑通过Putty远程连接树莓派
Take you to master the formatter of visual studio code
【FreeRTOS】FreeRTOS學習筆記(7)— 手寫FreeRTOS雙向鏈錶/源碼分析
大厂技术专家:架构设计中常用的思维模型