Scrivio Interview library
ConceptIntermediate7 min read · updated 12 November 2026

Compare standard JVM HotSwap through a debugger, Spring Boot DevTools restart, enhanced class redefinition (DCEVM-style, as in JetBrains Runtime), and commercial agents such as JRebel. What changes can each handle?

Standard HotSwap through a debugger uses JVMTI class redefinition and can change only method bodies; adding or removing fields or methods is rejected. A DevTools restart reloads all project classes in a fresh class loader and restarts the context, so any change works but in-memory state is lost. Enhanced redefinition, DCEVM-style as in JetBrains Runtime, also accepts structural changes such as new fields and methods without a restart, and JRebel-style agents rewrite classes and integrate with frameworks to refresh beans and mappings. All four are developer tools, not production deployment mechanisms.

Why this question is asked

Every Java team eventually asks why some code changes apply instantly in the debugger and others force a restart, and whether a better tool would remove the restarts entirely. The answer comes down to what the JVM is willing to change in a class that is already loaded and has live objects. Interviewers ask this to see whether we understand that limit and the trade-offs of the tools built around it. In this answer, we will recap class redefinition, go through each of the four approaches and what it can handle, compare them side by side, and finish with the risks that apply to all of them.

1A Quick Recap of Class Redefinition

Once a class is loaded, the JVM has laid out its objects in memory according to its fields, built method tables, and possibly compiled its methods to machine code and inlined them into callers. Changing a method body is comparatively easy: the JVM installs the new bytecode, discards compiled code that depended on the old version, and new calls use the new body. Changing the shape of a class, adding a field or a method, changing a superclass or an interface, is much harder, because every existing object of that class has the old layout and other code has been linked against the old method table.

The JVM exposes redefinition through JVMTI, the native tool interface used by debuggers and agents, as the RedefineClasses function, and through java.lang.instrument for Java agents. Debuggers use it when we edit code during a debug session.

2Standard HotSwap Through a Debugger

When we change a method body in the IDE during a debug session and recompile, the IDE sends the new bytes to the JVM over the debug protocol, and the JVM redefines the class. Running methods keep executing the old version until they return, and the IDE may drop the current frame so we can re-enter the method with the new code.

Java
// Before (loaded and running) // After edit: accepted by HotSwap
int price(int qty) { return qty * 10; } int price(int qty) { return qty * 12; }
// After edit: rejected by standard HotSwap
private int discount; // new field
int price(int qty, int pct) { ... } // new method
// java.lang.UnsupportedOperationException: class redefinition failed:
// attempted to add a method (the IDE shows "Hot swap failed: schema change not implemented")

The rule in a standard JVM is strict: method bodies may change, but fields, methods, the superclass and the implemented interfaces must stay the same. The reason is the layout problem above. HotSwap keeps all state, objects, caches and open connections, which is its great advantage, but it is limited to the most common edit, changing logic inside a method.

3DevTools Restart: Reload Everything, Lose State

Spring Boot DevTools takes the opposite approach. Instead of changing loaded classes, it loads all of the project's classes again in a fresh restart class loader and restarts the Spring application context, while library classes stay loaded in a base loader. Since every class is brand new, there are no restrictions at all: new fields, new classes, new beans, changed annotations and configuration all work.

The cost is state. Every bean is recreated, caches start empty, sessions held in memory are gone, and the start-up work of the context runs again, typically one or two seconds in a small application but much more in a large one. Static state in library classes, which are not reloaded, also survives, which can produce stale references to old objects.

4Enhanced Redefinition: Structural Changes in Place

DCEVM, the Dynamic Code Evolution VM, modified HotSpot so that RedefineClasses accepts structural changes: adding and removing fields and methods, and in many cases changing the class hierarchy. Existing objects are migrated to the new layout, with new fields set to their default values. JetBrains Runtime, the JDK the IntelliJ family ships, includes this as an option enabled with -XX:+AllowEnhancedClassRedefinition (check your version), and HotswapAgent is an open-source agent often used with it to refresh framework state such as Spring beans after a change.

This removes most restarts during development while keeping state. The catch is that new fields in existing objects hold defaults rather than what a constructor would have set, and static initialisers are not re-run, so code must cope with partially initialised state after a change.

