K. Rustan M. Leino RiSE, Microsoft Research, Redmond joint work with Peter Müller and Jan Smans Lecture 1 2 September 2009 FOSAD 2009, Bertinoro, Italy.

Slides:



Advertisements
Similar presentations
1 Lecture 5 Towards a Verifying Compiler: Multithreading Wolfram Schulte Microsoft Research Formal Methods 2006 Race Conditions, Locks, Deadlocks, Invariants,
Advertisements

Advanced programming tools at Microsoft
Joint work with Mike Barnett, Robert DeLine, Manuel Fahndrich, and Wolfram Schulte Verifying invariants in object-oriented programs K. Rustan M. Leino.
Demand-driven inference of loop invariants in a theorem prover
Writing specifications for object-oriented programs K. Rustan M. Leino Microsoft Research, Redmond, WA, USA 21 Jan 2005 Invited talk, AIOOL 2005 Paris,
1 Towards a Verifying Compiler: The Spec# Approach Wolfram Schulte Microsoft Research Formal Methods 2006 Joint work with Rustan Leino, Mike Barnett, Manuel.
Technologies for finding errors in object-oriented software K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 1 Summer school on Formal Models.
Technologies for finding errors in object-oriented software K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 0 Summer school on Formal Models.
Lecture 4 Towards a Verifying Compiler: Data Abstraction Wolfram Schulte Microsoft Research Formal Methods 2006 Purity, Model fields, Inconsistency _____________.
K. Rustan M. Leino Peter Müller IFIP WG 2.3 meeting June 2009 Boston, MA.
In this episode of The Verification Corner, Rustan Leino talks about Loop Invariants. He gives a brief summary of the theoretical foundations and shows.
Automated Software Verification with a Permission-Based Logic 20 th June 2014, Zürich Malte Schwerhoff, ETH Zürich.
Verification of Multithreaded Object- Oriented Programs with Invariants Bart Jacobs, K. Rustan M. Leino, Wolfram Schulte.
A simple sequential reasoning approach for sound modular verification of mainstream multithreaded programs Wolfram Schulte & Bart Jacobs Microsoft Research.
K. Rustan M. Leino Microsoft Research Peter Müller ETH Zurich Angela Wallenburg Chalmers University.
K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond, WA, USA 3 December 2008 U. Lugano Lugano, Switzerland.
ISBN Chapter 3 Describing Syntax and Semantics.
1 Discrete Structures Lecture 29 Predicates and Programming Read Ch
K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond, WA part 0 International Summer School Marktoberdorf Marktoberdorf,
Fractional Permissions without the Fractions Alex Summers ETH Zurich Joint work with: Stefan Heule, Rustan Leino, Peter Müller ETH Zurich MSR Redmond ETH.
ECI 2007: Specification and Verification of Object-Oriented Programs Lecture 2 Courtesy: K. Rustan M. Leino and Wolfram Schulte.
Lecture 2 Towards a Verifying Compiler: Logic of Object oriented Programs Wolfram Schulte Microsoft Research Formal Methods 2006 Objects, references, heaps,
ESC Java. Static Analysis Spectrum Power Cost Type checking Data-flow analysis Model checking Program verification AutomatedManual ESC.
Using and Building an Automatic Program Verifier K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond Lecture 1 LASER.
K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond, WA part 0 Summer School on Logic and Theorem-Proving in Programming.
K. Rustan M. Leino RiSE, Microsoft Research Typing, Analysis and Verification of Heap-Manipulating Programs Dagstuhl, Germany 20 July 2009.
Using and Building an Automatic Program Verifier K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond Lecture 0 LASER.
ECI 2007: Specification and Verification of Object- Oriented Programs Lecture 1.
Building a program verifier K. Rustan M. Leino Microsoft Research, Redmond, WA 10 May 2006 Guest lecture, Shaz Qadeer’s cse599f, Formal Verification of.
K. Rustan M. Leino Microsoft Research, Redmond NUI Maynooth Maynooth, Ireland 8 June 2007.
ESC Java. Static Analysis Spectrum Power Cost Type checking Data-flow analysis Model checking Program verification AutomatedManual ESC.
Using and Building an Automatic Program Verifier K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond Lecture 4 LASER.
Using and Building an Automatic Program Verifier K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond Lecture 5 LASER.
Describing Syntax and Semantics
Using and Building an Automatic Program Verifier K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond Lecture 3 LASER.
K. Rustan M. Leino Microsoft Research, Redmond, WA 10 Oct 2007 IFIP WG 2.3 meeting Santa Fe, NM.
K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond Caltech Pasadena, CA 12 November 2009.
K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond, WA part 1 Summer School on Logic and Theorem-Proving in Programming.
K. Rustan M. Leino RiSE, Microsoft Research, Redmond joint work with Peter Müller and Jan Smans Lecture 0 1 September 2009 FOSAD 2009, Bertinoro, Italy.
K. Rustan M. Leino RiSE, Joint work with: Peter Müller (ETH Zurich) Jan Smans (KU Leuven) Special thanks to Mike Barnett VMCAI, Madrid, Spain, 18 January.
Using and Building an Automatic Program Verifier K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond Lecture 3 Marktoberdorf.
Viper A Verification Infrastructure for Permission-Based Reasoning 1 st March 2015, ECOOP’15 PC Meeting, Zurich Uri Juhasz, Ioannis Kassios, Peter Müller,
Program Verification K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond University of Washington CSE P January.
Viper A Verification Infrastructure for Permission-Based Reasoning 24 th March 2015, JML Workshop, Leiden Uri Juhasz, Ioannis Kassios, Peter Müller, Milos.
Rustan Leino RiSE, Microsoft Research, Redmond MIT 5 June 2009 Joint work with: Peter Müller, ETH Zurich Jan Smans, KU Leuven.
Using and Building an Automatic Program Verifier K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond Lecture 0 Marktoberdorf.
K. Rustan M. Leino and Wolfram Schulte Microsoft Research, Redmond ESOP 2007 Braga, Portugal 28 March 2007.
Specifying and verifying programs in Spec# K. Rustan M. Leino Microsoft Research, Redmond, WA, USA Invited talk, PSI 2006 Novosibirsk, Russia 27 June 2006.
K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond, WA part 2 International Summer School Marktoberdorf Marktoberdorf,
An Introduction to Automated Program Verification with Permission Logics 15 th May 2015, Systems Group, ETH Zurich Uri Juhasz, Ioannis Kassios, Peter Müller,
K. Rustan M. Leino Microsoft Research, Redmond, WA, USA 15 Nov 2007 Chalmers Göteborg, Sweden.
Spec# John Lefor Program Manager Developer Division, Microsoft.
Presented by: Belgi Amir Seminar in Distributed Algorithms Designing correct concurrent algorithms Spring 2013.
1 Verification of object-oriented programs with invariants Mike Barnett, Robert DeLine, Manuel Fahndrich, K. Rustan M. Leino, Wolfram Schulte ECOOP 2003.
ESOP 2010, Paphos, Cyprus, 22 March 2010 K. Rustan M. Leino (RiSE group, Microsoft Research) Peter Müller (ETH Zurich) Jan Smans (KU Leuven)
Academic Year 2014 Spring Academic Year 2014 Spring.
Dafny An automatic program verifier for functional correctness
Specification techniques for verifying object-oriented software
Deductive Verification Tools Tutorial for Dagstuhl Seminar 16201
Auto-active verification
Weakest Precondition of Unstructured Programs
A Verification Infrastructure for Permission-based Reasoning
The Relationship Between Separation Logic and Implicit Dynamic Frames
The Relationship Between Separation Logic and Implicit Dynamic Frames
Program Verification via an Intermediate Verification Language
Verification of concurrent object-oriented programs
Auto-active verification
A Verification Infrastructure for Permission-Based Reasoning
Dafny An automatic program verifier for functional correctness
Auto-active verification
Presentation transcript:

K. Rustan M. Leino RiSE, Microsoft Research, Redmond joint work with Peter Müller and Jan Smans Lecture 1 2 September 2009 FOSAD 2009, Bertinoro, Italy

Permissions guide what memory locations are allowed to be accessed Activation records and monitors can hold permissions Permissions can be transferred between activation records and monitors Locks grant mutually exclusive access to monitors

More examples Preventing deadlocks Using abstraction Building a program verifier

Summary, and ghost variables

A deadlock is the situation where a nonempty set (cycle) of threads each waits for a resource (e.g., lock) that is held by another thread in the set Example: method M() … { acquire a; acquire b; … } method M() … { acquire a; acquire b; … } method N() … { acquire b; acquire a; … } method N() … { acquire b; acquire a; … }

Deadlocks are prevented by making sure no such cycle can ever occur The program partially order locks The program must acquire locks in strict ascending order A deadlock is the situation where a nonempty set (cycle) of threads each waits for a resource (e.g., lock) that is held by another thread in the set

Wait order is a dense partial order (Mu, <<) with a bottom element  << is the strict version of << The wait level of an object o is stored in a mutable ghost field o.mu Accessing o.mu requires appropriate permissions, as for other fields The syntax means (  l  Held  l.mu << X) where Held denotes the set of locks held by the current thread maxlock << X

