How does code hot swapping work, and what are its pitfalls?
summary
Demo shows a tiny running program with an embedded webserver, decompiler and an Update button that compiles code and pushes classes into the JVM. Hot swap uses JVMTI-like hooks or the java.lang.instrumentation agent calling redefineClasses or retransform to replace bytecode; common generators are javac/compiler API, ASM or ByteBuddy. Works for turning tracing on or capturing locals but cannot add or remove fields or methods or change signatures or inheritance, and repeated swaps cause deoptimization, safepoint pauses and metaspace growth after hundreds or thousands.
AI-written summary · about
chapters (7)
- 0:00Code hot swapping intro
- 2:31Hot swapping in Java
- 5:43JVM TI and Java agents
- 9:35Generating bytecode
- 10:39Hot swap use cases
- 11:42Hot swap pitfalls
- 13:11Q&A
related talks
46mThe Hitchhiker’s guide to Java class reloading
55mMaking Java more dynamic
49mAn Introduction to JVM Performance
59mAn Introduction to JVM Performance
01h 09mFrom Bytecode to Native Code in HotSpot JVM
41mAn Introduction to JVM Performance
01h 01mAn Introduction to JVM Performance
45mMaking Java more dynamic
