Instrument to Remove: Using Java agents for fun and profit
summary
A small Java agent prototype instruments classes by inserting a static initializer via javassist bytecode insertion to record class usage, then appends a runtime jar into the bootstrap loader with appendToBootstrap runtime jar so instrumented code can call back into the agent. Running on Spring PetClinic (56 MB jar, ~30,000 classes) it observes ~12,000 loaded and ~9,000 actually initialized (PetClinic: 56MB → 9,000 used classes), writes usage lists for manual removal or pre-instrumented jar rewriting, and exposes an agent control port for inspection.
AI-written summary · about
chapters (14)
- 0:00Java agents and de-bloating
- 4:16Limitations of existing tools
- 8:11Nerd sniping and new tool
- 10:15Unused classes for de-bloating
- 16:17Java agent basics
- 20:38Java agent implementation
- 24:49Class loader challenges
- 26:57Agent startup timing
- 28:20Bytecode libraries and techniques
- 30:05Demo and results
- 32:10Debugging Mockito
- 33:54Agent design patterns
- 36:21Summary and resources
- 37:26Q&A on agents
related talks
30mWriting Java agents for fun and not so much profit
01h 01mThe definite guide to Java agents
39mThe Java Agent: Modifying Bytecode at Runtime to Protect Against Log4J
45mMaking Java more dynamic
50mCode Coverage Instrumentation
30mInstrument Your Java Applications with OpenTelemetry!
39mEverything You Never Wanted to Know about Java Class Initialization
48mSetting up monitoring for Java apps
