I am having an issue with a JNI program randomly running out of memory.
This is a 32 bit java program which reads a file, does some image processing, typically using
The following assumes you're using the hotspot jvm.
32bit processes are not just constrained by committed memory, far more importantly they're constrained by virtual memory, i.e. reserved address space. On 64bit systems you only have 4GB worth of addresses that can be used, on 32bit systems it's only 2-3GB.
The JVM will reserve a fixed, possibly large amount of address space for the managed heap up front, then dynamically allocates some internal structures on top of that amount and then possibly even more for DirectByteBuffers or memory-mapped files. This can leave very little room for native code to run.
Use Native Memory Tracking to determine how much various parts of the JVMs are using and pmap
to check for memory-mapped files. Then try to limit that without hampering your application.
Alternatively you could spawn a new process and do the image processing there.