当前位置:网站首页>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
边栏推荐
- [sword finger offer] sword finger offer 53 - ii Missing numbers from 0 to n-1
- Exch: repair the missing system mailbox
- [BJDCTF2020]The mystery of ip|[CISCN2019 华东南赛区]Web11|SSTI注入
- JS from prototype chain to inheritance
- 编写C语言的最简单小程序Hello world
- 基于SSM的新闻管理系统
- [machine learning] K-means clustering analysis
- [binary tree] preorder traversal to construct binary search tree
- 【剑指Offer】53 - I. 在排序数组中查找数字 I
- Rainbow Brackets 插件的快捷键
猜你喜欢
随机推荐
应届生毕业之后先就业还是先择业?
DeFi借贷协议机制对比:Euler、Compound、Aave和Rari Capital
[sword finger offer] 53 - I. find the number I in the sorted array
Design and principle of tubes responsive data system
Ten thousand volumes - list sorting [01]
Animesr: learnable degradation operator and new real world animation VSR dataset
svg实现的订票UI效果
Distributed machine learning: model average Ma and elastic average easgd (pyspark)
Cloud practice of key business migration of Internet of things by well-known Internet housing rental service companies
[BJDCTF2020]The mystery of ip|[CISCN2019 华东南赛区]Web11|SSTI注入
IEEE TBD SCI影响因子提升至4.271,位列Q1区!
【架构】1366- 如何画出一张优秀的架构图
5g business is officially commercial. What are the opportunities for radio and television?
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
Flutter custom component
自旋锁探秘
How can you choose to work in the county after graduation?
NFT: 开启加密艺术时代的无限可能
大文件处理(上传,下载)思考
Tubes响应性数据系统的设计与原理










