当前位置:网站首页>快速串讲——JVM内存的区域划分
快速串讲——JVM内存的区域划分
2022-04-22 13:24:00 【万猫学社】
目的
- 快速定位JVM内存泄漏或者溢出等问题。
- 面试基础题,加分项。
程序计数器(Program Counter Register)
- 记录当前线程所执行的字节码的行号。
- 依赖其实现分支、循环、跳转、异常处理、线程恢复。
- Natvie 方法时,其的值就为空。
- Java 虚拟机规范中唯一没有规定内存溢出的区域。
- “线程私有”的内存区域。
虚拟机栈(Virtual Machine Stacks)
- 其生命周期与线程相同。
- 存储局部变量表、操作数栈、动态链接、方法出口等信息。
- 方法被执行的时候创建一个栈帧并入栈。
- 方法执行完成的时候对应栈帧出栈。
- 栈的深度过大时,抛出 StackOverflowError 。
- 线程数过多时,抛出 OutOfMemoryError 。
- “线程私有”的内存区域。
本地方法栈(Native Method Stacks)
- 为虚拟机使用到的 Native 方法服务。
- 栈的深度过大时,抛出 StackOverflowError 。
- 线程数过多时,抛出 OutOfMemoryError 。
- “线程私有”的内存区域。
堆(Java Heap)
- 用于存放对象实例,是JVM占用内存最大一块区域。
- 垃圾收集器管理的主要区域。
- 使用分代收集算法时,堆被细分为新生代和老年代,新生代再细分为Eden空间、 From Survivor 空间、 To Survivor 空间。
- 在HotSpot虚拟机中,通过-Xmx和-Xms控制堆的大小,通过-Xmn控制新生代的大小。
- 堆可以处于物理上不连续的内存空间中,只要逻辑上是连续的即可。
- 没有内存完成实例分配时,抛出 OutOfMemoryError 。
- “线程共享”的内存区域,线程共享的堆中又可能划分出多个线程私有的分配缓存区(Thread Local Allocation Buffer,TLAB)。
方法区(Method Area)
- 存储已被JVM加载的类信息、常量、静态变量、即时编译器编译后的代码。
- 回收目标主要是针对常量池的回收和对类型的卸载。
- 可以选择不实现垃圾收集。
- 当方法区无法满足内存分配需求时,将抛出 OutOfMemoryError 。
- JDK6 使用永久代实现方法区。
- JDK7 中永久代的字符串常量池被移出。
- JDK8 使用元空间实现方法区。
- “线程共享”的内存区域。
总结
- 程序计数器:当前线程所执行的字节码的行号指示器。
- 虚拟机栈:Java方法执行的内存模型,用于存储局部变量表、操作数栈、动态链接、方法出口等信息。
- 本地方法栈:本地方法执行的内存模型,和虚拟机栈非常相似,其区别是本地方法栈为 JVM 使用到的 Native 方法服务。
- 堆:用于存储对象实例,是垃圾收集器管理的主要区域。
- 方法区:用于存储已被JVM加载的类信息、常量、静态变量、即时编译器编译后的代码等数据。
版权声明
本文为[万猫学社]所创,转载请带上原文链接,感谢
https://cloud.tencent.com/developer/article/1985726
边栏推荐
- [introduction to keras] MNIST dataset classification
- Array and string offset access syntax with curly braces is deprecated
- MySQL8. 0 learning record 08 - data type default
- Redis如何查看单个key所占用的内存大小
- HDU 2680 最短路 Dijkstra + 链式向前星 + 优先队列(模板)
- Algorithm --- reverse linked list (kotlin)
- 各省GTFP綠色全要素生產率面板數據(2004-2018年)
- API of H5 mobile terminal
- Summary of maximum matching number, minimum path coverage number, maximum independent number and minimum point coverage number theorems
- ROS2——手把手教你编写一个话题
猜你喜欢

FreeRTOS quick start

ROS机器人学习——麦克纳姆轮运动学解算

稻盛和夫:直面现实、拼命思考、正面迎击

销量大腰斩,岚图无蓝图

Inamori Kazuo: face the reality, think hard and fight head-on

Can ainai get out of the dilemma by 35 billion yuan?

FreeRTOS快速入门-初探FreeRTOS

Trying to access array offset on value of type int

Digital business cloud electronic bidding system solution - standardize the political procurement process and improve work efficiency

Communication principle of SPI protocol
随机推荐
POJ 3259 shortest SPFA + negative ring (template)
最大匹配数,最小路径覆盖数,最大独立数,最小点覆盖数 定理总结
Panel data of green total factor productivity of gtfp in all provinces (2004-2018)
Trying to access array offset on value of type int
Partition - elegant violence
How to use colormaps and customize your favorite colorbar?
Redis persistence
RT thread configuration SPI flash (w25q256)
Alibaba cloud changes its commander and competes for Huawei's territory
Learn shell script (5) -- function, random number, regular expression
原来,这才是开发者打开世界读书日的正确姿势!
Redisconfig configuration class
FreeRTOS快速入门-初探FreeRTOS
PM4PY - BPMN support
Drawing violin picture with R language geom_ Violin, how to add additional points geom_ point? geom_ violin + geom_ boxplot + geom_ Point combination
中英文会计&金融情绪词典
Wechat applet adds data to the database
MPU6050-DMP读不出数据
Walk in the clouds - travel to the edge of the universe
redis持久化