9/11/2023 0 Comments Java deadlock detectionfindbugsBoth methods acquire locks on two lock objects, cacheLock and tableLock, before they proceed. The following example shows a set of methods that have the potential for deadlock. Since the thread might already hold locks associated with other objects, two threads could each be waiting for the other to release a lock in such a case, they will end up waiting forever. Synchronization deadlocks in Java programsĭeadlocks can occur in Java because the synchronized keyword causes the executing thread to block while waiting for the lock, or monitor, associated with the specified object. Unless the system is designed to recover from deadlocks, a deadlock causes the program or system to hang. If this graph contains a cycle, the system is deadlocked. Another way to illustrate a deadlock is to build a directed graph whose vertices are threads or processes and whose edges represent the "is-waiting-for" relation. We say that a set of processes or threads is deadlocked when each thread is waiting for an event that only another process in the set can cause. However, another risk is associated with excessive synchronization: deadlock. So it seems that there is now less reason than ever to avoid synchronizing. Additionally, while synchronization carries a performance penalty, the penalty associated with uncontended synchronization is not as great as some sources have suggested, and has reduced steadily with each successive JVM implementation. Read the full paperĪ compositional deadlock detector for Android Java AcknowledgementsĪdditional thanks to the co-authors of this research, James Brotherston, Paul Brunet, and Max Kanovich, all at University College London (UCL).In my earlier article " Double-Checked Locking: Clever, but Broken" ( JavaWorld, February 2001), I described how several common techniques for avoiding synchronization are in fact unsafe, and recommended a strategy of "When in doubt, synchronize." In general, you should synchronize whenever you are reading any variable that might have been previously written by a different thread, or whenever you are writing any variable that might be subsequently read by another thread. Our approach achieves this goal while also making the analyzer sufficiently scalable so that it can be deployed on the massive codebases at Meta. Deadlocks are also very difficult bugs to diagnose because thread scheduling is essentially non-deterministic and, thus, a test might need to run thousands or millions of times in order to exhibit the problem.ĭetecting deadlocks statically, without running or even building the code is, therefore, extremely valuable. Why it matters:Ī deadlock is typically an unrecoverable error. In other words, in this language, we can find all the deadlocks without false positives. In our paper, we also prove that our analysis is sound and complete for an abstract programming language that has only non-deterministic control. It is this heuristic that enables our analysis to scale. Then, based on that data, it applies a heuristic that locates methods outside the revision that could potentially deadlock with one of the methods in the revision. Instead, it first processes all methods in the revision’s modified files. To be fast and efficient, our tool avoids analyzing all source files in an app. This data, computed across all methods, is enough to let us answer the question of whether a deadlock is possible between two concurrent methods. A critical pair (A,B) records the following fact: The method tries to acquire lock B, and at that time, it’s already holding precisely locks in set A. The central part of the summary is the set of critical pairs of the method. This is done in a compositional manner: Each method is summarized once, at most, and its summary is used in the summarization of its callers, ensuring predictable high performance. For each method, the analyzer computes a summary of how the method behaves in terms of lock acquisition and release, as well as whether the method will run on the main thread or on a background thread. We used abstract interpretation techniques to design our analyzer. Our analyzer is open source and forms part of the Infer static analysis framework. In the last two years, developers have actioned over 200 fixes in response to deadlock reports, at a fix rate of around 54 percent. We have deployed our analyzer in Meta’s continuous integration system, where it scans every commit to the Android app family. What distinguishes our analyzer from past research is its ability to analyze revisions in codebases with hundreds of millions of lines of code. We’ve developed a new static analyzer that catches deadlocks in Java code for Android without ever running the code.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |