如何修复Java堆的大小

时间:2022-11-07 19:07:24

I know Java VM has "-XMx" and "-XMs" for setting the size of the heap. It also has a feature called "ergonomics", that can intelligently adjust the size of the heap. But, I have a problem at hand requiring the heap with strictly fixed size.

我知道Java VM有“-XMx”和“-XMs”来设置堆的大小。它还有一个名为“人体工程学”的功能,可以智能地调整堆的大小。但是,我手头有一个问题,要求堆具有严格固定的大小。

Here is the command line arguments:

这是命令行参数:

"-Xms2m -Xmx2m -XX:+PrintGCDetails"

However, by observing the GC logs, it seems the size of the heap was not fixed at 2048K. See, e.g. 2368K, 2432K, 2176K, etc:

但是,通过观察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]

Is there a way to do the "strict sizing" (no more no less) of a Java heap?

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

5 个解决方案

#1


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.

我相信JVM会按照您的意图管理堆,但是您的示例中的问题是最大堆大小实际上被忽略为太低。

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.)

在Sun的Windows JVM版本1.6.0_06上,我认为最小'最大堆大小'大约是6MB(即-Xmx6m)。如果您尝试设置较低,那么堆可能实际上变大。 (我原以为最小值是16米,但是一些实验表明,低至6米的值似乎有效。)

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

但是,如果你设置-Xms8m和-Xmx8m,我认为你会发现堆保持这个大小。

#2


0  

There are other options along with -Xmx and -Xms that determine the initial heap size. Check the jvm tuning guide for details.

还有其他选项以及-Xmx和-Xms来确定初始堆大小。有关详细信息,请查看jvm调整指南。

#3


0  

I guess it is just too small. Try something higher, like 16m or 64m. Additionally the internal and the external size are different shoes. The heap will not be full all the time, so a less than Xmx is always possible, even a less than Xms in case the program just has been started. But externally, you will see that Xms amount of memory has been allocated.

我想这太小了。尝试更高的东西,比如16米或64米。此外,内部和外部尺寸是不同的鞋子。堆不会一直都是满的,所以总是可以小于Xmx,即使程序刚刚启动也不到Xms。但在外部,您将看到已分配Xms内存量。

#4


0  

When I first read that I thought it said 2 GB ;)

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

Don't forget Java uses at least 10 - 30 MB of non heap space so the few hundred K you save might not make as much difference as you think.

不要忘记Java使用至少10 - 30 MB的非堆空间,所以你节省的几百K可能没有你想象的那么多。

#5


-1  

As far as I know this is not possible using the standard VM. Unfortunately I have no references at hand right now.

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

#1


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.

我相信JVM会按照您的意图管理堆,但是您的示例中的问题是最大堆大小实际上被忽略为太低。

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.)

在Sun的Windows JVM版本1.6.0_06上,我认为最小'最大堆大小'大约是6MB(即-Xmx6m)。如果您尝试设置较低,那么堆可能实际上变大。 (我原以为最小值是16米,但是一些实验表明,低至6米的值似乎有效。)

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

但是,如果你设置-Xms8m和-Xmx8m,我认为你会发现堆保持这个大小。

#2


0  

There are other options along with -Xmx and -Xms that determine the initial heap size. Check the jvm tuning guide for details.

还有其他选项以及-Xmx和-Xms来确定初始堆大小。有关详细信息,请查看jvm调整指南。

#3


0  

I guess it is just too small. Try something higher, like 16m or 64m. Additionally the internal and the external size are different shoes. The heap will not be full all the time, so a less than Xmx is always possible, even a less than Xms in case the program just has been started. But externally, you will see that Xms amount of memory has been allocated.

我想这太小了。尝试更高的东西,比如16米或64米。此外,内部和外部尺寸是不同的鞋子。堆不会一直都是满的,所以总是可以小于Xmx,即使程序刚刚启动也不到Xms。但在外部,您将看到已分配Xms内存量。

#4


0  

When I first read that I thought it said 2 GB ;)

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

Don't forget Java uses at least 10 - 30 MB of non heap space so the few hundred K you save might not make as much difference as you think.

不要忘记Java使用至少10 - 30 MB的非堆空间,所以你节省的几百K可能没有你想象的那么多。

#5


-1  

As far as I know this is not possible using the standard VM. Unfortunately I have no references at hand right now.

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