- This ability is natively provided by JVM in debug mode. Feature available since JDK 1.4.2 (Alex's favourite Java release :)) provided via the Java Debug Interface (http://java.sun.com/j2se/1.4.2/docs/guide/jpda/jdi/com/sun/jdi/VirtualMachine.html)
- Redefine (also known as "HotSwap") was added in 1.4.2: http://java.sun.com/j2se/1.4.2/docs/guide/jpda/enhancements.html
This new feature encapsulates the ability to substitute modified code in a running application through the debugger APIs. For example, one can recompile a single class and replace the old instance with the new instance.
This change was made to address these issues:
* Tool (IDE) vendors want 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.
HotSwap adds functionality to the JavaTM Platform Debugger Architecture (JPDA) to allow a class to be updated while under the control of a debugger. The two central components of this functionality are RedefineClasses which replaces the class definitions and PopFrame which pops frames off the stack allowing a method which has been redefined to be re-executed.
In the reference implementation, this functionality is implemented at the Java Virtual Machine Debug Interface (JVMDI) layer and made available through the higher layers of JPDA - the Java Debug Wire Protocol (JDWP) and the Java Debug Interface (JDI).
Redefinition Functionality offered:
JDI VirtualMachine.redefineClasses(Map classToBytes)
JDWP RedefineClasses (Cmd 18) in VirtualMachine (CmdSet 1)
JVMDI RedefineClasses(jint classCount, JVMDI_class_definition *classDefs)
According to the above, HotSwap (on-the-fly class redefinition) can happen only in debug mode. I guess it can't be natively run in normal deployed mode, because I assume that Sun thinks that if the application is already running and deployed, them this hotswap support is not needed. Deployed version is a deployed one, no need to change it, unless you're currently developing it :).
So, the rule should be, if you're developing, always run your applications in debug mode to rip the benefits of JVMs hotswap (on-the-fly class redefinition).
Also, this hotswap can have a dark side, that is, can take up resources incrementaly while in this debugging session, that is, the old (already redefined classes) can be left there and take memory resources, so memory exceptions can take place, but from my experience, this does not occur very often (i have used WTP in this mode for 1 day, without having a single memory exception; assumed that the memory settings of the JVM are properly set). However, having a practice of ocasional restart in debug mode, is always a good idea :)
For the WTP context, to put it in a 'productive development mode', you'll need to make two changes:
- set reloadable="false" on your eclipse configured server, for your application context
- always use debug mode during development
* Interesting development* : HotSwapping with ANT (using Ant task):
- Defines a hotswap target for Ant that allows your build file to replace class definitions on a running JVM. (https://hotswap.dev.java.net/ - java.net incubator project)
Hope this helps,
Posted by ipenov @ 11:22 AM GMT [ Comments  ]