打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
java堆与非堆的一些研究
java有堆内存,可以通过-xms -xmx来进行控制,当然使用该参数控制的也只是堆内存.
1. 为什么启动tomcat后我设置的最大xmx为64,但实际可能占用128
原因:内存说明见下:

Heap Memory Pool 
A. Eden Space(heap):大多数物件初始化时从Eden Space池分配记忆体,即是存在于此池中 
B. Survivor Space(heap):此池包含的物件是那些原先在eden space中,但是已经经历过垃圾回收而仍然存在的物件。 
C. Tenured Generation(heap):在surviver space中已经存在了一段时间之后的物件会移动到这个池中。

Non-Heap Memory Pool 
D. Code Cache (non-heap):储存编译的程式码和local variables。 
E. Permanent Generation(non-heap):包含虚拟机器自身的所有反射资料。 比如classmothod物件。 对于使用class data sharing的JVM,分为唯读(shared-ro)读写(shared-rw)两个区域。

由上可知,jvm除占用堆内存外还占用了非堆内存,该非堆内存可能占用的和堆内存一样大.
2.非堆内存会垃圾回收吗?
可以:

Can the permanent generation be garbage collected?

Yes it can. There is often the misconception that string constants cannot be garbage collected. However the only requirement that the JVM specification stipulates is that identity comparison works for constant string values. There is no requirement that the constant be the same object throughout the lifetime of the JVM. Hence if there are no references left to a string constant, there is no reason why it cannot be garbage collected.

To prove this take the following code:

 public class PermGenDemo {  public static void main(String[] args) {    int i = 0;    while (true) {      ("string-" + ++i).intern();    }  }}

If the above code is run using the following command:

 $ java -verbose:gc -XX:PermSize=8m -XX:MaxPermSize=64m PermGenDemo

The following output will be seen (note output cut for brevity):

 [Full GC [PSYoungGen: 32K->0K(28928K)] . . . [PSPermGen: 65535K->6461K(65536K)]][Full GC [PSYoungGen: 32K->0K(31168K)] . . . [PSPermGen: 65535K->6461K(65536K)]]
The above conclusively shows that the permanent generation is collected and when it requires collecting, triggers a full collection.
 
另有一张清晰的图可以说明:
3.非堆内存里面还有什么?
非堆内存里面还有code cache,正在研究如何控制他们.
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
JVM调优
性能测试总结之内存泄露和内存溢出
Java 内存模型及GC原理
Java深入:JVM内存堆布局图解分析
java虚拟机内存管理机制(二):了解JVM的内存管理与垃圾回收
JVM内存:年轻代、老年代、永久代(推荐 转)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服