- What it is: A special
.jar with a premain (for startup agents) or agentmain (for runtime attach) method defined in its MANIFEST.MF.
- How it works: Loaded by the JVM before your main application starts (
premain), or dynamically attached to an already-running JVM (agentmain).
- Powers:
- Can use the Instrumentation API to inspect or modify bytecode of classes as they are being loaded.
- Works across the whole JVM, not just where your code references it.
- Common for monitoring, profiling, APMs (e.g., New Relic, SkyWalking, Arthas).
- Lifecycle: Intercepts class loading at the JVM level; your app code doesn’t need to explicitly reference it.