Java Modeling Language (JML)

Slides:



Advertisements
Similar presentations
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
Advertisements

Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Copyright W. Howden1 Programming by Contract CSE 111 6/4/2014.
Design By Contract Using JMSAssert.
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 6 Disclaimer. These notes are derived from notes originally.
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 8.
272: Software Engineering Fall 2012
Semantics Static semantics Dynamic semantics attribute grammars
ICE1341 Programming Languages Spring 2005 Lecture #6 Lecture #6 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
Verifying Executable Object-Oriented Specifications with Separation Logic Stephan van Staden, Cristiano Calcagno, Bertrand Meyer.
The Java Modeling Language JML Erik Poll Digital Security Radboud University Nijmegen.
Politecnico di Milano Advanced Topics in Software Engineering JML in a Nutshell Domenico Bianculli & Alessandro Monguzzi {bianculli,
JML and ESC/Java2: An Introduction Karl Meinke School of Computer Science and Communication, KTH.
Securing Java applets Erik Poll Security of Systems (SOS) group University of Nijmegen
272: Software Engineering Fall 2008 Instructor: Tevfik Bultan Lecture 3: Java Modeling Language and Extended Static Checking.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Axiomatic Semantics.
ISBN Chapter 3 Describing Syntax and Semantics.
Fall Semantics Juan Carlos Guzmán CS 3123 Programming Languages Concepts Southern Polytechnic State University.
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.
1 Design by Contract with JML CS 3331 Fall 2009 Gary T. Leavens and Yoonsik Cheon. Design by Contract with JML. Available from
Formal Methods of Systems Specification Logical Specification of Hard- and Software Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
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.
ESC Java. Static Analysis Spectrum Power Cost Type checking Data-flow analysis Model checking Program verification AutomatedManual ESC.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
JML and Class Specifications Class invariant JML definitions Queue example Running JML in Eclipse.
CS 330 Programming Languages 09 / 18 / 2007 Instructor: Michael Eckmann.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
Software Quality: Testing and Verification II. 2 1.A failure is an unacceptable behaviour exhibited by a system — The frequency of failures measures software.
CS 330 Programming Languages 09 / 16 / 2008 Instructor: Michael Eckmann.
Describing Syntax and Semantics
Ranga Rodrigo. Class is central to object oriented programming.
1 Abstraction  Identify important aspects and ignore the details  Permeates software development programming languages are abstractions built on hardware.
Analyzing the Requirements with Formal Specifications Vienna Development Method Specification Language (VDM-SL) Book: Formal Software Development From.
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.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Design by Contract in Java Concept and Comparison.
Chapter 25 Formal Methods Formal methods Specify program using math Develop program using math Prove program matches specification using.
Extended Static Checking for Java  ESC/Java finds common errors in Java programs: null dereferences, array index bounds errors, type cast errors, race.
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.
Chapter 5: Sequences, Mathematical Induction, and Recursion 5.5 Application: Correctness of Algorithms 1 [P]rogramming reliability – must be an activity.
Chapter 3 Part II Describing Syntax and Semantics.
Semantics In Text: Chapter 3.
Pre- and postconditions, Using assertions and exceptions 1 Pre- and postconditions Using assertions and exceptions.
Spec# Andreas Vida. Motivation Correct and maintainable software Correct and maintainable software Cost effective software production Cost effective software.
 Asserting Expectations. Introduction -Observation alone is not enough for debugging as it can be a burden for a programmer. -One must compare observed.
Verificare şi Validarea Sistemelor Soft Tem ă Laborator 1 ESC/Java2 Extended Static Checker for Java Dat ă primire laborator: Lab 1 Dat ă predare laborator:
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Principle of Programming Lanugages 3: Compilation of statements Statements in C Assertion Hoare logic Department of Information Science and Engineering.
1 Assertions. 2 A boolean expression or predicate that evaluates to true or false in every state In a program they express constraints on the state that.
PROGRAMMING PRE- AND POSTCONDITIONS, INVARIANTS AND METHOD CONTRACTS B MODULE 2: SOFTWARE SYSTEMS 13 NOVEMBER 2013.
Institute for Applied Information Processing and Communications (IAIK) – Secure & Correct Systems 1 Static Checking  note for.
CSSE501 Object-Oriented Development. Chapter 10: Subclasses and Subtypes  In this chapter we will explore the relationships between the two concepts.
Faithful mapping of model classes to mathematical structures Ádám Darvas ETH Zürich Switzerland Peter Müller Microsoft Research Redmond, WA, USA SAVCBS.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
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.
Winter 2006CISC121 - Prof. McLeod1 Stuff Midterm exam in JEF234 on March 9th from 7- 9pm.
Accessible Formal Methods A Study of the Java Modeling Language
Java Programming Language
MSIS 655 Advanced Business Applications Programming
Programming Languages 2nd edition Tucker and Noonan
Hoare-style program verification
Semantics In Text: Chapter 3.
Assertions References: internet notes; Bertrand Meyer, Object-Oriented Software Construction; 4/25/2019.
Chap 2. Identifiers, Keywords, and Types
Programming Languages 2nd edition Tucker and Noonan
Programming Languages 2nd edition Tucker and Noonan
COP4020 Programming Languages
Presentation transcript:

Java Modeling Language (JML) JML is a behavioral interface specification language JML is a specification language that allows specification of the behavior of an API not just its syntax, but its semantics JML specifications are written as annotations As far as Java compiler is concerned they are comments but a JML compiler can interpret them

JML One goal of JML is to make writing specifications easily understandable and usable by Java programmers, so it stays close to the Java syntax and semantics whenever possible JML supports design by contract style specifications with Pre-conditions Post-conditions (Class) invariants

JMLAnnotations JML annotations are added as comments to the Java source code either between /*@ . . . @*/ or after //@ These are annotations and they are ignored by the Java compiler JML properties are specified as Java boolean expressions JML provides operators to support design by contract style specifications such as \old and \result JML also provides quantification operators (\forall, \exists) JML also has additional keywords such as requires, ensures, signals, assignable, pure, invariant, non null, . . .

JML contracts Preconditions are written as a requires clauses Postconditions are written as ensures clauses Invariants are written as invariant clauses

JML assertions JML assertions are written as Java expressions, but: Cannot have side effects No use of =, ++, --, etc., and Can only call pure methods (i.e., methods with no side effects) JML extensions to Java expression syntax: Syntax Meaning \result the return value for the method call \old(E) value of E just before the method call a ==> b a implies b a <== b b implies a a <==> b a if and only if b a <=!=> b !(a <==> b)

JML 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; class272.contains(s); s.getProject() != null) (\forall Student s; class272.contains(s) ==> s.getProject() != null) Without quantifiers, we would need to write loops to specify these types of constraints

JML Quantifiers (cont) Quantifier expressions Start with a declaration that is local to the quantifier expression (\forall Student s; ... Followed by an optional range predicate ... class272.contains(s); ... Followed by the body of the quantifier ... s.getProject() != null)

JML quantifiers (cont) \sum, \product, \min, \max return the sum, product, min and max of the values of their body expression when the quantified variables satisfy the given range expression For example, (\sum int x; 1 <= x && x <= 5; x) denotes the sum of values between 1 and 5 inclusive The numerical quantifier, \num_of, returns the number of values for quantified variables for which the range and the body predicate are true

JML Example: Purse public class Purse { final int MAX_BALANCE; int balance; //@ invariant 0 <= balance && balance <= MAX_BALANCE; byte[] pin; /*@ invariant pin != null && pin.length == 4 @ && (\forall int i; 0 <= i && i < 4; @ 0 <= pin[i] && pin[i] <= 9); @*/ . . . }

JML Example: Purse, Cont’d /*@ requires amount >= 0; @ assignable balance; @ ensures balance == \old(balance) - amount @ && \result == balance; @ signals (PurseException) balance == \old(balance); @*/ int debit(int amount) throws PurseException { if (amount <= balance) { balance -= amount; return balance; } else { throw new PurseException("overdrawn by " + amount); } } The assignable clause indicates that balance is the only field that will be assigned This type of information is very useful for analysis and verification tools The default assignable clause is: assignable \everything

JML post conditions The keyword \old can be used to refer to the value of a field just before the execution of the method The keyword \result can be used to refer to the return value of the method Both of these keywords are necessary and useful tools for specifying post conditions

JML Example: Purse, Cont’d /*@ requires p != null && p.length >= 4; @ assignable \nothing; @ ensures \result <==> (\forall int i; 0 <= i && i < 4; @ pin[i] == p[i]); @*/ boolean checkPin(byte[] p) { boolean res = true; for (int i=0; i < 4; i++) { res = res && pin[i] == p[i]; } return res;

JML Example: Purse, Cont’d /*@ requires 0 < mb && 0 <= b && b <= mb @ && p != null && p.length == 4 @ && (\forall int i; 0 <= i && i < 4; @ 0 <= p[i] && p[i] <= 9); @ assignable MAX_BALANCE, balance, pin; @ ensures MAX_BALANCE == mb && balance == b @ && (\forall int i; 0 <= i && i < 4; p[i] == pin[i]); @*/ Purse(int mb, int b, byte[] p) { MAX_BALANCE = mb; balance = b; pin = (byte[]) p.clone(); }

JML Libraries JML has an extensive library that supports concepts such as sets, sequences, and relations. These can be used in JML assertions directly without needing to re-specify these mathematical concepts

Assert clauses The requires clauses are used to specify conditions that should hold just before a method execution, i.e., preconditions The ensures clauses are used to specify conditions that should hold just after a method execution, i.e., postconditions An assert clause can be used to specify a condition that should hold at some point in the code (rather than just before or right after a method execution) if (i <= 0 || j < 0) { ... } else if (j < 5) { //@ assert i > 0 && 0 < j && j < 5; } else { //@ assert i > 0 && j > 5; }

Assert in JML Although assert is also a part of Java language now, assert in JML is more expressive for (n = 0; n < a.length; n++) if (a[n]==null) break; /*@ assert (\forall int i; 0 <= i && i < n; @ a[i] != null); @*/

JML Tools tools for parsing and typechecking Java programs and their JML annotations JML compiler (jmlc) tools for supporting documentation with JML HTML generator (jmldoc) tools for runtime assertion checking: Test for violations of assertions (pre, postconditions, invariants) during execution Tool: jmlrac testing tools based on JML JML/JUnit unit test tool: jmlunit Extended static checking: Automatically prove that contracts are never violated at any execution Automatic verification is done statically (i.e., at compile time). Tool: ESC/Java