Model Programs for Preserving Composite Invariants SAVCBS 2008 Challenge Problem Solution by Steve Shaner, Hridesh Rajan, Gary T. Leavens Iowa State and.

Slides:



Advertisements
Similar presentations
Modular Verification of Higher-Order Methods in JML Gary T. Leavens, Steve Shaner, and David A. Naumann Support from US NSF grant CCF
Advertisements

Chapter 13 Abstraction and inheritance. This chapter discusses n Implementing abstraction. u extension u inheritance n Polymorphism/dynamic binding. n.
Joint work with Mike Barnett, Robert DeLine, Manuel Fahndrich, and Wolfram Schulte Verifying invariants in object-oriented programs K. Rustan M. Leino.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
Writing specifications for object-oriented programs K. Rustan M. Leino Microsoft Research, Redmond, WA, USA 21 Jan 2005 Invited talk, AIOOL 2005 Paris,
Technologies for finding errors in object-oriented software K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 3 Summer school on Formal Models.
Challenges in increasing tool support for programming K. Rustan M. Leino Microsoft Research, Redmond, WA, USA 23 Sep 2004 ICTAC Guiyang, Guizhou, PRC joint.
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 8.
Addressing the Challenges of Current Software. Questions to Address Why? What? Where? How?
Hoare’s Correctness Triplets Dijkstra’s Predicate Transformers
The Java Modeling Language JML Erik Poll Digital Security Radboud University Nijmegen.
JMLAutoTest and Its Double- phase Testing Way Guoqing Xu Com Sci., East China Normal Univ. Shanghai , PRC FATES 2003, Montreal, Canada, Oct.6th 2003.
ISBN Chapter 3 Describing Syntax and Semantics.
Dept. of Computer Science A Runtime Assertion Checker for the Java Modeling Language (JML) Yoonsik Cheon and Gary T. Leavens SERP 2002, June 24-27, 2002.
March Ron McFadyen1 Composite Used to compose objects into tree structures to represent part-whole hierarchies Composite lets clients treat.
Lecture 2 Towards a Verifying Compiler: Logic of Object oriented Programs Wolfram Schulte Microsoft Research Formal Methods 2006 Objects, references, heaps,
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.
Static and Dynamic Contract Verifiers For Java Hongming Liu.
JML and Class Specifications Class invariant JML definitions Queue example Running JML in Eclipse.
On the Relationship Between Concurrent Separation Logic and Assume-Guarantee Reasoning Xinyu Feng Yale University Joint work with Rodrigo Ferreira and.
OOP #10: Correctness Fritz Henglein. Wrap-up: Types A type is a collection of objects with common behavior (operations and properties). (Abstract) types.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
Feb. 23, 2004CS WPI1 CS 509 Design of Software Systems Lecture #5 Monday, Feb. 23, 2004.
Chapter 1 Principles of Programming and Software Engineering.
Describing Syntax and Semantics
Introduction to Software Design Chapter 1. Chapter 1: Introduction to Software Design2 Chapter Objectives To become familiar with the software challenge.
CSCI-383 Object-Oriented Programming & Design Lecture 15.
Subclasses and Subtypes CMPS Subclasses and Subtypes A class is a subclass if it has been built using inheritance. ▫ It says nothing about the meaning.
Mathematics throughout the CS Curriculum Support by NSF #
A Formal Model of Modularity in Aspect-Oriented Programming Jonathan Aldrich : Objects and Aspects Carnegie Mellon University.
Computer Science School of Computing Clemson University Discrete Math and Reasoning about Software Correctness Murali Sitaraman
Software Engineering Prof. Dr. Bertrand Meyer March 2007 – June 2007 Chair of Software Engineering Static program checking and verification Slides: Based.
Introduction Ellen Walker CPSC 201 Data Structures Hiram College.
1 Abstraction  Identify important aspects and ignore the details  Permeates software development programming languages are abstractions built on hardware.
111 The Java Modeling Language Based on: Gary T. Leavens, et al., JML Tutorial at OOPSLA Gary. T Leavens, et al., Preliminary Design of JML: A Behavioral.
1 Total Correctness of Recursive Functions Using JML4 FSPV George Karabotsos, Patrice Chalin, Perry R. James, Leveda Giannas Dependable Software Research.
Low-Level Detailed Design SAD (Soft Arch Design) Mid-level Detailed Design Low-Level Detailed Design Design Finalization Design Document.
CS212: Object Oriented Analysis and Design Lecture 15: Inheritance in C++ -II.
Computer Science School of Computing Clemson University Discrete Math and Reasoning about Software Correctness Joseph E. Hollingsworth
Today’s Agenda  Quick Review  Continue on JML Formal Methods in Software Engineering1.
A Survey on Java Modeling Languages Gergely Kovásznai,Eszterházy Károly College Wolfgang Schreiner,Johannes Kepler University Gábor Kusper,Eszterházy Károly.
OOP: Encapsulation,Abstraction & Polymorphism. What is Encapsulation Described as a protective barrier that prevents the code and data being randomly.
A Universe-Type-Based Verification Technique for Mutable Static Fields and Methods Alexander J Summers Sophia Drossopoulou Imperial College London Peter.
Reasoning about programs March CSE 403, Winter 2011, Brun.
(c) University of Washington15-1 CSC 143 Java List Implementation via Arrays Reading: 13.
David Evans CS655: Programming Languages University of Virginia Computer Science Lecture 17: Inheritance & Behavioral.
Applying Translucid Contracts for Modular Reasoning about Aspect and Object Oriented Events Mehdi Bagherzadeh Gary T. Leavens Robert Dyer Foundations of.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
Design Patterns David Talby. This Lecture Re-routing method calls Chain of Responsibility Coding partial algorithms Template Method The Singleton Pattern.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
PROGRAMMING PRE- AND POSTCONDITIONS, INVARIANTS AND METHOD CONTRACTS B MODULE 2: SOFTWARE SYSTEMS 13 NOVEMBER 2013.
CSSE501 Object-Oriented Development. Chapter 10: Subclasses and Subtypes  In this chapter we will explore the relationships between the two concepts.
Defining Classes I Part B. Information hiding & encapsulation separate how to use the class from the implementation details separate how to use the class.
Faithful mapping of model classes to mathematical structures Ádám Darvas ETH Zürich Switzerland Peter Müller Microsoft Research Redmond, WA, USA SAVCBS.
DBC NOTES. Design By Contract l A contract carries mutual obligations and benefits. l The client should only call a routine when the routine’s pre-condition.
Object Design More Design Patterns Object Constraint Language Object Design Specifying Interfaces Review Exam 2 CEN 4010 Class 18 – 11/03.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
Zach Tatlock / Winter 2016 CSE 331 Software Design and Implementation Lecture 6 Representation Invariants.
CSCI 383 Object-Oriented Programming & Design Lecture 15 Martin van Bommel.
Extended Static Checking for Java
OOP: Encapsulation &Abstraction
Accessible Formal Methods A Study of the Java Modeling Language
Design by Contract Fall 2016 Version.
Programming Languages 2nd edition Tucker and Noonan
Hoare-style program verification
Java Modeling Language (JML)
The Zoo of Software Security Techniques
Programming Languages 2nd edition Tucker and Noonan
Programming Languages 2nd edition Tucker and Noonan
A Considerate Specification of the Composite Pattern
Presentation transcript:

Model Programs for Preserving Composite Invariants SAVCBS 2008 Challenge Problem Solution by Steve Shaner, Hridesh Rajan, Gary T. Leavens Iowa State and University of Central Florida Support from US NSF grants CNS and CNS

Summary Problem Specify and verify invariants for composite, which extend outside an object. Approach: JML model programsJML Grey-box [Büchi-Weck97,99] specification Verification modular by: Copy rule / substitution [Morgan88] Structurally-restricted refinement Contribution Exposes only code for maintaining invariant

Setting JML Pre- and postcondition specifications Several verification tools: ESC/Java2 Jack, LOOP, … Java Libraries: Swing I/O frameworks Jakarta Commons

Grey-Box (Ref. Calc.) Approach [Büchi–Weck97, 99] vs. lnr.actionPerformed() c.count++ Pre Post lnr.actionPerformed() c.count > 0 c.count == 0

Grey-Box Specifications in JML [Shaner-Leavens-Naumann07] lnr.actionPerformed() c.count > 0 c.count == 0 requires c.count == ensures c.count > lnr.actionPerformed(); Specification requires c.count == ensures c.count > { c.count++; } lnr.actionPerformed(); Code

Soundness of JML’s Approach [Shaner-Leavens-Naumann07] Structural Refinement: Exposed code appears exactly as shown Specification statements refined by refining statements Cannot call methods with exposed calls Behavioral Subtyping: Overriding methods must structurally refine

