Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Outline
What is the Java Modeling Language? JML tutorial; JML tools;
ESC/JAVA;
10/27/2004
Outline
What is the Java Modeling Language? JML tutorial; JML tools;
ESC/JAVA;
10/27/2004
10/27/2004
Gary T. Leavens, Yoonsik Cheon. Design by Contract with JML, 2004 Erik Pool. Introduction to JML, 2004
10/27/2004 JML and ESC/Java 2 6
JML history
Created at Iowa University (Leavens, Cheon); Soon became an international effort:
University of Nijmegen (Poll, Van den Berg); HP (f.k.a. Compaq) SRC group (Leino, Nelson); Kodak (Cok);
10/27/2004 JML and ESC/Java 2 7
The caller must ensure precondition holds while the called must ensure postconditions on exit; The caller may assume postcondition while the called may assume preconditions;
Gary T. Leavens, Yoonsik Cheon. Design by Contract with JML, 2004
10/27/2004 JML and ESC/Java 2 8
Contracts as Documentation
For each method say:
What it requires (if anything), and What it ensures.
Contracts are:
More abstract than code, Often machine checkable, so can help with debugging, and Machine checkable contracts can always be up-to-date.
10/27/2004 JML and ESC/Java 2 10
10/27/2004
Abstraction by contracts
A contract can be satisfied in many ways:
a method can have many implementation satisfying the contract; Different performances (time, space, etc);
Modularity
Typical OO code is modular;
source.close(); dest.close(); getFile().setLastModified(loc.modTime().getTime());
A contract abstracts from the implementation details; Hence we can change implementations later.
10/27/2004 JML and ESC/Java 2 11
We should be able to take advantage of the code modularity even in specifying / prove code properties.
10/27/2004 JML and ESC/Java 2 12
Called code
By contrast, contracts:
Allow vendors to specify intent, Allow vendors freedom to change details, and Tell clients what they can count on.
13 10/27/2004 JML and ESC/Java 2 14
Outline
What is the Java Modeling Language? JML tutorial; JML tools;
ESC/JAVA;
Introduction to JML
JML specifications are contained in annotations, which are comments like:
//@ or /*@ @ @*/
At-signs (@) on the beginning of lines are ignored within annotations.
10/27/2004
15
10/27/2004
16
Informal Description
An informal description looks like:
(* some text describing a property *) It is treated as a boolean value by JML, and Allows
Escape from formality, and Organize English as contracts.
Formal Specifications
Formal assertions are written as Java expressions, but:
Cannot have side effects
No use of =, ++, --, etc., and Can only call pure methods.
Syntax \result a ==> b a <== b a <==> b a <=!=> b \old(E)
17 10/27/2004
public class Account { /*@ requires (* x is positive *); @ ensures \result >= 0 && @ (* \result is the updated balance after the deposit*) @*/ public static double deposit_into_account(double x) { } }
10/27/2004 JML and ESC/Java 2
10/27/2004
10/27/2004
20
Example (invariant)
// File: Account.java public class Account { private /*@ spec_public non_null @*/ String accountNumber; private /*@ spec_public @*/ double balance; //@ public invariant !accountNumber.equals() && balance >= 0; //@ ensures \result == balance; public double getBalance(); /*@ ensures balance >= 0 && balance == \old(balance + deposit); exsures (Exception e) x > DEPOSIT_LIMIT && balance == \old(balance) && e.getReason() == AMOUNT_TOO_BIG; @*/ public void deposit_into_account(int kgs); /*@ requires !n.equals(); ensures n.equals(accountNumber) && balance == 0; @*/ public Account(/*@ non_null @*/ String n); JML and ESC/Java 2 21 10/27/2004
Quantifiers
JML supports several forms of quantifiers
Universal and existential (\forall and \exists) General quantifiers (\sum, \product, \min, \max) Numeric quantifier (\num_of)
(\forall Student s; juniors.contains(s); s.getAdvisor() != null) (\forall Student s; juniors.contains(s) ==> s.getAdvisor() != null)
} 10/27/2004
22
Model Variables
Are specification only variables
Like domain-level constructs Given value only by represents clauses: Information hiding; Data abstraction;
name abstract (model)
Example
method Increment() modifies only n; ensures old(n) + 1 = n; method Decrement() modifies only n; ensures old(n) = n + 1; }
23 10/27/2004 JML and ESC/Java 2 24
represented by fullName
10/27/2004
concrete (real)
Example
class Counter { model n: int; private a: int; private b: int; representation n is a b; method Increment() modifies only n; ensures old(n) + 1 = n; { a := a + 1 } method Decrement() modifies only n; ensures old(n) = n + 1; { b := b + 1 }
JML and ESC/Java 2 25
Outline
What is the Java Modeling Language? Introduction to JML syntax and semantic; JML tools;
ESC/JAVA;
}
10/27/2004
ESC vision
Increased programmer productivity and program reliability through increased rigor:
Record design decisions; Utilize automatic checking; Detect errors and improve maintainability;
Etc
10/27/2004 JML and ESC/Java 2 27
ESC vision
Improve the current software engineering process developing practical tools; It is NOT program verification, it is like a type checker:
its warnings are intended to be interpreted by the author of the program; It does not find all the errors, but reduce the process cost finding some of them early; We are interested in failed proof only;
D. Detlefs, R. Leino, G.Nelson, J. Saxe. Extended Static Checking,1998.
10/27/2004 JML and ESC/Java 2 29
ESC vision
Take a program annotated with assertions. Consider a tool capable of: Automatically check if the assertions are always true; Statically without any user input; Reason about non-trivial properties (not just type-correctness);
J. Kiniri, ESC/Java 2, extended static checking for Java, 2004
10/27/2004 JML and ESC/Java 2 30
ESC
An Extended Static Checker tries to prove the correctness of specifications, at compile-time, fully automatically, but: ESC/Java is neither sound or complete but It find lots of bugs quickly;
J. Kiniri, ESC/Java 2, extended static checking for Java, 2004
10/27/2004 JML and ESC/Java 2 31
ESC implementation
ESC unsoundness
Sources of unsoundness: User-controlled:
Use of assume, no warn and axiom pragmas;
ESC/Java
Built at Compaq SRC
ESC/Java 2 built by Joe Kiniry (U. Nijmegen) and David Cok (Kodak)
Un-controlled:
Interdependent pragmas; Loops; Aliasing;
J. Kiniri, ESC/Java 2, extended static checking for Java, 2004
10/27/2004 JML and ESC/Java 2 33
Annotation language captures programmer design decisions Powered by program semantics and automatic theorem proving Performs modular checking
10/27/2004 JML and ESC/Java 2 34
Outline
What is the Java Modeling Language? JML tutorial; JML tools;
ESC/JAVA;
JML References
Papers:
Gary T. Leavens and Yoonsik Cheon. Design by Contract with JML, 2004; Lilian Burdy, Yoonsik Cheon, David Cok, Michael Ernst, Joe Kiniry, Gary T. Leavens, K. Rustan M. Leino, and Erik Poll. An overview of JML tools and applications, 2003; Gary T. Leavens, K. Rustan M. Leino, Erik Poll, Clyde Ruby, and Bart Jacobs. JML: notations and tools supporting detailed design in Java, 2000; Presentations:
People:
Gary Leavens @ Iowa university; Erik Pol @ University of Nijmegen;
Web-sites:
http://www.jmlspecs.org;
10/27/2004 JML and ESC/Java 2 35 10/27/2004 JML and ESC/Java 2 36
ESC/JAVA 2 references
Papers:
D. Detlefs, R. Leino, G. Nelson, J. Saxe. Extended Static Checking.1998. R. Leino, G. Nelson, J.Saxe. ESC/Java User's Manual. 2000
Outline
What is the Java Modeling Language? JML tutorial; JML tools;
ESC/JAVA;
People:
Rustan Leino @ University of Washington; David Cok @ Kodak; Joe Kiniri @ University of Nijmegen.
10/27/2004 JML and ESC/Java 2 37
10/27/2004
38