The root cause of the deadlock problem is
incorrect synchronization of pair or more objects
(Holt, 1972), incorrect ordering of lock acquisitions
(Li et al., 2005) or incorrect implementation of API
or application. Using static analysis can help us to
detect all synchronized statements, synchronized
methods and wait-notify methods in the source code
of the multithreading API.
3 RELATED WORKS
There are algorithms developed on the concept of
static analysis such as the work of Naik et al. (2008).
They used 0-CFA call graph, flow-insensitive k-
object-sensitive analysis, thread-escape analysis and
may-happen-in-parallel analysis to get the result of
the deadlock site. Otto and Moschny (2008) used the
point-to and may-happen-in-parallel analysis.
Agarwal and Stoller (2006) proposed operations to
detect the deadlock that are acquired and released of
locks, wait-notify on condition variables, up and
down operations on semaphores, accesses to shared
variables and thread start and join and termination
operations. Williams et al. (2005) used flows-
sensitive and context-sensitive analysis for static
deadlock detection in Java libraries and lock-order
graphs to represent locking. They focused on
deadlocks occurred by synchronized statements and
the wait-notify methods of Java. Jyotirmoy
Deshmukh, E. Allen Emerson and Sriram
Sankaranarayanan (2009) used symbolic deadlock
analysis. They used lock-order graph analysis,
logical formulae for symbolic enumeration of alias
patterns, Soot framework, may-aliases for tracking
locked objects across methods. They detected
deadlocks in Java, concurrent libraries and
multithreaded client applications. Gianpiero
Francesca, Antonella Santone, Gigliola Vaglini and
Maria Luisa Villani (2011) used the Calculus of
Communicating System (CCS) to detect deadlocks.
CCS is temporal-logic formula representing the
requirement verified by the concept of Model
Checking for complex system and proving
correctness of a system. Engler and Ashcraft (2003)
developed a static tool named RacerX using flow-
sensitive, interprocedural analysis to detect both race
conditions and deadlocks in the code. Mikhail
Moiseev, Alexey Zakharov, Ilya Klotchkov and
Sergey Salishev (2011) presented an approach of
deadlock detection in the SystemC design based on
static code analysis and implemented in the
Deadlock Analyzer tool.
4 DEADLOCK DETECTION
ALGORITHM
For the deadlock detection algorithm, we use six
conditions of the deadlock (Naik et al., 2009) and a
code pattern (Otto et al., 2008). We adapt them to
implement our own algorithm to detect the potential
deadlock in the source code of the multithreading
API. Six conditions of the deadlock (Naik et al.,
2009) consider locked objects whether they can be
accessed by several threads or not. A code pattern
(Otto et al., 2008) provides information about the
Cyclic Lock Dependency that if the lock order of
two fragment of code is reverse order, it shows the
cyclic and causes a deadlock. In summary, the
deadlock detection algorithm considers
synchronized statements, synchronized methods and
wait-notify methods in the source code of the
multithreading API. Then the algorithm will find the
relation of locked objects, methods and threads from
all these statements, methods and classes in the
source code to get information for locked objects in
each thread. Using six conditions of deadlock (Naik
et al., 2009) the algorithm will verify whether there
are more than 2 threads lock the same object or not.
Using the Cyclic Lock Dependency (Otto et al.,
2008) to verify whether there are more than 2
threads locks the same object in reverse lock order.
If it is in this case, it is possible that the deadlock
occurs. For easier to implement the deadlock
detection algorithm, we will split the deadlock
detection algorithm up to 3 parts that are 4.1 Source
Code Information that gets information of object
names, method names and thread names in the
source code of the multithreading API, 4.2 Source
Code Analyzing that analyzes the relation of objects,
methods and threads and which threads call methods
and lock which objects. And the last part is 4.3
Deadlock Detection that detects the deadlock using
information from prior parts.
4.1 Source Code Information
Firstly, the deadlock detection algorithm should
have source code information of the multithreading
API. We will use java.lang.reflect package of the
Java API to get Meta data of the class, synchronized
methods, synchronized objects, fields of class, wait-
notify methods, Thread names and names of method
callers and callees. The algorithm collects
information into the container for providing relation
and detecting the deadlock in next steps.
The following part of example code is used to
demonstrate our algorithm for getting source code
ENASE2013-8thInternationalConferenceonEvaluationofNovelSoftwareApproachestoSoftwareEngineering
134