Java进程内存检查测试 [英] Java process memory check test
问题描述
我试着看看 -Xmx
和 -Xms
参数如何影响我的程序并查看内存的数量我的进程消耗。
I tried to see how -Xmx
and -Xms
parameters impact on my program and check how much memory does my process consume.
我写了一个简单的程序,但我无法推断出结果。请帮忙。
I wrote a simple program but am not able to reason out the results. Kindly help.
public static void main( String[] args ) {
char[] array = new char[69926904];
}
我使用参数 -Xms5M运行 - Xmx200M
即可。理想情况下,由于字符占用2个字节,因此在超出内存限制之前应保留100M字符。即使我们说,很少有空间用于指针和长度,我不知道,为什么它会在 69926904之后抛出错误 长度。
I ran with parameters -Xms5M -Xmx200M
. Ideally, since a character takes 2 bytes, it should hold 100M characters before exceeding the memory limit. Even if we say, few space is getting used for pointer and length, I don't know, why it is throwing error after 69926904 length.
谢谢。
推荐答案
请仔细阅读 JVM垃圾收集调整指南关于Generational Heap,它有望回答你的问题。
Read carefully JVM Garbage Collection Tuning Guide about Generational Heap, and it will hopefully answer your question.
用 -XX运行Java:+ PrintGCDetails
选项,一切都应该变得清晰:
Run Java with -XX:+PrintGCDetails
option, and everything should become clear:
Heap
PSYoungGen total 3584K, used 294K [0x00000000fbd60000, 0x00000000fc160000, 0x0000000100000000)
eden space 3072K, 9% used [0x00000000fbd60000,0x00000000fbda9860,0x00000000fc060000)
from space 512K, 0% used [0x00000000fc0e0000,0x00000000fc0e0000,0x00000000fc160000)
to space 512K, 0% used [0x00000000fc060000,0x00000000fc060000,0x00000000fc0e0000)
PSOldGen total 136576K, used 136576K [0x00000000f3800000, 0x00000000fbd60000, 0x00000000fbd60000)
object space 136576K, 100% used [0x00000000f3800000,0x00000000fbd60000,0x00000000fbd60000)
PSPermGen total 21248K, used 2595K [0x00000000ee600000, 0x00000000efac0000, 0x00000000f3800000)
object space 21248K, 12% used [0x00000000ee600000,0x00000000ee888db0,0x00000000efac0000)
你的200M Java堆由2代组成:1/3(66.7M)是YoungGen,2/3(133.3M)是OldGen。
Your 200M Java Heap consists of 2 generations: 1/3 (66.7M) is YoungGen and 2/3 (133.3M) is OldGen.
-XX:NewRatio
选项允许更改比例,但默认值2意味着YoungGen将保留堆的1 /(2 + 1)部分。
-XX:NewRatio
option allows to change the proportion, but the default value of 2 means that YoungGen will reserve 1/(2+1) part of the heap.
Java对象不能跨越世代,因此对象的最大大小不能大于最大代。在你的情况下,最大的一代是OldGen:136576K = 139853824,它的大小正好是 char [69926904]
(16字节标题+ 2 * 69926904字节的数据)。
Java objects cannot span generations, so the maximum size of object cannot be larger than the largest generation. In your case the largest generation is OldGen: 136576K = 139853824 which is exactly the size of char[69926904]
(16 bytes header + 2 * 69926904 bytes of data).
这篇关于Java进程内存检查测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!