Locking discipline inference and checking Michael D

Slides:



Advertisements
Similar presentations
Dataflow Analysis for Datarace-Free Programs (ESOP 11) Arnab De Joint work with Deepak DSouza and Rupesh Nasre Indian Institute of Science, Bangalore.
Advertisements

Verification of Multithreaded Object- Oriented Programs with Invariants Bart Jacobs, K. Rustan M. Leino, Wolfram Schulte.
SPLINT STATIC CHECKING TOOL Sripriya Subramanian 10/29/2002.
A Randomized Dynamic Program Analysis for Detecting Real Deadlocks Koushik Sen CS 265.
Concurrency 101 Shared state. Part 1: General Concepts 2.
Eraser: A Dynamic Data Race Detector for Multithreaded Programs STEFAN SAVAGE, MICHAEL BURROWS, GREG NELSON, PATRICK SOBALVARRO and THOMAS ANDERSON.
1 Concurrency Specification. 2 Outline 4 Issues in concurrent systems 4 Programming language support for concurrency 4 Concurrency analysis - A specification.
Taming Win32 Threads with Static Analysis Jason Yang Program Analysis Group Center for Software Excellence (CSE) Microsoft Corporation.
/ PSWLAB Atomizer: A Dynamic Atomicity Checker For Multithreaded Programs By Cormac Flanagan, Stephen N. Freund 24 th April, 2008 Hong,Shin.
CS 263 Course Project1 Survey: Type Systems for Race Detection and Atomicity Feng Zhou, 12/3/2003.
Checking and Inferring Local Non-Aliasing Alex AikenJeffrey S. Foster UC BerkeleyUMD College Park John KodumalTachio Terauchi UC Berkeley.
CS444/CS544 Operating Systems Synchronization 2/16/2006 Prof. Searleman
C. FlanaganAtomicity for Reliable Concurrent Software - PLDI'05 Tutorial1 Atomicity for Reliable Concurrent Software Part 3a: Types for Race-Freedom and.
C. FlanaganSAS’04: Type Inference Against Races1 Type Inference Against Races Cormac Flanagan UC Santa Cruz Stephen N. Freund Williams College.
An overview of JML tools and applications Lilian Burdy Gemplus Yoonsik Cheon, Gary Leavens Iowa Univ. David Cok Kodak Michael Ernst MIT Rustan Leino Microsoft.
Confined Types Encapsulation and modularity Seminar November, 2005 presented by: Guy Gueta.
Mayur Naik Alex Aiken John Whaley Stanford University Effective Static Race Detection for Java.
Slides prepared by Rose Williams, Binghamton University Chapter 13 Interfaces and Inner Classes.
Programming Language Semantics Java Threads and Locks Informal Introduction The Java Specification Language Chapter 17.
1 Program Analysis Mooly Sagiv Tel Aviv University Textbook: Principles of Program Analysis.
1 Islands : Aliasing Protection In Object-Oriented Languages By : John Hogg OOPSLA 91 Aharon Abadi.
Synchronization in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1 Sharing Objects – Ch. 3 Visibility What is the source of the issue? Volatile Dekker’s algorithm Publication and Escape Thread Confinement Immutability.
Program Analysis Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
/ PSWLAB Eraser: A Dynamic Data Race Detector for Multithreaded Programs By Stefan Savage et al 5 th Mar 2008 presented by Hong,Shin Eraser:
Concurrency Recitation – 2/24 Nisarg Raval Slides by Prof. Landon Cox.
C. FlanaganType Systems for Multithreaded Software1 Cormac Flanagan UC Santa Cruz Stephen N. Freund Williams College Shaz Qadeer Microsoft Research.
Software Engineering Prof. Dr. Bertrand Meyer March 2007 – June 2007 Chair of Software Engineering Static program checking and verification Slides: Based.
Types for Programs and Proofs Lecture 1. What are types? int, float, char, …, arrays types of procedures, functions, references, records, objects,...
1 Concurrent Languages – Part 1 COMP 640 Programming Languages.
Dan Johnson.  Functional language that started development in  Committee designed language  Pure and Lazy  Compiled or Interpreted  Named after.
1 Effective Static Race Detection for Java Mayur, Alex, CS Department Stanford University Presented by Roy Ganor 14/2/08 Point-To Analysis Seminar.
/ PSWLAB Type-Based Race Detection for J AVA by Cormac Flanagan, Stephen N. Freund 22 nd Feb 2008 presented by Hong,Shin Type-Based.
Applications of extended static checking K. Rustan M. Leino Compaq SRC K. Rustan M. Leino Compaq SRC Systems Research Center Invited talk, SAS’01, Paris,
User-defined type checkers for error detection and prevention in Java Michael D. Ernst MIT Computer Science & AI Lab
ICS 313: Programming Language Theory Chapter 13: Concurrency.
Dataflow Analysis for Concurrent Programs using Datarace Detection Ravi Chugh, Jan W. Voung, Ranjit Jhala, Sorin Lerner LBA Reading Group Michelle Goodstein.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Concurrency & Dynamic Programming.
Debugging Threaded Applications By Andrew Binstock CMPS Parallel.
COSC 3407: Operating Systems Lecture 9: Readers-Writers and Language Support for Synchronization.
PROGRAMMING PRE- AND POSTCONDITIONS, INVARIANTS AND METHOD CONTRACTS B MODULE 2: SOFTWARE SYSTEMS 13 NOVEMBER 2013.
Effective Static Deadlock Detection Mayur Naik (Intel Research) Chang-Seo Park and Koushik Sen (UC Berkeley) David Gay (Intel Research)
1 Ivan Marsic Rutgers University LECTURE 19: Concurrent Programming.
Extended Static Checking for Java Cormac Flanagan Joint work with: Rustan Leino, Mark Lillibridge, Greg Nelson, Jim Saxe, and Raymie Stata Compaq Systems.
Eraser: A dynamic Data Race Detector for Multithreaded Programs Stefan Savage, Michael Burrows, Greg Nelson, Patrick Sobalvarro, Thomas Anderson Presenter:
Using Escape Analysis in Dynamic Data Race Detection Emma Harrington `15 Williams College
LECTURE 10 Semantic Analysis. REVIEW So far, we’ve covered the following: Compilation methods: compilation vs. interpretation. The overall compilation.
Jeremy Nimmer, page 1 Automatic Generation of Program Specifications Jeremy Nimmer MIT Lab for Computer Science Joint work with.
CSE341: Programming Languages Lecture 11 Type Inference
Javarifier: inference of reference immutability
Types for Programs and Proofs
CS 326 Programming Languages, Concepts and Implementation
University of Washington, USA Università di Verona, Italy NFM 2016
runtime verification Brief Overview Grigore Rosu
Functional Programming with Java
Threads and Memory Models Hal Perkins Autumn 2011
Over-Approximating Boolean Programs with Unbounded Thread Creation
CSE341: Programming Languages Lecture 11 Type Inference
Threads and Memory Models Hal Perkins Autumn 2009
CSE341: Programming Languages Lecture 11 Type Inference
Subject : T0152 – Programming Language Concept
CSE 451: Operating Systems Autumn 2004 Module 6 Synchronization
CSE 451: Operating Systems Autumn 2003 Lecture 7 Synchronization
CSE 451: Operating Systems Autumn 2005 Lecture 7 Synchronization
CSE 451: Operating Systems Winter 2003 Lecture 7 Synchronization
CSE341: Programming Languages Lecture 11 Type Inference
CSE341: Programming Languages Lecture 11 Type Inference
CSE 332: Concurrency and Locks
Programming Languages 2nd edition Tucker and Noonan
CSE341: Programming Languages Lecture 11 Type Inference
Presentation transcript:

Locking discipline inference and checking Michael D Locking discipline inference and checking Michael D. Ernst, Alberto Lovato, Damiano Macedonio, Fausto Spoto, Javier Thaine University of Washington, USA Università di Verona, Italy Julia Srl, Italy ICSE 2016

Concurrency: essential but error-prone Essential for performance (exploit multiple cores) Design component of GUIs Data races: concurrent access to shared data easy mistake to make leads to corrupted data structures difficult to reproduce and diagnose

Thread-unsafe code class BankAccount { int balance; void withdraw(int amount) { int oldBal = this.balance; int newBal = oldBal - amount; this.balance = newBal; } ...

Data race example Shared account Initial balance = 500 Thread 1: sharedAccount.withdraw(50) int oldBal = this.balance; int newBal = oldBal - amount; this.balance = newBal; Thread 2: sharedAccount.withdraw(100) int oldBal = this.balance; int newBal = oldBal - amount; this.balance = newBal; 500 500 I'm thirsty and want to buy a round at the Cantina. So I withdraw 50 Galactic Standard Credits. Galactic Standard Credits. My spouse wants to purchase a used R2 unit (or: a moisture harvesting droid) from some upstanding Jawa entrepreneurs. So she withdraws 100 Galactic Standard Credits.] There is a data race on the balance field of the shared account. [The Imperial Bank is motivated to prevent this situation, and their solution is locking.]There is a data race on the balance field of the shared account. 500 50 500 100 450 400 Withdrawals = 150 Final balance = 450

Solution: locking Locking: Only one thread can aquire the lock class BankAccount { int balance; void withdraw(int amount) { int oldBal = this.balance; int newBal = oldBal - amount; this.balance = newBal; } ... Locking: Only one thread can aquire the lock No concurrent access to data Which lock to hold? Object acctLock; @GuardedBy(“acctLock”) int balance; int balance; synchronized (acctLock) { Key issues: Names vs. values Aliasing }

Locking discipline = which locks to hold when accessing what data @GuardedBy("lock1") int w; @GuardedBy("lock2") int x; @GuardedBy("lock2") int y; int z; Write locking discipline as documentation and for use by tools @GuardedBy [Goetz 2006] is a de-facto standard On GitHub, 35,000 uses in 7,000 files Its semantics is informal, ambiguous, and incorrect (allows data races) Similar problems with other definitions [The @GuardedBy annotation is a de-facto standard for expressing a locking discipline; GitHub contains 35K uses in 7K files.] [every interpretation is incorrect and permits data races]

Contributions Formal semantics for locking disciplines value-based unambiguous prevents data races Two implementations: type-checker that validates use of locking inference tool that infers locking discipline Experiments: programmer-written @GuardedBy: are often inconsistent with informal semantics permit data races even when consistent Type-checker alidates programmer-written locking discipline, expressed as @GuardedBy annotations.

Concurrency background Each object is associated with a monitor or intrinsic lock specification of locking discipline Date d = new Date(); @GuardedBy("d") List lst = ...; synchronized (d) { lst.add(...) lst.remove(...) otherList = lst; } synchronized statement or method locks the monitor. guard expression; arbitrary, e.g. a.b().f guard expression; arbitrary, e.g. a.b().f Exiting the statement or method unlocks the monitor. Our implementations handle explicit locks too

Defining a locking discipline Guard expression: Aliases? Reassignment? Side effects? Scoping? Guard expression: Aliases? Reassignment? Scoping? Defining a locking discipline Yes No Def site Informally: “If program element x is annotated by @GuardedBy(L), a thread may only use x while holding the lock L.” MyObject lock; @GuardedBy("lock.field") Pair shared; @GuardedBy("lock.field") Pair alias; synchronized (lock.field) { shared.a = 22; alias = shared; } Element being guarded: Name or value? Aliases? Reassignments? Side effects? Element being guarded: Name or value? Aliases? Reassignments? Side effects? Value Yes Current allows data races, ours does not What is a use? Any occurrence of name? Dereferences of name? Dereferences of value? What is a use? Occurrence of name? Dereference of name? (x.f) Dereference of value? ← current ← our def

Name protection Value protection … not value protection MyObject lock; @GuardedBy("lock") Pair shared; Pair alias; Name protection Value protection … not value protection … not name protection synchronized (lock) { alias = shared; } alias.a = ... shared = alias; synchronized (lock) { shared.a = ... } Suffers a data race No data race

Locking discipline semantics providing value protection Suppose expression x has type @GuardedBy(L) When the program dereferences a value that has ever been bound to x, the program holds the lock on the value of expression L. The referent of L must not change while the thread holds the lock. A use is a dereference May lock an alias No restriction on copying, argument-passing (including as the receiver), or returning values. [[ * Note: The protection is shallow. It applies to the value that x evaluates to, not to all values reachable from it. ]] No reassignment of guard expression. Side effects permitted (do not affect the monitor). Formal semantics + proof of correctness [Ernst NFM 2016]

Static analysis of a locking discipline Goal is to determine facts about values Program is written in terms of facts about variables Analysis computes an approximation (an abstraction) of values each expression may evaluate to of locks currently held by the program Both abstractions are sound

Enforcement via type-checking Type rule: If x : @GB(L) , then L must be held when x is dereferenced Type system also supports method pre/postconditions (@Holding annotations) side effect annotations type qualifier polymorphism reflection flow-sensitive type inference No two @GuardedBy annotations are related by subtyping Why not @GB(L1) <: @GB(L1, L2)? Side effects and aliasing

Inference via abstract interpretation [Spoto TOPLAS 2003] Expression e is @GuardedBy(L) if e’s fields are accessed only when L is held [Nikolic ICTAC 2012] Acquired on entry to sync(…) { … }. Released on exit or side effect.

Experimental evaluation 15 programs, 1.3 MLOC BitcoinJ, Daikon, Derby, Eclipse, Guava, Jetty, Velicity, Zookeeper, Tomcat, … 5 contain programmer-written @GuardedBy annotations 661 correct annotations Candidates: annotations written by the programmer or inferred by our tool Correct: program never suffers a data race on the element (manual analysis) Results: Inference: precision 100%, recall 83% Type-checking: precision 100%, recall 99% Programmers: precision 50%, recall 42% Due to complex reasoning Numbers are with respect to inference results Due to limitations of Java syntax

Programmer mistakes Errors in every program that programmers annotated with respect to both value and name semantics Creating external aliases Lock writes but not reads Syntax errors Omitted annotations

Implementations Type checker: Inference: Lock Checker, distributed with the Checker Framework http://CheckerFramework.org/ Live demo: http://eisop.uwaterloo.ca/live Inference: Julia abstract interpretation http://juliasoft.com/

Contributions Formal semantics for locking disciplines value-based unambiguous prevents data races Two implementations: type-checker that validates use of locking discipline (@GuardedBy) inference tool that infers locking discipline (@GuardedBy) Experiments: programmer-written @GuardedBy: are often inconsistent with informal semantics permit data races even when consistent with informal semantics Type-checker alidates programmer-written locking discipline, expressed as @GuardedBy annotations.

Related work Name-based semantics: JML, JCIP, many others Heuristic checking tools: Warlock, ESC/Modula-3, ESC/Java Unsound inference: [Naik PLDI 2006] uses may-alias, [Rose CSJP 2004] is dynamic Sound inference for part of Java [Flanagan SAS 2004] Type-and-effect type systems: heavier-weight, detect deadlocks too Ownership types