Hot Swap
Hot Swap (class redefinition while the target JVM is executing) is a new JPDA
(Java Platform Debugger Architecture) feature implemented in JDK 1.4.
For example, one can recompile a single class and replace the old instance with the new instance.
Example uses of Hot Swap are:
- The ability to do fix-and-continue debugging. That is, while debugging, identify a problem, fix it,
and continue debugging with fixed code.
- Organizations deploying long running servers wish to be able to fix bugs without taking down the server.
Hot Swap is performed in the GUI by selecting a class in the Loaded Classes Panel
and selecting the Hot Swap... menu item from
the right click popup context menu. Or Hot Swap is performed in the GUI by selecting the
Hot Swap... menu item from the right click popup context menu
in the source file currently displayed in the Source Panel,
for the corresponding class containing the blinking cursor.
If there are currently multiple classes by the same name loaded into the target JVM (by multiple ClassLoaders),
you will be prompted to confirm that you really want to try and Hot Swap them all.
If so, then the number of classes successfully Hot Swapped will be reported.
If any redefined methods have active stack frames, those active frames continue to run the bytecodes of the
previous method. The redefined methods will be used on new invocations.
If you are suspended in the method that is going to be Hot Swapped, and you want to re-execute the
method with the new code, you can first Pop
a frame(s) off the stack. Then Hot Swap the corresponding class and then you can step into the (popped off)
method(s) again and execute the new code.
After a class has been Hot Swapped, breakpoints that are currently set in
that class, will be re-resolved.
Check the Target Info Dialog to see the Hot Swap
capabilities of the target JVM:
- Can redefine classes - if true, then Hot Swap is supported by the target JVM.
- Can add methods - if true, then the target JVM can Hot Swap a class that implements
new methods.
- Can Unrestrictedly Redefine Classes - if false, attempting any of the following is
not permitted:
- changing the schema (the fields)
- changing the hierarchy (subclasses, interfaces)
- deleting a method
- changing class modifiers
- changing method modifiers
A Hot Swap operation can return the following errors:
- The class bytes do not correspond to the given class.
- The class bytes do not verify or there is a security problem.
- The class bytes do not represent a valid class.
- A circularity has been detected while initializing the class.
- The major and minor version numbers in the class bytes are not supported by the target VM.
For more details on Hot Swap, see the JPDA documentation.
©2001-2010. debugtools.com LLC. All rights reserved.