当前位置:网站首页>Deep understanding of JVM (I) - memory structure (I)
Deep understanding of JVM (I) - memory structure (I)
2022-06-30 18:03:00 【Zhaoliwen is a pig】
In depth understanding of JVM( One )—— Memory structure ( One )
List of articles
The overall architecture

1、 Program counter
effect
Used to hold JVM The address of the next instruction to be executed in
characteristic
- Thread private
- CPU Time slices are allocated to each thread , When the time slice of the current thread is used up ,CPU Will execute the code in another thread
- The program counter is Every thread the private Of , When the time slice of another thread runs out , When you return to executing the code of the current thread , Through the program counter, you can know which instruction should be executed
- There will be no memory overflow
2、 Virtual machine stack
Definition
- Every Threads Memory space required for operation , be called Virtual machine stack
- Each stack consists of multiple Stack frame form , Corresponds to the memory occupied each time the method is called
- Each thread can only have An active stack frame , Corresponding Currently executing method
demonstration
Code
public class Main {
public static void main(String[] args) {
method1();
}
private static void method1() {
method2(1, 2);
}
private static int method2(int a, int b) {
int c = a + b;
return c;
}
}
You can see in the console , When the method in the main class enters the virtual machine stack , Conform to the characteristics of stack
Problem Formulation
- Does garbage collection involve stack memory ?
- Unwanted . Because the virtual machine stack is composed of stack frames , After the method is executed , The corresponding stack frame will be popped out of the stack . So there is no need to recycle memory through garbage collection mechanism .
- The larger the stack memory allocation, the better ?
- No . because Physical memory is certain , The larger the stack memory , Can support more recursive calls , But the fewer threads you can execute .
- Whether local variables in methods are thread safe ?
- If within the method Local variables do not escape the scope of the method , It is Thread safety Of
- If Local variables refer to objects , and Escaped the scope of the method , You need to consider thread safety
out of memory
Java.lang.stackOverflowError Stack memory overflow
Cause of occurrence
- In the virtual machine stack , Too many stack frames ( Infinite recursion )
- Every stack frame Occupied too much
Thread running diagnostics
CPU Occupy too much
- Linux When running some programs in the environment , May lead to CPU The occupation is too high , At this time, it is necessary to locate the occupied area CPU Too high thread
- top command , Check which one is process Occupy CPU Too high
- ps H -eo pid, tid( Threads id), %cpu | grep Just passed top The process number found adopt ps Command to further see which thread is occupying CPU Too high
- jstack process id By looking at the number of threads in the process nid, Just passed ps Command to see tid Come on Contrast positioning , Be careful jstack Found thread id yes 16 It's binary , Need to transform
3、 Native Method Stack
Some with native keyword The best way is to need JAVA To call the local C perhaps C++ Method , because JAVA Sometimes you can't directly interact with the underlying operating system , So you need to use local methods
边栏推荐
- Hyper-V: enable SR-IOV in virtual network
- Splitting.js文本标题缓慢加载js特效
- 流批一体在京东的探索与实践
- Six photos vous montrent pourquoi TCP serre la main trois fois?
- Several points in MySQL that are easy to ignore and forget
- Parker proportional overflow valve rs10r35s4sn1jw
- Exch: database integrity checking
- Canvas mouse control gravity JS effect
- 【机器学习】K-means聚类分析
- Word中添加代码块(转载)
猜你喜欢
随机推荐
Daily interview 1 question - how to prevent CDN protection from being bypassed
How can you choose to work in the county after graduation?
[sword finger offer] 53 - I. find the number I in the sorted array
A tough battle for Tencent cloud
Nielseniq welcomes dawn E. Norvell, head of retail lab, to accelerate the expansion of global retail strategy
Login box tricks
墨天轮沙龙 | 清华乔嘉林:Apache IoTDB,源于清华,建设开源生态之路
Hyper-v:在虚拟网络中启用 SR-IOV
应届生毕业之后先就业还是先择业?
【二叉树】前序遍历构造二叉搜索树
[Netease Yunxin] playback demo build: unable to convert parameter 1 from "asyncmodalrunner *" to "std:: nullptr\u T"**
K-line diagram interpretation and practical application skills (see position entry)
MySQL reports that the column timestamp field cannot be null
What should I pay attention to when playing futures? Where is safe to open an account? It's my first contact
News management system based on SSM
Tencent cloud installs MySQL database
Mo Tianlun salon | Tsinghua qiaojialin: Apache iotdb, originated from Tsinghua, is building an open source ecological road
【剑指Offer】52. 两个链表的第一个公共节点
Exch:完整性检查 Database Integrity Checking
. Net ORM framework hisql practice - Chapter 1 - integrating hisql










