2013-04-04 47 views
6

「爲代碼緩存無法保留足夠的空間」,我有以下問題:Java的失敗

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

由系統看到的內存容量似乎足夠了:

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

我嘗試降低堆設置低至16MB,但它沒有幫助:

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

什麼可能是錯的?我怎樣才能調試呢?

編輯: 忘了包括版本 - 我使用Sun Java 7u15,64位。我實際上無法讓它顯示一個版本字符串,因爲「java -version」失敗時會出現相同的錯誤。

而且,由於某些原因,如果我使用的OpenJDK 6u27,它啓動 - 但是由於應用希望Java 7中,這是行不通的。

+0

已經回答了這裏: http://stackoverflow.com/questions/7350486/error-occurred-during-initialization-of-vm-could-not-reserve-enough-space-for-o – Vitaly 2013-04-04 13:44:48

+0

@維塔利 - 正如我在問題中所述,我已經嘗試過-Xmx低至16 MB - 並且「free -m」報告的內存足夠大 – Rogach 2013-04-04 13:45:49

+0

也許'16m'是不夠的。再試試! – boomz 2013-04-04 13:48:17

回答

5

看來,我的Java是在Gentoo Hardened Linux運行,並且內核已使PaX。要禁用pax內存控制,我使用了以下命令:

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

之後,一切都很順利。

-1

您可以將這些sysctl開關(在BSD是在/etc/sysctl.conf中)

security.pax.mprotect.enabled=0 
security.pax.mprotect.global=0 
security.pax.mprotect.ptrace=0 

比.... /etc/rc.d/sysctl重啓 做的 「絕招」