150 likes | 283 Views
Types for Safe Locking: Static Race Detection for Java. MARTIN ABADI Microsoft Research and University of California at Santa Cruz CORMAC FLANAGAN University of California at Santa Cruz STEPHEN N. FREUND Williams College Presented By Krishna C Tatikunta. Introduction to the Problem.
E N D
Types for Safe Locking: Static RaceDetection for Java MARTIN ABADI Microsoft Research and University of California at Santa Cruz CORMAC FLANAGAN University of California at Santa Cruz STEPHEN N. FREUND Williams College Presented By Krishna C Tatikunta
Introduction to the Problem • Race conditions are common, insidious errors in multithreaded programs. • A race condition occurs when two threads manipulate a shared data structure simultaneously, without synchronization.
What is this article about? • This article presents a static race-detection analysis for multithreaded shared-memory programs, focusing on the Java programming language. • The analysis is based on a type system that captures many common synchronization patterns. • It supports classes with internal synchronization, classes that require client-side synchronization, and thread-local classes.
RaceFreeJava field ::= [final]opt t fn = v[guarded by l ]opt meth ::= t mn(arg∗) requires ls {e} ls ::= l∗ (lock set) l ::= x (lock expression)
External Locks defn ::= class cngarg∗ body (class declaration) garg ::= ghost t x (ghost declaration) c ::= cnl∗ | Object (class type)
Thread Local Classes • Large multithreaded programs typically include sections of code that operate on data that is not shared across multiple threads. Eg., only a single thread in a concurrent web server may need to access the information about a particular request. • Objects used in this fashion require no synchronization and should not need to have locks guarding their fields. • To accommodate this situation, we introduce the concept of thread-local classes. • defn ::= [thread local]opt class cngarg∗ body
THE RCCJAVA CHECKER • Extention of the RACEFREEJAVA type system to the full Java language. • This race-condition checker, rccjava, extends the Concurrent Java type system to accommodate the additional features of Java, including arrays, interfaces, constructors, and static fields and methods.
The RCCJAVA CHECKER Contd… • The rccjava checker provides mechanisms for escaping from the type system when it proves too restrictive. • The simplest escape mechanism is the no warn annotation, which turns off certain kinds of warnings on a particular line of code, as in: f.a = 3; //# no warn race • This annotation is commonly used if a particular race condition is considered benign.
Related Work • A number of tools have been developed for detecting race conditions, both statically and dynamically. • Warlock is a static race-detection system for ANSI C programs. • It supports the lock-based synchronization discipline through annotations similar to RCCJAVA. • It works by tracing execution paths through the program, but it fails to trace paths through loops or recursive function calls, and thus may not detect certain race conditions. • The extended static checker for Java (ESC/Java) is a tool for static detection of software defects • Eraser is a tool for detecting race conditions and deadlocks dynamically, rather than statically.
Related Work Contd… • Grossman [2003] has developed a type system for preventing race conditions in Cyclone, a statically safe variant of C, using RCCJAVA approach. • RACEFREEJAVA has also been extended to verify atomicity. • Whereas race conditions yield valuable indications of unintended interference between threads, atomicity guarantees the absence of such interference. • In particular, a method is atomic if for every program execution, there is an equivalent serial execution where the actions of the method are executed contiguously, without interleaved actions of other threads.
Conclusion • Type systems have proven remarkably effective for preventing errors in sequential programs. • In this work, the authors have adapted to type-based analysis techniques to multithreaded programs, and focus in particular on race conditions, a common source of errors in multithreaded programs. • Dependent types are a key feature of our type system, since the type of a field includes its protecting lock.