A method and apparatus for code debugging

By using the virtual machine's dynamic class loading mechanism to dynamically load the bytecode to be replaced, the problem of long debugging time in network application development is solved, achieving efficient code debugging and fast rollback, avoiding Java probe permission issues, and improving debugging efficiency.

CN119862108BActive Publication Date: 2026-03-17BEIJING WODONG TIANJUN INFORMATION TECH CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-10-17
Publication Date
2026-03-17

AI Technical Summary

Technical Problem

In existing technologies, code debugging is time-consuming during the development and debugging of network applications, especially in test and online environments. Due to the large number of application system modules and lines of code, the time required for recompiling, rebuilding, and deploying after code adjustments is long and inefficient.

Method used

By leveraging the virtual machine's dynamic class loading mechanism, bytecode to be replaced is dynamically loaded, enabling class reloading without the need for compilation, building, or deployment. A custom class loader is used to replace the current bytecode, and combined with a monitoring center recording code change data, it supports rapid rollback.

Benefits of technology

It reduces code debugging time, improves debugging efficiency, avoids Java probe connection JVM permission issues and dependencies on third-party programs, and enables fast rollback functionality.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119862108B_ABST
    Figure CN119862108B_ABST
Patent Text Reader

Abstract

This invention discloses a method and apparatus for code debugging, relating to the field of computer technology. One specific embodiment of the method includes: responding to a code debugging command, acquiring code modification configuration information, which includes the class name to be replaced and the bytecode to be replaced; based on the class name, searching for the current bytecode corresponding to the class name in the current code, and replacing the current bytecode with the bytecode to be replaced; and reloading the class corresponding to the class name by loading the bytecode to be replaced, based on the virtual machine's dynamic class loading mechanism, for code debugging. This embodiment, based on the virtual machine's dynamic class loading mechanism, dynamically reloads classes, eliminating the need for code compilation, construction, and deployment, thereby saving debugging time and improving debugging efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, and in particular to a method and apparatus for code debugging. Background Technology

[0002] In the current development, testing, and deployment of web applications, code debugging is essential. Currently, during code testing, if a problem is encountered during debugging, the first step is to check the logs and then locate the issue within the code based on the logs. If the problem is located, the relevant code snippet is modified, and the code is recompiled, rebuilt, and deployed. If the problem cannot be located, logs are added around the problematic area to aid in its location. After the code is deployed, if an online issue is encountered during debugging, the first step is to locate the problem within the code based on the logs, modify the relevant code snippet accordingly, and then use a Java probe to replace the problematic code before recompiling, rebuilding, and deploying. If the problem cannot be located, a rapid rollback to the online version is necessary, and the previous stable version of the code is compiled and deployed.

[0003] In the process of realizing this invention, the inventors discovered at least the following problems in the prior art:

[0004] For the routine code debugging process in both testing and production environments, since application systems typically have multiple modules and a large number of lines of code, the time required for code adjustments, recompiling, rebuilding, and deployment is relatively long, resulting in lengthy code debugging time and low efficiency. Summary of the Invention

[0005] In view of this, embodiments of the present invention provide a method and apparatus for code debugging, which can dynamically reload classes based on the dynamic class loading mechanism of the virtual machine, eliminating the need for code compilation, construction and deployment, thereby saving code debugging time and improving code debugging efficiency.

[0006] To achieve the above objectives, according to one aspect of the present invention, a method for code debugging is provided, comprising: responding to a code debugging instruction, obtaining code modification configuration information, the code modification configuration information including a class name to be replaced and bytecode to be replaced; based on the class name, searching for the current bytecode corresponding to the class name in the current code, and replacing the current bytecode with the bytecode to be replaced; and reloading the class corresponding to the class name by loading the bytecode to be replaced based on the dynamic class loading mechanism of the virtual machine, so as to perform code debugging.

[0007] Optionally, replacing the current bytecode with the bytecode to be replaced includes: modifying the current bytecode to the bytecode to be replaced using a hook method, so as to replace the current bytecode with the bytecode to be replaced.

[0008] Optionally, the method further includes: if the class corresponding to the class name is implemented as a container component, obtaining the context of the container and re-registering the component.

[0009] Optionally, after reloading the class corresponding to the class name by loading the bytecode to be replaced, the method further includes: notifying the monitoring center to record code change data, wherein the code change data includes the class name and the current bytecode, and the current bytecode is saved to the historical modification record stack corresponding to the class name.

[0010] Optionally, when the code debugging instruction is a code rollback instruction, the code modification configuration information is generated in the following way: the bytecode to be rolled back is retrieved from the top of the historical modification record stack corresponding to the class name, and the bytecode to be rolled back is used as the bytecode to be replaced; the code modification configuration information is generated based on the bytecode to be replaced.

[0011] Optionally, if the code debugging instruction is a code rollback instruction, before generating the code modification configuration information, the method further includes: determining that there is bytecode in the historical modification record stack corresponding to the class name; and, if there is no bytecode in the historical modification record stack corresponding to the class name, issuing an alarm reminder.

[0012] Optionally, the code debugging instruction is generated under the following circumstances: a problem is detected in the current code, and the code is modified according to the problem; a problem is detected in the current code, and it is determined that code rollback is required according to the problem; or the code is modified according to business requirements during code execution.

[0013] According to another aspect of the present invention, a code debugging apparatus is provided, comprising: a configuration information acquisition module, configured to acquire code modification configuration information in response to a code debugging instruction, the code modification configuration information including a class name to be replaced and bytecode to be replaced; a bytecode replacement module, configured to find the current bytecode corresponding to the class name in the current code according to the class name, and replace the current bytecode with the bytecode to be replaced; and a class dynamic loading module, configured to reload the class corresponding to the class name by loading the bytecode to be replaced based on the dynamic class loading mechanism of the virtual machine, so as to perform code debugging.

[0014] According to another aspect of the present invention, an electronic device is provided, comprising: one or more processors; and a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the code debugging method provided in the embodiments of the present invention.

[0015] According to another aspect of the present invention, a computer-readable medium is provided having a computer program stored thereon, which, when executed by a processor, implements the code debugging method provided in the embodiments of the present invention.

[0016] One embodiment of the above invention has the following advantages or beneficial effects: By responding to code debugging instructions, code modification configuration information is obtained, including the class name to be replaced and the bytecode to be replaced; based on the class name, the current bytecode corresponding to the class name is found in the current code, and the current bytecode is replaced with the bytecode to be replaced; this technical solution, based on the virtual machine's dynamic class loading mechanism, reloads the class corresponding to the class name by loading the bytecode to be replaced, thus enabling code debugging. By implementing a custom class loader to load the bytecode to be replaced, class reloading can be performed dynamically, eliminating the need for code compilation, construction, and deployment, thereby saving debugging time and improving debugging efficiency. Furthermore, the technical solution of this invention does not rely on Java probes for code replacement, thus avoiding the permission issues associated with connecting to the JVM and the dependency issues on third-party programs. In addition, this invention can monitor and record each code debugging operation, enabling rapid rollback of code replacement operations when necessary.

[0017] The further effects of the aforementioned unconventional alternative methods will be explained below in conjunction with specific implementation methods. Attached Figure Description

[0018] The accompanying drawings are provided to better understand the invention and are not intended to unduly limit the scope of the invention. Wherein:

[0019] Figure 1 This is a schematic diagram illustrating the main steps of a code debugging method according to an embodiment of the present invention;

[0020] Figure 2 This is a schematic diagram of the dynamic class loading process during code debugging according to an embodiment of the present invention;

[0021] Figure 3 This is a schematic diagram of the code change data recording process according to an embodiment of the present invention;

[0022] Figure 4This is a schematic diagram of the code modification configuration information generation process according to an embodiment of the present invention;

[0023] Figure 5 This is a schematic diagram of the module interaction principle of one embodiment of the present invention;

[0024] Figure 6 This is a schematic diagram of the main modules of a code debugging apparatus according to an embodiment of the present invention;