With these preconditions, both methods verify The conjunction of the preconditions is false, so the methods can never be invoked at the same time method M() requires a.mu << b.mu { acquire a; acquire b; … } method M() requires a.mu << b.mu { acquire a; acquire b; … } method N() requires b.mu << a.mu { acquire b; acquire a; … } method N() requires b.mu << a.mu { acquire b; acquire a; … } requires rd(a.mu) requires rd(b.mu) requires rd(a.mu) requires rd(b.mu)

Recall, the wait level of an object o is stored in the ghost field o.mu Initially, the.mu field is  The.mu field is set by the share statement: picks some wait level strictly between L and H, and sets o.mu to that level Provided L << H and neither denotes an extreme element, such a wait level exists, since the order is dense means share o between L and H; share o; share o between maxlock and ;

Deadlock prevention

Specifying wait levels

When is: allowed? When o.mu is writable! … and the thread holds o Recall, means (  l  Held  l.mu << X), so uttering m axlock has the effect of reading many.mu fields We either need r d(maxlock), or reorder o between L and H; maxlock << X

Include threads in wait order method M() … { fork tk := N(); acquire a; join tk; … } method M() … { fork tk := N(); acquire a; join tk; … } method N() … { acquire a; … release a; } method N() … { acquire a; … release a; }

picks a level θ between L and H, and then sets tk.mu to θ The precondition of o.M() is checked, substituting θ as the value of any occurrence of maxlock now means (  l  Held  l.mu << X)  θ << X where θ is the one for the current thread requires maxlock << tk.mu without between clause, θ is picked as just barely above maxlock of the forking thread fork tk := o.M() between L and H; maxlock << X join tk;

Fine-grained locking :List:List :Node:Node :Node:Node :Node:Node :Node:Node head tail current

:Node:Node :Node:Node :Node:Node :Node:Node tail p method Update(p: Node) requires acc(p.data,40) … { acquire p; while (p.next != null) … { var nx := p.next; acquire nx; nx.data := nx.data + 1; release p; p := nx; } release p; } method Update(p: Node) requires acc(p.data,40) … { acquire p; while (p.next != null) … { var nx := p.next; acquire nx; nx.data := nx.data + 1; release p; p := nx; } release p; } invariant acc(data,60) && … && (next != null ==> acc(next.data,40) && data <= next.data); invariant acc(data,60) && … && (next != null ==> acc(next.data,40) && data <= next.data);

:Node:Node :Node:Node :Node:Node :Node:Node tail p method Update(p: Node) requires acc(p.data,40) … { acquire p; while (p.next != null) … { var nx := p.next; acquire nx; nx.data := nx.data + 1; release p; p := nx; } release p; } method Update(p: Node) requires acc(p.data,40) … { acquire p; while (p.next != null) … { var nx := p.next; acquire nx; nx.data := nx.data + 1; release p; p := nx; } release p; } nx invariant acc(data,60) && … && (next != null ==> acc(next.data,40) && data <= next.data); invariant acc(data,60) && … && (next != null ==> acc(next.data,40) && data <= next.data);

