Operation information generation method, device, electronic device and storage medium

By marking borrowed attributes and ordinary attributes on the stack pointer variable during source program compilation, unnecessary ARC operations are reduced, the problem of resource consumption and low throughput caused by delayed reference counting is solved, and system performance and garbage memory recycling efficiency are improved.

CN113900660BActive Publication Date: 2024-09-06BEIJING DAJIA INTERNET INFORMATION TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202111185877.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-10-12
Publication Date
2024-09-06
Estimated Expiration
2041-10-12

AI Technical Summary

Technical Problem

In the existing technology, delayed reference counting technology leads to inaccurate object reference counting, delayed garbage memory collection, large system resource consumption, low program throughput, and frequent ARC operations impact performance.

Method used

By marking borrowed attributes and ordinary attributes on the stack pointer variable during the compilation of the source program, it refuses to generate reference count operation information in the case of borrowed attributes, reducing unnecessary ARC operations and optimizing reference count updates.

Benefits of technology

It reduces the frequent updates of reference counting operations, reduces resource consumption, improves the throughput of the target program, ensures timely recycling of garbage memory, and improves system performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113900660B
    Figure CN113900660B
Patent Text Reader

Abstract

The present disclosure relates to an operation information generation method, device, electronic device and storage medium, the method comprising: obtaining a source program and multiple target stack pointer variables in an assignment relationship in the source program; obtaining attribute information of the multiple target stack pointer variables; refusing to generate reference count operation information when the attribute information of the multiple target stack pointer variables is a borrowing attribute; the borrowing attribute is used to indicate that in the process of mutual assignment of multiple target stack pointer variables, the reference count of the heap object referenced by the multiple target stack pointer variables is refused to be updated. The technical solution of the present disclosure is adopted to refuse to generate reference count operation information when the attribute information of the multiple target stack pointer variables in an assignment relationship is a borrowing attribute, thereby avoiding unnecessary automatic reference count operations in the source program compilation process, avoiding frequent updates of reference counts, and affecting the overall performance of the target program compiled from the source program when it is running.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of Internet technology, and in particular to an operation information generating method, device, electronic device and storage medium. Background Art

[0002] Automatic Reference Counting (ARC) is a technology for automatically managing memory in programming languages. The core idea is that the compiler associates a reference count with each heap object. When the heap object is referenced, the reference count automatically increases by 1, and when the heap object is dereferenced, the reference count automatically decreases by 1. However, if the reference count is updated frequently, it will affect the overall performance of the program.

[0003] The solution of delayed reference technology used in related technologies is to ignore the reference count operation of the pointer on the stack, and only adjust the reference count of the referenced object when the pointer is written to the object in the heap, so as to reduce the frequent changes of the pointer reference on the stack, thereby reducing the frequent ARC operations and optimizing the performance of the program. However, the delayed reference count operation makes the reference count of the object inaccurate, resulting in the garbage memory not being recycled in time, and the system resource consumption is large; in addition, in order to correctly recycle the garbage memory, the related technology also needs to scan the pointer on the stack, which prolongs the maximum pause time of the program, thereby reducing the throughput of the program. Summary of the invention

[0004] The present disclosure provides an operation information generation method, device, electronic device and storage medium to at least solve the problem of large system resource consumption and low program throughput in the process of reducing ARC operations caused by frequent changes of pointers on the stack in the related art. The technical solution of the present disclosure is as follows:

[0005] According to a first aspect of an embodiment of the present disclosure, there is provided a method for generating operation information, comprising:

[0006] Acquire a source program and a plurality of target stack pointer variables having an assignment relationship in the source program;

[0007] Obtaining attribute information of the multiple target stack pointer variables;

[0008] When the attribute information of the multiple target stack pointer variables is a borrowing attribute, the reference count operation information is refused to be generated; the borrowing attribute is used to indicate that during the mutual assignment process of the multiple target stack pointer variables, the reference count of the heap object referenced by the multiple target stack pointer variables is refused to be updated.

[0009] In an exemplary embodiment, the method further comprises:

[0010] In the case where the attribute information of the multiple target stack pointer variables is a common attribute, the reference count operation information is generated; the common attribute is used to indicate that the reference count is updated during the assignment process.

[0011] In an exemplary embodiment, the method further includes marking the borrowed attribute and the common attribute, wherein marking the borrowed attribute and the common attribute includes:

[0012] Obtaining a function to be processed in the source program, wherein the function to be processed includes a plurality of pointer variables;

[0013] According to the multiple pointer variables and the assignment relationship between the multiple pointer variables, construct a first directed graph corresponding to the function to be processed; the vertices of the first directed graph represent the pointer variables, and the edges of the first directed graph represent the assignment relationship between any two pointer variables;

[0014] Marking the attribute information of the stack pointer variable among the multiple pointer variables as the common attribute;

[0015] Determine candidate stack pointer variables from the stack pointer variables according to the vertex corresponding to the stack pointer variable among the multiple pointer variables, the position in the first directed graph, and the scope of the stack pointer variable, the candidate stack pointer variables including the multiple target stack pointer variables;

[0016] The attribute information of the candidate stack pointer variable is updated from the common attribute to the borrowed attribute.

[0017] In an exemplary implementation, constructing a first directed graph corresponding to the function to be processed according to the multiple pointer variables and the assignment relationship between the multiple pointer variables includes:

[0018] Generate the vertex corresponding to each pointer variable;

[0019] According to the assignment relationship between any two pointer variables, determining an assigning variable and an assigned variable in the any two pointer variables, wherein the assigned variable is used to receive the value assigned by the assigning variable;

[0020] Create a directed edge from the vertex corresponding to the assigned variable to the vertex corresponding to the assigned variable;

[0021] The first directed graph is generated according to the vertices and the directed edges.

[0022] In an exemplary embodiment, the vertex stores a variable type and a scope level of a pointer variable represented by the vertex, and the determining a candidate stack pointer variable from the stack pointer variables according to a vertex corresponding to a stack pointer variable among the multiple pointer variables, a position in the first directed graph, and a scope of the stack pointer variable includes:

[0023] According to the variable types stored in the vertices corresponding to the multiple pointer variables, a preset number of stack pointer variables whose variable types are stack pointer types are obtained from the multiple pointer variables;

[0024] Traverse each stack pointer variable in turn, and perform the following operations when traversing each stack pointer variable;

[0025] In a case where there is no first target vertex on the first path in the first directed graph and there is no second path in the first directed graph, determining each stack pointer variable as the candidate stack pointer variable;

[0026] Among them, the first path is a path that can be reached from the vertex corresponding to each stack pointer variable in the first directed graph, and the second path is a path from the second target vertex to the vertex corresponding to each pointer variable in the first directed graph, the first target vertex represents the vertex corresponding to the pointer variable whose scope level is smaller than the scope level of each stack pointer variable, and the second target vertex represents the vertex corresponding to the pointer variable whose scope level is greater than the scope level of each pointer variable.

[0027] In an exemplary embodiment, there are multiple functions to be processed, and the method further includes:

[0028] Based on the calling relationship between the multiple functions to be processed, generating a second directed graph corresponding to the multiple functions to be processed; the vertices in the second directed graph represent the functions to be processed, and the edges in the second directed graph represent the calling relationship between any two functions to be processed;

[0029] Performing a depth-first traversal on the second directed graph based on a preset depth-first search algorithm, and determining a preset number of target functions from the multiple functions to be processed based on the traversal result, wherein the preset number of target functions represent strongly connected components in the second directed graph;

[0030] In the case where there is no recursive call between the preset number of objective functions, the preset number of objective functions are sorted in reverse order according to the calling sequence between the preset number of objective functions to obtain a first function sequence;

[0031] According to the order of each function in the first function sequence, the multiple pointer variables in each function in the first function sequence, and the assignment relationship between the multiple pointer variables in each function in the first function sequence, a first directed graph corresponding to each function in the first function sequence is constructed in sequence.

[0032] In an exemplary embodiment, the method further comprises:

[0033] In the case where the recursive call exists between the preset number of target functions, obtaining a recursive call function, wherein the recursive call function includes a plurality of target functions that have the recursive call between each other;

[0034] According to the calling sequence between the recursive calling function and the other functions, the recursive calling function and the other functions are sorted in reverse order to obtain a second function sequence, wherein the other functions represent functions other than the recursive calling function among the preset number of target functions;

[0035] According to the order of each function in the second function sequence, the multiple pointer variables in each function in the second function sequence, and the assignment relationship between the multiple pointer variables in each function in the second function sequence, a first directed graph corresponding to each function in the second function sequence is constructed in sequence.

[0036] In an exemplary embodiment, the method further comprises:

[0037] Running a target program compiled from the source program, the target program including a plurality of operation information, the plurality of operation information including the reference count operation information;

[0038] When the reference count operation information is executed, the reference count is updated.

[0039] According to a second aspect of an embodiment of the present disclosure, there is provided an operation information generating device, including:

[0040] A first acquisition module is configured to execute and acquire a source program and a plurality of target stack pointer variables having an assignment relationship in the source program;

[0041] A second acquisition module is configured to execute acquisition of attribute information of the plurality of target stack pointer variables;

[0042] The first generation module is configured to refuse to generate reference count operation information when the attribute information of the multiple target stack pointer variables is a borrowing attribute; the borrowing attribute is used to indicate that during the mutual assignment process of the multiple target stack pointer variables, the reference count of the heap object referenced by the multiple target stack pointer variables is refused to be updated.

[0043] In an exemplary embodiment, the device further comprises:

[0044] The second generating module is configured to generate the reference count operation information when the attribute information of the multiple target stack pointer variables is a common attribute; the common attribute is used to indicate that the reference count is updated during the assignment process.

[0045] In an exemplary embodiment, the device further includes a marking module for marking the borrowed attribute and the common attribute, and the marking module includes:

[0046] A to-be-processed function acquisition unit is configured to execute and acquire a to-be-processed function in the source program, wherein the to-be-processed function includes a plurality of pointer variables;

[0047] A first directed graph construction unit is configured to construct a first directed graph corresponding to the to-be-processed function according to the multiple pointer variables and the assignment relationship between the multiple pointer variables; the vertices of the first directed graph represent the pointer variables, and the edges of the first directed graph represent the assignment relationship between any two pointer variables;

[0048] a labeling unit configured to label attribute information of a stack pointer variable among the plurality of pointer variables as the common attribute;

[0049] a candidate stack pointer variable determining unit, configured to determine candidate stack pointer variables from the stack pointer variables according to a vertex corresponding to a stack pointer variable among the multiple pointer variables, a position in the first directed graph, and a scope of the stack pointer variable, the candidate stack pointer variables including the multiple target stack pointer variables;

[0050] The attribute updating unit is configured to update the attribute information of the candidate stack pointer variable from the common attribute to the borrowed attribute.

[0051] In an exemplary embodiment, the first directed graph construction unit includes:

[0052] The vertex determination subunit is configured to execute generation of a vertex corresponding to each pointer variable;

[0053] The assignment variable determination subunit is configured to determine an assignment variable and an assigned variable in any two pointer variables according to the assignment relationship between the two pointer variables, wherein the assigned variable is used to receive the value assigned by the assignment variable;

[0054] A directed edge determination subunit, configured to execute creation of a directed edge from the vertex corresponding to the assigned variable to the vertex corresponding to the assigned variable;

[0055] A generating subunit is configured to generate the first directed graph according to the vertices and the directed edges.

[0056] In an exemplary embodiment, the vertex stores the variable type and scope level of the pointer variable represented by the vertex, and the candidate stack pointer variable determination unit includes:

[0057] The stack pointer variable determination subunit is configured to execute, according to the variable types stored in the vertices corresponding to the plurality of pointer variables, obtaining a preset number of stack pointer variables whose variable types are the pointer types on the stack from the plurality of pointer variables;

[0058] The traversal subunit is configured to traverse each stack pointer variable in sequence, and perform the following operations when traversing each stack pointer variable;

[0059] The candidate stack pointer variable determination subunit is configured to determine each stack pointer variable as the candidate stack pointer variable when there is no first target vertex on the first path in the first directed graph and there is no second path in the first directed graph; wherein the first path is a path that can be reached from the vertex corresponding to each stack pointer variable in the first directed graph, the second path is a path from the second target vertex in the first directed graph to the vertex corresponding to each pointer variable, the first target vertex represents the vertex corresponding to the pointer variable having a scope level less than the scope level of each stack pointer variable, and the second target vertex represents the vertex corresponding to the pointer variable having a scope level greater than the scope level of each pointer variable.

[0060] In an exemplary embodiment, the number of the to-be-processed functions is multiple, and the apparatus further includes:

[0061] A second directed graph generation module is configured to generate a second directed graph corresponding to the multiple functions to be processed based on the calling relationship between the multiple functions to be processed; the vertices in the second directed graph represent the functions to be processed, and the edges in the second directed graph represent the calling relationship between any two functions to be processed;

[0062] an objective function determination module, configured to perform a depth-first traversal of the second directed graph based on a preset depth-first search algorithm, and determine a preset number of objective functions from the multiple functions to be processed based on the traversal result, wherein the preset number of objective functions represent strongly connected components in the second directed graph;

[0063] A first function sequence determination module is configured to perform reverse sorting of the preset number of objective functions according to a calling sequence among the preset number of objective functions when there is no recursive call among the preset number of objective functions to obtain a first function sequence;

[0064] The first construction module is configured to execute, in sequence, construction of a first directed graph corresponding to each function in the first function sequence according to the order of each function in the first function sequence, multiple pointer variables in each function in the first function sequence, and the assignment relationship between the multiple pointer variables in each function in the first function sequence.

[0065] In an exemplary embodiment, the device further comprises:

[0066] A recursive calling function acquisition module is configured to acquire a recursive calling function when the recursive calling exists between the preset number of target functions, wherein the recursive calling function includes a plurality of target functions that have the recursive calling between them;

[0067] A second function sequence determination module is configured to perform reverse sorting of the recursively called function and the other functions according to a calling sequence between the recursively called function and the other functions to obtain a second function sequence, wherein the other functions represent functions other than the recursively called function among the preset number of target functions;

[0068] The second construction module is configured to execute, in sequence, construction of a first directed graph corresponding to each function in the second function sequence according to the order of each function in the second function sequence, the multiple pointer variables in each function in the second function sequence, and the assignment relationship between the multiple pointer variables in each function in the second function sequence.

[0069] In an exemplary embodiment, the device further comprises:

[0070] A running module, configured to execute a target program compiled from the source program, wherein the target program includes a plurality of operation information, and the plurality of operation information includes the reference count operation information;

[0071] The update module is configured to update the reference count when executing the reference count operation information.

[0072] According to a third aspect of an embodiment of the present disclosure, there is provided an electronic device, including:

[0073] processor;

[0074] A memory for storing instructions executable by the processor; wherein the processor is configured to execute the instructions to implement the operation information generating method as described above.

[0075] According to a fourth aspect of an embodiment of the present disclosure, a computer-readable storage medium is provided. When instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device executes the operation information generating method as described above.

[0076] According to a fifth aspect of an embodiment of the present disclosure, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the above-mentioned operation information generating method is implemented.

[0077] The technical solution provided by the embodiments of the present disclosure brings at least the following beneficial effects:

[0078] In the disclosed embodiment, two different attributes (normal attributes and borrowed attributes) are pre-marked on the stack pointer variable during the compilation period of the source program. When it is determined that the attribute information of multiple target stack pointer variables is the borrowed attribute, the generation of reference count operation information is refused, thereby reducing the amount of reference count operation information generated during the compilation period, optimizing unnecessary ARC operations, and avoiding frequent updates of reference counts during the operation of the target program compiled from the source program, which would cause additional burden on the operation of the target program, thereby reducing resource consumption and improving the throughput of the target program.

[0079] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0080] The drawings herein are incorporated into and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the description are used to explain the principles of the present disclosure, and do not constitute improper limitations on the present disclosure.

[0081] Figure 1 The present invention is a flowchart of a method for generating operation information according to an exemplary embodiment.

[0082] Figure 2 The present invention is a flowchart showing a method of labeling borrowed attributes and common attributes according to an exemplary embodiment.

[0083] Figure 3 The diagram is a schematic diagram showing a method of creating edges in a first directed graph through an assignment relationship according to an exemplary embodiment.

[0084] Figure 4 A process of constructing a first directed graph according to an exemplary embodiment is shown Figure 1 .

[0085] Figure 5 The invention is a flowchart showing a method of determining a candidate stack pointer variable from stack pointer variables according to an exemplary embodiment.

[0086] Figure 6 A process of constructing a first directed graph according to an exemplary embodiment is shown Figure 2 .

[0087] Figure 7 It is a schematic diagram showing recursive calls between a preset number of objective functions according to an exemplary embodiment.

[0088] Figure 8 The figure is a block diagram of a device for generating operation information according to an exemplary embodiment.

[0089] Fig. 9 The invention is a block diagram of an electronic device for generating operation information according to an exemplary embodiment. DETAILED DESCRIPTION

[0090] In order to enable ordinary persons in the art to better understand the technical solutions of the present disclosure, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the accompanying drawings.

[0091] It should be noted that the terms "first", "second", etc. in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.

[0092] First, the technical terms involved in the embodiments of the present disclosure are explained:

[0093] Stack: refers to a special linear table that can only perform insertion and deletion operations at one end. It stores data according to the first-in-last-out principle. The first data entered is pushed to the bottom of the stack, and the last data is at the top of the stack. When data needs to be read, data is popped from the top of the stack (the last data is read out first). In a computer system, the stack is a dynamic memory area with the above properties. The program can push data into the stack and pop data from the top of the stack. The stack saves the maintenance information required when a function is called during program execution, namely the stack frame or activity record. The stack frame generally contains the return address and parameters of the function, as well as temporary variables (including non-static local variables of the function and other temporary variables automatically generated by the compiler).

[0094] Heap: refers to a special type of data structure in computer science. A heap is usually an array object that can be viewed as a tree. The heap satisfies the following properties: the value of a node in the heap is not greater than or less than the value of its parent node and the heap is a complete binary tree. The heap stores arrays and objects.

[0095] Heap object: refers to an object that can be created or deleted at any time during the program running.

[0096] Pointer: refers to the address of a unit, the content of which stores data. In C language, pointers are generally considered to be pointer variables. The content of pointer variables stores the first address of the object they point to. The object pointed to can be a variable (pointer variables are also variables), arrays, functions and other entities that occupy storage space.

[0097] Pointer variable: a variable that stores a memory address. Unlike other types of variables, it is specifically used to store memory addresses and is also called an address variable. In C language, pointer variables are allowed to store pointers. Therefore, the value of a pointer variable is the address of a memory unit or a pointer to a memory unit.

[0098] Scope: refers to the range of variable availability. Generally speaking, the names used in a program code are not always valid and available, and the code range that limits the availability of this name is the scope of this name. The use of scope can improve the locality of program logic, enhance program reliability, and reduce name conflicts. From the perspective of scope, variables can be divided into global variables and local variables.

[0099] Definition of scope level size: If the lifetime of variable a is greater than the lifetime of variable b, or the visibility range of variable a is greater than the visibility range of variable b, then the scope level of a is greater than the scope of b.

[0100] Figure 1 FIG. 1 is a flow chart of a method for generating operation information according to an exemplary embodiment. Figure 1 As shown, the process includes the following steps.

[0101] In step S11, a source program and a plurality of target stack pointer variables having an assignment relationship in the source program are obtained.

[0102] Specifically, source code (also called source code) refers to an uncompiled text file written in accordance with certain programming language specifications, which is a series of human-readable computer language instructions.

[0103] Exemplarily, the source program may be subjected to lexical analysis, syntax analysis, semantic analysis, and type checking to determine the types of variables and expressions in the source program.

[0104] Optionally, the variables in the source program may include pointer variables and non-pointer variables.

[0105] Specifically, the stack pointer variable refers to the pointer variable on the stack, that is, the pointer variable existing on the stack.

[0106] Optionally, the above-mentioned assignment relationship may include an explicitly existing assignment relationship and an implicitly existing assignment relationship.

[0107] Exemplarily, the displayed assignment relationship is as follows: for example, a=b, variable b is assigned to variable a. The displayed assignment relationship represents actual parameters (actual parameters), which contain real data and will be used by the code inside the function.

[0108] For example, the implicit assignment relationship is as follows: For example, when calling a function, the value of a formal parameter (formal parameter) is passed. The formal parameter can be regarded as a placeholder, which has no data and can only receive the passed data when the function is called.

[0109] Specifically, in the above step S11, multiple target stack pointer variables having an assignment relationship can be obtained from multiple pointer variables in the source program according to the above explicit assignment relationship and implicit assignment relationship.

[0110] In step S13, the attribute information of the above-mentioned multiple target stack pointer variables is obtained.

[0111] Specifically, the attribute information (borrowed attribute or common attribute) of the target stack pointer variable is pre-marked.

[0112] In an exemplary embodiment, the above operation information generation method can be used in the following scenario: if the pointer variable on the stack (i.e., the stack pointer variable) is within its scope, it is not passed to a pointer variable within a higher scope by direct or indirect assignment, that is, the scope of the referenced heap object will not be expanded. Then, within the scope of the stack pointer variable, there is no need to perform an ARC operation on the heap object referenced by the stack pointer variable. Because in this case, the reference count of the heap object referenced by the stack pointer variable will not change at the beginning and end of the life cycle of the stack pointer variable, that is, the increase and decrease of the reference count will offset each other.

[0113] Specifically, in order to be able to model the above scenario, two properties of the stack pointer variable can be predefined:

[0114] Borrowed attribute: If a stack pointer variable will not be assigned to a pointer variable with a larger scope level (i.e., the first other pointer variable), and the stack pointer variable will not reference the heap object referenced by a pointer variable with a smaller scope level (i.e., the second other pointer variable), then when such pointer variables (i.e., pointer variables whose attribute information is all borrowed attributes) are assigned to each other, no ARC operation is required. That is, the borrowed attribute is used to indicate that in the process of assigning values ​​to each other, the reference counts of the heap objects referenced by the multiple target stack pointer variables are refused to be updated.

[0115] For example, a source code may be as follows:

[0116]

[0117] Among them, the local pointer variables a and b in the Test function in the source program, and the parameter variable a of the Print function can all be marked as the borrowed attribute. Then, the assignment transfer generated by Print(a) and b:=a does not require ARC operation (that is, refusing to update the reference count of the referenced heap object), and the heap object can have its memory reclaimed at the end of the function life cycle.

[0118] Normal attribute: This attribute is the default annotation attribute of the stack pointer variable and requires ARC operation (i.e., updating the reference count of the referenced heap object). That is, the above normal attribute is used to indicate that during the mutual assignment of the above multiple target stack pointer variables, the reference count of the above heap object referenced by the above multiple target stack pointer variables is updated.

[0119] Among them, the pointer of the normal attribute can be assigned to the pointer of the borrowed attribute, but the pointer of the borrowed attribute cannot be assigned to the pointer of the normal attribute.

[0120] In step S15, when the attribute information of the above-mentioned multiple target stack pointer variables is a borrowing attribute, the reference count operation information is refused to be generated; the above-mentioned borrowing attribute is used to indicate that in the process of mutual assignment of the above-mentioned multiple target stack pointer variables, the reference count of the heap object referenced by the above-mentioned multiple target stack pointer variables is refused to be updated.

[0121] In a feasible embodiment, the above method may further include:

[0122] In the case where the attribute information of the above-mentioned multiple target stack pointer variables is a common attribute, the above-mentioned reference count operation information is generated; the above-mentioned common attribute is used to indicate that the above-mentioned reference count is updated during the above-mentioned assignment process.

[0123] Specifically, the reference count operation information represents an instruction to update the reference count of the heap object. Optionally, the update includes increasing (ie, adding 1 to the reference count) and decreasing (ie, subtracting 1 from the reference count).

[0124] Optionally, when the attribute information of a plurality of target stack pointer variables having an assignment relationship with each other is a common attribute, reference count operation information of the heap object is generated.

[0125] Optionally, when the attribute information of multiple target stack pointer variables that have an assignment relationship with each other is a borrowing attribute, the counting operation information is refused to be generated.

[0126] Since the stack pointer variable can be annotated with two different attributes (normal attributes and borrowed attributes) in advance during the compilation of the source program, when it is determined that the attribute information of multiple target stack pointer variables with an assignment relationship is a normal attribute, reference count operation information of the heap object is generated, and when it is determined that the attribute information of a target stack pointer variable is a borrowed attribute, the reference count operation information is refused to be generated, thereby reducing the amount of reference count operation information generated during the compilation period, avoiding unnecessary ARC operations, and avoiding frequent updates of reference counts during the operation of the target program compiled from the source program, which would cause additional burden on the operation of the target program, thereby reducing resource consumption and improving the throughput of the target program.

[0127] Figure 2 FIG. 1 is a flowchart showing a method of labeling borrowed attributes and common attributes according to an exemplary embodiment. Figure 2 As shown, in an optional embodiment, the method further includes: marking the common attributes and the borrowed attributes, and the marking of the common attributes and the borrowed attributes may include:

[0128] In step S21, a function to be processed in the source program is obtained, where the function to be processed includes a plurality of pointer variables.

[0129] The disclosed embodiment will annotate the attribute information of variables during the process of compiling the source program into the target program. Exemplarily, the process of compiling the source program into the target program is divided into five stages: lexical analysis, syntax analysis, semantic analysis and intermediate code generation stage, code optimization stage, and target code generation program stage.

[0130] Specifically, the function to be processed is an encapsulation of a section of code, which can be called through the function name and parameters and is the basic component unit of the program.

[0131] Exemplarily, lexical analysis, syntax analysis, semantic analysis, and type checking may be performed on the source program to determine the types of variables and expressions in the target program.

[0132] Optionally, type checking includes checking the types of expressions and variables. Type checking is mainly to determine whether the actual type of the variable or parameter matches the declared type. This type checking can facilitate early detection of type mismatch problems without waiting until the target program is executed, thereby reducing the cost of the problem.

[0133] In step S23, a first directed graph corresponding to the function to be processed is constructed based on the above-mentioned multiple pointer variables and the assignment relationship between the above-mentioned multiple pointer variables; the vertices of the above-mentioned first directed graph represent the above-mentioned pointer variables, and the edges of the above-mentioned first directed graph represent the assignment relationship between any two pointer variables.

[0134] Exemplarily, the expressions and statements in the function to be processed may be analyzed to obtain a plurality of pointer variables in the function to be processed and the assignment relationship between the plurality of pointer variables.

[0135] Optionally, the assignment relationship between the multiple pointer variables may include the above-mentioned explicitly existing assignment relationship and the above-mentioned implicitly existing assignment relationship.

[0136] Specifically, when constructing the first directed graph, the vertices in the graph represent pointer type variables, and the edges represent the assignment relationships between variables. Optionally, the vertices in the graph will store attributes such as the scope level of the variable and whether it is a pointer variable on the stack.

[0137] Figure 3 FIG. 1 is a schematic diagram showing a method of creating an edge in a first directed graph by assigning a value relationship according to an exemplary embodiment. Figure 3 As shown, the pointer assignment expression "p=q" can create an edge from vertex p to vertex q.

[0138] In step S25, the attribute information of the stack pointer variable among the plurality of pointer variables is marked as the common attribute.

[0139] Specifically, the attribute information of each stack pointer variable is marked as a common attribute by default.

[0140] In step S27, based on the vertex corresponding to the stack pointer variable among the above-mentioned multiple pointer variables, the position in the above-mentioned first directed graph, and the scope of the above-mentioned stack pointer variable, candidate stack pointer variables are determined from the above-mentioned stack pointer variables, and the above-mentioned candidate stack pointer variables include the above-mentioned multiple target stack pointer variables.

[0141] In step S29, the attribute information of the candidate stack pointer variable is updated from the common attribute to the borrowed attribute.

[0142] Specifically, the graph theory method can be combined to determine the candidate stack pointer variables that need to be marked as borrowed attributes from the stack pointer variables according to the vertices corresponding to the stack pointer variables among the multiple pointer variables, the positions in the above-mentioned first directed graph, and the scopes of the stack pointer variables, and update the attribute information of the candidate stack pointer variables from ordinary attributes to borrowed attributes.

[0143] Exemplarily, the corresponding attribute information can also be saved in the vertices of the stack pointer variable in the first directed graph. That is, the vertices in the first directed graph not only save the scope level and variable type of the represented pointer variable, but also store the borrowing attribute or common attribute of whether the pointer variable performs the ARC operation in the process of mutual assignment of other pointer variables.

[0144] The disclosed embodiment constructs a first directed graph corresponding to the function to be processed according to multiple pointer variables in the function to be processed and the assignment relationship between the multiple pointer variables (the vertices of the first directed graph represent the pointer variables, and the edges of the first directed graph represent the assignment relationship between any two pointer variables), and then determines a candidate stack pointer variable from the stack pointer variables according to the position of the vertex corresponding to the stack pointer variable (the attributes of the stack pointer variable are defaulted to the common attributes for performing ARC operations) among the multiple pointer variables in the first directed graph, and the scope of the stack pointer variable, and finally updates the attributes of the candidate stack pointer variable from the common attributes to the borrowed attributes that do not perform ARC operations, thereby updating the candidate stack pointer variable with the In the process of mutual assignment of other pointer variables, the reference count of the heap object referenced by it is not adjusted, thereby optimizing unnecessary ARC operations, avoiding frequent updates of reference counts, and affecting the overall performance of the target program when it is running; in addition, the present disclosure can improve the calculation accuracy of heap object reference counts through the above method, ensure that garbage memory can be recovered in time, thereby reducing the consumption of system resources by the heap object reference counting process, avoiding additional burden on the target program when it is running, and effectively improving the performance of the target program; in addition, the above attribute information labeling is performed during the compilation process, which is imperceptible to users and does not require user access, thereby reducing the cost of attribute information labeling.

[0145] Figure 4 A process of constructing a first directed graph according to an exemplary embodiment is shown Figure 1 .like Figure 4 As shown, in a possible embodiment, in the above step S23, constructing the first directed graph corresponding to the above function to be processed according to the above multiple pointer variables and the assignment relationship between the above multiple pointer variables may include:

[0146] In step S2301, the vertex corresponding to each pointer variable is generated.

[0147] In step S2303, according to the assignment relationship between any two pointer variables, the assigning variable and the assigned variable in the above arbitrary two pointer variables are determined, and the above assigned variable is used to accept the value assigned by the above assigning variable.

[0148] In step S2305, a directed edge is created from the vertex corresponding to the assigned variable to the vertex corresponding to the assigned variable.

[0149] In step S2307, the first directed graph is generated according to the vertices and the directed edges.

[0150] Exemplarily, the vertex corresponding to each pointer variable may be generated according to the position of each pointer vector in space.

[0151] Continue as Figure 3 As shown, Figure 3 The assignment relationship in is: assign the value of variable q to variable p, then variable q is the assigned variable, variable p is the assigned variable, and variable p accepts the value assigned by variable q.

[0152] Continue as Figure 3 As shown, a directed edge can be created from the vertex corresponding to the variable p to the vertex corresponding to the variable q. In this way, a directed edge between any two pointer variables among multiple pointer variables can be obtained, thereby generating the first directed graph.

[0153] Exemplarily, the first directed graph may be a directed unweighted graph. Specifically, an unweighted graph means that the line between two points has no length, that is, if the two points are connected, the distance between them is 1, and if they are not connected, the distance between them is 0.

[0154] In the disclosed embodiment, according to multiple pointer variables in the function to be processed and the assignment relationship between the multiple pointer variables, the assignment variable and the assigned variable among any two of the above pointer variables are determined, and a directed edge is created from the vertex corresponding to the above assigned variable to the vertex corresponding to the above assignment variable, so as to generate the first directed graph according to the above vertices and the above directed edges. The first directed graph created in this way can accurately reflect the position relationship of each pointer variable in space, as well as the assignment relationship between them. Through the first directed graph, the candidate stack pointer variables that need to be marked as borrowed attribute information can be accurately determined, so as to ensure the generation of accurate reference count operation information, and further ensure the accurate control of the reference count of the heap object.

[0155] Figure 5 FIG. 1 is a flowchart showing a method of determining a candidate stack pointer variable from a stack pointer variable according to an exemplary embodiment. Figure 5 As shown, in a feasible embodiment, the vertex stores the variable type and scope level of the pointer variable represented by the vertex. In the step S27, the step of determining the candidate stack pointer variable from the stack pointer variables according to the vertex corresponding to the stack pointer variable in the plurality of pointer variables, the position in the first directed graph, and the scope of the stack pointer variable may include:

[0156] In step S2701, according to the variable types stored in the vertices corresponding to the above-mentioned multiple pointer variables, a preset number of stack pointer variables whose variable types are stack pointer types are obtained from the multiple pointer variables.

[0157] Specifically, since each vertex corresponding to each pointer variable stores the variable type of each pointer variable, the variable type may include a stack pointer variable type, a heap pointer variable type, etc. According to the variable type, a preset number of stack pointer variables whose variable type is a stack pointer type can be obtained from multiple pointer variables.

[0158] In step S2703, each stack pointer variable is traversed in sequence, and the following operations are performed when traversing each stack pointer variable.

[0159] In step S2705, when there is no first target vertex on the first path in the above-mentioned first directed graph and there is no second path in the above-mentioned first directed graph, each stack pointer variable is determined to be the above-mentioned candidate stack pointer variable; wherein the above-mentioned first path is a path that can be reached from the vertex corresponding to each stack pointer variable in the above-mentioned first directed graph, and the above-mentioned second path is a path in the above-mentioned first directed graph that starts from the second target vertex and reaches the vertex corresponding to each pointer variable, the above-mentioned first target vertex represents the vertex corresponding to the pointer variable whose scope level is less than the scope level of each stack pointer variable, and the above-mentioned second target vertex represents the vertex corresponding to the pointer variable whose scope level is greater than the scope level of each pointer variable.

[0160] Assuming that the vertex corresponding to a stack pointer variable a is vertex A, in the above-mentioned first directed graph, if there is no vertex corresponding to a pointer variable with a scope level less than the scope level of the stack pointer variable a on the first path that can be reached from vertex A, and there is no second path that reaches the vertex A from the vertex corresponding to the pointer variable with a scope level greater than the scope level of the stack pointer variable a, it means that the stack pointer variable a will not be assigned to a pointer variable with a higher level of scope, and the stack pointer variable a will not reference the heap object referenced by the pointer variable with a smaller level of scope, then when the stack pointer variable a and other pointer variables (pointer variables with attribute information of borrowing attributes) are assigned to each other, there is no need to perform ARC operation, and it is considered that the attribute information of the stack pointer variable a is a candidate stack pointer variable that needs to be marked as a borrowing attribute. By means of the path and scope of the vertices of the stack pointer variable in the first directed graph, the candidate stack pointer variable that needs to be marked as a borrowing attribute can be accurately determined, thereby ensuring the generation of accurate reference count operation information, and then ensuring accurate control of the reference count of the heap object.

[0161] Figure 6 A process of constructing a first directed graph according to an exemplary embodiment is shown Figure 2 .like Figure 6 As shown, in an optional embodiment, the number of the above-mentioned functions to be processed is multiple, and the above-mentioned method may also include:

[0162] In step S31, based on the calling relationship between multiple functions to be processed, a second directed graph corresponding to the multiple functions to be processed is generated; the vertices in the second directed graph represent the functions to be processed, and the edges in the second directed graph represent the calling relationship between any two functions to be processed.

[0163] Exemplarily, the process of generating the first directed graph may be as follows:

[0164] Each function to be processed is used as a vertex in the second directed graph. According to the calling relationship between any two functions, a calling function and a called function in any two functions are determined, and the calling function calls the called function.

[0165] Create a directed edge from the vertex corresponding to the calling function to the directed edge corresponding to the called function, and generate a second directed graph based on the vertex and the directed edge.

[0166] For example, if function a calls function b and function c, then in the directed graph there are directed edges from vertex a to vertex b and vertex c respectively.

