Essential Tools for JNI Global Reference Leak Detection
Effective diagnosis relies on tools like heap dump analyzers (e.g., Eclipse MAT, JProfiler) to visualize GC roots, the JVM's Native Memory Tracking (NMT) for native memory insights, and runtime checks such as `-Xcheck:jni` (or Android's CheckJNI) to flag incorrect JNI usage.
The top 3
- JVMTI Agents: Deepest JNI Reference Tracking: Custom JVMTI agents offer the most precise control, allowing developers to intercept `NewGlobalRef` and `DeleteGlobalRef` calls directly to log and track every JNI global reference's lifecycle for leak identification.
- NMT: First Line for JNI Memory Growth: The JVM's Native Memory Tracking (`-XX:NativeMemoryTracking=summary|detail`) provides categorized breakdowns of native memory usage, quickly highlighting if the JNI category is experiencing significant, unexplained growth indicative of leaks.
- Custom JNI Wrappers: Development-Time Leak Insight: Implementing custom wrapper functions for JNI calls or adding explicit logging around `NewGlobalRef` and `DeleteGlobalRef` in native code offers immediate, granular visibility into reference management during development and testing.
Sources
Open the full topic