PhiLIOsoph

18.12.2009

Virtual server / VPS vs. Java: “Could not reserve enough space for object heap”

Filed under: Informatik,Internet,Java,Linux,PC — Robert @ 00:44:17

Today I encountered the following error message on my virtual server:

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

This error message occurred every single time Java was involved in something… Even “java -version” crashed…

After several hours I figured out it was not a problem of having too less memory but instead a problem of having too much free memory. In particular, my system (a virtual server) always seems to have a lot of free memory, which is in fact used by the other virtual server instances on the same physical machine. Thus, Java attempts to allocate a very big part of the memory (expecting it is not used otherwise). The memory allocation fails and Java crashes with the deceptive message “Could not reserve enough space for object heap”. At least this is my explanation so far…

The solution

The problem can be fixed by manually specifying the maximum heapsize. E.g., execute “java -Xmx128m -version” instead of “java -version”.

Since it is a pain and sometimes almost impossible to enable this commandline parameter (think of applications making use of java indirectly) you can make it the default by changing the environment variable _JAVA_OPTIONS. Either edit /etc/environment (persistent solution) or execute

export _JAVA_OPTIONS="-Xmx128m"

(solves the issue only for the current session).

It worked for me and I’m running Ubuntu 8.04 on a VPS hosted by Hosteurope.

© Robert Nitsch
(Powered by WordPress)