当前位置:网站首页>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 .
边栏推荐
- Boast about Devops
- BasicVSR++: Improving Video Super-Resolutionwith Enhanced Propagation and Alignment
- Master-slave replication principle of MySQL database
- It's healthy to drink medicinal wine like this. Are you drinking it right
- kubernetes集群之Label管理
- tornado之目录
- Enter the year, month, and determine the number of days
- A real penetration test
- Campus network problems
- The final week, I split
猜你喜欢
BasicVSR++: Improving Video Super-Resolutionwith Enhanced Propagation and Alignment
NLP literature reading summary
[Mori city] random talk on GIS data (I)
Improve the accuracy of 3D reconstruction of complex scenes | segmentation of UAV Remote Sensing Images Based on paddleseg
Tri des fonctions de traitement de texte dans MySQL, recherche rapide préférée
Zephyr 学习笔记2,Scheduling
Centos8 install mysql 7 unable to start up
Introduction to deep learning Ann neural network parameter optimization problem (SGD, momentum, adagrad, rmsprop, Adam)
Crawler (III) crawling house prices in Tianjin
Summary of MySQL common judgment functions!! Have you used it
随机推荐
Blue Bridge Cup Quick sort (code completion)
大学阶段总结
Enter the year, month, and determine the number of days
What is the use of cloud redis? How to use cloud redis?
[freertos] freertos Learning notes (7) - written freertos bidirectionnel Link LIST / source analysis
Introduction to sap commerce cloud B2B organization function
In the era of low code development, is it still needed?
Node foundation ~ node operation
window上用.bat文件启动项目
【FreeRTOS】FreeRTOS學習筆記(7)— 手寫FreeRTOS雙向鏈錶/源碼分析
The important role of host reinforcement concept in medical industry
MySQL error resolution - error 1261 (01000): row 1 doesn't contain data for all columns
Centos8 install mysql 7 unable to start up
Rhcsa the next day
Paddleocr prompt error: can not import AVX core while this file exists: xxx\paddle\fluid\core_ avx
CMS source code of multi wechat management system developed based on thinkphp6, with one click curd and other functions
Data double write consistency between redis and MySQL
Rhcsa day 3
com. alibaba. nacos. api. exception. NacosException
Comparison between applet framework and platform compilation