Specifying Multithreaded Java semantics for Program Verification Abhik Roychoudhury National University of Singapore (Joint work with Tulika Mitra)

Slides:



Advertisements
Similar presentations
Bounded Model Checking of Concurrent Data Types on Relaxed Memory Models: A Case Study Sebastian Burckhardt Rajeev Alur Milo M. K. Martin Department of.
Advertisements

Implementation and Verification of a Cache Coherence protocol using Spin Steven Farago.
Tintu David Joy. Agenda Motivation Better Verification Through Symmetry-basic idea Structural Symmetry and Multiprocessor Systems Mur ϕ verification system.
Construction process lasts until coding and testing is completed consists of design and implementation reasons for this phase –analysis model is not sufficiently.
Architecture-aware Analysis of Concurrent Software Rajeev Alur University of Pennsylvania Amir Pnueli Memorial Symposium New York University, May 2010.
Abstraction and Modular Reasoning for the Verification of Software Corina Pasareanu NASA Ames Research Center.
D u k e S y s t e m s Time, clocks, and consistency and the JMM Jeff Chase Duke University.
Concurrency 101 Shared state. Part 1: General Concepts 2.
1 Concurrency Specification. 2 Outline 4 Issues in concurrent systems 4 Programming language support for concurrency 4 Concurrency analysis - A specification.
An Case for an Interleaving Constrained Shared-Memory Multi- Processor CS6260 Biao xiong, Srikanth Bala.
/ PSWLAB Atomizer: A Dynamic Atomicity Checker For Multithreaded Programs By Cormac Flanagan, Stephen N. Freund 24 th April, 2008 Hong,Shin.
Jan Ron McFadyen1 Singleton To guarantee that there is at most one instance of a class we can apply the singleton pattern. Singleton Static.
Oct Ron McFadyen1 Singleton To guarantee that there is at most one instance of a class we can apply the singleton pattern. Singleton Static.
Slides 8d-1 Programming with Shared Memory Specifying parallelism Performance issues ITCS4145/5145, Parallel Programming B. Wilkinson Fall 2010.
“THREADS CANNOT BE IMPLEMENTED AS A LIBRARY” HANS-J. BOEHM, HP LABS Presented by Seema Saijpaul CS-510.
CS 290C: Formal Models for Web Software Lecture 10: Language Based Modeling and Analysis of Navigation Errors Instructor: Tevfik Bultan.
Formalisms and Verification for Transactional Memories Vasu Singh EPFL Switzerland.
Programming Language Semantics Java Threads and Locks Informal Introduction The Java Specification Language Chapter 17.
Specifying Java Thread Semantics Using a Uniform Memory Model Jason Yue Yang Ganesh Gopalakrishnan Gary Lindstrom School of Computing University of Utah.
Spring 2010ACS-3913 Ron McFadyen1 Singleton To guarantee that there is at most one instance of a class we can apply the singleton pattern. Singleton Static.
1 Sharing Objects – Ch. 3 Visibility What is the source of the issue? Volatile Dekker’s algorithm Publication and Escape Thread Confinement Immutability.
CS510 Concurrent Systems Class 5 Threads Cannot Be Implemented As a Library.
User-Level Interprocess Communication for Shared Memory Multiprocessors Brian N. Bershad, Thomas E. Anderson, Edward D. Lazowska, and Henry M. Levy Presented.
Analyzing the CRF Java Memory Model Yue Yang Ganesh Gopalakrishnan Gary Lindstrom School of Computing University of Utah.
Semantics of Multithreaded Java Jeremy Manson and William Pugh Background Material Jack Newton University of Alberta
Winter 2007ACS-3913 Ron McFadyen1 Singleton To guarantee that there is at most one instance of a class we can apply the singleton pattern. Singleton Static.
272: Software Engineering Fall 2012 Instructor: Tevfik Bultan Lecture 4: SMT-based Bounded Model Checking of Concurrent Software.
Memory Consistency Models Some material borrowed from Sarita Adve’s (UIUC) tutorial on memory consistency models.
Thread-modular Abstraction Refinement Thomas A. Henzinger, et al. CAV 2003 Seonggun Kim KAIST CS750b.
Advances in Language Design
SEC(R) 2008 Intel® Concurrent Collections for C++ - a model for parallel programming Nikolay Kurtov Software and Services.
1 Lecture 4: Threads Operating System Fall Contents Overview: Processes & Threads Benefits of Threads Thread State and Operations User Thread.
Design patterns. What is a design pattern? Christopher Alexander: «The pattern describes a problem which again and again occurs in the work, as well as.
1 Concurrent Languages – Part 1 COMP 640 Programming Languages.
CDP 2013 Based on “C++ Concurrency In Action” by Anthony Williams, The C++11 Memory Model and GCCThe C++11 Memory Model and GCC Wiki and Herb Sutter’s.
Java Threads 11 Threading and Concurrent Programming in Java Introduction and Definitions D.W. Denbo Introduction and Definitions D.W. Denbo.
Dynamic Analysis of Multithreaded Java Programs Dr. Abhik Roychoudhury National University of Singapore.
1 Causal-Consistent Reversible Debugging Ivan Lanese Focus research group Computer Science and Engineering Department University of Bologna/INRIA Bologna,
Compactly Representing Parallel Program Executions Ankit Goel Abhik Roychoudhury Tulika Mitra National University of Singapore.
ABSTRACT The real world is concurrent. Several things may happen at the same time. Computer systems must increasingly contend with concurrent applications.
Contracts for Concurrency - Contracts & Inheritance Aryabrata Basu University of Georgia.
Sharing Objects  Synchronization  Atomicity  Specifying critical sections  Memory visibility  One thread’s modification seen by the other  Visibility.
Shared Memory Consistency Models. SMP systems support shared memory abstraction: all processors see the whole memory and can perform memory operations.
Memory Consistency Models. Outline Review of multi-threaded program execution on uniprocessor Need for memory consistency models Sequential consistency.
Java Thread and Memory Model
Multiprocessor Cache Consistency (or, what does volatile mean?) Andrew Whitaker CSE451.
SPL/2010 Guarded Methods and Waiting 1. SPL/2010 Reminder! ● Concurrency problem: asynchronous modifications to object states lead to failure of thread.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Concurrency & Dynamic Programming.
ICFEM 2002, Shanghai Reasoning about Hardware and Software Memory Models Abhik Roychoudhury School of Computing National University of Singapore.
Threads and Singleton. Threads  The JVM allows multiple “threads of execution”  Essentially separate programs running concurrently in one memory space.
Detecting Atomicity Violations via Access Interleaving Invariants
CSC Multiprocessor Programming, Spring, 2012 Outline for Chapters 1-3 and 13 Dr. Dale E. Parson.
Operating System Concepts
Testing Concurrent Programs Sri Teja Basava Arpit Sud CSCI 5535: Fundamentals of Programming Languages University of Colorado at Boulder Spring 2010.
1 Programming with Shared Memory - 3 Recognizing parallelism Performance issues ITCS4145/5145, Parallel Programming B. Wilkinson Jan 22, 2016.
Lecture 20: Consistency Models, TM
Healing Data Races On-The-Fly
The Singleton Pattern SE-2811 Dr. Mark L. Hornick.
Memory Consistency Models
Threads Cannot Be Implemented As a Library
Memory Consistency Models
Specifying Multithreaded Java semantics for Program Verification
Threads and Memory Models Hal Perkins Autumn 2011
Threads and Memory Models Hal Perkins Autumn 2009
Lecture 22: Consistency Models, TM
Threads Chapter 4.
Memory Consistency Models
CSE 153 Design of Operating Systems Winter 19
Relaxed Consistency Finale
Programming with Shared Memory Specifying parallelism
Presentation transcript:

Specifying Multithreaded Java semantics for Program Verification Abhik Roychoudhury National University of Singapore (Joint work with Tulika Mitra)

ICSE 2002, Orlando FL2 Java Multithreading Threads communicate via shared variables Threads run on uni- or multi-processors Semantics given as abstract rules : Java Memory Model (JMM) Supports locking of shared variables via synchronized statements Locking may be avoided ….

ICSE 2002, Orlando FL3 Shared variable access without locks Initially : A = 0, B = 0 B = 1; A = 1; while (A != 1) {}; return B || Expected returned value = 1 Locks not used, but using A as flag.

ICSE 2002, Orlando FL4 What may happen Returned value = 0 A= 1 return B B = 1 May happen if ….. Threads are executed on different processors. B = 1; A = 1; while (A != 1) {}; return B ||

ICSE 2002, Orlando FL5 Sequential Consistency || Op1; Op2; Op’ ; Op’’ ; Programmer expects statements within a thread to complete in program order: Sequential Consistency I.Each thread proceeds in program order II.Operations across threads are interleaved Op1 Op’’ Op2 Op’ violates SC

ICSE 2002, Orlando FL6 Is this a problem ? Programmers expect SC Verification techniques assume SC execution SC not guaranteed by execution platforms Not demanded by Java language spec. Unrealistic for any future spec. to demand YES !!

ICSE 2002, Orlando FL7 Organization Shared variable access without locks Candidate solutions Specifying the Java Memory Model (JMM) Using JMM for verification