[0025] Figure 7 This is an exemplary system architecture diagram in which embodiments of the present invention can be applied;

[0026] Figure 8 This is a schematic diagram of the structure of a computer system suitable for implementing terminal devices or servers of the present invention. Detailed Implementation

[0027] The following description, in conjunction with the accompanying drawings, illustrates exemplary embodiments of the present invention, including various details to aid understanding. These details should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the invention. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.

[0028] It should be noted that the technical solutions disclosed in this invention, regarding the collection, updating, analysis, processing, use, transmission, and storage of user personal information, all comply with relevant laws and regulations, are used for legitimate purposes, and do not violate public order and good morals. Necessary measures are taken to prevent unauthorized access to user personal information data and to safeguard user personal information security, network security, and national security.

[0029] In the current development, testing, and deployment of web applications, code debugging is essential. Currently, when debugging code during testing, if a problem is encountered, the first step is to check the logs and then locate the issue in the code based on the logs. If the problem is located, the relevant code snippet is modified, and the code is recompiled, rebuilt, and deployed. If the problem cannot be located, logs are added around the problematic area to aid in its identification.

[0030] When debugging code after deployment, if online issues are encountered, first locate the problem in the code based on the logs, modify the relevant code snippets accordingly, then use a Java probe to replace the code, recompile, build, and deploy. If the problem cannot be located, a quick rollback to the online version is required, followed by compiling and deploying the previous stable version. When using a Java probe for code replacement, another program needs to connect to the JVM (Java Virtual Machine) of the program whose code needs to be replaced, and then load the specified compressed package to perform runtime code replacement and modification.

[0031] For standard code debugging processes in both testing and production environments, application systems typically have multiple modules and a large number of lines of code. Therefore, recompiling, rebuilding, and deploying code after adjustments takes a considerable amount of time, resulting in lengthy and inefficient debugging. Furthermore, using Java probes for runtime code replacement requires a third-party program to connect to the target application's virtual machine. The first challenge is JVM permission issues; to ensure JVM security, virtual machine connection permissions are generally not granted. Secondly, each replacement requires modifying the third-party application's startup parameters or code and restarting it. Finally, runtime code replacement carries inherent security risks, making recovery difficult once problems occur.

[0032] This invention primarily addresses the following technical problems encountered by current web application developers when debugging and troubleshooting online issues:

[0033] 1. Reduce the time required for redeployment when code modifications are needed;

[0034] 2. Avoid permission issues when using Java probes to connect to the JVM and avoid dependencies on third-party programs;

[0035] 3. It can monitor and record each operation, and can quickly roll back the operation when needed.

[0036] Figure 1 This is a schematic diagram illustrating the main steps of a code debugging method according to an embodiment of the present invention. Figure 1 As shown, the code debugging method of this embodiment mainly includes the following steps S101 to S103.

[0037] Step S101: In response to a code debugging instruction, obtain code modification configuration information, which includes the class name to be replaced and the bytecode to be replaced. In embodiments of the present invention, the code debugging instruction may be generated under the following circumstances: a problem is detected in the current code, and code modifications are made based on the problem; a problem is detected in the current code, and a code rollback is determined based on the problem; or code modifications are made during code execution according to business requirements. That is, in a test environment or online environment, a code debugging instruction can be triggered when a code problem is detected and minor code modifications are made, or when a code rollback is determined based on the detected problem, or when the user actively modifies the code according to business requirements.

[0038] The code debugging system of this invention is deployed on the target application. Upon receiving a code debugging command, it retrieves specific code modification configuration information from the configuration center server and parses this information to obtain information such as the class name to be replaced, the bytecode to be replaced, the target application identifier, the operator, and the configuration submission time. The target application identifier is used to locate the application. The class name to be replaced and the bytecode to be replaced are the core content of the code modification configuration information, used to perform the actual code replacement operation. The operator and the configuration submission time are used to record security-related information. Bytecode is a binary file containing an executable program, consisting of a sequence of op code or data pairs; it is a type of intermediate code.