:Node:Node :Node:Node :Node:Node :Node:Node tail p method Update(p: Node) requires acc(p.data,40) … { acquire p; while (p.next != null) … { var nx := p.next; acquire nx; nx.data := nx.data + 1; release p; p := nx; } release p; } method Update(p: Node) requires acc(p.data,40) … { acquire p; while (p.next != null) … { var nx := p.next; acquire nx; nx.data := nx.data + 1; release p; p := nx; } release p; } nx invariant acc(data,60) && … && (next != null ==> acc(next.data,40) && data <= next.data); invariant acc(data,60) && … && (next != null ==> acc(next.data,40) && data <= next.data);

:Node:Node :Node:Node :Node:Node :Node:Node tail p method Update(p: Node) requires acc(p.data,40) … { acquire p; while (p.next != null) … { var nx := p.next; acquire nx; nx.data := nx.data + 1; release p; p := nx; } release p; } method Update(p: Node) requires acc(p.data,40) … { acquire p; while (p.next != null) … { var nx := p.next; acquire nx; nx.data := nx.data + 1; release p; p := nx; } release p; } nx invariant acc(data,60) && … && (next != null ==> acc(next.data,40) && data <= next.data); invariant acc(data,60) && … && (next != null ==> acc(next.data,40) && data <= next.data);

What permissions to include in method Play’s precondition? :RockBand:RockBand :Guitar:Guitar :GtString:GtString:GtString:GtString :Organ:Organ :DrawBar:DrawBar :Drums:Drums :Kick:Kick :Snare:Snare method Play() … method Bang() … method Strum() … method Grind() …

Named container of permissions acc(y) class C { predicate P {…} … } class C { predicate P {…} … } fold P; unfold P;

Predicates

Intermediate verification language Verification engine Spec#Spec#DafnyDafny C with VCC specifications ChaliceChalice C with HAVOC specifications Z3Z3SimplifySimplify SMT Lib BoogieBoogie Isabelle/ HOL

First-order mathematical declarations type const function axiom Imperative declarations var procedure implementation

x := E havoc x assert E assume E … Useful idiom: havoc x; assume P(x); “set x to a value such that P(x) holds”

wp( x := E, Q ) = wp( havoc x, Q ) = wp( assert P, Q ) = wp( assume P, Q ) = wp( S ; T, Q ) = Q[ E / x ] (  x  Q ) P  Q P  Q wp( S, wp( T, Q )) For any command S and post-state predicate Q, wp(S,Q) is the pre-state predicate that characterizes those initial states from which every terminating trace of S: does not go wrong, and terminates in a state satisfying Q

var Heap: Ref  FieldName  Value; var Mask: Ref  FieldName  Permission; x := o.f; ≡ assert o ≠ null; assert Mask[o, f] > 0; x := Heap[o, f]; o.f := x ≡ assert o ≠ null; assert Mask[o, f] == 100; Heap[o, f] := x;

o := new C ≡ … o.mu :=  … share o between L and H ≡ assert CanWrite(o,mu)  o.mu =  ; assert L << H; havoc μ; assume L << μ << H; o.mu := μ; Exhale MonitorInv(o); acquire o ≡ assert CanRead(o,mu); assert maxlock << o.mu; Held := Held  {o}; Inhale MonitorInv(o); release o ≡ assert o  Held; Exhale MonitorInv(o); Held := Held – {o}; thread local shared, available shared, locked newshareacquire release

Defined by structural induction For expression P without permission predicates Exhale P≡assert P Inhale P≡assume P Exhale acc(o.f, p) ≡ assert Mask[o,f] ≥ p; Mask[o,f] := Mask[o,f] – p; Inhale acc(o.f, p) ≡ if (Mask[o,f] == 0) { havoc Heap[o,f]; } Mask[o,f] := Mask[o,f] + p;

Boogie encoding

Chalice (and Boogie) available as open source: Spec# also available as open source under academic license: