This guide highlights common footguns when writing JVM agents.
- Enabling events without the required capability yields silent failures.
- Calling JNI from
GarbageCollectionStart/Finishis forbidden. - Holding JVM monitors while calling JVMTI can deadlock the VM.
JNIEnvis thread-local and invalid on other threads.- Callback order can differ across JVM implementations.
ClassFileLoadHookcan be called concurrently and very early.- Allocating memory in hot callbacks can cause severe pauses.
- Mis-sized
new_class_data_lencorrupts class loading. - JVMTI buffers must be deallocated with
Deallocate, notfree. - Some events are disabled by default for performance reasons.