[0039] Step S102: Based on the class name, locate the current bytecode corresponding to the class name in the current code, and replace the current bytecode with the bytecode to be replaced. The code currently being debugged in the target application is the current code. This step requires locating the current bytecode of the corresponding class in the current code based on the class name to be replaced in the code modification configuration information, and then performing the code replacement.

[0040] In one embodiment of the present invention, replacing the current bytecode with the bytecode to be replaced may specifically include: modifying the current bytecode to the bytecode to be replaced using a hook method, so as to replace the current bytecode with the bytecode to be replaced.

[0041] When a Java application starts, the JVM loads classes. During loading, the class structure information is stored in the JVM's method area, while the actual object resides in the heap. Runtime code replacement is essentially a process of reloading classes. This involves modifying the class bytecode using JVM hook methods and then re-initializing the class based on the modified bytecode. In this embodiment, runtime class loading is primarily based on the `ClassLoader` class, an abstract class whose instances are responsible for reading Java bytecode into the JVM. In the JVM's class loading mechanism, each class loader has its own namespace, and for the same class loader, a class with the same name can only be loaded once. Therefore, during dynamic code replacement, a custom class loader needs to be implemented to load the bytecode to be replaced.

[0042] Step S103: Based on the virtual machine's dynamic class loading mechanism, the class corresponding to the class name is reloaded by loading the bytecode to be replaced for code debugging. This dynamic class loading mechanism, by implementing a custom class loader to load the bytecode to be replaced, allows for dynamic class reloading without the need for code compilation, construction, and deployment, thus saving debugging time and improving debugging efficiency. Furthermore, this invention does not rely on Java probes for code replacement, thus avoiding the permission issues associated with connecting to the JVM when using probes for code replacement, as well as the dependency issues related to third-party programs.

[0043] According to one embodiment of the present invention, the code debugging method may further include: if the class corresponding to the class name is implemented as a container component, obtaining the context of the container and re-registering the component. If the class to be replaced belongs to a component bean in the Spring container, the context of the Spring container must also be obtained for re-registration of the bean. The Spring container is the core of the Spring framework, used to manage objects. The container creates objects, connects them, configures them, and manages their entire lifecycle from creation to destruction.

[0044] According to another embodiment of the present invention, after reloading the class corresponding to the class name by loading the bytecode to be replaced, the method further includes: notifying the monitoring center to record code change data, wherein the code change data includes the class name and the current bytecode, and the current bytecode is saved in the historical modification record stack corresponding to the class name. The present invention monitors and records each code debugging operation, enabling rapid rollback of code replacement operations when needed.

[0045] Figure 2This is a schematic diagram of the dynamic class loading process during code debugging according to an embodiment of the present invention. Figure 2 As shown, in an embodiment of the present invention, in response to a code debugging instruction, code modification configuration information is first obtained; then, the code modification configuration information is parsed to obtain the class name and bytecode to be replaced; then, the bytecode to be replaced is used to replace the current bytecode of the class; the bytecode to be replaced is loaded through the class loader to perform dynamic class loading. Next, it is determined whether the class to be replaced is a container component. If so, the container context is obtained and the component is re-registered, and the monitoring center is notified to record the code change data; otherwise, the monitoring center is directly notified to record the code change data. Thus, dynamic class loading during code debugging can be achieved.

[0046] Figure 3 This is a schematic diagram illustrating the code change data recording process according to an embodiment of the present invention. Figure 3 As shown, in an embodiment of the present invention, the monitoring center maintains a historical modification record stack for each class to store the bytecode of historically modified versions. When recording code change data, the monitoring center first parses the notification message to obtain the code change data, which includes information such as the class name of the code replacement, the current bytecode before the replacement, the time of the replacement, and the operator. Then, the code change data is recorded and stored, and the current bytecode before the replacement is saved to the historical modification record stack corresponding to the class name.

[0047] According to another embodiment of the present invention, when the code debugging instruction is a code rollback instruction, the code modification configuration information is generated in the following way: The bytecode to be rolled back is retrieved from the top of the historical modification record stack corresponding to the class name, and the bytecode to be rolled back is used as the bytecode to be replaced; the code modification configuration information is generated based on the bytecode to be replaced. The code modification configuration information is generated by the configuration center server. When the problem detection system detects a problem and determines that code rollback is required, it triggers the configuration center server to generate a code rollback instruction and send it to the code debugging system deployed on the target application, so that the code debugging system can obtain the code modification configuration information from the configuration center server. In this scenario, when the configuration center server generates the code modification configuration information, it can retrieve the code of the previous stable version from the top of the historical modification record stack corresponding to the class that needs code replacement as the bytecode to be rolled back, thereby obtaining the bytecode to be replaced for generating the code modification configuration information. A stack is a linear list with restricted operations, where insertion and deletion operations are limited to the tail of the list, which is called the top of the stack.

[0048] According to another embodiment of the present invention, when the code debugging instruction is a code rollback instruction, before generating the code modification configuration information, the method may further include: determining that there is bytecode in the historical modification record stack corresponding to the class name; and, if there is no bytecode in the historical modification record stack corresponding to the class name, issuing an alarm. If there is no bytecode in the historical modification record stack corresponding to the class that needs code replacement (i.e., the stack is empty), it indicates that the currently running code is the version used when the application was initially started, and therefore code rollback is not possible. In this case, an alarm can be issued.

[0049] Figure 4 This is a schematic diagram illustrating the code modification configuration information generation process according to an embodiment of the present invention. For example... Figure 4 As shown, in an embodiment of the present invention, when the code debugging instruction is a code rollback instruction, the configuration center server will generate code modification configuration information. Specifically, it first determines whether there is bytecode in the historical modification record stack; if so, it retrieves the bytecode to be rolled back from the top of the stack and generates code modification configuration information based on the bytecode to be rolled back; otherwise, it cannot retrieve any bytecode from the stack and directly issues an alarm reminder.

[0050] Figure 5 This is a schematic diagram illustrating the module interaction principle of one embodiment of the present invention. In one embodiment of the present invention, the modules involved in code debugging mainly include: a configuration center server, a configuration center client, a dynamic code replacement module, and a monitoring center. The configuration center server may also deploy a problem detection system to detect whether there are problems in the target application's code and send the detection results to the configuration center server so that the configuration center server generates corresponding code debugging instructions. The configuration center client, dynamic code replacement module, and monitoring center can all be deployed independently in the target application, or they can be integrated and deployed in the target application. Alternatively, only the configuration center client and dynamic code replacement module can be integrated and deployed in the target application, while the monitoring center is deployed independently of the target application in another location. The present invention does not limit this. The configuration center server is a network application independent of the code debugging system, used to decouple the configuration information required by the code debugging system from the code debugging system and to manage the configuration in a unified manner. Currently, commonly used configuration centers in the industry include the open-source distributed configuration centers Apollo and Nacos, and the intelligent monitoring platform Ducc, etc.

[0051] When the configuration on the configuration center server changes due to user-initiated configuration or automatic configuration based on detection results, the configuration center server generates code debugging instructions and sends them to the configuration center client. It can also generate code modification configuration information based on the changed configuration information. Specifically, when the code debugging instruction is a code rollback instruction, the configuration center server retrieves the bytecode to be rolled back from the monitoring center and generates code modification configuration information based on that bytecode.

[0052] After receiving a code debugging command, the configuration center client retrieves and parses the code modification configuration information from the configuration center server. It then triggers the dynamic code replacement module to replace the bytecode of the class requiring replacement in the target application and reloads the class dynamically. Once the class is loaded, the dynamic code replacement module notifies the monitoring center to record the code change data, which mainly includes the name of the replaced class and the bytecode before replacement. The monitoring center saves the bytecode before replacement to the historical modification record stack corresponding to the replaced class in this code change, for use during code rollback.

[0053] Figure 6 This is a schematic diagram of the main modules of a code debugging apparatus according to an embodiment of the present invention. Figure 6 As shown, the code debugging device 600 of this embodiment mainly includes a configuration information acquisition module 601, a bytecode replacement module 602, and a class dynamic loading module 603.

[0054] The configuration information acquisition module 601 is used to acquire code modification configuration information in response to code debugging instructions. The code modification configuration information includes the class name and bytecode to be replaced.

[0055] The bytecode replacement module 602 is used to find the current bytecode corresponding to the class name in the current code according to the class name, and replace the current bytecode with the bytecode to be replaced;

[0056] The class dynamic loading module 603 is used for a virtual machine-based dynamic class loading mechanism. It loads the bytecode to be replaced to reload the class corresponding to the class name for code debugging.

[0057] According to one embodiment of the present invention, the bytecode replacement module 602 can also be used to: modify the current bytecode to the bytecode to be replaced by a hook method, so as to use the bytecode to be replaced to replace the current bytecode.

[0058] According to another embodiment of the present invention, the code debugging apparatus 600 may further include a component registration module (not shown in the figure), used to: obtain the context of the container and re-register the component when the class corresponding to the class name is implemented as a container component.

[0059] According to another embodiment of the present invention, the code debugging apparatus 600 may further include a change data recording module (not shown in the figure), used to: after reloading the class corresponding to the class name by loading the bytecode to be replaced, notify the monitoring center to record code change data, wherein the code change data includes the class name and the current bytecode, wherein the current bytecode is saved to the historical modification record stack corresponding to the class name.

[0060] According to another embodiment of the present invention, when the code debugging instruction is a code rollback instruction, the code modification configuration information is generated in the following manner: the bytecode to be rolled back is retrieved from the top of the historical modification record stack corresponding to the class name, and the bytecode to be rolled back is used as the bytecode to be replaced; the code modification configuration information is generated according to the bytecode to be replaced.

[0061] According to another embodiment of the present invention, when the code debugging instruction is a code rollback instruction, before generating the code modification configuration information, the method further includes: determining that there is bytecode in the historical modification record stack corresponding to the class name; and, if there is no bytecode in the historical modification record stack corresponding to the class name, issuing an alarm reminder.

[0062] According to another embodiment of the present invention, the code debugging instruction is generated under the following circumstances: a problem is detected in the current code, and code modifications are made based on the problem; a problem is detected in the current code, and it is determined that code rollback is required based on the problem; or code modifications are made according to business requirements during code execution.

[0063] According to the technical solution of this invention, in response to a code debugging instruction, code modification configuration information is obtained. This configuration information includes the class name to be replaced and the bytecode to be replaced. Based on the class name, the current bytecode corresponding to the class name is located in the current code, and the current bytecode is replaced using the bytecode to be replaced. This technical solution utilizes the virtual machine's dynamic class loading mechanism to reload the class corresponding to the class name by loading the bytecode to be replaced, thereby enabling dynamic class reloading without the need for code compilation, construction, and deployment. This saves debugging time and improves debugging efficiency. Furthermore, this invention does not rely on Java probes for code replacement, thus avoiding permission issues associated with connecting to the JVM and dependencies on third-party programs. Additionally, this invention can monitor and record each code debugging operation, enabling rapid rollback of code replacement operations when necessary.

[0064] Figure 7 An exemplary system architecture 700 is shown, in which the code debugging method or apparatus of embodiments of the present invention can be applied.

[0065] like Figure 7 As shown, system architecture 700 may include terminal devices 701, 702, and 703, a network 704, and a server 705. Network 704 serves as the medium for providing communication links between terminal devices 701, 702, and 703 and server 705. Network 704 may include various connection types, such as wired or wireless communication links, or fiber optic cables, etc.

[0066] Users can use terminal devices 701, 702, and 703 to interact with server 705 via network 704 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 701, 702, and 703, such as programming applications, code debugging applications, code testing applications, etc. (for example only).

[0067] Terminal devices 701, 702, and 703 can be various electronic devices with displays and web browsing capabilities, including but not limited to smartphones, tablets, laptops, and desktop computers.

[0068] Server 705 can be a server providing various services, such as a backend management server supporting websites browsed by users using terminal devices 701, 702, and 703 (for example only). The backend management server can respond to received code debugging commands and other data by obtaining code modification configuration information, including the class name to be replaced and the bytecode to be replaced. Based on the class name, it finds the current bytecode corresponding to the class name in the current code and replaces the current bytecode with the bytecode to be replaced. Based on the virtual machine's dynamic class loading mechanism, it loads the bytecode to be replaced to reload the class corresponding to the class name, and feeds back the processing results (e.g., class reloading results, code debugging results – for example only) to the terminal devices.

[0069] It should be noted that the code debugging method provided in this embodiment of the invention is generally executed by server 705, and correspondingly, the code debugging device is generally set in server 705.

[0070] It should be understood that Figure 7 The number of terminal devices, networks, and servers shown is merely illustrative. Depending on implementation needs, any number of terminal devices, networks, and servers can be included.

[0071] The following is for reference. Figure 8 It shows a schematic diagram of the structure of a computer system 800 suitable for implementing terminal devices or servers of the present invention. Figure 8 The terminal device or server shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of the present invention.

[0072] like Figure 8 As shown, the computer system 800 includes a central processing unit (CPU) 801, which can perform various appropriate actions and processes based on programs stored in read-only memory (ROM) 802 or programs loaded from storage section 808 into random access memory (RAM) 803. The RAM 803 also stores various programs and data required for the operation of the system 800. The CPU 801, ROM 802, and RAM 803 are interconnected via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.

[0073] The following components are connected to I / O interface 805: an input section 806 including a keyboard, mouse, etc.; an output section 807 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 808 including a hard disk, etc.; and a communication section 809 including a network interface card such as a LAN card, modem, etc. The communication section 809 performs communication processing via a network such as the Internet. A drive 810 is also connected to I / O interface 805 as needed. A removable medium 811, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on drive 810 as needed so that computer programs read from it can be installed into storage section 808 as needed.

[0074] In particular, according to the embodiments disclosed in this invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this invention include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 809, and / or installed from removable medium 811. When the computer program is executed by central processing unit (CPU) 801, it performs the functions defined above in the system of this invention.

[0075] It should be noted that the computer-readable medium shown in this invention can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this invention, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this invention, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media can also be any computer-readable medium other than computer-readable storage media, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.

[0076] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0077] The units or modules described in the embodiments of the present invention can be implemented in software or hardware. The described units or modules can also be located in a processor; for example, a processor can be described as including a configuration information acquisition module, a bytecode replacement module, and a class dynamic loading module. The names of these units or modules do not necessarily limit the unit or module itself. For example, the configuration information acquisition module can also be described as "used to acquire code modification configuration information in response to code debugging instructions, wherein the code modification configuration information includes the class name to be replaced and the module whose bytecode to be replaced."

[0078] In another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiments; or it may exist independently and not assembled into the device. The computer-readable medium carries one or more programs, which, when executed by the device, cause the device to include: in response to a code debugging instruction, acquiring code modification configuration information, the code modification configuration information including the class name to be replaced and the bytecode to be replaced; based on the class name, searching for the current bytecode corresponding to the class name in the current code, and replacing the current bytecode with the bytecode to be replaced; and, based on the virtual machine's dynamic class loading mechanism, reloading the class corresponding to the class name by loading the bytecode to be replaced, for code debugging.

[0079] According to the technical solution of this invention, in response to a code debugging instruction, code modification configuration information is obtained. This configuration information includes the class name to be replaced and the bytecode to be replaced. Based on the class name, the current bytecode corresponding to the class name is located in the current code, and the current bytecode is replaced using the bytecode to be replaced. This technical solution utilizes the virtual machine's dynamic class loading mechanism to reload the class corresponding to the class name by loading the bytecode to be replaced, thereby enabling dynamic class reloading without the need for code compilation, construction, and deployment. This saves debugging time and improves debugging efficiency. Furthermore, this invention does not rely on Java probes for code replacement, thus avoiding permission issues associated with connecting to the JVM and dependencies on third-party programs. Additionally, this invention can monitor and record each code debugging operation, enabling rapid rollback of code replacement operations when necessary.