[0167] In step S33, a depth-first traversal is performed on the second directed graph based on a preset depth-first search algorithm, and a preset number of target functions are determined from the multiple functions to be processed based on the traversal results. The preset number of target functions represent strongly connected components in the second directed graph.

[0168] Specifically, a strongly connected component means that in a directed graph G, if there is a directed path from u to v between two vertices u and v, and there is also a directed path from v to u, then the two vertices are said to be strongly connected. If every two vertices of a directed graph G are strongly connected, G is called a strongly connected graph. A maximal strongly connected subgraph of a directed non-strongly connected graph is called a strongly connected component.

[0169] Optionally, the preset depth-first search algorithm may include but is not limited to: Tarjan algorithm, Gabow algorithm, etc. Below, taking Tarjan algorithm as an example, the calculation principle of strongly connected components is introduced:

[0170] The Tarjan algorithm is based on a depth-first search of the graph. Each strongly connected component is a subtree in the search tree. When searching, the unprocessed nodes in the current search tree are added to a stack. When backtracking, it can be determined whether the node from the top of the stack to the stack is a strongly connected component.

[0171] Define DFN(u) as the order number (timestamp) of the search for node u, and Low(u) as the order number of the earliest node in the stack that u or its subtree can be traced back to.

[0172] When DFN(u) = Low(u), all nodes on the search subtree with u as the root are a strongly connected component.

[0173] In step S35, when there is no recursive call between the preset number of objective functions, the preset number of objective functions are sorted in reverse order according to the calling sequence between the preset number of objective functions to obtain a first function sequence.

[0174] Specifically, recursive call refers to a special kind of nested call, where a function calls itself or calls other functions and then calls itself again. As long as functions calling each other can generate a loop, it must be a recursive call.

[0175] If there are no recursive calls between the preset number of objective functions, each objective function (i.e., strongly connected component) is an independent function, and the function called at the bottom layer will be ranked first.

[0176] Assume that the target function includes fa, fb, fc and fd, fa calls fb, fb calls fc, and fc calls fd. Since there is no recursive call between fa, fb, fc and fd, the first function sequence is: fd, fc, fb and fa.

[0177] In step S37, according to the order of each function in the first function sequence, the multiple pointer variables in each function in the first function sequence, and the assignment relationship between the multiple pointer variables in each function in the first function sequence, the first directed graph corresponding to each function in the first function sequence is constructed in sequence.

[0178] Specifically, the first directed graph corresponding to each function in the first function sequence can be constructed in sequence according to the order of each function in the first function sequence. The construction process of the first directed graph can be found in the above steps S2301 to S2307, which will not be described in detail here.

[0179] In the embodiment of the present disclosure, when there are multiple functions to be processed, a second directed graph corresponding to the multiple functions to be processed can be constructed, and the strongly connected components in the second directed graph are determined according to a preset depth-first search algorithm. Subsequently, it is only necessary to construct a first directed graph for the target function corresponding to the strongly connected component, and there is no need to construct a first directed graph for each function to be processed, thereby reducing the construction scale of the first directed graph, reducing the consumption of system resources, and improving the efficiency of attribute information labeling; in addition, when there is no recursive call between the target functions, each target function is sorted as an independent individual to obtain a first function sequence, and when constructing the first directed graph, the first directed graph corresponding to each function in the first function sequence is constructed in sequence according to the sorting of each function in the first function sequence, that is, the first directed graph of the bottom-level called function is first constructed, and the first directed graph of the bottom-level called function is vector-labeled, and by constructing a directed graph and vector-labeling the functions in order from lower calling complexity to higher calling complexity, it is beneficial to improve the speed and accuracy of the first directed graph construction, thereby improving the speed and accuracy of the vector attribute information labeling.

[0180] In another optional embodiment, continue as Figure 6 As shown, the above method may also include:

[0181] In step S36, in the case that the above-mentioned recursive calls exist between the above-mentioned preset number of target functions, a recursive calling function is obtained, and the above-mentioned recursive calling function includes a plurality of target functions that have the above-mentioned recursive calls between each other.

[0182] In step S38, the recursively called function and the other functions are sorted in reverse order according to the calling sequence between the recursively called function and the other functions to obtain a second function sequence, wherein the other functions represent the functions among the preset number of target functions except the recursively called function.

[0183] In step S310, according to the order of each function in the second function sequence, the multiple pointer variables in each function in the second function sequence, and the assignment relationship between the multiple pointer variables in each function in the second function sequence, a first directed graph corresponding to each function in the second function sequence is constructed in sequence.

[0184] Specifically, if there are recursive calls, the strongly connected components with recursive calls are the function sets of the recursive calls, and the strongly connected components with recursive calls can be sorted as a whole.

[0185] For example, another source code may be as follows:

[0186]

[0187]

[0188] The source code includes a preset number of target functions (ie, f1, f2, f3, f4 and Main).

[0189] Figure 7 FIG. 1 is a schematic diagram showing a recursive call between a preset number of objective functions according to an exemplary embodiment. Figure 7 As shown, the calling relationship between the preset number of target functions is:

[0190] 1) Main—f1—f2—f3—f1; 2) Main—f1—f2—f4.

[0191] Since there are recursive calls between f1, f2, and f3, f1, f2, and f3 are considered as a whole. Since the bottom-level called function is f4, the second function sequence is: f4, (f1, f2, f3), main. (f1, f2, f3) is the recursive calling function, and f4 and main are other functions.

[0192] Specifically, the first directed graph corresponding to each function in the second function sequence can be constructed in sequence according to the order of each function in the second function sequence. The construction process of the first directed graph can be found in the above steps S2301 to S2307, which will not be described in detail here.

[0193] In the disclosed embodiment, when there are recursive calls between various target functions, the target function with recursive calls is sorted as a whole with other non-recursive call functions to obtain a second function sequence, and the first directed graph corresponding to each function in the second function sequence is constructed in sequence, that is, the first directed graph of the bottom-level called function is first constructed, and the first directed graph of the bottom-level called function is vector attribute labeled. By constructing a directed graph and performing feature labeling on the functions in order from lower call complexity to higher call complexity, it is helpful to improve the speed and accuracy of the first directed graph construction, thereby improving the speed and accuracy of attribute information labeling. In addition, since the target function with recursive calls is a whole, when constructing the first directed graph, it is only necessary to construct the first directed graph corresponding to the whole, and there is no need to construct the first directed graph corresponding to each function in the whole, which reduces the number of first directed graphs to be constructed, further reduces the consumption of system resources, and further improves the speed of vector attribute information labeling.

[0194] In an exemplary embodiment, the above method may further include:

[0195] A target program compiled from the source program is run, wherein the target program includes a plurality of operation information, and the plurality of operation information includes the reference count operation information.

[0196] When the reference count operation information is executed, the reference count is updated.

[0197] Optionally, the target program is compiled from the source program, which includes but is not limited to user programs and application software packages. The user program is the part of the software provided to meet the application needs of users in different fields and different problems. The application software package is a collection of programs designed to solve certain types of problems using computers and is used by multiple users.

[0198] In the embodiment of the present disclosure, during the operation of the target program, when the reference count operation information is executed, the reference count of the referenced heap object is updated. Since in the process of generating reference count operation information during the compilation process, when the attribute information of multiple target stack pointer variables is a borrowed attribute, the reference count operation information is refused to be generated, thereby avoiding unnecessary ARC operations. Therefore, during the operation of the target program, the number of reference count operation information executed is greatly reduced, thereby avoiding the frequent update of the reference count to cause additional burden on the operation of the target program, thereby reducing resource consumption and improving the throughput of the target program; in addition, the present disclosure can improve the calculation accuracy of the reference count of the heap object through the above method, and at the end of its life cycle, the heap object can be used for memory recovery to ensure that the garbage memory can be recovered in time, thereby further avoiding the additional burden on the target program during operation, and effectively improving the performance of the target program.

[0199] Figure 8 is a block diagram of an operation information generating device according to an exemplary embodiment. Figure 8 The device includes a first acquisition module 41, a second acquisition module 43 and a first generation module 45.

[0200] The first acquisition module 41 is configured to execute and acquire a source program and a plurality of target stack pointer variables having an assignment relationship in the source program.

[0201] The second acquisition module 43 is configured to execute acquisition of attribute information of the above-mentioned multiple target stack pointer variables.

[0202] The first generation module 45 is configured to execute, when the attribute information of the above-mentioned multiple target stack pointer variables is a borrowing attribute, refusing to generate reference count operation information; the above-mentioned borrowing attribute is used to indicate that in the process of mutual assignment of the above-mentioned multiple target stack pointer variables, the reference count of the heap object referenced by the above-mentioned multiple target stack pointer variables is refused to be updated.

[0203] In an exemplary embodiment, the above-mentioned device also includes: a second generation module, configured to generate the above-mentioned reference count operation information when the attribute information of the above-mentioned multiple target stack pointer variables is a normal attribute; the above-mentioned normal attribute is used to indicate that the above-mentioned reference count is updated during the above-mentioned assignment process.

[0204] In an exemplary embodiment, the apparatus further includes a marking module for marking the borrowed attributes and the common attributes, and the marking module includes:

[0205] A to-be-processed function acquisition unit is configured to execute and acquire the to-be-processed function in the source program, wherein the to-be-processed function includes a plurality of pointer variables;

[0206] A first directed graph construction unit is configured to construct a first directed graph corresponding to the function to be processed according to the plurality of pointer variables and the assignment relationship between the plurality of pointer variables; the vertices of the first directed graph represent the pointer variables, and the edges of the first directed graph represent the assignment relationship between any two pointer variables;

[0207] A labeling unit is configured to label the attribute information of the stack pointer variable among the plurality of pointer variables as the common attribute;

[0208] a candidate stack pointer variable determining unit, configured to determine candidate stack pointer variables from the stack pointer variables according to a vertex corresponding to a stack pointer variable among the plurality of pointer variables, a position in the first directed graph, and a scope of the stack pointer variable, wherein the candidate stack pointer variables include the plurality of target stack pointer variables;

[0209] The attribute updating unit is configured to update the attribute information of the candidate stack pointer variable from the common attribute to the borrowed attribute.

[0210] In an exemplary embodiment, the first directed graph construction unit includes:

[0211] The vertex determination subunit is configured to execute generation of a vertex corresponding to each pointer variable;

[0212] The assignment variable determination subunit is configured to determine the assignment variable and the assigned variable in any two pointer variables according to the assignment relationship between the two pointer variables, wherein the assigned variable is used to receive the value assigned by the assignment variable;

[0213] A directed edge determination subunit is configured to execute creation of a directed edge from the vertex corresponding to the assigned variable to the vertex corresponding to the assigned variable;

[0214] The generating subunit is configured to generate the first directed graph according to the vertices and the directed edges.

[0215] In an exemplary embodiment, the vertex stores the variable type and scope level of the pointer variable represented by the vertex, and the candidate stack pointer variable determination unit includes:

[0216] The stack pointer variable determination subunit is configured to execute, according to the variable types stored in the vertices corresponding to the above-mentioned multiple pointer variables, to obtain a preset number of stack pointer variables whose variable types are the pointer types on the stack from the multiple pointer variables;

[0217] The traversal subunit is configured to traverse each stack pointer variable in sequence, and perform the following operations when traversing each stack pointer variable;

[0218] The candidate stack pointer variable determination subunit is configured to determine each stack pointer variable as the candidate stack pointer variable when there is no first target vertex on the first path in the first directed graph and there is no second path in the first directed graph; wherein the first path is a path that can be reached from the vertex corresponding to each stack pointer variable in the first directed graph, the second path is a path from the second target vertex in the first directed graph to the vertex corresponding to each pointer variable, the first target vertex represents the vertex corresponding to the pointer variable having a scope level less than the scope level of each stack pointer variable, and the second target vertex represents the vertex corresponding to the pointer variable having a scope level greater than the scope level of each pointer variable.

[0219] In an exemplary embodiment, the number of the functions to be processed is multiple, and the apparatus further includes:

[0220] A second directed graph generation module is configured to generate a second directed graph corresponding to the plurality of to-be-processed functions based on the calling relationship between the plurality of to-be-processed functions; the vertices in the second directed graph represent the to-be-processed functions, and the edges in the second directed graph represent the calling relationship between any two to-be-processed functions;

[0221] An objective function determination module is configured to perform a depth-first traversal of the second directed graph based on a preset depth-first search algorithm, and determine a preset number of objective functions from the multiple functions to be processed based on the traversal result, wherein the preset number of objective functions represent strongly connected components in the second directed graph;

[0222] The first function sequence determination module is configured to perform, when there is no recursive call between the preset number of target functions, reverse sorting of the preset number of target functions according to the calling sequence between the preset number of target functions to obtain a first function sequence;

[0223] The first construction module is configured to execute, in sequence, construction of a first directed graph corresponding to each function in the first function sequence according to the order of each function in the first function sequence, multiple pointer variables in each function in the first function sequence, and the assignment relationship between the multiple pointer variables in each function in the first function sequence.

[0224] In an exemplary embodiment, the above device further comprises:

[0225] A recursive calling function acquisition module is configured to acquire a recursive calling function when the recursive calling exists between the preset number of target functions, wherein the recursive calling function includes a plurality of target functions that have the recursive calling between each other;

[0226] A second function sequence determination module is configured to perform reverse sorting of the recursively called function and the other functions according to a calling sequence between the recursively called function and the other functions to obtain a second function sequence, wherein the other functions represent functions other than the recursively called function among the preset number of target functions;

[0227] The second construction module is configured to execute, in sequence, construction of a first directed graph corresponding to each function in the second function sequence according to the order of each function in the second function sequence, the multiple pointer variables in each function in the second function sequence, and the assignment relationship between the multiple pointer variables in each function in the second function sequence.

[0228] In an exemplary embodiment, the above device further comprises:

[0229] The running module is configured to execute a target program compiled from the source program, wherein the target program includes a plurality of operation information, and the plurality of operation information includes the reference count operation information.

[0230] The update module is configured to update the reference count when executing the reference count operation information.

[0231] Regarding the device in the above embodiment, the specific manner in which each module performs the operation has been described in detail in the embodiment of the method, and will not be elaborated here.

[0232] In an exemplary embodiment, an electronic device is also provided, including a processor; a memory for storing instructions executable by the processor; wherein the processor is configured to implement the steps of any operation information generating method in the above-mentioned embodiments when executing the instructions stored in the memory.

[0233] The electronic device may be a terminal, a server or a similar computing device. For example, the electronic device is a server. Fig. 9It is a block diagram of an electronic device for generating operation information according to an exemplary embodiment. The electronic device 50 may have relatively large differences due to different configurations or performances, and may include one or more central processing units (CPU) 51 (the central processing unit 51 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA), a memory 53 for storing data, and one or more storage media 52 (such as one or more mass storage devices) for storing application programs 523 or data 522. Among them, the memory 53 and the storage medium 52 can be short-term storage or permanent storage. The program stored in the storage medium 52 may include one or more modules, each of which may include a series of instruction operations in the electronic device. Furthermore, the central processing unit 51 can be configured to communicate with the storage medium 52 to execute a series of instruction operations in the storage medium 52 on the electronic device 50. The electronic device 50 may also include one or more power supplies 56, one or more wired or wireless network interfaces 55, one or more input and output interfaces 54, and / or one or more operating systems 521, such as Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, etc.

[0234] The input / output interface 54 may be used to receive or send data via a network. The specific example of the network may include a wireless network provided by a communication provider of the electronic device 50. In one example, the input / output interface 54 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In an exemplary embodiment, the input / output interface 54 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0235] It can be understood by those skilled in the art that Fig. 9 The structure shown is only for illustration and does not limit the structure of the above electronic device. Fig. 9 More or fewer components as shown, or with Fig. 9 Different configurations are shown.

[0236] In an exemplary embodiment, a computer-readable storage medium is also provided. When instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device can execute the steps of any operation information generating method in the above embodiments.

[0237] In an exemplary embodiment, a computer program product is also provided, including a computer program, and when the computer program is executed by a processor, the operation information generating method provided in any one of the above embodiments is implemented.

[0238] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided by the present disclosure can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).

[0239] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.

[0240] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.

Claims

1. A method for generating operation information, It is characterized in that include: Acquire a source program and a plurality of target stack pointer variables having an assignment relationship in the source program; Obtaining attribute information of the multiple target stack pointer variables; When the attribute information of the multiple target stack pointer variables is a borrowing attribute, the reference count operation information is refused to be generated; the borrowing attribute is used to indicate that during the mutual assignment process of the multiple target stack pointer variables, the reference count of the heap object referenced by the multiple target stack pointer variables is refused to be updated.

2. The operation information generating method according to claim 1, It is characterized in that The method further comprises: In the case where the attribute information of the multiple target stack pointer variables is a common attribute, the reference count operation information is generated; the common attribute is used to indicate that the reference count is updated during the assignment process.

3. The operation information generating method according to claim 2, It is characterized in that The method further includes marking the common attributes and the borrowed attributes, wherein marking the common attributes and the borrowed attributes includes: Obtaining a function to be processed in the source program, wherein the function to be processed includes a plurality of pointer variables; According to the multiple pointer variables and the assignment relationship between the multiple pointer variables, construct a first directed graph corresponding to the function to be processed; the vertices of the first directed graph represent the pointer variables, and the edges of the first directed graph represent the assignment relationship between any two pointer variables; Marking the attribute information of the stack pointer variable among the multiple pointer variables as the common attribute; Determine candidate stack pointer variables from the stack pointer variables according to the vertex corresponding to the stack pointer variable among the multiple pointer variables, the position in the first directed graph, and the scope of the stack pointer variable, the candidate stack pointer variables including the multiple target stack pointer variables; The attribute information of the candidate stack pointer variable is updated from the common attribute to the borrowed attribute.

4. The operation information generating method according to claim 3, It is characterized in that The step of constructing a first directed graph corresponding to the function to be processed according to the plurality of pointer variables and the assignment relationship between the plurality of pointer variables comprises: Generate the vertex corresponding to each pointer variable; According to the assignment relationship between any two pointer variables, determining an assigning variable and an assigned variable in the any two pointer variables, wherein the assigned variable is used to receive the value assigned by the assigning variable; Create a directed edge from the vertex corresponding to the assigned variable to the vertex corresponding to the assigned variable; The first directed graph is generated according to the vertices and the directed edges.

5. The operation information generating method according to claim 3, It is characterized in that The vertex stores a variable type and a scope level of a pointer variable represented by the vertex, and the determining a candidate stack pointer variable from the stack pointer variables according to a vertex corresponding to a stack pointer variable among the multiple pointer variables, a position in the first directed graph, and a scope of the stack pointer variable, comprises: According to the variable types stored in the vertices corresponding to the multiple pointer variables, a preset number of stack pointer variables whose variable types are stack pointer types are obtained from the multiple pointer variables; Traverse each stack pointer variable in turn, and perform the following operations when traversing each stack pointer variable; In a case where there is no first target vertex on the first path in the first directed graph and there is no second path in the first directed graph, determining each stack pointer variable as the candidate stack pointer variable; Among them, the first path is a path that can be reached from the vertex corresponding to each stack pointer variable in the first directed graph, and the second path is a path from the second target vertex to the vertex corresponding to each pointer variable in the first directed graph, the first target vertex represents the vertex corresponding to the pointer variable whose scope level is smaller than the scope level of each stack pointer variable, and the second target vertex represents the vertex corresponding to the pointer variable whose scope level is greater than the scope level of each pointer variable.

6. The method for generating operation information according to any one of claims 3 to 5, It is characterized in that The number of the functions to be processed is multiple, and the method further includes: Based on the calling relationship between the multiple functions to be processed, generating a second directed graph corresponding to the multiple functions to be processed; the vertices in the second directed graph represent the functions to be processed, and the edges in the second directed graph represent the calling relationship between any two functions to be processed; Performing a depth-first traversal on the second directed graph based on a preset depth-first search algorithm, and determining a preset number of target functions from the multiple functions to be processed based on the traversal result, wherein the preset number of target functions represent strongly connected components in the second directed graph; In the case where there is no recursive call between the preset number of objective functions, the preset number of objective functions are sorted in reverse order according to the calling sequence between the preset number of objective functions to obtain a first function sequence; According to the order of each function in the first function sequence, the multiple pointer variables in each function in the first function sequence, and the assignment relationship between the multiple pointer variables in each function in the first function sequence, a first directed graph corresponding to each function in the first function sequence is constructed in sequence.

7. An operation information generating device, It is characterized in that include: A first acquisition module is configured to execute and acquire a source program and a plurality of target stack pointer variables having an assignment relationship in the source program; A second acquisition module is configured to execute acquisition of attribute information of the plurality of target stack pointer variables; The first generation module is configured to refuse to generate reference count operation information when the attribute information of the multiple target stack pointer variables is a borrowing attribute; the borrowing attribute is used to indicate that during the mutual assignment process of the multiple target stack pointer variables, the reference count of the heap object referenced by the multiple target stack pointer variables is refused to be updated.

8. An electronic device, It is characterized in that include: processor; A memory for storing instructions executable by the processor; wherein the processor is configured to execute the instructions to implement the operation information generating method according to any one of claims 1 to 6. 9 . A computer-readable storage medium. When instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device executes the operation information generating method according to claim 1 .

10. A computer program product comprising a computer program, It is characterized in that When the computer program is executed by a processor, the operation information generating method according to any one of claims 1 to 6 is implemented.

Citation Information

Patent Citations

  • Reference count implementation method and device

    CN111736925A

  • Accelerating reference count processing in object deletion

    US20180239597A1

  • Hardware apparatuses, methods, and systems for individually revocable capabilities for enforcing temporal memory safety

    US20210200546A1