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 4 EEF summer school on Specification, Refinement, and Verification 23 Aug 2002, Turku, Finland
25
Embed
Checking correctness properties of object-oriented programs K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 4 EEF summer school on Specification,
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
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 4EEF summer school on Specification, Refinement, and Verification23 Aug 2002, Turku, Finland
Programming methodologyProgramming methodology Restricts programs by imposing a Restricts programs by imposing a
programming disciplineprogramming discipline Can simplify concepts involved in Can simplify concepts involved in
reasoning about programsreasoning about programs Not always a match for all good Not always a match for all good
programs, because:programs, because: the methodology may not be adequately the methodology may not be adequately
formalized, andformalized, and programming methodologies evolveprogramming methodologies evolve
Valid/state paradigmValid/state paradigmclass T {
abstract field valid: boolabstract field state: unit
constructor T(this, x, y, z)requires P(x,y,z) modifies this.valid, this.state ensures
constructor T(this, x, y, z)requires P(x,y,z) modifies this.state ensures true
method operation0(this, x, y, z)requires R0(x,y,z) modifies this.state ensures true
method operation1(this, x, y, z)requires R1(x,y,z) modifies this.state ensures true
…field f: int in statefield g: int in statefield h: int in state
invariant this.f < this.g
…}
Can state be “hidden”?Can state be “hidden”?
Summary: invariantsSummary: invariants simple conceptsimple concept tricky to get rules righttricky to get rules right language designers beware: design language designers beware: design
constructors carefully!constructors carefully! does not (alone) handle close does not (alone) handle close
methodsmethods requires more researchrequires more research
ConcurrencyConcurrency Multiple threads running in parallel, Multiple threads running in parallel,
reading and writing shared datareading and writing shared data Mutual exclusion provided by Mutual exclusion provided by
mutexes (locks)mutexes (locks)varvar mu: Mutex mu: Mutex……locklock mu mu dodo // acquire mu// acquire mu
A A race condition race condition occurs when a occurs when a shared variable is written by one shared variable is written by one thread and concurrently read or thread and concurrently read or written by another threadwritten by another thread
Avoid race conditionsAvoid race conditions Methodology: Every shared variable Methodology: Every shared variable
is protected by some declared mutexis protected by some declared mutex
varvar mu: Mutex mu: Mutexvarvar x x monitored_bymonitored_by mu mu
locklock mu mu dodo… x …… x …
endend
Concurrency: deadlocksConcurrency: deadlocks A A deadlockdeadlock occurs when a set of occurs when a set of
threads each waits for a mutex that threads each waits for a mutex that another thread holdsanother thread holds
K. Rustan M. Leino and Greg Nelson. K. Rustan M. Leino and Greg Nelson. Data abstraction and Data abstraction and information hidinginformation hiding. Research Report 160, Compaq SRC, Nov. . Research Report 160, Compaq SRC, Nov. 2000. To appear in 2000. To appear in TOPLASTOPLAS..
Bertrand Meyer. Bertrand Meyer. Object-oriented Software ConstructionObject-oriented Software Construction. . International Series in Computer Science, Prentice Hall, 1988.International Series in Computer Science, Prentice Hall, 1988.
K. Rustan M. Leino and Raymie Stata. K. Rustan M. Leino and Raymie Stata. Checking object Checking object invariantsinvariants. Technical Note 1997-007, DEC SRC, Jan. 1997.. Technical Note 1997-007, DEC SRC, Jan. 1997.
K. Rustan M. Leino, Greg Nelson, and James B. Saxe. K. Rustan M. Leino, Greg Nelson, and James B. Saxe. ESC/Java ESC/Java User’s ManualUser’s Manual. Technical Note 2000-002, Compaq SRC, Oct. . Technical Note 2000-002, Compaq SRC, Oct. 2000.2000.
Cormac Flanagan, K. Rustan M. Leino, Mark Lillibridge, Greg Cormac Flanagan, K. Rustan M. Leino, Mark Lillibridge, Greg Nelson, James B. Saxe, and Raymie Stata. “Extended static Nelson, James B. Saxe, and Raymie Stata. “Extended static checking for Java”. In checking for Java”. In PLDI ’02PLDI ’02, SIGPLAN Notices 37(5), pp. 234-, SIGPLAN Notices 37(5), pp. 234-245, ACM, May 2002.245, ACM, May 2002.
ReferencesReferences Gary T. Leavens, Albert L. Baker, and Clyde Ruby. Gary T. Leavens, Albert L. Baker, and Clyde Ruby.
Preliminary Design of JML: A Behavioral Interface Preliminary Design of JML: A Behavioral Interface Specification Language for JavaSpecification Language for Java. Department of Computer . Department of Computer Science, Iowa State University, TR #98-06r, Aug. 2002.Science, Iowa State University, TR #98-06r, Aug. 2002.
K. Rustan M. Leino. “A myth in the modular specification of K. Rustan M. Leino. “A myth in the modular specification of programs”. Unpublished manuscript KRML 63, DEC SRC, programs”. Unpublished manuscript KRML 63, DEC SRC, Nov. 1995. Available from author.Nov. 1995. Available from author.
C.A.R. Hoare. “Monitors: an operating system structuring C.A.R. Hoare. “Monitors: an operating system structuring concept”. concept”. CACMCACM 17(10), pp. 549-557, ACM, Oct. 1974. 17(10), pp. 549-557, ACM, Oct. 1974.