checking correctness properties of object-oriented programs k. rustan m. leino microsoft research,...

19
Checking correctness Checking correctness properties of object- properties of object- oriented programs oriented programs K. Rustan M. Leino K. Rustan M. Leino Microsoft Research, Redmond, WA Microsoft Research, Redmond, WA Lecture 1 EEF summer school on Specification, Refinement, and Verification 20 Aug 2002, Turku, Finland

Post on 19-Dec-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Checking correctness properties of object-oriented programs K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 1 EEF summer school on Specification,

Checking correctness Checking correctness properties of object-oriented properties of object-oriented

programsprograms

K. Rustan M. LeinoK. Rustan M. LeinoMicrosoft Research, Redmond, WAMicrosoft Research, Redmond, WA

Lecture 1EEF summer school on Specification, Refinement, and Verification20 Aug 2002, Turku, Finland

Page 2: Checking correctness properties of object-oriented programs K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 1 EEF summer school on Specification,

ExerciseExercise Implement a union-find class in Java Implement a union-find class in Java

and check it with ESC/Javaand check it with ESC/Java

class UnionFind {

// creates a union-find data structure with “size” elements,// each in a separate equivalence classpublic UnionFind(int size) { … }

// returns the representative for the equivalence class containing “c”

public int find(int c) { … }

// merges the equivalence classes containing elements “c” and “d”

public void union(int c, int d) { … }

}

Page 3: Checking correctness properties of object-oriented programs K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 1 EEF summer school on Specification,
Page 4: Checking correctness properties of object-oriented programs K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 1 EEF summer school on Specification,

CommandsCommands A command may:A command may:

terminate normallyterminate normally go wrong (crash the computer)go wrong (crash the computer) diverge (fail to terminate, infinite diverge (fail to terminate, infinite

recursion)recursion) block (fail to start, also called block (fail to start, also called

“miraculous termination”)“miraculous termination”)

Page 5: Checking correctness properties of object-oriented programs K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 1 EEF summer school on Specification,
Page 6: Checking correctness properties of object-oriented programs K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 1 EEF summer school on Specification,
Page 7: Checking correctness properties of object-oriented programs K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 1 EEF summer school on Specification,
Page 8: Checking correctness properties of object-oriented programs K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 1 EEF summer school on Specification,
Page 9: Checking correctness properties of object-oriented programs K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 1 EEF summer school on Specification,
Page 10: Checking correctness properties of object-oriented programs K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 1 EEF summer school on Specification,
Page 11: Checking correctness properties of object-oriented programs K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 1 EEF summer school on Specification,
Page 12: Checking correctness properties of object-oriented programs K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 1 EEF summer school on Specification,
Page 13: Checking correctness properties of object-oriented programs K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 1 EEF summer school on Specification,
Page 14: Checking correctness properties of object-oriented programs K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 1 EEF summer school on Specification,
Page 15: Checking correctness properties of object-oriented programs K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 1 EEF summer school on Specification,

ExerciseExercise Define specification statement where Define specification statement where

postcondition mentions x,x’ instead postcondition mentions x,x’ instead of xof x00,x,x

Example: x:[true, x<x’ ]Example: x:[true, x<x’ ]

Page 16: Checking correctness properties of object-oriented programs K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 1 EEF summer school on Specification,

ExerciseExercise DefineDefine

whilewhile { {invinv J J } } B B dodo w w : : SS endend

where where ww is the list of targets in is the list of targets in SS

in terms of the commands seen so in terms of the commands seen so far.far.

Page 17: Checking correctness properties of object-oriented programs K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 1 EEF summer school on Specification,

Answer:Answer:

Page 18: Checking correctness properties of object-oriented programs K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 1 EEF summer school on Specification,

ReferencesReferences Edsger W. Dijkstra. Edsger W. Dijkstra. A Discipline of ProgrammingA Discipline of Programming. Prentice . Prentice

Hall, 1976.Hall, 1976. Greg Nelson. “A Generalization of Dijkstra's Calculus”. Greg Nelson. “A Generalization of Dijkstra's Calculus”.

TOPLAS TOPLAS 11(4), pp. 517-561, ACM, 1989.11(4), pp. 517-561, ACM, 1989. Ralph-Johan Back and Joakim von Wright. Ralph-Johan Back and Joakim von Wright. Refinement Refinement

Calculus: A Systematic IntroductionCalculus: A Systematic Introduction. Graduate Texts in . Graduate Texts in Computer Science, Springer-Verlag, 1998.Computer Science, Springer-Verlag, 1998.

C.A.R. Hoare. “An axiomatic basis for computer C.A.R. Hoare. “An axiomatic basis for computer programming”. programming”. CACM CACM 12(10), pp. 576-580,583, Oct. 1969.12(10), pp. 576-580,583, Oct. 1969.

Carroll Morgan. “The specification statement”. Carroll Morgan. “The specification statement”. TOPLASTOPLAS 10(3), pp. 403-419, ACM, Jul. 1988.10(3), pp. 403-419, ACM, Jul. 1988.

John McCarthy and James Painter. “Correctness of a John McCarthy and James Painter. “Correctness of a compiler for arithmetic expressions”. In J.-T. Schwartz, ed., compiler for arithmetic expressions”. In J.-T. Schwartz, ed., Proceedings of Symposia in Applied MathematicsProceedings of Symposia in Applied Mathematics, American , American Mathematical Society, 1967.Mathematical Society, 1967.

Page 19: Checking correctness properties of object-oriented programs K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 1 EEF summer school on Specification,

ReferencesReferences O.-J. Dahl, E.W. Dijkstra, and C.A.R. Hoare. O.-J. Dahl, E.W. Dijkstra, and C.A.R. Hoare. Structured Structured

ProgrammingProgramming. Academic Press, 1972.. Academic Press, 1972. C.A.R. Hoare and Niklaus Wirth. “An axiomatic definition of C.A.R. Hoare and Niklaus Wirth. “An axiomatic definition of

the programming language PASCAL”. In the programming language PASCAL”. In Acta InformaticaActa Informatica 2, 2, Springer, 1973.Springer, 1973.

G. Birkhoff. G. Birkhoff. Lattice TheoryLattice Theory. Volume 25 of Colloquium . Volume 25 of Colloquium Publications 25. American Mathematical Society, 1967.Publications 25. American Mathematical Society, 1967.

David L. Parnas. “A Technique for Software Module David L. Parnas. “A Technique for Software Module Specification with Examples”. Specification with Examples”. CACM CACM 15(5), pp. 330-336, 15(5), pp. 330-336, ACM, May 1972.ACM, May 1972.

K. Rustan M. Leino, James B. Saxe, and Raymie Stata. K. Rustan M. Leino, James B. Saxe, and Raymie Stata. “Checking Java programs via guarded commands”. In Bart “Checking Java programs via guarded commands”. In Bart Jacobs, et al., eds., Jacobs, et al., eds., Formal Techniques for Java ProgramsFormal Techniques for Java Programs, , Technical Report 251, FernUniversitTechnical Report 251, FernUniversität Hagen, May 1999.ät Hagen, May 1999.