CN115794592A - Data competition detection method based on high-order function - Google Patents
Data competition detection method based on high-order function Download PDFInfo
- Publication number
- CN115794592A CN115794592A CN202310094558.XA CN202310094558A CN115794592A CN 115794592 A CN115794592 A CN 115794592A CN 202310094558 A CN202310094558 A CN 202310094558A CN 115794592 A CN115794592 A CN 115794592A
- Authority
- CN
- China
- Prior art keywords
- function
- thread
- access
- order
- event
- 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.)
- Granted
Links
Images
Classifications
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D10/00—Energy efficient computing, e.g. low power processors, power management or thermal management
Landscapes
- Devices For Executing Special Programs (AREA)
Abstract
The invention discloses a data competition detection method based on a high-order function, which comprises the following steps: preprocessing a program, constructing a cross-thread function call graph and a control flow graph of each function, traversing the function call graph according to the sequence of reverse topological sorting, and determining the analysis sequence of each function; selecting a function to be analyzed in sequence, traversing a control flow graph of the function, and acquiring a high-order function abstract of each function and an inter-process access event set generated by function calling and parameter transfer; performing occurrence order analysis on the access events based on the vector clock and the high-order function abstract; and excluding unsatisfied access event pairs through the condition of the occurrence of the data competition, and acquiring all results of the possible occurrence of the data competition. The invention can conveniently complete the substitution of high-order function parameters in the function abstract at the calling point according to the corresponding relation of the actual parameters and the form parameters, effectively improves the efficiency of data competition information collection among the processes, and can carry out efficient generation sequence analysis by combining the vector clock and the function abstract.
Description
Technical Field
The invention relates to the technical field of functional programming and program analysis, in particular to a data race detection method based on a high-order function.
Background
With the continuous development of computer technology, the applications related to the concurrency characteristics occupy an important position. In a concurrent environment, an error occurs when multiple threads access the same memory location concurrently, and a "lock" is needed at this time, so that only one thread is allowed to access at the same time during the concurrent. Because of the uncertainty in the concurrent program, the concurrent program is prone to some problems, which commonly include data contention, atomic violation, deadlock, and the like, and a serious concurrent problem may cause a program crash, the detection of these problems is very important. The most common and basic defect problem is data contention, in a concurrent program, multiple threads access the same shared memory, one of the threads is write operation, and exclusive operation is performed on the shared memory without locking, which causes data contention, and the data contention is hard to be discovered once it occurs.
With the increase of the software scale, the function of the program is called very frequently nowadays because the function can be called repeatedly to reduce the amount of code. Different calls of the same function have different parameters, so that it is difficult to distinguish which shared variables are accessed by the function, and the data competition information of the called function is different.
High order functions are an important feature of functional programming. In the functional programming, the function is equal to other data types, and can be transmitted to other functions as a parameter or used as a return value of other functions. When the analysis is performed in the process of facing a plurality of parameters, the high-order function can flexibly generate the abstract taking the form parameter as the function parameter, and the corresponding parameter is reserved for the introduction of the actual parameter in the function abstract, so that the secondary analysis is avoided, and the efficiency of acquiring the data competition information in the process is improved. Therefore, the invention provides a data competition detection method based on a high-order function, which can effectively improve the efficiency of data competition information collection among processes.
Disclosure of Invention
This section is for the purpose of summarizing some aspects of embodiments of the invention and to briefly introduce some preferred embodiments. In this section, as well as in the abstract and title of the application, simplifications or omissions may be made to avoid obscuring the purpose of the section, the abstract and the title, and such simplifications or omissions are not intended to limit the scope of the invention.
The present invention has been made in view of the above-mentioned conventional problems.
Therefore, the invention aims to provide a data race detection method based on a high-order function to solve the problem of collecting data race information causing crash in concurrent programs.
In order to solve the technical problems, the invention provides the following technical scheme:
in a first aspect, an embodiment of the present invention provides a data contention detection method based on a high-order function, including: preprocessing a program, constructing a cross-thread function call graph and a control flow graph of each function, traversing the function call graph according to the sequence of reverse topological sorting, and determining the analysis sequence of each function;
selecting a function to be analyzed in sequence, traversing a control flow graph of the function, and acquiring a high-order function abstract of each function and an inter-process access event set generated by function calling and parameter transfer;
performing occurrence sequence analysis on the access events based on the vector clock and the high-order function abstract;
and excluding unsatisfied access event pairs through the condition of the occurrence of the data competition, and acquiring all results of the possible occurrence of the data competition.
The invention relates to a data competition detection method based on a high-order function, wherein the method comprises the following steps: obtaining the high-order function digest of each function includes,
selecting a P function to be analyzed in sequence, carrying out in-process analysis on each function, and defining a high-order function, wherein parameters of the high-order function are actual parameters corresponding to a calling process;
lock datasets are collected for lock statement nodes, and access event datasets are collected for access nodes as follows:
initializing a constraint set of a P function;
thread interaction primitive information is collected for the thread interaction nodes.
The invention relates to a data competition detection method based on a high-order function, wherein the method comprises the following steps: also comprises a step of adding a new type of additive,
traversing the P function control flow graph through a data flow analysis technology, analyzing four types of statements, namely a lock statement, an access statement, a function call statement and a thread interaction statement, and transmitting an analysis result of the statements according to a traversal sequence;
representing the parts of the lock data set and the access event data set which relate to the calling function by using parameters of a defined high-order function;
let F (id,l,vt, L) is a constraint function of the statement s to be analyzed, wherein id is the event number of the iteration to the statement s,lfor the lock variable in the statement s,vthe method comprises the steps that shared variables in a statement s are used, t is a thread name interacting with a current thread in the statement s, and L is a constraint set sequentially transmitted to the statement s to be analyzed;
statement set s i ∈S ,i=1,2,3. }, where s is a program statement,iestablishing constraint relation extraction equations corresponding to different sentences for line numbers corresponding to the sentences S and S which is a set of all program sentences;
and after all statements in the P function are processed, storing the analysis result as a high-order function abstract by taking the form parameter as the function parameter.
The invention relates to a data competition detection method based on a high-order function, wherein the method comprises the following steps: the set of inter-procedural access events resulting from function calls and parameter passing includes,
for a function call statement, correspondingly bringing the obtained high-order function form access event function abstract into a corresponding relation between an argument and a function parameter, obtaining an access event set in the process, obtaining a complete inter-process access event result of the function, and for a thread call statement, instantiating a thread interaction primitive set of the thread while obtaining the complete access event result of the thread;
and recording the called function as a Q function at the function calling node, transmitting the event number and the lock set iterated to the current statement into an access event of the Q function in a parameter mode, and correspondingly substituting the function parameters in the high-order function abstract according to the corresponding relation between the form parameter and the actual parameter to obtain a complete inter-process analysis result of the function Q.
The invention relates to a data competition detection method based on a high-order function, wherein the method comprises the following steps: also comprises the following steps of (1) preparing,
recording and creating a th thread at a thread function calling node, namely a create method node, correspondingly substituting function parameters in the high-order function summary according to the corresponding relation between the form parameter and the actual parameter, and instantiating and obtaining an access event set and a thread interaction primitive set of the th thread;
when the analysis results of all the called functions are transmitted to the corresponding function calling points, the complete access event and thread interaction primitive message of each thread can be obtained.
The invention relates to a data competition detection method based on a high-order function, wherein the method comprises the following steps: analyzing the order of occurrence of the access events based on the vector clock and the high-order function digest includes,
when analyzing a main thread, the number gid of the initialized thread is 0, one local vector clock is clock = [1], an access event set and a vector clock are abstracted in an event set GA and used for storing the access event set with the same clock, and occurrence order analysis is convenient to perform later;
after the analysis result of each thread is obtained, clock analysis is carried out from the interactive primitive set of the main thread;
creating thread primitives<id,t,create,th>: get the thread number gid of the new thread th And vector clock th Increasing the clock value step number of the corresponding thread number of the vector clock of the t thread by 1, and analyzing the thread interaction primitive set of the th thread;
waiting for a thread primitive<id,t,join,th>: clock value clock of waiting thread th th With its own vector clock t The information is compared and updated, and then the direction of the t thread is compared and updatedThe clock value step number of the corresponding thread number of the measurement clock is increased by 1;
storing access events between two primitives ti1 and ti2 of the same thread into the same event set GA i In, i.e. event number greater than id ti1 Is less than id ti2 If ti1 is not preceded by other interaction primitives, the event number is from 0 to id ti1 If there are no other interactive primitives after ti2, the event number is selected from id ti2 To the event number of the last access event of the current function.
The invention relates to a data competition detection method based on a high-order function, wherein the method comprises the following steps: excluding unsatisfied access event pairs by the condition of data race occurrence, obtaining all possible results of data race occurrence including,
obtaining an event set GA i After all event sets which are possible to generate data competition are processed by the program, the access event pairs which do not meet the occurrence conditions are excluded by taking the conditions of the data competition as constraints, namely the access event pairs which are the same in variable, have at least one access as a write operation, are not protected by the same lock and do not have the occurrence sequence relation, and the access event pairs which are possible to generate the data competition are finally obtained.
In a second aspect, an embodiment of the present invention provides a data race detection system based on a high-order function, including,
the preprocessing module is used for preprocessing a program, constructing a cross-thread function call graph and a control flow graph of each function, traversing the function call graph according to the sequence of reverse topological sorting and determining the analysis sequence of each function;
the traversal module is used for sequentially selecting a function to be analyzed, traversing a control flow diagram of the function and acquiring a high-order function abstract of each function and an inter-process access event set generated by function calling and parameter transmission;
the analysis module is used for carrying out occurrence sequence analysis on the access events based on the vector clock and the high-order function abstract;
and the output module is used for eliminating unsatisfied access event pairs through the conditions of data competition occurrence and acquiring all possible results of the data competition.
In a third aspect, an embodiment of the present invention provides a computing device, including:
a memory and a processor;
the memory is configured to store computer-executable instructions, and the processor is configured to execute the computer-executable instructions, when the one or more programs are executed by the one or more processors, to cause the one or more processors to implement a method for data race detection based on higher-order functions according to any embodiment of the present invention.
In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, which stores computer-executable instructions, and when the computer-executable instructions are executed by a processor, the method for detecting data contention based on a high-order function is implemented.
The invention has the beneficial effects that: the invention is based on the data competition detection of the high-order function, obtains the access event set in the process through the characteristics of the high-order function, generates the function abstract expressed in the form of the high-order function, can conveniently complete the substitution of high-order function parameters in the function abstract according to the corresponding relation of actual parameters and form parameters at a calling point, effectively improves the efficiency of data competition information collection among the processes, and performs efficient generation sequence analysis through the combination of a vector clock and the function abstract.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings needed to be used in the description of the embodiments will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without inventive exercise. Wherein:
fig. 1 is a flowchart of a data race detection method based on a high-order function according to the present invention.
Detailed Description
In order to make the aforementioned objects, features and advantages of the present invention comprehensible, embodiments accompanied with figures are described in detail below.
In the following description, numerous specific details are set forth in order to provide a thorough understanding of the present invention, but the present invention may be practiced in other ways than those specifically described and will be readily apparent to those of ordinary skill in the art without departing from the spirit of the present invention, and therefore the present invention is not limited to the specific embodiments disclosed below.
Furthermore, the references herein to "one embodiment" or "an embodiment" refer to a particular feature, structure, or characteristic that may be included in at least one implementation of the present invention. The appearances of the phrase "in one embodiment" in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments.
Furthermore, the present invention is described in detail with reference to the drawings, and in the detailed description of the embodiments of the present invention, the cross-sectional view illustrating the structure of the device is not enlarged partially according to the general scale for convenience of illustration, and the drawings are only exemplary and should not be construed as limiting the scope of the present invention. In addition, the three-dimensional dimensions of length, width and depth should be included in the actual fabrication.
Example 1
Referring to fig. 1, an embodiment of the present invention provides a data contention detection method based on a high-order function, including:
as shown in FIG. 1, the specific process of the present invention is as follows:
s1: preprocessing a program, constructing a cross-thread function call graph and a control flow graph of each function, traversing the function call graph according to the sequence of reverse topological sorting, and determining the analysis sequence of each function.
S2: and selecting a function to be analyzed in sequence, traversing a control flow graph of the function, and acquiring a high-order function abstract of each function and an inter-process access event set generated by function calling and parameter transfer. It should be noted that:
performing in-process analysis on each function, defining a high-order function, wherein parameters of the high-order function are actual parameters corresponding to a calling process;
lock datasets are collected for lock statement nodes, and access event datasets are collected for access nodes as follows:
and selecting a P function to be analyzed in sequence, initializing a constraint set L = < ls, access and Inter > of the function, wherein ls is a lock set, access is an Access event set, inter is a primitive set, ls, access and Inter are null, and the number id of the initialization event =0. Abstracting an access event as e = < id, v, rw, ls >, and respectively representing an event number id, an accessed variable v, a read-write operation rw and a lock set ls consisting of a lock protecting a current statement;
create thread primitive event ti = < id, t, create, th >, indicating the event number is id, t thread creates th thread. Waiting for a thread primitive event ti = < id, t, join, th >, the event number is id, and the t thread waits for the th thread to finish executing;
traversing the P function control flow graph through a data flow analysis technology, analyzing four types of statements, namely a lock statement, an access statement, a function call statement and a thread interaction statement, and transmitting an analysis result of the statements according to a traversal sequence;
the parts of the lock data set and the access event data set related to the calling function are represented by parameters of a defined high-order function;
let F (id,l,vt, L) is a constraint function of the statement s to be analyzed, wherein id is the event number of the iteration to the statement s,lfor the lock variable in the statement s,vis a shared variable in a statement s, t is a thread name interacting with a current thread in the statement s, L represents a constraint set sequentially transmitted to the statement s to be analyzed, and if the current statement s has no corresponding type variable, the constraint set is used for determining whether the current statement s has the corresponding type variableComing from nullRepresenting;
from the set of statements { s | s i ∈S ,i=1,2,3. }, where s is a program statement,ifor the line number corresponding to the sentence S, S is the set of all program sentences), the constraint relation extraction equation corresponding to different sentences is constructed:
if statement s i For locking type statementslLock () in which the clock signal is synchronized,lfor lock type variables, the constraint relationship extraction equation is:
L i =F(id,l,null,null,L)=<{l}∪L.ls,L.Access,L.Inter>
if statement s i To unlockType statementlUnlock () wherein the number of bits in the block,lfor lock type variables, the constraint relationship extraction equation is:
L i =F(id,l,null,null,L)=<L.ls-{l},L.Access,L.Inter>
if statement s i For access type statements such as:vplus + wherein (c) in the reaction chamber,vacquiring the read-write information and the shared variables of the current statement for the shared type variables, wherein the constraint relation extraction equation is as follows:
L i =F(id,null,v,null,L)=<L.ls,{<id+1,v,rw,ls>}∪L.Access,L.Inter>
if statement s i Create () for create type statement th, wherein th is the thread name of the newly created thread, the constraint relation extraction equation is:
L i =F(id,null,null,t,L)=<L.ls,L.Access,{<id+1,t,create,th>}∪L.Inter>
if statement s i Join () for join type statements th, where th is the thread name of the waiting thread, the constraint relation extraction equation is:
L i =F(id,null,null,t,L)=<L.ls,L.Access,{<id+1,t,join,th>}∪L.Inter>
after all statements in the P function are processed, storing the analysis result as a function abstract of a high-order function form by taking form parameters as function parametersλl.λk.λX.({<k+id,v,rw,l+ls>}∪{<k+id,t,create,th>,<k+id,t,join,th>}),xIs a formal parameter of the P-function,v∈X,ls⊆X,X={x 1 ,x 2 ,x 3 a plurality of parameters can be provided,lis the set of locks held when the P-function is invoked iteratively,kis the event number when the P function is called iteratively.
For a function call statement, correspondingly bringing the obtained high-order function form access event function abstract into a corresponding relation between actual parameters and function parameters to obtain an access event set in the process and obtain a complete inter-process access event result of the function, and for a thread call statement, instantiating a thread interaction primitive set of the thread while obtaining the complete access event result of the thread;
recording a called function as a Q function at a function calling node, transmitting an event number and a lock set iterated to a current statement into an access event of the Q function in a parameter mode, and correspondingly substituting function parameters in a high-order function abstract according to a corresponding relation between form parameters and actual parameters to obtain a complete inter-process analysis result of the function Q;
the constraint relation extraction equation of the function call statement is as follows: l is a radical of an alcohol i =F(id,null,a,b..,null,L)=<L.ls,λl.λk.λX.{<k+id,x,rw,l+ls>}∪L.Access,L.Inter>Root of Chinese character 'xing' ginsenglCorresponding actual ginseng is L.ls, configurational ginsengkCorresponding parameters are id, and parameters a, bXIn (1).
Creating th thread at thread function calling node, namely create method node, correspondingly substituting function parameter in high-order function abstract according to corresponding relation between form parameter and actual parameter, calling function parameter for threadlThe data is a null set, and the data is transmitted to the mobile terminal,kwhen the value is 0, instantiating an access event set and a thread interaction primitive set of the acquisition th thread;
when the analysis results of all the called functions are transmitted to the corresponding function calling points, the complete access event and thread interaction primitive message of each thread can be obtained.
S3: and performing occurrence order analysis on the access events based on the vector clock and the high-order function digest. It should be noted that:
when the main thread is analyzed, the initialization thread number gid is 0, and one local vector clock = [1]]. Abstracting the access event set and the vector clock in the event set, namely GA: =<clock,{e 1 ,e 2 ,e 3 ...}>And the access event set is used for storing access event sets with the same clock, so that the subsequent occurrence sequence analysis is facilitated.
After the analysis result of each thread is obtained, clock analysis is carried out from the interactive primitive set of the main thread;
creating thread primitives<id,t,create,th>: get the thread number gid of the new thread th And vector clock th Increasing the clock value step number of the corresponding thread number of the vector clock of the t thread by 1, and analyzing the thread interaction primitive set of the th thread as follows:
gid th =gid t +1,clock th =clock t ,clock th [gid th ]=1,clock t [gid t ]+=1;
wait for thread primitive < id, t, join, th >: comparing and updating the clock value clockth of the waiting thread th with the vector clock clockt information of the waiting thread th, and increasing the clock value step number of the thread number corresponding to the vector clock of the t thread by 1 as follows:
clock t =max(clock t [i],clock th [i])(i=0,1,2...),clock t [gid t ]+=1;
storing access events between two primitives ti1 and ti2 of the same thread into the same event set GA i In, i.e. event number greater than id ti1 Is less than id ti2 If ti1 is not preceded by other interaction primitives, the event number is from 0 to id ti1 If there are no other interactive primitives after ti2, the event number is identified by id ti2 Event number of last access event to current function;
s4: and (4) excluding unsatisfied access event pairs through the condition of the occurrence of the data competition, and acquiring all possible results of the data competition. It should be noted that:
in obtaining event set GA i After all event sets which are possible to generate data competition are processed by the program, the access event pairs which do not meet the generation conditions are excluded by taking the conditions of the data competition, namely the access event pairs which are the same in variable, have at least one access as a write operation, are not protected by the same lock and do not have the occurrence sequence relation, and the access event pairs which are possible to generate the data competition are finally obtained.
GA for two event sets 1 And GA 2 ,<clock 1 ,{<id 1 ,v 1 ,rw 1 ,ls 1 >}>∈GA 1 ,<clock 2 ,{<id 2 ,v 2 ,rw 2 ,ls 2 >}>∈GA 2 First, it is determined whether the two event sets have no occurrence order relationship, i.e.! (clock) 1 [i]<=clock 2 [i]||clock 1 [i]<= clock 2 [i]) (i =0,1, 2.) if the occurrence sequence relation is not satisfied, then whether the access events of the two event sets satisfy the condition that the data competition occurs is determined as follows: access to the same variable:v 1 =v 2 (ii) a At least one is a write operation: ! (rw) 1 =r&&rw 2 = r); not protected by the same handle lock: ls is 1 ∩ls 2 =null;
The present embodiment further provides a data race detection system based on a high-order function, including:
the preprocessing module is used for preprocessing a program, constructing a cross-thread function call graph and a control flow graph of each function, traversing the function call graph according to the sequence of reverse topological sorting and determining the analysis sequence of each function;
the traversal module is used for sequentially selecting a function to be analyzed, traversing a control flow diagram of the function and acquiring a high-order function abstract of each function and an inter-process access event set generated by function calling and parameter transmission;
the analysis module is used for carrying out occurrence sequence analysis on the access events based on the vector clock and the high-order function abstract;
and the output module is used for eliminating unsatisfied access event pairs through the conditions of data competition occurrence and acquiring all possible results of the data competition.
The embodiment further provides a computing device, which is suitable for a case of a data race detection method based on a high-order function, and the method includes:
a memory and a processor; the memory is used for storing computer executable instructions, and the processor is used for executing the computer executable instructions to realize the data race detection method based on the high-order function as proposed in the above embodiment.
The computer device may be a terminal comprising a processor, a memory, a communication interface, a display screen and an input means connected by a system bus. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device comprises a nonvolatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of an operating system and computer programs in the non-volatile storage medium. The communication interface of the computer device is used for carrying out wired or wireless communication with an external terminal, and the wireless communication can be realized through WIFI, an operator network, NFC (near field communication) or other technologies. The display screen of the computer equipment can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer equipment can be a touch layer covered on the display screen, a key, a track ball or a touch pad arranged on a shell of the computer equipment, an external keyboard, a touch pad or a mouse and the like.
The present embodiment also provides a storage medium, on which a computer program is stored, which when executed by a processor implements a method for implementing a high-order function-based data race detection as set forth in the above embodiments.
The storage medium proposed in this embodiment belongs to the same inventive concept as the data storage method proposed in the above embodiment, and the technical details that are not described in detail in this embodiment can be referred to the above embodiment, and this embodiment has the same beneficial effects as the above embodiment.
Example 2
For another embodiment of the present invention, a verification test of a data race detection method based on a high-order function is provided, and technical effects adopted in the method are verified and explained.
The program code selected in this example is:
table 1: example code.
In this example, the analysis order of the traversal function call graph determination function in the reverse topological order is fun → th → main, and the program has a total of three threads, including main thread, t thread and t1 thread.
And performing intra-process analysis on each function, defining a high-order function, wherein the parameters of the high-order function are actual parameters corresponding to the calling process.
And selecting a P function to be analyzed in sequence, initializing a constraint set L = < ls, access, inter >, ls, access and Inter of the function, and initializing an event number id =0.
This example first analyzes the fun function and initializes L fun =<ls,Access,Inter>Ls, access and Inter are null, id fun =0。
Statement set of fun functions s 3 ,s 4 ,s 5 And constructing constraint relation extraction equations corresponding to different sentences as follows:
sentence s 3 Adding constraint L for locking type statement 3 =F(0,m1,null,null,L)=<{m1}∪L.ls,L.Access,L.Inter>=<{m1},Ø,Ø>. Sentence s 4 To write (p + +) the argument variable, i.e. the access type statement, constraints are added: l is 4 = F(0,null,p,null,L)=<{m1},{<0+1,p,rw,{m1}>}∪L.Access,L.Inter>=<{m1},{<1,p,w,{m1}>},Ø>。
Sentence s 5 To unlock type statements, add constraints as follows:
L 5 =F(1,m1,null,null,L)=<L.ls-{m1},L.Access,L.Inter>=<Ø,{<1,p,w,{m1}>},Ø>。
after all statements in the P function are processed, storing the analysis result as a function abstract of a high-order function form by taking form parameters as function parametersλl.λk.λX.({<k+id,v,rw,l+ls>}∪{<k+id,t,create,th>,<k+id,t,join,th>})。
The function digest of the higher order functional form of the fun function is obtained asλl.λk.λp.{<k+1,p,w,l+{m1}>};
Recording a called function as a Q function at a function calling node, transmitting an event number and a lock set iterated to a current statement into an access event of the Q function in a parameter mode, and correspondingly substituting function parameters in a high-order function abstract according to a corresponding relation between form parameters and actual parameters to obtain a complete inter-process analysis result of the function Q;
when analyzing the th function, the statement set s 8 ,s 9 ,s 10 }。
Sentence s 8 To call a function statement, the high order function of the fun function is summarized asλl.λk.λp.{<k+1,p,w,l+{m1}>};
Adding constraint of L 8 =F(0,null,v,null,L)=<L.ls,λl.λk.λX.{<k+1,p,w,l+{m1}>}∪L.Access,L.Inter>=<Ø,{<1,v,w, {m1}>},Ø>。
Creating a th thread at a thread function calling node, namely a create method node, correspondingly substituting function parameters in the high-order function abstract according to the corresponding relation between the form parameters and the actual parameters, and calling the function parameters for the threadlThe data is an empty set,kto 0, an access event set and a thread interaction primitive set of the get th thread are instantiated.
Sentence s 9 Is a create type statement, adding constraints as follows:
L 9 =F(0,null,null,t,L)=<L.ls,L.Access,{<0+1,th,create,t>}
∪L.Inter>=<Ø,{<1,v,w, {m1}>},{<2,th,create,t1>}>;
the higher-order function of fun function is summarized asλl.λk.λp.{<k+1,p,w,l+{m1}>Call function parameters for threadslThe data is a null set, and the data is transmitted to the mobile terminal,kand 0, replacing the parameter p with a variable v to acquire the event set Access of the t1 thread t1 ={<1,a,w,{m1}>};
Sentence s 10 Is a join type statement, adding constraints as follows:
L 10 =F(1,null,null,t,L)=<L.ls,L.Access,{<1+1,th,join,t1>}
∪L.Inter>=<Ø,{<1,v,w, {m1}>},{<2,th,create,t1>,<3,th,join,t1>}>;
th function high-order function abstractTo be thatλl.λk.λv.({<k+1,v,w,{m1}>}∪{<k+2,th,create,t1>,<k+3,th,join,t1>});
When the analysis results of all the called functions are transmitted to the corresponding function calling points, the complete access event and thread interaction primitive message of each thread can be obtained.
Access event set Access of main thread of the embodiment main ={<2,a,w,{m1,m2}>,<3,a,w,{m2}>H and primitive set Inter main ={<1,main,create,t>,<4,main,join,t>Access to Access event set of t threads t ={<1,a,w,{m1}>H and primitive set Inter t = {<2,th,create,t1>,<3,th,join,t1>Access event set Access of t1 thread t1 ={<1,a,w,{m1}>}。
In parsing the main thread, the initialization thread number gid is 0 and one local vector clock = [1].
In this example, when analyzing the main function, the initialization thread number gid is 0 and the local vector clock = [1].
And after the analysis result of each thread is obtained, starting to perform clock analysis from the primitives of the interaction primitive set of the main thread.
First, the primitive set Inter of the main thread main Analysis is made for creating thread primitives<1,main,create,t>The thread creating thread t with event number 1,main is obtained, and the thread number gid of the created thread t is obtained t =1 and vector clock t =[1,1]Then, the clock value step number of the thread number corresponding to the main thread is increased by 1,clock = [2 ]];
Storing access events between two primitives ti1 and ti2 of the same thread into the same event set GA i Performing the following steps;
primitive set Inter to t threads t Analyze and create thread primitives<1,t,create,t1>Get the thread number t1=2,clock of the created thread t1 t1 =[1,1,1]Then, the clock value step number of the corresponding thread number of the t thread is increased by 1 t =[1,2]Storing access events of the t1 thread to the event set GA due to the t1 thread-to-thread interaction primitive 1 Middle, namely GA 1 =<[1,1,1], {<1,a,w,{m1}>}>The t thread has two primitives, and stores an access event smaller than the first create primitive event number 2 into an event set GA 2 Middle, namely GA 2 =<[1,1], {<1,a,w,{m1}>}>;
For Inter t Is/are as follows<3,th,join,t1>Analyzing the clock value clock of the waiting thread t1 t1 With its own vector clock t The information is compared and updated, clock t =max(clock t [i],clock t1 [i])=[1,2,1](i =0,1, 2), and then the number of clock steps of the thread number corresponding to the t thread is increased by 1, clock t =[1,3,1]No access event between the two primitives;
wait primitive for main thread<4,main,join,t>To obtain clock = [3,3,1 ]]Storing access events between two primitives of main thread into the same event set GA 3 Middle, namely GA 3 =<[2],{<2,a,w,{m1,m2}>,<3,a,w,{m2}>}>。
After all event sets which are possible to generate data competition are obtained, the access event pairs which do not meet the occurrence conditions are excluded by taking the conditions of the data competition as constraints, namely the access event pairs are identical in variable, have at least one access as a write operation, are not protected by the same lock and do not have the occurrence sequence relation, and the access event pairs which are possible to generate the data competition are finally obtained.
In this example, the above steps are used to obtain a set of events that may cause data contention for the program.
GA 1 =<[1,1,1],{<1,a,w,{m1}>}>;
GA 2 =<[1,1], {<1,a,w,{m1}>}>;
GA 3 =<[2],{<2,a,w,{m1,m2}>,<3,a,w,{m2}>}>;
First, determine whether two event sets satisfy! (clock 1[ i!)]<=clock2[i]||clock1[i]<=clock2[i]) (i =0,1,2.) ensure no ordering relationship, GA 1 And GA 3 、GA 2 And GA 3 The method has no occurrence order relationship, wherein the access events may have data competition, and then the access events of the two event sets are judgedWhether the conditions for the occurrence of the data competition are met or not is judged, and finally the access event pair meeting the conditions for the occurrence of the data competition is GA 2 Is/are as follows<1,a,w,{m1}>And GA 3 Is/are as follows<3,a,w,{m2}>。
It should be noted that the above-mentioned embodiments are only for illustrating the technical solutions of the present invention and not for limiting, and although the present invention is described in detail with reference to the preferred embodiments, it should be understood by those skilled in the art that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention, which should be covered by the claims of the present invention.
Claims (10)
1. A data competition detection method based on a high-order function is characterized in that: comprises the steps of (a) preparing a mixture of a plurality of raw materials,
preprocessing a program, constructing a cross-thread function call graph and a control flow graph of each function, traversing the function call graph according to the sequence of reverse topological sorting, and determining the analysis sequence of each function;
selecting a function to be analyzed in sequence, traversing a control flow graph of the function, and acquiring a high-order function abstract of each function and an inter-process access event set generated by function calling and parameter transfer;
performing occurrence order analysis on the access events based on the vector clock and the high-order function abstract;
and excluding unsatisfied access event pairs through the condition of the occurrence of the data competition, and acquiring all results of the possible occurrence of the data competition.
2. The method according to claim 1, wherein the data race detection method based on the higher-order function comprises: obtaining the high-order function digest of each function includes,
selecting a P function to be analyzed in sequence, performing in-process analysis on each function, and defining a high-order function, wherein parameters of the high-order function are actual parameters corresponding to a calling process;
lock datasets are collected for lock statement nodes, and access event datasets are collected for access nodes as follows:
initializing a constraint set of a P function;
and collecting the thread interaction primitive information for the thread interaction nodes.
3. The method of claim 2, wherein the data race detection method based on the higher-order function comprises: also comprises the following steps of (1) preparing,
traversing the P function control flow graph through a data flow analysis technology, analyzing four types of statements, namely a lock statement, an access statement, a function call statement and a thread interaction statement, and transmitting an analysis result of the statements according to a traversal sequence;
representing the parts of the lock data set and the access event data set which relate to the calling function by using parameters of a defined high-order function;
let F (id,l,vt, L) is a constraint function of the statement s to be analyzed, wherein id is the event number of the iteration to the statement s,lfor the lock variable in the statement s,vthe method comprises the steps that shared variables in a statement s are used, t is a thread name interacting with a current thread in the statement s, and L is a constraint set sequentially transmitted to the statement s to be analyzed;
statement set s i ∈S , i=1,2,3. }, where s is a program statement,iconstructing constraint relation extraction equations corresponding to different sentences for the line number corresponding to the sentence S and the set of all program sentences S;
and after all the statements in the P function are processed, storing the analysis result as a high-order function abstract by taking the form parameter as the function parameter.
4. The method for detecting data competition based on the high-order function as claimed in any one of claims 1 to 3, wherein: the set of inter-procedural access events resulting from function calls and parameter passing includes,
for a function call statement, correspondingly bringing the obtained high-order function form access event function abstract into a corresponding relation between actual parameters and function parameters to obtain an access event set in the process and obtain a complete inter-process access event result of the function, and for a thread call statement, instantiating a thread interaction primitive set of the thread while obtaining the complete access event result of the thread;
and recording the called function as a Q function at the function calling node, transmitting the event number and the lock set iterated to the current statement into an access event of the Q function in a parameter mode, and correspondingly substituting the function parameters in the high-order function abstract according to the corresponding relation between the form parameter and the actual parameter to obtain a complete inter-process analysis result of the function Q.
5. The method according to claim 4, wherein the data race detection method based on the higher-order function comprises: also comprises the following steps of (1) preparing,
recording and creating a th thread at a thread function calling node, namely a create method node, correspondingly substituting function parameters in the high-order function abstract according to the corresponding relation between the form parameter and the actual parameter, and instantiating an access event set and a thread interaction primitive set for obtaining the th thread;
when the analysis results of all the called functions are transmitted to the corresponding function calling points, the complete access event and thread interaction primitive message of each thread can be obtained.
6. The method according to claim 1, wherein the data race detection method based on the higher-order function comprises: analyzing the order of occurrence of the access events based on the vector clock and the high-order function digest includes,
when analyzing a main thread, the number gid of the initialized thread is 0, one local vector clock is clock = [1], an access event set and a vector clock are abstracted in an event set GA and used for storing the access event set with the same clock, and occurrence order analysis is convenient to perform later;
after the analysis result of each thread is obtained, clock analysis is carried out from the interactive primitive set of the main thread;
creating thread primitives<id,t,create,th>: get the thread number gid of the new thread th And vector clock th Increasing the clock value step number of the corresponding thread number of the vector clock of the t thread by 1, and analyzing the thread interaction primitive set of the th thread;
waiting for thread primitive<id,t,join,th>: clock value clock of thread th to be waited th With its own vector clock t Comparing and updating the information, and increasing the clock value step number of the thread number corresponding to the vector clock of the t thread by 1;
storing access events between two primitives ti1 and ti2 of the same thread into the same event set GA i In, i.e. event number greater than id ti1 Is less than id ti2 If ti1 is not preceded by other interaction primitives, the event number is from 0 to id ti1 If there are no other interactive primitives after ti2, the event number is identified by id ti2 Event number to the last access event of the current function.
7. The method according to claim 1, wherein the data race detection method based on the higher-order function comprises: excluding unsatisfied access event pairs by the condition of data race occurrence, obtaining all possible results of data race occurrence including,
obtaining an event set GA i After all event sets which are possible to generate data competition are processed by the program, the access event pairs which do not meet the occurrence conditions are excluded by taking the conditions of the data competition as constraints, namely the access event pairs which are the same in variable, have at least one access as a write operation, are not protected by the same lock and do not have the occurrence sequence relation, and the access event pairs which are possible to generate the data competition are finally obtained.
8. A data race detection system based on a high-order function is characterized by comprising,
the preprocessing module is used for preprocessing a program, constructing a cross-thread function call graph and a control flow graph of each function, traversing the function call graph according to the sequence of reverse topological sorting and determining the analysis sequence of each function;
the traversal module is used for selecting a function to be analyzed in sequence, traversing a control flow graph of the function, and acquiring a high-order function abstract of each function and an inter-process access event set generated by function calling and parameter transfer;
the analysis module is used for carrying out occurrence order analysis on the access events based on the vector clock and the high-order function abstract;
and the output module is used for eliminating unsatisfied access event pairs through the conditions of data competition occurrence and acquiring all possible results of the data competition.
9. A computing device, comprising:
a memory and a processor;
the memory is configured to store computer-executable instructions, and the processor is configured to execute the computer-executable instructions, which when executed by the processor, implement the steps of the high-order function based data race detection system of any one of claims 1 to 7.
10. A computer readable storage medium storing computer executable instructions which, when executed by a processor, perform the steps of the high order function based data race detection system of any one of claims 1 to 7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202310094558.XA CN115794592B (en) | 2023-02-10 | 2023-02-10 | Data competition detection method based on higher-order function |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202310094558.XA CN115794592B (en) | 2023-02-10 | 2023-02-10 | Data competition detection method based on higher-order function |
Publications (2)
Publication Number | Publication Date |
---|---|
CN115794592A true CN115794592A (en) | 2023-03-14 |
CN115794592B CN115794592B (en) | 2023-07-04 |
Family
ID=85430772
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202310094558.XA Active CN115794592B (en) | 2023-02-10 | 2023-02-10 | Data competition detection method based on higher-order function |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN115794592B (en) |
Citations (14)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102073589A (en) * | 2010-12-29 | 2011-05-25 | 北京邮电大学 | Code static analysis-based data race detecting method and system thereof |
CN102760095A (en) * | 2011-04-25 | 2012-10-31 | 清华大学 | Dynamic data race detection method based on static shared variable recognition |
CN104077144A (en) * | 2014-07-07 | 2014-10-01 | 西安交通大学 | Data race detection and evidence generation method based on multithreaded program constraint building |
WO2016122548A1 (en) * | 2015-01-29 | 2016-08-04 | Hewlett Packard Enterprise Development Lp | Hash index |
WO2016122546A1 (en) * | 2015-01-29 | 2016-08-04 | Hewlett Packard Enterprise Development Lp | Transactional key-value store |
CN109885489A (en) * | 2019-01-31 | 2019-06-14 | 清华大学 | Data contention detection method and device in driver |
CN111552539A (en) * | 2014-07-14 | 2020-08-18 | 甲骨文国际公司 | Variable handle |
CN112817787A (en) * | 2021-01-28 | 2021-05-18 | 南京大学 | Automatic detection method for data competition of interrupt-driven embedded system |
CN112965838A (en) * | 2021-03-16 | 2021-06-15 | 支付宝(杭州)信息技术有限公司 | Data race checking method and device for concurrent program |
US20220012060A1 (en) * | 2020-07-09 | 2022-01-13 | Femtosense, Inc. | Methods and apparatus for thread-based scheduling in multicore neural networks |
CN114238078A (en) * | 2021-11-23 | 2022-03-25 | 南京邮电大学 | Method for extracting dependency relationship between programs based on high-order function |
CN114428733A (en) * | 2022-01-19 | 2022-05-03 | 南京大学 | Kernel data competition detection method based on static program analysis and fuzzy test |
CN114647575A (en) * | 2022-02-23 | 2022-06-21 | 南京邮电大学 | C + + inter-process anomaly analysis system and method based on high-order function |
CN115098108A (en) * | 2022-06-22 | 2022-09-23 | 南京邮电大学 | Lightweight context sensitive pointer analysis method based on high-order function |
-
2023
- 2023-02-10 CN CN202310094558.XA patent/CN115794592B/en active Active
Patent Citations (14)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102073589A (en) * | 2010-12-29 | 2011-05-25 | 北京邮电大学 | Code static analysis-based data race detecting method and system thereof |
CN102760095A (en) * | 2011-04-25 | 2012-10-31 | 清华大学 | Dynamic data race detection method based on static shared variable recognition |
CN104077144A (en) * | 2014-07-07 | 2014-10-01 | 西安交通大学 | Data race detection and evidence generation method based on multithreaded program constraint building |
CN111552539A (en) * | 2014-07-14 | 2020-08-18 | 甲骨文国际公司 | Variable handle |
WO2016122548A1 (en) * | 2015-01-29 | 2016-08-04 | Hewlett Packard Enterprise Development Lp | Hash index |
WO2016122546A1 (en) * | 2015-01-29 | 2016-08-04 | Hewlett Packard Enterprise Development Lp | Transactional key-value store |
CN109885489A (en) * | 2019-01-31 | 2019-06-14 | 清华大学 | Data contention detection method and device in driver |
US20220012060A1 (en) * | 2020-07-09 | 2022-01-13 | Femtosense, Inc. | Methods and apparatus for thread-based scheduling in multicore neural networks |
CN112817787A (en) * | 2021-01-28 | 2021-05-18 | 南京大学 | Automatic detection method for data competition of interrupt-driven embedded system |
CN112965838A (en) * | 2021-03-16 | 2021-06-15 | 支付宝(杭州)信息技术有限公司 | Data race checking method and device for concurrent program |
CN114238078A (en) * | 2021-11-23 | 2022-03-25 | 南京邮电大学 | Method for extracting dependency relationship between programs based on high-order function |
CN114428733A (en) * | 2022-01-19 | 2022-05-03 | 南京大学 | Kernel data competition detection method based on static program analysis and fuzzy test |
CN114647575A (en) * | 2022-02-23 | 2022-06-21 | 南京邮电大学 | C + + inter-process anomaly analysis system and method based on high-order function |
CN115098108A (en) * | 2022-06-22 | 2022-09-23 | 南京邮电大学 | Lightweight context sensitive pointer analysis method based on high-order function |
Non-Patent Citations (3)
Title |
---|
CHONGHUI GE 等: "Reversible Database Watermarking Based on Random Forest and Genetic Algorithm" * |
张杨 等: "并发程序中数据竞争检测方法" * |
禹振 等: "多线程程序数据竞争检测和验证方法研究综述" * |
Also Published As
Publication number | Publication date |
---|---|
CN115794592B (en) | 2023-07-04 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
Ivančić et al. | Efficient SAT-based bounded model checking for software verification | |
CN101894065B (en) | System and method for demonstrating the correctness of an execution trace in concurrent processing environments | |
US20090193416A1 (en) | Decidability of reachability for threads communicating via locks | |
Esparza et al. | Parameterized verification of asynchronous shared-memory systems | |
Bouyer et al. | Reachability in networks of register protocols under stochastic schedulers | |
Groote et al. | Modelling and analysing software in mCRL2 | |
Chatterjee et al. | Algorithms for algebraic path properties in concurrent systems of constant treewidth components | |
La Torre et al. | Safety of parametrized asynchronous shared-memory systems is almost always decidable | |
Finkbeiner et al. | Bounded cycle synthesis | |
Li et al. | Lilac: a modal separation logic for conditional probability | |
Shi et al. | A UTP semantics for communicating processes with shared variables and its formal encoding in PVS | |
Zhu et al. | Linking operational semantics and algebraic semantics for a probabilistic timed shared-variable language | |
CN115794592A (en) | Data competition detection method based on high-order function | |
Shi et al. | An analytical and experimental comparison of CSP extensions and tools | |
CN117473201A (en) | Determination method and device for feasible solution of constraint expression and electronic equipment | |
Jorgensen et al. | Computer aided verification of Lamport's fast mutual exclusion algorithm using colored Petri nets and occurrence graphs with symmetries | |
Waldburger | Checking Presence Reachability Properties on Parameterized Shared-Memory Systems | |
Dongol et al. | Simplifying proofs of linearisability using layers of abstraction | |
Wilhelm | Symbolic representations in WCET analysis | |
Finkbeiner et al. | Reactive synthesis: towards output-sensitive algorithms | |
Chen et al. | An abstract domain to infer linear absolute value equalities | |
He et al. | Stochastic circuit synthesis via satisfiability | |
Fu et al. | Algorithmic Analysis of Termination Problems for Nondeterministic Quantum Programs | |
Abrams et al. | CHITRA94: A Tool to Dynamically Charaterize Ensembles of Traces for Input Data Modeling and Output Analsis | |
Fronk et al. | State space analysis of Petri nets with relation-algebraic methods |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |