简体   繁体   English

避免初始内存堆大小错误

[英]Avoiding Initial Memory Heap Size Error

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选项,以便我们可以执行代码?

You've exceeded the maximum heap size of your JVM. 您已超过JVM的最大堆大小。 This is both JVM and OS dependent. 这是JVM和OS相关的。 In most 32-bit systems the maximum value will be 2Gb, regardless of the physical memory available. 在大多数32位系统中,无论可用的物理内存如何,最大值都是2Gb。

By default Java will run in 32 bit mode. 默认情况下,Java将以32位模式运行。 Be sure to give it the -d64 option to put it into 64 bit mode. 一定要给它-d64选项,使其进入64位模式。 Once in 64-bit mode, you shouldn't have any trouble allocating a 6GB JVM. 一旦进入64位模式,分配6GB JVM就不会有任何问题。

Actually, the maximum memory size on 32-bit systems can vary, being anything up to 4 GB, but 2 GB is a common value. 实际上,32位系统上的最大内存大小可能会有所不同,最高可达4 GB,但2 GB是一个常见值。 It's often possible to re-link your kernel to increase this to 3 or 3.5 GB. 通常可以重新链接内核以将其增加到3或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? 你试过一台64位机器吗?

Also, remember to set your ulimit higher before you do this. 此外,请记住在执行此操作之前将ulimit设置得更高。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM