Specifying and Checking Stateful Software Interfaces (Lecture 3) Manuel Fähndrich Microsoft Research 2005 Summer School on Reliable Computing.

Slides:



Advertisements
Similar presentations
Advanced programming tools at Microsoft
Advertisements

Joint work with Mike Barnett, Robert DeLine, Manuel Fahndrich, and Wolfram Schulte Verifying invariants in object-oriented programs K. Rustan M. Leino.
Operating Systems Components of OS
Writing specifications for object-oriented programs K. Rustan M. Leino Microsoft Research, Redmond, WA, USA 21 Jan 2005 Invited talk, AIOOL 2005 Paris,
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Lecture 4 Towards a Verifying Compiler: Data Abstraction Wolfram Schulte Microsoft Research Formal Methods 2006 Purity, Model fields, Inconsistency _____________.
Challenges in increasing tool support for programming K. Rustan M. Leino Microsoft Research, Redmond, WA, USA 23 Sep 2004 ICTAC Guiyang, Guizhou, PRC joint.
Automatic Verification Book: Chapter 6. What is verification? Traditionally, verification means proof of correctness automatic: model checking deductive:
Abstraction and Modular Reasoning for the Verification of Software Corina Pasareanu NASA Ames Research Center.
Constraint Semantics for Abstract Read Permissions 28 th July 2014, FTfJP, Uppsala John Tang Boyland (UW-Milwaukee/ETH Zurich) Peter Müller, Malte Schwerhoff,
PROTOCOL VERIFICATION & PROTOCOL VALIDATION. Protocol Verification Communication Protocols should be checked for correctness, robustness and performance,
1 Mooly Sagiv and Greta Yorsh School of Computer Science Tel-Aviv University Modern Compiler Design.
Verification of Multithreaded Object- Oriented Programs with Invariants Bart Jacobs, K. Rustan M. Leino, Wolfram Schulte.
Language Support for Fast and Reliable Message-based Communication in Singularity Manuel Fähndrich, Mark Aiken, Chris Hawblitzel, Orion Hodson, Galen Hunt,
ESP: A Language for Programmable Devices Sanjeev Kumar, Yitzhak Mandelbaum, Xiang Yu, Kai Li Princeton University.
EXTENSIBILITY, SAFETY AND PERFORMANCE IN THE SPIN OPERATING SYSTEM B. Bershad, S. Savage, P. Pardyak, E. G. Sirer, D. Becker, M. Fiuczynski, C. Chambers,
Background information Formal verification methods based on theorem proving techniques and model­checking –to prove the absence of errors (in the formal.
CS 355 – Programming Languages
Component Interaction in Distributed Systems Nat Pryce Imperial College
Using Programmer-Written Compiler Extensions to Catch Security Holes Authors: Ken Ashcraft and Dawson Engler Presented by : Hong Chen CS590F 2/7/2007.
Typestates for Objects R. DeLine and M. Fähnrich In Proceedings of the European Conference on Object-oriented Programming (ECOOP '04), June Presented.
Vertically Integrated Analysis and Transformation for Embedded Software John Regehr University of Utah.
CS294, YelickESC, p1 CS Extended Static Checking
Developing Verifiable Concurrent Software Tevfik Bultan Department of Computer Science University of California, Santa Barbara
Programming Language Semantics Java Threads and Locks Informal Introduction The Java Specification Language Chapter 17.
Active Messages: a Mechanism for Integrated Communication and Computation von Eicken et. al. Brian Kazian CS258 Spring 2008.
A Type System for Expressive Security Policies David Walker Cornell University.
Specifying and Checking Stateful Software Interfaces Manuel Fähndrich Microsoft Research 2005 Summer School on Reliable Computing Eugene,
Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.
VB in Context Michael B. Spring Department of Information Science and Telecommunications University of Pittsburgh Pittsburgh, Pa 15260
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
Declaring and Checking Non-null Types in an Object-Oriented Language Authors: Manuel Fahndrich K. Rustan M. Leino OOPSLA’03 Presenter: Alexander Landau.
Mechanized Metatheory for User- Defined Type Extensions Dan Marino, Brian Chin, Todd Millstein UCLA Gang Tan Boston College Robert J. Simmons, David Walker.
User-Level Interprocess Communication for Shared Memory Multiprocessors Brian N. Bershad, Thomas E. Anderson, Edward D. Lazowska, and Henry M. Levy Presented.
1/25 Pointer Logic Changki PSWLAB Pointer Logic Daniel Kroening and Ofer Strichman Decision Procedure.
CS252: Systems Programming Ninghui Li Final Exam Review.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
CSE 425: Object-Oriented Programming II Implementation of OO Languages Efficient use of instructions and program storage –E.g., a C++ object is stored.
Polymorphism &Virtual Functions
Software Engineering Prof. Dr. Bertrand Meyer March 2007 – June 2007 Chair of Software Engineering Static program checking and verification Slides: Based.
Inter-Process Communication Mechanisms CSE331 Operating Systems Design.
Presentation of Singularity OS Seminar, winter 2005 by Jacob Munk-Stander November 23 rd, 2005.
Eric Keller, Evan Green Princeton University PRESTO /22/08 Virtualizing the Data Plane Through Source Code Merging.
1 Chapter 10: Data Abstraction and Object Orientation Aaron Bloomfield CS 415 Fall 2005.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Threads and Processes.
Introduction to Distributed Systems Slides for CSCI 3171 Lectures E. W. Grundke.
Introduction to Formal Methods Based on Jeannette M. Wing. A Specifier's Introduction to Formal Methods. IEEE Computer, 23(9):8-24, September,
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
1 Lecture 5 (part2) : “Interprocess communication” n reasons for process cooperation n types of message passing n direct and indirect message passing n.
Writing Systems Software in a Functional Language An Experience Report Iavor Diatchki, Thomas Hallgren, Mark Jones, Rebekah Leslie, Andrew Tolmach.
A Universe-Type-Based Verification Technique for Mutable Static Fields and Methods Alexander J Summers Sophia Drossopoulou Imperial College London Peter.
CE Operating Systems Lecture 13 Linux/Unix interprocess communication.
Hwajung Lee.  Interprocess Communication (IPC) is at the heart of distributed computing.  Processes and Threads  Process is the execution of a program.
Lecture 5 1 CSP tools for verification of Sec Prot Overview of the lecture The Casper interface Refinement checking and FDR Model checking Theorem proving.
SWE 4743 Abstract Data Types Richard Gesick. SWE Abstract Data Types Object-oriented design is based on the theory of abstract data types Domain.
Formal Verification. Background Information Formal verification methods based on theorem proving techniques and model­checking –To prove the absence of.
1 Proving program termination Lecture 5 · February 4 th, 2008 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: A.
1 Verification of object-oriented programs with invariants Mike Barnett, Robert DeLine, Manuel Fahndrich, K. Rustan M. Leino, Wolfram Schulte ECOOP 2003.
Implementing Remote Procedure Call Landon Cox February 12, 2016.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 20 – C++ Subclasses and Inheritance.
1 Chapter 2: Operating-System Structures Services Interface provided to users & programmers –System calls (programmer access) –User level access to system.
Web Design & Development Lecture 9
Abstract Factory Pattern
Matching Logic An Alternative to Hoare/Floyd Logic
(One-Path) Reachability Logic
Abstract Factory Pattern
Logical architecture refinement
Computer Science 340 Software Design & Testing
Presentation transcript:

Specifying and Checking Stateful Software Interfaces (Lecture 3) Manuel Fähndrich Microsoft Research 2005 Summer School on Reliable Computing Eugene, Oregon

Reliable Computing Stateful Software Interfaces Lecture 2 (recap)  Frame axiom  Type-states using capabilities  Vault: W2K driver case study  Recursive data structures  Unifying non-linear data structures and linear data

Reliable Computing Stateful Software Interfaces Lecture 3  Fractional permissions  Fugue: Type-states for objects  Sing# and Singularity  No more type rules!

Reliable Computing Stateful Software Interfaces Read-only sharing  Idea by John Boyland: fractional permissions {  ! h }, ½{  ! h } ­ ½{  ! h }  In general {  ! h }, k{  ! h } ­ (1-k){  ! h }  Permission k{   h}  Write if k = 1  Read-only otherwise  Can express temporary sharing  Useful for multiple threads

Reliable Computing Stateful Software Interfaces Fugue (MSR)  C# + annotations only  No change in the language  Type states for objects  Resource/alias management  Non-null types  Checker at MSIL level (standard C# compiler)  Parts of the analysis are used in FxCop  will ship with VS2005

Reliable Computing Stateful Software Interfaces Fugue Demo

Reliable Computing Stateful Software Interfaces Typestates and class invariants Relate symbolic typestate name with internal class properties  Gives meaning to typestates What do ‘open’ and ‘closed’ mean?

Reliable Computing Stateful Software Interfaces Typestates and class invariants Socket socket closed Socket socket open WebPageFetcher CloseOpen GetPage [ WithProtocol(“open”,”closed”) ] class WebPageFetcher { private Socket socket; [Creates(“closed”)] public WebPageFetcher (); [ChangesState(“closed”,”open”)] public void Open (string server); [InState(“open”)] public string GetPage (string url); [ChangesState(“open”,”closed”)] public void Close (); }

Reliable Computing Stateful Software Interfaces Typestates and class invariants [ WithProtocol(“open”,”closed”) ] class WebPageFetcher { [Null(WhenEnclosingState=“closed”)] [InState(“connected”, WhenEnclosingState=“open”)] private Socket socket; [Creates(“closed”)] public WebPageFetcher (); [ChangesState(“closed”,”open”)] public void Open (string server); [InState(“open”)] public string GetPage (string url); [ChangesState(“open”,”closed”)] public void Close (); } null Socket socket closed connected Socket socket open WebPageFetcher CloseOpen GetPage

Reliable Computing Stateful Software Interfaces  Named predicate over object state  connected, open, closed, etc…  Pack and unpack  Transitions between abstract named predicate and field knowledge  Interpreted and abstract views x.state == open  x.socket.state == connected Typestates are predicates

Reliable Computing Stateful Software Interfaces null Socket socket - connected Socket socket - closed open Pack and unpack Packed viewUnpacked view Unpack Pack Unpack = apply definition Pack = prove predicate

Reliable Computing Stateful Software Interfaces Abstract vs. interpreted typestate In what contexts are pack and unpack allowed?  No unpack or pack:  Completely abstract object view.  By name matching  Unpack allowed  Object invariant visible anywhere  Pack allowed  State changes allowed anywhere Prototype design  Unpack anywhere  Pack within scope of class

Reliable Computing Stateful Software Interfaces Reasoning about objects  Frame stack and subclass state  Up- and down-casts  Object extensions (subclassing)  Open state model. By default, every predicate on a frame means true.  Sliding method semantics  Example: Caching WebPageFetcher

Reliable Computing Stateful Software Interfaces Modeling object state Inheritance hierarchyFrame stack object AB CDE A D Subclasses

Reliable Computing Stateful Software Interfaces Modeling object state Typestate  One per class frame  Single symbolic state for unknown subclasses Each frame  Packed, or  Unpacked Frame stack object A D f : Null g : Bound Subclasses open closed

Reliable Computing Stateful Software Interfaces Motivation for frame stacks  Characterize complete object state  Including unknown subclasses  Needed for casts  Modularity  Invariants do not span frames  Extensibility : subclasses can interpret typestate individually  State changes  How to change state of entire object?  Code can only directly manipulate concrete frames

Reliable Computing Stateful Software Interfaces Up- and down-casts F open closed object A D open closed down-cast to F

Reliable Computing Stateful Software Interfaces Typestate and subclassing class CacheWebPageFetcher : WebPageFetcher { [Null(WhenEnclosingState=“closed”)] [NotNull(WhenEnclosingState=“open”)] private Hashtable cache; [Creates(“closed”)] CachedWebPageFetcher (); [ChangesState(“closed”,”open”)] override void Open (string server); [InState(“open”)] override string GetPage (string url); [ChangesState(“open”,”closed”)] override void Close (); } CloseOpen null Hashtable cache closed null Socket socket closed notnull Hashtable cache closed connected Socket socket open

Reliable Computing Stateful Software Interfaces GetPage method class WebPageFetcher { [InState(“open”)] virtual string GetPage (string url) { … this.socket … } class CachedWebPageFetcher : WebPageFetcher { [InState(“open”)] override string GetPage (string url) { … this.cache … … base.GetPage(url) … } object WebPageFetcher open this

Reliable Computing Stateful Software Interfaces GetPage method class WebPageFetcher { … [InState(“open”)] virtual string GetPage (string url) { … this.socket … } class CachedWebPageFetcher : WebPageFetcher { … [InState(“open”)] override string GetPage (string url) { … this.cache … … base.GetPage(url) … } object WebPageFetcher open this openCachedWebPageFetcher

Reliable Computing Stateful Software Interfaces Establish new typestates  GetPage leaves object in same typestate  Open method must change frames from ‘closed’ to ‘open’  How can a method change the typestate of all frames?

Reliable Computing Stateful Software Interfaces Open method (client view) class WebPageFetcher { … [ChangesState(“closed”,”open”)] virtual void Open (string server); } object WebPageFetcher closed this before object WebPageFetcher open this after

Reliable Computing Stateful Software Interfaces Open method (implementation) class WebPageFetcher { … [ChangesState(“closed”,”open”)] virtual void Open (string server) { … this.socket = new Socket(); … } object WebPageFetcher closed X this before object WebPageFetcher open X this after

Reliable Computing Stateful Software Interfaces Open method (override) class CachedWebPageFetcher { … [ChangesState(“closed”,”open”)] override void Open (string server) { … base.Open(server); … this.cache = new Hashtable(); } object WebPageFetcher closed X this before object WebPageFetcher open X this after closedCachedWeb…openCachedWebPageFetcher

Reliable Computing Stateful Software Interfaces Sliding methods Method signatures differ:  Virtual call (entire object changes)  Method specs for C.m (and non-virtual call)  only prefix including C changes  frames below C do not change

Reliable Computing Stateful Software Interfaces Open method (override) [ChangesState(“closed”,”open”)] override void Open (string server) { … base.Open(server); … this.cache = new Hashtable(); } object WebPage… closed X this closedCachedWeb… open X this closed open X this open

Reliable Computing Stateful Software Interfaces Object type-states summary  Break object state into class frames  Each frame has individual type state  Symbolic treatment of type states of subclasses (ECOOP04)  Related work: Spec# object invariants  Also frame based  Invariants allowed to depend on base-class fields  Requires suffix unpacking  See Journal of Object Technology (JOT article)

Reliable Computing Stateful Software Interfaces Singularity  Research agenda: how do we build reliable software?  Singularity OS  Based on type safe language and IL verification  Strong process isolation  Communication solely by messages But: message-based code is difficult to write  Message not understood errors  Deadlocks Goal:  Provide language and tool support for message- based programs and systems programming  Compile time detection of errors

Reliable Computing Stateful Software Interfaces Sing# Language  Channel contracts  Specify typed message passing and valid protocol sequences  Provide efficient implementation based on pre-allocated receipt buffers  rep structs  Hierarchical structures safe to exchange over channels  Custom heaps  Explicit, but compiler verified, resource management for endpoints and other exchangeable data  Switch-receive  asynchronous event pattern matching  Overlays  Type safe structural casts for arrays of scalars  Deadlock prevention methodology

Reliable Computing Stateful Software Interfaces Deadlock prevention  … in dynamically configured communication networks.

Reliable Computing Stateful Software Interfaces Communication model  Inter-process communication via messages.  Messages are exchanged over channels  Assume synchronous  Channels are point-to-point  Two endpoints  Each owned by exactly one process  Bidirectional  Endpoints can be sent over a channel  Processes can fork, partitioning their endpoints

Reliable Computing Stateful Software Interfaces Communication model explained Kernel Name Server I III II create channel Kernel IV fork

Reliable Computing Stateful Software Interfaces P1 Kernel creates a process I IIIIV II Kernel Name Server Kernel Name Server Kernel Name Server send a over b a b Kernel Name Server fork

Reliable Computing Stateful Software Interfaces P1 2 processes connect I IIIIV II Kernel Name Server P2 P1 Kernel Name Server P2 P1 Kernel Name Server P2 P1 Kernel Name Server P2

Reliable Computing Stateful Software Interfaces Operational semantics  At each step of the configuration, each process chooses one of three actions: 1.Create channel 2. Fork 3. Communicate (by selecting a non-empty subset of its endpoints)  Deadlock:  Every process wants to communicate, but no channel has both endpoints selected.

Reliable Computing Stateful Software Interfaces P2 P3 P4 A dead lock P1

Reliable Computing Stateful Software Interfaces Basic idea: Obstructions Configuration invariant: At any point during execution, for each cycle C in the graph, there exists at least one process that witnesses C  Witness process is responsible for breaking cycle  A process witnesses a cycle via an obstruction, ie., a pair of endpoints local to a process connected by a path.

Reliable Computing Stateful Software Interfaces P3 Breaking the cycle Selection Strategy: A process P wanting to communicate must select at least one endpoint a. If a is obstructed with b, P must also select b. P1 P2P4

Reliable Computing Stateful Software Interfaces Instrumented Semantics  Configurations contain a set of obstructions O  E x E  Actions operate on obstructions  Create channel  Adds obstruction between new endpoints  Fork  Can split obstructed endpoints  Move a over b  Sender closure: Add (d, e) if (a,d) and (b,e)  Receiver closure: Add (a, f) if (c, f)  Add (a,c) or (d, b) for all (d,a)

Reliable Computing Stateful Software Interfaces Create Channel PP

Reliable Computing Stateful Software Interfaces P2P1 Fork P

Reliable Computing Stateful Software Interfaces P b P b d Q c a Send a over b (simple) Q c a d

Reliable Computing Stateful Software Interfaces Q P b d e P e d Q c a Send a over b (2) c a b Sender closure

Reliable Computing Stateful Software Interfaces Q f Q f P b P c a Send a over b (3) c a b Receiver closure

Reliable Computing Stateful Software Interfaces Type system  Based on linear treatment of endpoints  Tracking of obstructions  Enforcing selection strategy at receives  Status:  Still experimenting with expressiveness

Reliable Computing Stateful Software Interfaces Soundness  Preservation:  Every step in the configuration maintains obstruction invariant: every cycle is covered by an obstruction  Progress:  If all processes want to communicate, the endpoint selection strategy guarantees the existence of an enabled channel

Reliable Computing Stateful Software Interfaces Summary: deadlock prevention  Surprising result  a modular type system, reasoning only locally, guarantees global dead-lock freedom  Novelty:  not based on some locking order  network is dynamically changing  Network allowed to be cyclic (has to be)

Reliable Computing Stateful Software Interfaces Conclusion  World is stateful, need ways to deal with changing state  Type systems based on spatial logics can express many important rules  Resource management, type states, locking, etc.  Type systems advantage over first-order logics:  Higher-order  Abstraction over predicates  Methodology not after-the-fact analysis  Language provides a programming model for correct usage  Language makes failures explicit  Make programmers deal with failures  Guide programmer from the beginning  Programming languages based on such ideas  Under development in research community  Cyclone, Clay, Sing#, …

Reliable Computing Stateful Software Interfaces Open Research Questions  Sweet spot in domain of spatial logics  Expressive but amenable to automation  Combination with traditional theories (arithmetic)  Finding good abstractions for combining linear and non-linear data  Dealing with complicated, cross-module heap invariants  e.g. Subject-Observer pattern  abstraction gets in the way  Programming Language design

Reliable Computing Stateful Software Interfaces Backups

Reliable Computing Stateful Software Interfaces Clay (Chris Hawblitzel et.al.)  Explicit memory capabilities and Presburger arithmetic  Type Mem(i,  )  Explicit embedding of Mem in data, function args, return  Explicit proof terms  Coercion functions for proof terms  Case study: copying GC  (ATS by Xi is similar in style)

Reliable Computing Stateful Software Interfaces Cyclone (Morrisett, Jim, Grossman)  C replacement, very close to C  Regions, ref counted and unique pointers  Region lifetimes are stack like  Provides many useful lifetime constraints  Very nice syntax and defaults