1

我知道 Java VM 有“-XMx”和“-XMs”来设置堆的大小。它还有一个叫做“人机工程学”的特性,可以智能地调整堆的大小。但是,我手头有一个问题,需要严格固定大小的堆。

这是命令行参数:

"-Xms2m -Xmx2m -XX:+PrintGCDetails"

但是,通过观察 GC 日志,似乎堆的大小并没有固定在 2048K。参见,例如 2368K、2432K、2176K 等:

[GC [PSYoungGen: 480K->72K(704K)] 1740K->1332K(2368K), 0.0032190 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] 
[GC [PSYoungGen: 560K->64K(768K)] 2094K->1598K(2432K), 0.0033090 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] 
[GC [PSYoungGen: 544K->32K(768K)] 1675K->1179K(2176K), 0.0009960 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]

有没有办法对 Java 堆进行“严格的 大小调整”(不多不少)?

4

5 回答 5

4

I believe the JVM will manage the heap as you intend, but the problem in your example is that the max heap size is effectively ignored as too low.

On Sun's Windows JVM version 1.6.0_06 I believe the minimum 'max heap size' is approximately 6MB (i.e. -Xmx6m). If you attempt a setting lower then this the heap may actually grow larger. (I had thought the minimum was 16m but a little experimentation shows that values as low as 6m appear to work.)

If you set -Xms8m and -Xmx8m, however, I think you'll find the heap stays at that size.

于 2009-03-11T20:39:40.463 回答
0

除了 -Xmx 和 -Xms 之外,还有其他选项可以确定初始堆大小。查看 jvm调优指南了解详细信息。

于 2009-03-11T02:59:47.923 回答
0

我想它太小了。尝试更高的高度,例如 16m 或 64m。此外,内部和外部尺寸是不同的鞋子。堆不会一直是满的,所以小于 Xmx 总是可能的,甚至在程序刚刚启动的情况下小于 Xms。但在外部,您会看到已分配 Xms 量的内存。

于 2009-05-19T09:43:28.307 回答
0

当我第一次阅读时,我认为它说的是 2 GB ;)

不要忘记 Java 使用至少 10 - 30 MB 的非堆空间,因此您节省的几百 K 可能不会像您想象的那么大。

于 2009-05-19T19:21:41.913 回答
-1

据我所知,使用标准虚拟机是不可能的。不幸的是,我现在手头没有参考资料。

于 2009-03-10T23:42:49.613 回答