如何确定 Java 堆的大小

发布于 2024-07-15 01:01:51 字数 703 浏览 6 评论 0原文

我知道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 堆进行“严格 调整大小”(不多也不少)?

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.

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 [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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

生生不灭 2024-07-22 01:01:56

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

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

浅浅淡淡 2024-07-22 01:01:56

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

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

When I first read that I thought it said 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.

攒眉千度 2024-07-22 01:01:55

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

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.

伴我心暖 2024-07-22 01:01:55

我相信 JVM 会按照您的预期管理堆,但您示例中的问题是最大堆大小因太小而被有效忽略。

在 Sun 的 Windows JVM 版本 1.6.0_06 上,我相信最小“最大堆大小”约为 6MB(即 -Xmx6m)。 如果您尝试设置低于此值,堆实际上可能会变得更大。 (我原以为最小值是 16m,但一些实验表明低至 6m 的值似乎也有效。)

但是,如果您设置 -Xms8m 和 -Xmx8m,我认为您会发现堆保持在该大小。

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.

情仇皆在手 2024-07-22 01:01:55

还有其他选项以及 -Xmx 和 -Xms 来确定初始堆大小。 检查 jvm 调优指南 了解详情。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文