Extended Java HotSwap capabilities

Balazs Toth
3 min readApr 11, 2021

--

Would you like to try it now? https://github.com/zsalab/dcevm-spring-boot

Working with script languages comes with an advantage to code on the fly. Unfortunately that is not that simple with Java, least is not that simple without DCEVM and HotswapAgent. It is really comfortable to run the application, write code and try it in an instance. Of course you have unit tests those run really fast to check your code, but some times you may have to check multiple services and/or UI interactions when you debug and fix something. Sometimes it just come handy to change something in the code, just to try the solution out and see the result in an instance. Standard JVM helps you with hot code replacement capability, unfortunately that is really limited. You can change and check code if your change restricted to method bodies. I guess everybody, who work with Java knows the “hot code replace failed” or “hot swap failed” errors.

If you wish to see your change than time to restart. It is not your IDE, this limitation is come from the JVM.

Spring Loaded

You can find solutions like Spring Loaded that never work properly and the project is completely dead for years, furthermore it was Spring specific.

JRebel

Other option to use JRebel, that comes with some problems:
1., It is expensive. Developers are expensive, every second cost money that spent on waiting for the application to start after a change. The price reflects the accumulated time of a developer can save with using JRebel.
2., The configuration is not always simple and even with the IDE plugins can be tricky. Yes, you most likely will need to use JRebel plugin for your IDE.
3., The JRebel agent is hacking your classes on load to be able to provide extended hot swap capabilities. I would prefer to run the same code as will be executed in production.

DCEVM and HotSwap Agent

The solution I would like to introduce to you is a combination of a special VM and a collection of plugins to handle internal status of frameworks. DCEVM is an extended OpenJDK, it works pretty much as OpenJDK with the capability to handle changes like class field, method addition and removal plus some capabilities not supported by the standard JVM.

“The only unsupported operation is hierarchy change (change the superclass or remove an interface).”

The other part of the solution is the HotSwap Agent, it comes with plugins for many “frameworks” like Spring, Hibernate, Tomcat, Jetty, Weld, Jersey, … and of course you can extend it with your own plugin.

Any IDE supported regards no plugin or additional configuration needed, you just have to use the DCEVM and start your application with the selected Hotswap Agent plugin collection. The only parameter you have to pass to your VM on application startup is ‘-XX:HotswapAgent=[core|fatjar|external]’

Would like to try? Just couple of minutes and you can try in your IDE with a simple step by step guide.
Theia / Visual Studio Code | Eclipse / Spring Tool Suite | IntelliJ Idea

Would you like to learn more?
http://hotswapagent.org/index.html

--

--