[0080] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can occur depending on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.

Claims

1. A method of code debugging, characterized by, The method comprises the following steps: In response to a code debugging instruction, code modification configuration information is obtained, the code modification configuration information comprising a class name requiring code replacement and to-be-replaced bytecode; According to the class name, current bytecode corresponding to the class name is found from current code, and the current bytecode is replaced with the to-be-replaced bytecode; Based on a dynamic class loading mechanism of a virtual machine, reloading of a class corresponding to the class name is performed by loading the to-be-replaced bytecode, so as to perform code debugging; In a case where the code debugging instruction is a code rollback instruction, the code modification configuration information is generated in the following manner: to-be-rolled-back bytecode is taken out from a top of a historical modification record stack corresponding to the class name, and the to-be-rolled-back bytecode is taken as the to-be-replaced bytecode, the historical modification record stack being used to save bytecode of a historical modification version of the class name; The code modification configuration information is generated according to the to-be-replaced bytecode.

2. The method of claim 1, wherein, The current bytecode is replaced with the to-be-replaced bytecode, comprising the following steps: The current bytecode is modified into the to-be-replaced bytecode through a hook method, so as to replace the current bytecode with the to-be-replaced bytecode.

3. The method of claim 1, wherein, The method further comprises the following steps: In a case where the class corresponding to the class name is implemented as a container component, a context of the container is obtained and registration of the component is performed again.

4. The method of claim 1, wherein, After reloading of the class corresponding to the class name is performed by loading the to-be-replaced bytecode, the following step is further included: A monitoring center is notified to record code change data, the code change data comprising the class name and the current bytecode, wherein the current bytecode is saved into a historical modification record stack corresponding to the class name.

5. The method of claim 1, wherein, In a case where the code debugging instruction is a code rollback instruction, the following steps are further included before the code modification configuration information is generated: It is determined that there is bytecode in a historical modification record stack corresponding to the class name; And in a case where there is no bytecode in the historical modification record stack corresponding to the class name, an alarm is given.

6. The method of claim 1, wherein, The code debugging instruction is generated in the following case: It is detected that there is a problem in the current code, and code modification is performed according to the problem; It is detected that there is a problem in the current code, and it is determined that code rollback needs to be performed according to the problem; During code running, code modification is performed according to business requirements.

7. An apparatus for code debugging, the apparatus comprising: The method comprises the following steps: A configuration information obtaining module is configured to obtain code modification configuration information in response to a code debugging instruction, the code modification configuration information comprising a class name requiring code replacement and to-be-replaced bytecode; A bytecode replacing module is configured to find current bytecode corresponding to the class name from current code according to the class name, and replace the current bytecode with the to-be-replaced bytecode; A class dynamic loading module is configured to perform reloading of a class corresponding to the class name by loading the to-be-replaced bytecode based on a dynamic class loading mechanism of a virtual machine, so as to perform code debugging; In a case where the code debugging instruction is a code rollback instruction, the code modification configuration information is generated by the following manner: taking out a to-be-rolled-back bytecode from a top of a history modification record stack corresponding to the class name, and taking the to-be-rolled-back bytecode as the to-be-replaced bytecode, the history modification record stack being used for saving a bytecode of a history modification version of the class name; generating the code modification configuration information according to the to-be-replaced bytecode.

8. An electronic device, comprising: comprising: one or more processors; a memory device for storing one or more programs, when the one or more programs are executed by the one or more processors, so that the one or more processors implement the method as claimed in any one of claims 1-6.

9. A computer readable medium having stored thereon a computer program, characterized in that The program is executed by the processor to implement the method as claimed in any one of claims 1-6. The program is executed by the processor to implement the method as claimed in any one of claims 1-6.