CN118151946A - Lock use detection method and device, storage medium and electronic device - Google Patents
Lock use detection method and device, storage medium and electronic device Download PDFInfo
- Publication number
- CN118151946A CN118151946A CN202410382192.0A CN202410382192A CN118151946A CN 118151946 A CN118151946 A CN 118151946A CN 202410382192 A CN202410382192 A CN 202410382192A CN 118151946 A CN118151946 A CN 118151946A
- Authority
- CN
- China
- Prior art keywords
- detection
- lock
- lock use
- detection result
- parameter
- 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.)
- Pending
Links
- 238000001514 detection method Methods 0.000 title claims abstract description 439
- 238000004458 analytical method Methods 0.000 claims abstract description 65
- 230000003068 static effect Effects 0.000 claims abstract description 29
- 238000000034 method Methods 0.000 claims abstract description 18
- 238000005457 optimization Methods 0.000 claims description 58
- 238000004891 communication Methods 0.000 claims description 14
- 238000012795 verification Methods 0.000 claims description 9
- 238000012545 processing Methods 0.000 claims description 7
- 238000004590 computer program Methods 0.000 claims description 3
- 238000011161 development Methods 0.000 abstract description 13
- 230000007812 deficiency Effects 0.000 description 10
- 230000008569 process Effects 0.000 description 7
- 230000002159 abnormal effect Effects 0.000 description 6
- 238000010586 diagram Methods 0.000 description 6
- 230000006870 function Effects 0.000 description 4
- 238000012544 monitoring process Methods 0.000 description 4
- 238000013024 troubleshooting Methods 0.000 description 4
- 230000009286 beneficial effect Effects 0.000 description 3
- 230000006399 behavior Effects 0.000 description 2
- 238000007405 data analysis Methods 0.000 description 2
- 238000005516 engineering process Methods 0.000 description 2
- 230000007717 exclusion Effects 0.000 description 2
- 206010000117 Abnormal behaviour Diseases 0.000 description 1
- 230000005856 abnormality Effects 0.000 description 1
- 238000004364 calculation method Methods 0.000 description 1
- 230000015556 catabolic process Effects 0.000 description 1
- 238000013461 design Methods 0.000 description 1
- 238000003745 diagnosis Methods 0.000 description 1
- 230000014509 gene expression Effects 0.000 description 1
- 238000012423 maintenance Methods 0.000 description 1
- 230000007246 mechanism Effects 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 230000004044 response Effects 0.000 description 1
- 230000000007 visual effect Effects 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/42—Syntactic analysis
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/42—Syntactic analysis
- G06F8/425—Lexical analysis
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/42—Syntactic analysis
- G06F8/427—Parsing
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/44—Encoding
- G06F8/443—Optimisation
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/45—Exploiting coarse grain parallelism in compilation, i.e. parallelism between groups of instructions
- G06F8/458—Synchronisation, e.g. post-wait, barriers, locks
Landscapes
- Engineering & Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Software Systems (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Debugging And Monitoring (AREA)
Abstract
The embodiment of the application provides a lock use detection method and device, a storage medium and electronic equipment. The method comprises the following steps: determining a detection command, a detection parameter and an abstract syntax tree for a multithreading program, wherein the detection command is used for detecting various lock use conditions, and the detection parameter at least comprises one lock use parameter; analyzing the detection command and the detection parameter, and determining a lock use detection target corresponding to the detection command and the detection parameter; traversing the abstract syntax tree based on the lock use detection target to obtain a lock use detection result corresponding to the lock use detection target; and generating a lock use optimizing strategy corresponding to the lock use detection result, and outputting the lock use detection result and the lock use optimizing strategy. Therefore, static code analysis and targeted analysis of source codes of the multithreaded program are realized, and the development efficiency of the program is improved.
Description
Technical Field
The present application relates to the field of computer technologies, and in particular, to a lock usage detection method and apparatus, a storage medium, and an electronic device.
Background
In order to ensure consistency and correctness of data, it is required to prevent multiple threads from modifying the same piece of data at the same time by using a lock, and accordingly security issues related to lock use are also becoming more important.
In the related art, static code analysis is generally used in the field of lock usage analysis and optimization to detect lock usage. The static code analysis is to detect common lock use errors, such as deadlock and competition conditions, by directly performing static analysis on codes input into a computer in a compiling period or a code examination process. That is, the static code in the related art cannot be detected in a targeted manner according to the needs of developers, and the development performance of the program is poor.
Disclosure of Invention
In view of the above, the embodiments of the present application provide a lock usage detection method and apparatus, a storage medium, and an electronic device, so as to solve or alleviate the problem that static codes in the related art cannot be detected pertinently according to the needs of developers, and the problem that the development performance of programs is poor.
According to a first aspect of an embodiment of the present application, there is provided a lock use detection method, the method including: determining a detection command, a detection parameter and an abstract syntax tree for a multithreading program, wherein the detection command is used for detecting various lock use conditions, and the detection parameter at least comprises one lock use parameter; analyzing the detection command and the detection parameter, and determining a lock use detection target corresponding to the detection command and the detection parameter; traversing the abstract syntax tree based on the lock use detection target to obtain a lock use detection result corresponding to the lock use detection target; and generating a lock use optimizing strategy corresponding to the lock use detection result, and outputting the lock use detection result and the lock use optimizing strategy.
In some embodiments of the present application, resolving the detection command and the detection parameter, determining a lock usage detection target corresponding to the detection command and the detection parameter, includes: analyzing the detection command and determining at least one detection object corresponding to the detection command; analyzing the detection parameters, and inquiring detection parameters corresponding to at least one detection object in the detection parameters; and correlating at least one detection object with the corresponding detection parameter to obtain the lock use detection object.
In some embodiments of the present application, traversing the abstract syntax tree based on the lock usage detection target obtains a lock usage detection result corresponding to the lock usage detection target, including: querying a lock usage detection code associated with the lock usage detection target based on the lock usage detection target traversing the abstract syntax tree; and carrying out code analysis on the lock use detection code to obtain a lock use detection result corresponding to the lock use detection target.
In some embodiments of the application, the lock usage detection result includes at least one of a lock contention detection result, a lock overuse detection result, a lock lack detection result, and a deadlock detection result.
In some embodiments of the present application, generating a lock usage optimization policy corresponding to a lock usage detection result includes: determining a type of lock use detection result, wherein the type of lock use detection result comprises at least one of a lock contention detection result, a lock overuse detection result, a lock lack detection result and a deadlock detection result; a lock usage optimization policy corresponding to the type of lock usage detection result is generated.
In some embodiments of the application, determining an abstract syntax tree for a multithreaded program comprises: acquiring a multithreading program; and carrying out static code analysis on the multithreaded program to obtain an abstract syntax tree.
In some embodiments of the present application, static code analysis is performed on a multithreaded program to obtain an abstract syntax tree, comprising: performing lexical analysis on the code character stream of the multithreaded program through a lexical analyzer to obtain a lexical unit stream; performing grammar verification on the lexical unit stream through a grammar analyzer to obtain a lexical analysis tree; and checking the lexical analysis tree through a semantic analyzer, and obtaining an abstract syntax tree after checking.
According to a second aspect of embodiments of the present application, there is provided a lock use detection device, the device comprising: the system comprises a determining module, a processing module and a processing module, wherein the determining module is used for determining a detection command, a detection parameter and an abstract syntax tree aiming at a multithreaded program, the detection command is used for detecting various lock use conditions, and the detection parameter at least comprises one lock use parameter; the analysis module is used for analyzing the detection command and the detection parameter and determining a lock use detection target corresponding to the detection command and the detection parameter; the traversal module is used for traversing the abstract syntax tree based on the lock use detection target to obtain a lock use detection result corresponding to the lock use detection target; the generation module is used for generating a lock use optimization strategy corresponding to the lock use detection result and outputting the lock use detection result and the lock use optimization strategy.
According to a third aspect of an embodiment of the present application, there is provided an electronic apparatus including: the device comprises a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface are communicated with each other through the communication bus; the memory is configured to store at least one executable instruction, where the executable instruction causes the processor to perform operations corresponding to the lock usage detection method according to any of the embodiments described above.
According to a fourth aspect of embodiments of the present application, there is provided a computer storage medium having stored thereon a computer program which, when executed by a processor, implements a lock use detection method as in any of the embodiments described above.
According to the lock use detection method, the lock use detection device, the storage medium and the electronic equipment, the lock use detection targets corresponding to the detection commands and the detection parameters are determined through analyzing the acquired detection commands and the detection parameters, so that the lock use detection results corresponding to the lock use detection targets are obtained based on the lock use detection targets by traversing the abstract syntax tree, static code analysis and targeted analysis of source codes of the multi-thread program are realized, the lock use optimization strategy corresponding to the lock use detection results is generated, the lock use detection results and the lock use optimization strategy are output, developers can be helped to quickly locate and solve the lock use problem, the abnormal problem can be solved as soon as possible according to the lock use optimization strategy, the time for debugging and checking the problem is shortened, and the development efficiency of the program is improved.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings that are required in the embodiments or the description of the prior art will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments described in the embodiments of the present application, and other drawings may be obtained according to these drawings for a person having ordinary skill in the art.
FIG. 1 is a flow chart of a lock usage detection method according to one embodiment of the present application;
FIG. 2 is a schematic diagram of an application flow of a tool for a lock usage detection method according to an embodiment of the present application;
FIG. 3 is a block diagram of a lock usage detection method apparatus according to one embodiment of the present application;
fig. 4 is a block diagram of an electronic device according to one embodiment of the application.
Detailed Description
In order to better understand the technical solutions in the embodiments of the present application, the following description will clearly and completely describe the technical solutions in the embodiments of the present application with reference to the accompanying drawings in the embodiments of the present application, and it is obvious that the described embodiments are only some embodiments of the present application, not all embodiments. All other embodiments, which are derived by a person skilled in the art based on the embodiments of the present application, shall fall within the scope of protection of the embodiments of the present application.
Currently, in the field of lock usage analysis and optimization, a static code analysis method and a runtime monitoring method are mainly adopted, wherein the static code analysis is to detect common lock usage problems through static analysis on codes, and the static code analysis is to detect common lock usage errors (such as deadlock and competing locks) in compiling time or code examining process, but the static code analysis method only provides diagnosis of the problems, lacks specific optimization suggestions, and cannot accurately analyze dynamic behaviors of a multi-thread program, so that false alarm or undetectable problems can be generated in the multi-thread program.
The runtime monitoring is a method for monitoring the use condition of the lock in the running process of the program, analyzes the use condition of the lock by recording the acquisition and release operations of the lock, and detects the problem of potential competition conditions, and the runtime detection can detect the dynamic behavior of the thread, but needs to insert additional codes into the program to collect the use information of the lock to obtain a detection result, and may have a certain influence on the performance of the program when the method for runtime monitoring is used.
In summary, the application provides a lock use detection method, which determines a lock use detection target corresponding to a detection command and a detection parameter by analyzing the acquired detection command and the detection parameter, so as to traverse an abstract syntax tree based on the lock use detection target to obtain a lock use detection result corresponding to the lock use detection target, realize static code analysis and targeted analysis of source codes of a multithreaded program, generate a lock use optimization strategy corresponding to the lock use detection result, output the lock use detection result and the lock use optimization strategy, help developers to quickly locate and solve the lock use problem and solve the abnormal problem as soon as possible according to the lock use optimization strategy, and reduce the time for debugging and troubleshooting the problem, thereby improving the development efficiency of the program.
The implementation of the embodiments of the present application will be further described below with reference to the accompanying drawings.
FIG. 1 is a flow chart of a lock usage detection method according to one embodiment of the present application.
As shown in fig. 1, the lock use detection method includes:
s11: determining a detection command for the multithreaded program, a detection parameter and an abstract syntax tree, wherein the detection command is used for detecting various lock use conditions, and the detection parameter at least comprises one lock use parameter.
Specifically, the detection command and detection parameters for the multithreaded program can be adjusted based on actual requirements, the detection command refers to a command for detecting the lock use condition in the multithreaded program, and the detection command can include information for lock contention, lock overuse, lock lack or deadlock, and the like, and can also include other detection information related to the lock use condition, which is not limited herein. The detection parameters are parameters related to the lock use condition, and can comprise parameters such as a lock type parameter, a function parameter of the lock use, a lock state parameter, a lock quantity parameter, a thread scheduling strategy or a timeout time, and the like, and can also comprise other parameters related to the lock use condition. Because the detection command and the detection parameters can be adjusted based on actual demands, developers can correspondingly adjust according to demands and program characteristics, system resources where the multithreaded program is located can be fully utilized, the calculation efficiency of the system is improved, and the lock use detection method is easier to implement.
For example, the detect command for the multithreaded program may be a detect lock deficiency command, where the required detect parameters are determined to be a lock type parameter and a thread number parameter based on the detect lock deficiency command. An abstract syntax tree (also called syntax parsing tree, abstract syntax tree, AST) is a syntax tree obtained by a compiler performing lexical analysis, syntax analysis and syntax verification on a source code composed of a multi-threaded program, and identifies the syntax structure and logic of the code. The application analyzes static codes of the multithreaded program at the compiling period and discovers the lock use problem in the multithreaded program according to the lock use condition.
S12: analyzing the detection command and the detection parameter, and determining a lock use detection target corresponding to the detection command and the detection parameter;
s13: traversing the abstract syntax tree based on the lock use detection target to obtain a lock use detection result corresponding to the lock use detection target.
Specifically, traversing the abstract syntax tree based on the lock use detection target refers to traversing sentences and expressions of source codes formed by the multithreading program on the basis of the abstract syntax tree, and identifying possible lock use problems of codes where the lock use detection target is located, thereby obtaining a lock use detection result. In addition, possible lock usage problems are recorded and marked after they are identified for subsequent optimization suggestion generation.
That is, after determining the detection command and the detection parameter, if the detection command is a detection lock deficiency command, the detection parameter is a lock type parameter and a thread number parameter, analyzing the detection command and the detection parameter, determining a corresponding lock use detection target, if the lock type parameter in the detection parameter is a write lock and the thread number parameter is 20, determining that the corresponding lock use detection target is a thread program using the write lock according to the lock type, then traversing an abstract syntax tree obtained by processing a source code formed by the multithreaded program, recognizing whether the lock deficiency problem of the write lock exists in the detection code, and if the lock deficiency problem exists, obtaining a lock use detection result corresponding to the lock use detection target, wherein the lock use detection result can be the write lock deficiency problem.
S14: and generating a lock use optimizing strategy corresponding to the lock use detection result, and outputting the lock use detection result and the lock use optimizing strategy.
Based on the problem of lack of locks in the mutual exclusion lock obtained in the embodiment, a corresponding lock use optimization strategy is generated, and the lock use optimization strategy can be used for introducing new mutual exclusion lock protection and outputting the lock use detection result and the lock use optimization strategy to a display interface for displaying to staff.
Fig. 2 is a schematic diagram illustrating an application flow of a tool applied to a lock usage detection method according to an embodiment of the present application.
As shown in fig. 2, the application flow of the lock usage analysis and optimization tool includes:
S21: acquiring source codes of a multithreaded program to be analyzed and optimized, and taking the source codes as input of a user interface of a tool applied to the lock use detection method;
S22: a compiler of the code analysis module performs static code analysis on source codes of the multithreaded program to generate an abstract syntax tree;
s23: acquiring detection commands and detection parameters for a multithreaded program and taking the detection commands and the detection parameters as input of a user interface of a tool applied to a lock use detection method;
S24: the code analysis module performs data analysis on the detection command and the detection parameter to determine a lock use detection target corresponding to the detection command and the detection parameter;
S25: the code analysis module traverses the abstract syntax tree based on the lock use detection target to obtain a lock use detection result corresponding to the lock use detection target, wherein analysis of control flow and data flow of the multithreaded program is involved in the process of traversing the abstract syntax tree and identifying potential lock use problems in source codes;
S26: the optimization suggestion module classifies and analyzes lock use detection results, wherein the lock use detection results can be classified according to detection commands and detection parameters, and can be classified into lock competition detection results, lock overuse detection results, lock lack detection results, deadlock detection results and the like, and corresponding data analysis is performed on different types of lock use detection results;
s27: the optimization suggestion module generates a lock use optimization strategy corresponding to the lock use detection result, wherein the generated lock use optimization strategy can be the lock use optimization strategy generated based on the optimization rule or the lock use optimization strategy in practice;
S28: the optimization suggestion module outputs the lock use detection result and the lock use optimization strategy to a user interface, wherein the user interface can be in a graphical interface, a command line interface or other visual display interfaces.
In this way, the lock use detection targets corresponding to the detection commands and the detection parameters are determined by analyzing the acquired detection commands and the detection parameters, so that the lock use detection results corresponding to the lock use detection targets are obtained based on the lock use detection targets by traversing the abstract syntax tree, static code analysis and targeted analysis of source codes of the multi-thread program are realized, the lock use optimization strategy corresponding to the lock use detection results is generated, the lock use detection results and the lock use optimization strategy are output, the lock use problem can be quickly positioned and understood by a developer, the lock use problem can be quickly solved according to the lock use optimization strategy, the time for debugging and checking the problem is shortened, and the development efficiency of the program is improved.
It should be noted that the lock usage analysis and optimization tool may be integrated into a development environment or a building system, and a developer may optimize the lock usage analysis and optimization tool according to actual requirements and program characteristics during the development process, so that the developer may better understand and master the specification and practice of the multithreading programming, and promote the development of the multithreading programming technology, thereby improving the performance and concurrency of the program.
In some embodiments, resolving the detection command and the detection parameter, determining a lock usage detection target corresponding to the detection command and the detection parameter, includes: analyzing the detection command and determining at least one detection object corresponding to the detection command; analyzing the detection parameters, and inquiring detection parameters corresponding to at least one detection object in the detection parameters; and correlating at least one detection object with the corresponding detection parameter to obtain the lock use detection object.
Specifically, only lock usage problem types may be included in the detection command, such as: detecting lock deficiency problems may also include lock types and lock usage problem types, such as: a lock deficiency problem of the write lock is detected. Therefore, the detection object can be of a lock use problem type, and comprises common lock competition problems and deadlock problems, also comprises problems of excessive lock use problems, lock deficiency problems and the like, and is obtained based on detection commands; but may also be a lock use problem type and a lock type. The detection command can be updated according to actual requirements, so that the lock using problem can be comprehensively analyzed.
The detection parameters can select corresponding parameters based on the detection command, so after the detection command is analyzed to obtain a detection object, the detection parameters corresponding to the detection object can be queried in the detection parameters, and the detection and the corresponding detection parameters are associated to obtain a lock use detection target, so that a corresponding lock use detection result is determined based on the lock use detection target traversing the abstract syntax tree.
In some embodiments, traversing the abstract syntax tree based on the lock usage detection target to obtain a lock usage detection result corresponding to the lock usage detection target includes: querying a lock usage detection code associated with the lock usage detection target based on the lock usage detection target traversing the abstract syntax tree; and carrying out code analysis on the lock use detection code to obtain a lock use detection result corresponding to the lock use detection target. Wherein, in some embodiments, the lock usage detection result includes at least one of a lock contention detection result, a lock overuse detection result, a lock lack detection result, and a deadlock detection result.
In the process of obtaining a lock use detection result corresponding to the lock use detection target based on the lock use detection target traversing the abstract syntax tree, firstly, searching the position of a function to which the mutex lock belongs based on the lock use detection target traversing the abstract syntax tree, determining the function code to which the mutex lock belongs as a lock use detection code related to the lock use detection target, analyzing the lock use detection code of the mutex lock, judging whether resources to be protected by the mutex lock are in the protection range of the mutex lock, if the resources to be protected by the mutex lock are determined not to be in the protection range, the number of the mutex lock is considered to be small, unprotected resources exist, and at the moment, the mutex lock can be output to be displayed on a user interface, so that staff can perform lock use optimization according to the lock use detection result as soon as possible.
Further, in some embodiments, generating a lock usage optimization policy corresponding to the lock usage detection result includes: determining a type of lock use detection result, wherein the type of lock use detection result comprises at least one of a lock contention detection result, a lock overuse detection result, a lock lack detection result and a deadlock detection result; a lock usage optimization policy corresponding to the type of lock usage detection result is generated.
In the foregoing embodiment, the lock usage detection result is that the exclusive lock has a lock deficiency problem, and a corresponding lock usage optimization policy may be generated for the lock usage detection result to introduce new exclusive lock protection to ensure correct access of the shared resource. In another example, the lock usage detection result may be a lock contention detection result and a deadlock detection result, for which a corresponding lock usage optimization policy may be generated to suggest adjusting the granularity of the lock to avoid unnecessary lock contention and resource contention, or to replace the exclusive lock with a lighter-weight synchronization mechanism, such as: semaphores or read-write locks, etc. to reduce lock contention problems and improve concurrency performance of the program; the dead lock detection results may generate a corresponding lock usage optimization strategy to optimize the order of lock acquisition (i.e., locking) and release (i.e., unlocking) to reduce the potential risk of deadlock.
Therefore, aiming at the unused lock use detection result, a corresponding lock use optimization strategy is generated, the lock use can be analyzed and optimized, the occurrence frequency of abnormal lock use problems can be improved, the concurrency and response performance of a program can be improved, abnormal behaviors such as program breakdown and the like caused by improper lock use can be reduced, and the stability and reliability of the program can be improved.
In some embodiments, determining an abstract syntax tree for a multithreaded program includes: acquiring a multithreading program; and carrying out static code analysis on the multithreaded program to obtain an abstract syntax tree.
Wherein in some embodiments, static code analysis is performed on the multithreaded program to obtain an abstract syntax tree, comprising: performing lexical analysis on the code character stream of the multithreaded program through a lexical analyzer to obtain a lexical unit stream; performing grammar verification on the lexical unit stream through a grammar analyzer to obtain a lexical analysis tree; and checking the lexical analysis tree through a semantic analyzer, and obtaining an abstract syntax tree after checking.
Specifically, static code analysis can be performed on a multithreaded program through a compiler to obtain an abstract syntax tree, the front end task of the compiler is to read input characters from codes of the multithreaded program through a lexical analyzer, and divide the codes into a series of words (token) according to word-forming rules to obtain a lexical unit stream (token stream); then, using the lexical unit stream as input of a grammar analyzer, performing grammar verification through the lexical unit stream of the grammar analyzer, and judging whether the lexical unit stream is a legal program of a corresponding programming language or not so as to obtain a lexical analysis tree after verification is passed; and then the semantic analyzer performs semantic verification on the lexical analysis tree, and after verification is passed, an abstract syntax tree is obtained.
In summary, the lock use detection method provided by the application determines the lock use detection target corresponding to the detection command and the detection parameter by analyzing the acquired detection command and the detection parameter, so as to obtain the lock use detection result corresponding to the lock use detection target based on the lock use detection target traversing abstract syntax tree, realize static code analysis and targeted analysis of the source code of the multithreaded program, generate the lock use optimization strategy corresponding to the lock use detection result, output the lock use detection result and the lock use optimization strategy, help developers to quickly locate and understand the lock use problem, quickly solve the lock use problem according to the lock use optimization strategy, reduce the maintenance cost of the program, reduce the probability of abnormality of the lock use problem in the multithreaded environment, improve the development efficiency and expandability of the program, and be easier to popularize for systems (such as servers, database systems, scientific computing applications and the like) needing a large number of concurrent operations.
In addition, the lock use detection method can also be combined with the technical means of runtime detection on the basis of static code analysis, so that the comprehensive detection of the lock use problem of the multithreaded program is realized.
The lock usage detection method of the present embodiment may be performed by any suitable electronic device having data processing capabilities, including, but not limited to: servers, mobile terminals (such as mobile phones, PADs, etc.), and PCs, etc.
Fig. 3 is a block diagram of a lock usage detecting device according to an embodiment of the present application.
As shown in fig. 3, the lock use detection apparatus 300 may perform the lock use detection method of fig. 1, the lock use detection apparatus 300 including: a determining module 301, configured to determine a detection command, a detection parameter and an abstract syntax tree for a multithreaded program, where the detection command is used to detect various lock usage conditions, and the detection parameter includes at least one lock usage parameter; the analyzing module 302 is configured to analyze the detection command and the detection parameter, and determine a lock usage detection target corresponding to the detection command and the detection parameter; a traversing module 303, configured to traverse the abstract syntax tree based on the lock usage detection target, and obtain a lock usage detection result corresponding to the lock usage detection target; the generating module 304 is configured to generate a lock usage optimization policy corresponding to the lock usage detection result, and output the lock usage detection result and the lock usage optimization policy.
In some embodiments of the present application, the parsing module 302 is specifically configured to determine a lock usage detection target corresponding to the detection command and the detection parameter, including: analyzing the detection command and determining at least one detection object corresponding to the detection command; analyzing the detection parameters, and inquiring detection parameters corresponding to at least one detection object in the detection parameters; and correlating at least one detection object with the corresponding detection parameter to obtain the lock use detection object.
In some embodiments of the present application, the traversal module 303 is specifically configured to: querying a lock usage detection code associated with the lock usage detection target based on the lock usage detection target traversing the abstract syntax tree; and carrying out code analysis on the lock use detection code to obtain a lock use detection result corresponding to the lock use detection target.
In some embodiments of the application, the lock usage detection result includes at least one of a lock contention detection result, a lock overuse detection result, a lock lack detection result, and a deadlock detection result.
In some embodiments of the present application, the generating module 304 is specifically configured to: determining a type of lock use detection result, wherein the type of lock use detection result comprises at least one of a lock contention detection result, a lock overuse detection result, a lock lack detection result and a deadlock detection result; a lock usage optimization policy corresponding to the type of lock usage detection result is generated.
In some embodiments of the present application, the determining module 301 is specifically configured to: acquiring a multithreading program; and carrying out static code analysis on the multithreaded program to obtain an abstract syntax tree.
In some embodiments of the present application, parsing module 302 is further configured to: performing lexical analysis on the code character stream of the multithreaded program through a lexical analyzer to obtain a lexical unit stream; performing grammar verification on the lexical unit stream through a grammar analyzer to obtain a lexical analysis tree; and checking the lexical analysis tree through a semantic analyzer, and obtaining an abstract syntax tree after checking.
According to the lock use detection device provided by the embodiment of the application, the lock use detection targets corresponding to the detection commands and the detection parameters are determined by analyzing the acquired detection commands and the detection parameters, so that the lock use detection results corresponding to the lock use detection targets are obtained based on the lock use detection targets by traversing the abstract syntax tree, the static code analysis and the targeted analysis of the source codes of the multi-thread program are realized, the lock use optimization strategy corresponding to the lock use detection results is generated, and the lock use detection results and the lock use optimization strategy are output, thereby being beneficial to developers to quickly positioning and solving the lock use problem and solving the abnormal problem as soon as possible according to the lock use optimization strategy, reducing the time for debugging and troubleshooting the problem, and further improving the development efficiency of the program.
The lock usage detection device 300 of the present embodiment is configured to implement the corresponding lock usage detection method in the foregoing multiple method embodiments, and has the beneficial effects of the corresponding method embodiments, which are not described herein. In addition, the functional implementation of each module in the lock usage detecting apparatus 300 of the present embodiment may refer to the description of the corresponding parts in the foregoing method embodiments, and will not be repeated here.
Fig. 4 is a block diagram of an electronic device according to an embodiment of the present application, and the embodiment of the present application is not limited to the specific implementation of the electronic device.
As shown in fig. 4, the electronic device 400 may include: processor 402, memory 403, communication interface 404, and communication bus 405, processor 402, memory 403, and communication interface 404 completing communication with each other via communication bus 405; the memory 403 is configured to store at least one executable instruction, where the executable instruction causes the processor 402 to perform operations corresponding to the lock usage detection method according to any of the above embodiments.
The processor 402 may be a central processing unit CPU, or an Application-specific integrated Circuit ASIC (Application SPECIFIC INTEGRATED Circuit), or one or more integrated circuits configured to implement embodiments of the present application. The one or more processors comprised by the smart device may be the same type of processor, such as one or more CPUs; but may also be different types of processors such as one or more CPUs and one or more ASICs.
The memory 403 is used for storing programs, and may include a high-speed RAM memory, and may further include a non-volatile memory (non-volatile memory), such as at least one magnetic disk memory.
According to the electronic equipment, the lock use detection targets corresponding to the detection commands and the detection parameters are determined by analyzing the acquired detection commands and the detection parameters, so that lock use detection results corresponding to the lock use detection targets are obtained based on the lock use detection targets by traversing the abstract syntax tree, static code analysis and targeted analysis of source codes of the multithreaded program are realized, lock use optimization strategies corresponding to the lock use detection results are generated, and the lock use detection results and the lock use optimization strategies are output, so that developers can be helped to quickly locate and solve lock use problems and quickly solve abnormal problems according to the lock use optimization strategies, the time for debugging and troubleshooting the problems is shortened, and the development efficiency of the program is improved.
The embodiment of the application also provides a computer storage medium, on which a computer program is stored, which when executed by a processor implements the lock use detection method of any of the above embodiments.
According to the computer storage medium of the embodiment of the application, the lock use detection targets corresponding to the detection commands and the detection parameters are determined by analyzing the acquired detection commands and the detection parameters, so that the lock use detection results corresponding to the lock use detection targets are obtained based on the lock use detection targets by traversing the abstract syntax tree, the static code analysis and the targeted analysis of the source codes of the multi-thread program are realized, the lock use optimization strategy corresponding to the lock use detection results is generated, and the lock use detection results and the lock use optimization strategy are output, thereby being beneficial to developers to quickly positioning and solving the lock use problem and quickly solving the abnormal problem according to the lock use optimization strategy, reducing the time for debugging and troubleshooting the problem, and improving the development efficiency of the program
It should be noted that, according to implementation requirements, each component/step described in the embodiments of the present application may be split into more components/steps, or two or more components/steps or part of operations of the components/steps may be combined into new components/steps, so as to achieve the objects of the embodiments of the present application.
The above-described methods according to embodiments of the present application may be implemented in hardware, firmware, or as software or computer code storable in a recording medium such as a CD ROM, RAM, floppy disk, hard disk, or magneto-optical disk, or as computer code originally stored in a remote recording medium or a non-transitory machine-readable medium and to be stored in a local recording medium downloaded through a network, so that the methods described herein may be stored on such software processes on a recording medium using a general purpose computer, special purpose processor, or programmable or special purpose hardware such as an ASIC or FPGA. It is understood that a computer, processor, microprocessor controller or programmable hardware includes a memory component (e.g., RAM, ROM, flash memory, etc.) that can store or receive software or computer code that, when accessed and executed by the computer, processor or hardware, implements the lock usage detection methods described herein. Further, when the general-purpose computer accesses code for implementing the lock use detection method shown herein, execution of the code converts the general-purpose computer into a special-purpose computer for executing the lock use detection method shown herein.
Those of ordinary skill in the art will appreciate that the elements and method steps of the examples described in connection with the embodiments disclosed herein can be implemented as electronic hardware, or as a combination of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the solution. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the embodiments of the present application.
The above embodiments are only for illustrating the embodiments of the present application, but not for limiting the embodiments of the present application, and various changes and modifications may be made by one skilled in the relevant art without departing from the spirit and scope of the embodiments of the present application, so that all equivalent technical solutions also fall within the scope of the embodiments of the present application, and the scope of the embodiments of the present application should be defined by the claims. The system, device or module set forth in the above embodiments may be implemented in particular by a computer chip or entity, or by a product having some function.
Claims (10)
1. A lock use detection method, the method comprising:
determining a detection command, detection parameters and an abstract syntax tree for a multithreaded program, wherein the detection command is used for detecting various lock use conditions, and the detection parameters at least comprise one lock use parameter;
Analyzing the detection command and the detection parameter, and determining a lock use detection target corresponding to the detection command and the detection parameter;
Traversing the abstract syntax tree based on the lock use detection target to obtain a lock use detection result corresponding to the lock use detection target;
and generating a lock use optimizing strategy corresponding to the lock use detection result, and outputting the lock use detection result and the lock use optimizing strategy.
2. The lock use detection method according to claim 1, wherein analyzing the detection command and the detection parameter, determining a lock use detection target corresponding to the detection command and the detection parameter, comprises:
analyzing the detection command and determining at least one detection object corresponding to the detection command;
Analyzing the detection parameters, and inquiring detection parameters corresponding to the at least one detection object in the detection parameters;
And correlating the at least one detection object with the corresponding detection parameter to obtain the lock use detection object.
3. The lock use detection method according to claim 1, wherein traversing the abstract syntax tree based on the lock use detection target obtains a lock use detection result corresponding to the lock use detection target, comprising:
Traversing the abstract syntax tree based on the lock usage detection target, querying a lock usage detection code associated with the lock usage detection target;
And carrying out code analysis on the lock use detection code to obtain a lock use detection result corresponding to the lock use detection target.
4. The lock use detection method according to claim 3, wherein the lock use detection result includes at least one of a lock contention detection result, a lock overuse detection result, a lock lack detection result, and a deadlock detection result.
5. The lock use detection method according to claim 4, wherein generating a lock use optimization policy corresponding to the lock use detection result includes:
Determining a type of the lock usage detection result, wherein the type of the lock usage detection result comprises at least one of the lock contention detection result, the lock overuse detection result, the lock lack detection result, and the deadlock detection result;
and generating a lock use optimization strategy corresponding to the type of the lock use detection result.
6. The lock usage detection method according to claim 1, wherein determining an abstract syntax tree for a multithreaded program comprises:
Acquiring the multithreaded program;
and carrying out static code analysis on the multithreaded program to obtain the abstract syntax tree.
7. The lock usage detection method according to claim 6, wherein performing static code analysis on the multithreaded program results in the abstract syntax tree, comprising:
Performing lexical analysis on the code character stream of the multi-thread program through a lexical analyzer to obtain a lexical unit stream;
performing grammar verification on the lexical unit stream through a grammar analyzer to obtain a lexical analysis tree;
and checking the lexical analysis tree through a semantic analyzer, and obtaining the abstract syntax tree after the checking is passed.
8. A lock use detection device, comprising:
the system comprises a determining module, a processing module and a processing module, wherein the determining module is used for determining a detection command, detection parameters and an abstract syntax tree aiming at a multithreaded program, the detection command is used for detecting various lock use conditions, and the detection parameters at least comprise one lock use parameter;
The analysis module is used for analyzing the detection command and the detection parameter and determining a lock use detection target corresponding to the detection command and the detection parameter;
The traversing module is used for traversing the abstract syntax tree based on the lock use detection target to obtain a lock use detection result corresponding to the lock use detection target;
The generation module is used for generating a lock use optimization strategy corresponding to the lock use detection result and outputting the lock use detection result and the lock use optimization strategy.
9. An electronic device, comprising: the device comprises a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface complete communication with each other through the communication bus; the memory is configured to store at least one executable instruction that causes the processor to perform operations corresponding to the lock usage detection method according to any one of claims 1 to 7.
10. A computer storage medium having stored thereon a computer program which when executed by a processor implements the lock use detection method as claimed in any one of claims 1 to 7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202410382192.0A CN118151946A (en) | 2024-03-29 | 2024-03-29 | Lock use detection method and device, storage medium and electronic device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202410382192.0A CN118151946A (en) | 2024-03-29 | 2024-03-29 | Lock use detection method and device, storage medium and electronic device |
Publications (1)
Publication Number | Publication Date |
---|---|
CN118151946A true CN118151946A (en) | 2024-06-07 |
Family
ID=91298432
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202410382192.0A Pending CN118151946A (en) | 2024-03-29 | 2024-03-29 | Lock use detection method and device, storage medium and electronic device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN118151946A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN118519792A (en) * | 2024-07-24 | 2024-08-20 | 福建时代星云科技有限公司 | Lock scheduling optimization method and terminal |
-
2024
- 2024-03-29 CN CN202410382192.0A patent/CN118151946A/en active Pending
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN118519792A (en) * | 2024-07-24 | 2024-08-20 | 福建时代星云科技有限公司 | Lock scheduling optimization method and terminal |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US8732669B2 (en) | Efficient model checking technique for finding software defects | |
CN114428733B (en) | Kernel data race detection method based on static program analysis and fuzz testing | |
KR101979329B1 (en) | Method and apparatus for tracking security vulnerable input data of executable binaries thereof | |
US20090193417A1 (en) | Tractable dataflow analysis for concurrent programs via bounded languages | |
EP3752945B1 (en) | Automatic generation of patches for security violations | |
US10466988B2 (en) | Systems and methods for automatic computer code parallelization | |
US10725889B2 (en) | Testing multi-threaded applications | |
US8392891B2 (en) | Technique for finding relaxed memory model vulnerabilities | |
CN118151946A (en) | Lock use detection method and device, storage medium and electronic device | |
Tunç et al. | Sound dynamic deadlock prediction in linear time | |
Li et al. | Effectively manifesting concurrency bugs in android apps | |
US8607204B2 (en) | Method of analyzing single thread access of variable in multi-threaded program | |
CN103778062A (en) | Multi-interrupt routine data access conflict detection method based on abstract interpretation | |
CN110244954B (en) | Compiling method and equipment for application program | |
WO2021238462A1 (en) | Method and device for detecting memory out-of-order | |
CN118152298A (en) | Memory access detection method and device, electronic equipment and computer storage medium | |
US8875100B2 (en) | Pattern analysis and performance accounting | |
CN114153750B (en) | Code checking method and device, code compiling method and electronic equipment | |
Malakar et al. | RaceFixer--An Automated Data Race Fixer | |
Guo et al. | Thread scheduling sequence generation based on all synchronization pair coverage criteria | |
Feng et al. | Towards understanding bugs in go programming language | |
Bae et al. | Lightweight Method for On-the-fly Detection of Multivariable Atomicity Violations | |
US9229725B2 (en) | Safe conditional-load and conditional-store operations | |
Jalbert et al. | Using clone detection to identify bugs in concurrent software | |
He et al. | An efficient method for detecting concurrency errors in object-oriented programs |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |