一句话:为超大规模 Android Java 应用提出组合式静态死锁检测,基于临界对将问题判定为 NP 并部署于 Infer。
本文面向 Facebook 在研的商用 Android Java 应用(数千万行代码),提出一种可在代码评审时仅分析改动代码及其依赖、并在约 15 分钟内给出报告的静态死锁分析。作者将真实语言抽象为带平衡可重入锁、非确定性迭代/分支和非递归过程调用的抽象语言,证明死锁存在性等价于各程序线程 critical pairs(临界对)集合上的某条件;由于临界对有限且可计算,该死锁检测问题可判定且属于 NP。实现采用组合式抽象解释风格计算临界对,运行时间为拟指数级,并以开源形式构建于 Infer 验证框架;已工业部署两年多,收到 200 多份已修复死锁报告,修复率约 54%。
We develop a static deadlock analysis for commercial Android Java applications, of sizes in the tens of millions of LoC, under active development at Facebook. The analysis runs primarily at code-review time, on only the modified code and its dependents; we aim at reporting to developers in under 15 minutes.To detect deadlocks in this setting, we first model the real language as an abstract language with balanced re-entrant locks, nondeterministic iteration and branching, and non-recursive procedure calls. We show that the existence of a deadlock in this abstract language is equivalent to a certain condition over the sets of critical pairs of each program thread; these record, for all possible executions of the thread, which locks are currently held at the point when a fresh lock is acquired. Since the critical pairs of any program thread is finite and computable, the deadlock detection problem for our language is decidable, and in NP.We then leverage these results to develop an open-source implementation of our analysis adapted to deal with real Java code. The core of the implementation is an algorithm which computes critical pairs in a compositional, abstract interpretation style, running in quasi-exponential time. Our analyser is built in the Infer verification framework and has been in industrial deployment for over two years; it has seen over two hundred fixed deadlock reports with a report fix rate of ~54%.