Java teams put real effort into the JVM. Heap sizes get argued about in pull requests, and someone usually makes sure GC logs end up somewhere searchable. That work assumes the JVM is where the interesting things happen. Once a service leans on native code, through JNI or by shelling out to a binary, part of its behaviour lives somewhere those settings can't reach.
Memory the heap dump can't see
The pod gets OOMKilled with exit code 137. Someone pulls the metrics and the heap was sitting at 60% of -Xmx, and the heap dump shows nothing unusual.
The memory was allocated by malloc inside a native library, and the JVM never knew about it. Native Memory Tracking (-XX:NativeMemoryTracking=summary) reports what the JVM itself allocates, such as code cache, GC structures, metaspace and thread stacks. Allocations made by third-party native code aren't included, so the NMT total looks reasonable while the process RSS keeps climbing.
Container sizing makes this worse. A common setup is -XX:MaxRAMPercentage=75, which leaves a quarter of the container for direct buffers, metaspace, thread stacks and anything a native library decides it needs. A decoder that holds a few hundred MB of bitmaps per request fits comfortably when tests send one request at a time, and runs out of room once twenty arrive together.
glibc's allocator also contributes. To reduce lock contention it creates multiple memory arenas, up to eight per core on 64-bit systems, and a service calling native code from many threads can end up with RSS that grows and never returns to the OS. Setting MALLOC_ARENA_MAX=2 in the container environment is the usual mitigation, and switching to jemalloc is another. Both are changes to the container environment, so someone tuning JVM flags is unlikely to come across them.
The quickest diagnostic is to compare RSS from the OS against NMT's committed total over time. If the gap keeps widening, the leak is outside Java.
The library unpacks itself into /tmp
System.load needs a real file, so many JNI libraries ship the .so inside the JAR and extract it to the temp directory on first use. Netty's native transports, snappy-java, sqlite-jdbc and zstd-jni all do a version of this.
This breaks when the platform team hardens the deployment. A read-only root filesystem makes the extraction fail outright, which is at least obvious. With /tmp mounted noexec, the file gets written fine and then loading it throws an UnsatisfiedLinkError about failing to map a segment from the shared object. That message reads like a corrupted binary or the wrong architecture, and people tend to chase both of those first.
The fix is usually a system property pointing extraction at a directory that is writable and executable (Netty reads io.netty.native.workdir, the others have their own), plus a mounted volume to back it. It's worth looking up the property for each of these libraries ahead of any change to how the containers are locked down.
One classloader per library
Under JNI, a given native library can be loaded by only one classloader at a time. A second load from a different classloader fails with an UnsatisfiedLinkError saying the library is already loaded in another classloader, and pure Java code never runs into this.
App servers that redeploy a WAR without restarting the JVM hit it, because the old classloader keeps the library until it's garbage collected, which may be never. Plugin systems hit it when two plugins bundle the same library, and so do test frameworks that isolate classloaders between test classes. The standard workaround is moving the library into a shared parent classloader, which means it then gets deployed and upgraded with the server instead of with your application.
ProcessBuilder has its own list
Shelling out to a binary sidesteps JNI, so none of the above applies, though subprocesses bring problems of their own.
The best known is a deadlock. The child process writes more output than the OS pipe buffer holds, nothing on the Java side reads it, and the child blocks on write while the parent waits in waitFor() indefinitely. The Process javadoc warns about this. It only appears with inputs large enough to produce verbose output, so tests with small fixtures pass.
The simplest way out is to stop relying on pipes. Merge stderr into stdout, send both to a log file, and nothing on the Java side ever has to drain a stream. Then wait using the waitFor overload that takes a timeout. A malformed input can send a converter into a loop, and without a ceiling every stuck request holds a thread and an OS process indefinitely.
When the timeout fires, kill the process's descendants before the process itself. Plenty of tools spawn helper processes, and destroying the direct child leaves the grandchildren running. Once the parent is gone they get reparented, and Process.descendants() can no longer find them.
In a container, those orphans get reparented to PID 1. If PID 1 is the JVM, it reaps its own children and nobody else's, so the zombies accumulate until the process table fills. Running the container with Docker's --init flag or using tini as the entrypoint takes care of it.
Fonts come from the operating system
Native renderers read their environment in ways most Java code doesn't. Headless browsers, office suites and PDF tools ask fontconfig what's installed and substitute when a document asks for a font that isn't there. A developer laptop typically has hundreds of fonts installed, while a slim container image may have a handful or none.
The conversion still succeeds and the output changes. Text reflows, and a table that fit on one page can spill onto two. Nothing gets logged, so it's often a customer who spots the difference.
To be fair to the native side, the JDK on Linux depends on fontconfig too, and a JVM in an image without it fails as soon as anything touches font metrics, headless or not. It does at least fail with an error. Fonts should be installed explicitly in the Dockerfile like any other dependency, with a rendering test that compares output against a reference file.
The JDK has started asking about this
JDK 24 shipped JEP 472, which makes System.load and System.loadLibrary restricted methods. The first time code in a module calls one without native access enabled, the JVM prints a warning naming the caller. The default mode is warn, --illegal-native-access=deny turns each illegal call into an IllegalCallerException, and the stated plan is for deny to become the default in a later release. Classpath code can be granted access with --enable-native-access=ALL-UNNAMED.
If you're on JDK 25, the current LTS, those warnings are a free inventory of JNI use you may not have known about. JDK 24 also added jnativescan, which statically scans your application's JARs and their dependencies, then reports which ones declare native methods or call restricted ones. It finds them before anything runs, which the runtime warning can't do.
Neither tool sees subprocesses, because running a binary through ProcessBuilder never touches a restricted method. In your own code, a search for ProcessBuilder and Runtime.exec finds them quickly. Subprocess calls inside third-party libraries are harder to track down and need the library's source or a decompiler.
I work at IDRsolutions, which sells pure Java PDF and image libraries, so I have a commercial reason to notice these problems. Every check above works the same on your stack whoever wrote the native code in it.