Self-adaptive lightweight dynamic hybrid data competition detection method
1. A self-adaptive lightweight dynamic hybrid data competition detection method is characterized by comprising the following steps:
the method comprises the following steps: aiming at a Java concurrent program P, in the process of not influencing the dynamic execution of the P, a dynamic data race detector respectively maintains two read queues RC with the length of Q _ LEN being 6 for each shared variable xxAnd write queue WCx,RCxAnd WCxStoring the read access information and the write access information of each thread to x by a cache mechanism by adopting a first-in first-out principle, and accessing the information to<epoch,LockSet>The form storage is used for representing the thread number, the access timestamp and the lock set held by the current thread of the thread t, wherein epoch is represented as t @ c, which means that the current timestamp of the thread t is c;
step two: when the thread t accesses x, judging whether the current access is read access, and if not, entering a fifth step; otherwise, firstly judging whether the current x is in the read sharing state, if so, updating the read vector clock RxClock vector VC for thread tt(ii) a Otherwise, the current read access and RC of t are judgedxWhether the read access stored by the last element forms a concurrent access state or not, if so, the dynamic data race detector automatically switches to a read vector clock RxRecording the history of read access, and entering the step three;
step three: traverse and analyze WCxThe history of the middle thread u for x accesses information up to the last element, i.e. if WCx[u]Timestamp of middle thread u and timestamp VC of current thread tt[u]The Happens-before relationship is not satisfied, and t is the currently acquired lock set and WCx[u]The LockSet intersection is empty, then write-once is reportedReading type data race errors, and entering a step four;
step four: determining RCxWhether the epoch value of the last element is equal to the epoch value of t or not is judged, and if yes, the LockSet set of the last element is updated; otherwise, judging whether the queue is full, if the queue is in full state, deleting the queue head element and adding the current access information into the RCxOtherwise, directly adding the current access information into the RCx;
Step five: the thread t accesses the x and judges whether the current access is write access, if the current access is not write access, the step two is returned, and if not, the WC is traversed and analyzedxThe history of the middle thread u for x accesses information up to the last element, i.e. if WCx[u]Timestamp of middle thread u and timestamp VC of current thread tt[u]The Happens-before relationship is not satisfied, and t is the currently acquired lock set and WCx[u]Reporting write-write type data competition errors if the LockSet intersection is an empty set, and entering a sixth step;
step six: judging whether x is currently in a read sharing state, and judging a read vector clock R if x is currently in the read sharing statexWhether the current thread t meets the Happens-before relation or not, if so, the data competition error of the read-write type is reported and R is deletedxOtherwise, entering the step seven;
step seven: traverse and analyze RCxThe history of the middle thread u for x accesses information up to the last element, i.e. if RCx[u]Timestamp of middle thread u and timestamp VC of current thread tt[u]Does not satisfy Happens-before relationship, and t is the current acquired lock set and RCx[u]Reporting a read-write type data competition error if the LockSet intersection is an empty set, and entering the step eight;
step eight: judging WCxWhether the epoch value of the last element is equal to the epoch value of t or not is judged, and if yes, the LockSet set of the last element is updated; otherwise, judging whether the queue is full, if the queue is in a full state, deleting the queue head element and adding the current access information into the WCxOtherwise, directly adding the current access information into the RCx;
Step nine: judging a termination condition, judging whether the program P is executed completely, and if the program P is executed completely, outputting a data competition detection report; otherwise, returning to the step two.
Background
Multithread programs are ubiquitous in modern programming, and are widely applied due to the advantages of remarkably improving the computing efficiency and performance of a system, but many concurrent defects are difficult to find due to the staggered execution of the threads, so that the correctness of the running result of the concurrent program can be caused or the system is directly crashed. The concurrent program defect detection plays an important role in concurrent program research, and particularly, the data competition problem is larger in common concurrent defects, so that how to accurately and efficiently detect the data competition defect becomes a problem which is urgently needed to be solved for improving the reliability and the safety of the multi-thread program.
In order to detect data race errors as much as possible, a plurality of scholars at home and abroad are dedicated to research on a data race dynamic detection technology, and can detect data races as much as possible in a low detection overhead mode under the condition of not influencing the correctness of a program operation result. The dynamic data race defect detection technology mainly judges which access operations form data race by collecting relevant access information in the dynamic execution process of a tested program, but the collected relevant information is incomplete due to uncertainty of thread scheduling, the situations of missing report and false report exist, and a large amount of memory resources are consumed by the technology. Therefore, the invention provides a self-adaptive lightweight dynamic hybrid data race detection method which can accurately and effectively detect data races in a low-execution-overhead and high-coverage mode.
Disclosure of Invention
The dynamic data competition detection technology mainly utilizes Happens-berform to verify whether concurrent access exists or not by collected read-write access information of each thread on a shared variable, and utilizes lock information to verify whether the shared variable is protected by a lock in the access process or not, and comprehensively utilizes the two methods to detect data competition. In using dynamic data race detection, the goal is to improve detection accuracy as much as possible while reducing detection time and memory overhead as much as possible.
The invention relates to a self-adaptive lightweight dynamic hybrid data competition detection method, which is characterized by comprising the following steps of:
the method comprises the following steps: aiming at a Java concurrent program P, in the process of not influencing the dynamic execution of the P, a dynamic data race detector respectively maintains two read queues RC with the length of Q _ LEN being 6 for each shared variable xxAnd write queue WCx,RCxAnd WCxStoring the read access information and the write access information of each thread to x by a cache mechanism by adopting a first-in first-out principle, and accessing the information to<epoch,LockSet>A formal deposit used to represent the thread number of the thread t, the access timestamp and the lock set held by the current thread, where epoch is denoted as t @ c, meaningThe current timestamp of the thread t is c;
step two: when the thread t accesses x, judging whether the current access is read access, and if not, entering a fifth step; otherwise, firstly judging whether the current x is in the read sharing state, if so, updating the read vector clock RxClock vector VC for thread tt(ii) a Otherwise, the current read access and RC of t are judgedxWhether the read access stored by the last element forms a concurrent access state or not, if so, the dynamic data race detector automatically switches to a read vector clock RxRecording the history of read access, and entering the step three;
step three: traverse and analyze WCxThe history of the middle thread u for x accesses information up to the last element, i.e. if WCx[u]Timestamp of middle thread u and timestamp VC of current thread tt[u]The Happens-before relationship is not satisfied, and t is the currently acquired lock set and WCx[u]Reporting a write-read type data competition error if the LockSet intersection is an empty set, and entering a fourth step;
step four: determining RCxWhether the epoch value of the last element is equal to the epoch value of t or not is judged, and if yes, the LockSet set of the last element is updated; otherwise, judging whether the queue is full, if the queue is in full state, deleting the queue head element and adding the current access information into the RCxOtherwise, directly adding the current access information into the RCx;
Step five: the thread t accesses the x and judges whether the current access is write access, if the current access is not write access, the step two is returned, and if not, the WC is traversed and analyzedxThe history of the middle thread u for x accesses information up to the last element, i.e. if WCx[u]Timestamp of middle thread u and timestamp VC of current thread tt[u]The Happens-before relationship is not satisfied, and t is the currently acquired lock set and WCx[u]Reporting write-write type data competition errors if the LockSet intersection is an empty set, and entering a sixth step;
step six: judging whether x is currently in a read sharing state, and judging a read vector clock R if x is currently in the read sharing statexWhether the current thread t satisfies HaIf the sense-before relation is satisfied, reporting the read-write type data competition error and deleting RxOtherwise, entering the step seven;
step seven: traverse and analyze RCxThe history of the middle thread u for x accesses information up to the last element, i.e. if RCx[u]Timestamp of middle thread u and timestamp VC of current thread tt[u]Does not satisfy Happens-before relationship, and t is the current acquired lock set and RCx[u]Reporting a read-write type data competition error if the LockSet intersection is an empty set, and entering the step eight;
step eight: judging WCxWhether the epoch of the last element is equal to the epoch of the t or not is judged, and if yes, the LockSet set of the last element is updated; otherwise, judging whether the queue is full, if the queue is in a full state, deleting the queue head element and adding the current access information into the WCxOtherwise, directly adding the current access information into the RCx;
Step nine: judging a termination condition, judging whether the program P is executed completely, and if the program P is executed completely, outputting a data competition detection report; otherwise, returning to the step two.
Drawings
Fig. 1 is a flow chart of a method for detecting contention of adaptive lightweight dynamic hybrid data.
FIG. 2 is a comparison graph of the average data race amounts detected by different dynamic data race detection methods.
FIG. 3 is a comparison graph of average memory overhead for different dynamic data race detection methods.
Detailed Description
Taking data race detection of a classic Java benchmark program "raytracer" as an example, a specific implementation of the adaptive lightweight dynamic hybrid data race detection method provided by the invention is described with reference to fig. 1.
The method comprises the following steps: aiming at a Java concurrent program raytracer, in the process of not influencing the dynamic execution of the raytracer, a dynamic data race detector respectively maintains two read queues RC with the length of Q _ LEN ═ 6 for each shared variable xxAnd write queue WCx,RCxAnd WCxStoring the read access information and the write access information of each thread to x by a cache mechanism by adopting a first-in first-out principle, and accessing the information to<epoch,LockSet>The form storage is used for representing the thread number, the access timestamp and the lock set held by the current thread of the thread t, wherein epoch is represented as t @ c, which means that the current timestamp of the thread t is c;
step two: when the thread 2 accesses the shared variable checksum1, judging whether the current access is read access, and if the current access is not read access, entering the step five; otherwise, firstly judging whether the current checksum1 is in the read sharing state, if so, updating the read vector clock RxClock vector VC for thread 2t(ii) a Otherwise, judging 2 current read access and RCxWhether the read access stored by the last element forms a concurrent access state or not, if so, the dynamic data race detector automatically switches to a read vector clock RxRecording the history of read access, and entering the step three;
step three: traverse and analyze WCxThe history of the access information of the middle thread u to the checksum1 until the last element, i.e. if WCx[u]Timestamp of middle thread u and timestamp VC of current thread 2t[u]The Happens-before relationship is not satisfied and thread 2 currently acquires a lock set and WCx[u]Reporting a write-read type data competition error if the LockSet intersection is an empty set, and entering a fourth step;
step four: determining RCxWhether the epoch value of the last element is equal to the epoch value of the thread 2 or not is judged, and if yes, the LockSet set of the last element is updated; otherwise, judging whether the queue is full, if the queue is in full state, deleting the queue head element and adding the current access information into the RCxOtherwise, directly adding the current access information into the RCx;
Step five: thread 2 accesses checksum1, judges whether the current access is write access, if not, returns to step two, otherwise, traverses and analyzes WCxThe history of the access information of the middle thread u to the checksum1 until the last element, i.e. if WCx[u]Timestamp of middle thread u and timestamp VC of current thread 2t[u]The Happens-before relationship is not satisfied and thread 2 currently acquires a lock set and WCx[u]Reporting write-write type data competition errors if the LockSet intersection is an empty set, and entering a sixth step;
step six: judging whether the checksum1 is in a read sharing state currently, and judging a read vector clock R if the checksum1 is in the read sharing statexWhether the current thread t meets the Happens-before relation or not, if so, the data competition error of the read-write type is reported and R is deletedxOtherwise, entering the step seven;
step seven: traverse and analyze RCxThe history of the middle thread u for x accesses information up to the last element, i.e. if RCx[u]Timestamp of middle thread u and timestamp VC of current thread 2t[u]The Happens-before relationship is not satisfied, and thread 2 currently acquires a Lock set and RCx[u]Reporting a read-write type data competition error if the LockSet intersection is an empty set, and entering the step eight;
step eight: judging WCxWhether the epoch value of the last element is equal to the epoch of the thread 2 or not is judged, and if yes, the LockSet set of the last element is updated; otherwise, judging whether the queue is full, if the queue is in a full state, deleting the queue head element and adding the current access information into the WCxOtherwise, directly adding the current access information into the RCx;
Step nine: judging a termination condition, judging whether the execution of the program raytracer is finished, and if the execution of the program raytracer is finished, outputting a data competition detection report; otherwise, returning to the step two. For example, after the program raytracer is executed, the output data race detection report is:
through the above processes, a self-adaptive lightweight dynamic hybrid data competition detection method can be realized, a detection flow chart is shown in fig. 1, 10 experiments are respectively performed by using an Eraser method, a Djit + method and the method in the invention aiming at a benchmark program "raytracer", fig. 2 is an average value of data competition quantity detected in 10 experiments, and fig. 3 is average memory overhead of each detection method in 10 experiments. As can be seen from fig. 2 and fig. 3, the data contention amount detected by the method is equivalent to Djit +, and the average memory overhead is reduced by 40%, which is 88.9% lower than the false alarm rate of the Eraser method. The method can effectively detect the data competition with low cost and can be used as a new method for detecting the dynamic data competition.