Wishnu Prasetya
wishnu@cs.uu.nl www.cs.uu.nl/docs/vakken/pv
ESC/Java Approach Wishnu Prasetya wishnu@cs.uu.nl - - PowerPoint PPT Presentation
ESC/Java Approach Wishnu Prasetya wishnu@cs.uu.nl www.cs.uu.nl/docs/vakken/pv ESC/Java Extended Static Checker for Java an implementation of Hoare Logic. Semi-automatic theorem prover back-end. It is not intended to verify
wishnu@cs.uu.nl www.cs.uu.nl/docs/vakken/pv
2
3
1: class Bag { 2: int[] a; 3: int n; 4: 5: Bag (int[] input) { 6: n = input.length; 7: a = new int[n]; 8: System.arraycopy(input, 0, a, 0, n); 9: } 10: 11: int extractMin() { 12: int m = Integer.MAX_VALUE; 13: int mindex = 0; 14: for (int i = 1; i <= n; i++) { 15: if (a[i] < m) { 16: mindex = i; 17: m = a[i]; 18: } 19: } 20: n--; 21: a[mindex] = a[n]; 22: return m; 23: } 24: }
/* @ non_null */ //@ requires n 1 // @ invariant 0 n & n a.length
Still persist despite the inv. real bug
4
(WP/SP-alg)
Implementing the Hoare logic to work directly on Java is complex and error prone; but in theory you’ll get better error messages. ESC/Java first render Java to a much simpler
logic operates on GCL.
5 In principle this core is reusable. Alternatively, you can use the Boogie core.
cmd
expr : formula or term from untyped first-order pred.
Also of the form Label x e to tag e with feedback
Data type : bool, int, infinite arrays 6
7
8
9
10
11
12
This would require that v is not null.
13
14
15
16
17
18
(assuming fresh x’… else you need to apply subst on Q to protect refrence to x’ there, then reverse the substituton again as you are exiting the block)
19
20
Undecidable problem. There are heuristics, for example replacing lower/upper
Note: ESC/Java does not have a while construct. Instead it
21
{ ? } while g inv I do S { Q } Full verification : Take I as the wlp of the loop Additionally generate two verification conditions (VCs) of the loop-rule:
Rather than explicitly generating VCs we can also encode the verifcation
22
23
24
25
{ ? } if g then { S ; if g then { S ; if g then assume false }} { Q }
26
27
28
29
Note that Java’s array should be treated as an object, and is not translated directly to native GCL array.
30
31
But... u gets a new object; so for any expression v which is not
32