The meta-agent project now supports instrumenting native Java agents by hot-patching the JVM. Native agents use the JVMTI API (written in C/C++) and register ClassFileLoadHook callbacks via SetEventCallbacks. The technique works by overriding the SetEventCallbacks function pointer in the JVMTI environment struct so the meta-agent intercepts all subsequent agent registrations. To support multiple agents, a fixed array of wrapper functions is generated via macros. Communication between the native wrapper and the Java meta-agent is handled through temporary files in /tmp to avoid circular class loading issues. This enables visibility into bytecode transformations performed by native agents like async-profiler's method tracer, and even reveals that the Java instrumentation agent (libinstrument) instruments itself.

10m read timeFrom mostlynerdless.de
Post cover image
Table of contents
BackgroundPatching JVMTISupporting Multiple AgentsCommunicating with the meta-agentUsing the Native AgentConclusionAuthorRelated Posts:

Sort: