Information processing apparatus, information processing method, and program

By updating source code to include annotations indicating object generation, the information processing apparatus generates a call graph that accurately reflects the execution behavior in application frameworks, addressing the challenge of inaccurate static analysis.

JP2024142692AActive Publication Date: 2024-10-11NS SOLUTIONS CORPORATION
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
JP2023054943
Authority / Receiving Office
JP · JP
Patent Type
Applications
Current Assignee / Owner
Filing Date
2023-03-30
Publication Date
2024-10-11
Estimated Expiration
2043-03-30

AI Technical Summary

Technical Problem

In programs created using application frameworks, dependencies between objects are not explicitly defined in the source code, making it difficult to perform accurate static analysis such as pointer analysis, leading to inaccurate call graphs.

Method used

An information processing apparatus updates the source code by adding annotations that indicate object generation, allowing for the generation of a call graph that aligns with the actual execution behavior by identifying dependencies through static analysis.

Benefits of technology

This approach enables the generation of a call graph that accurately reflects the actual execution behavior, overcoming the limitations of existing static analysis methods in application frameworks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure 2024142692000001_ABST
    Figure 2024142692000001_ABST
Patent Text Reader

Abstract

To generate a call graph of a source code which is to be statically analyzed, in a more favorable mode.SOLUTION: An information processing apparatus includes: acquisition means which acquires a series of source codes to be analyzed; extraction means which extracts a first source code including a first annotation indicating generation of an object, for update, out of the series of source codes; and update means which adds, for a field in which the first annotation is presented, in the first source code extracted for update, one of a first code and a second code, the first code directly indicating generation of an object corresponding to the field, and the second code indirectly indicating generation of the object, to update the first source code, and generates an execution code for calling a process specified in the updated first source code. A call graph is generated on the basis of the updated first source code and the execution code.SELECTED DRAWING: Figure 7
Need to check novelty before this filing date? Find Prior Art

Description

[Technical field]

[0001] The present disclosure relates to an information processing device, an information processing method, and a program. [Background technology]

[0002] In developing or maintaining a program, in order to understand the program, the source code of the program may be analyzed and the results of the analysis may be used. One of the known methods of source code analysis is called pointer analysis, which analyzes how objects generated in a program are propagated. As data output as a result of pointer analysis, for example, data showing the call relationships between objects, called a call graph, is known.

[0003] Furthermore, in recent years, in order to develop programs more efficiently, there have been an increasing number of cases where templates having numerous reusable program parts, also known as application frameworks, are used. [Prior art documents] [Patent documents]

[0004] [Patent Document 1] International Publication No. 2022 / 123763 Summary of the Invention [Problem to be solved by the invention]

[0005] On the other hand, in a program created using an application framework, the application framework configures dependencies between objects when the program is executed. Therefore, when a program is created using an application framework, the code showing the creation of objects may not be explicitly specified in the source code. In such a case, it may be difficult to perform an accurate analysis using so-called static analysis methods such as pointer analysis.

[0006] To address the above-mentioned issues, Patent Document 1 discloses an example of a technique for generating a call graph using information related to Dependency Injection (DI). However, the technique disclosed in Patent Document 1 does not necessarily generate an accurate call graph (a call graph that is more in line with reality) because it does not perform pointer analysis.

[0007] In view of the above problems, an object of the present invention is to enable a call graph of source code that is the subject of static analysis to be generated in a more suitable manner. [Means for solving the problem]

[0008] The information processing device of the present invention comprises an extraction means for extracting, from a series of source codes to be analyzed, a first source code having a first annotation suggesting the generation of an object as an update target, and an update means for updating the first source code extracted as the update target by adding, to a field in which the first annotation is indicated in the first source code, either a first code that directly indicates the generation of an object corresponding to the field, or a second code that indirectly indicates the generation of the object, and generating an execution code that invokes a process defined in the updated first source code, and a call graph is generated based on the updated first source code and the execution code. Effect of the Invention

[0009] According to the present invention, it is possible to generate a call graph of source code that is the subject of static analysis in a more suitable manner. [Brief description of the drawings]

[0010] [Figure 1] FIG. 2 is a diagram for explaining an overview of functions of an information processing device. [Diagram 2]FIG. 11 is a diagram illustrating an example of a method for updating source code. [Diagram 3] FIG. 2 is a diagram illustrating an example of a hardware configuration of an information processing device. [Figure 4] FIG. 2 is a functional block diagram showing an example of a functional configuration of an information processing device. [Diagram 5] 11 is a flowchart showing an example of processing by an information processing device. [Figure 6] FIG. 13 illustrates an example of a case where an error occurs due to an update of source code. [Figure 7] FIG. 11 is a diagram illustrating an example of a method for updating source code. [Figure 8A] FIG. 13 is a diagram illustrating an example of a case where a singleton is not applied. [Figure 8B] FIG. 13 is a diagram showing an example in which a singleton is applied. [Figure 9] FIG. 13 is a diagram for explaining consideration of singletons. [Figure 10] FIG. 13 is a diagram illustrating an example of a mechanism for determining whether or not a singleton can be applied. [Figure 11] FIG. 13 is a diagram illustrating an example of a mechanism for determining whether or not a singleton can be applied. [Figure 12] FIG. 11 is a diagram illustrating an example of a method for updating source code. [Figure 13] FIG. 11 is a diagram illustrating an example of a method for generating an execution code. DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS

[0011] Hereinafter, preferred embodiments of the present disclosure will be described in detail with reference to the accompanying drawings. In this specification and the drawings, components having substantially the same functional configurations are denoted by the same reference numerals, and redundant description will be omitted.

[0012] <First embodiment> An information processing device according to a first embodiment of the present disclosure will be described below. First, an overview of the functions of the information processing device according to the present embodiment will be described with reference to Figs. As described above, there are some programs, such as those created using an application framework, in which dependencies between objects are configured by the application framework when the program is executed. In such programs, the code indicating the creation of an object may not be explicitly specified in the source code. For example, Figure 1 shows an example of a case in which the code indicating the creation of an object is not explicitly specified in the source code.

[0013] Specifically, source code C111 shown in Fig. 1(a) prescribes, within the code of class X, a field C112 of an object of class B and code C113 for calling a process (method) of the object held in field C112. Fig. 1(b) shows an example of a call graph showing the calling relationships between objects when a program of source code such as that shown in Fig. 1(a) is executed under such a premise. On the other hand, in pointer analysis, which analyzes the calling relationships between objects based on source code without executing the program, field C112 is treated as Null because the creation of an object for that field is not explicitly specified. Therefore, when attempting to generate a call graph for source code C111 using pointer analysis (static analysis), a call graph that does not match the reality may be generated, as shown in Figure 1(c), which is based on the assumption that an object of class B has not been created.

[0014] In consideration of the above situation, the information processing device according to this embodiment makes it possible to generate a call graph that is more in line with the actual situation by making partial modifications to the source code to be analyzed and updating the source code to source code for pointer analysis (static analysis). For example, Fig. 2 is an explanatory diagram for explaining an overview of the functions of the information processing device according to this embodiment.

[0015] 2(a) shows an example of a result of updating a source code to be analyzed by the information processing device 100 according to this embodiment. Specifically, source code C121 shows an example of the source code to be analyzed after the source code has been updated by being modified by the information processing device 100. Source code C122 is execution code (so-called code in which a Main class is defined) that calls a process defined in the updated source code C121. In some frameworks, annotations are added to parts that configure dependencies between objects at run time. Based on the annotations, the information processing device 100 according to the present embodiment identifies source code to be updated from a series of source codes designated as analysis targets, and code (e.g., fields) to be updated in the source code. Then, based on a definition of the code to be updated, the information processing device 100 modifies the code.

[0016] For example, in the example shown in FIG. 2(a), an annotation C123 indicated by a keyword "@Autowired" which means that a dependency between objects is configured at run time is added to a field C124. Therefore, the information processing device 100 extracts the source code C121 to which the annotation C123 is added as an update target from among a series of source codes specified as an analysis target. Then, the information processing device 100 adds a code indicating the generation of an object to the field C124 to which the annotation C123 is indicated, in accordance with the definition in the source code C121. Specifically, in the example shown in FIG. 2(a), a code directly indicating the generation of an object (for example, a code to create a new object) is added to the field C124 to which the annotation C123 is indicated. At this time, the information processing device 100 identifies the object to be generated based on, for example, an annotation added to a class that the framework treats as a component to be managed. For example, the object set in the field C124 is an object of class A or class B. In the example shown in FIG. 2(a), an annotation C125 indicated by the keyword "@Component" is added to the class B, which indicates that the object is a component to be managed. On the other hand, no annotation is added to the class A, which indicates that the object is a component to be managed. Therefore, the information processing device 100 recognizes that the object set in the field C124 is an object of class B, and adds a code that directly indicates the generation of an object of class B. In this manner, the source code C121 is updated. Furthermore, the information processing device 100 generates source code C122 corresponding to the execution code that is the starting point when generating a call graph, based on the update result of the target source code. Specifically, the information processing device 100 generates source code C122 as the execution code to be called by at least the code related to the call of the updated code. For example, in the example shown in FIG. 2(a), the field C124 in the source code C121 is the object to be updated, and the object held in the field C124 is referenced in the code C125. Therefore, the information processing device 100 generates an object of class X in which the field C124 to be updated is defined, and generates source code C122 in which the code C126 that calls the process defined as the code C125 as the process of the object is defined. As long as it is possible to generate an execution code (a code equivalent to source code C122) that satisfies the above requirements, the method is not particularly limited. For example, it is possible to generate an execution code that satisfies the above requirements by using the method disclosed in the reference document shown below. ·Reference: Jens Dietrich, Francois Gauthier, and Padmanabhan Krishnan. 2018. Driver Generation for Java EE Web Applications. In Australasian Software Engineering Conference (ASWEC). IEEE, 121-25. As another example, it is possible to generate execution code that satisfies the above-mentioned requirements by using annotations added by the framework to the source code to be analyzed. The method of generating execution code using annotations will be described in detail later as a modified example of this embodiment. In addition, in FIG. 2(a), annotation C123 indicated by the keyword "@Autowired", which means that a dependency relationship between objects is configured at run time, corresponds to an example of a "first annotation" that suggests the generation of an object. That is, source code C121 to which annotation C123 is added, i.e., source code to be updated, corresponds to an example of a "first source code". Also, code that directly indicates the generation of an object and is added to field C124 indicated by annotation C123 corresponds to an example of a "first code".

[0017] Note that the keywords added as the annotation C123 may differ depending on the framework to be applied. Therefore, the information processing device 100 may appropriately change the keywords extracted as the annotation C123 depending on the framework to be applied. Also, as long as the information processing device 100 can identify the framework to be applied, the method is not particularly limited. As a specific example, the information processing device 100 may recognize the framework to be applied in response to an instruction from a user, and change the keywords to be extracted as the annotation C123 depending on the framework. Also, as another example, the information processing device 100 may recognize the framework to be applied by analyzing information included in the source code specified as the analysis target, a configuration file linked to the source code, or the like.

[0018] FIG. 2(b) shows an example of a call graph showing the call relationship between objects when a program of the source code before the update is executed. FIG. 2(c) shows an example of a call graph generated by pointer analysis (static analysis) of the updated source code shown in FIG. 2(a). As can be seen by comparing FIG. 2(b) and FIG. 2(c), the call graph shown in FIG. 2(c) includes a call graph related to a call from the execution code C122, but the other call graphs are the same as the call graph shown in FIG. 2(b). That is, by updating the source code to be analyzed as shown in FIG. 2(a), it becomes possible to generate a call graph that matches the actual situation even under the circumstances where pointer analysis is used. In the following, the information processing device 100 according to this embodiment will be described in more detail.

[0019] (Hardware configuration) An example of a hardware configuration of the information processing device according to the present embodiment will be described with reference to FIG. 3. As shown in FIG. 1, the information processing device 100 according to the present embodiment includes a central processing unit (CPU) 910, a read only memory (ROM) 920, and a random access memory (RAM) 930. The information processing device 100 also includes an auxiliary storage device 940 and a network I / F 970. The information processing device 100 may also include at least one of an output device 950 and an input device 960. The CPU 910, the ROM 920, the RAM 930, the auxiliary storage device 940, the output device 950, the input device 960, and the network I / F 970 are connected to each other via a bus 980.

[0020] The CPU 910 is a central processing unit that controls various operations of the information processing device 100. For example, the CPU 910 may control the operation of the entire information processing device 100. The ROM 920 stores a control program, a boot program, and the like that can be executed by the CPU 910. The RAM 930 is the main storage memory of the CPU 910, and is used as a work area or a temporary storage area for expanding various programs.

[0021] The auxiliary storage device 940 stores various data and various programs. The auxiliary storage device 940 is realized by a storage device capable of temporarily or persistently storing various data, such as a non-volatile memory represented by an HDD (Hard Disk Drive) or an SSD (Solid State Drive).

[0022] The output device 950 is a device that outputs various types of information, and is used to present various types of information to a user. For example, the output device 950 may be realized by a display device such as a display. In this case, the output device 950 presents information to a user by displaying various types of display information. As another example, the output device 950 may be realized by an audio output device that outputs sounds such as voice and electronic sounds. In this case, the output device 950 presents information to a user by outputting sounds such as voice and telegrams. In addition, a device applied as the output device 950 may be appropriately changed depending on a medium used to present information to a user.

[0023] The input device 960 is used to receive various instructions from the user. In this embodiment, the input device 960 includes input devices such as a mouse, a keyboard, and a touch panel. As another example, the input device 960 may include a sound collection device such as a microphone, and collect the voice uttered by the user. In this case, various analysis processes such as acoustic analysis and natural language processing are performed on the collected voice, and the content indicated by the voice is recognized as an instruction from the user. In addition, the device applied as the input device 960 may be appropriately changed depending on the method of recognizing the instruction from the user. In addition, multiple types of devices may be applied as the input device 960.

[0024] The network I / F 970 is used for communication with an external device via a network. The device used as the network I / F 970 may be changed as appropriate depending on the type of communication path and the communication method used.

[0025] The CPU 910 expands a program stored in the ROM 220 or the auxiliary storage device 940 into the RAM 930 and executes this program, thereby realizing the functional configuration of the information processing device described later with reference to Figure 4 and the processing of the information processing device described later with reference to Figure 5.

[0026] (Functional configuration) An example of a functional configuration of the information processing device 100 according to this embodiment will be described with reference to Fig. 4. As shown in Fig. 4, the information processing device 100 according to this embodiment includes a control unit 110 and a call graph generation unit 120.

[0027] The control unit 110 receives an input of a series of source codes D210 to be analyzed, performs the update described with reference to Fig. 2 on the source codes D210, and outputs the updated source codes D220 to a predetermined output destination.

[0028] The analysis unit 111 performs a predetermined analysis on a series of source codes D210 to be analyzed, thereby identifying source codes to be updated from the series of source codes D210 and code to be updated in the source codes. Specifically, as described with reference to Fig. 2(a), the analysis unit 111 extracts source codes to which predetermined annotations are added as source codes to be updated, and identifies code in the source codes to which the annotations are indicated as code to be updated. Furthermore, when there is other source code that has a dependency relationship with the series of source codes D210 to be analyzed but is not included in the series of source codes D210, the analysis unit 111 may also include the other source code in the analysis target. As a specific example, when a series of source codes to be analyzed is specified by a management unit used for managing source codes such as a project, the analysis unit 111 may identify the dependency relationship between the management units by using a configuration file or the like. Then, when another management unit that has a dependency relationship with the management unit specified as the analysis target is not included in the analysis target, the analysis unit 111 may also include the other management unit in the analysis target.

[0029] Based on the result of identifying the source code to be updated and the code in the source code by the analysis unit 111, the update unit 112 performs an update to add a code related to the generation of an object (for example, a code directly indicating the generation of an object) to the source code as described with reference to FIG. 2(a). In addition, the update unit 112 generates an execution code (a code in which a so-called Main class is defined) that is a starting point for generating a call graph for at least the source code, based on the result of updating the source code to be updated. Then, the update unit 112 outputs a series of source codes to be analyzed including the updated source code and the generated execution code to a predetermined output destination as a series of source codes D220 for generating a call graph. For example, in the example shown in FIG. 4, the update unit 112 outputs a series of source codes D220 for generating a call graph to the call graph generation unit 120 described later.

[0030] The call graph generating unit 120 generates a call graph by static analysis such as so-called pointer analysis for a series of source codes D220 for generating a call graph, at least a part of which has been updated by the control unit 110. Note that as long as it is possible to generate a so-called call graph by analyzing the source code, the method (e.g., a method of analyzing the source code) is not particularly limited. That is, a known logic may be applied to the generation of the call graph. Therefore, for example, a known tool that analyzes a series of input source codes to generate a call graph may be applied as the call graph generating unit 120. In this way, the call graph generating unit 120 generates a call graph D230 using a series of source codes D220 as an input, and outputs the generated call graph D230 to a predetermined output destination.

