Weighted dependency graph-based concurrent program execution trajectory static simplification method
Technical Field
The invention belongs to the technical field of software testing, in particular to the field of concurrent program debugging, and is used for helping developers to quickly understand and repair errors in concurrent programs.
Background
The rise of multi-core architecture processors has rapidly broken through the performance bottleneck of single-core processors. To accommodate hardware upgrades, programming must transition to multithreading. Therefore, concurrent programs are becoming the mainstream of the software development industry today. However, concurrency deficiencies can result due to the concurrent program's shared memory mechanism and thread scheduling uncertainty. Unlike serial programs, these concurrency flaws occur under a particular thread schedule, i.e., with contingencies. Even if a concurrency defect occurs in a certain program execution, the concurrency defect cannot be easily reproduced in the next execution, thereby bringing great trouble to the debugging work of the concurrency program.
The simplification of the execution track of the concurrent program can effectively help developers to quickly understand and repair the concurrent defects, and the program debugging efficiency is improved. By simplifying the execution track of the concurrent program, on one hand, the execution speed of the concurrent program can be improved on the premise of ensuring the recurrence of the concurrent defects, and on the other hand, the method is also beneficial to a developer to reason the reasons for causing the concurrent defects, thereby repairing the defects more accurately.
The main goal of concurrent program execution trace simplification is to reduce the number of thread switches. This problem has proven to be an optimization problem. The existing concurrent program execution trajectory simplification method mainly comprises the following 2 types: inline and offline simplifications. Inline simplification simplifies the trace by accurately acquiring shared memory dependencies on-the-fly using vector clock or lock distribution techniques, and then grouping variables using either transfer conventions or thread/space localization. The online simplification is accurate but less efficient. Offline simplification is a relatively straightforward simplification method. It first obtains the entire execution trajectory and then performs the simplified operation on the trajectory. A traditional simplification method based on a graph randomly selects a local edge, judges whether nodes at two ends of the local edge can be combined or not, and combines the nodes if the conditions are met. However, its randomness reduces the efficiency of concurrent program execution trace simplification, and in some cases, an optimal simplified trace cannot be obtained.
Disclosure of Invention
The invention aims to provide a method for statically simplifying the execution track of a concurrent program based on a weighted dependency graph, which solves the problem that the existing method for simplifying the execution track of the concurrent program cannot quickly and effectively obtain the optimal simplified track, further reduces context switching in the original track as much as possible, improves the working efficiency of software debugging and better infers the reason of the concurrency defect.
To achieve the above objective, the present invention provides a method for statically simplifying concurrent program execution traces based on a weighted dependency graph. The method comprises the following steps:
1) calculating an event dependency relationship, namely dividing two adjacent events into a local dependency and a remote dependency by judging whether the two adjacent events in an original track are in the same thread or not, and further dividing the two adjacent events into a conflict dependency and a synchronous dependency according to the two adjacent event types belonging to the remote dependency, wherein the conflict dependency comprises a read-write dependency, a write-read dependency and a write-write dependency, and the synchronous dependency comprises an unlocking and locking dependency, a thread creation and opening dependency, a thread quitting and ending dependency and a wakeup waiting dependency;
2) constructing a weighted dependency graph, namely constructing the weighted dependency graph by using the dependency relationship calculated in the step 1), adding a local edge and updating the node degree only when remote dependency occurs, otherwise, combining the node with the previous node, adding a remote edge and updating the node degree, and finally updating the weight of the local edge;
3) simplifying the weighted dependency graph, which is an iterative process, wherein each iteration selects a local edge with the minimum weight from the initial weighted dependency graph constructed in the step 2), and judges whether the local edge meets a merging condition, if the local edge is unreachable except the local edge from the entry node to the exit node, the local edge indicates that no other dependent event exists between the two nodes and the local edge can be merged, otherwise, the local edge cannot be merged, the degree of the relevant node and the weight of the relevant edge are updated after merging, and the iteration is carried out until all the local edges are checked once, so that the process of simplifying the weighted dependency graph is ended;
4) topological sorting, namely, for the simplified weighted dependency graph obtained in the step 3), generating a linear sequence by using an existing topological sorting algorithm, wherein the sequence is a final simplified concurrent program execution track, the occurrence sequence of events in the track still obeys the dependency relationship in the original track, and the track contains the least context switches.
Further, the specific steps of the step 1) are as follows:
step 1) -1: an initial state;
step 1) -2: judging whether two adjacent events belong to the same thread;
step 1) -3: if the two current events belong to the same thread, the two current events belong to local dependency and are added into a local dependency list;
step 1) -4: if the two current events do not belong to the same thread, further judging whether the two current events are two adjacent events with synchronous primitives, if so, judging that the two current events belong to synchronous dependency and adding the two current events into a synchronous dependency list;
step 1) -5: otherwise, the current two events belong to conflict dependency and are added into a conflict dependency list;
step 1) -6: judging whether all adjacent nodes are completely calculated, if so, executing the steps 1-7, otherwise, moving the checker forwards, returning to the steps 1-2, and continuously calculating the dependency relationship of two adjacent events;
step 1) -7: finishing the calculation of the event dependency relationship;
further, the specific steps of the step 2) are as follows:
step 2) -1: an initial state;
step 2) -2: adding local edges and updating the degree of the nodes;
step 2) -3: adding remote edges and updating the degree of the node;
step 2) -4: updating the weight of the local edge;
step 2) -5: finishing the construction of the initial weighted dependency graph;
further, the specific steps of the step 3) are as follows:
step 3) -1: an initial state;
step 3) -2: selecting a local edge with the minimum weight;
step 3) -3: judging whether a merging condition is met, if so, executing the steps 3) -4, otherwise, returning to the steps 3) -2, and reselecting a local edge with the minimum weight;
step 3) -4: combining the nodes at two ends of the local edge;
step 3) -5: updating the degree of the related node;
step 3) -6: updating the weight of the relevant edge;
step 3) -7: judging whether all edges are checked, if so, executing the steps 3) -8, otherwise, returning to the steps 3) -2, and continuously selecting a local edge with the minimum weight;
step 3) -8: simplifying the weighted dependency graph;
further, the specific steps of the step 4) are as follows:
step 4) -1: an initial state;
step 4) -2: selecting a topological sorting algorithm;
step 4) -3: generating a sequence by using the topological sorting algorithm selected in the step 4) -2;
step 4) -4: the simplified concurrent program execution track is generated;
the invention simplifies the concurrent program execution track based on the weighted dependency graph, improves the understanding of the concurrent defects and improves the efficiency of simplifying the concurrent program execution track; calculating the dependency relationship of all events in the original execution track, constructing an initial weighted dependency graph, simplifying the weighted dependency graph as much as possible on the premise of not breaking the event dependency relationship, and finally performing topological sorting on the simplified weighted dependency graph by using a topological sorting algorithm to generate a linear sequence, namely the simplified concurrent program execution track. Therefore, the reason of the concurrent defects caused by the concurrent defects is rapidly inferred, the debugging efficiency of the concurrent program is improved, and the repairing accuracy of the concurrent defects is further improved.
Drawings
Fig. 1 is a flowchart of a method for statically simplifying a concurrent program execution path based on a weighted dependency graph according to an embodiment of the present invention.
Fig. 2 is a flowchart of event dependency calculation in fig. 1.
FIG. 3 is a flow chart of the weighted dependency graph construction of FIG. 1.
FIG. 4 is a simplified flow diagram of the weighted dependency graph of FIG. 1.
Fig. 5 is a flow chart of the topology ranking of fig. 1.
Detailed Description
In order to better understand the technical content of the present invention, specific embodiments are described below with reference to the accompanying drawings.
Fig. 1 is a flowchart of a method for statically simplifying a concurrent program execution path based on a weighted dependency graph according to an embodiment of the present invention.
A method for statically simplifying a concurrent program execution path based on a weighted dependency graph is characterized by comprising the following steps:
1) calculating an event dependency relationship, namely dividing two adjacent events into a local dependency and a remote dependency by judging whether the two adjacent events in an original track are in the same thread or not, and further dividing the two adjacent events into a conflict dependency and a synchronous dependency according to the two adjacent event types belonging to the remote dependency, wherein the conflict dependency comprises a read-write dependency, a write-read dependency and a write-write dependency, and the synchronous dependency comprises an unlocking and locking dependency, a thread creation and opening dependency, a thread quitting and ending dependency and a wakeup waiting dependency;
2) building a weighted dependency graph, adding a local edge and updating the node degree only when remote dependency occurs, otherwise combining the node with the previous node, then adding a remote edge and updating the node degree, and finally updating the weight of the local edge;
3) simplifying the weighted dependency graph, iteratively selecting a local edge with the minimum weight from the constructed initial weighted dependency graph, judging whether the local edge meets a merging condition, if the local edge is unreachable except the local edge from an entry node to an exit node, indicating that no other dependent event exists between the two nodes, merging the local edge and the entry node, otherwise, not merging the local edge, updating the degree of the relevant node and the weight of the relevant edge after merging, iterating until all the local edges are checked once, and ending the simplification process of the weighted dependency graph;
4) and topological sorting, namely for the simplified weighted dependency graph, generating a linear sequence by using an existing topological sorting algorithm, wherein the sequence is a final simplified concurrent program execution track, the occurrence sequence of events in the track still obeys the dependency relationship in the original track, and the track contains the least context switching.
FIG. 2 is a flow chart of event dependency calculation. Judging whether two adjacent events in an original track are in the same thread, dividing the two adjacent events into local dependence and remote dependence, and further dividing the two adjacent events into conflict dependence and synchronous dependence according to the two adjacent event types belonging to the remote dependence, wherein the conflict dependence comprises read-write dependence, write-read dependence and write-write dependence, and the synchronous dependence comprises unlocking and locking dependence, thread creation and opening dependence, thread quitting and ending dependence and awakening and waiting dependence. The method comprises the following specific steps:
step 1: an initial state; step 2: judging whether two adjacent events belong to the same thread; and step 3: if the two current events belong to the same thread, the two current events belong to local dependency and are added into a local dependency list; and 4, step 4: if the two current events do not belong to the same thread, further judging whether the two current events are two adjacent events with synchronous primitives, if so, judging that the two current events belong to synchronous dependency and adding the two current events into a synchronous dependency list; and 5: otherwise, the current two events belong to conflict dependency and are added into a conflict dependency list; step 6: judging whether all adjacent nodes are completely calculated, if so, executing a step 7, otherwise, moving the checker forwards, returning to the step 2, and continuously calculating the dependency relationship of two adjacent events; and 7: and finishing the calculation of the event dependency relationship.
FIG. 3 is a flow chart of weighted dependency graph construction. And starting to construct an initial weighted dependency graph according to the event dependency relationship, adding a local edge and updating the node degree only when remote dependency occurs, otherwise, merging the node into the last node, then adding a remote edge and updating the node degree, and finally updating the weight of the local edge. The method comprises the following specific steps:
step 1: an initial state; step 2: adding local edges and updating the degree of the nodes; and step 3: adding remote edges and updating the degree of the node; and 4, step 4: updating the weight of the local edge; and 5: the initial weighted dependency graph is constructed.
Fig. 4 is a simplified flow diagram of a weighted dependency graph. Iteratively selecting a local edge with the minimum weight from the constructed initial weighted dependency graph, judging whether the local edge meets a merging condition, if the local edge is unreachable except the local edge from an ingress node to an egress node, indicating that no other dependent event exists between the two nodes, merging the local edge and the ingress node, otherwise, not merging the local edge, updating the degree of the relevant node and the weight of the relevant edge after merging, iterating until all local edges are checked, and ending the simplification process of the weighted dependency graph. The method comprises the following specific steps:
step 1: an initial state; step 2: selecting a local edge with the minimum weight; and step 3: judging whether a merging condition is met, if so, executing the step 4, otherwise, returning to the step 2, and reselecting a local edge with the minimum weight; and 4, step 4: combining the nodes at two ends of the local edge; and 5: updating the degree of the related node; step 6: updating the weight of the relevant edge; and 7: judging whether all edges are checked, if so, executing a step 8, otherwise, returning to the step 2, and continuously selecting a local edge with the minimum weight; and 8: and simplifying the weighted dependency graph.
FIG. 5 is a flow chart of topology ranking. For the simplified weighted dependency graph, an existing topological sorting algorithm is used for generating a linear sequence, the linear sequence is a final simplified concurrent program execution track, the occurrence sequence of events in the track still obeys the dependency relationship in the original track, and the track contains the least context switching. The method comprises the following specific steps:
step 1: an initial state; step 2: selecting a topological sorting algorithm; and step 3: generating a sequence by using the topological sorting algorithm selected in the step 2; and 4, step 4: and finishing the generation of the execution track of the simplified concurrent program.
In conclusion, the invention solves the problem that the prior concurrent program execution trajectory method can not quickly and effectively obtain the optimal simplified trajectory, not only reduces the context switching in the original trajectory to the maximum extent, but also reduces a large amount of time consumed by the concurrency program execution trajectory simplification process due to randomness, and further improves the concurrent program debugging efficiency, thereby providing guarantee for accurately repairing the concurrent defects.