5JRebel-Style Agents: Framework-Aware Reloading

Commercial agents such as JRebel work on standard JVMs. As a Java agent, JRebel rewrites classes as they are loaded so that method calls and field access go through its own indirection, which lets it add methods and fields to live classes without needing JVM support for structural redefinition. Its real value is the integrations: it knows how Spring, Hibernate, JAX-RS and many other frameworks cache information, and after a change it refreshes the relevant parts, for example re-wiring a Spring bean whose dependencies changed or re-reading a JPA mapping. The cost is a licence, an agent in every developer JVM, and some overhead and occasional mismatches with framework versions.

What each approach can handle
ChangeHotSwapDevToolsEnhanced redef.JRebel-style
Edit a method bodyyesyes, restartyesyes
Add or remove a methodnoyes, restartyesyes
Add or remove a fieldnoyes, restartyes, default valueyes
New Spring bean or mappingnoyes, restartwith HotswapAgentyes, refreshed
Keeps in-memory stateyesnoyesyes
Needsa debuggera dependencya patched JDKan agent and licence

6Why None of Them Belongs in Production

All four tools change running code in ways that leave the process different from any built artifact, and they are designed for one developer's JVM, not a fleet. HotSwap needs a debug port open, which is itself a security hole. Enhanced redefinition needs a non-standard JDK. Restarts lose state. Agents add overhead and their own failure modes. A production change should be a new, tested artifact deployed through the normal pipeline, so that what runs is what was reviewed and can be rolled back.

7Follow-up questions

What can go wrong when static state survives a hot swap?

Static initialisers are not re-run when a class is redefined, so any static value computed by the old code stays as it was. If we change how a static cache is built, the cache still holds entries built the old way. If we add a static field with an initialiser through enhanced redefinition, it may hold its default value, such as null, rather than the initialised value. Objects created before the swap keep their old field values, so an invariant the new code expects, such as a field always being non-null, may not hold for them. The program then behaves in a way that neither the old nor the new version would, which is why a full restart is the reliable test before committing.

Why does HotSwap sometimes seem to do nothing?

Because a method that is currently running keeps executing its old version until it returns, and code that was inlined into a caller is only replaced once that compiled code is discarded. A long-running loop inside the edited method never picks up the change; dropping the frame in the debugger, or calling the method again, does.

8Conclusion

In this answer, we compared four ways of changing code while developing. Standard HotSwap redefines classes through JVMTI and accepts only method body changes while keeping all state. A DevTools restart reloads every project class in a new loader and restarts the context, so it accepts any change but loses state. Enhanced redefinition in DCEVM-style JVMs such as JetBrains Runtime adds structural changes in place, and JRebel-style agents rewrite classes and refresh framework state. All of them are developer tools, and production changes should always be new, deployed artifacts.

What to say in the interviewAbout 90 seconds aloud

Open with

The difference comes down to what the JVM will change in a class that is already loaded. Standard HotSwap through a debugger uses JVMTI RedefineClasses, and in a normal JVM that accepts only method body changes.

Then, if they want more

If I add or remove a field or a method, or change the hierarchy, redefinition is rejected, because existing objects and linked code depend on the old layout. Its advantage is that all state survives.

Spring Boot DevTools takes the opposite approach: it does not redefine anything, it throws away the restart class loader with all my project classes, loads them fresh and restarts the application context, while library classes stay loaded. So any change works, new classes, fields, beans, but in-memory state is lost and the context start-up runs again.

Enhanced class redefinition, DCEVM-style as in JetBrains Runtime with the enhanced redefinition flag, extends RedefineClasses to structural changes like adding fields and methods without a restart, migrating existing objects with default values for new fields, and is often combined with HotswapAgent to refresh Spring.

Commercial agents like JRebel rewrite classes at load time so they can add members on a standard JVM, and their main value is framework integration, refreshing Spring beans, Hibernate mappings and so on after a change. None of these is a safe way to change production.

They leave running code different from the deployed artifact, so production changes should go through a normal deployment.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Compare standard JVM HotSwap through a debugger, Spring Boot DevTools restart, enhanced...": https://scrivio-interview-library.netlify.app/java/class-loading/f64000e0ae/