[0031] It should be noted that the configuration shown in FIG. 4 is merely an example and does not necessarily limit the functional configuration of the information processing device 100 according to the present embodiment. For example, the series of components shown in FIG. 4 may be realized by cooperation of a plurality of devices. As a specific example, a component corresponding to the call graph generating unit 120 may be realized by another device other than the information processing device 100. In this case, the information processing device 100 including the control unit 110 may transmit a series of source codes D220 for generating a call graph to the other device connected via a network. As another example, the control unit 110 may output a series of source codes D220 for generating a call graph to a predetermined storage device (e.g., a server for data management, etc.). In this case, the other device including the call graph generating unit 120 may acquire a series of source codes to be used for generating a call graph from the storage device. As another example, the processing load of at least some of the components in the series of components shown in FIG. 4 may be distributed to a plurality of devices. Furthermore, at least some of the components of the series of components shown in FIG. 4 may be realized by a so-called network service such as a cloud service.

[0032] (process) An example of processing by the information processing device 100 according to this embodiment will be described with reference to FIG. In S110, the control unit 110 receives an input of a series of source codes D210 to be analyzed. In addition, at this time, the control unit 110 may check whether there is other source code having a dependency relationship with the series of source codes D210 to be analyzed, and may include the other source codes in the analysis target.

[0033] In S120, the analysis unit 111 performs a predetermined analysis process on a series of source codes D210 that have been input as an analysis target in S110, thereby identifying source codes to be updated and update locations in the source codes (i.e., code to be updated). Specifically, the analysis unit 111 extracts source codes to which a predetermined annotation C123 has been added as source codes to be analyzed, and identifies code in the source codes where the annotation C123 is indicated as an update location.

[0034] In S130, the update unit 112 updates the source code by adding code related to the generation of an object corresponding to the code indicated in the update portion to the source code based on the result of identifying the source code to be updated and the update portion in S120. In addition, the update unit 112 generates execution code that serves as a starting point for generating a call graph for at least the source code based on the update result of the source code to be updated. The update unit 112 then outputs the series of source codes to be analyzed including the updated source code and the generated execution code to a predetermined output destination as a series of source codes for generating a call graph. The series of source codes output from the update unit 112 in the manner described above is used by the call graph generation unit 120 to generate a call graph, for example.

[0035] (Modification) As a modification of this embodiment, an example of a method for identifying a process to be called in an execution code by using an annotation added by a framework to a source code to be analyzed when the information processing device 100 generates the execution code will be described. For example, Fig. 13 is an explanatory diagram for explaining an overview of the functions of the information processing device according to this modification.

[0036] Source code C151 shown in Fig. 13(a) is an example of source code to be analyzed. In the source code C151, similar to the source code C111 shown in Fig. 1(a), a field C154 of an object of class B and a code C158 that calls a process (method) of the object held in the field C154 are defined in the code of class X. An annotation C155 indicated by "@Controller" is added to the class X. This annotation C155 is an annotation that is added to a class that is the starting point of application execution, and can be added to a class that is called first in response to an HTTP request, for example. Moreover, the above code C158 is added with an annotation C156 indicated by the keyword "@RequestMapping". This annotation C156 is defined in association with the annotation C155, and is added to a method that receives and processes an HTTP request, and the "method" attribute specifies which HTTP method the request is to be processed. Similarly to the annotation C156, other annotations that can specify which HTTP method the request is to be processed include annotations indicated by keywords such as "@GetMapping", "@PostMapping", "@PutMapping", "@DeleteMapping", and "@PatchMapping". In this modified example, these annotations are also treated in the same way as the annotation C156. Note that the @Controller annotation includes the @Component annotation. In other words, class X with the @Controller annotation will also be managed as a component.

[0037] 13(b) shows an example of the result of updating the source code to be analyzed by the information processing device 100 according to this modification. Specifically, source code C152 shows an example of the source code to be analyzed after it has been updated by modifying the source code by the information processing device 100. Source code C153 is execution code that calls a process defined in the updated source code C152.

[0038] In source code C152, similar to the example described with reference to Figures 1 and 2, field C154 is updated by adding code that directly indicates the generation of an object of class B. Note that the method of updating source code C151 to source code C152 is similar to the example described with reference to Figures 1 and 2, so detailed description will be omitted.

[0039] Furthermore, when generating the execution code C153, the information processing device 100 according to this modification specifies the process to be called by the execution code C153 based on the annotations C155 and C156. Specifically, the information processing device 100 identifies a class to be called for processing based on the annotation C155 added to the source code C151 to be analyzed. In the example shown in Fig. 13, the information processing device 100 identifies class X as the target. Next, the information processing device 100 identifies a process to be called by the execution code from among a series of processes of the class identified as a target, based on the annotation C156 added to the source code C151 to be analyzed. For example, in the example shown in Fig. 13, the annotation C156 is added to the process indicated by the code C158 in the class X. Therefore, the information processing device 100 generates the execution code C153 so that the process indicated by the code C158 is called as the process of the object of the class X.

[0040] As a modification of this embodiment, an example of a method in which the information processing device 100 uses annotations added by a framework to a source code to be analyzed when generating the execution code to identify a process to be called in the execution code has been described above.

[0041] (Action and effect) As described above, the information processing device 100 according to the present embodiment extracts source code to which a predetermined annotation is added from a series of source codes to be analyzed as source code to be updated, and identifies the code to which the annotation is added as an update location. Then, the information processing device 100 updates the identified update location in the source code to be updated by adding code related to the generation of an object corresponding to the code (for example, a field) indicated in the update location (for example, a code directly indicating the generation of an object). In addition, the information processing device 100 generates execution code that is a starting point for generating a call graph with at least the source code as a target, based on the update result of the source code to be updated. Then, the information processing device 100 outputs a series of source codes to be analyzed including the updated source code and the generated execution code to a predetermined output destination as a series of source codes for generating a call graph. By using a series of source codes generated in the above manner, it is possible to generate a call graph that is more in line with reality, even when static analysis such as pointer analysis is used to generate a call graph, as described with reference to FIG. 2.

[0042] <Second embodiment> A second embodiment of the present disclosure will be described. In the above-mentioned embodiment, the source code is updated by adding code that directly indicates the generation of an object to the target source code (for example, code that creates a new object). On the other hand, when code that directly indicates the generation of an object is added to the target source code in this way, an error may occur when compiling the source code (i.e., compilation may fail). In this embodiment, in consideration of such a situation, another example of a method for updating the target source code will be described. Note that this embodiment will be described by focusing on parts that are particularly different from the first embodiment described above, and detailed description of parts that are substantially similar to the first embodiment will be omitted.

[0043] First, referring to FIG. 6, an example of a case where an error occurs when compiling a source code by adding a code that directly indicates the generation of an object to the target source code is described. In the example shown in FIG. 6, classes A and X are managed in project 1, and class B that inherits class A is managed in project 2. Note that "inheritance" in this disclosure corresponds to inheritance defined as one of the concepts constituting object orientation, and means that an object inherits the characteristics of another object. That is, in this disclosure, inheritance means that a common part related to the definition of a class is consolidated into another class. Also, in class X, a field in which an object of class B is held is defined, and code to be called as processing of the object held in the field is indicated. In such a case, as in the first embodiment described above, code that directly indicates the generation of an object of class B (for example, code that creates a new object of class B) is added to class X. Under such circumstances, when compilation of source code is executed for project 1, class B is not defined in project 1, and project 1 does not depend on project 2, so class B cannot be referenced in class X, which causes an error and compilation to fail.

[0044] Therefore, in this embodiment, an example of a mechanism that enables a call graph to be generated for a series of source code by static analysis such as pointer analysis while maintaining the series of source code in a compilable state even under the circumstances exemplified above will be described.

[0045] For example, Fig. 7 is a diagram for explaining an example of a method for updating a source code to be processed by the information processing device 100 according to the present embodiment. Specifically, Fig. 7(a) shows an example of the update content of the source code by the information processing device 100 according to the present embodiment.

[0046] In FIG. 7(a), project C331 is a schematic diagram of a project (management unit) for managing a series of source codes to be analyzed. In the example shown in FIG. 7(a), for convenience, a part of source codes that are particularly important among a series of source codes included in project C331 is extracted and illustrated. As in the first embodiment, the analysis unit 111 of the information processing device 100 extracts source codes to which a predetermined annotation C333 is added as source codes to be updated, and identifies code C335 (field) in which the annotation C333 is indicated in the source codes as code to be updated (in other words, an update location). Then, the update unit 112 of the information processing device 100 adds code that indirectly indicates the generation of an object indicated by the code C335 based on the result of identifying the code C335 to be updated. Specifically, the update unit 112 adds an abstract class C334 corresponding to the code to be updated to the project C331, and then adds code for invoking a generation process of a target object to the abstract class C334. The update unit 112 also adds code for invoking the above process of the generated abstract class C334 to the code C335 to be updated. 7(a), the code that indirectly indicates the generation of an object (the code that calls the processing of the separately added abstract class C334) that is added to the code C335 (field) in which the annotation C333 is indicated corresponds to an example of the "second code". Also, the source code in which the class C336 that inherits the abstract class C334 is defined, that is, the source code other than the source code to be updated in which the code that directly indicates the generation of an object is indicated, corresponds to an example of the "second source code".

[0047] Furthermore, the update unit 112 generates a project C332 separate from the project C331 to be analyzed, and adds to the project C332 a class C336 that inherits the abstract class C334, and execution code C337 that is a starting point for generating a call graph. Specifically, the update unit 112 adds to the class C336 code for a process called by the code defined in the abstract class C334, and adds to the code code a code that directly indicates the generation of a target object (for example, code for creating a new object). Furthermore, the update unit 112 specifies, in the execution code C337, code for generating an object of the class C336, and for the process of the object, code for calling the process of the abstract class C334 that was added in association with the object indicated by the code C335 in the source code to be updated.

[0048] FIG. 7(b) shows an example of a call graph showing the call relationship between objects when a program of the source code before the update is executed. FIG. 7(c) shows an example of a call graph generated by pointer analysis (static analysis) of the updated source code shown in FIG. 7(a). As can be seen by comparing FIG. 7(b) and FIG. 7(c), although the call graphs are different as a whole, the call graph shown in FIG. 7(c) includes a call graph substantially similar to the call graph shown in FIG. 7(b) as a partial call graph C338. That is, the call graph shown in FIG. 7(c) includes a call graph C338 substantially similar to the call graph originally assumed, and a call graph generated based on the code added for the analysis. Under such a premise, in order to obtain a call graph substantially equivalent to the original call graph by removing the unnecessary parts, for example, the call graph of the source code to be analyzed may be extracted from the series of call graphs shown in FIG. 7(c) using the package name or the like as an extraction condition. In this way, even in the present embodiment, it is possible to generate a call graph that matches the actual situation (i.e., the call graph C338) even in a situation where pointer analysis is used. In addition, as shown in Fig. 7(a), by updating the source code to be analyzed, the grammatical consistency of the programming language is maintained even after the update, so that no errors occur when compiling the source code. Specifically, even if compilation is performed for project C331 in the state shown in Fig. 7(a), the compilation will end normally. In other words, the information processing device 100 according to this embodiment makes it possible to generate a call graph for a series of source codes by static analysis such as pointer analysis while maintaining the series of source codes in a compilable state.

[0049] <Third embodiment> The third embodiment of the present disclosure will be described below. In this embodiment, as an embodiment further extending the second embodiment, an example of a mechanism for generating a call graph of a source code to be analyzed will be described, taking into consideration a case where the source code is specified based on a design concept (design pattern) called a Singleton. Note that in this embodiment, the description will focus on parts that are particularly different from the first and second embodiments described above, and detailed descriptions of parts that are substantially similar to the first and second embodiments will be omitted.

[0050] First, in order to more clearly explain the features of this embodiment, an outline of the difference between a case where a singleton is not applied and a case where a singleton is applied will be described with reference to FIGS. 8A and 8B.

[0051] For example, FIG. 8A is a diagram showing an example of a case where singletons are not applied. Specifically, FIG. 8A(a) is a diagram showing an example of source code to be analyzed. In the example shown in FIG. 8A(a), as a premise, an object of Dog class is set in the pet field of an object of House class (hereinafter also referred to as house object) for each of objects x and y. Under such circumstances, for object x, the object set in the pet field of the house object is replaced with an object of Cat class (i.e., the object of Cat class is newed and assigned). For reference, FIG. 9 shows an example of source code of a series of objects defined by the source code shown in FIG. 8A and FIG. 8B described later. Fig. 8A(b) shows an example of the result of applying pointer analysis to the source code shown in Fig. 8A(a) when singleton is not applied. When singleton is not applied, a house object is generated separately for each of objects x and y, so that different house objects are called from each of objects x and y, as shown in Fig. 8A(b). That is, for object x, the generation process of a Cat class object is called from the house object, and for object y, the generation process of a Dog class object is called from the house object. Fig. 8A(c) shows an example of a call graph output as a result of the pointer analysis described with reference to Fig. 8A(b). That is, from the main method of the Main class, the cry method of the Cat class, which is called as processing of object x, and the cry method of the Dog class, which is called as processing of object y, are output to the call graph.

[0052] FIG. 8B is a diagram showing an example in which a singleton is applied. Specifically, Fig. 8B(a) is a diagram showing an example of source code to be analyzed. The example shown in Fig. 8B(a) is similar to the example shown in Fig. 8A(a) in terms of code description, but differs from the example shown in Fig. 8A(a) in whether a singleton is applied or not. Fig. 8B(b) shows an example of the result of applying pointer analysis to the source code shown in Fig. 8A(a) when singleton is applied. When singleton is applied, a common house object is applied to each of objects x and y, so that a common house object is called from each of objects x and y, as shown in Fig. 8B(b). Fig. 8B(c) shows an example of a call graph output as a result of the pointer analysis described with reference to Fig. 8B(b). That is, the cry method of the Cat class, which is commonly called as processing for objects x and y from the main method of the Main class, is output to the call graph, but the cry method of the Dog class is not output to the call graph. In the following description, for convenience, an object to which the singleton is applied is also referred to as a singleton object. That is, in the example shown in Fig. 8B, the house object is a singleton object. In contrast, in the example shown in Fig. 8A, the house object is not a singleton object.

[0053] 8A and 8B, even when a common source code is applied, the operation of the program differs depending on whether a singleton is applied, and as a result, the output call graph also differs. In view of this situation, in this embodiment, an example of updating the source code to be analyzed so that a call graph that is more in line with the actual situation is generated by taking into account whether a singleton is applied to the source code.

[0054] First, an example of a mechanism by which the information processing device 100 according to the present embodiment determines whether a singleton is applied to source code to be analyzed will be described. For example, some frameworks allow the scope of a target program to be specified by an annotation added to the source code, a configuration file associated with the source code, or the like. In such a case, for example, it may be possible to set whether or not a singleton is applied as a setting for the scope. Therefore, for example, the information processing device 100 may determine whether or not a singleton is applied to the target source code by using the mechanism of such a framework.

[0055] For example, Fig. 10 is a diagram showing an example of a mechanism for determining whether a singleton is applied to source code based on an annotation added to the source code by a framework. In the example shown in Fig. 10, whether a singleton is applied is shown according to whether an annotation indicated by the keyword "@Scope", which means the specification of the scope of the program realized by the target source code, is added or not, and according to the parameters specified in the annotation. Specifically, as shown in FIG. 10(a) and FIG. 10(b), the annotation "@Scope" can specify an attribute value as a parameter, and the scope of the target source code is determined according to the attribute value specified as the parameter. In addition, when "singleton" meaning the application of a singleton is specified as an attribute value for this annotation "@Scope", it means that the singleton is applied to the target source code. That is, in the example shown in FIG. 10(a), the annotation "@Scope" means that the singleton is not applied. Also, in the example shown in FIG. 10(b), the annotation "@Scope" means that the singleton is applied. Therefore, the information processing device 100 may determine whether or not the singleton is applied to the target source code based on the attribute value specified for the annotation added to the target source code. Also, it may be assumed that no attribute value is specified for the annotation "@Scope" as shown in FIG. 10(c), or that the annotation "@Scope" is not added as shown in FIG. 10(d). In such a case, a default setting is applied as the scope. Therefore, in such a case, the information processing device 100 may determine whether or not a singleton is applied to the target source code depending on whether or not the default setting means that a singleton is applied. Specifically, in the examples shown in FIG. 10(c) or FIG. 10(d), if the default setting means that a singleton is applied, the information processing device 100 determines that a singleton is applied to the target source code.

[0056] As another example, Fig. 11 is a diagram showing an example of a mechanism for determining whether or not a singleton is applied to a source code based on a scope-related setting defined in a configuration file associated with the target source code by a framework. In the example shown in Fig. 11, whether or not a singleton is applied is shown according to whether or not an attribute indicated by the keyword "scope", which means the specification of the scope of the program realized by the target source code, is specified for a "bean" tag that specifies various settings for each class, and the attribute value specified for the attribute. Specifically, as shown in FIG. 11(a) and FIG. 11(b), an attribute value is specified for the "scope" attribute of the "bean" tag, and the scope of the target source code is determined according to the attribute value. In addition, when "singleton", which means the application of a singleton, is specified as the attribute value for this "scope" attribute, it means that the singleton is applied to the target source code. That is, in the example shown in FIG. 11(a), the "scope" attribute means that the singleton is not applied. Also, in the example shown in FIG. 11(b), the "scope" attribute means that the singleton is applied. Therefore, the information processing device 100 may refer to a configuration file associated with the target source code, and determine whether or not a singleton is applied to the class indicated by the "bean" tag (in other words, the source code of the class) based on the attribute value specified for the "scope" attribute of the "bean" tag in the configuration file. Also, as shown in FIG. 11(c), a case may be assumed where the "scope" attribute is not specified for the "bean" tag. In such a case, a default setting is applied as the scope. Therefore, in such a case, the information processing device 100 may determine whether or not a singleton is applied to the target source code depending on whether or not the default setting means that a singleton is applied. Specifically, in the case of the example shown in FIG. 11(c), if the default setting means that a singleton is applied, the information processing device 100 determines that a singleton is applied to the target source code.

