CN106201874B - The MHP analysis method and device of concurrent program - Google Patents

The MHP analysis method and device of concurrent program Download PDF

Info

Publication number
CN106201874B
CN106201874B CN201610527181.2A CN201610527181A CN106201874B CN 106201874 B CN106201874 B CN 106201874B CN 201610527181 A CN201610527181 A CN 201610527181A CN 106201874 B CN106201874 B CN 106201874B
Authority
CN
China
Prior art keywords
thread
node
mhp
analyzed
control flow
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201610527181.2A
Other languages
Chinese (zh)
Other versions
CN106201874A (en
Inventor
周卿
李炼
冯晓兵
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Huawei Technologies Co Ltd
Institute of Computing Technology of CAS
Original Assignee
Huawei Technologies Co Ltd
Institute of Computing Technology of CAS
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Huawei Technologies Co Ltd, Institute of Computing Technology of CAS filed Critical Huawei Technologies Co Ltd
Priority to CN201610527181.2A priority Critical patent/CN106201874B/en
Publication of CN106201874A publication Critical patent/CN106201874A/en
Application granted granted Critical
Publication of CN106201874B publication Critical patent/CN106201874B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3604Software analysis for verifying properties of programs
    • G06F11/3608Software analysis for verifying properties of programs using formal methods, e.g. model checking, abstract interpretation

Abstract

The embodiment of the present invention provides the MHP analysis method and device of a kind of concurrent program, a kind of MHP analysis method of concurrent program includes: since the main thread of concurrent program to be analyzed, one thread of selection every time, simulate the execution of concurrent program to be analyzed, wherein, when the thread for simulating execution can not continue to execute, any thread simulation continued to execute is jumped to execute, until all threads simulation of concurrent program to be analyzed is finished, wherein, concurrent program to be analyzed includes at least two threads;According to concurrent program to be analyzed carry out simulation execution as a result, corresponding with the concurrent program to be analyzed Multi-thread control flow graph of building;Multi-thread control flow graph is handled, obtains guarding correct Multi-thread control flow graph, the concurrent MHP result of possibility for guarding each node in correct Multi-thread control flow graph, which is not present, to be failed to report;MHP analysis is carried out to correct Multi-thread control flow graph is guarded, obtains the MHP analysis result of concurrent program to be analyzed.

Description

The MHP analysis method and device of concurrent program
Technical field
The present embodiments relate to field of computer technology more particularly to the MHP analysis methods and dress of a kind of concurrent program It sets.
Background technique
With the development of computer technology, computer develops to multicore era by monokaryon, is developed to by single machine processing big The processing of scale cluster.The development of computer equally promotes the development of computer software, even to this day, had up to hundreds of Computer programming language be continuously created, such as universal C/C++, Java, Python etc..Various big software programs, example Such as operating system, database, large software game, are exactly the code of rows up to a million easily, these big software programs may Need team's experience that can just developed for many years.So, how more effectively software program to be debugged, and carried out The problems such as program correctness verifying and optimization, becomes as the research hotspot in computer software exploitation.
With the development of multiple programming, the analysis to concurrent program is the hot issue of software program analysis again.And stroke Sequence analysis wants complicated many relative to serial program analysis.The analysis of serial program be mainly based upon control stream, pointer analysis with And program control flow and data-flow analysis on the fundamental analysis such as definite value reference, what key was serial program is in the nature any It is carved at one and only a sentence can execute.And for concurrent program, any one moment, there may be a plurality of Different threads or the sentence of process are performed simultaneously, and whether then how may concurrently execute between determining program sentence just becomes simultaneously One research direction of line program analysis.
The basic reason of Parallel Program Analysis complexity is that existing simultaneously multiple and different threads or the parallel of process statements holds Row, this makes different threads or the sentence of process on executing sequence there are uncertain relationship, and such uncertainty relation It then may cause the serious error of program.Then a basic problem in Parallel Program Analysis is exactly possible concurrent (May Happen in Parallel, MHP) analysis, the result of this analysis is exactly all possibility parallel subqueries an of sentence Set, or judge any 2 sentences whether there may be parallel execution relationships.The supplementary set of this problem, which gives, to be certainly existed The sentence set of precedence relationship in execution.After having MHP analysis, so that it may in conjunction with the method for serial analysis, do pointer analysis, number According to flow point analysis etc..
Before carrying out MHP analysis to program, need first to construct controlling stream graph (Control Flow corresponding with program Graph, CFG), then MHP analysis is carried out based on CGF.And for concurrent program, how to construct correct multithreading CFG figure It is the key that guarantee MHP analysis correctness.But the method for building multithreading GFG is too simple at present, generally only investigates creation (creat) primitive and the analysis of locking (lock)/unlock (unlock) primitive, and ignore and (Happens-Before) formerly occurs The importance of analysis causes analysis result to have very big wrong report or fail to report when so that carrying out MHP analysis according to CFG.
Summary of the invention
The embodiment of the present invention provides the MHP analysis method and device of a kind of concurrent program, for improve to concurrent program into The accuracy of row MHP analysis.
First aspect provides a kind of MHP analysis method of concurrent program, comprising:
Since the main thread of concurrent program to be analyzed, a thread is selected every time, simulates the concurrent program to be analyzed Execution, wherein when the thread for simulating execution can not continue to execute, jump to it is any continue to execute thread simulation It executes, until all threads simulation of the concurrent program to be analyzed is finished, wherein the concurrent program to be analyzed includes At least two threads;
According to the concurrent program to be analyzed carry out simulation execution as a result, building with the concurrent program pair to be analyzed The Multi-thread control flow graph answered;
The Multi-thread control flow graph is handled, obtains guarding correct Multi-thread control flow graph, it is described to guard just There is no fail to report the concurrent MHP result of the possibility of each node in true Multi-thread control flow graph;
Correct Multi-thread control flow graph progress MHP analysis is guarded to described, obtains the MHP of the concurrent program to be analyzed Analyze result.
MHP analysis method provided in an embodiment of the present invention, it is corresponding with concurrent program to be analyzed multi-thread program-controlled by constructing Then flow graph processed is handled the Multi-thread control flow graph, obtain guarding correct Multi-thread control flow graph, conservative just to this True Multi-thread control flow graph carries out MHP analysis, so that the MHP for obtaining concurrent program to be analyzed is analyzed as a result, due to multithreading CFG be it is conservative correctly, therefore it is higher to the building accuracy of multithreading CFG, MHP analysis is carried out according to multithreading CFG The result wrong report of acquisition is less also there is no failing to report, and improves the accuracy rate that MHP analysis is carried out to concurrent program.
It is described that the Multi-thread control flow graph is handled in a kind of possible implementation of first aspect, it obtains Guard correct Multi-thread control flow graph, comprising:
If addition primitive node in the Multi-thread control flow graph and multiple thread match, delete it is all with it is described plus Enter the side of primitive node connection;
If waiting primitive node and multiple triggering primitive node matchings in the Multi-thread control flow graph are deleted all The side being connect with the waiting primitive node;
Using obtained Multi-thread control flow graph as guarding correct Multi-thread control flow graph.
Due to when carrying out MHP analysis, judging that it is correct matched excessively complexity with which thread actually that primitive, which is added, because This can delete all sides connecting with addition primitive herein, can make in this way when carrying out MHP analysis, it is believed that after primitive is added The sentence in face all may be concurrent with addition primitive, this is a kind of wrong report, but is not failed to report.Similarly, primitive and triggering primitive are waited Match, if therefore the waiting primitive node in multi-thread program-controlled CFG and multiple triggering primitive node matchings, delete and wait original The side of language node connection.By above-mentioned processing, that is, it can guarantee that obtained multithreading CFG is conservative correct.
It is described to guard correct Multi-thread control flow graph progress to described in a kind of possible implementation of first aspect MHP analysis obtains the MHP analysis result of the concurrent program to be analyzed, comprising:
Calculate the non-concurrent set and productive set for guarding each node in correct Multi-thread control flow graph, wherein The non-concurrent set expression of node A can not be concurrent with node A node set, the productive set of node A indicates that node A is produced The set of raw node;
Correct Multi-thread control flow graph is guarded according to the iterative calculation of the non-concurrent set and productive set of each node is described In each node MHP analysis as a result, until the MHP analysis result convergence, obtain the concurrent program to be analyzed MHP analysis As a result.
It is described since the main thread in a kind of possible implementation of first aspect, a thread is selected every time, Simulate the execution of the concurrent program to be analyzed, wherein when the thread for simulating execution can not continue to execute, jump to and appoint The one thread simulation that can be continued to execute executes, until all threads simulation of the concurrent program to be analyzed is finished, comprising:
Step 1 selects a thread, the execution of the thread of analog selection, when described since the main thread every time When the thread of selection can not continue to execute, locks the selected thread and record the current position letter of the selected thread Breath;
Step 2 jumps to any first thread being not locked out and can continue to execute, simulates holding for the first thread Row, when the first thread can not continue to execute, locks the first thread and records the current position of the first thread Information, until all threads that is not locked out and can continue to execute are modeled execution;
Step 3 releases all locked threads, and repeats step 2, until the concurrent program to be analyzed All thread simulations are finished.
The method simulation provided according to embodiments of the present invention executes the multithreading CFG of obtained result detection, can be true The relationship in concurrent program to be analyzed between each thread is embodied, to obtain accurately and reliably multithreading CFG.
In a kind of possible implementation of first aspect, the execution of the thread of the analog selection, comprising:
Using the execution of the thread of depth-first search analytic approach analog selection;
The execution of the simulation first thread, comprising:
The execution of the first thread is simulated using depth-first search analytic approach.
It is described to record the current location information of the selected thread in a kind of possible implementation of first aspect, Include:
The mark of the selected thread and the mark of current sentence are recorded in scheduling information table;
It is described to record the current location information of the first thread, comprising:
The mark of the first thread and the mark of current sentence are recorded in the scheduling information table.
Second aspect provides a kind of MHP analytical equipment of concurrent program, comprising:
Execution module is simulated, for selecting a thread every time since the main thread of concurrent program to be analyzed, simulates institute State the execution of concurrent program to be analyzed, wherein when the thread for simulating execution can not continue to execute, jump to it is any can be after The continuous thread executed, which is simulated, to be executed, until all threads simulation of the concurrent program to be analyzed is finished, wherein it is described to Analyzing concurrent program includes at least two threads;
Controlling stream graph construct module, for according to the concurrent program to be analyzed carry out simulation execution as a result, building Multi-thread control flow graph corresponding with the concurrent program to be analyzed;
Controlling stream graph processing module obtains conservative correctly multi-thread for handling the Multi-thread control flow graph Process control flow graph, there is no fail to report the concurrent MHP result of possibility for guarding each node in correct Multi-thread control flow graph;
MHP analysis module, for guarding correct Multi-thread control flow graph to described and carry out MHP analysis, obtain it is described to The MHP for analyzing concurrent program analyzes result.
In a kind of possible implementation of second aspect, the controlling stream graph processing module, if being specifically used for described more Addition primitive node in thread controlling stream graph and multiple thread match are then deleted and all are added what primitive node was connect with described Side;If waiting primitive node and multiple triggering primitive node matchings in the Multi-thread control flow graph, delete all and institute State the side for waiting the connection of primitive node;Using obtained Multi-thread control flow graph as guarding correct Multi-thread control flow graph.
In a kind of possible implementation of second aspect, the MHP analysis module is specifically used for calculating described guard just The non-concurrent set and productive set of each node in true Multi-thread control flow graph, wherein the non-concurrent set expression of node A without The set of method and node A concurrent node, the productive set of node A indicate the set of node caused by node A;According to each section The non-concurrent set and productive set of point iterate to calculate the MHP analysis for guarding each node in correct Multi-thread control flow graph As a result, until MHP analysis result convergence, obtains the MHP analysis result of the concurrent program to be analyzed.
In a kind of possible implementation of second aspect, the simulation execution module is specifically used for executing following steps: Step 1 selects a thread, the execution of the thread of analog selection, when the selected line since the main thread every time When Cheng Wufa is continued to execute, locks the selected thread and record the current location information of the selected thread;Step 2, Any first thread being not locked out and can continue to execute is jumped to, the execution of the first thread is simulated, when the First Line When Cheng Wufa is continued to execute, lock the first thread and record the current location information of the first thread, until it is all not Thread that is locked and can continuing to execute is modeled execution;Step 3 releases all locked threads, and repeats step Rapid two, until all threads simulation of the concurrent program to be analyzed is finished.
In a kind of possible implementation of second aspect, the simulation execution module is specifically used for using depth-first The execution of the thread of searching analysis method analog selection;The execution of the first thread is simulated using depth-first search analytic approach.
In a kind of possible implementation of second aspect, the simulation execution module is specifically used in scheduling information table The mark of the middle mark for recording the selected thread and current sentence;The First Line is recorded in the scheduling information table The mark of journey and the mark of current sentence.
MHP analysis method provided in an embodiment of the present invention and device are corresponding with concurrent program to be analyzed more by constructing Then thread controlling stream graph is handled the Multi-thread control flow graph, obtain guarding correct Multi-thread control flow graph, to this Guard correct Multi-thread control flow graph and carry out MHP analysis, thus obtain the MHP analysis of concurrent program to be analyzed as a result, due to Multithreading CFG be it is conservative correctly, therefore it is higher to the building accuracy of multithreading CFG, carried out according to multithreading CFG The result wrong report that MHP analysis obtains is less also there is no failing to report, and improves the accuracy rate that MHP analysis is carried out to concurrent program.
Detailed description of the invention
In order to more clearly explain the embodiment of the invention or the technical proposal in the existing technology, to embodiment or will show below There is attached drawing needed in technical description to be briefly described, it should be apparent that, the accompanying drawings in the following description is this hair Bright some embodiments for those of ordinary skill in the art without any creative labor, can be with Other attached drawings are obtained according to these attached drawings.
Fig. 1 is the flow chart of the MHP analysis method embodiment one of concurrent program provided in an embodiment of the present invention;
Fig. 2 is the flow chart of the MHP analysis method embodiment two of concurrent program provided in an embodiment of the present invention;
Fig. 3 is the flow chart of the MHP analysis method embodiment three of concurrent program provided in an embodiment of the present invention;
Fig. 4 is the structural schematic diagram of the MHP analytical equipment embodiment one of concurrent program provided in an embodiment of the present invention.
Specific embodiment
In order to make the object, technical scheme and advantages of the embodiment of the invention clearer, below in conjunction with the embodiment of the present invention In attached drawing, technical scheme in the embodiment of the invention is clearly and completely described, it is clear that described embodiment is A part of the embodiment of the present invention, instead of all the embodiments.Based on the embodiments of the present invention, those of ordinary skill in the art All other embodiment obtained without creative efforts, shall fall within the protection scope of the present invention.
During being compiled to concurrent program, when constructing the CFG of concurrent program, need to match the wound in each thread Build (creat)/addition (join) primitive, triggering (signal)/wait (wait) primitive, locking (lock)/unlock (unlock) Primitive.Wherein creat/join primitive, the matching between signal/wait primitive constitute Happens-Before problem, because The sentence that these primitive act on it is shown in that there are specific partial ordering relation, this partial ordering relation is inevitable during program really executes The execution order relation of satisfaction.So if analysis program cannot catch this partial order feature well, analysis result is necessarily adjoint A large amount of error analysis (such as the sentence that centainly cannot concurrently execute be judged as may be concurrent).
Fig. 1 is the flow chart of the MHP analysis method embodiment one of concurrent program provided in an embodiment of the present invention, such as Fig. 1 institute Show, MHP analysis method provided in this embodiment includes:
Step S101 selects a thread since the main thread of concurrent program to be analyzed every time, simulates to be analyzed parallel The execution of program, wherein when the thread for simulating execution can not continue to execute, jump to any thread continued to execute Simulation executes, until all threads simulation of concurrent program to be analyzed is finished, wherein concurrent program to be analyzed includes at least Two threads.
Specifically, MHP analysis method provided in this embodiment is applied to during being compiled to concurrent program.For One concurrent program to be analyzed, due to parallel feature, including multiple threads, one of thread is main thread, should be to Analysis concurrent program is executed since main thread.
In the present embodiment, first since the main thread of concurrent program to be analyzed, a thread is selected every time, to each Thread is analyzed, the execution of the thread of analog selection.There is a principle for the simulation of per thread, exactly when simulating When the thread of execution can not continue to execute, then jump to any one thread simulation execution that can be continued to execute.It is above-mentioned to continue The thread of execution can meet the condition that can be continued to execute during certain threads are performed and therefore repeat the above steps, can It is all simulated with to be analysed to all threads of concurrent program and is finished.
Step S102, according to concurrent program to be analyzed carry out simulation execution as a result, building with concurrent program to be analyzed Corresponding Multi-thread control flow graph.
Specifically, after all threads to concurrent program to be analyzed are all simulated execution, you can learn that each thread Between relationship, i.e., whether there is creat/join, the matching of signal/wait, lock/unlock primitive are closed between each thread System.According to the matching relationship between each thread, multithreading GFG corresponding with concurrent program to be analyzed can be constructed.
Step S103 handles Multi-thread control flow graph, obtains guarding correct Multi-thread control flow graph, guards just There is no fail to report the MHP result of each node in true Multi-thread control flow graph.
Specifically, multithreading CFG corresponding with concurrent program to be analyzed embody in concurrent program to be analyzed thread it Between logical relation, carrying out analysis to multithreading CFG can be obtained analysis result to concurrent program to be analyzed.Due to right When program carries out MHP analysis, in fact it could happen that two kinds of mistakes, one kind to fail to report, i.e., will likely concurrent sentence be judged as can not be simultaneously Hair, another kind are wrong report, that is, would be impossible to concurrent sentence and be judged as concurrent.When carrying out static analysis to program, it is ensured that point The case where there is no fail to report in analysis result then claims to guard when the result correct.
Step S104 carries out MHP analysis to correct Multi-thread control flow graph is guarded, obtains concurrent program to be analyzed MHP analyzes result.
Specifically, after obtaining guarding correct multithreading CFG, MHP analysis can be carried out to it, obtains analysis result. The analysis result is to reflect the MHP analysis result of concurrent program to be analyzed.Since multithreading CFG is to guard correctly, It is higher to the building accuracy of multithreading CFG, it is less that the result wrong report that MHP analysis obtains is carried out according to multithreading CFG There is no failing to report, the accuracy rate that MHP analysis is carried out to concurrent program is improved.
MHP analysis method provided in this embodiment, by constructing Multi-thread control stream corresponding with concurrent program to be analyzed Figure, then handles the Multi-thread control flow graph, obtains guarding correct Multi-thread control flow graph, conservative correct to this Multi-thread control flow graph carries out MHP analysis, so that the MHP for obtaining concurrent program to be analyzed is analyzed as a result, since multithreading CFG is It is conservative correct therefore higher to the building accuracy of multithreading CFG, carry out what MHP analysis obtained according to multithreading CFG As a result it reports less be also not present by mistake to fail to report, improves the accuracy rate for carrying out MHP analysis to concurrent program.
It, can be to step in order to guarantee that the multithreading CFG obtained after handling multithreading CFG is to guard correctly The multithreading CFG that S102 is obtained is handled as follows: if addition primitive node and multiple threads in Multi-thread control flow graph Match, then deletes all sides connecting with addition primitive node;If waiting primitive node and multiple touchings in Multi-thread control flow graph Primitive node matching is sent out, then deletes the side connecting with the waiting primitive node;Using obtained Multi-thread control flow graph as guarantor Keep correct Multi-thread control flow graph.
It specifically, is for matching with creation primitive since primitive is added, but multiple creation primitive may be using one A identical mark, therefore addition primitive may match with multiple threads, but only one of them thread is that primitive is added to answer It is correct matched.Due to when carrying out MHP analysis, judging that it is correct matched excessively multiple with which thread actually that primitive, which is added, It is miscellaneous, therefore all sides connecting with addition primitive can be deleted herein, it can make in this way when carrying out MHP analysis, it is believed that be added The subsequent sentence of primitive all may be concurrent with addition primitive, this is a kind of wrong report, but is not failed to report.Similarly, primitive and touching are waited Hair primitive matches, if therefore the waiting primitive node in multi-thread program-controlled CFG and multiple triggering primitive node matchings, delete and Wait the side of primitive node connection.By above-mentioned processing, that is, it can guarantee that obtained multithreading CFG is conservative correct.
Further, in the embodiment shown in fig. 1, it in step S104, is carried out to correct Multi-thread control flow graph is guarded The step of MHP is analyzed, and obtains the MHP analysis result of concurrent program to be analyzed, can specifically include: calculating conservative correctly multi-thread The non-concurrent set and productive set of each node in process control flow graph, wherein the non-concurrent set expression of node A can not be with node The set of A concurrent node, the productive set of node A indicate the set of node caused by node A;According to each node it is non-simultaneously Hair set and productive set iterative calculation guard the MHP analysis of each node in correct Multi-thread control flow graph as a result, until MHP Result convergence is analyzed, the MHP analysis result of concurrent program to be analyzed is obtained.
Specifically, when to correct multithreading CFG progress MHP analysis is guarded, it is necessary first to each in multithreading CFG Node is analyzed, and determines the non-concurrent set and productive set of each node.The non-concurrent set expression of one of node A without The set of method and node A concurrent node, that is, certainly can not be concurrent with node A node set.The generation collection of node A Close the set for indicating node caused by node A.Then a node is selected every time, is saved according to its input node set, output Point set, non-concurrent set and productive set calculate the MHP result of the node.Wherein, the input node knot of each node It closes, the union of output node set and productive set, then subtracts non-concurrent set, as the MHP of the node analyzes result.It will be right Each calculated MHP analysis result of node is iterated if having circulation along the execution sequence transmitting downwards of multithreading CFG It calculates, finally gathered the MHP of each node points after obtaining, set obtains the MHP analysis result of concurrent program to be analyzed.
Fig. 2 is the flow chart of the MHP analysis method embodiment two of concurrent program provided in an embodiment of the present invention, such as Fig. 2 institute Show, MHP analysis method provided in this embodiment includes:
Step S201 selects a thread, the execution of the thread of analog selection, when selection since main thread every time When thread can not continue to execute, locks the thread of selection and record the current location information of thread of selection.
Specifically, MHP analysis method provided in this embodiment is that the specific of step S101 in embodiment illustrated in fig. 1 executes step Suddenly.Firstly, selecting a thread every time since main thread, simulating the execution of selected thread, until the thread of the selection It can not continue to execute, that is, the thread of each selection is required as much as possible to simulate execution, until can not continue to execute. Then the thread of the selection is locked, and records the current location of the thread of the selection.Before the thread UNLOCKS to the selection, no It can continue the thread that simulation executes the selection.That is, can holding using the thread of depth-first search analytic approach analog selection Row.The mark of the thread of selection and the mark of current sentence can be recorded in scheduling information table, to record the line of selection The location information of Cheng Dangqian.
Step S202 jumps to any first thread being not locked out and can continue to execute, simulates the execution of first thread, When first thread can not continue to execute, locks first thread and record the current location information of first thread, until not locked Thread that is fixed and can continuing to execute is modeled execution.
Specifically, after having locked the thread of above-mentioned selection, any one can be jumped to and be not locked out and can continue to hold Capable first thread, and simulate the execution of first thread.Ability simulation maximum to the greatest extent is also required to the simulation of first thread to execute, Until first thread can not continue to execute.Then it locks first thread and records the current position of first thread.Repeat selection not First thread that is locked and can continuing to execute, until all threads that is not locked out and can continue to execute are modeled and hold Row.That is, can be using the execution of depth-first search analytic approach simulation first thread.Can be recorded in scheduling information table The mark of one thread and the mark of current sentence, thus the location information that the thread for recording selection is current.
Step S203 releases locked thread, and repeats step S202, until concurrent program to be analyzed is all Thread simulation is finished.
Specifically, when thread that is no unlocked and can continuing to execute, need to release all locked threads simultaneously. Then step S202 is repeated, until all threads that must analyze program are modeled and are finished.That is, at this In embodiment, the principle that simulation execution is carried out to each thread is first, and the simulation that needs to do one's best executes the line currently selected Journey, second, if still there is executable thread, locked thread cannot be executed.
The multithreading CFG that obtained result detection is executed according to method provided in this embodiment simulation, being capable of real embodiment Relationship in concurrent program to be analyzed between each thread, to obtain accurately and reliably multithreading CFG.
Figures 1 and 2 show that the implementing procedure of the MHP analysis method of concurrent program provided by the invention, below with one The MHP analysis method of Fig. 1 and concurrent program shown in Fig. 2 is further described in specific embodiment.
Fig. 3 is the flow chart of the MHP analysis method embodiment three of concurrent program provided in an embodiment of the present invention, such as Fig. 3 institute Show, MHP analysis method provided in this embodiment includes:
Step S301 constructs a scheduler, using the execution of scheduler simulation dynamic routine, selects a thread every time Carry out static analysis.
Specifically, firstly, constructing a scheduling information list, the information of the thread for saving concurrent program to be analyzed, This information is mark (Identity, ID) and the analysis position of present analysis thread, for example, where function, place it is basic fast with Which sentence of place.Each cross-thread is using random schedule or follows bad scheduling scheme, and using the depth-first of standard in thread Search for (Depth First Search, DFS) analysis method.Then for a thread, in scheduling information list The schedulable position of only one will be occupied, and its information can behave as the form of stack, function interbed when for expressing DFS analysis The relationship that layer calls.Device to be compiled scans through source code, and carries out basic morphology, multithreading CFG in syntactic analysis and process Building after, scheduler start from principal function to multithreading CFG scan, if a creation primitive is met, in scheduling information The information of this new wound thread is established in list, and this new wound thread is analyzed in right times later.If adjusted Degree device meets linear function calling, then is analyzed according to DFS, the location information pop down of calling function, then jump to and adjusted Function is analyzed.If current thread cannot be analyzed again, for example meet an addition primitive etc., scheduler saves current Analyze and the location informations such as the place function of primitive, place basic block, place sentence be added, then select another thread after It is continuous to be analyzed.If current thread analysis finishes, the information of this thread can be cancelled in scheduling information list.
Step S302, scheduler analyze each thread, occur blocking or cannot divide again in currently analyzed thread It is switched to other threads when analysis to be analyzed, after meeting certain conditions, scheduler can continue to analyze before those It is blocked or unanalyzable thread.
Specifically, according to the meaning of each primitive, it may be defined that and primitive is added, triggering primitive, waits primitive that there is obstruction Meaning.Namely: primitive, triggering primitive is added, primitive is waited to have the ability that analysis program is prevented to continue to analyze the energy of current thread Power, until some condition meets.Analysis is carried out to each thread and needs to meet following two rule:
Rule one: analysis program should use up its best endeavors and do analysis, (because of quilt before it cannot do again any analysis Obstruction or part Thread Analysis finish), analysis program cannot do any creation/addition primitive and the matching of triggering/waiting primitive Work.Rule two: once creation/addition primitive and the matching work of triggering/waiting primitive are done in analysis program preparation, journey is analyzed Sequence should handle current all creation/addition primitive and triggering/waiting primitive, then unlock again after blocked state continues analysis Continuous program.
Step S303, circulation execute step S302, finish until institute's source code is analyzed.Then pass through two method of purifications Then guarantee that constructed multithreading CFG is conservative correct.
First purification rule: if an addition primitive node (can include standard thread with multiple thread match The case where (normalized thread)), just delete all sides connecting with the addition primitive node.Article 2 purifies rule: As soon as if waiting primitive node can be deleted all with multiple triggering primitive node matchings (the case where including standard thread) The side being connect with the waiting primitive node.Above-mentioned standard thread is defined as: the thread created in circulation;These threads are usual There is identical subject thread function body, but in static analysis, due to that can not know the number of creation thread, usually according to list A thread or 2 threads are analyzed, but to be labeled as standard thread, to indicate the difference with general thread.
Step S304 calculates the multithreading CFG after creation and carries out MHP calculating.
Specifically, define some symbols first: t indicates that a thread, N (t) indicate all nodes of this thread;N table Show a node, (it is online that the node returned belongs to n institute to localpred (n) by the predecessor node immediately for returning to the local n Journey), localsucc (n) returns to the descendant node immediately of the local n;Pred (n) returns to all predecessor nodes of n, and succ (n) is returned Return all descendant nodes of n;All ancestor nodes of anc (n) return n;All descendant nodes of des (n) return n;path_ Des (n1, n2) returns to all paths that n2 is reached from n1, these paths obtain before all passing through to traversal;P is a paths, p ∈ path_des(n1,n2);N (p) returns to all nodes on this paths p;Path_anc (n1, n2) is returned from n1 and is reached n2's All paths, these paths obtain after all passing through to traversal.
The non-concurrent set and productive set of some key nodes are calculated according to the following formula, and wherein KILL (n) indicates section The non-concurrent set of point n, GEN (n) indicate the productive set of node n.Signal_node indicates triggering primitive node, wait_ Node indicates that waiting primitive node, begin_node indicate that the ingress when opening of thread, join_node indicate that primitive is added Node, the egress create_node at the end of exit_node indicates thread indicate creation primitive node, create_succ_ Node indicates the descendant node of creation primitive.
It calculates KILL (signal_node)
Wherein wait_node is the node to match with signal_node, and wait_node and begin_node belong to together One thread.
It calculates GEN (signal_node)
GEN (signal_node) :=KILL (signal_node)
It calculates KILL (wait_node)
KILL (wait_node) :=n | n ∈ anc (signal_node)-des (signal_node) }
Signal_node is the node to match with wait_node.
It calculates KILL (begin_node)
KILL (begin_node) :=∪n∈signal_nodeKILL(n)
Begin_node and signal_node belongs to the same thread.
It calculates KILL (join_node)
KILL (join_node) :=ane (exit_node)
It calculates GEN (begin_node/create_succ_node)
Each create_node is there are two descendant node immediately, and one is begin_node, and one is create_succ_ node。
It calculates GEN (begin_node/create_succ_node)
Then the calculating of MHP is carried out according to the formula of following data-flow equations.
IN (n) :=∪p∈localpred(n)out(p)
POUT (n) :=OUT (n) ∪ IN (n) ∪ GEN (n)-KILL (n)
MHP (n)=: OUT (n)-LOCK (n)
Cycle calculations are carried out to entire concurrent program to be analyzed, so as to obtain the MHP analysis of concurrent program to be analyzed As a result.
Fig. 4 is the structural schematic diagram of the MHP analytical equipment embodiment one of concurrent program provided in an embodiment of the present invention, is such as schemed Shown in 4, the MHP analytical equipment of concurrent program provided in this embodiment includes:
Execution module 41 is simulated, for since the main thread of concurrent program to be analyzed, selecting a thread, simulation every time The execution of the concurrent program to be analyzed, wherein when the thread for simulating execution can not continue to execute, jump to it is any can The thread simulation continued to execute executes, until all threads simulation of the concurrent program to be analyzed is finished, wherein described Concurrent program to be analyzed includes at least two threads.
Controlling stream graph construct module 42, for according to the concurrent program to be analyzed carry out simulation execution as a result, structure Build Multi-thread control flow graph corresponding with the concurrent program to be analyzed.
Controlling stream graph processing module 43 obtains conservative correctly more for handling the Multi-thread control flow graph Thread controlling stream graph, there is no leakages for the concurrent MHP result of possibility for guarding each node in correct Multi-thread control flow graph Report.
MHP analysis module 44 obtains described for guarding correct Multi-thread control flow graph progress MHP analysis to described The MHP of concurrent program to be analyzed analyzes result.
The MHP analytical equipment of concurrent program provided in this embodiment for realizing concurrent program shown in Fig. 1 the analysis side MHP The process of method, it is similar that the realization principle and technical effect are similar, and details are not described herein again.
Further, in the embodiment shown in fig. 4, controlling stream graph processing module 43, if being specifically used for described multi-thread program-controlled Addition primitive node and multiple thread match in flow graph processed then delete all sides connecting with the addition primitive node;If Waiting primitive node and multiple triggering primitive node matchings in the Multi-thread control flow graph, then delete all and waiting The side of primitive node connection;Using obtained Multi-thread control flow graph as guarding correct Multi-thread control flow graph.
Further, in the embodiment shown in fig. 4, MHP analysis module 44 is specifically used for calculating described conservative correctly more The non-concurrent set and productive set of each node in thread controlling stream graph, wherein the non-concurrent set expression of node A can not be with section The set of point A concurrent node, the productive set of node A indicate the set of node caused by node A;According to the non-of each node Concurrency set and productive set iterate to calculate it is described guard each node in correct Multi-thread control flow graph MHP analysis as a result, Until MHP analysis result convergence, obtains the MHP analysis result of the concurrent program to be analyzed.
Further, in the embodiment shown in fig. 4, execution module 41 is simulated, is specifically used for executing following steps: step One, since the main thread, every time select a thread, the execution of the thread of analog selection, when the selected thread without When method continues to execute, locks the selected thread and record the current location information of the selected thread;Step 2 jumps To any first thread being not locked out and can continue to execute, simulate the execution of the first thread, when the first thread without It when method continues to execute, locks the first thread and records the current location information of the first thread, do not locked until all Thread that is fixed and can continuing to execute is modeled execution;Step 3 releases all locked threads, and repeats step Two, until all threads simulation of the concurrent program to be analyzed is finished.
Further, in the embodiment shown in fig. 4, execution module 41 is simulated, is specifically used for using depth-first search point The execution of the thread of analysis method analog selection;The execution of the first thread is simulated using depth-first search analytic approach.
Further, in the embodiment shown in fig. 4, execution module 41 is simulated, specifically for recording in scheduling information table The mark of the selected thread and the mark of current sentence;The mark of the first thread is recorded in the scheduling information table Know the mark with current sentence.
Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention., rather than its limitations;To the greatest extent Pipe present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that: its according to So be possible to modify the technical solutions described in the foregoing embodiments, or to some or all of the technical features into Row equivalent replacement;And these are modified or replaceed, various embodiments of the present invention technology that it does not separate the essence of the corresponding technical solution The range of scheme.

Claims (12)

1. a kind of MHP analysis method of concurrent program characterized by comprising
Since the main thread of concurrent program to be analyzed, a thread is selected every time, simulates holding for the concurrent program to be analyzed Row, wherein when the thread for simulating execution can not continue to execute, jump to any thread simulation continued to execute and hold Row, until all threads simulation of the concurrent program to be analyzed is finished, wherein the concurrent program to be analyzed includes extremely Few two threads;
According to the concurrent program to be analyzed carry out simulation execution as a result, building it is corresponding with the concurrent program to be analyzed Multi-thread control flow graph;
The Multi-thread control flow graph is handled, obtains guarding correct Multi-thread control flow graph, it is described conservative correct There is no fail to report the concurrent MHP result of the possibility of each node in Multi-thread control flow graph;
Correct Multi-thread control flow graph progress MHP analysis is guarded to described, obtains the MHP analysis of the concurrent program to be analyzed As a result.
2. being obtained the method according to claim 1, wherein described handle the Multi-thread control flow graph To guarding correct Multi-thread control flow graph, comprising:
If addition primitive node and multiple thread match in the Multi-thread control flow graph, delete all former with the addition The side of language node connection;
If waiting primitive node and multiple triggering primitive node matchings in the Multi-thread control flow graph, delete all and institute State the side for waiting the connection of primitive node;
Using obtained Multi-thread control flow graph as guarding correct Multi-thread control flow graph.
3. method according to claim 1 or 2, which is characterized in that described to guard correct Multi-thread control stream to described Figure carries out MHP analysis, obtains the MHP analysis result of the concurrent program to be analyzed, comprising:
Calculate the non-concurrent set and productive set for guarding each node in correct Multi-thread control flow graph, wherein node A Non-concurrent set expression can not be concurrent with node A node set, the productive set of node A indicates caused by node A The set of node;
It is guarded in correct Multi-thread control flow graph respectively according to the iterative calculation of the non-concurrent set and productive set of each node is described The MHP of node is analyzed as a result, until MHP analysis result convergence, obtains the MHP analysis knot of the concurrent program to be analyzed Fruit.
4. method according to claim 1 or 2, which is characterized in that described since the main thread, selection one every time Thread simulates the execution of the concurrent program to be analyzed, wherein when the thread for simulating execution can not continue to execute, jumps It goes to any thread simulation continued to execute to execute, until all threads simulation of the concurrent program to be analyzed has executed Finish, comprising:
Step 1 selects a thread, the execution of the thread of analog selection, when the selection since the main thread every time Thread when can not continue to execute, lock the selected thread and record the current location information of the selected thread;
Step 2 jumps to any first thread being not locked out and can continue to execute, simulates the execution of the first thread, when When the first thread can not continue to execute, locks the first thread and records the current location information of the first thread, Until all threads that is not locked out and can continue to execute are modeled execution;
Step 3 releases all locked threads, and repeats step 2, until the concurrent program to be analyzed is all Thread simulation is finished.
5. according to the method described in claim 4, it is characterized in that, the execution of the thread of the analog selection, comprising:
Using the execution of the thread of depth-first search analytic approach analog selection;
The execution of the simulation first thread, comprising:
The execution of the first thread is simulated using depth-first search analytic approach.
6. according to the method described in claim 4, it is characterized in that, described record the current position letter of the selected thread Breath, comprising:
The mark of the selected thread and the mark of current sentence are recorded in scheduling information table;
It is described to record the current location information of the first thread, comprising:
The mark of the first thread and the mark of current sentence are recorded in the scheduling information table.
7. a kind of MHP analytical equipment of concurrent program characterized by comprising
Simulate execution module, for since the main thread of concurrent program to be analyzed, select a thread every time, simulation it is described to Analyze the execution of concurrent program, wherein when the thread for simulating execution can not continue to execute, jump to and any continue to hold Capable thread, which is simulated, to be executed, until all threads simulation of the concurrent program to be analyzed is finished, wherein described to be analyzed Concurrent program includes at least two threads;
Controlling stream graph construct module, for according to the concurrent program to be analyzed carry out simulation execution as a result, building and institute State the corresponding Multi-thread control flow graph of concurrent program to be analyzed;
Controlling stream graph processing module obtains conservative correctly multi-thread program-controlled for handling the Multi-thread control flow graph Flow graph processed, there is no fail to report the concurrent MHP result of possibility for guarding each node in correct Multi-thread control flow graph;
MHP analysis module obtains described to be analyzed for guarding correct Multi-thread control flow graph progress MHP analysis to described The MHP of concurrent program analyzes result.
8. device according to claim 7, which is characterized in that the controlling stream graph processing module, if being specifically used for described Addition primitive node in Multi-thread control flow graph and multiple thread match are then deleted and all are connect with the addition primitive node Side;If waiting primitive node in the Multi-thread control flow graph and multiple triggering primitive node matchings, delete it is all and The side for waiting the connection of primitive node;Using obtained Multi-thread control flow graph as guarding correct Multi-thread control flow graph.
9. device according to claim 7 or 8, which is characterized in that the MHP analysis module is specifically used for described in calculating Guard the non-concurrent set and productive set of each node in correct Multi-thread control flow graph, wherein the non-concurrent set of node A Indicate the set of node that can not be concurrent with node A, the productive set of node A indicates the set of node caused by node A;Root It is iterated to calculate according to the non-concurrent set and productive set of each node and described guards each node in correct Multi-thread control flow graph MHP analysis is as a result, until MHP analysis result convergence, obtains the MHP analysis result of the concurrent program to be analyzed.
10. device according to claim 7 or 8, which is characterized in that the simulation execution module is specifically used for executing such as Lower step: step 1 selects a thread, the execution of the thread of analog selection, when the choosing since the main thread every time When the thread selected can not continue to execute, locks the selected thread and record the current location information of the selected thread; Step 2 jumps to any first thread being not locked out and can continue to execute, the execution of the first thread is simulated, when described When first thread can not continue to execute, locks the first thread and record the current location information of the first thread, until All threads that is not locked out and can continue to execute are modeled execution;Step 3 releases all locked threads, and repeats Step 2 is executed, until all threads simulation of the concurrent program to be analyzed is finished.
11. device according to claim 10, which is characterized in that the simulation execution module is specifically used for using depth The execution of the thread of first search analytic approach analog selection;Holding for the first thread is simulated using depth-first search analytic approach Row.
12. device according to claim 10, which is characterized in that the simulation execution module is specifically used for believing in scheduling The mark of the selected thread and the mark of current sentence are recorded in breath table;Described is recorded in the scheduling information table The mark of one thread and the mark of current sentence.
CN201610527181.2A 2016-07-06 2016-07-06 The MHP analysis method and device of concurrent program Active CN106201874B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201610527181.2A CN106201874B (en) 2016-07-06 2016-07-06 The MHP analysis method and device of concurrent program

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201610527181.2A CN106201874B (en) 2016-07-06 2016-07-06 The MHP analysis method and device of concurrent program

Publications (2)

Publication Number Publication Date
CN106201874A CN106201874A (en) 2016-12-07
CN106201874B true CN106201874B (en) 2018-12-28

Family

ID=57465874

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201610527181.2A Active CN106201874B (en) 2016-07-06 2016-07-06 The MHP analysis method and device of concurrent program

Country Status (1)

Country Link
CN (1) CN106201874B (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP0406602B1 (en) * 1989-06-29 1995-08-16 International Business Machines Corporation Method and apparatus for debugging parallel programs by serialization
CN101937365A (en) * 2009-06-30 2011-01-05 国际商业机器公司 Deadlock detection method of parallel programs and system
CN102073588A (en) * 2010-12-28 2011-05-25 北京邮电大学 Code static analysis based multithread deadlock detection method and system
CN104536898A (en) * 2015-01-19 2015-04-22 浙江大学 C-program parallel region detecting method

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP0406602B1 (en) * 1989-06-29 1995-08-16 International Business Machines Corporation Method and apparatus for debugging parallel programs by serialization
CN101937365A (en) * 2009-06-30 2011-01-05 国际商业机器公司 Deadlock detection method of parallel programs and system
CN102073588A (en) * 2010-12-28 2011-05-25 北京邮电大学 Code static analysis based multithread deadlock detection method and system
CN104536898A (en) * 2015-01-19 2015-04-22 浙江大学 C-program parallel region detecting method

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
高可扩展性的MHP分析算法;印乐;《软件学报》;20131130;第2289-2299页 *

Also Published As

Publication number Publication date
CN106201874A (en) 2016-12-07

Similar Documents

Publication Publication Date Title
Wong et al. Effective software fault localization using an RBF neural network
Bensalem et al. Verification and validation meet planning and scheduling
Fellner et al. Model-based, mutation-driven test-case generation via heuristic-guided branching search
Peled Model checking
Li et al. Practical symbolic race checking of GPU programs
Tulsian et al. Mux: algorithm selection for software model checkers
Baluda et al. Bidirectional symbolic analysis for effective branch testing
Bensalem et al. Confirmation of deadlock potentials detected by runtime analysis
Duarte et al. Using contexts to extract models from code
Peled Formal methods
Wang et al. Symbolic predictive analysis for concurrent programs
CN106201874B (en) The MHP analysis method and device of concurrent program
Křena et al. Automated formal analysis and verification: an overview
Cheng et al. Algorithms for synthesizing priorities in component-based systems
Chechik et al. Property-based methods for collaborative model development
Wang et al. Interactive inconsistency fixing in feature modeling
Qian et al. A strategy for multi-target paths coverage by improving individual information sharing
Fernando et al. Workflowdsl: Scalable workflow execution with provenance for data analysis applications
CN114138669A (en) Software automatic testing method based on function level selection symbolized mixed execution
Li et al. Automatically generating functional scenarios from SOFL CDFD for specification inspection
Bu et al. Genetic synthesis of concurrent code using model checking and statistical model checking
Zhang et al. Regression test generation approach based on tree-structured analysis
Ito et al. A method for detecting bad smells and ITS application to software engineering education
Timm Three-valued abstraction and heuristic-guided refinement for verifying concurrent systems
Xu et al. A log-linear probabilistic model for prioritizing extract method refactorings

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant