一句话:提出基于静态事件分析的 Java 基本线程误用检测方法,并实现工具 Leopard。
Java 基础异步线程 java.lang.Thread 容易被误用:开发者若不了解垃圾回收与线程中断机制,可能写出无法及时响应中断的代码,造成资源泄漏或浪费。现有动态方法缺乏有效输入,路径敏感静态方法则因路径爆炸耗时高且漏报。本文观察到线程行为及其与引用对象的交互可被抽象,提出事件分析方法,聚焦事件是否存在及其顺序以减少漏报。方法抽取线程事件及线程引用对象的销毁事件等误用相关事件,并借助循环识别、happens-before 关系构建和别名判定进行分析,实现工具 Leopard。在真实 Java 程序和 Android 应用上,Leopard 比已有方法检测到更多误用(723 vs 47),耗时更短(60s vs 30min),精度更优;报告的 66 个问题获确认,其中 21 个已修复。
The fundamental asynchronous thread (java.lang. Thread) in Java can be easily misused, due to the lack of deep understanding for garbage collection and thread interruption mechanism. For example, a careless implementation of asynchronous thread may cause no response to the interrupt mechanism in time, resulting in unexpected thread-related behaviors, especially resource leak/waste. Currently, few works aim at these misuses and related works adopt either the dynamic approach which lacks effective inputs or the static path-sensitive approach with high time consumption due to the path explosion, causing false negatives. We have found that the behavior of threads and the interaction between threads and its referencing objects can be abstracted. In this paper, we propose an event analysis approach to detect the defects in Java programs and Android apps, which focuses on the existence or the order of the events to reduce the false negatives. We extract the misuse-related events, containing the thread events and the destroy events of the object referenced by the thread. Then we analyze the events with loop identification, happens-before relationship construction and alias determination. Finally, we implement an automatic tool named Leopard and evaluate it on real world Java programs and Android apps. Experiments show that it is efficient when comparing with the existing approach (misuse: 723 vs 47, time: 60s vs 30min), which also outperforms the existing work in precision. The manual check indicates that Leopard is more efficient and effective than existing work. Besides, 66 issues reported by us have been confirmed and 21 of them have been fixed by developers.
@inproceedings{CuiWZYYZ23,
title = {Detection of Java Basic Thread Misuses Based on Static Event Analysis},
author = {Baoquan Cui and Miaomiao Wang and Chi Zhang and Jiwei Yan and Jun Yan and Jian Zhang},
booktitle = {ASE},
year = {2023},
doi = {10.1109/ase56229.2023.00145}
}