Composite Design Pattern Component parent total Composite components[] count addComponent(Component)

Sample Assertion to Prove Composite root = new Composite(); Composite child = new Composite(); Component comp = new Component(); assume root.total == 1 && child.total == 1; assume comp.total == 1; assume root.parent == null && child.parent == null; assume comp.parent == null; root.addComponent(child); child.addComponent(comp); assert root.total == 3;

Specification of Component class Component { protected spec_public Composite parent; protected int total = 1; protected invariant 1 <= total; }

Specification of Composite (Data and Invariant) class Composite extends Component { private Component[] components = new Component[5]; private int count = 0; protected total == 1 + (\sum int 0 <= i && i <

Composite’s Specification (addComponent) public model_program { normal_behavior requires c != this && c.parent == null; assignable this.components; ensures this.components.length > this.count; normal_behavior assignable c.parent, this.objectState; ensures c.parent == this; ensures this.hasComponent(c); this.addToTotal(c.total); public void addComponent(Component c)

private model_program { normal_behavior requires 0 <= p; assignable this.total; ensures this.total == \old(this.total) + p; Component aParent = this.parent; while (aParent != null) { normal_behavior assignable aParent.total, aParent; ensures aParent.total == \old(aParent.total) + p; ensures aParent == \old(aParent.parent); } private void addToTotal(int p) Composite’s Specification (addToTotal)

Verification Using Copy Rule [Morgan88] To verify method call: Substitute model program specification Replace formals with actuals Avoid capture Usual rules for other statements

Rule for Method Calls (Copy Rule + Substitution) Γ, x:T |- P && x instanceof T’ { x.m(z); } Q specFor(T’, m) = mp(S’), methType(T’, m) = y:U -> void, this:T’, z:U |- S’, T ≤ T’, S’ doesn’t assign to y, S = S’ [x,z/this,y], Γ, x:T’ |- P { S } Q

Verification of Sample Composite root = new Composite(); Composite child = new Composite(); Component comp = new Component(); assume root.total == 1 && child.total == 1; assume comp.total == 1; assume root.parent == null && child.parent == null; assume comp.parent == null; root.addComponent(child); child.addComponent(comp); assert root.total == 3;

Copy Rule Applied root.addComponent(child);  normal_behavior requires child != root && child.parent == null; assignable root.components; ensures root.components.length > root.count; normal_behavior assignable child.parent, root.objectState; ensures child.parent == root; ensures root.hasComponent(child); root.addToTotal(child.total);

Copy Rule Applied root.addToTotal(child.total);  { normal_behavior requires 0 <= child.total; assignable root.total; ensures root.total == \old(root.total) + child.total; Component aParent = root.parent; while (aParent != null) { normal_behavior assignable aParent.total, aParent; ensures aParent.total == \old(aParent.total) + child.total; ensures aParent == \old(aParent.parent); } }

Discussion Argument exposure in invariant: Exposed code shows how total is updated Precondition of addComponent ==> no cycles Special case of visibility technique Subtypes and overriding methods: Inherit model program specifications So implementations must refine Subtypes and new methods: Inherit invariant Must not make cycles (not specified!)

Conclusions Simple specification technique Exposing code needed for invariant Hiding rest of the code Simple verification technique Copy rule Limited depth of recursion can be handled

Questions? jmlspecs.org Thanks to David Naumann.

Other Solutions Hallstrom and Soundarajan: Requires calls to operation() like our calls to addToTotal() Can’t specify states in which calls made other specs like JML’s history constraints More sophisticated mathematics

Other Solutions Bierhoff and Aldrich: Abstraction of functional behavior Careful treatment of aliasing issues

Other Solutions Jacobs, Smans, Piessens: Doesn’t expose any code More mathematically sophisticated Specifies effects on parents using context Only treats binary trees