Method, device and equipment for identifying redundant codes and computer readable medium
By intercepting access requests and recording call status during class loading, redundant code is solved, and the problem of not being able to identify redundant code in time in the prior art is improved, and the stability and high availability of the application are improved.
Patent Information
- Application Number
- CN202310631974.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-30
- Publication Date
- 2024-12-03
AI Technical Summary
The redundant code cannot be identified in time in the prior art, resulting in the accumulation of business logic code, which seriously affects the normal access of the application and system stability.
By intercepting access requests, requests that meet the cache conditions are stored, and the original class is instrumented when the class is loaded, the call status is recorded, and the redundant code is identified based on the code coverage.
It realizes timely identification of redundant codes, reduces the impact on access requests, improves the stability and high availability of the business system, and ensures normal access to the application.
Smart Images

Figure CN119065950A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method, device, equipment and computer-readable medium for identifying redundant codes. Background Art
[0002] With the development of Internet technology, users can directly access servers through applications. The access portals provided by some applications have huge traffic, with millions of transactions per second at peak times. At the same time, as core business systems, they have very high requirements for stability.
[0003] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art: in the process of daily development, testing and maintenance, the business logic code only increases but never decreases, and the new business logic code leads to the abandonment of the logic code, which is called redundant code. Since the redundant code cannot be identified in time, the normal access of the application is seriously affected. Summary of the invention
[0004] In view of this, embodiments of the present invention provide a method, apparatus, device and computer-readable medium for identifying redundant codes, which can timely identify redundant codes and improve the normal access of guaranteed applications.
[0005] To achieve the above object, according to one aspect of an embodiment of the present invention, a method for identifying redundant codes is provided, comprising:
[0006] After intercepting the access request, storing the access request that meets the cache condition;
[0007] During class loading, the original class of the access request is instrumented to obtain an instrumented class to record the calling status of the access request;
[0008] The code coverage rate in the application is determined according to the calling status, so as to identify redundant codes in the application according to the code coverage rate.
[0009] After intercepting the access request, storing the access request that meets the cache condition includes:
[0010] According to the chain of responsibility model, intercept the access request;
[0011] A blocking queue of the access request is established based on the cache condition, and the access request in the blocking queue is stored.
[0012] The blocking queue includes a linked list blocking queue.
[0013] The storing the access request that meets the cache condition includes:
[0014] When processing the sending request, the access request that meets the cache condition is asynchronously stored.
[0015] The class loading includes class loading when the access request is running;
[0016] The inserting the original class of the access request to obtain the inserted class to record the calling status of the access request includes:
[0017] The original class of the access request is instrumented, and the bytecode structure is changed to obtain the instrumented class to record the calling status of the access request.
[0018] The class loading includes class loading during access request compilation;
[0019] The instrumenting the original class of the access request includes:
[0020] The logic instructions of the operation source code of the access request include an unconditional jump instruction or a termination instruction, and before the unconditional jump instruction or the termination instruction, the original class of the access request is plugged;
[0021] The logic instructions of the operation source code of the access request include a conditional jump instruction. After the conditional jump instruction, the original class of the access request is plugged.
[0022] The identifying redundant code in the application according to the code coverage includes:
[0023] In the process of refactoring a code project or optimizing a code, redundant codes of methods in the class of the application are identified according to the code coverage.
[0024] According to a second aspect of an embodiment of the present invention, there is provided a device for identifying a redundant code, comprising:
[0025] A storage module, used for storing the access requests that meet the cache conditions after intercepting the access requests;
[0026] A status module, used to insert a stub into the original class of the access request when the class is loaded, and obtain the inserted class to record the calling status of the access request;
[0027] The identification module is used to determine the code coverage rate in the application according to the calling state, so as to identify the redundant code in the application according to the code coverage rate.
[0028] According to a third aspect of an embodiment of the present invention, there is provided an electronic device for identifying a redundant code, comprising:
[0029] one or more processors;
[0030] a storage device for storing one or more programs,
[0031] When the one or more programs are executed by the one or more processors, the one or more processors implement the above method.
[0032] According to a fourth aspect of an embodiment of the present invention, there is provided a computer-readable medium on which a computer program is stored, and when the program is executed by a processor, the method as described above is implemented.
[0033] One embodiment of the above invention has the following advantages or beneficial effects: after intercepting the access request, the access request that meets the cache condition is stored; when loading the class, the original class of the access request is plugged to obtain the plugged class to record the call status of the access request; the code coverage rate in the application is determined according to the call status to identify the redundant code in the application according to the code coverage rate. Storing the access request and then identifying the redundant code can, on the one hand, reduce the impact on the normal processing of the access request; on the other hand, timely identifying the redundant code in the application can improve the stability and high availability of the business system, thereby improving the guarantee of normal access to the application.
[0034] 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
[0035] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0036] Figure 1 is a schematic diagram of the main flow of a method for identifying redundant codes according to an embodiment of the present invention;
[0037] Figure 2 is a schematic diagram of a process of storing access requests that meet cache conditions according to an embodiment of the present invention;
[0038] Figure 3 is a schematic diagram of a blocking queue according to an embodiment of the present invention;
[0039] Figure 4 is a schematic diagram of a process for identifying redundant codes according to an embodiment of the present invention;
[0040] Figure 5 is a schematic diagram of the main structure of a device for identifying redundant codes according to an embodiment of the present invention;
[0041] Figure 6 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;
[0042] Figure 7 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
[0043] 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.
[0044] In the daily development, testing and maintenance process, too much redundant code often leads to reduced system reliability and maintainability. Since the redundant code cannot be identified in time, the normal access of the application is seriously affected.
[0045] In order to identify redundant codes in a timely manner and ensure normal access to applications, the following technical solutions in the embodiments of the present invention may be adopted.
[0046] See also Figure 1 , Figure 1 FIG. 1 is a schematic diagram of the main flow of a method for identifying redundant codes according to an embodiment of the present invention. Based on a storage access request, redundant codes are identified through the call status of the access request. Figure 1 As shown, the specific steps include:
[0047] S101. After intercepting access requests, store access requests that meet cache conditions.
[0048] In an embodiment of the present invention, a user accesses an application by sending an access request. As an example, the user sends an access request to a server of the application to access the application.
[0049] In the case where a user sends an access request, the access request is intercepted and the access request that meets the storage condition is stored, with the purpose of identifying redundant codes based on the stored access request.
[0050] See also Figure 2 , Figure 2 The flowchart of storing access requests that meet the cache conditions according to an embodiment of the present invention is shown in FIG. The flowchart specifically includes the following steps:
[0051] S201. Intercept access requests according to the chain of responsibility model.
[0052] In an embodiment of the present invention, intercepting the access request may be intercepting all access requests to the application within a preset time period. By analyzing the access requests within the preset time period, redundant codes in the application are identified.
[0053] In one embodiment of the present invention, in order to improve the comprehensiveness of intercepting access requests and reduce the omission of intercepting access requests, access requests can be intercepted according to the responsibility chain model. The responsibility chain model regards each node in the chain as an object, each node processes different requests, and automatically maintains a next node object internally. When a request is sent from the first section of the chain, it will be passed to each node object along the path of the chain until an object processes the request.
[0054] As an example, a node object includes processor A, processor B, and processor C. In the chain of responsibility pattern, multiple processors process the same request in sequence. A request is first processed by processor A, and then passed to processor B. After processor B processes the request, it passes the request to processor C, and so on, forming a chain of responsibility. Each processor in the chain of responsibility assumes its own processing responsibilities. This chain of responsibility pattern will execute all processors once without interruption.
[0055] In the embodiment of the present invention, in order to intercept the access request without affecting the normal processing of the access request, the responsibility chain mode is adopted to intercept the access request. As an example, the node object includes processor A and processor B. The access request is a request to access the application. After receiving the access request, processor A continues to execute the access request; after receiving the access request, processor B monitors the access request to implement the interception of the access request.
[0056] S202: Establish a blocking queue for access requests based on a cache condition, and store the access requests in the blocking queue.
[0057] In an embodiment of the present invention, in order to improve the processing efficiency of access requests, a blocking queue can be used to store access requests. Specifically, a blocking queue of access requests is established based on a cache condition, and the access requests in the blocking queue are stored. The cache condition is a preset restriction condition for caching access requests. As an example, the cache condition includes the amount of data stored in each data block in the blocking queue.
[0058] See also Figure 3 , Figure 3 is a schematic diagram of a blocking queue according to an embodiment of the present invention. Figure 3 In FIG. 5 , the blocking queue includes five flows, namely, flow 1, flow 2, flow 3, flow 4, and flow 5. The data volume of the data block corresponding to each flow is the same. It can be understood that the access requests in the blocking queue are stored according to the cache conditions.
[0059] In one embodiment of the present invention, the blocking queue includes a linked blocking queue (LinkedBlockingQueue). The linked blocking queue is a blocking queue implemented based on a linked list. As an example, a linked blocking queue is used in a memory to store access requests. The access requests are stored in flow 1, and after the amount of data in the cache condition is met, the access requests are continued to be stored in flow 2.
[0060] The use of linked list blocking queues can improve the concurrency performance of obtaining and sending access requests. Specifically, in the linked list blocking queue, independent and different locks are used to control data synchronization for the operations of adding access requests and obtaining access requests. In the case of high concurrency, obtaining and sending access requests can operate the data in the queue in parallel, thereby improving the concurrency performance of the entire queue.
[0061] In one embodiment of the present invention, in order to decouple the identification of redundant codes and the normal processing of access requests and ensure that the two do not affect each other, in the case of processing access requests, access requests that meet the cache conditions are asynchronously stored.
[0062] S102: When loading a class, the original class of the access request is instrumented to obtain an instrumented class to record the calling status of the access request.
[0063] Instrumentation is to insert probes into the program while ensuring the logical integrity of the original program. The probes collect information in the code and insert code segments at specific locations to collect dynamic context information when the program is running.
[0064] The class loading process refers to the process in which the JVM virtual machine loads the class information in the .class file into the memory and parses it to generate the corresponding class object.
[0065] In one embodiment of the present invention, class loading includes class loading when the access request is running. That is, class loading is performed while the access request is running. The original class of the access request is instrumented, and the instrumented class is obtained after the bytecode structure is changed to record the call status of the access request. As an example, the call status of the access request includes called or not called.
[0066] Specifically, the original class is instrumented during class loading, and a probe is added to the class file to change the bytecode structure to obtain the instrumented class. The probe does not change the behavior of the method in the original class file, but only records whether the method has been executed. If the method in the class file has been executed, the call status includes called; if the method in the class file has not been executed, the call status includes not called.
[0067] It can be seen that by inserting the original class, the calling status of the method is recorded.
[0068] In one embodiment of the present invention, class loading includes class loading when the access request is compiled. It is understandable that class loading is performed while the access request is compiled. The original class of the access request is instrumented and can be executed based on the instruction type.
[0069] Instrumentation mainly collects characteristic data of program operation through the execution of instrumentation points, inserts boolean[] array into bytecode through agent to mark method executable code, and generates corresponding mark when corresponding statement is executed. Boolean array and generated mark are called probe. When source code is compiled into bytecode, logical instructions of source code, such as conditional judgment, loop, etc., will be compiled into special instructions. In the process of dynamic instrumentation, when these instructions are processed, they will be instrumented in different ways according to different logics.
[0070] As an example, the logic instructions of the operation source code of the access request include an unconditional jump instruction or a termination instruction, and before the unconditional jump instruction or the termination instruction, the original class of the access request is plugged in. For example, the termination instruction includes return or throw.
[0071] As another example, the logic instructions of the operation source code of the access request include a conditional jump instruction, and after the conditional jump instruction, the original class of the access request is instrumented.
[0072] S103: Determine the code coverage rate in the application according to the calling state, so as to identify redundant codes in the application according to the code coverage rate.
[0073] Code coverage is a metric in software testing that describes the proportion and extent of source code in a program that is tested. The resulting proportion is called code coverage.
[0074] In an embodiment of the present invention, the code coverage of an application is determined according to the call status. It should be noted that the call status is an identifier of whether a method in an application class is called. Therefore, determining the code coverage of an application according to the call status includes determining the code coverage of a method in an application class according to the call status of the method in the application class. That is, the embodiment of the present invention can identify redundant code in the method dimension.
[0075] As an example, a class in an application includes method 1 and method 2. If method 1 is not called, the calling status of method 1 is: not called; if method 2 is not called, the calling status of method 2 is: not called. It can be seen that the code coverage of the application is 0.
[0076] The embodiments of the present invention are mostly used in code refactoring projects or code optimization. As an example, the code refactoring project includes creating a new application. As another example, the code optimization includes application update.
[0077] Specifically, in the process of refactoring a code project or optimizing a code, redundant codes of methods in an application class are identified according to code coverage.
[0078] In an embodiment of the present invention, after the code coverage is determined, redundant code in the application can be identified according to the code coverage. As an example, a redundancy threshold is preset, and codes with a code coverage less than the redundancy threshold are regarded as redundant codes.
[0079] See also Figure 4 , Figure 4 1 is a schematic diagram of a process of identifying redundant codes according to an embodiment of the present invention. After a user sends an access request, the access request may be stored when the access request is processed. Based on the stored access request, the redundant code is identified by the type of class loading. The above process of identifying redundant codes does not affect the normal processing of method requests.
[0080] The following is an example of the technical solution in the embodiment of the present invention using the pre-split application. A class PackageSplitServiceImpl.java of the pre-split application includes a getPreOrderPackageDTO() method and a getDefaultResponse() method.
[0081] The getPreOrderPackageDTO() method is used to add a default stacking label to sku that has no business meaning. This method is not called anywhere in the code base, and the calling status includes not called.
[0082] The function of the getDefaultResponse() method is similar to that of the getPreOrderPackageDTO() method. The getDefaultResponse() method takes in the request dimension as an input parameter, which adds a default stacking label to the sku with unclear business meaning, and provides it to the caller. If no default business label is given, a stacking exception will occur. The getDefaultResponse() method is called in the code base, and the call status includes called.
[0083] According to the code coverage of the method determined by the above calling status, the getPreOrderPackageDTO() method can be identified as redundant code and the getDefaultResponse() method as non-redundant code in combination with the preset redundancy threshold.
[0084] In the above embodiment, after intercepting the access request, the access request that meets the cache condition is stored; when loading the class, the original class of the access request is instrumented to obtain the instrumented class to record the call status of the access request; the code coverage in the application is determined according to the call status to identify the redundant code in the application according to the code coverage. Storing the access request and then identifying the redundant code can, on the one hand, reduce the impact on the normal processing of the access request; on the other hand, timely identifying the redundant code in the application can improve the stability and high availability of the business system, thereby improving the guarantee of normal access to the application.
[0085] In addition, online traffic, i.e. access requests, can be cached in real time or offline to accurately identify redundant code, and the coverage results of business code can be provided to developers for manual verification.
[0086] See also Figure 5 , Figure 5 is a schematic diagram of the main structure of the apparatus for identifying redundant codes according to an embodiment of the present invention. The apparatus for identifying redundant codes can implement a method for identifying redundant codes, such as Figure 5 As shown, the device for identifying redundant codes specifically includes:
[0087] The storage module 501 is used to store the access request that meets the cache condition after intercepting the access request;
[0088] The state module 502 is used to insert the original class of the access request during class loading to obtain the inserted class to record the calling state of the access request;
[0089] The identification module 503 is used to determine the code coverage in the application according to the calling state, so as to identify the redundant code in the application according to the code coverage.
[0090] In one embodiment of the present invention, the storage module 501 is specifically used to intercept the access request according to the chain of responsibility model;
[0091] A blocking queue of the access request is established based on the cache condition, and the access request in the blocking queue is stored.
[0092] In one embodiment of the present invention, the blocking queue comprises a linked list blocking queue.
[0093] In one embodiment of the present invention, the storage module 501 is specifically configured to asynchronously store the access request that meets the cache condition when processing the sending request.
[0094] In one embodiment of the present invention, the class loading includes class loading when the access request is running;
[0095] The state module 502 is specifically used to insert a stub into the original class of the access request, and obtain the inserted class after changing the bytecode structure, so as to record the calling state of the access request.
[0096] In one embodiment of the present invention, the class loading includes class loading at the time of access request compilation;
[0097] The state module 502 is specifically used for the logic instruction of the operation source code of the access request to include an unconditional jump instruction or a termination instruction, and before the unconditional jump instruction or the termination instruction, the original class of the access request is plugged;
[0098] The logic instructions of the operation source code of the access request include a conditional jump instruction. After the conditional jump instruction, the original class of the access request is plugged.
[0099] In one embodiment of the present invention, the identification module 503 is specifically used to identify redundant codes of methods in the class of the application according to the code coverage rate during the process of reconstructing a code project or optimizing a code.
[0100] Figure 6 An exemplary system architecture 600 is shown to which the method for identifying redundant codes or the apparatus for identifying redundant codes according to the embodiments of the present invention can be applied.
[0101] like Figure 6 As shown, system architecture 600 may include terminal devices 601, 602, 603, network 604 and server 605. Network 604 is used to provide a medium for communication links between terminal devices 601, 602, 603 and server 605. Network 604 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0102] Users can use terminal devices 601, 602, and 603 to interact with server 605 through network 604 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 601, 602, and 603, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only examples).
[0103] The terminal devices 601 , 602 , and 603 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, etc.
[0104] The server 605 may be a server that provides various services, such as a backend management server (only an example) that provides support for shopping websites browsed by users using the terminal devices 601, 602, and 603. The backend management server may analyze and process the received data such as product information query requests, and feed back the processing results (such as target push information, product information - only an example) to the terminal device.
[0105] It should be noted that the method for identifying redundant codes provided in the embodiment of the present invention is generally executed by the server 605 , and accordingly, the device for identifying redundant codes is generally disposed in the server 605 .
[0106] It should be understood that Figure 6 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.
[0107] Reference below Figure 7 , which shows a schematic diagram of the structure of a computer system 700 of a terminal device suitable for implementing an embodiment of the present invention. Figure 7 The terminal device 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.
[0108] like Figure 7 As shown, the computer system 700 includes a central processing unit (CPU) 701, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 702 or a program loaded from a storage part 708 into a random access memory (RAM) 703. In the RAM 703, various programs and data required for the operation of the system 700 are also stored. The CPU 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.
[0109] The following components are connected to the I / O interface 705: an input section 706 including a keyboard, a mouse, etc.; an output section 707 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 708 including a hard disk, etc.; and a communication section 709 including a network interface card such as a LAN card, a modem, etc. The communication section 709 performs communication processing via a network such as the Internet. A drive 710 is also connected to the I / O interface 705 as needed. A removable medium 711, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 710 as needed, so that a computer program read therefrom is installed into the storage section 708 as needed.
[0110] 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 709, and / or installed from the removable medium 711. When the computer program is executed by the central processing unit (CPU) 701, the above-mentioned functions defined in the system of the present invention are executed.
[0111] 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.
[0112] 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.
[0113] The modules involved in the embodiments of the present invention may be implemented in software or hardware. The modules described may also be set in a processor, for example, it may be described as: a processor includes a storage module, a state module and an identification module. The names of these modules do not constitute a limitation on the modules themselves in some cases, for example, the storage module may also be described as "used to intercept access requests and store the access requests that meet the cache conditions".
[0114] As another aspect, the present invention further provides a computer-readable medium, which may be included in the device described in the above embodiment; or 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:
[0115] After intercepting the access request, storing the access request that meets the cache condition;
[0116] During class loading, the original class of the access request is instrumented to obtain an instrumented class to record the calling status of the access request;
[0117] The code coverage rate in the application is determined according to the calling status, so as to identify redundant codes in the application according to the code coverage rate.
[0118] According to the technical solution of the embodiment of the present invention, after intercepting the access request, the access request that meets the cache conditions is stored; when the class is loaded, the original class of the access request is instrumented to obtain the instrumented class to record the call status of the access request; the code coverage in the application is determined according to the call status to identify the redundant code in the application according to the code coverage. Storing the access request and then identifying the redundant code can, on the one hand, reduce the impact on the normal processing of the access request; on the other hand, timely identifying the redundant code in the application can improve the stability and high availability of the business system, thereby improving the guarantee of normal access to the application.
[0119] The above specific implementation methods do not constitute limitations on the scope of protection of the present invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the scope of protection of the present invention. It should be noted that in the technical solution disclosed in this disclosure, the acquisition, storage and application of user personal information involved are in compliance with the provisions of relevant laws and regulations and do not violate public order and good morals.
Claims
1. A method for identifying redundant codes, It is characterized in that include: After intercepting the access request, storing the access request that meets the cache condition; During class loading, the original class of the access request is instrumented to obtain an instrumented class to record the calling status of the access request; The code coverage rate in the application is determined according to the calling status, so as to identify redundant codes in the application according to the code coverage rate.
2. The method for identifying redundant codes according to claim 1, It is characterized in that After intercepting the access request, storing the access request that meets the cache condition includes: According to the chain of responsibility model, intercept the access request; A blocking queue of the access request is established based on the cache condition, and the access request in the blocking queue is stored.
3. The method for identifying redundant codes according to claim 2, It is characterized in that The blocking queue includes a linked list blocking queue.
4. The method for identifying redundant codes according to claim 1, It is characterized in that The storing the access request that meets the cache condition includes: When processing the sending request, the access request that meets the cache condition is asynchronously stored.
5. The method for identifying redundant codes according to claim 1, It is characterized in that The class loading includes class loading when the access request is running; The inserting the original class of the access request to obtain the inserted class to record the calling status of the access request includes: The original class of the access request is instrumented, and the bytecode structure is changed to obtain the instrumented class to record the calling status of the access request.
6. The method for identifying redundant codes according to claim 1, It is characterized in that The class loading includes class loading during access request compilation; The instrumenting the original class of the access request includes: The logic instructions of the operation source code of the access request include an unconditional jump instruction or a termination instruction, and before the unconditional jump instruction or the termination instruction, the original class of the access request is plugged; The logic instructions of the operation source code of the access request include a conditional jump instruction. After the conditional jump instruction, the original class of the access request is plugged.
7. The method for identifying redundant codes according to claim 1, It is characterized in that The identifying redundant code in the application according to the code coverage includes: In the process of refactoring a code project or optimizing a code, redundant codes of methods in the class of the application are identified according to the code coverage.
8. A device for identifying redundant codes, It is characterized in that include: A storage module, used for storing the access requests that meet the cache conditions after intercepting the access requests; A status module, used to insert a stub into the original class of the access request when the class is loaded, and obtain the inserted class to record the calling status of the access request; The identification module is used to determine the code coverage rate in the application according to the calling state, so as to identify the redundant code in the application according to the code coverage rate.
9. An electronic device for identifying redundant codes, It is 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, It is characterized in that When the program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
