Code debugging method and device

Through the dynamic class loading mechanism of the virtual machine, classes are dynamically reloaded, which solves the problems of long code debugging time and Java probe permissions, and realizes efficient code debugging and fast rollback.

CN119862108AActive Publication Date: 2025-04-22BEIJING WODONG TIANJUN INFORMATION TECH CO LTD +1
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202311344783.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-10-17
Publication Date
2025-04-22
Estimated Expiration
2043-10-17

AI Technical Summary

Technical Problem

In the prior art, the conventional process of code debugging in test environments and online environments has long compiled construction and deployment time and low efficiency due to multiple modules and multiple lines of code, and has permission problems and dependency problems when using Java probes.

Method used

Through a dynamic class loading mechanism based on virtual machine, classes are reloaded dynamically, without compiling, building and deployment, and bytecode is directly replaced for code debugging.

Benefits of technology

Saves code debugging time, improves efficiency, avoids permission problems and dependencies of Java probes, and supports fast rollback of code replacement operations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119862108A_ABST
    Figure CN119862108A_ABST
Patent Text Reader

Abstract

The invention discloses a code debugging method and device, and relates to the technical field of computers. According to one specific embodiment, the method comprises the steps that in response to a code debugging instruction, code modification configuration information is obtained, and the code modification configuration information comprises a class name needing to be subjected to code replacement and a byte code to be replaced; searching a current byte code corresponding to the class name from the current code according to the class name, and replacing the current byte code with the byte code to be replaced; and reloading the class corresponding to the class name by loading the byte code to be replaced based on a dynamic class loading mechanism of the virtual machine so as to debug the code. According to the embodiment, the class is dynamically reloaded based on the dynamic class loading mechanism of the virtual machine, and code compiling construction and deployment are not needed, so that the code debugging time is saved, and the code debugging efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method and device for code debugging. Background Art

[0002] In the current web application development, testing, and online process, code debugging is required. At present, when debugging the code during the code testing process, if you encounter a problem, you first need to query the log, and then locate the problem in the code according to the log. If the problem is located, modify the relevant code snippets and recompile, build, and deploy. If the problem cannot be located, you need to add logs around the problem point to locate the problem. When debugging the code after the code is online, if you encounter an online problem, first locate the problem in the code according to the log, and modify the relevant code snippets according to the located problem, and then use the java (a computer language) probe to replace the code and recompile, build, and deploy. If the problem cannot be located, you need to quickly roll back the online version and compile and build the code of the previous stable version for deployment.

[0003] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:

[0004] For the conventional code debugging process in the test environment and the online environment, since the application system usually has multiple modules and many lines of code, it takes a long time to recompile, build and deploy the code after adjustment, resulting in time-consuming code debugging and low code debugging efficiency. Summary of the invention

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

[0006] To achieve the above-mentioned purpose, according to one aspect of an embodiment of the present invention, a method for code debugging is provided, comprising: in response to a code debugging instruction, obtaining code modification configuration information, the code modification configuration information including a class name that needs to be replaced and a bytecode to be replaced; according to the class name, searching for a current bytecode corresponding to the class name from the current code, and using the bytecode to be replaced to replace the current bytecode; based on the dynamic class loading mechanism of the virtual machine, reloading the class corresponding to the class name by loading the bytecode to be replaced, so as to perform code debugging.

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

[0008] Optionally, the method further comprises: when 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, it also includes: notifying a monitoring center to record code change data, the code change data including the class name and the current bytecode, wherein the current bytecode is saved in a historical modification record stack corresponding to the class name.

[0010] Optionally, in the case where the code debugging instruction is a code rollback instruction, the code modification configuration information is generated in the following manner: taking out the bytecode to be rolled back from the top of the historical modification record stack corresponding to the class name, and using the bytecode to be rolled back as the bytecode to be replaced; generating the code modification configuration information based on the bytecode to be replaced.

[0011] Optionally, when the code debugging instruction is a code rollback instruction, before generating the code modification configuration information, it also includes: determining whether there is bytecode in the historical modification record stack corresponding to the class name; and when there is no bytecode in the historical modification record stack corresponding to the class name, an alarm is issued.

[0012] Optionally, the code debugging instruction is generated in the following situations: a problem is detected in the current code, and the code is modified according to the existing problem; a problem is detected in the current code, and it is determined that a code rollback is required based on the existing problem; during code execution, the code is modified according to business needs.

[0013] According to another aspect of an embodiment of the present invention, a device for code debugging is provided, including: a configuration information acquisition module, used to obtain code modification configuration information in response to a code debugging instruction, the code modification configuration information including a class name that needs to be replaced and a bytecode to be replaced; a bytecode replacement module, used to search for a current bytecode corresponding to the class name from a current code according to the class name, and use the bytecode to be replaced to replace the current bytecode; a class dynamic loading module, used to reload the class corresponding to the class name by loading the bytecode to be replaced based on a dynamic class loading mechanism of a virtual machine, so as to perform code debugging.

[0014] According to another aspect of an embodiment of the present invention, an electronic device is provided, comprising: one or more processors; 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 by an embodiment of the present invention.

[0015] According to another aspect of the embodiments of the present invention, a computer-readable medium is provided, on which a computer program is stored. When the program is executed by a processor, the code debugging method provided by the embodiments of the present invention is implemented.

[0016] An embodiment of the above invention has the following advantages or beneficial effects: by responding to the code debugging instruction, the code modification configuration information is obtained, and the code modification configuration information includes the class name and the bytecode to be replaced that need to be replaced; according to the class name, the current bytecode corresponding to the class name is found from the current code, and the bytecode to be replaced is used to replace the current bytecode; based on the dynamic class loading mechanism of the virtual machine, the class corresponding to the class name is reloaded by loading the bytecode to be replaced, so as to perform the technical solution of code debugging, based on the dynamic class loading mechanism of the virtual machine, by implementing a custom class loader to load the bytecode to be replaced, the class can be reloaded dynamically, and there is no need to compile, build and deploy the code, thereby saving the time of code debugging and improving the efficiency of code debugging. At the same time, the technical solution of the present invention does not realize code replacement based on java probes, so there will be no permission problems when using probes to replace code and the dependence on third-party programs. In addition, the present invention can also monitor and record each code debugging operation, and can achieve rapid rollback of code replacement operations when necessary.

[0017] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.

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

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

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

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

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

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

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

[0026] Figure 8 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION

[0027] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.

[0028] It should be noted that the collection, collection, updating, analysis, processing, use, transmission, storage and other aspects of user personal information involved in the technical solution disclosed in the present invention are in compliance with the provisions of relevant laws and regulations, are used for legitimate purposes, and do not violate public order and good morals. Necessary measures are taken for user personal information to prevent illegal access to user personal information data and maintain the security of user personal information, network security and national security.

[0029] In the current web application development, testing, and online process, code debugging is required. Currently, when debugging code during code testing, if you encounter a problem, you first need to query the log, and then locate the problem in the code based on the log. If the problem is located, modify the relevant code snippets and recompile, build, and deploy. If the problem cannot be located, you need to add logs around the problem point to locate the problem.

[0030] When debugging the code after the code is online, if you encounter an online problem, first locate the problem in the code according to the log, modify the relevant code snippets according to the located problem, and then use the Java (a computer language) probe to replace the code and recompile, build, and deploy. If the problem cannot be located, you need to quickly roll back the online version and compile and build the last stable version of the code for deployment. When using the Java probe to replace the code, you need to connect to the JVM (Java Virtual Machine) of the program that needs to replace the code through other programs, and then load the specified compressed package to replace and modify the runtime code.

[0031] For the conventional code debugging process in the test environment and the online environment, since the application system usually has multiple modules and many lines of code, it takes a long time to recompile, build and deploy the code after adjustment, resulting in a long time for code debugging and low code debugging efficiency. In addition, the use of Java probes for runtime code replacement requires a third-party program to connect to the virtual machine of the target application. The first problem encountered is the JVM permission problem of the target application. In order to ensure the security of the JVM, the virtual machine is generally not allowed to connect. Secondly, each time this method is used for replacement, it is necessary to modify the startup parameters or code of the third-party application and restart it. Finally, there are certain security risks in runtime code replacement, and it is difficult to recover after a problem occurs.

[0032] The present invention mainly solves the following technical problems that current network application developers have when debugging and handling online problems:

[0033] 1. Reduce the time required for redeployment when modifying the code;

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

[0035] 3. Ability to monitor and record each operation, and quickly roll back replacement operations when necessary.

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

[0037] Step S101: In response to the code debugging instruction, obtain code modification configuration information, wherein the code modification configuration information includes the class name that needs to be replaced and the bytecode to be replaced. In an embodiment of the present invention, the code debugging instruction may be specifically generated in the following situations: it is detected that there is a problem with the current code, and the code is modified according to the existing problem; it is detected that there is a problem with the current code, and it is determined that a code rollback is required based on the existing problem; during the code running process, the code is modified according to business needs. That is to say, in a test environment or an online environment, when a problem is detected in the code and a small amount of code modification is made, or it is determined that a code rollback is required based on the detected problem, or the user actively modifies the code according to business needs, the generation of code debugging instructions can be triggered.

[0038] The code debugging system of the present invention is deployed on the target application. After receiving the code debugging instruction, it will obtain specific code modification configuration information from the configuration center server, and parse the code modification configuration information to obtain the class name that needs to be replaced, the bytecode to be replaced, the target application identifier, the operator, the configuration submission time and other information. Among them, the target application identifier is used to locate the application, the class name that needs to be replaced and the bytecode to be replaced are the core content of the code modification configuration information, which are used to perform the actual code replacement operation, and the operator and configuration submission time are used to record security-related information. Among them, bytecode (Byte-code) is a binary file that contains an execution program and consists of a sequence of op codes or data pairs, which is an intermediate code.

[0039] Step S102: According to the class name, the current bytecode corresponding to the class name is searched from the current code, and the bytecode to be replaced is used to replace the current bytecode. The code currently being debugged in the target application is the current code. This step requires searching the current bytecode of the corresponding class from the current code according to the class name that needs to be replaced in the code modification configuration information, and then performing 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 by 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 the class. During the loading process, the structural information of the class will be stored in the method area of ​​the JVM, and the specific object will be stored in the heap. Code replacement in the runtime environment is the process of reloading the class. The bytecode of the class is modified by the hook method of the JVM, and the class is reinitialized based on the modified bytecode. In an embodiment of the present invention, class loading at runtime is mainly based on the ClassLoader class, which is an abstract class, and its instance is responsible for reading the Java bytecode into the JVM. In the class loading mechanism of the JVM, each class loader has its own namespace. For the same class loader, classes with the same name can only be loaded once. Therefore, when performing dynamic code replacement, it is necessary to implement a custom class loader to load the bytecode to be replaced.

[0042] Step S103: Based on the dynamic class loading mechanism of the virtual machine, the class corresponding to the class name is reloaded by loading the bytecode to be replaced to debug the code. Based on the dynamic class loading mechanism of the virtual machine, a custom class loader is implemented to load the bytecode to be replaced, so that the class can be reloaded dynamically without the need for code compilation, construction and deployment, thereby saving time for code debugging and improving the efficiency of code debugging. At the same time, the technical solution of the present invention does not rely on Java probes to implement code replacement, so there will be no permission issues when using probes to replace code and the need to connect to the JVM and the dependence on third-party programs.

[0043] According to one of the embodiments of the present invention, the code debugging method may also include: when 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 that needs to be replaced with code belongs to a component bean in a Spring container, it is also necessary to obtain the context of the Spring container to re-register the bean. Among them, the Spring container is the core of the Spring framework and is used to manage objects. The container will create objects, connect them together, configure them, and manage their entire life cycle 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, it also includes: notifying a monitoring center to record code change data, the code change data including the class name and the current bytecode, wherein the current bytecode is saved to a historical modification record stack corresponding to the class name. The present invention can quickly roll back the code replacement operation when necessary by monitoring and recording each code debugging operation.

[0045] Figure 2FIG. 1 is a schematic diagram of a dynamic class loading process in a code debugging process 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, first obtain code modification configuration information; then parse the code modification configuration information to obtain the class name and the bytecode to be replaced that need to be replaced; then use the bytecode to be replaced to replace the current bytecode of the class; load the bytecode to be replaced through the class loader to perform dynamic loading of the class. Then, determine whether the replaced class is a container component. If so, obtain the container context and re-register the component, and notify the monitoring center to record the code change data. Otherwise, directly notify the monitoring center to record the code change data. At this point, dynamic class loading can be achieved during code debugging.

