CN116166547A - Code change range analysis method, device, equipment and storage medium - Google Patents

Code change range analysis method, device, equipment and storage medium Download PDF

Info

Publication number
CN116166547A
CN116166547A CN202310109832.6A CN202310109832A CN116166547A CN 116166547 A CN116166547 A CN 116166547A CN 202310109832 A CN202310109832 A CN 202310109832A CN 116166547 A CN116166547 A CN 116166547A
Authority
CN
China
Prior art keywords
code
call
calling
name
stack
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310109832.6A
Other languages
Chinese (zh)
Inventor
乔迟
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
CCB Finetech Co Ltd
Original Assignee
CCB Finetech Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by CCB Finetech Co Ltd filed Critical CCB Finetech Co Ltd
Priority to CN202310109832.6A priority Critical patent/CN116166547A/en
Publication of CN116166547A publication Critical patent/CN116166547A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3604Software analysis for verifying properties of programs
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

The disclosure provides a code change range analysis method, a device, equipment and a storage medium, which can be applied to the fields of computer technology and financial science and technology. The method comprises the following steps: in the process of code operation, storing the method name of the called method into a preset stack variable based on the calling sequence; sequentially popping up the method names of the methods from the stack variable according to the order of call ending, and forming a call branch by taking the method names as nodes; merging the same nodes in each call branch to form a tree call structure; when the code is changed, a call branch of a changed method is acquired from the tree call structure, and a code change range is obtained. The method can be realized through a byte code editing technology, the method is not invasive to the original code, the collection of a code logic call chain can be realized under the condition of not modifying the production code, the analysis of the reflection call relation can be realized, and the influence range of code change can be more completely analyzed.

Description

Code change range analysis method, device, equipment and storage medium
Technical Field
The present disclosure relates to the field of computer technology and financial science and technology, and in particular, to a method, apparatus, device, and storage medium for analyzing a code change range.
Background
Along with the development of the modern software technology towards the large and complicated directions, along with the high-rhythm business iteration requirement, the normal operation of the existing business functions is not affected while the existing codes are modified to realize the new function delivery, so that the basic requirement for the evolution of an application software system is met. However, due to the complexity of the software coding process, it is difficult to make a perfect face-to-face when code changes are made. Modern application systems tend to be large in scale, and performing a system-level comprehensive test on code changes generated by a single iteration tends to require significant labor and time costs. Therefore, how to accurately identify the influence range of the changed code and accurately position the test range, so that the improvement of the test accuracy and the reduction of the test cost become important.
The existing main mode for realizing the analysis of the influence of the changed codes is that firstly, static code analysis is carried out on the existing codes to form a tree-shaped hierarchical calling relation structure; then comparing the codes, and comparing the difference between the codes before and after the change; and finally, extracting a function calling range from the difference code, and substituting the function calling range into the hierarchical calling relation structure formed in the first step to obtain a final change influence range.
The main disadvantage of the above analysis of the influence of the change code is that the static code analysis tool on which the method depends can only extract the calling relation of normal method call, but has no ability to reflect call widely used in modern Java application programs. Therefore, when the call relation analysis is performed on the existing application system, the reflection call relation cannot be identified, so that a large deviation exists between the identification of the influence range and the actual influence range.
Disclosure of Invention
In view of the foregoing, the present disclosure provides a code change range analysis method, apparatus, device, and medium.
According to a first aspect of the present disclosure, there is provided a code change range analysis method including: in the code running process, obtaining the method name of each method, and sequentially storing the method names into preset stack variables based on the calling sequence; when the calling of each method is finished, sequentially popping up the method names of each method from the stack variable according to the sequence of the call finishing to form a calling branch, wherein the node of the calling branch is the method name, and the forming sequence of the branch is consistent with the popping sequence of the method names; traversing all methods in the code, generating a plurality of calling branches, and merging the same nodes in each calling branch to form a tree-like calling structure; when the code is changed, a call branch of a changed method is acquired from the tree call structure, and a code change range is obtained.
According to an embodiment of the present disclosure, the method comprises: inserting piles at the request access point of the code, and setting a ThreadLocal variable initialization logic for initializing the stack variable when the code is initialized; and storing the method name of the request access point into the stack variable, wherein the method name of the request access point is the root node of the tree-like calling structure.
According to an embodiment of the disclosure, the obtaining the method name of each method, and sequentially storing the method names into a preset stack variable based on the calling sequence includes: when the method is called, the method name of the method is obtained, and the method name of the method is stored in the stack variable; and when the method calls other methods in the execution process, repeating the previous step according to the calling sequence, and storing the method name of each method into the stack variable.
According to an embodiment of the present disclosure, the method comprises: setting a method name acquisition code at an entry of the method based on a byte code editing technology, wherein the method name acquisition code is used for reading a byte code file of the method when the method is called, and acquiring the method name of the method.
According to an embodiment of the present disclosure, when the calling of each method is finished, sequentially popping the method names of each method from the stack variable according to the order of the call finishing, and forming a call branch includes: obtaining a method name of a current execution method, and comparing the method name of the method with a method name of the stack top of the stack variable; when the method name of the method is different from the method name of the stack top, the method name of the stack top is popped up after the execution of the method corresponding to the method name of the stack top is finished; repeatedly comparing the method name of the method with the method name of the stack top of the stack variable until the method name of the method is the same as the method name of the stack top; and sequentially adding nodes based on the pop-up sequence of the method names at the stack top to form the calling branch.
According to an embodiment of the present disclosure, the method further comprises: when the method name of the method is different from the method name of the stack top, the calling relationship represented by the method name of the method and the method name of the stack top is stored in a lasting mode; and generating the call branch based on the call relation of the newly added node and the persistent storage.
According to an embodiment of the present disclosure, when the code is changed, obtaining a call branch of a method related to the change from the tree call structure, and obtaining a code change range includes: when the code is changed, all methods related to the change are obtained through a code comparison tool; traversing the method names of the methods related to the change in the tree call structure, and screening call branches and sub-branches of the call branches comprising the method names of the methods related to the change; and acquiring codes of corresponding methods based on the method names included in the calling branch and the sub-branches thereof, and obtaining the code change range.
According to an embodiment of the present disclosure, the method includes a method of generating, invoking or constructing an object based on a reflection mechanism.
A second aspect of the present disclosure provides a code change range analysis apparatus including: the method stack pressing module is used for acquiring the method name of each method in the code running process and sequentially storing the method names into preset stack variables based on the calling sequence; the calling branch forming module is used for sequentially popping out the method names of the methods from the stack variables according to the sequence of ending the calling when each method is called to be ended, so as to form a calling branch, wherein the node of the calling branch is the method name, and the branching sequence is consistent with the popping sequence of the method names; the tree-like calling structure forming module is used for traversing all the methods in the codes, generating a plurality of calling branches, and merging the same nodes in each calling branch to form a tree-like calling structure; and the code change range analysis module is used for acquiring call branches of the changed method from the tree call structure when the code is changed, so as to obtain the code change range.
A third aspect of the present disclosure provides an electronic device, comprising: one or more processors; and a memory for storing one or more programs, wherein the one or more programs, when executed by the one or more processors, cause the one or more processors to perform the method described above.
A fourth aspect of the present disclosure also provides a computer-readable storage medium having stored thereon executable instructions that, when executed by a processor, cause the processor to perform the above-described method.
According to the code change range analysis method, the device, the equipment and the medium, the method names which are called are collected in the code running process, a tree-like calling structure is generated based on the actual calling relation of the method, and when the method is changed, the code change range is determined based on the tree-like calling structure. Because the method generates the tree-like calling structure in the process of calling the method, the method based on the reflection mechanism can be recorded, therefore, the method calling relation based on the reflection mechanism can be accurately obtained, and the code changing range can be accurately identified based on the tree-like calling structure when the code is changed. The method can be realized by adopting the existing byte code editing technology, and can realize the collection of the code logic call chain under the condition of not modifying the production code by adopting a non-invasive mode.
Drawings
The foregoing and other objects, features and advantages of the disclosure will be more apparent from the following description of embodiments of the disclosure with reference to the accompanying drawings, in which:
FIG. 1 schematically illustrates an application scenario diagram of a code change range analysis method, apparatus, device, and storage medium according to an embodiment of the present disclosure;
FIG. 2 schematically illustrates a flow chart of a code change range analysis method according to an embodiment of the disclosure;
FIG. 3 schematically illustrates a method name push diagram according to an embodiment of the present disclosure;
FIG. 4 schematically illustrates a method bullet stack diagram according to an embodiment of the present disclosure;
FIG. 5 schematically illustrates a tree call structure diagram according to an embodiment of the present disclosure;
FIG. 6 schematically shows a block diagram of a code change range analysis apparatus according to an embodiment of the present disclosure; and
fig. 7 schematically illustrates a block diagram of an electronic device adapted to implement a code change range analysis method according to an embodiment of the disclosure.
Detailed Description
Hereinafter, embodiments of the present disclosure will be described with reference to the accompanying drawings. It should be understood that the description is only exemplary and is not intended to limit the scope of the present disclosure. In the following detailed description, for purposes of explanation, numerous specific details are set forth in order to provide a thorough understanding of the embodiments of the present disclosure. It may be evident, however, that one or more embodiments may be practiced without these specific details. In addition, in the following description, descriptions of well-known structures and techniques are omitted so as not to unnecessarily obscure the concepts of the present disclosure.
The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the disclosure. The terms "comprises," "comprising," and/or the like, as used herein, specify the presence of stated features, steps, operations, and/or components, but do not preclude the presence or addition of one or more other features, steps, operations, or components.
All terms (including technical and scientific terms) used herein have the same meaning as commonly understood by one of ordinary skill in the art unless otherwise defined. It should be noted that the terms used herein should be construed to have meanings consistent with the context of the present specification and should not be construed in an idealized or overly formal manner.
Where expressions like at least one of "A, B and C, etc. are used, the expressions should generally be interpreted in accordance with the meaning as commonly understood by those skilled in the art (e.g.," a system having at least one of A, B and C "shall include, but not be limited to, a system having a alone, B alone, C alone, a and B together, a and C together, B and C together, and/or A, B, C together, etc.).
In the technical scheme of the disclosure, the related data (such as including but not limited to personal information of a user) are collected, stored, used, processed, transmitted, provided, disclosed, applied and the like, all conform to the regulations of related laws and regulations, necessary security measures are adopted, and the public welcome is not violated.
Description of technical terms:
the Java reflection mechanism is used for constructing an object of any one class in the running state of a program, knowing the class to which any one object belongs, knowing the member variable and method of any one class and calling the attribute and method of any one object. The function of dynamically acquiring program information and dynamically calling an object is called as a Java language reflection mechanism;
thread local is a JDK provided thread local variable access class, which is used for realizing that independent local variables for a single thread are stored in access, and the variables are different from other normal variables in that each thread accessing the variable has an independent initialized variable copy inside;
JAVA bytecode is an instruction format executed by a JAVA virtual machine. The JAVA language is different from other compiling execution languages, after the programming is completed, the JAVA language is not directly compiled into binary codes executed in a target environment, but is compiled into a byte code file in an intermediate format, and the byte code file is loaded into a JAVA virtual machine for execution;
and editing the byte codes, namely editing and modifying the byte code class files loaded into the JAVA virtual machine to generate brand-new byte code instructions, so that the function enhancement effect is achieved. Such techniques include CGLIB, javaAssist, byteBuddy and the like;
The byte code is dynamically modified, after JDK1.6, JAVA language provides an Instrument class library, so that an developer can dynamically modify the byte code during operation. Prior to JDK1.6, instrument can only take effect when the JVM just started to load a class, whereas after JDK1.6, instrument supports modification of class definition at runtime.
The embodiment of the disclosure provides a code change range analysis method, which comprises the following steps: in the code running process, obtaining the method name of each method, and sequentially storing the method names into preset stack variables based on the calling sequence; when the calling of each method is finished, sequentially popping up the method names of each method from the stack variable according to the sequence of the call finishing to form a calling branch, wherein the node of the calling branch is the method name, and the forming sequence of the branch is consistent with the popping sequence of the method names; traversing all methods in the code, generating a plurality of calling branches, and merging the same nodes in each calling branch to form a tree-like calling structure; when the code is changed, a call branch of a changed method is acquired from the tree call structure, and a code change range is obtained.
Fig. 1 schematically illustrates an application scenario diagram of a code change range analysis method, and apparatus according to an embodiment of the present disclosure.
As shown in fig. 1, the application scenario 100 according to this embodiment may include a code programming scenario of the financial industry. The network 104 is a medium used to provide a communication link between the first terminal device 101, the second terminal device 102, the third terminal device 103, and the server 105. The network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, among others.
The user may interact with the server 105 through the network 104 using at least one of the first terminal device 101, the second terminal device 102, the third terminal device 103, to receive or send messages, etc. Various communication client applications, such as a shopping class application, a web browser application, a search class application, an instant messaging tool, a mailbox client, social platform software, etc. (by way of example only) may be installed on the first terminal device 101, the second terminal device 102, and the third terminal device 103.
The first terminal device 101, the second terminal device 102, the third terminal device 103 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smartphones, tablets, laptop and desktop computers, and the like.
The server 105 may be a server providing various services, such as a background management server (by way of example only) providing support for websites browsed by the user using the first terminal device 101, the second terminal device 102, and the third terminal device 103. The background management server may analyze and process the received data such as the user request, and feed back the processing result (e.g., the web page, information, or data obtained or generated according to the user request) to the terminal device.
It should be noted that the code change range analysis method provided by the embodiments of the present disclosure may be generally performed by the server 105. Accordingly, the code change range analysis apparatus provided by the embodiments of the present disclosure may be generally provided in the server 105. The code change range analysis method provided by the embodiments of the present disclosure may also be performed by a server or a server cluster that is different from the server 105 and is capable of communicating with the first terminal device 101, the second terminal device 102, the third terminal device 103, and/or the server 105. Accordingly, the code change range analysis apparatus provided by the embodiments of the present disclosure may also be provided in a server or a server cluster that is different from the server 105 and is capable of communicating with the first terminal device 101, the second terminal device 102, the third terminal device 103, and/or the server 105.
It should be understood that the number of terminal devices, networks and servers in fig. 1 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
The code change range analysis method of the disclosed embodiment will be described in detail below with reference to fig. 2 to 6 based on the scenario described in fig. 1.
Fig. 2 schematically illustrates a flow chart of a code change range analysis method according to an embodiment of the present disclosure.
As shown in fig. 2, the code change range analysis method of this embodiment includes operations S210 to S240.
In operation S210, in the process of code running, a method name of each method is acquired, and the method names are sequentially stored in a preset stack variable based on a calling sequence.
When the method call ends, the method names of the methods are sequentially popped from the stack variable according to the order of the call end to form a call branch, wherein the node of the call branch is the method name, and the forming order of the branch is consistent with the popping order of the method names in operation S220.
In operation S230, all methods in the code are traversed, multiple call branches are generated, and identical nodes in the call branches are combined to form a tree call structure.
In operation S240, when the code is changed, a call branch of the method related to the change is acquired from the tree call structure, and a code change range is obtained.
According to the method provided by the embodiment of the disclosure, the names of the called methods are captured in sequence according to the call in the code running process, so that the reflection call relation except the static call can be obtained; storing the method names into a stack according to the calling relation, when the method call is finished and the result is returned, popping the method names from the stack, and generating a calling branch based on the calling relation; and then a complete tree call structure can be formed.
In this embodiment, the method in the code includes a method of generating, calling, or constructing an object based on the reflection mechanism, in addition to the normal method in which the call relationship exists. Because the method provided by the embodiment of the disclosure can record the sequence of the method actually called by the code, the execution substitution of the method for the object generated or called based on the reflection mechanism can be recorded faithfully, namely, the tree-like call structure generated based on the method not only comprises the static call relationship, but also comprises the call relationship based on the reflection mechanism, and the defect of the traditional static code analysis on the reflection call logic is solved, so that a more accurate call relationship tree-like structure is obtained. On the basis of obtaining the tree call structure, the tree call structure is applied to code change, so that the change influence range can be more completely analyzed.
The code change range analysis method provided in the embodiment of the present disclosure will be described in detail with reference to fig. 3 to 5.
In an embodiment of the present disclosure, before performing the method, the method includes: inserting piles at the request access point of the codes, adding a Threadlocal variable initialization logic, initializing to generate a Stack variable, obtaining the name information of the current method through a Throwable API, and pushing the name information into the Stack variable. Code that initializes stack variables such as:
StackTraceElement [ ] stacktrace=new threadable (). GetStackTrace (); string methodName = stackTrace [0]. GetmethodName (). The thread local is a thread local variable access class and is used for realizing that independent local variables of a single thread are stored in access, and each thread accessing the variable has an independent initialized variable copy in the thread, so that the conflict of method name records generated during the multithreading execution method can be avoided.
In this embodiment, for a request access point of a code, a method name of the request access point may be stored in the stack variable. Because the method in the code block is actually the method called inside the request access point, the method name of the request access point is stored in the stack variable, and the method name of the request access point is called as the root node of the tree call structure. The stack variable in the global range can be used for storing and acquiring all methods in the request access point, is convenient for acquiring the calling relation based on the storage sequence of the method names, and generates a complete tree-like calling structure.
According to operation S210, a method name of each method is obtained, and the method names are sequentially stored in a preset stack variable based on a calling sequence, which may specifically include operations S211 to S212.
In operation S211, a method name of the method is acquired when the method is called and stored in the stack variable.
In the embodiment of the disclosure, before the code is run, a method name acquisition code is set at an entry of the method based on a byte code editing technology, and the method name acquisition code is used for reading a byte code file of the method when the method is called and acquiring the method name of the method. After the method name is obtained, it is pushed into the Stack Stack variable in ThreadLocal. The method name is acquired based on the byte code editing technology, excessive coding is not needed by a developer, and the complexity is low.
In operation S212, when the method calls other methods during execution, repeating the previous step according to the calling sequence, and storing the method name of each method into the stack variable.
The method can be used for identifying the static call relationship among the existing methods and identifying the call relationship based on the reflection mechanism. When the method is called, the operation S211 is repeatedly executed, and the method name of the method in the calling logic is pushed to the stack variable, and the actual storage sequence in the stack variable is the calling sequence of the calling logic, so that the subsequent generation of the calling branch is facilitated.
Because the method provided by the embodiment of the disclosure can record the sequence of the method actually called by the code, the execution substitution of the method for the object generated or called based on the reflection mechanism can be recorded faithfully, namely, the tree-like call structure generated based on the method not only comprises the static call relationship, but also comprises the call relationship based on the reflection mechanism, and the defect of the traditional static code analysis on the reflection call logic is solved, so that a more accurate call relationship tree-like structure is obtained.
Fig. 3 schematically illustrates a method name push diagram according to an embodiment of the present disclosure.
As shown in fig. 3, in one call logic, method a calls method B, method B calls method C, and method C calls method D. According to operation S210, when each method is called, the method name of each method is obtained based on the method name acquisition code at each method entry, and according to the calling sequence, the method names of method a are stored in the stack variable, and according to the calling, the method names of method B, method C, and method D are sequentially stored in the stack variable.
According to operation S220, when the method calls are finished, the method names of the methods are sequentially popped from the stack variable according to the order of the call finishing, so as to form a call branch, which may specifically include operations S221 to S224.
In operation S221, a method name of the currently executed method is acquired, and the method name of the method and a method name of the stack top of the stack variable are compared.
In operation S222, when the method name of the method is different from the method name of the stack top, the method name of the stack top is popped up after the execution of the method corresponding to the method name of the stack top is completed.
When the method name of the method is different from the method name of the stack top, the calling relation represented by the method name of the method and the method name of the stack top is stored in a lasting mode, and the static calling relation and the reflection calling relation are stored, so that a tree-shaped calling structure can be generated conveniently.
In operation S223, comparing the method name of the method with the method name of the stack top of the stack variable is repeated until the method name of the method is the same as the method name of the stack top.
In operation S224, nodes are sequentially added based on the pop-up sequence of the method names at the stack top, so as to form the call branch. Specifically, in order to make the order of the call branches correct, the call branches are generated based on the call relationship between the newly added node and the persistent storage. According to the method, if the method name of the current method is different from the method name of the stack top, it indicates that the current method calls the method of the stack top, for example, the method A calls the method B, the current method is the method A, if the method B is currently executing, the method name of the method B is stored at the stack top, and if the method name of the stack top is different from the current method A, the execution of the method called by the method needs to be waited for to finish. In the case that the method called by the current method also calls other methods, the other methods need to wait for the execution of the other methods. When the method of the stack top is executed, the method name of the stack top is popped up, and the node at the bottom layer is popped up. And sequentially popping up the method names at the stack top, adding the method names to the position above the node of the calling branch, and finally forming the calling branch.
Fig. 4 schematically illustrates a method bullet stack diagram according to an embodiment of the present disclosure.
As shown in fig. 4, in the process of executing method a, method B, method C, and method D are sequentially called, and A, B, C and D are sequentially pushed onto the stack, where a is at the bottom of the stack and D is at the top of the stack. When the method D calls and returns, the method name of the method D is popped up from the stack top of the stack variable; when the method C returns, popping up the method name of the method C from the stack top of the stack variable; when the method B returns, popping up the method name of the method B from the stack top of the stack variable; when method A returns, pop the method name of method A from the top of stack of the stack variable. D is the child node of the bottommost layer; the method C calls the method D, and in the call branch, C is the father node of D; the method B calls a method C, and B is a father node of C in a call branch memory; method A calls method B, in the call branch, A is the parent node of B. Finally, call branches D-C-B-A from bottom to top are formed.
According to operation S230, the method provided by the embodiment of the present disclosure is executed multiple times during the code running process, and after all call branches are obtained, the call branches are combined, so as to obtain a tree call structure.
Fig. 5 schematically illustrates a tree call structure diagram according to an embodiment of the present disclosure.
As shown in fig. 5, assume that the final scan results in three call branches: A-B-C-D, A-B-C-E, A-F. The calling branches A-B-C-D are identical to the nodes A, B and C in the calling branches A-B-C-E, and the nodes A, B and C of the two calling branches are combined, wherein the node C comprises a child node D and a child node E. And continuing to combine the combined branches with the call branches A-F, wherein the node A comprises a child node B and a child node F, so that a tree call structure is formed.
According to operation S240, when the code is changed, a call branch of the method related to the change is acquired from the tree call structure, and the code change range is obtained to include S241 to S243.
In operation S241, when the code is changed, all methods related to the change are obtained by the code comparison tool.
In operation S242, the method names of the methods related to the modification in the tree call structure are traversed, and call branches including the method names of the methods related to the modification and sub-branches thereof are screened out.
In operation S243, the code of the corresponding method is obtained based on the method names included in the call branch and the sub-branches thereof, and the code change range is obtained.
According to the method provided by the embodiment of the disclosure, all call relations including static call and reflection call of the code to be obtained, the code range of the call branch influenced by the method is identified based on the tree call structure, and the condition that some code areas with the reflection call relations and influenced by the code change are ignored can be avoided, so that a complete code change range is obtained.
According to the code change range analysis method provided by the embodiment of the disclosure, the method names are obtained by inserting the piles based on the byte coding technology, the collection of the code logic call chains can be realized under the condition that the production codes are not modified, the method with the reflection call relationship can be prevented from being ignored during code change, and technicians can be helped to accurately position the test range, so that the test accuracy is improved, and the test cost is reduced.
Based on the code change range analysis method, the disclosure also provides a code change range analysis device. The device will be described in detail below in connection with fig. 6.
Fig. 6 schematically shows a block diagram of a code change range analysis apparatus according to an embodiment of the present disclosure.
As shown in fig. 6, the code change range analysis device 600 of this embodiment includes a method push module 610, a call branch formation module 620, a tree call structure formation module 630, and a code change range analysis module 640.
The method stacking module 610 is configured to obtain a method name of each method during the code running process, and store the method names in a preset stack variable sequentially based on a calling sequence. In an embodiment, the method push module 610 may be used to perform the operation S210 described above, which is not described herein.
And the call branch forming module 620 is configured to sequentially pop up the method names of the methods from the stack variables according to the order of call ending when each method call ends, so as to form a call branch, where the node of the call branch is the method name, and the branching order is consistent with the pop-up order of the method names. In an embodiment, the call branch forming module 620 may be used to perform the operation S220 described above, which is not described herein.
The tree call structure forming module 630 is configured to traverse all methods in the code, generate multiple call branches, and combine the same nodes in each call branch to form a tree call structure. In an embodiment, the tree call structure forming module 630 may be used to perform the operation S230 described above, which is not described herein.
The code change range analysis module 640 is configured to obtain, when a code is changed, a call branch of a method related to the change from the tree call structure, and obtain a code change range.
According to an embodiment of the present disclosure, the method push module 610 includes a method name push unit and a method call unit.
The method name pressing stack unit is used for acquiring the method name of the method when the method is called and storing the method name of the method into the stack variable.
And the method calling unit is used for repeating the previous step according to the calling sequence when the method calls other methods in the execution process, and storing the method name of each method into the stack variable.
According to an embodiment of the present disclosure, the code change range analysis device 600 further includes a stack variable initializing unit.
The stack variable initializing unit is used for setting a method name acquisition code at an entry of the method based on a byte code editing technology, wherein the method name acquisition code is used for reading a byte code file of the method when the method is called, and acquiring the method name of the method.
According to an embodiment of the present disclosure, the call branching formation module 620 includes: the device comprises a method name acquisition unit, a bullet stack unit, a repeated comparison unit and a branch forming unit.
The method name acquisition unit is used for acquiring the method name of the current execution method and comparing the method name of the method with the method name of the stack top of the stack variable.
And the pop-up unit is used for popping up the method name of the stack top after the execution of the method corresponding to the method name of the stack top is finished when the method name of the method is different from the method name of the stack top.
And the repeated comparison unit is used for repeatedly comparing the method name of the method with the method name of the stack top of the stack variable until the method name of the method is the same as the method name of the stack top.
And the branch forming unit is used for sequentially adding nodes based on the pop-up sequence of the method names at the stack top to form the calling branch.
According to an embodiment of the present disclosure, the code change range analysis device 600 further includes a method name storage unit. And the method name storage unit is used for storing the calling relation represented by the method name of the method and the method name of the stack top in a lasting way when the method name of the method is different from the method name of the stack top. And the branch forming unit is used for generating the call branch based on the call relation of the newly added node and the persistent storage.
According to an embodiment of the present disclosure, the code change range analysis module 640 includes: the device comprises a change comparison unit, a structure traversing unit and a range determining unit.
When the code is changed by the change comparison unit, all methods related to the change are obtained through the code comparison tool.
The structure traversing unit is used for traversing the method names of the methods related to the change in the tree call structure, and screening call branches and sub-branches of the call branches comprising the method names of the methods related to the change.
And the range determining unit is used for acquiring codes of the corresponding methods based on the method names included in the calling branch and the sub-branches thereof, and obtaining the code change range.
Any of the method push module 610, the call branch formation module 620, the tree call structure formation module 630, and the code change range analysis module 640 may be combined in one module to be implemented, or any of the modules may be split into a plurality of modules, according to an embodiment of the present disclosure. Alternatively, at least some of the functionality of one or more of the modules may be combined with at least some of the functionality of other modules and implemented in one module. At least one of the method push module 610, the call branching formation module 620, the tree call structure formation module 630, and the code change range analysis module 640 may be implemented, at least in part, as hardware circuitry, such as a Field Programmable Gate Array (FPGA), a Programmable Logic Array (PLA), a system on a chip, a system on a substrate, a system on a package, an Application Specific Integrated Circuit (ASIC), or as hardware or firmware in any other reasonable manner of integrating or packaging the circuitry, or as any one of or a suitable combination of any of the three. Alternatively, at least one of the method push module 610, the call branching formation module 620, the tree call structure formation module 630, and the code change range analysis module 640 may be at least partially implemented as a computer program module, which when executed, may perform the corresponding functions.
Fig. 7 schematically illustrates a block diagram of an electronic device adapted to implement a code change range analysis method according to an embodiment of the disclosure.
As shown in fig. 7, an electronic device 700 according to an embodiment of the present disclosure includes a processor 701 that 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 section 708 into a Random Access Memory (RAM) 703. The processor 701 may include, for example, a general purpose microprocessor (e.g., a CPU), an instruction set processor and/or an associated chipset and/or a special purpose microprocessor (e.g., an Application Specific Integrated Circuit (ASIC)), or the like. The processor 701 may also include on-board memory for caching purposes. The processor 701 may comprise a single processing unit or a plurality of processing units for performing different actions of the method flows according to embodiments of the disclosure.
In the RAM 703, various programs and data necessary for the operation of the electronic apparatus 700 are stored. The processor 701, the ROM 702, and the RAM 703 are connected to each other through a bus 704. The processor 701 performs various operations of the method flow according to the embodiments of the present disclosure by executing programs in the ROM 702 and/or the RAM 703. Note that the program may be stored in one or more memories other than the ROM 702 and the RAM 703. The processor 701 may also perform various operations of the method flow according to embodiments of the present disclosure by executing programs stored in the one or more memories.
According to an embodiment of the present disclosure, the electronic device 700 may further include an input/output (I/O) interface 705, the input/output (I/O) interface 705 also being connected to the bus 704. The electronic device 700 may also include one or more of the following components connected to the I/O interface 705: an input section 706 including a keyboard, a mouse, and the like; an output portion 707 including a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, a speaker, and the like; a storage section 708 including a hard disk or the like; and a communication section 709 including a network interface card such as a LAN card, a modem, or the like. The communication section 709 performs communication processing via a network such as the internet. The 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, or the like is mounted on the drive 710 as necessary, so that a computer program read therefrom is mounted into the storage section 708 as necessary.
The present disclosure also provides a computer-readable storage medium that may be embodied in the apparatus/device/system described in the above embodiments; or may exist alone without being assembled into the apparatus/device/system. The computer-readable storage medium carries one or more programs which, when executed, implement methods in accordance with embodiments of the present disclosure.
According to embodiments of the present disclosure, the computer-readable storage medium may be a non-volatile computer-readable storage medium, which may include, for example, but is not limited to: a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this disclosure, a computer-readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. For example, according to embodiments of the present disclosure, the computer-readable storage medium may include ROM 702 and/or RAM 703 and/or one or more memories other than ROM 702 and RAM 703 described above.
Embodiments of the present disclosure also include a computer program product comprising a computer program containing program code for performing the methods shown in the flowcharts. The program code, when executed in a computer system, causes the computer system to implement the item recommendation method provided by embodiments of the present disclosure.
The above-described functions defined in the system/apparatus of the embodiments of the present disclosure are performed when the computer program is executed by the processor 701. The systems, apparatus, modules, units, etc. described above may be implemented by computer program modules according to embodiments of the disclosure.
In one embodiment, the computer program may be based on a tangible storage medium such as an optical storage device, a magnetic storage device, or the like. In another embodiment, the computer program may also be transmitted, distributed over a network medium in the form of signals, downloaded and installed via the communication section 709, and/or installed from the removable medium 711. The computer program may include program code that may be transmitted using any appropriate network medium, including but not limited to: wireless, wired, etc., or any suitable combination of the foregoing.
In such an embodiment, the computer program may be downloaded and installed from a network via the communication portion 709, and/or installed from the removable medium 711. The above-described functions defined in the system of the embodiments of the present disclosure are performed when the computer program is executed by the processor 701. The systems, devices, apparatus, modules, units, etc. described above may be implemented by computer program modules according to embodiments of the disclosure.
According to embodiments of the present disclosure, program code for performing computer programs provided by embodiments of the present disclosure may be written in any combination of one or more programming languages, and in particular, such computer programs may be implemented in high-level procedural and/or object-oriented programming languages, and/or assembly/machine languages. Programming languages include, but are not limited to, such as Java, c++, python, "C" or similar programming languages. The program code may execute entirely on the user's computing device, partly on the user's device, partly on a remote computing device, or entirely on the remote computing device or server. In the case of remote computing devices, the remote computing device may be connected to the user computing device through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computing device (e.g., connected via the Internet using an Internet service provider).
The flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
Those skilled in the art will appreciate that the features recited in the various embodiments of the disclosure and/or in the claims may be provided in a variety of combinations and/or combinations, even if such combinations or combinations are not explicitly recited in the disclosure. In particular, the features recited in the various embodiments of the present disclosure and/or the claims may be variously combined and/or combined without departing from the spirit and teachings of the present disclosure. All such combinations and/or combinations fall within the scope of the present disclosure.
The embodiments of the present disclosure are described above. However, these examples are for illustrative purposes only and are not intended to limit the scope of the present disclosure. Although the embodiments are described above separately, this does not mean that the measures in the embodiments cannot be used advantageously in combination. The scope of the disclosure is defined by the appended claims and equivalents thereof. Various alternatives and modifications can be made by those skilled in the art without departing from the scope of the disclosure, and such alternatives and modifications are intended to fall within the scope of the disclosure.

Claims (11)

1. A code change range analysis method, comprising:
in the code running process, obtaining the method name of each method, and sequentially storing the method names into preset stack variables based on the calling sequence;
When the calling of each method is finished, sequentially popping up the method names of each method from the stack variable according to the sequence of the call finishing to form a calling branch, wherein the node of the calling branch is the method name, and the forming sequence of the branch is consistent with the popping sequence of the method names;
traversing all methods in the code, generating a plurality of calling branches, and merging the same nodes in each calling branch to form a tree-like calling structure;
when the code is changed, a call branch of a changed method is acquired from the tree call structure, and a code change range is obtained.
2. The code change range analysis method according to claim 1, characterized in that the method comprises:
inserting piles at the request access point of the code, and setting a ThreadLocal variable initialization logic for initializing the stack variable when the code is initialized;
and storing the method name of the request access point into the stack variable, wherein the method name of the request access point is the root node of the tree-like calling structure.
3. The code change range analysis method according to claim 1, wherein the obtaining the method name of each method and sequentially storing the method names in a preset stack variable based on a calling order comprises:
When the method is called, the method name of the method is obtained, and the method name of the method is stored in the stack variable;
and when the method calls other methods in the execution process, repeating the previous step according to the calling sequence, and storing the method name of each method into the stack variable.
4. A code variation range analysis method according to claim 3, characterized in that the method comprises:
setting a method name acquisition code at an entry of the method based on a byte code editing technology, wherein the method name acquisition code is used for reading a byte code file of the method when the method is called, and acquiring the method name of the method.
5. The code change range analysis method according to claim 1, wherein when each of the method calls ends, sequentially popping up the method names of each of the methods from the stack variable in order of call ends, forming a call branch includes:
obtaining a method name of a current execution method, and comparing the method name of the method with a method name of the stack top of the stack variable;
when the method name of the method is different from the method name of the stack top, the method name of the stack top is popped up after the execution of the method corresponding to the method name of the stack top is finished;
Repeatedly comparing the method name of the method with the method name of the stack top of the stack variable until the method name of the method is the same as the method name of the stack top;
and sequentially adding nodes based on the pop-up sequence of the method names at the stack top to form the calling branch.
6. The code change range analysis method according to claim 5, characterized in that the method further comprises:
when the method name of the method is different from the method name of the stack top, the calling relationship represented by the method name of the method and the method name of the stack top is stored in a lasting mode;
and generating the call branch based on the call relation of the newly added node and the persistent storage.
7. The code change range analysis method according to claim 1, wherein when the code is changed, acquiring call branches of the changed-related method from the tree call structure, and obtaining the code change range includes:
when the code is changed, all methods related to the change are obtained through a code comparison tool;
traversing the method names of the methods related to the change in the tree call structure, and screening call branches and sub-branches of the call branches comprising the method names of the methods related to the change;
And acquiring codes of corresponding methods based on the method names included in the calling branch and the sub-branches thereof, and obtaining the code change range.
8. The code range of variation analysis method of claim 1, wherein the method comprises a method of generating, invoking or constructing an object based on a reflection mechanism.
9. A code change range analysis device, comprising:
the method stack pressing module is used for acquiring the method name of each method in the code running process and sequentially storing the method names into preset stack variables based on the calling sequence;
the calling branch forming module is used for sequentially popping out the method names of the methods from the stack variables according to the sequence of ending the calling when each method is called to be ended, so as to form a calling branch, wherein the node of the calling branch is the method name, and the branching sequence is consistent with the popping sequence of the method names;
the tree-like calling structure forming module is used for traversing all the methods in the codes, generating a plurality of calling branches, and merging the same nodes in each calling branch to form a tree-like calling structure; and
and the code change range analysis module is used for acquiring call branches of the changed method from the tree call structure when the code is changed, so as to obtain the code change range.
10. An electronic device, comprising:
one or more processors;
storage means for storing one or more programs,
wherein the one or more programs, when executed by the one or more processors, cause the one or more processors to perform the method of any of claims 1-8.
11. A computer readable storage medium having stored thereon executable instructions which, when executed by a processor, cause the processor to perform the method according to any of claims 1-8.
CN202310109832.6A 2023-02-13 2023-02-13 Code change range analysis method, device, equipment and storage medium Pending CN116166547A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310109832.6A CN116166547A (en) 2023-02-13 2023-02-13 Code change range analysis method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310109832.6A CN116166547A (en) 2023-02-13 2023-02-13 Code change range analysis method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN116166547A true CN116166547A (en) 2023-05-26

Family

ID=86421489

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310109832.6A Pending CN116166547A (en) 2023-02-13 2023-02-13 Code change range analysis method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN116166547A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116483423A (en) * 2023-06-25 2023-07-25 杭州谐云科技有限公司 Incremental code scanning method and system based on genetic algorithm

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116483423A (en) * 2023-06-25 2023-07-25 杭州谐云科技有限公司 Incremental code scanning method and system based on genetic algorithm
CN116483423B (en) * 2023-06-25 2023-09-05 杭州谐云科技有限公司 Incremental code scanning method and system based on genetic algorithm

Similar Documents

Publication Publication Date Title
CN109992498B (en) Test case generation method and system and computer system
JP5989097B2 (en) Registration and execution of highly parallel processing tasks
CN111221521A (en) Method and device for generating log code, computer system and readable storage medium
JP7394211B2 (en) Methods, devices, equipment, and media for parallel execution of smart contracts
US11144840B2 (en) Completing decision logic to avoid a side effect
US9311111B2 (en) Programming environment with support for handle and non-handle user-created classes
US20210357206A1 (en) Modification of Codified Infrastructure for Orchestration in a Multi-Cloud Environment
CN116166547A (en) Code change range analysis method, device, equipment and storage medium
CN113535577B (en) Application testing method and device based on knowledge graph, electronic equipment and medium
US10459703B2 (en) Systems and methods for task parallelization
CN110795331A (en) Software testing method and device
US20210073018A1 (en) Enhanced virtual machine image management system
CN115080433A (en) Testing method and device based on flow playback
JP7111967B2 (en) Program verification program, program verification method and program verification device
CN113032256A (en) Automatic test method, device, computer system and readable storage medium
CN112068814A (en) Method, device, system and medium for generating executable file
CN113110947B (en) Program call chain generation method, system, electronic device and medium
CN116452208B (en) Method, device, equipment and medium for determining change transaction code
US11086829B2 (en) Comparing schema definitions using sampling
CN112799954B (en) Method, apparatus and computer readable medium for quickly constructing test environment
CN117370177A (en) Project document normalization checking method and device
CN116661857A (en) Data extraction method, device, equipment and storage medium
US20230229460A1 (en) Method and apparatus for identifying dynamically invoked computer code
CN114817036A (en) Decision tree testing method and device, electronic equipment and storage medium
CN116795867A (en) Data processing method, device, electronic equipment and medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination