Solving “Error occurred during initialization of VM” on a VPS

After installing java (via yum) on a VPS, running java results in:

Error occurred during initialization of VM
Could not reserve enough space for object heap
*** glibc detected *** java: double free or corruption (out): 0x0000000041040f30 ***
======= Backtrace: =========
/lib64/libc.so.6[0x2afe08ed12ef]
/lib64/libc.so.6(cfree+0x4b)[0x2afe08ed173b]
/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/amd64/server/libjvm.so[0x2afe0978cbb4]
/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/amd64/server/libjvm.so[0x2afe0978cd78]
/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/amd64/server/libjvm.so[0x2afe09791733]
/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/amd64/server/libjvm.so(JNI_CreateJavaVM+0x74)[0x2afe0950eb14]
java(JavaMain+0x96)[0x4026c6]
/lib64/libpthread.so.0[0x2afe08841617]
/lib64/libc.so.6(clone+0x6d)[0x2afe08f32c2d]
======= Memory map: ========

This can be solved by running:

export _JAVA_OPTIONS="-Xms20m -Xmx64m -XX:MinHeapFreeRatio=20 -XX:MaxHeapFreeRatio=40 -XX:NewSize=10m -XX:MaxNewSize=10m -XX:SurvivorRatio=6 -XX:TargetSurvivorRatio=80 -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled"

Or placing it in the bashrc file.

Note: You will need to change the Xms (initial java heap size), Xmx (maximum java heap size) above depending on the amount of free memory your container has. See addendum II


Addendum I actually attempted to run this in a OpenVZ VPS. There is absolutely no hope in getting java to run under OpenVZ unless you have a lot of guaranteed memory. If you really need to get java working in your VPS, try to get a Xen or vmware based VPS.


Addendum II I got java to run on an openVZ container with 256 MB guaranteed ram using the following java arguments:

-Xms8m -Xmx16m -Xss4m

However, upon creating threads and executing commands, java failed immediately with cannot fork memory messages.

I just got a XEN 128MB / 256MB swap VPS and it ran the same java application without a single problem. I didn’t even need those arguments.

Leave a Reply

Your email address will not be published.