[0046] Figure 3 FIG. 1 is a schematic diagram of a 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 save the bytecode of the historical modification version. When recording the code change data, the monitoring center first parses the notification message to obtain the code change data, which includes the class name of the code replacement, the current bytecode before the replacement, the time of the replacement, the operator and other information; then, the code change data is recorded and stored, and the current bytecode before the replacement is saved in 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 manner: taking out the bytecode to be rolled back from the top of the historical modification record stack corresponding to the class name, and taking the bytecode to be rolled back as the bytecode to be replaced; generating the code modification configuration information according to 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 a code rollback is required, it triggers the configuration center server to generate a code rollback instruction and sends it to the code debugging system deployed on the target application, so that the code debugging system obtains 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 take out the last stable version of the code from the top of the historical modification record stack corresponding to the class that needs to be replaced as the bytecode to be rolled back, thereby obtaining the bytecode to be replaced, which is used to generate the code modification configuration information. In this scenario, the stack is also called a stack, which is a linear table with limited operations, which is limited to a linear table that performs insertion and deletion operations only at the end of the table, and the end of the table 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, it may also include: determining that there is bytecode in the historical modification record stack corresponding to the class name; and, when there is no bytecode in the historical modification record stack corresponding to the class name, an alarm reminder is issued. If there is no bytecode in the historical modification record stack corresponding to the class that needs to be replaced (i.e., the stack is empty), it means that the currently running code is already the version when the application was initially started, so the code cannot be rolled back, and an alarm reminder can be issued at this time.

[0049] Figure 4 FIG. 1 is a schematic diagram of a code modification configuration information generation process according to an embodiment of the present invention. 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 will first determine whether there is bytecode in the historical modification record stack; if so, the bytecode to be rolled back is taken out from the top of the stack, and the code modification configuration information is generated according to the bytecode to be rolled back; otherwise, no bytecode can be obtained from the stack, and an alarm reminder can be directly issued.

[0050] Figure 5 It is a schematic diagram of the module interaction principle of an embodiment of the present invention. In one embodiment of the present invention, when debugging the code, the modules involved mainly include: a configuration center server, a configuration center client, a dynamic code replacement module and a monitoring center, wherein a problem detection system may also be deployed in the configuration center server to detect whether there is a problem with the code of the target application, and send the detection result to the configuration center server, so that the configuration center server generates corresponding code debugging instructions. The configuration center client, the dynamic code replacement module and the monitoring center can be deployed separately in the target application, or the three can be integrated and deployed in the target application, or only the configuration center client and the dynamic code replacement module can be integrated and deployed in the target application, and the monitoring center can be deployed separately from the target application in other places, which is not limited by the present invention. The configuration center server is a network application independent of the code debugging system, which is used to decouple the configuration information required by the code debugging system from the code debugging system and manage the configuration in a unified manner. Currently, the commonly used configuration centers in the industry include open source distributed configuration centers Apollo, Nacos and intelligent monitoring platform Ducc.

[0051] When the configuration of the configuration center server changes due to active configuration by the user or automatic configuration based on the detection results, the configuration center server will generate a code debugging instruction and send it to the configuration center client, and can also generate code modification configuration information based on the changed configuration information. Among them, when the code debugging instruction is a code rollback instruction, the configuration center server will obtain the bytecode to be rolled back from the monitoring center, and generate code modification configuration information based on the bytecode to be rolled back.

[0052] After receiving the code debugging instruction, the configuration center client obtains the code modification configuration information from the configuration center server and parses it, then triggers the dynamic code replacement module to perform the bytecode replacement operation corresponding to the class that needs to be replaced in the target application, and reloads the class dynamically. After the class loading is completed, the dynamic code replacement module will notify the monitoring center to record the code change data, which mainly includes the replaced class name and the bytecode before replacement. Among them, the monitoring center will save the bytecode before replacement to the historical modification record stack corresponding to the class replaced in this code change, so that it can be obtained and used when the code is rolled back.

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

[0054] Configuration information acquisition module 601, used to obtain code modification configuration information in response to a code debugging instruction, wherein the code modification configuration information includes a class name that needs to be replaced and a bytecode to be replaced;

[0055] A bytecode replacement module 602 is used to search the current bytecode corresponding to the class name from 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 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.

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

[0058] According to another embodiment of the present invention, the code debugging device 600 may also include a component registration module (not shown in the figure) for obtaining the context of the container and re-registering 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 device 600 may further include a change data recording module (not shown in the figure), which is 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, the code change data including the class name and the current bytecode, wherein the current bytecode is saved in 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: taking out the bytecode to be rolled back from the top of the historical modification record stack corresponding to the class name, and using the bytecode to be rolled back as the bytecode to be replaced; generating the code modification configuration information 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, it also includes: determining whether there is bytecode in the historical modification record stack corresponding to the class name; and, when 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 in the following situations: it is detected that there is a problem with the current code, and the code is modified according to the existing problem; it is detected that there is a problem with the current code, and it is determined that a code rollback is required based on the existing problem; during the code running process, the code is modified according to business needs.

[0063] According to the technical solution of the embodiment of the present invention, by responding to the code debugging instruction, the code modification configuration information is obtained, and the code modification configuration information includes the class name and the bytecode to be replaced that need to be replaced; according to the class name, the current bytecode corresponding to the class name is found from the current code, and the bytecode to be replaced is used to replace the current bytecode; based on the dynamic class loading mechanism of the virtual machine, the class corresponding to the class name is reloaded by loading the bytecode to be replaced, so as to carry out the technical solution of code debugging, based on the dynamic class loading mechanism of the virtual machine, by implementing a custom class loader to load the bytecode to be replaced, the class can be reloaded dynamically, and there is no need to compile, build and deploy the code, thereby saving the time of code debugging and improving the efficiency of code debugging. At the same time, the technical solution of the present invention does not realize code replacement based on java probe, so there will be no permission problem when the probe needs to be connected to JVM for code replacement and the problem of dependence on third-party programs. In addition, the present invention can also monitor and record each code debugging operation, and can achieve rapid rollback of code replacement operation when necessary.

[0064] Figure 7 An exemplary system architecture 700 is shown to which the code debugging method or code debugging apparatus according to an embodiment of the present invention can be applied.

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

[0066] Users can use terminal devices 701, 702, 703 to interact with server 705 through network 704 to receive or send messages, etc. Terminal devices 701, 702, 703 can be installed with various communication client applications, such as programming applications, code debugging applications, code testing applications, etc. (only examples).

[0067] The terminal devices 701 , 702 , and 703 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers.

[0068] Server 705 may be a server that provides various services, such as a background management server that provides support for websites browsed by users using terminal devices 701, 702, and 703 (for example only). The background management server may respond to the received code debugging instructions and other data in accordance with the code debugging instructions, and obtain code modification configuration information, wherein the code modification configuration information includes the class name and the bytecode to be replaced that need to be replaced; according to the class name, the current bytecode corresponding to the class name is searched from the current code, and the bytecode to be replaced is used to replace the current bytecode; based on the dynamic class loading mechanism of the virtual machine, the class corresponding to the class name is reloaded by loading the bytecode to be replaced, and the processing result (such as class reloading result, code debugging result - for example only) is fed back to the terminal device.

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

[0070] It should be understood that Figure 7 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.

[0071] Reference below Figure 8 , which shows a schematic diagram of the structure of a computer system 800 of a terminal device or server suitable for implementing an embodiment of the present invention. Figure 8 The terminal device or server shown is only an example and should not bring any limitation to the functions 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 according to a program stored in a read-only memory (ROM) 802 or a program loaded from a storage part 808 into a random access memory (RAM) 803. In the RAM 803, various programs and data required for the operation of the system 800 are also stored. The CPU 801, the ROM 802, and the RAM 803 are connected to each other 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 the I / O interface 805: an input section 806 including a keyboard, a mouse, etc.; an output section 807 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, 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, a modem, etc. The communication section 809 performs communication processing via a network such as the Internet. A drive 810 is also connected to the I / O interface 805 as needed. A removable medium 811, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 810 as needed, so that a computer program read therefrom is installed into the storage section 808 as needed.

[0074] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 809, and / or installed from the removable medium 811. When the computer program is executed by the central processing unit (CPU) 801, the above-mentioned functions defined in the system of the present invention are executed.

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

[0076] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0077] The units or modules involved in the embodiments of the present invention may be implemented in software or hardware. The units or modules described may also be provided in a processor, for example, may be described as: a processor including a configuration information acquisition module, a bytecode replacement module and a class dynamic loading module. Among them, the names of these units or modules do not constitute a limitation on the units or modules themselves in certain circumstances, for example, the configuration information acquisition module may also be described as "used to obtain code modification configuration information in response to a code debugging instruction, wherein the code modification configuration information includes the class name for which code replacement is required and the module of the bytecode to be replaced".

[0078] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or it may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes: in response to a code debugging instruction, obtaining code modification configuration information, the code modification configuration information includes the class name and the bytecode to be replaced that need to be replaced; according to the class name, searching the current bytecode corresponding to the class name from the current code, and using the bytecode to be replaced to replace the current bytecode; based on the dynamic class loading mechanism of the virtual machine, reloading the class corresponding to the class name by loading the bytecode to be replaced, so as to debug the code.

[0079] According to the technical solution of the embodiment of the present invention, by responding to the code debugging instruction, the code modification configuration information is obtained, and the code modification configuration information includes the class name and the bytecode to be replaced that need to be replaced; according to the class name, the current bytecode corresponding to the class name is found from the current code, and the bytecode to be replaced is used to replace the current bytecode; based on the dynamic class loading mechanism of the virtual machine, the class corresponding to the class name is reloaded by loading the bytecode to be replaced, so as to carry out the technical solution of code debugging, based on the dynamic class loading mechanism of the virtual machine, by implementing a custom class loader to load the bytecode to be replaced, the class can be reloaded dynamically, and there is no need to compile, build and deploy the code, thereby saving the time of code debugging and improving the efficiency of code debugging. At the same time, the technical solution of the present invention does not realize code replacement based on java probe, so there will be no permission problem when the probe needs to be connected to JVM for code replacement and the problem of dependence on third-party programs. In addition, the present invention can also monitor and record each code debugging operation, and can achieve rapid rollback of code replacement operation when necessary.

[0080] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A code debugging method, characterized in that: include: In response to the code debugging instruction, code modification configuration information is obtained, where the code modification configuration information includes a class name that needs to be replaced and a bytecode to be replaced; According to the class name, searching for a current bytecode corresponding to the class name from the current code, and replacing the current bytecode with the bytecode to be replaced; Based on the dynamic class loading mechanism of the virtual machine, the class corresponding to the class name is reloaded by loading the bytecode to be replaced, so as to perform code debugging.

2. The method according to claim 1, characterized in that Replacing the current bytecode with the bytecode to be replaced includes: The current bytecode is modified into the bytecode to be replaced by a hook method, so as to replace the current bytecode with the bytecode to be replaced.

3. The method according to claim 1, characterized in that The method further comprises: In the case where the class corresponding to the class name is implemented as a container component, the context of the container is obtained and the component is re-registered.

4. The method according to claim 1, characterized in that After reloading the class corresponding to the class name by loading the bytecode to be replaced, the method further includes: The monitoring center is notified to record code change data, wherein the code change data includes the class name and the current bytecode, wherein the current bytecode is saved in a historical modification record stack corresponding to the class name.

5. The method according to claim 4, characterized in that In the case where the code debugging instruction is a code rollback instruction, the code modification configuration information is generated in the following manner: Taking out the bytecode to be rolled back from the top of the historical modification record stack corresponding to the class name, and using the bytecode to be rolled back as the bytecode to be replaced; The code modification configuration information is generated according to the bytecode to be replaced.

6. The method according to claim 5, characterized in that In the case where the code debugging instruction is a code rollback instruction, before generating the code modification configuration information, the method further includes: Determine whether there is bytecode in the historical modification record stack corresponding to the class name; Furthermore, when there is no bytecode in the historical modification record stack corresponding to the class name, an alarm is issued.

7. The method according to claim 1, characterized in that The code debugging instructions are generated in the following situations: It is detected that there is a problem with the current code, and the code is modified according to the existing problem; Detecting that there is a problem with the current code, and determining that a code rollback is required based on the problem; During the code running process, the code was modified according to business needs.

8. A device for code debugging, characterized in that: include: A configuration information acquisition module, used to obtain code modification configuration information in response to a code debugging instruction, wherein the code modification configuration information includes a class name that needs to be replaced and a bytecode to be replaced; A bytecode replacement module, used to search for a current bytecode corresponding to the class name from the current code according to the class name, and replace the current bytecode with the bytecode to be replaced; The class dynamic loading module is used for 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.

9. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 7.

10. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Code operation method and device

    CN105808266A

  • JAVA card bytecode reference access test method

    CN106649009A

  • Online vulnerability repairing method and device

    CN111506904A

  • Test processing method and device

    CN113760701A

  • Dynamic debugging method and device of software product, computer equipment and storage medium

    CN113791979A