Friday 4 January 2013

High memory java death

I recently further upgraded my system's memory to 12GBs.


I turned the computer on and everything worked just fine.
I popped open Thunderbird and Chrome and everything was right with the world. Until suddenly, Thunderbird just dies when I opened the Chat tab. I found that rather odd, but the bug was reproducible. I couldn't really be bothered with debugging it, had more important things to do, but then Chrome started randomly dying. I ran it through the command line, and the error was "Bus error" and chrome://crashes/ didn't show anything. Obviously, I immediately blamed the new memory stick: it must be faulty!

I also noticed that my ebuild of NetBeans and LibreOffice were failing as well, although other ebuilds were unaffected. The ebuilds failed with


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

Which sounds odd. I mean, 12 GBs of RAM and Java says no memory? Well, I did disable the kernel's over-allocation, but surely it would have made no difference.
I Googled about this and found out that the VM will allocate a quarter of a system's ram for the heap. Well, a quarter of my system's ram is 3GBs, which in a 32bit system would surely make the address space of the process rather tight, which would explain why the kernel simply refused it. Oh wait, according to that page I found, the VM clamps this allocation to 1GB. That's odd. I wonder if they took into account that a 32 bit system can have more than 4GBs and used a large variable to store the system's total memory (ie, if they used a 32 bit integer and queried the number of bytes available in my ram, it would surely have overflown).

I switched to other VMs; I was using Sun's, and tried Oracle's and IcedTea, but all failed with the same error.

Alas the solution was simple:

export _JAVA_OPTIONS="-Xmx640m"

And emerge built NetBeans and LibreOffice with no problems. For some strange reason, if I increase the value (from 640) the Java death returns. No idea why.
Oh yeah, you still need an export to get emerge going with forced Java options

export I_WANT_GLOBAL_JAVA_OPTIONS=true

No comments:

Post a Comment