CN107479980A - A kind of method and apparatus for detecting deadlock in application - Google Patents

A kind of method and apparatus for detecting deadlock in application Download PDF

Info

Publication number
CN107479980A
CN107479980A CN201610402975.6A CN201610402975A CN107479980A CN 107479980 A CN107479980 A CN 107479980A CN 201610402975 A CN201610402975 A CN 201610402975A CN 107479980 A CN107479980 A CN 107479980A
Authority
CN
China
Prior art keywords
lock
operation information
lock operation
intended application
deadlock
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
Application number
CN201610402975.6A
Other languages
Chinese (zh)
Other versions
CN107479980B (en
Inventor
赵树起
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Alibaba Group Holding Ltd
Original Assignee
Alibaba Group Holding Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Alibaba Group Holding Ltd filed Critical Alibaba Group Holding Ltd
Priority to CN201610402975.6A priority Critical patent/CN107479980B/en
Publication of CN107479980A publication Critical patent/CN107479980A/en
Application granted granted Critical
Publication of CN107479980B publication Critical patent/CN107479980B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/52Program synchronisation; Mutual exclusion, e.g. by means of semaphores
    • G06F9/524Deadlock detection or avoidance

Abstract

The purpose of the application is to provide a kind of method and apparatus for detecting deadlock in application.Compared with prior art, the application performs lock tracking configuration operation to intended application, obtains multiple lock operation informations during the intended application operation, determines to whether there is deadlock in the intended application by detecting the multiple lock operation information;The application completes the tracking to any lock operation using the method for dynamic modification application program actuating code, and user-defined lock operation can be tracked, then deadlock is determined whether there is according to lock usage track result, so as to accurately and efficiently detect Deadlock, lifts Consumer's Experience.In addition, when herein described potential dead lock condition is included with association's journey task switching occurs in physical thread, before switching there is the lock not discharged in association's journey task, so as to support the detection to Deadlock in association's journey.

Description

A kind of method and apparatus for detecting deadlock in application
Technical field
The application is related to computer realm, more particularly to a kind of technology for detecting deadlock in application.
Background technology
Different from general single threaded application program development, multithread programs exploitation needs to consider the problem of more, such as Common potential cross-thread interaction problems.The resource accessed for multi-thread concurrent, if protected without mutually exclusive operation, it can send out Raw mutual competitions and conflicts, multithreading can cause application exception because interacting, and operation result is unreliable.Therefore, resource Such issues that protection lock is made to solve.But in multithread application, because the application method of lock or more lock locking order Problem, application program deadlock is likely to result in, causes thread to be hung dead, program is not normally functioning.
Deadlock be most difficult in multithread programs investigation the problem of one of, many Deadlocks even can not exploitation survey The examination stage finds, reaches the standard grade until product and is just triggered in some scenarios, the generation of this problem is for those requirement of real-time Very high business is fatal.Such issues that in order to solve, a variety of methods are mined out, but because the complexity of deadlock reason Property, it can be found that all Deadlocks without a kind of general method.Below first common deadlock detection method/Facility Column Lift as follows:
1) method that scanning software source code carries out static analysis:Cqual/Oink/Jqual is the static instruction point increased income Analysis instrument, its technological synthesis employ type inference and constraint solving, can be good at completing Deadlock Detection problem;Clang is carried For-Wthread-safety compiler toggles, whether can be met according to code annotation information Static Detection code in annotation and retouched The specification stated, DeLesley Hutchins etc. checks for thread-safety provides Deadlock Detection extension.
2) method that application method and dynamic analysis are locked during application program operation is tracked:Valgrind is under a set of Linux, The set of the artificial debugging instrument of open source code (GPL V2).Helgrind is to be used in valgrind between dynamic detection process The instrument of concurrence error, support the programming languages such as C/C++/Fortran.Helgrind can detect three kinds of POSIX pthreads Use problem:Lock type misuse, lock deadlock and data access concurrency conflict caused by sequence error.
3) method that static analysis and dynamic authentication are combined:Potential Deadlock is found using static analysis, then Construction triggering scene confirms the presence of Deadlock in application program operation.
Because the complexity of program syntax, static analysis tools typically can not directly determine the major issue of program.It is static The undecidability of analysis tool shows that the static analysis tools of any automation is all difficult not only reliable but also complete judgement one Whether program is operationally truly present some problem.Report by mistake too high, the practicality of instrument can be had a strong impact on, in order to reduce wrong report For rate it is necessary to sacrifice the precision of certain procedures, which results in the generation reported by mistake and failed to report, and ultimately results in static analysis tools and all can Face serious rate of false alarm, rate of failing to report and report rate again.
Dynamic testing method is in the case where running tested program, performs test program by test case or increase is true Real application scenarios carry out the defects of inspection software, and testing result has the advantages of rate of false alarm is low, but the Dynamic Execution time is grown, if The covering result for needing to reach more satisfied then needs very perfect test use cases, therefore dynamic detection has detection efficiency The low and high inferior position of rate of failing to report.
In addition, more important point is these conventional static state and dynamic testing methods all just in the specific line of system Journey mutual exclusion primitive provides the support to pthread operations under support, such as unix/linux, to critical under windows Support of section operations etc..But current many application program such as tcmalloc realize the lock of User space, if user There is the problems such as deadlock in customized lock operation, is not detectable with these universal solutions.
The content of the invention
The purpose of the application is to provide a kind of method and apparatus for detecting deadlock in application, accurate, efficient to solve Detect the problem of deadlock in ground.
According to the one side of the application, there is provided a kind of method for detecting deadlock in application, wherein, this method includes:
Lock tracking configuration operation is performed to intended application;
Obtain multiple lock operation informations during the intended application operation;
Determine to whether there is deadlock in the intended application by detecting the multiple lock operation information.
According to further aspect of the application, a kind of equipment for detecting deadlock in application is additionally provided, wherein, the equipment bag Include:
Configuration device, for performing lock tracking configuration operation to intended application;
Acquisition device, for multiple lock operation informations during obtaining the intended application operation;
Detection means, for being determined by detecting the multiple lock operation information in the intended application with the presence or absence of dead Lock.
According to the another aspect of the application, a kind of application for being used to detect deadlock is additionally provided, wherein, the application bag Include equipment as described above.
Compared with prior art, the application performs lock tracking configuration operation to intended application, obtains the intended application fortune Multiple lock operation informations between the departure date, determined by detecting the multiple lock operation information in the intended application with the presence or absence of dead Lock;The application completes the tracking to any lock operation using the method for dynamic modification application program actuating code, and can track User-defined lock operation, then determines whether there is deadlock, so as to accurately and efficiently detect according to lock usage track result Deadlock, lift Consumer's Experience.In addition, herein described potential dead lock condition is included with generation association journey task in physical thread During switching, before switching there is the lock not discharged in association's journey task, so as to support the detection to Deadlock in association's journey.
Brief description of the drawings
By reading the detailed description made to non-limiting example made with reference to the following drawings, the application's is other Feature, objects and advantages will become more apparent upon:
Fig. 1 shows the method flow diagram of deadlock in being applied according to a kind of detection of the application one side;
Fig. 2 shows to rely on topological diagram according to a kind of lock of the application one embodiment;
Fig. 3 shows the equipment schematic diagram of deadlock in being applied according to a kind of detection of the application other side.
Same or analogous reference represents same or analogous part in accompanying drawing.
Embodiment
The application is described in further detail below in conjunction with the accompanying drawings.
In one typical configuration of the application, terminal, the equipment of service network and trusted party include one or more Processor (CPU), input/output interface, network interface and internal memory.
Internal memory may include computer-readable medium in volatile memory, random access memory (RAM) and/or The forms such as Nonvolatile memory, such as read-only storage (ROM) or flash memory (flash RAM).Internal memory is computer-readable medium Example.
Computer-readable medium includes permanent and non-permanent, removable and non-removable media can be by any method Or technology come realize information store.Information can be computer-readable instruction, data structure, the module of program or other data. The example of the storage medium of computer includes, but are not limited to phase transition internal memory (PRAM), static RAM (SRAM), moved State random access memory (DRAM), other kinds of random access memory (RAM), read-only storage (ROM), electric erasable Programmable read only memory (EEPROM), fast flash memory bank or other memory techniques, read-only optical disc read-only storage (CD-ROM), Digital versatile disc (DVD) or other optical storages, magnetic cassette tape, magnetic disk storage or other magnetic storage apparatus or Any other non-transmission medium, the information that can be accessed by a computing device available for storage.Defined according to herein, computer Computer-readable recording medium does not include non-temporary computer readable media (transitory media), such as the data-signal and carrier wave of modulation.
This application provides a kind of application for being used to detect deadlock, wherein, the application includes equipment 1.For example, described set Standby 1 can be Deadlock Detection storehouse.The equipment 1 can track user it is interested lock operation (including it is user-defined lock behaviour Make), and lock conflict detection is carried out according to the lock operation information of record.
Preferably, the equipment 1 is to be added into the application by static linkage or dynamic link.
For example, the chain of equipment 1 can be tapped into application program by user in compiling;For the application using dynamic link The equipment 1 operationally can also be directly injected into application program by program, user by way of injection.Specifically, can be with Malloc (internal memories of application specified bytes) or open (opening and establishment file) method for packing are realized in the equipment 1, So as to ensure that the equipment 1 can run the setup code that be most carried out at first in the equipment 1 in the application. And the link order of the equipment 1 is placed on before libc (C function storehouse) in static linkage and dynamic link;For dynamic Libc application program is linked, the equipment 1 can be injected into by injection modes such as LD_PRELOAD environmental variances by application Program, the Deadlock Detection function of the equipment 1 is directly used without recompilating application program.
Fig. 1 shows the method flow diagram of deadlock in being applied according to a kind of detection of the application one side, and this method includes Step S11, step S12 and step S13.
First, in step s 11, equipment 1 performs lock tracking configuration operation to intended application.
In the particular embodiment, can be operated by a series of configurations, it is each to track by tracking function to be tracked Call operation is locked, and obtains multiple lock operation informations.
Preferably, in step s 11, equipment 1 obtains the entry address information of function to be tracked in intended application;Will from institute State the instruction set more than or equal to predetermined length that the entry address information of function to be tracked starts and back up to destination address;Will be from First instruction modification that the entry address information of the function to be tracked starts instructs for the migration of predetermined length, wherein, institute The destination address for stating migration instruction is the destination address;Extra instruction is added to the instruction positioned at the destination address Collection.
For example, after intended application starts, an initialization operation, initialization function can be performed after the equipment 1 loading The information of function to be tracked in intended application is collected first, is then inquired by application program symbol table information each to be tracked The entry address of function, according to these address informations, created using mmap (file or other object maps are entered into internal memory) One or more new executable memory field (section), the first address of these new memory fields and one or more letters to be tracked The address space distance of several entry addresses is within 2GB.
It is highly preferred that in step s 11, the dynamic dis-assembling of equipment 1 is opened from the entry address information of the function to be tracked The instruction set of the predetermined length of beginning, to determine the complete length of the instruction set, wherein, the complete length is more than or equal to institute State predetermined length;The instruction set of the complete length is backed up into destination address.
For example, connecting example, the predetermined length is set to 5 bytes.For the entry address of any one function to be tracked, Dynamic dis-assembling includes instruction set corresponding to preceding 5 bytes since the address, and the complete length of determine instruction collection, if If these instructions are all the unrelated instruction in position, just these instructions are copied to the new memory field of mmap establishments, if wherein If having instruction to be the relevant instruction in position, new command is copied again to new internal memory after just first repairing the position offset information of instruction Area, instruction set corresponding to preceding 5 bytes of the entry address of all functions to be tracked of guarantee complete backup.
It is highly preferred that in step s 11, if the instruction of equipment 1 is concentrated with instruction and includes position offset information, by institute State instruction set to back up to before the destination address, correspondingly change the position offset information.
For example, example is connected, if the operational access global variable or static variable of function to be tracked, these variables Address be to be calculated according to current instruction address biasing shifting amount, if instruction is simply transferred to new address, access Be exactly wrong address, application exception can be caused.In this case, institute's rheme in assembly instruction is correspondingly changed Put offset information.
Then, the meeting of equipment 1 fork (creating one and the substantially identical process of original process) creates subprocess, Parent process waits subprocess to complete, and subprocess inherits the memory mirror of parent process, preserves complete memory information.Subprocess root According to the list of the entry address of all functions to be tracked, by calling ptrace (parent process can control subprocess to run), repair First instruction for changing the entry address of each function to be tracked is the E9cd opcode (jmpq addr) of 5 bytes, wherein, E9 For assembler code jmpq machine code, cd is offset (offset) of the entry address with move target address of function to be tracked, Opcode represents command code, and the command code is jmpq addr, and jmpq is exactly jmp (unconditional branch) instructions, and q represents to redirect To 64 bit address.Subprocess terminates ptrace and exited after setting successfully, and parent process finds that subprocess is completed to continue executing with, but afterwards All operations for calling functions to be tracked can all jump to move target address (i.e. described destination address) execution, this for lock calling with Track provides chance.
In order to complete the tracking that lock calls, the application addition of additionally in the instruction set positioned at the destination address Instruction, the content for actually redirecting the destination address are instruction set corresponding to false code in following table:
It is migrated former instruction
JMP, which is returned, is migrated next instruction of instruction set
save parameter list
prepare parameter list as before
Callq migrates IA
Test%rax, %rax
je record_lock_operation
retq
Table 1
Wherein, " next of instruction set is migrated to instruct " entry address of i.e. described function to be tracked in the complete length First instruction afterwards;" save parameter list " refer to the parameter list of the function to be tracked;“prepare Parameter list as before " refer to the content for taking function parameter list to be tracked;" callq migrates IA " The address of first instruction of instruction is migrated in Compass;" test%rax, %rax " are used to judge whether lock operation succeeds, Successfully keep a record operation;Current lock Action Events are recorded in record_lock_operation;Retq is that the return of subprogram refers to Order.
As described above, the application using the method for dynamic modification application program actuating code complete to any lock operation with Track.
Then, in step s 12, equipment 1 obtains multiple lock operation informations during the intended application operation.
Preferably, the lock operation information includes following at least any one:Lock operation information;Attempt to lock operation letter Breath;Put lock operation information.
For example, user can control the behavior of the equipment 1 by environmental variance, the equipment 1 can be become by environment Amount receives the lock operation information;The locking operation information can include the registration of locking function title/address list need with Track locks the parameter position of the function name and lock variable of operation in function call, and the locking operation information of attempting can include Attempting locking function title/address list registration needs to track the function name for attempting to lock operation and lock variable in function call Parameter bit value, it is described put lock operation information and can include putting the registration of lock function name/address list need tracking to put lock operation Parameter position in function call of function name and lock variable.
Preferably, in step s 12, equipment 1 obtains multiple lock operation informations during the intended application operation;According to The multiple lock operation information builds lock corresponding to the intended application and relies on topological diagram.
For example, it is assumed that following operation in thread A be present:Lock a is locked, lock b is locked, lock is put to lock b, lock c is locked, Lock is put to lock c, lock is put to lock a, then can construct lock as shown in Figure 2 according to multiple lock operation informations as described above relies on topology Figure.
Preferably, in step s 12, equipment 1 is for each lock operation information, if the lock operation information should for the target First lock operation information of affiliated thread, is locally stored (Thread Local Storage, TLS) in thread and holds lock stack in In record the lock operation information;Otherwise, held from the thread-local storage and upper lock operation information is obtained in lock stack, described Lock corresponding to intended application relies on directed edge of the addition one from upper one lock operation information to the lock operation information in topological diagram, And record the lock operation information in lock stack is held in the thread-local storage.
For example, if current operation is locks or attempted to lock operation and successfully take lock, (1) is if current lock is this First lock that thread is held, then directly minute book is locked in thread is locally stored and holds lock stack;(2) otherwise, deposited from thread-local Storage is held in lock stack and obtains one and hold lock object, and in lock relies on topological diagram plus one from a upper directed edge for being locked into this lock, And minute book is locked in thread is locally stored and holds lock stack.If current operation is locked to put lock and operating and successfully discharge, in thread It is locally stored to hold in lock stack and ejects this lock object.
Then, in step s 13, equipment 1 by detect it is the multiple lock operation information determine be in the intended application It is no deadlock to be present.
Here, the multiple lock operation information can include the corresponding multiple lock operations of multiple threads in the intended application Information.
Preferably, in step s 13, equipment 1 by travel through it is described lock rely on topological diagram determine be in the intended application It is no deadlock to be present.
For example, it is assumed that the intended application includes thread 1 and thread 2;Following operation in thread 1 be present:Lock A is added Lock, lock B is locked, lock C is locked, lock is put to lock C, lock is put to lock B, lock is put to lock A;Following operation in thread 2 be present:To lock C is locked, and lock A is locked, and lock is put to lock A, and lock is put to lock C;It is A- that then lock corresponding to the intended application, which relies on topological diagram,>B->C-> A, ring structure can be found by traveling through the lock dependence topological diagram, so that it is determined that deadlock be present in the intended application.
Preferably, in step s 13, equipment 1 whether there is potential deadlock by detecting in the multiple lock operation information Condition, determine to whether there is deadlock in the intended application.
For example, can by detect thread or assist journey in multiple lock operation informations, judge whether potential dead lock condition, So that it is determined that it whether there is deadlock in the intended application.
Here, association's journey is a kind of program assembly, starts to be widely used in the exploitation of C/C++ backstages in recent years, be by sub- example The concept of journey (process, function, routine, method, subprogram) is extensive and comes, and subroutine only has an entrance and only return to one It is secondary, and assist journey to allow multiple entrances, it can be hung up in specified location and recover to perform.C/C++ language is primary not to support association Journey, but there is many realize to complete the function, such as the libtask storehouses that Russ Cox are realized, under C++ Boost.coroutine storehouses, the libco of Tengxun etc..Association's journey framework is synchronous, it is necessary to using User space in order to complete to assist method in journey Assist journey lock, these lock operation and existing Deadlock Detection tool detection less than, and the application it can be found that association Cheng Zhongcun Deadlock.
Preferably, the potential dead lock condition includes following at least any one:Lock in the multiple lock operation information be present Rely on ring;During with association's journey task switching occurring in physical thread, before switching there is the lock not discharged in association's journey task.
For example, the dependence that the lock dependence ring can be included between the multiple lock operation information is annular in shape, such as The lock, which is relied in topological diagram, has ring structure, then explanation has potential deadlock point.A kind of in addition, association's User space threads of Cheng Zuowei Realization, it is allowed to context (context) switching can occur in a tasks carrying, i.e., holding in same physical thread Row power gives another association's journey task, so as to fully improve the utilization rate of thread.But found in actually using, because C/C++ Association's journey be that non-protogenous are realized, switch in the event of context, then it cannot be guaranteed that the alternative of lock operation, such as association journey A and association Journey B is operated in physical thread X, and is required for performing certain operations under lock L protection, if association journey A is in the holder lock L phases Between control give association journey B, then assist journey B because can not take lock and wait always, simultaneously as association journey B because wait can not lead It is dynamic to give association journey A control, cause A to have no chance to put lock so as to form deadlock.Equipment 1 is if it find that jljl in step S12 When managing generation association journey task switching in thread, journey task is assisted to have lock not discharge before switching, then equipment 1 can be sent out in step s 13 An existing potential deadlock.
Preferably, methods described also includes:There is deadlock in equipment 1, report the triggering of corresponding deadlock when the intended application Condition.
For example, the trigger condition of the deadlock can include the possible triggering path of deadlock.If in the intended application In operation, topological graph discovery ring structure is relied on by traveling through the lock, then explanation has potential Deadlock, and this paths is then The possible triggering path of deadlock.Here, Deadlock Detection result can be collected and reported to user.
Fig. 3 shows the equipment 1 of deadlock in being applied according to a kind of detection of the application other side, wherein, equipment 1 includes Configuration device 11, acquisition device 12 and detection means 13.
First, the configuration device 11 performs lock tracking configuration operation to intended application.
In the particular embodiment, can be operated by a series of configurations, it is each to track by tracking function to be tracked Call operation is locked, and obtains multiple lock operation informations.
Preferably, the configuration device 11 obtains the entry address information of function to be tracked in intended application;Will be from described The instruction set more than or equal to predetermined length that the entry address information of function to be tracked starts backs up to destination address;Will from institute First instruction modification that the entry address information of function to be tracked starts is stated to instruct for the migration of predetermined length, wherein, it is described The destination address of migration instruction is the destination address;Extra instruction is added to the instruction positioned at the destination address Collection.
For example, after intended application starts, an initialization operation, initialization function can be performed after the equipment 1 loading The information of function to be tracked in intended application is collected first, is then inquired by application program symbol table information each to be tracked The entry address of function, according to these address informations, created using mmap (file or other object maps are entered into internal memory) One or more new executable memory field (section), the first address of these new memory fields and one or more letters to be tracked The address space distance of several entry addresses is within 2GB.
It is highly preferred that the dynamic dis-assembling of configuration device 11 is since the entry address information of the function to be tracked The instruction set of predetermined length, to determine the complete length of the instruction set, wherein, the complete length is more than or equal to described pre- Measured length;The instruction set of the complete length is backed up into destination address.
For example, connecting example, the predetermined length is set to 5 bytes.For the entry address of any one function to be tracked, Dynamic dis-assembling includes instruction set corresponding to preceding 5 bytes since the address, and the complete length of determine instruction collection, if If these instructions are all the unrelated instruction in position, just these instructions are copied to the new memory field of mmap establishments, if wherein If having instruction to be the relevant instruction in position, new command is copied again to new internal memory after just first repairing the position offset information of instruction Area, instruction set corresponding to preceding 5 bytes of the entry address of all functions to be tracked of guarantee complete backup.
If it is highly preferred that the instruction of the configuration device 11 is concentrated with instruction and includes position offset information, by described in Instruction set is backed up to before the destination address, correspondingly changes the position offset information.
For example, example is connected, if the operational access global variable or static variable of function to be tracked, these variables Address be to be calculated according to current instruction address biasing shifting amount, if instruction is simply transferred to new address, access Be exactly wrong address, application exception can be caused.In this case, institute's rheme in assembly instruction is correspondingly changed Put offset information.
Then, the meeting of equipment 1 fork (creating one and the substantially identical process of original process) creates subprocess, Parent process waits subprocess to complete, and subprocess inherits the memory mirror of parent process, preserves complete memory information.Subprocess root According to the list of the entry address of all functions to be tracked, by calling ptrace (parent process can control subprocess to run), repair First instruction for changing the entry address of each function to be tracked is the E9cd opcode (jmpq addr) of 5 bytes, wherein, E9 For assembler code jmpq machine code, cd is offset (offset) of the entry address with move target address of function to be tracked, Opcode represents command code, and the command code is jmpq addr, and jmpq is exactly jmp (unconditional branch) instructions, and q represents to redirect To 64 bit address.Subprocess terminates ptrace and exited after setting successfully, and parent process finds that subprocess is completed to continue executing with, but afterwards All operations for calling functions to be tracked can all jump to move target address (i.e. described destination address) execution, this for lock calling with Track provides chance.
In order to complete the tracking that lock calls, the application addition of additionally in the instruction set positioned at the destination address Instruction, the content for actually redirecting the destination address are instruction set corresponding to false code in following table:
Table 2
Wherein, " next of instruction set is migrated to instruct " entry address of i.e. described function to be tracked in the complete length First instruction afterwards;" save parameter list " refer to the parameter list of the function to be tracked;“prepare Parameter list as before " refer to the content for taking function parameter list to be tracked;" callq migrates IA " The address of first instruction of instruction is migrated in Compass;" test%rax, %rax " are used to judge whether lock operation succeeds, Successfully keep a record operation;Current lock Action Events are recorded in record_lock_operation;Retq is that the return of subprogram refers to Order.
As described above, the application using the method for dynamic modification application program actuating code complete to any lock operation with Track.
Then, the acquisition device 12 obtains multiple lock operation informations during the intended application operation.
Preferably, the lock operation information includes following at least any one:Lock operation information;Attempt to lock operation letter Breath;Put lock operation information.
For example, user can control the behavior of the equipment 1 by environmental variance, the equipment 1 can be become by environment Amount receives the lock operation information;The locking operation information can include the registration of locking function title/address list need with Track locks the parameter position of the function name and lock variable of operation in function call, and the locking operation information of attempting can include Attempting locking function title/address list registration needs to track the function name for attempting to lock operation and lock variable in function call Parameter bit value, it is described put lock operation information and can include putting the registration of lock function name/address list need tracking to put lock operation Parameter position in function call of function name and lock variable.
Preferably, the acquisition device 12 obtains multiple lock operation informations during the intended application operation;According to institute State multiple lock operation informations and build lock dependence topological diagram corresponding to the intended application.
For example, it is assumed that following operation in thread A be present:Lock a is locked, lock b is locked, lock is put to lock b, lock c is locked, Lock is put to lock c, lock is put to lock a, then can construct lock as shown in Figure 2 according to multiple lock operation informations as described above relies on topology Figure.
Preferably, the acquisition device 12 is for each lock operation information, if the lock operation information is the intended application In first of affiliated thread lock operation information, be locally stored to hold in thread and record the lock operation information in lock stack;Otherwise, from institute State thread-local storage hold lock stack in obtain one lock operation information, corresponding to the intended application lock rely on topological diagram in Directed edge of the addition one from upper one lock operation information to the lock operation information, and in lock stack is held in the thread-local storage Record the lock operation information.
For example, if current operation is locks or attempted to lock operation and successfully take lock, (1) is if current lock is this First lock that thread is held, then directly minute book is locked in thread is locally stored and holds lock stack;(2) otherwise, deposited from thread-local Storage is held in lock stack and obtains one and hold lock object, and in lock relies on topological diagram plus one from a upper directed edge for being locked into this lock, And minute book is locked in thread is locally stored and holds lock stack.If current operation is locked to put lock and operating and successfully discharge, in thread It is locally stored to hold in lock stack and ejects this lock object.
Then, the detection means 13 determines whether deposited in the intended application by detecting the multiple lock operation information In deadlock.
Here, the multiple lock operation information can include the corresponding multiple lock operations of multiple threads in the intended application Information.
Preferably, the detection means 13 determines whether deposited in the intended application by traveling through the lock dependence topological diagram In deadlock.
For example, it is assumed that the intended application includes thread 1 and thread 2;Following operation in thread 1 be present:Lock A is added Lock, lock B is locked, lock C is locked, lock is put to lock C, lock is put to lock B, lock is put to lock A;Following operation in thread 2 be present:To lock C is locked, and lock A is locked, and lock is put to lock A, and lock is put to lock C;It is A- that then lock corresponding to the intended application, which relies on topological diagram,>B->C-> A, ring structure can be found by traveling through the lock dependence topological diagram, so that it is determined that deadlock be present in the intended application.
Preferably, the detection means 13 whether there is potential deadlock bar by detecting in the multiple lock operation information Part, determine to whether there is deadlock in the intended application.
For example, can by detect thread or assist journey in multiple lock operation informations, judge whether potential dead lock condition, So that it is determined that it whether there is deadlock in the intended application.
Here, association's journey is a kind of program assembly, starts to be widely used in the exploitation of C/C++ backstages in recent years, be by sub- example The concept of journey (process, function, routine, method, subprogram) is extensive and comes, and subroutine only has an entrance and only return to one It is secondary, and assist journey to allow multiple entrances, it can be hung up in specified location and recover to perform.C/C++ language is primary not to support association Journey, but there is many realize to complete the function, such as the libtask storehouses that Russ Cox are realized, under C++ Boost.coroutine storehouses, the libco of Tengxun etc..Association's journey framework is synchronous, it is necessary to using User space in order to complete to assist method in journey Assist journey lock, these lock operation and existing Deadlock Detection tool detection less than, and the application it can be found that association Cheng Zhongcun Deadlock.
Preferably, the potential dead lock condition includes following at least any one:Lock in the multiple lock operation information be present Rely on ring;During with association's journey task switching occurring in physical thread, before switching there is the lock not discharged in association's journey task.
For example, the dependence that the lock dependence ring can be included between the multiple lock operation information is annular in shape, such as The lock, which is relied in topological diagram, has ring structure, then explanation has potential deadlock point.A kind of in addition, association's User space threads of Cheng Zuowei Realization, it is allowed to context (context) switching can occur in a tasks carrying, i.e., holding in same physical thread Row power gives another association's journey task, so as to fully improve the utilization rate of thread.But found in actually using, because C/C++ Association's journey be that non-protogenous are realized, switch in the event of context, then it cannot be guaranteed that the alternative of lock operation, such as association journey A and association Journey B is operated in physical thread X, and is required for performing certain operations under lock L protection, if association journey A is in the holder lock L phases Between control give association journey B, then assist journey B because can not take lock and wait always, simultaneously as association journey B because wait can not lead It is dynamic to give association journey A control, cause A to have no chance to put lock so as to form deadlock.If herein described acquisition device 12 is sent out When now with association's journey task switching occurs in physical thread, association's journey task has lock not discharge before switching, then the detection means 13 A potential deadlock can be found.
Preferably, the equipment 1 also includes annunciator (not shown);The annunciator works as the intended application Deadlock be present, report the trigger condition of corresponding deadlock.
For example, the trigger condition of the deadlock can include the possible triggering path of deadlock.If in the intended application In operation, topological graph discovery ring structure is relied on by traveling through the lock, then explanation has potential Deadlock, and this paths is then The possible triggering path of deadlock.Here, Deadlock Detection result can be collected and reported to user.
Compared with prior art, the application performs lock tracking configuration operation to intended application, obtains the intended application fortune Multiple lock operation informations between the departure date, determined by detecting the multiple lock operation information in the intended application with the presence or absence of dead Lock;The application completes the tracking to any lock operation using the method for dynamic modification application program actuating code, and can track User-defined lock operation, then determines whether there is deadlock, so as to accurately and efficiently detect according to lock usage track result Deadlock, lift Consumer's Experience.In addition, herein described potential dead lock condition is included with generation association journey task in physical thread During switching, before switching there is the lock not discharged in association's journey task, so as to support the detection to Deadlock in association's journey.
It should be noted that the application can be carried out in the assembly of software and/or software and hardware, for example, can adopt With application specific integrated circuit (ASIC), general purpose computer or any other realized similar to hardware device.In one embodiment In, the software program of the application can realize steps described above or function by computing device.Similarly, the application Software program (including related data structure) can be stored in computer readable recording medium storing program for performing, for example, RAM memory, Magnetically or optically driver or floppy disc and similar devices.In addition, some steps or function of the application can employ hardware to realize, example Such as, coordinate as with processor so as to perform the circuit of each step or function.
In addition, the part of the application can be applied to computer program product, such as computer program instructions, when its quilt When computer performs, by the operation of the computer, it can call or provide according to the present processes and/or technical scheme. And the programmed instruction of the present processes is called, it is possibly stored in fixed or moveable recording medium, and/or pass through Broadcast or the data flow in other signal bearing medias and be transmitted, and/or be stored according to described program instruction operation In the working storage of computer equipment.Here, including a device according to one embodiment of the application, the device includes using Memory in storage computer program instructions and processor for execute program instructions, wherein, when the computer program refers to When order is by the computing device, method and/or skill of the plant running based on foregoing multiple embodiments according to the application are triggered Art scheme.
It is obvious to a person skilled in the art that the application is not limited to the details of above-mentioned one exemplary embodiment, Er Qie In the case of without departing substantially from spirit herein or essential characteristic, the application can be realized in other specific forms.Therefore, no matter From the point of view of which point, embodiment all should be regarded as exemplary, and be nonrestrictive, scope of the present application is by appended power Profit requires rather than described above limits, it is intended that all in the implication and scope of the equivalency of claim by falling Change is included in the application.Any reference in claim should not be considered as to the involved claim of limitation.This Outside, it is clear that the word of " comprising " one is not excluded for other units or step, and odd number is not excluded for plural number.That is stated in device claim is multiple Unit or device can also be realized by a unit or device by software or hardware.The first, the second grade word is used for table Show title, and be not offered as any specific order.

Claims (22)

1. a kind of method for detecting deadlock in application, wherein, this method includes:
Lock tracking configuration operation is performed to intended application;
Obtain multiple lock operation informations during the intended application operation;
Determine to whether there is deadlock in the intended application by detecting the multiple lock operation information.
2. the method according to claim 11, wherein, it is described to determine the target by detecting the multiple lock operation information Include in the presence or absence of deadlock:
It whether there is potential dead lock condition by detecting in the multiple lock operation information, determine whether deposited in the intended application In deadlock.
3. according to the method for claim 2, wherein, the potential dead lock condition includes following at least any one:
Lock in the multiple lock operation information be present and rely on ring;
During with association's journey task switching occurring in physical thread, before switching there is the lock not discharged in association's journey task.
4. according to the method for claim 1, wherein, methods described also includes:
When the intended application has deadlock, the trigger condition of the corresponding deadlock of report.
5. according to the method for claim 1, wherein, the multiple locks operation obtained during the intended application is run is believed Breath includes:
Obtain multiple lock operation informations during the intended application operation;
The lock according to corresponding to the multiple lock operation information builds the intended application relies on topological diagram;
Wherein, it is described to determine with the presence or absence of deadlock to include in the intended application by detecting the multiple lock operation information:
Determine to whether there is deadlock in the intended application by traveling through the lock dependence topological diagram.
6. the method according to claim 11, wherein, it is described that the intended application is built according to the multiple lock operation information Corresponding lock, which relies on topological diagram, to be included:
For each lock operation information, if the lock operation information is first lock operation letter of affiliated thread in the intended application Breath, records the lock operation information in thread is locally stored;Otherwise, held from the thread-local storage in lock stack and obtain upper one Operation information is locked, addition one is from upper one lock operation information to the lock in lock corresponding to the intended application relies on topological diagram The directed edge of operation information, and record the lock operation information in lock stack is held in the thread-local storage.
7. according to the method for claim 1, wherein, the lock operation information includes following at least any one:
Lock operation information;
Attempt to lock operation information;
Put lock operation information.
8. method according to any one of claim 1 to 7, wherein, it is described that lock tracking configuration behaviour is performed to intended application Work includes:
Obtain the entry address information of function to be tracked in intended application;
The instruction set more than or equal to predetermined length since the entry address information of the function to be tracked is backed up into mesh Mark address;
First instruction modification since the entry address information of the function to be tracked is instructed for the migration of predetermined length, Wherein, the destination address of the migration instruction is the destination address;
Extra instruction is added to the instruction set positioned at the destination address.
9. the method according to claim 11, wherein, it is described by since the entry address information of the function to be tracked Instruction set more than or equal to predetermined length backs up to destination address and included:
The instruction set of predetermined length of the dynamic dis-assembling since the entry address information of the function to be tracked, with described in determination The complete length of instruction set, wherein, the complete length is more than or equal to the predetermined length;
The instruction set of the complete length is backed up into destination address.
10. the method according to claim 11, wherein, it is described by since the entry address information of the function to be tracked The instruction set more than or equal to predetermined length back up to destination address and include:
If it is described instruction be concentrated with instruction include position offset information, by the instruction set back up to the destination address it Before, correspondingly change the position offset information.
11. a kind of equipment for detecting deadlock in application, wherein, the equipment includes:
Configuration device, for performing lock tracking configuration operation to intended application;
Acquisition device, for multiple lock operation informations during obtaining the intended application operation;
Detection means, for determining to whether there is deadlock in the intended application by detecting the multiple lock operation information.
12. equipment according to claim 11, wherein, the detection means is used for:
It whether there is potential dead lock condition by detecting in the multiple lock operation information, determine whether deposited in the intended application In deadlock.
13. equipment according to claim 12, wherein, the potential dead lock condition includes following at least any one:
Lock in the multiple lock operation information be present and rely on ring;
During with association's journey task switching occurring in physical thread, before switching there is the lock not discharged in association's journey task.
14. equipment according to claim 11, wherein, the equipment also includes:
Annunciator, for deadlock be present when the intended application, report the trigger condition of corresponding deadlock.
15. equipment according to claim 11, wherein, the acquisition device is used for:
Obtain multiple lock operation informations during the intended application operation;
The lock according to corresponding to the multiple lock operation information builds the intended application relies on topological diagram;
Wherein, the detection means is used for:
Determine to whether there is deadlock in the intended application by traveling through the lock dependence topological diagram.
16. equipment according to claim 15, wherein, it is described to be answered according to the multiple lock operation information structure target Relying on topological diagram with corresponding lock includes:
For each lock operation information, if the lock operation information is first lock operation letter of affiliated thread in the intended application Breath, thread be locally stored hold lock stack in record the lock operation information;Otherwise, hold in lock stack and obtain from the thread-local storage Upper lock operation information, one is added in lock corresponding to the intended application relies on topological diagram from upper one lock operation information To the directed edge of the lock operation information, and the lock operation information is recorded in lock stack is held in the thread-local storage.
17. equipment according to claim 11, wherein, the lock operation information includes following at least any one:
Lock operation information;
Attempt to lock operation information;
Put lock operation information.
18. the equipment according to any one of claim 11 to 17, wherein, the configuration device is used for:
Obtain the entry address information of function to be tracked in intended application;
The instruction set more than or equal to predetermined length since the entry address information of the function to be tracked is backed up into mesh Mark address;
First instruction modification since the entry address information of the function to be tracked is instructed for the migration of predetermined length, Wherein, the destination address of the migration instruction is the destination address;
Extra instruction is added to the instruction set positioned at the destination address.
19. equipment according to claim 18, wherein, it is described by since the entry address information of the function to be tracked The instruction set more than or equal to predetermined length back up to destination address and include:
The instruction set of predetermined length of the dynamic dis-assembling since the entry address information of the function to be tracked, with described in determination The complete length of instruction set, wherein, the complete length is more than or equal to the predetermined length;
The instruction set of the complete length is backed up into destination address.
20. equipment according to claim 18, wherein, it is described by since the entry address information of the function to be tracked The instruction set more than or equal to predetermined length back up to destination address and include:
If it is described instruction be concentrated with instruction include position offset information, by the instruction set back up to the destination address it Before, correspondingly change the position offset information.
21. a kind of application for being used to detect deadlock, wherein, the application is included as any one of claim 11 to 20 Equipment.
22. application according to claim 21, wherein, the equipment is added into by static linkage or dynamic link The application.
CN201610402975.6A 2016-06-08 2016-06-08 Method and equipment for detecting deadlock in application Active CN107479980B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201610402975.6A CN107479980B (en) 2016-06-08 2016-06-08 Method and equipment for detecting deadlock in application

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201610402975.6A CN107479980B (en) 2016-06-08 2016-06-08 Method and equipment for detecting deadlock in application

Publications (2)

Publication Number Publication Date
CN107479980A true CN107479980A (en) 2017-12-15
CN107479980B CN107479980B (en) 2021-02-12

Family

ID=60594517

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201610402975.6A Active CN107479980B (en) 2016-06-08 2016-06-08 Method and equipment for detecting deadlock in application

Country Status (1)

Country Link
CN (1) CN107479980B (en)

Cited By (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109445951A (en) * 2018-10-31 2019-03-08 新华三技术有限公司 A kind of information processing method and device
CN109918207A (en) * 2019-02-18 2019-06-21 天津麒麟信息技术有限公司 A kind of c program deadlock positioning method of non-intruding
CN111638952A (en) * 2020-05-09 2020-09-08 北京达佳互联信息技术有限公司 Memory dump method and device and electronic equipment
CN112363846A (en) * 2021-01-11 2021-02-12 北京金山云网络技术有限公司 Deadlock detection method and device for database transaction and electronic equipment
CN112905267A (en) * 2019-12-03 2021-06-04 阿里巴巴集团控股有限公司 Method, device and equipment for accessing virtual machine to coroutine library
CN113535412A (en) * 2020-04-13 2021-10-22 伊姆西Ip控股有限责任公司 Method, apparatus and computer program product for tracking locks
CN114035970A (en) * 2022-01-10 2022-02-11 南京云信达科技有限公司 Data concurrent competition conflict detection analysis method and system
US11288105B2 (en) 2020-07-27 2022-03-29 International Business Machines Corporation Preventing deadlocks in runtime
CN113535412B (en) * 2020-04-13 2024-05-10 伊姆西Ip控股有限责任公司 Method, apparatus and computer program product for tracking locks

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1987796A (en) * 2005-12-22 2007-06-27 国际商业机器公司 Methods and apparatus for detecting deadlock in multithreading programs
CN102222016A (en) * 2010-04-16 2011-10-19 国际商业机器公司 Program deadlock detection method and system
CN103678122A (en) * 2013-11-29 2014-03-26 华为技术有限公司 Deadlock detecting method, equipment and system

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1987796A (en) * 2005-12-22 2007-06-27 国际商业机器公司 Methods and apparatus for detecting deadlock in multithreading programs
CN102222016A (en) * 2010-04-16 2011-10-19 国际商业机器公司 Program deadlock detection method and system
CN103678122A (en) * 2013-11-29 2014-03-26 华为技术有限公司 Deadlock detecting method, equipment and system

Cited By (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109445951B (en) * 2018-10-31 2020-09-25 新华三技术有限公司 Information processing method and device
CN109445951A (en) * 2018-10-31 2019-03-08 新华三技术有限公司 A kind of information processing method and device
CN109918207A (en) * 2019-02-18 2019-06-21 天津麒麟信息技术有限公司 A kind of c program deadlock positioning method of non-intruding
CN112905267A (en) * 2019-12-03 2021-06-04 阿里巴巴集团控股有限公司 Method, device and equipment for accessing virtual machine to coroutine library
CN112905267B (en) * 2019-12-03 2024-05-10 阿里巴巴集团控股有限公司 Method, device and equipment for accessing virtual machine to coroutine library
CN113535412A (en) * 2020-04-13 2021-10-22 伊姆西Ip控股有限责任公司 Method, apparatus and computer program product for tracking locks
US11954529B2 (en) 2020-04-13 2024-04-09 EMC IP Holding Company LLC Method, device and computer program product for tracking lock
CN113535412B (en) * 2020-04-13 2024-05-10 伊姆西Ip控股有限责任公司 Method, apparatus and computer program product for tracking locks
CN111638952A (en) * 2020-05-09 2020-09-08 北京达佳互联信息技术有限公司 Memory dump method and device and electronic equipment
US11288105B2 (en) 2020-07-27 2022-03-29 International Business Machines Corporation Preventing deadlocks in runtime
CN112363846A (en) * 2021-01-11 2021-02-12 北京金山云网络技术有限公司 Deadlock detection method and device for database transaction and electronic equipment
CN112363846B (en) * 2021-01-11 2021-04-13 北京金山云网络技术有限公司 Deadlock detection method and device for database transaction and electronic equipment
CN114035970A (en) * 2022-01-10 2022-02-11 南京云信达科技有限公司 Data concurrent competition conflict detection analysis method and system
CN114035970B (en) * 2022-01-10 2022-04-22 南京云信达科技有限公司 Data concurrent competition conflict detection analysis method and system

Also Published As

Publication number Publication date
CN107479980B (en) 2021-02-12

Similar Documents

Publication Publication Date Title
CN107479980A (en) A kind of method and apparatus for detecting deadlock in application
US9600403B1 (en) Method and system for creating functional model of test cases
Stocco et al. Visual web test repair
Kim et al. Automatic identification of bug-introducing changes
US9898387B2 (en) Development tools for logging and analyzing software bugs
Huang et al. Persuasive prediction of concurrency access anomalies
CN111756575B (en) Performance analysis method and device of storage server and electronic equipment
CN102567201B (en) Method for automatically recovering cross-model GUI (graphic user interface) test scripts
US9870309B2 (en) Variable tracking in program debugging
CN103440196B (en) A kind of operating-system resources failure detecting method
CN102053906A (en) System and method for collecting program runtime information
CN105074672A (en) Call stacks for asynchronous programs
CN109446107A (en) A kind of source code detection method and device, electronic equipment
CN102135877B (en) Automated construction method and device
CN112817787B (en) Automatic detection method for data competition of interrupt-driven embedded system
Fontana et al. An experience report on detecting and repairing software architecture erosion
CN110018954A (en) Code quality detection, the appraisal procedure of code detection quality, device and equipment
CN107250988A (en) Application testing
Xu et al. Melton: a practical and precise memory leak detection tool for C programs
CN100432955C (en) Detecting method for illegal memory reading and writing
Harzevili et al. Characterizing and understanding software security vulnerabilities in machine learning libraries
Andrews et al. Fail-safe test generation in safety critical systems
Trifu et al. Automated design flaw correction in object-oriented systems
Artho et al. Visual analytics for concurrent Java executions
Lumpe et al. Learning better inspection optimization policies

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