当前位置:网站首页>JVM内存模型解析
JVM内存模型解析
2022-07-26 02:57:00 【ni?】
JVM内存模型解析
内存结构示意图:

public class Dome{
public static void main(String[] args){
Student stu = new Student();
stu.study();
stu.hash();
stu = null;
}
}
在Dome类运行的全过程:
1、Dome类被javac解析成字节码被JVM识别
2、创建main线程时,占用的是虚拟机栈内存并开始运行main方法
3、如果遇到未见过的类(例如Dome、Student),会继续调用类加载过程,将类的原始信息(类的名称,方法、继承关系、成员变量等)存入方法区
4、new 对象Student存储在栈中(内存大小:计算成员变量预计所占的内存)
6、调用方法时,所需要的临时变量、方法参数都存入了虚拟机的栈帧内存中
7、调用方法时,会从方法区中得到该方法的字节码指令,并由解释器将字节码转换成机器码交由CPU执行
8、调用方法时,会将正在执行的指令行数存储在程序计数器中
9、对于虚拟机栈和本地方法栈,java所使用的Oracle的Hotspot虚拟机并未划分详细,调用本地方法hash同样使用了虚拟机栈的内存。
10、调用方法时,方法多次调用,解释器同样多次调用浪费资源,所有对于热点方法会用到即时编译器来编译
11、当对象不再使用的时候,内存不足时会触发GC回收机制回收堆内存空间。
会出现内存溢出的部分
注意:程序计数器不会发生内存溢出
抛出OutOfMemoryError错误:
堆内存:当对象不断被创建并且一直被占用时
虚拟机栈:虚拟机栈中每个线程占1M内存,当线程的个数越来越多而长时间运行不销毁
方法区:加载的类越来越多
总结:
方法区主要负责存放类加载时的相关信息
虚拟机栈负责线程、临时变量、临时参数的存放
堆负责存放对象
程序计数器负责记录程序运行的位置
边栏推荐
- 如何加速矩阵乘法
- Be highly vigilant! Weaponization of smartphone location data on the battlefield
- [steering wheel] tool improvement: common shortcut key set of sublime text 4
- The sixth day of the third question of daily Luogu
- pbootcms上传缩略图尺寸自动缩小变模糊
- 如何有效的去防止别人穿该网站首页快照
- assert _ Aligns
- Pbootcms upload thumbnail size automatically reduces and blurs
- After clicking play, the variables in editorwindow will be destroyed inexplicably
- Masscode is an excellent open source code fragment manager
猜你喜欢

Arthas download and startup

Safety margin of mass consumption

Masscode is an excellent open source code fragment manager

GAMES101复习:光栅化

Jenkins' study notes are detailed
![[steering wheel] tool improvement: common shortcut key set of sublime text 4](/img/51/fe95e95ccd5cd6406f3b49e3bdba3f.png)
[steering wheel] tool improvement: common shortcut key set of sublime text 4

Self-supervised learning method to solve the inverse problem of Fokker-Planck Equation

Chapter 3 business function development (delete clues)

图像识别(六)| 激活函数

VOFA+ 串口调试助手
随机推荐
微信公众号互助、开白群,小白报团取暖
这种动态规划你见过吗——状态机动态规划之股票问题(上)
ES6高级-利用原型对象继承方法
AMD64 (x86_64) architecture ABI document:
如何加速矩阵乘法
图像识别(六)| 激活函数
Turn on the LED
Arthas view the source code of the loaded class (JAD)
Annotation development
I hope you can help me with MySQL
Neo4j import CSV data error: neo4j load CSV error: couldn't load the external resource
Machine learning foundation plan 0-2: what is machine learning? What does it have to do with AI?
How to design automated test cases?
(九)属性自省
Get hours, minutes and seconds
How to design test cases according to the requirements of login testing?
Jenkins' study notes are detailed
Cycle and branch (I)
pbootcms上传缩略图尺寸自动缩小变模糊
Games101 review: rasterization