Inferring Object Invariants Bor-Yuh Evan ChangK. Rustan M. Leino University of California, BerkeleyMicrosoft Research January 21, 2005 AIOOL 2005 Paris,

Slides:



Advertisements
Similar presentations
Verification of object-oriented programs with invariants Mike Barnett, Robert DeLine, Manuel Fahndrich, K. Rustan M. Leino, Wolfram Schulte Formal techniques.
Advertisements

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.
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.
An Abstract Interpretation Framework for Refactoring P. Cousot, NYU, ENS, CNRS, INRIA R. Cousot, ENS, CNRS, INRIA F. Logozzo, M. Barnett, Microsoft Research.
Comp 212: Intermediate Programming Lecture 18 – Java Generics By: Anupam Chanda.
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 11.
Abstract Interpretation with Alien Expressions and Heap Structures Bor-Yuh Evan ChangK. Rustan M. Leino University of California, BerkeleyMicrosoft Research.
Program Analysis as Constraint Solving Sumit Gulwani (MSR Redmond) Ramarathnam Venkatesan (MSR Redmond) Saurabh Srivastava (Univ. of Maryland) TexPoint.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 1 Abstract Classes and Interfaces.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Immutable Objects and Classes.
Lecture 2 Towards a Verifying Compiler: Logic of Object oriented Programs Wolfram Schulte Microsoft Research Formal Methods 2006 Objects, references, heaps,
Aliases in a bug finding tool Benjamin Chelf Seth Hallem June 5 th, 2002.
Abstract Interpretation with Alien Expressions and Heap Structures Bor-Yuh Evan ChangK. Rustan M. Leino UC BerkeleyMicrosoft Research November 11, 2004.
Building a program verifier K. Rustan M. Leino Microsoft Research, Redmond, WA 10 May 2006 Guest lecture, Shaz Qadeer’s cse599f, Formal Verification of.
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 1 Behavioral Refinement Principles of Object-Oriented Software Development.
CSE 331 Software Design & Implementation Dan Grossman Fall 2014 Data Abstraction: Abstract Data Types (ADTs) (Based on slides by Mike Ernst, David Notkin,
Computer Science 340 Software Design & Testing Design By Contract.
Abstract classes and Interfaces. Abstract classes.
Inheritance using Java
Internet Software Development Classes and Inheritance Paul J Krause.
1 Abstraction  Identify important aspects and ignore the details  Permeates software development programming languages are abstractions built on hardware.
Cs205: engineering software university of virginia fall 2006 Data Abstraction David Evans
Program Analysis and Verification Spring 2015 Program Analysis and Verification Lecture 14: Numerical Abstractions Roman Manevich Ben-Gurion University.
Computer Science and Engineering College of Engineering The Ohio State University Interfaces The credit for these slides goes to Professor Paul Sivilotti.
ICS 201 Introduction to Computer Science Problem Solving #4.
Object-Oriented Programming (OOP). Implementing an OOD in Java Each class is stored in a separate file. All files must be stored in the same package.
Program Analysis and Verification Spring 2014 Program Analysis and Verification Lecture 14: Numerical Abstractions Roman Manevich Ben-Gurion University.
Type Systems CS Definitions Program analysis Discovering facts about programs. Dynamic analysis Program analysis by using program executions.
Verification of Programs with Inspector Methods Bart Jacobs and Frank Piessens Dept. CS, K.U.Leuven, Belgium.
A Universe-Type-Based Verification Technique for Mutable Static Fields and Methods Alexander J Summers Sophia Drossopoulou Imperial College London Peter.
Aspect-Oriented Programming and Modular Reasoning G. KiczalesM. Mezini Presented by Alex Berendeyev.
Mark Marron IMDEA-Software (Madrid, Spain) 1.
Formal verification of skiplist algorithms Student: Trinh Cong Quy Supervisor: Bengt Jonsson Reviewer: Parosh Abdulla.
Chapter 14 Abstract Classes and Interfaces. Abstract Classes An abstract class extracts common features and functionality of a family of objects An abstract.
11th Nov 2004PLDI Region Inference for an Object-Oriented Language Wei Ngan Chin 1,2 Joint work with Florin Craciun 1, Shengchao Qin 1,2, Martin.
K. Rustan M. Leino and Wolfram Schulte Microsoft Research, Redmond ESOP 2007 Braga, Portugal 28 March 2007.
Testing OO software. State Based Testing State machine: implementation-independent specification (model) of the dynamic behaviour of the system State:
Difficult Specifications in Javari Immutability Inference Jaime Quinonez Program Analysis Group April 20, 2007.
Interfaces An interface is like an extreme case of an abstract class – However, an interface is not a class – It is a type that can be satisfied by any.
SWE 4743 Abstract Data Types Richard Gesick. SWE Abstract Data Types Object-oriented design is based on the theory of abstract data types Domain.
Understanding ADTs CSE 331 University of Washington.
COM S 228 Introduction to Data Structures Instructor: Ying Cai Department of Computer Science Iowa State University Office: Atanasoff.
PROGRAMMING TESTING B MODULE 2: SOFTWARE SYSTEMS 22 NOVEMBER 2013.
CSSE501 Object-Oriented Development. Chapter 10: Subclasses and Subtypes  In this chapter we will explore the relationships between the two concepts.
Object Modeling THETOPPERSWAY.COM. Object Modelling Technique(OMT)  Building a model of an application domain and then adding implementation.
/ PSWLAB Thread Modular Model Checking by Cormac Flanagan and Shaz Qadeer (published in Spin’03) Hong,Shin Thread Modular Model.
ReIm & ReImInfer: Checking and Inference of Reference Immutability and Method Purity Wei Huang 1, Ana Milanova 1, Werner Dietl 2, Michael D. Ernst 2 1.
1 Verification of object-oriented programs with invariants Mike Barnett, Robert DeLine, Manuel Fahndrich, K. Rustan M. Leino, Wolfram Schulte ECOOP 2003.
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
(c) University of Washington05-1 CSC 143 Java Abstract Classes and Frameworks Reading: Ch. 11.
David Evans CS201J: Engineering Software University of Virginia Computer Science Lecture 5: Implementing Data Abstractions.
Object Invariants in Dynamic Contexts K.R.M. Leino and P. Muller : Objects and Aspects Presented by Jonathan Aldrich.
Abstraction and Abstract Interpretation. Abstraction (a simplified view) Abstraction is an effective tool in verification Given a transition system, we.
Lecture 6:Interfaces and Abstract Classes Michael Hsu CSULA.
A Static Analyzer for Large Safety-­Critical Software Presented by Dario Bösch, ETH Zürich Research Topics in Software Engineering Dario.
Spring 2016 Program Analysis and Verification
Class-local object invariants
COP 3331 Object Oriented Analysis and Design Chapter 5 – Classes and Inheritance Jean Muhammad.
Software Engineering Fall 2005
Overloading and Constructors
Interface.
Conditional Statements
Classes & Objects: Examples
Hoare-style program verification
Data Abstraction David Evans cs205: engineering software
Chapter 14 Abstract Classes and Interfaces
Chapter 13 Abstract Classes and Interfaces Part 01
Overloading Each method has a signature: its name together with the number and types of its parameters Methods Signatures String toString()
Presentation transcript:

Inferring Object Invariants Bor-Yuh Evan ChangK. Rustan M. Leino University of California, BerkeleyMicrosoft Research January 21, 2005 AIOOL 2005 Paris, France

2 1/21/2005Chang and Leino: Inferring Object Invariants What to Infer? class A { int x; A() { this.x := 8; } void M() { this.x := this.x + 1; } int N(int y) { return y / this.x; } invariant this.x ¸ 8 } Treat “this.x” as one variable Used to show divide by zero impossible

3 1/21/2005Chang and Leino: Inferring Object Invariants Too Naïve class B { int x; B() { this.x := 8; } void M(B b) { this.x := b.x + 1; } invariant this.x ¸ 8; } Treat “this.x” as one variable this.x == ? Too Imprecise

4 1/21/2005Chang and Leino: Inferring Object Invariants Too Naïve class C { int x; C() { this.x := 8; } void M(C c) { c.x := 7; } invariant this.x == 8; } Treat “this.x” as one variable this.x == 8 Unsound

5 1/21/2005Chang and Leino: Inferring Object Invariants Methodology distinguishes between “valid” and “mutable” objects UnpackpackUnpack/pack block where the object invariant may be temporarily violated unpackfrom unpack o from T … packas pack o as T Object invariant may be violated Fields may be modified Object invariant holds cannotFields cannot be modified Object Invariant Methodology

6 1/21/2005Chang and Leino: Inferring Object Invariants Outline Overview Obtaining Object Invariants –Abstract State –Abstract Transition for Unpack/Pack Example Concluding Remarks

7 1/21/2005Chang and Leino: Inferring Object Invariants Overview of Contributions To extend standard reasoning to fields –use parameterized abstract interpretation framework [VMCAI 2005] To simultaneously track an unbounded number of objects –treat “valid” objects collectively following object invariant methodology [JOT 2004] To capture interaction between multiple object invariants –separate analysis into flow-sensitive and flow- insensitive parts –interaction given by object invariant methodology

8 1/21/2005Chang and Leino: Inferring Object Invariants Abstract State policy domainKind of invariants obtained given by policy domain P –e.g., linear arithmetic if P is Polyhedra Standard local flow-sensitive abstract interpretation using C ( P, S ) –policy domain extended to work with fields Global flow-insensitive part captured by I –mappings of the form T  C ( P ) e.g., B  sel(H,t,x) ¸ 8, which concretizes to ( 8 t:B ² ( 8 H ² sel(H,t,x) ¸ 8))

9 1/21/2005Chang and Leino: Inferring Object Invariants Abstract Transition Write the abstract transition for a statement s –one C per program point –one global I packunpackAll statements except pack/unpack affect only the local state C field updates –including field updates because methodology says that only “mutable” objects can be modified

10 1/21/2005Chang and Leino: Inferring Object Invariants Abstract Transition: Pack packIncorporate the information obtained from the local analysis on pack – note – note: does not depend on class context Extract constraints that involve fields of o that are declared in T or a superclass of T Rename o to t and widen into the current object invariant for T

11 1/21/2005Chang and Leino: Inferring Object Invariants Abstract Transition: Unpack unpackInstantiate current object invariant on unpack – methodology says that the object satisfies the object invariant right before the unpack – note – note: does not depend on class context Also instantiate object invariant for, say, “valid” method arguments

12 1/21/2005Chang and Leino: Inferring Object Invariants Outline Overview Obtaining Object Invariants –Abstract State –Abstract Transition for Unpack/Pack Example Concluding Remarks

13 1/21/2005Chang and Leino: Inferring Object Invariants Example class D extends B { int y; D() { this.y := 1; pack this as D; } } class B { int x; B() { this.x := 8; pack this as B; } void M(D d) { unpack this from B; this.x := d.x + d.y; pack this as B; } > I:I: D , B  ??

14 1/21/2005Chang and Leino: Inferring Object Invariants Example class D extends B { int y; D() { this.y := 1; pack this as D; } } class B { int x; B() { this.x := 8; pack this as B; } void M(D d) { unpack this from B; this.x := d.x + d.y; pack this as B; } I:I: D , B  ?? sel(H,this,y) = 1

15 1/21/2005Chang and Leino: Inferring Object Invariants Example class D extends B { int y; D() { this.y := 1; pack this as D; } } class B { int x; B() { this.x := 8; pack this as B; } void M(D d) { unpack this from B; this.x := d.x + d.y; pack this as B; } I:I: D , B  ? sel(H,this,y) = 1 sel(H,t,y) = 1

16 1/21/2005Chang and Leino: Inferring Object Invariants Example class D extends B { int y; D() { this.y := 1; pack this as D; } } class B { int x; B() { this.x := 8; pack this as B; } void M(D d) { unpack this from B; this.x := d.x + d.y; pack this as B; } I:I: D , B  sel(H,this,y) = 1 sel(H,t,y) = 1 sel(H,this,x) = 8 sel(H,t,x) = 8

17 1/21/2005Chang and Leino: Inferring Object Invariants Example class D extends B { int y; D() { this.y := 1; pack this as D; } } class B { int x; B() { this.x := 8; pack this as B; } void M(D d) { unpack this from B; this.x := d.x + d.y; pack this as B; } I:I: D , B  sel(H,this,y) = 1 sel(H,t,y) = 1 sel(H,this,x) = 8 sel(H,t,x) = 8 Assume d is valid sel(H,d,y) = 1 Æ sel(H,d,x) = 8

18 1/21/2005Chang and Leino: Inferring Object Invariants Example class D extends B { int y; D() { this.y := 1; pack this as D; } } class B { int x; B() { this.x := 8; pack this as B; } void M(D d) { unpack this from B; this.x := d.x + d.y; pack this as B; } I:I: D , B  sel(H,this,y) = 1 sel(H,t,y) = 1 sel(H,this,x) = 8 sel(H,t,x) = 8 sel(H,d,y) = 1 Æ sel(H,d,x) = 8 sel(H,d,y)=1 Æ sel(H,d,x)=8 Æ sel(H,this,x)=8

19 1/21/2005Chang and Leino: Inferring Object Invariants Example class D extends B { int y; D() { this.y := 1; pack this as D; } } class B { int x; B() { this.x := 8; pack this as B; } void M(D d) { unpack this from B; this.x := d.x + d.y; pack this as B; } sel(H,this,y) = 1 I:I: D , B  sel(H,t,y) = 1 sel(H,t,x) = 8 sel(H,this,x) = 8 sel(H,d,y) = 1 Æ sel(H,d,x) = 8 sel(H,d,y)=1 Æ sel(H,d,x)=8 Æ sel(H,this,x)=8 sel(H,this,x) = 9

20 1/21/2005Chang and Leino: Inferring Object Invariants Example class D extends B { int y; D() { this.y := 1; pack this as D; } } class B { int x; B() { this.x := 8; pack this as B; } void M(D d) { unpack this from B; this.x := d.x + d.y; pack this as B; } sel(H,this,y) = 1 I:I: D , B  sel(H,t,y) = 1 sel(H,t,x) ¸ 8 sel(H,this,x) = 8 sel(H,d,y) = 1 Æ sel(H,d,x) = 8 sel(H,d,y)=1 Æ sel(H,d,x)=8 Æ sel(H,this,x)=8 sel(H,this,x) = 9 Re-examine where previous object invariant for B was instantiated

21 1/21/2005Chang and Leino: Inferring Object Invariants Example: Remarks Weakening of object invariant must be with widening (like for loops) Needed the object invariant of D to obtained the desired object invariant for B unpackpackIncorporating information into object invariant determined by unpack/pack, not class context

22 1/21/2005Chang and Leino: Inferring Object Invariants Conclusion and Future Work Designed a technique to infer more precise object invariants –based on distinguishing “valid” and “mutable” objects –for class-based object-oriented langauges works with inheritance can obtain invariants on fields of a field using a notion of ownership (see paper) Combined with a methodology (strengthening both) Fits nicely in an abstract interpretation framework (e.g., Logozzo) Future Work: implementation and experiments

Thank you! Questions? Comments?