Linux 无法为对象堆保留足够的空间来启动 JVM

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6642184/
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-05 05:02:00  来源:igfitidea点击:

Could not reserve enough space for object heap to start JVM

javalinuxmemoryjvm

提问by user12384512

Just faced with strange issue. When i type

刚刚面临奇怪的问题。当我输入

java -version

i got

我有

Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.

.

.

java -Xms64m -Xmx64m -version

This command works fine

这个命令工作正常

java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) Client VM (build 19.1-b02, mixed mode)

If i change xms, xmx to 128m, i get error again.

如果我将 xms、xmx 更改为 128m,我将再次出错。

Using topcommand and free -mi can see, that i got over 192 mb free, so why i still get this error ?

使用top命令,free -m我可以看到,我有超过 192 mb 的可用空间,为什么我仍然收到此错误?

Mem:    262144k total,    64760k used,   197384k free,        0k buffers
Swap:        0k total,        0k used,        0k free,        0k cached

Thank you

谢谢

采纳答案by Jesper

It looks like the machine you're trying to run this on has only 256 MB memory.

看起来你试图运行它的机器只有 256 MB 内存。

Maybe the JVM tries to allocate a large, contiguous block of 64 MB memory. The 192 MB that you have free might be fragmented into smaller pieces, so that there is no contiguous block of 64 MB free to allocate.

也许 JVM 会尝试分配一个大的、连续的 64 MB 内存块。您拥有的 192 MB 可用空间可能会被分成更小的部分,因此没有连续的 64 MB 可用空间可供分配。

Try starting your Java program with a smaller heap size, for example:

尝试使用较小的堆大小启动 Java 程序,例如:

java -Xms16m ...

回答by mico

According to this postthis error message means:

根据这篇文章,此错误消息意味着:

Heap size is larger than your computer's physical memory.

堆大小大于计算机的物理内存。

Edit:Heap is not the only memory that is reserved, I suppose. At least there are other JVM settings like PermGenSpace that ask for the memory. With heap size 128M and a PermGenSpace of 64M you already fill the space available.

编辑:我想堆不是唯一保留的内存。至少还有其他 JVM 设置,例如 PermGenSpace 需要内存。使用 128M 的堆大小和 64M 的 PermGenSpace,您已经填满了可用空间。

Why not downsize other memory settings to free up space for the heap?

为什么不缩小其他内存设置以释放堆空间?

回答by Yamada

I had the same problem when using a 32 bit version of java in a 64 bit environment. When using 64 java in a 64 OS it was ok.

在 64 位环境中使用 32 位版本的 java 时,我遇到了同样的问题。在 64 位操作系统中使用 64 位 java 时没问题。