当前位置:网站首页>JVM runtime data area
JVM runtime data area
2022-07-03 14:00:00 【It's hard to choose a name】
List of articles
The following partitions are logical partitions ;
Class loader will class Static data structures are loaded into lvm in , The runtime data area stores these data ;
jvm Similar to von Neumann computer model :
1、 input device : Class loader , take class File loaded into jvm
2、 Memory : Run time data area
3、 Output devices :jvm Binary instructions output to the underlying operating system
4、 a central processor :( Arithmetic unit 、 controller ):
jvm It is similar to cpu Interaction with memory :
1、 Main memory :
Analogy method area and heap : Thread shared
2、cpu Cache in :
Thread private java Virtual machine stack 、 Native Method Stack 、 Program counter
Method area
The method area is actually a specification , Different java Virtual machines need to be implemented by themselves
jdk1.8 Previous implementations : Forever (PermGen)
jdk1.8 And after : Meta space (PermGen)
What data is stored in the method area ?
1、 String constant pool (jdk1.6 Previously stored in permanent generation ,1.8 And later actually stored in the heap )
2、 Static variables ( Stored in the heap in the meta space )
3、 Class information :( Meta space is stored in direct memory )
Version number 、 Field 、 Method 、 Interface 、 Description information such as parent class
4、 Immediately compiled code ( Such as final Embellished )
5、 Runtime constant pool
The method area is shared by threads
Static constant pool
Static constant pool is relative to runtime constant pool , Of description class Part of the file structure , from Literal and Symbol reference form , After the class is loaded, the static constant pool will be loaded into memory, that is, the runtime constant pool
Literal : Text , String and Final Decorated content
Symbol reference : class , Interface , Method , Fields and other related description information
Runtime constant pool
class , Interface , Method , Fields and other related description information , That is to really put the contents of the document into JVM The memory
String volume pool
String is the most commonly used data type , To reduce memory overhead , A memory area is specially opened for it ( String constant pool ) To store ;
JDK1.6 And previous versions , The string constant pool is located in the permanent generation ( Equivalent to the current method area ).
JDK1.8 And after , The string constant pool is located at Heap In the pile
common problem :String a ="aaaa"; At most one string object is generated
First “aaaa” Will be considered literal , First look in the string constant pool (.equals()), If not found , Create... In the heap “aaaa”
String object , And will “aaaa” The reference of is maintained in the string constant pool ( It's actually a hashTable structure , Deposit key-value
Structural data ), Then return the reference ; If it already exists in the string constant pool “aaaa” References to , Return the reference directly .
String a =new String("aaaa"); Create up to two objects
First “aaaa” Will be considered literal , First look in the string constant pool (.equals()), If not found , Create... In the heap “aaaa”
String object , Then create a... In the heap “aaaa” object , Go back “aaaa” References to
intern()
String s1 = new String("xxx");
String s2 = s1.intern();
System.out.println(s1 == s2); //false
String Medium intern The method is a native Methods , When calling intern When the method is used , If the constant pool already contains one equal to this String
Object's string ( use equals(object) Method determination ), Then return the string in the pool . otherwise , take intern The returned reference points to the current
character string s1(jdk1.6 The version needs to be s1 Copy to the string constant pool )
Pile up
The heap is thread shared What is stored in the heap ?
1、 Object instances and arrays
2、 The... Of the corresponding class created after the class is loaded java.lang.Class object
java Virtual machine stack
Thread private
1、 The virtual machine stack is a thread execution area , Save the call state of a method in a thread . let me put it another way , One Java The running state of the thread
state , Saved by a virtual machine stack , So the virtual machine stack must be thread private , Unique , Created with the creation of threads
2、 Every method executed by a thread , Is the stack frame in the stack , That is, each method corresponds to a stack frame . Call a method , Will be pushed into the stack
A stack frame ; A method call is completed , It will pop the stack frame out of the stack
For example, method calls :
void a(){
b();
}
void b(){
c();
}
void c(){
}

Stack frame
Thread private
1、 Each stack frame corresponds to a called method , It can be understood as the running space of a method
2、 Each stack frame contains a list of local variables (Local Variables)、 The stack of operands (Operand Stack)、 A reference to the runtime constant pool
(A reference to the run-time constant pool)、 Method return address (Return Address) And additional information
1、 Local variable table : The local variables defined in the method and the parameters of the method are stored in this table
Variables in local variable table cannot be used directly , If necessary , It must be loaded into the operand stack as an operand through related instructions
Use .
2、 The stack of operands : The method of storing operands by pressing and leaving the stack
3、 Dynamic links : Each stack frame contains a reference to the method that the stack frame belongs to in the runtime constant pool , This reference is held to support methods
Dynamic connection in the calling process (Dynamic Linking).
4、 Method return address : When a method starts executing , There are only two ways to exit , One is to encounter the bytecode instruction returned by the method ; One is
Encountered exception , And the exception is not handled in the method body .
Program counter
Thread private
We all know one JVM There are multiple threads executing in the process , And whether the content in the thread can have execution right , It's based on CPU From the dispatch
If a thread A Executing to somewhere , Suddenly lost CPU The enforcement of , Switch to thread B 了 , And then when the thread A And get CPU Executive power
When , How can we continue ? This is the need to maintain a variable in the thread , Record where the thread is executed .
If the thread is executing Java Method , Then the counter records the address of the executing virtual machine bytecode instruction ;
If what is being executed is Native Method , Then this counter is empty .
Native Method Stack
Thread private
1、 If the current thread execution method is Native Type of , These methods will be executed in the local method stack .
2、 Well, if it's in Java Method is called when it is executed native How about the method ?
Associate through dynamic link in stack frame
1、 The stack points to the heap
In the method A a=new A(), Local variable references point to heap objects ( In fact, there may be escape behavior , If this object is used
The scope is only in the method , Then the object will not exist in the heap , convenient GC);
2、 The method area points to the heap
Static variable references point to objects in the heap
3、 Heap points to method area
How does an object know which class it was created from ? When the objects in the heap are stored, some additional information will be stored : such as class point Point to
Class information stored in the method area ; It also stores mark word( Storage lock identification 、gc Age at )、 Example data ( It's the instance variable )、( If it is an array, the length of the array will be stored additionally )、 Alignment filling
边栏推荐
- QT learning 21 standard dialog box in QT (Part 2)
- Another industry has been broken by Chinese chips. No wonder the leading analog chip companies in the United States have cut prices and sold off
- Unable to stop it, domestic chips have made another breakthrough, and some links have reached 4nm
- Qt学习20 Qt 中的标准对话框(中)
- Error running 'application' in idea running: the solution of command line is too long
- Flutter dynamic | fair 2.5.0 new version features
- 1px problem of mobile terminal
- Software testing is so hard to find, only outsourcing offers, should I go?
- Qt学习22 布局管理器(一)
- Spring cup eight school league
猜你喜欢

Use and design of Muduo buffer class

Solve MySQL 1045 access denied for user 'root' @ 'localhost' (using password: yes)

可编程逻辑器件软件测试

SQL Injection (POST/Search)

太阳底下无新事,元宇宙能否更上层楼?

Use docker to build sqli lab environment and upload labs environment, and the operation steps are provided with screenshots.
[email protected](Fe)|甘草次酸修饰金属有机框架材料UiO-66-NH2(简称UiO-66-NH2-GA)"/>MIL-100( Fe) 包裹小分子阿司匹林形成[email protected](Fe)|甘草次酸修饰金属有机框架材料UiO-66-NH2(简称UiO-66-NH2-GA)

Go language web development series 27: Gin framework: using gin swagger to implement interface documents

JVM系列——概述,程序计数器day1-1

GoLand 2021.2 configure go (go1.17.6)
随机推荐
金属有机骨架MOFs装载非甾体类抗炎药物|ZIF-8包裹普鲁士蓝负载槲皮素(制备方法)
全局事件总线
Field problems in MySQL
Qt学习23 布局管理器(二)
Solve MySQL 1045 access denied for user 'root' @ 'localhost' (using password: yes)
Replace the GPU card number when pytorch loads the historical model, map_ Location settings
QT learning 22 layout manager (I)
Cross linked cyclodextrin metal organic framework loaded methotrexate slow-release particles | metal organic porous material uio-66 loaded with flavonoid glycosides | Qiyue
php 迷宫游戏
Use docker to build sqli lab environment and upload labs environment, and the operation steps are provided with screenshots.
JS continues to explore...
【BW16 应用篇】安信可BW16模组与开发板更新固件烧录说明
记录关于银行回调post请求405 问题
Doxorubicin loaded on metal organic framework MIL-88 DOX | folic acid modified uio-66-nh2 doxorubicin loaded [email
Spring cup eight school league
可编程逻辑器件软件测试
解决MySql 1045 Access denied for user ‘root‘@‘localhost‘ (using password: YES)
Disruptor -- a high concurrency and high performance queue framework for processing tens of millions of levels
jvm-类加载
Go language web development series 26: Gin framework: demonstrates the execution sequence of code when there are multiple middleware