[0057] Next, an example of a method for updating a source code to be analyzed by the information processing device 100 according to the present embodiment will be described with reference to FIG. 12. In FIG. 12, source code C501 is a schematic representation of a source code to be analyzed. Although not shown in FIG. 12, it is assumed that class A and class B are separately defined, as in the example described with reference to FIG. 6 and FIG. 7. It is also assumed that class X is defined as having a field b in which an object of class B inheriting class A is held, and that a predetermined annotation (@Autowired) is indicated for the field. Although not shown in FIG. 12, an execution code (Main class) that is a starting point for generating a call graph for the updated source code C501 is separately added.

[0058] The analysis unit 111 of the information processing device 100 extracts source code C501 to which a predetermined annotation (@Autowired) is added from a series of source codes designated as an analysis target, and identifies the code (field) to which the annotation is indicated as the code to be updated (in other words, the update location). In the example shown in Fig. 12, it is assumed that the field b in which an object of class B inheriting class A is set is identified as the code to be updated. Then, the update unit 112 of the information processing device 100 adds a code that indirectly indicates the generation of an object indicated by the code, based on the result of identifying the code to be updated. Specifically, the update unit 112 adds an abstract class C503 corresponding to the code to be updated to the same project (hereinafter referred to as project 1) as the source code C501, and then adds a code for calling a generation process of a target object to the abstract class C503. Note that, for convenience, the example shown in FIG. 12 illustrates a state in which the code C508 and the code C509 are added to the source code C503. The code C508 is a code (overridden code) whose substantial process is defined as the code C506 in the source code C502 described later. The code C509 is a code (overridden code) whose substantial process is defined as the code C507 in the source code C502. When the singleton is applied, both the codes C508 and C509 are used. On the other hand, when the singleton is not applied, only the code C509 is used. The update unit 112 may selectively switch the output of codes C508 and C509 as described above based on the result of determining whether a singleton has been applied to source code C501, or may add both regardless of whether a singleton has been applied. Furthermore, the update unit 112 adds code for calling the above-mentioned processing of the generated abstract class C503 to the code to be updated (field b) in the source code C501. For convenience, the example shown in Fig. 12 illustrates code C504 when a singleton is applied to the source code C501 and code C505 when a singleton is not applied to the source code C501. The update unit 112 adds either code C504 or C505 to the source code C501 based on the determination result of whether a singleton is applied to the source code C501.

[0059] Furthermore, the update unit 112 generates a project (hereinafter also referred to as project 3) different from project 1 including the source code C501 to be analyzed, and adds a class C502 that inherits the abstract class C503 to the project 3. Specifically, the update unit 112 adds to the class C502 a code of a process that is called by the code defined in the abstract class C503. As described above, either the code C508 (in the case of a singleton) or the code C509 (in the case of not being a singleton) is added to the abstract class C503 depending on whether or not a singleton is applied to the source code C501. Therefore, the update unit 112 appropriately changes the code to be added to the class C502 depending on the code added to the abstract class C503. In the example of source code C502 shown in FIG. 12, for convenience, a state in which code C506 and code C507 are added to source code C501 is illustrated. Specifically, code C506 is added with code for returning an object of class B (class inheriting class A) held in field b. In addition, the field b holds an object of class B generated (newed) by code C507, the details of which will be described later. In addition, code C507 is added with code for generating an object of class B (class inheriting class A). When a singleton is applied, both codes C506 and C507 are used. On the other hand, when a singleton is not applied, only C507 is used. The update unit 112 may selectively switch the output of codes C506 and C507 as described above based on the result of determining whether a singleton is applied or not, or may add both codes regardless of whether a singleton is applied or not. Needless to say, it is desirable to switch the control relating to the output of this code in conjunction with the switching of control relating to the output of codes C508 and C509 in source code C503. Although not shown in the example shown in Fig. 12, an execution code (Main class) that serves as a starting point for generating a call graph for the updated source code C501 is added to project 3 based on the same technical idea as in the example described with reference to Fig. 7. Note that the execution code is similar to the example shown in Fig. 7, so a detailed description thereof will be omitted.

[0060] In this manner, by updating the source code to be analyzed, it becomes possible to output a call graph for that source code in a manner more in line with reality, depending on whether or not a singleton is applied to that source code. In the above example, an example has been described in which the information processing device 100 determines whether or not a singleton is applied to the source code to be analyzed based on annotations added to the source code to be analyzed, a configuration file associated with the source code, and the like. On the other hand, as long as the information processing device 100 can determine whether or not a singleton is applied to the source code to be analyzed, the method is not particularly limited. For example, the information processing device 100 may receive an instruction from a user and determine whether or not a singleton is applied to the target source code based on the instruction.

[0061] <Supplementary Information> In each embodiment of the present disclosure, the description focuses mainly on the case where the source code defined in a programming language called Java is the target of analysis, but the target programming language is not particularly limited as long as the source code is defined in a programming language that involves the generation of objects. As a specific example, the technology according to the present disclosure can be applied to source code defined in C++, Objective-C, etc. In that case, since the method of writing code differs depending on the programming language applied to the source code to be analyzed, it goes without saying that the code to be added or modified when updating the target source code is also appropriately changed according to the rules of the programming language.

[0062] Furthermore, the above-described embodiment is merely an example and does not necessarily limit the configuration or processing of the present invention. Various modifications and changes may be made without departing from the technical spirit of the present invention.

[0063] In addition, the following configurations also fall within the technical scope of the present disclosure. (1) An information processing device comprising: an extraction means for extracting, from a series of source codes to be analyzed, a first source code to which a first annotation indicating the generation of an object has been added as an update target; and an update means for updating the first source code extracted as the update target by adding, to a field in which the first annotation is indicated in the first source code, either a first code that directly indicates the generation of an object corresponding to the field, or a second code that indirectly indicates the generation of the object, and generating an execution code that invokes a process defined in the updated first source code; wherein a call graph is generated based on the updated first source code and the execution code. (2) The information processing device described in (1), wherein the update means generates the execution code so as to directly call a process defined in the updated first source code when the first code is added to the first source code. (3) The information processing device described in (1), wherein the update means, when adding the second code to the first source code, generates a second source code associated with the second code, the second source code having a code that directly indicates the generation of an object corresponding to the field indicated by the first annotation, and generates the execution code so as to call the processing specified in the second source code, thereby calling the processing specified in the updated first source code. (4) The information processing device described in (3), wherein the second code is code that invokes a process defined in an abstract class of a class defined in the second source code, and the class is defined in the second source code so as to inherit the abstract class. (5) An information processing device according to any one of (1) to (4), wherein the update means determines whether a singleton is applied to an object corresponding to a field indicated by the first annotation in the first source code extracted as an update target, and if a singleton is applied to the object, updates the first source code by adding the second code. (6) The information processing device described in (5), wherein the update means determines whether a singleton is applied to an object corresponding to a field in the first source code extracted as an update target, based on the provisions of a second annotation indicating the scope of an object corresponding to the field, the second annotation being indicated for the field in which the first annotation is indicated. (7) The information processing device described in (5), wherein the update means determines whether a singleton is applied to an object corresponding to a field indicated in the first source code extracted as the update target based on attribute information indicating the scope of the object corresponding to the field indicated in the first source code in a configuration file associated with the first source code extracted as the update target. (8) An information processing method executed by an information processing device, comprising: an extraction step of extracting, from a series of source codes to be analyzed, a first source code to which a first annotation indicating the generation of an object has been added as an update target; and an update step of updating the first source code extracted as the update target by adding, to a field in which the first annotation is indicated in the first source code, either a first code that directly indicates the generation of an object corresponding to the field, or a second code that indirectly indicates the generation of the object, and generating an execution code that invokes a process defined in the updated first source code, wherein a call graph is generated based on the updated first source code and the execution code. (9) A program that causes a computer to execute the following steps: an extraction step of extracting, from a series of source codes to be analyzed, a first source code to which a first annotation indicating the generation of an object has been added as an update target; and an update step of updating the first source code extracted as an update target by targeting a field in the first source code to which the first annotation has been added, by adding either a first code that directly indicates the generation of an object corresponding to the field, or a second code that indirectly indicates the generation of the object, and generating an execution code that invokes a process defined in the updated first source code; and generating a call graph based on the updated first source code and the execution code. [Explanation of symbols]

[0064] 100 Information processing device 110 Control section 111 Analysis Department 112 Update Department 120 Call graph generator

Claims

1. an extracting means for extracting, from a series of source codes to be analyzed, a first source code to which a first annotation suggesting generation of an object is added as an update target; an updating means for updating the first source code extracted as an update target by adding either a first code that directly indicates the generation of an object corresponding to the field in which the first annotation is indicated or a second code that indirectly indicates the generation of the object, and for generating an execution code that calls a process defined in the updated first source code; Equipped with A call graph is generated based on the updated first source code and the execution code. Information processing device.

2. The update means includes: When the first code is added to the first source code, generating the execution code so as to directly call a process defined in the updated first source code; The information processing device according to claim 1 .

3. The update means includes: When the second code is added to the first source code, generating second source code in which a code is defined that directly indicates the generation of an object corresponding to the field in which the first annotation is indicated, in association with the second code; generating the execution code so as to call a process defined in the second source code, thereby calling a process defined in the updated first source code; The information processing device according to claim 1 .

4. the second code is code for invoking a process defined in an abstract class of a class defined in the second source code, The class is defined in the second source code so as to inherit the abstract class. The information processing device according to claim 3 .

5. The update means includes: determining whether a singleton is applied to an object corresponding to a field indicated by the first annotation in the first source code extracted as an update target; updating the first source code by adding the second code if a singleton is applied to the object; The information processing device according to claim 1 .

6. The update means determines whether or not a singleton is applied to an object corresponding to a field based on a definition of a second annotation that is indicated for a field in which the first annotation is indicated in the first source code extracted as an update target and indicates a scope of an object corresponding to the field. The information processing device according to claim 5 .

7. the update means determines whether or not a singleton is applied to an object corresponding to a field indicated in the first source code, based on attribute information indicating a scope of the object corresponding to the field indicated in the first source code in a configuration file associated with the first source code extracted as an update target; The information processing device according to claim 5 .

8. An information processing method executed by an information processing device, an extraction step of extracting, from a series of source codes to be analyzed, a first source code to which a first annotation suggesting generation of an object is added as an update target; an updating step of updating the first source code extracted as an update target by adding either a first code that directly indicates the generation of an object corresponding to the field in which the first annotation is indicated or a second code that indirectly indicates the generation of the object, and generating an execution code that calls a process defined in the updated first source code; Including, A call graph is generated based on the updated first source code and the execution code. Information processing methods.

9. On the computer, an extraction step of extracting, from a series of source codes to be analyzed, a first source code to which a first annotation suggesting generation of an object is added as an update target; an updating step of updating the first source code extracted as an update target by adding either a first code that directly indicates the generation of an object corresponding to the field in which the first annotation is indicated or a second code that indirectly indicates the generation of the object, and generating an execution code that calls a process defined in the updated first source code; Run the command, A call graph is generated based on the updated first source code and the execution code. program.

Citation Information

Patent Citations

  • UML design method

    JP2005327094A

  • Migrating computer programs to virtual compute services using annotations

    US10782934B1

  • Profile guided optimization in the presence of stale profile data

    US20160004518A1

  • Call graph creation device, call graph creation method, and program

    WO2022123763A1