Hot Code Replacement Using Incremental Bytecode Patching

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Existing debugging methods for large-scale software applications are inefficient due to the need for repeated stopping and restarting, which is time-consuming and affects debugging efficiency, especially when modifications beyond method bodies are required.

Innovation Solution

A hot code replace method that involves obtaining and transferring first and second bytecodes, patching instructions to invoke corresponding content in a third bytecode, and loading target bytecodes to support modifications beyond method bodies without full application restarts, using incremental compilation and dynamic generation of bytecodes.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Reliability

If repeated stopping and restarting is performed to modify code and verify running results, then code debugging can be completed, but debugging time increases significantly

Engineering Contradiction:
Improvecode verification accuracyVSAvoiddebugging time
Core Design Contradiction:
ReliabilityVSLoss of time

Solution Approach 1:

The patent applies preliminary action by pre-compiling modified code into new bytecode before actually needing to verify it. The bytecode replacement mechanism is prepared in advance, allowing immediate switching between old and new code versions without restarting the application, thus reducing debugging time while maintaining verification accuracy

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

The patent creates a copy of the original bytecode and modifies it to generate new bytecode. This copying approach allows the modified code to be tested independently by replacing the original bytecode in memory, enabling rapid verification without affecting the running application or requiring restarts

Inventive Principle:
Principle #26Copying

2Reliability

If full compilation is performed after code modification, then code changes are processed, but compilation time increases debugging costs

Engineering Contradiction:
Improvecode modification completenessVSAvoidcompilation time
Core Design Contradiction:
ReliabilityVSLoss of time

Solution Approach 1:

The patent applies partial action by performing only the necessary compilation steps for modified code portions rather than full compilation. The incremental compilation approach compiles only the changed classes and generates only the necessary bytecode segments, which are then selectively replaced in memory, significantly reducing compilation time while ensuring complete processing of code modifications

Inventive Principle:
Principle #16Partial or excessive action

3Loss of time

If existing hot code replace solution is used for method body modification, then debugging time is reduced, but it cannot support modifications beyond method bodies

Engineering Contradiction:
Improvedebugging timeVSAvoidmodification type support
Core Design Contradiction:
Loss of timeVSAdaptability or versatility

Solution Approach 1:

The patent achieves universality by creating a bytecode replacement mechanism that handles multiple types of code modifications beyond just method bodies. It supports class-level modifications, field changes, method signature changes, and structural modifications by generating and replacing entire bytecode segments or classes, making the debugging tool versatile for various modification scenarios while maintaining rapid replacement capability

Inventive Principle:
Principle #6Universality (Multi-functionality)

Data Source

PatentEP4715579A1Code hot replacement method and apparatus
Publication Date: 2026.03.25 HUAWEI CLOUD COMPUTING TECHNOLOGIES CO LTD
  • EP4715579A1 patent drawingFigure 1~2
  • EP4715579A1 patent drawingFigure 3~4
  • EP4715579A1 patent drawingFigure 5~6

AI summary

This application provides a hot code replace method and apparatus. The method includes: obtaining a first bytecode obtained by compiling source code and a second bytecode obtained by performing incremental compilation on the source code after modification; transferring, to a third bytecode, a declaration of first-type modification content in modification content in the second bytecode relative to the first bytecode, where the first-type modification content includes a modification other than a modification of a method body; patching at least one instruction in the second bytecode after transfer or the third bytecode, where the at least one instruction is used to invoke at least one piece of content in the second bytecode, and the at least one patched instruction is used to invoke content that is in the third bytecode and that corresponds to the at least one piece of content; and loading a target second bytecode and a target third bytecode. Solutions in embodiments of this application help improve debugging efficiency.