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.
The top 3
- Top 3 JVMTI Events for JNI Leak Tracing: JVMTI's `VMObjectAlloc` event tracks new object allocations, while garbage collection events (like `GarbageCollectionStart` and `GarbageCollectionFinish`) provide lifecycle hooks. Additionally, heap iteration functions allow agents to inspect all objects, including those referenced by JNI global references, to identify uncollected native allocations.
- Top 3 Challenges for JVMTI Agent Development: Developing JVMTI agents is inherently complex due to the low-level API and strict rules, making them difficult to get right. A poorly written agent can destabilize or crash the entire JVM process, as it operates within the same address space. Furthermore, such agents can introduce significant performance overhead by disabling JVM optimizations like Escape Analysis or forcing deoptimizations during exceptions.
- Key Approaches to JVMTI-Based Leak Detection Tools: Official JDK demos, like the `heapTracker` agent, illustrate basic JVMTI usage for heap analysis. Commercial profilers widely leverage JVMTI for deep introspection, offering advanced features beyond simple leak detection. Furthermore, modern language bindings, such as the Rust `jvmti` crate, provide safer abstractions and explicit safety boundaries for developing robust JVMTI agents, mitigating common pitfalls of traditional C/C++ development.
Sources
Open the full topic