Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java fails with "Could not reserve enough space for code cache"

Tags:

java

memory

crash

I have the following problem:

$ java -jar program.jar
Error occurred during initialization of VM
Could not reserve enough space for code cache

The amount of memory that is seen by the system seems sufficient:

$  free -m
             total       used       free     shared    buffers     cached
Mem:          5959        640       5318          0          0        390
-/+ buffers/cache:        249       5710
Swap:         4099          0       4099

I tried lowering heap settings as low as 16mb, but it didn't help:

$ java -Xmx16m -Xms16m -jar program.jar
Error occurred during initialization of VM
Could not reserve enough space for code cache

What can be wrong? How can I debug this?

EDIT: Forgot to include version - I use Sun Java 7u15, 64 bit. I actually can't get it to display a version string, because "java -version" fails with the same error.

Also, for some reason, if I use OpenJDK 6u27, it starts up - but since the app expects java 7, it doesn't work.

like image 645
Rogach Avatar asked Apr 04 '13 13:04

Rogach


1 Answers

Seems that my java was running on Gentoo Hardened Linux, and kernel had PaX enabled. To disable pax memory control, I used the following command:

paxctl -c -m /path/to/your/java/bin/java

After that, everything was smooth.

like image 55
Rogach Avatar answered Sep 21 '22 08:09

Rogach