JVM memory

JVM memory consist of heap , non-head and other

heap: which is the storage for java objects and array
堆存储对象和数组
non-heap: which is used by java to store loaded classs and other metadata
非堆存储class和meta信息
other: JVM code itself, JVM internal strcutures, loaded profiler agent code and data, etc

heap is the runtime data area from which memory for all class instances and array allocated. It created at the JVM start-up.
the heap size may be configured with the following VM options
-Xms: to set the initial java heap size 初始化大小
-Xmx: to set the maximum java heap size 最大值
By default, the maximum size is 64Mb
heap memory for objects is reclaimed by an automatic management system which is known as Garbage Collector. The heap may be a fixed of szie or expanded and shrunk, depending on the GC's strategy
head中的对象被GC回收
heap: 分为3个区
eden: new object
survivor(2): after GC operation still survivor
old generation: long lifecycle

eden和2个survivor组成新生代。
young generation consist of eden, and 2 survivor, have one survivor is always empty.

when young generation is full, then trigger minor collection(YGC), the survivor objects will move to tenured generation. Last when tenured generation is full, the cause magor collection(Full GC), it will collect all heap, incude young generation. permanent generation is stable, store classLoader info.
当新生代满了,则执行YGC把survivor里面的对象移到old中。如果old满了,则执行full GC,对整个堆进行回收。permanet一般不变。


non-heap
store the per-class structure, such as runtime constant pool, field and method data, and the code for method and contructors, as well as interned String
非堆存放class结构信息,常量池,字段方法等信息。
configure
-XX:PermSize 初始化大小
-XX:MaxPermSize(default 64Mb) 最大值
non-heap:分为2个区
permanent generation: store class, method and field
code cache: compile and store native code and do optimize


JVM运行时数据的区域:
PC寄存器
JVM支持多个线程,每个线程都有自己的pc寄存器,如果线程执行的方法不是本地方法,则pc寄存器存储当前线程执行方法的地址,若为Native,则未定义。

JVM方法栈
线程私有,描述java方法调用是的内存模型。每个方法被执行的时候都会创建帧栈,用于存储局部变量,操作栈,动态链接,方法出口等信息。有时候会粗分栈,堆,栈就是指这里的栈。而在线程中有个工作内存和主内存,这个jvm栈是线程私有,所以这里的工作内存指这里。


本地方法栈:为虚拟机使用到的Native方法服务

JVM堆:存放对象实例和数组

方法区(非堆):存放class的结构信息,包括常量池,字段描述,方法描述。这里的GC主要对常量池的回收和类的卸载。


java内存溢出问题:
java.lang.OutOfMemoryError:java heap space. JVM heap溢出
调节-Xmx大小

java.lang.OutOfMemoryError:PermGen space.
调节-XX:MaxPermSize大小

java.lang.StackOverflowError:栈溢出
调节-Xss大小


查看线程
jvisualVM
查看内存运行情况
jconsole
查询jvm进程id
jps
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值