The Craft of Metaprogramming on JVM
summary
Shows how to find classes annotated with @Command, scan packages, and then alter bytecode to inject behavior: adding constructors, inserting entry/exit calls, and even swapping in a generated superclass so existing instances adopt new behavior — demo compiles, scans, and loads those modified classes successfully. Uses ASM/Javassist/CGLIB for bytecode changes and Java agent (load-time instrumentation) or build-time weaving as the three deployment options; warns agents need JVM flags and that interfaces/signatures can’t be freely changed at runtime.
AI-written summary · about
chapters (13)
- 0:00Introduction to metaprogramming
- 3:33Instrumentation code basics
- 8:02Java constraints for metaprogramming
- 13:25Key challenges in JVM metaprogramming
- 17:12When metaprogramming is justified
- 21:09Tools for JVM metaprogramming
- 26:04Java agents and class loading
- 30:18Live demo setup
- 35:17Finding annotated classes
- 39:50Injecting behavior dynamically
- 42:25Changing class inheritance
- 46:20Demo results and implications
- 49:00Q&A and closing remarks
related talks
45mMaking Java more dynamic
55mLiving in the Matrix with Bytecode Manipulation
55mMaking Java more dynamic
55mMaking Java More Dynamic
52mGroovy MOPping
48mPatching Third-Party Library Bytecode at Runtime
53mWell there's your problem! Your engine's missing! A look under Java's hood
14mHow does code hot swapping work, and what are its pitfalls?
