Java 避免初始内存堆大小错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/909018/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 20:57:55  来源:igfitidea点击:

Avoiding Initial Memory Heap Size Error

javamemory-management

提问by neversaint

I run a Java code with the following command:

我使用以下命令运行 Java 代码:

$ java -Xms4G -Xmx4G myjavacode

My cpu's RAM capacity is 6GB.

我的 cpu 的 RAM 容量是 6GB。

However it always fail to execute giving me this error message:

但是它总是无法执行给我这个错误信息:

Invalid initial heap size: -Xms5G
The specified size exceeds the maximum representable size.
Could not create the Java virtual machine

Is there any way to set up Java option so that we can execute the code?

有没有办法设置Java选项以便我们可以执行代码?

采纳答案by kgiannakakis

You've exceeded the maximum heap size of your JVM. This is both JVM and OS dependent. In most 32-bit systems the maximum value will be 2Gb, regardless of the physical memory available.

您已超出 JVM 的最大堆大小。这取决于 JVM 和操作系统。在大多数 32 位系统中,最大值将为 2Gb,而不管可用的物理内存如何。

回答by cjs

Actually, the maximum memory size on 32-bit systems can vary, being anything up to 4 GB, but 2 GB is a common value. It's often possible to re-link your kernel to increase this to 3 or 3.5 GB. The issue, of course, is that you just don't have the address space to map more memory. Have you tried a 64-bit machine?

实际上,32 位系统上的最大内存大小可能会有所不同,最高可达 4 GB,但 2 GB 是常见值。通常可以重新链接您的内核以将其增加到 3 或 3.5 GB。当然,问题是您没有地址空间来映射更多内存。您是否尝试过 64 位机器?

Also, remember to set your ulimit higher before you do this.

另外,请记住在执行此操作之前将 ulimit 设置得更高。

回答by brianegge

By default Java will run in 32 bit mode. Be sure to give it the -d64 option to put it into 64 bit mode. Once in 64-bit mode, you shouldn't have any trouble allocating a 6GB JVM.

默认情况下,Java 将在 32 位模式下运行。请务必为其提供 -d64 选项以将其置于 64 位模式。一旦进入 64 位模式,分配 6GB JVM 就不会有任何问题。