How does my jre exceed its heap limits?

Solution 1:

The heap limit is the limit of the JVM heap presented to Java applications (no Java program can allocate more than that amount of space on the heap), but does not limit the size of the Java process (which includes the JVM heap that you're limiting, plus any items allocated by the JVM itself, plus the stack (for the JVM and your Java application), plus other stuff I'm almost certainly leaving out.

Normally you won't see much more than 10-15% bloat over the limits you set, but pathological cases probably exist, and there may even be a memory leak or other bug in the java runtime itself (good luck debugging that pig).

If you want to limit the size of the Java runtime at the OS level you should probably look in to the ulimit command. The JVM may handle hitting those limits gracefully.

Solution 2:

There's the off heap area which includes memory allocated by JNI code and Direct Byte buffers. You can control the last using -XX:MaxDirectMemorySize.