ICSE 2002, Orlando FL8 1. Program with caution Always synchronize (and acquire lock) before writing a shared object For these programs, any execution is SC Unacceptable performance overheads for low-level libraries Software libraries from other sources cannot be guaranteed to be properly synchronized

ICSE 2002, Orlando FL9 2. Change the Semantics Current semantics called Java Memory Model (JMM). Part of Java language spec. Weaker than Sequential Consistency. Specifies which re-orderings are allowed within a thread. Currently being considered for revision Existing/future JMM bound to be weaker than SC – Does not solve the problem

ICSE 2002, Orlando FL10 3. Use the semantics Develop a formal executable description of the Java Memory Model Use it for static checking of programs JMM captures all possible behaviors for any implementation – Platform independent reasoning Adds value to existing program verification techniques

ICSE 2002, Orlando FL11 Organization Shared variable access without locks Candidate solutions Specifying the Java Memory Model (JMM) Using JMM for verification

ICSE 2002, Orlando FL12 JMM Overview Each shared variable v has A master copy A local copy in each thread Threads read and write local/master copies by actions Imposes ordering constraints on actions Constraints are informal and declarative Hard to understand !!

ICSE 2002, Orlando FL13 JMM Actions Master copy of v read(v,t) <load(v,t) write(v,t)>store(v,t) Actions invoked by Program Execution: use/assign(t,v) Read from/ Write into local copy of v in t lock/unlock(t) Acquire/Release lock on shared variables Local copy of v in t

ICSE 2002, Orlando FL14 Formal Specification Asynchronous concurrent composition Th 1 || Th 2 || … || Th n || MM Local state of each thread modeled as cache ( Local copy, Stale bit, Dirty bit ) Queues for incomplete reads/writes Local state of MM ( Master copies, Lock ownership info )

ICSE 2002, Orlando FL15 Specifying JMM Actions Each action is a guarded command G  B Only 8 actions capture all the rules. Example: Use of variable v by thread t  stale[t,v]  return local_copy[t,v] Applicability of action stated as guard In rule-based description, several rules determine the applicability

ICSE 2002, Orlando FL16 Understanding JMM assign(t, v) < load(t,v)  assign(t,v) < store(t,v) < load(t,v) A store must intervene between an assign and a load action for a variable v by thread t

ICSE 2002, Orlando FL17 Understanding JMM assign(t, v) < store(t,v) < load(t,v)  assign(t,v) < store(t,v) < write(t,v) < read(t,v) < load(t,v) assign(t,v) < load(t,v)  read < assign <load is not possible. We specify assign(t,v) : empty(read_queue[t,v]) -> ….

ICSE 2002, Orlando FL18 Executable model Java threads invoke use,assign,lock,unlock Threads block if the next action not enabled To enable these, store,write,load,read are executed in any order provided guard holds Example: To enable assign, a load is executed (if there was an earlier read) Proof of equivalence between executable and rule-based JMM.

ICSE 2002, Orlando FL19 Other JMM Features Executable model also captures: Volatile variables : Every access of these variables accesses master copy Prescient stores: Writing master copy ahead of local copy Waiting and Notification Modeled by additional guarded commands.

ICSE 2002, Orlando FL20 Organization Shared variable access without locks Candidate solutions Specifying the Java Memory Model (JMM) Using JMM for verification

ICSE 2002, Orlando FL21 Verifying Unsynchronized Code assign(B,1) assign(A,1) While (use(A) !=1){} use(B) || use/assign invoke corresponding guarded commands load/store/read/write executed to enable use/assign Exhaustive state space exploration shows use(B) may return 1 or 0

ICSE 2002, Orlando FL22 Program verification Composing executable JMM allows search The state space explosion problem  Most Java programs are “properly synchronized” and hence SC execution Unsynchronized code appears in low-level fragments which are frequently executed These programs are small, so …

ICSE 2002, Orlando FL23 One possibility User chooses one program path in each thread (Creative step) Exhaustively check all possible execution traces from chosen program paths (Automated state space exploration: Can verify invariants) Choosing program paths requires understanding source code, not JMM

ICSE 2002, Orlando FL24 Case Study: Double Checked Locking Idiom for lazy instantiation of a singleton Check whether garbage data-fields can be returned by this object initialization routine Verification by composing the JMM reveals: Incompletely instantiated object can be returned Due to re-ordering of writes within constructor Detected by prototype invariant checker in 0.15 sec

ICSE 2002, Orlando FL25 Summary Executable specification of Multithreaded Java semantics Using the specification for checking multithreaded programs Similar approach has been studied before in the context of hardware multiprocessors How to correct the bugs found (the harmful re-orderings) ?