temporal logic in JavaMOP
CS 119
includes slides by Grigore Rosu
temporal logic in JavaMOP includes slides CS 119 by Grigore Rosu - - PowerPoint PPT Presentation
temporal logic in JavaMOP includes slides CS 119 by Grigore Rosu propositional logic extended with temporal operators referring to past and future 2 past time properties If A happens now B must have happened (A ! B) B A now
includes slides by Grigore Rosu
2
3
now
past past future future
4
now
past past future future
5 ERE LTL ptLTL ptCaRet logic plugins
JavaMOP BusMOP
CFG languages
today
6
7
8
http://en.wikipedia.org/wiki/Chomsky_hierarchy
9
p is even in every other state even /\ always(even implies (next next even))
does not work
even true
1 2
10
12
13
datarace deadlock temporal
paxm odules m odule datarace = ‘ java pax.Datarace’ ; m odule deadlock = ‘ java pax.Deadlock’ ; m odule tem poral = ‘ java pax.Tem poral spec’ ; end
Event stream
warning
…
warning
…
warning
…
15
Java Virtual Machine
instrumented bytecode
green yellow red g reen …
class Light{ void goRed(){ color = 1; } …
predicate red = (Light.color == 1); predicate yellow = (Light.color == 2); predicate green = (Light.color == 3); Instrumentation Script property p = [](green -> !red U yellow); Specification
16
_{_} : Formula x Event -> Formula (“consume” event e) F{e} formula that should hold after processing e
(F op F’){e} F{e} op F’{e}
17
(green → ¬red U yellow)
{red}
(green → ¬red U yellow){red} ∧ (green → ¬red U yellow) (green{red} → (yellow{red} ∨ ¬red{red} ∧ ¬red U yellow)) ∧ …
(false → (false ∨ false ∧ ¬red U yellow)) ∧ …
true ∧ (green → ¬red U yellow)
(green → ¬red U yellow)
{yellow}
(green → ¬red U yellow)
{green}
((¬red U yellow) ∧ (green → ¬red U yellow)){yellow}
(green → ¬red U yellow) {green}
((¬red U yellow) ∧ (green → ¬red U yellow)){red} (yellow{red} ∨ ¬red{red} ∧ ¬red U yellow) ∧ …
false ∧ …
false
18
5
t-δ t
19
20
21
22
Formula (green → ¬red U yellow) State 1 2 BTT yellow ? 1 : green ? (red ? false : 2) : 1 yellow ? 1 : (red ? false : 2) yellow green red 1 1 false 2
Y Y Y N N N
yellow red 1 false 2
Y Y N N
24
where (MAC)
25
– F = (F →¬↑F) ∧ (¬F → ↓F), [F,F’) = (¬F’) S F, ↑F = F ∧ ¬F
↑F ↓F
x x
[↓F,F’)
26
27
http://en.wikipedia.org/wiki/Dynamic_programming
28
1 2 3 4 5 6
Landing Approved Radio
for i=1..n {process(ei) m[6,i] = holds(Radio) m[5,i] = m[6,i-1] and not m[6,i] m[4,i] = holds(Approved) m[3,i] = holds(Landing) m[2,i] = not m[5,i] and (m[4,i] or m[2,i-1]) m[1,i] = m[3,i] and not m[3,i-1] m[0,i] = not m[1,i] or m[2,i] if m[0,i] == 0 then “Error” }
for i=1..n {process(ei) now[6] = holds(Radio) now[5] = prev[6] and not now[6] now[4] = holds(Approved) now[3] = holds(Landing) now[2] = not now[5] and (now[4] or prev[2]) now[1] = now[3] and not prev[3] now[0] = not now[1] or now[2] if now[0] == 0 then “Error” prev = now }
t1 = holds(Radio) t2 = holds(Landing) t3 = (not b1 or t1) and (holds(Approved) or b3) if (t2 and not (b2 or t3)) then “error” (b1,b2,b3) = (t1,t2,t3)
b1 b2 b3
30
– Often easier to express using past time LTL F, where F is a past time LTL formula – F equivalent to “monitor F”
<>F can never be violated in JavaMOP
32
33
R1: There should be no two calls to next() without a call to hasNext() in between,
34
class class Test { public public static tatic void
Vector<Integer> v1 = new ew Vector(); Vector<Integer> v2 = new ew Vector(); v1.add(1); v1.add(3); v2.add(5); v2.add(7); Iterator it1 = v1.iterator(); Iterator it2 = v2.iterator(); int int sum = 0; if if(it2.hasNext()) sum += (Integer)it2.next(); if if(it1.hasNext()) sum += (Integer)it2.next(); System.out.println(”sum(v2) = " + sum); } } should have been: if if(it2 it2.hasNext())
unguarded call: it2 it2.next()
35
partial, matching against suffix trace /*@ partial centralized scope = global logic = ERE HasNext(Iterator i) { event hasnext<i> : end(call(* i.hasNext())); event next<i> : begin(call(* i.next())); formula : next next } validation handler{ System.err.println("*** call hasNext() before next()"); } @*/ validation (not violation)
36
package ltl.hasnext; import java.util.*; /*@ centralized scope = global logic = PTLTL HasNext(Iterator i) { event hasnext<i> : end(call(* i.hasNext())); event next<i> : begin(call(* i.next())); formula : next /\ (*)next } validation handler { System.err.println("*** call hasNext() before next()"); } @*/ it does not look too different in this particular case, but PTLTL
not show more succinct here. partial matching does not make sense in PTLTL. Warning: PTLTL and validation does not currently work in JavaMOP. Likely a bug.
37
package ltl.hasnext; import java.util.*; /*@ centralized scope = global logic = PTLTL HasNext(Iterator i) { event hasnext<i> : end(call(* i.hasNext())); event next<i> : begin(call(* i.next())); formula : !(next /\ (*)next) } violation handler { System.err.println("*** call hasNext() before next()"); } @*/ less attractive but simularity to regular exp can still be noticed. partial matching does not make sense in PTLTL. In PTLTL: validation = not violation
38
39
package ltl.hasnext; import java.util.*; /*@ centralized scope = global logic = PTLTL HasNext(Iterator i) { event hasnext<i> : end(call(* i.hasNext())); event next<i> : begin(call(* i.next())); formula : next -> <*>hasnext } violation handler{ System.err.println("*** call hasNext() before next()"); } @*/ no longer partial not correct, will allow for example: it.hasNext(); it.next(); it.next()
40
package ltl.hasnext; import java.util.*; /*@ centralized scope = global logic = PTLTL HasNext(Iterator i) { event hasnext<i> : end(call(* i.hasNext())); event next<i> : begin(call(* i.next())); formula : next -> (*)(!next Ss hasnext) } violation handler{ System.err.println("*** call hasNext() before next()"); } @*/
correct, will not allow: it.hasNext(); it.next(); it.next() formula: next -> (*)[hasnext,next)s
41
R2: An enumeration should not be propagated after the underlying vector has been changed.
42
Vector v1 = new ew Vector(); Vector v2 = new ew Vector(); v1.add(1); v1.add(2); v2.add(4); v2.add(5); Enumeration e1 = v1.elements(); Enumeration e2 = v1.elements(); Enumeration e3 = v2.elements(); while while(e1.hasMoreElements())print(e1.nextElement()); v1.add(99); while while(e2.hasMoreElements())print(e2.nextElement()); while while(e3.hasMoreElements())print(e3.nextElement());
v1 v2 e1 e2 e3 create(v,e) next(e) updatesource(v) events: add next
43
/*@ partial centralized scope = global logic = ERE SafeEnum (Vector v, Enumeration+ e) { event create<e, v> : end(call(Enumeration v.elements())) with (e); event updatesource<v> : end(call(* v.add*(..))) \/ end(call(* v.clear())) \/ end(call(* v.insertElementAt(..))) && \/ end(call(* v.remove*(..))) \/ end(call(* v.retainAll(..))) \/ end(call(* v.set*(..))); event next<e> : begin(call(Object e.nextElement())); formula : create next* updatesource updatesource* next } validation handler { System.out.println("datasource changed during iteration!"); } @*/
44
/*@ centralized scope = global logic = PTLTL SafeEnum (Vector v, Enumeration+ e) { event create<e, v> : end(call(Enumeration v.elements())) with (e); event updatesource<v> : end(call(* v.add*(..))) \/ … \/ end(call(* v.set*(..))); event next<e> : begin(call(Object e.nextElement())); formula : next -> !(<*>(updatesource /\ <*>create)) } violation handler { System.out.println("the datasource is changed during iteration!"); } @*/
45
/*@ centralized scope = global logic = PTLTL SafeEnum (Vector v, Enumeration+ e) { event create<e, v> : end(call(Enumeration v.elements())) with (e); event updatesource<v> : end(call(* v.add*(..))) \/ … \/ end(call(* v.set*(..))); event next<e> : begin(call(Object e.nextElement())); formula : next -> [create,updatesource)s } violation handler { System.out.println("the datasource is changed during iteration!"); } @*/
47
48
R2: An enumeration should not be propagated after the underlying vector has been changed.
49
Vector v1 = new ew Vector(); Vector v2 = new ew Vector(); v1.add(1); v1.add(2); v2.add(4); v2.add(5); Enumeration e1 = v1.elements(); Enumeration e2 = v1.elements(); Enumeration e3 = v2.elements(); while while(e1.hasMoreElements())print(e1.nextElement()); v1.add(99); while while(e2.hasMoreElements())print(e2.nextElement()); while while(e3.hasMoreElements())print(e3.nextElement());
v1 v2 e1 e2 e3 create(v,e) next(e) updatesource(v) events: add next
50
/*@ centralized scope = global logic = PTLTL SafeEnum (Vector v, Enumeration+ e) { event create<e, v> : end(call(Enumeration v.elements())) with (e); event updatesource<v> : end(call(* v.add*(..))) \/ … \/ end(call(* v.set*(..))); event next<e> : begin(call(Object e.nextElement())); formula : next -> [create,updatesource)s } violation handler { System.out.println("the datasource is changed during iteration!"); } @*/
51
/*@ centralized scope = global logic = FTLTL SafeEnum (Vector v, Enumeration+ e) { event create<e, v> : end(call(Enumeration v.elements())) with (e); event updatesource<v> : end(call(* v.add*(..))) \/ end(call(* v.clear())) \/ end(call(* v.insertElementAt(..))) \/ end(call(* v.remove*(..))) \/ end(call(* v.retainAll(..))) \/ end(call(* v.set*(..))); event next<e> : begin(call(Object e.nextElement())); formula : [](create -> o [](updatesource -> [](!next))) } violation handler { System.out.println("the datasource is changed during iteration!"); } @*/
52