Dynamic Analysis of Java Applications for MultiThreaded Antipatterns S. Boroday CRIM 550 Sherbrooke West, 100 Montreal, Canada 1 (514) 840-1234 sboroday@crim.ca A. Petrenko CRIM 550 Sherbrooke West, 100 Montreal, Canada 1 (514) 840-1234 apetrenk@crim.ca J. Singh Concordia University 1455 Maisonneuve West Montreal, Canada +1 (514) 848-2424 j_singh@ece. concordia.ca H. Hallal CRIM 550 Sherbrooke West, 100 Montreal, Canada 1 (514) 840-1234 hhallal@crim.ca ABSTRACT Formal verification is not always applicable to large industrial software systems due to scalability issues and difficulties in formal model and requirements specification. The scalability and model derivation problems could be alleviated by runtime trace analysis, which combines both testing and formal verification. We implement and compare an ad-hoc custom approach and a formal approach to detect common bug patterns in multithreaded Java software. We use the tracing platform of the Eclipse IDE and state-of-the-art model checker Spin. Categories and Subject Descriptors Categories and Subject Descriptors: D.1.3 [Programming Techniques]: Concurrent Programming—parallel programming; D 2.4 [Software Engineering]: Software/Program Verification— model checking; D.2.5 [Software Engineering]: Testing and Debugging—debugging aids; monitors; tracing; D.4.1 [Operating Systems]: Process Management—concurrency; deadlock; multiprocessing/multiprogramming; synchronization. General Terms Algorithms, Reliability, Experimentation, Languages, Verification. Keywords Antipatterns, bug patterns, Java, bytecode, instrumentation, multithreading. 1. INTRODUCTION 1.1 Multithreading Java is a highly popular language that exploits the power of distributed computing and allows developing applications that run on different kinds of computer systems and other devices [27]. Among the strong features of Java is its support of multithreading. Java is the first mainstream language to support multithreading on the level of the language itself, rather than with external libraries. Threads are “lightweight” processes, which run concurrently but share common resources. Multithreading is a convenient way to decompose large programs into smaller tasks, so it adds to program organization. At the same time, it increases the overall efficiency; in particular, on truly multiprocessor or hyperthreaded architectures. Multithreading is heavily used in Java programming, especially on the server side, where one program must process multiple concurrent requests from numerous clients. Being one of the most attractive features of Java, multithreading happens to be the source of difficulty not only for novice but also for experienced programmers. Unlike sequential programs, a multithreaded program can have several execution paths for the same input data because of the unpredictable thread scheduling and the inherent parallelism in the behavior of threads. Errors could occur only on some executions, which makes them hard to detect. Also, it may be difficult to reproduce such errors. Even mature programmers, including authors of textbooks and research papers, could make mistakes in multithreaded programs. For example, the widely cited and used double check design pattern is shown to be error prone in Java both theoretically and experimentally [3]. In order to enable efficient compiler implementation on different systems, Java specifications provide a liberal and weak memory model. Thus tricks, which work for certain languages and environments with a coherent memory model, could cause problems in Java applications, especially when executed on a multiprocessor system and complied with a modern optimizing Java compiler. Even access to “atomic” data could result in data incoherence if the data was not protected appropriately. Since multithreading errors are difficult to avoid, a practical means to ensure the quality of multithreaded applications is to apply the automatic bug detection. In this work, we implement and compare two, promising approaches to multithreaded bug detection: the first is based on custom detection of multithreaded errors, and the second relies on the theory of model checking. Both approaches target the dynamic analysis of multithreaded programs. The resulting tools analyze traces collected by the quality assurance framework of the popular open-source Java development platform Eclipse [6]. Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage, and that copies bear this notice and the full citation on the first page. To copy otherwise, to republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Workshop on Dynamic Analysis (WODA 2005) 17 May 2005, St. Louis, MO, USA.. Copyright 2005 ISBN # 1-59593-126-0 17/05/05 ... $5.00