Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

You can hot swap Java code while a JVM is running, but standard debugger HotSwap is mainly for changing method bodies. It does not normally let you add fields or methods, change a class’s inheritance, or alter method signatures. A method already in progress can finish using its old bytecode; later calls can use the replacement. For changes to a class’s structure, you need a different reload technology—or a restart.

What hot swapping changes

Java hot swapping means redefining a class that has already been loaded into the JVM. In the standard tooling model, a debugger or other JVM tool supplies a replacement class definition through JVMTI’s RedefineClasses operation. The JVM installs new versions of eligible methods without replacing the class’s identity.

The JVM Tool Interface specification describes the key behavior: new method versions are used for new invocations, while active stack frames continue executing the original bytecode. This makes standard HotSwap useful for testing a logic change during a debugging session, but it is not equivalent to rebuilding or replacing the application.

What standard HotSwap can and cannot change

Usually supported: method implementation changes

Standard redefinition is shape-preserving. It can replace method bodies and make certain changes to constant-pool data and permitted class-file attributes, provided the class’s structure remains compatible. This is why changing a calculation or conditional inside an existing method may take effect without restarting the JVM.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Not supported: class-shape changes

Standard HotSwap does not allow structural edits such as adding, removing, or renaming fields or methods; changing a method signature or modifier; or changing a class’s inheritance. Adding a constructor or a superclass therefore commonly requires a restart or a reload technology with broader support. JRebel’s guide characterizes ordinary HotSwap in practical terms as method-body-only redefinition.

The boundary is about the loaded class definition, not whether an edit looks small in the source file. A one-line change that adds a field is structural; a larger change contained within an existing method can remain eligible.

What happens to running code and existing objects

  • Calls already in progress: an active method frame can finish with the bytecode it started with. Invocations that begin after redefinition can use the new method version.
  • Existing instances: they are not rebuilt. Their existing field storage remains, which is one reason standard redefinition cannot add a field to the loaded class.
  • Static state: existing static values are preserved. Class initialization does not run again, so changing a static initialization expression does not recalculate a value that was already initialized.
  • Threads and breakpoints: JVMTI redefinition does not require threads to be suspended, but breakpoints in the redefined class are cleared.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Which Java reload option fits the change?

Option Class changes Runtime behavior and constraints
JVMTI or debugger HotSwap Best suited to method-body edits; standard class-shape restrictions apply. New calls can use new method versions while active frames continue with old bytecode. Built into the JVM tooling model; suited to debugging.
JRebel Vendor documentation describes class-loader-level integration intended to go beyond the narrow standard HotSwap model. Check current licensing, supported JDKs, framework support, and deployment fit for the target application.
DCEVM with HotswapAgent Enhanced VM and plugin approach for changes beyond standard redefinition limits. DCEVM documents deoptimization after redefinition and a HotswapDeoptClassPath option to limit affected packages. It introduces VM or distribution constraints, and deoptimization can affect performance.
WebLogic FastSwap Oracle documents support for classes with new shapes beyond the ordinary HotSwap model. Behavior depends on the WebLogic release and deployment configuration.

These options are not interchangeable guarantees. The cited documentation describes mechanisms and constraints, not a universal compatibility matrix across JDKs, IDEs, frameworks, application servers, or deployments.

How to choose and use hot swapping safely

  1. Identify the edit. If it changes only the body of an existing method, try the debugger’s standard HotSwap. If it changes fields, methods, signatures, modifiers, or inheritance, plan to restart or evaluate a broader reload option.
  2. Check runtime effects. Do not expect active calls to switch bytecode mid-execution, existing objects to acquire new fields, or static initializers to run again.
  3. Match the tool to the environment. For JRebel, DCEVM with HotswapAgent, or WebLogic FastSwap, verify the exact JDK, framework, server release, deployment settings, licensing where relevant, and rollback procedure before relying on redefinition.
  4. Validate after each change. Confirm that the class was redefined, revisit breakpoints cleared by standard JVMTI redefinition, and exercise both new method calls and any state that existed before the change. If the edit exceeds the tool’s supported class shape, restart rather than assuming the JVM applied it.

Why a change may not appear immediately

  • The edit altered class structure: standard HotSwap cannot add a field or method or change inheritance. Use a supported enhanced reload option or restart.
  • The old behavior is in a call already running: that stack frame may complete on the original bytecode; check a later invocation.
  • The changed value was initialized earlier: redefinition does not rerun class initialization, so an existing static value remains as it was.
  • A breakpoint stopped binding as expected: JVMTI redefinition clears breakpoints in the class, so set them again.
  • The enhanced tool does not match the deployment: support depends on JDK, framework, plugin or server version, and configuration. Verify those specifics rather than assuming compatibility.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.