当前位置:网站首页>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
边栏推荐
- Do fresh students get a job or choose a job after graduation?
- 分布式机器学习:模型平均MA与弹性平均EASGD(PySpark)
- Taishan Office Technology Lecture: how to align and draw words of different sizes on the same line
- 广电5G正式启航,黄金频段将如何应用引关注
- 【剑指Offer】53 - I. 在排序数组中查找数字 I
- 分享 5 大常用的特征选择方法,机器学习入门必看!!!
- Horizontal visual error effect JS special effect code
- Babbitt | yuanuniverse daily must read: minors ask for a refund after a reward. The virtual anchor says he is a big wrongdoer. How do you think of this regulatory loophole
- Ardunio esp32 obtains real-time temperature and humidity in mqtt protocol (DH11)
- 5g has been in business for three years. Where will innovation go in the future?
猜你喜欢
Key to understanding the trend of spot Silver
Development: how to install offline MySQL in Linux system?
[zero basic IOT pwn] environment construction
What will be the game changes brought about by the meta universe?
分享 5 大常用的特征选择方法,机器学习入门必看!!!
How can you choose to work in the county after graduation?
4 years of working experience, and you can't tell the five communication modes between multithreads. Can you believe it?
【网易云信】播放demo构建:无法将参数 1 从“AsyncModalRunner *”转换为“std::nullptr_t”**
Parker Parker sensor p8s-grflx
TFTP download kernel, NFS mount file system
随机推荐
6 張圖帶你搞懂 TCP 為什麼是三次握手?
【网易云信】播放demo构建:无法将参数 1 从“AsyncModalRunner *”转换为“std::nullptr_t”**
.NET ORM框架HiSql实战-第一章-集成HiSql
[BJDCTF2020]The mystery of ip|[CISCN2019 华东南赛区]Web11|SSTI注入
Write the simplest small program in C language Hello World
Splitting.js文本标题缓慢加载js特效
Nft: unlimited possibilities to open the era of encryption Art
IEEE TBD SCI impact factor increased to 4.271, ranking Q1!
阿里云ECS导入本地,解决部署的问题
Flutter custom component
Login box tricks
4年工作经验,多线程间的5种通信方式都说不出来,你敢信?
Rexroth hydraulic control check valve z2s10-1-3x/
MIT科技评论2022年35岁以下创新者名单发布,含AlphaFold作者等
后渗透之文件系统+上传下载文件
基于eNSP的校园网设计的仿真模拟
MSF后渗透总结
Babbitt | yuanuniverse daily must read: minors ask for a refund after a reward. The virtual anchor says he is a big wrongdoer. How do you think of this regulatory loophole
A tough battle for Tencent cloud
DeFi借贷协议机制对比:Euler、Compound、Aave和Rari Capital