Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook,...

78
Proving Java Termination: Reducing the Ugly to the Bad Marc Brockschmidt LuFG Informatik 2, RWTH Aachen University, Germany September 2012

Transcript of Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook,...

Page 1: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Proving Java Termination: Reducing the Ugly to theBad

Marc Brockschmidt

LuFG Informatik 2, RWTH Aachen University, Germany

September 2012

Page 2: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Automated Termination Analysis

Imperative Programs:

Synthesis of Linear Ranking Functions(Colon & Sipma, ’01), (Podelski & Rybalchenko, ’04), . . .

Termination Analysis for C (via Transition Invariants)Terminator – (Cook, Podelski, Rybalchenko et al., since ’05)

CProver – (Kroening, Sharygina, Tsitovich, Wintersteiger, since ’10)

Declarative Programs:

Logic Programming (since the 70s)

Term Rewriting (since the 70s)

Transformation of Imperative to Declarative Programs:

Termination Analysis for C (via Polynomial Orders)KITTeL – (Falke, Kapur, Sinz, since ’11)

Termination Analysis for Java (via Path Length, CLP backend)Julia – (Spoto, Mesnard, Payet, since ’08)

COSTA – (Albert, Arenas, Codish, Genaim, Puebla, Zanardini, since ’08)

Page 3: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Automated Termination Analysis

Imperative Programs:

Synthesis of Linear Ranking Functions(Colon & Sipma, ’01), (Podelski & Rybalchenko, ’04), . . .

Termination Analysis for C (via Transition Invariants)Terminator – (Cook, Podelski, Rybalchenko et al., since ’05)

CProver – (Kroening, Sharygina, Tsitovich, Wintersteiger, since ’10)

Declarative Programs:

Logic Programming (since the 70s)

Term Rewriting (since the 70s)

Transformation of Imperative to Declarative Programs:

Termination Analysis for C (via Polynomial Orders)KITTeL – (Falke, Kapur, Sinz, since ’11)

Termination Analysis for Java (via Path Length, CLP backend)Julia – (Spoto, Mesnard, Payet, since ’08)

COSTA – (Albert, Arenas, Codish, Genaim, Puebla, Zanardini, since ’08)

Page 4: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Automated Termination Analysis

Imperative Programs:

Synthesis of Linear Ranking Functions(Colon & Sipma, ’01), (Podelski & Rybalchenko, ’04), . . .

Termination Analysis for C (via Transition Invariants)Terminator – (Cook, Podelski, Rybalchenko et al., since ’05)

CProver – (Kroening, Sharygina, Tsitovich, Wintersteiger, since ’10)

Declarative Programs:

Logic Programming (since the 70s)

Term Rewriting (since the 70s)

Transformation of Imperative to Declarative Programs:

Termination Analysis for C (via Polynomial Orders)KITTeL – (Falke, Kapur, Sinz, since ’11)

Termination Analysis for Java (via Path Length, CLP backend)Julia – (Spoto, Mesnard, Payet, since ’08)

COSTA – (Albert, Arenas, Codish, Genaim, Puebla, Zanardini, since ’08)

Page 5: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Automated Termination Analysis

Imperative Programs:

Synthesis of Linear Ranking Functions(Colon & Sipma, ’01), (Podelski & Rybalchenko, ’04), . . .

Termination Analysis for C (via Transition Invariants)Terminator – (Cook, Podelski, Rybalchenko et al., since ’05)

CProver – (Kroening, Sharygina, Tsitovich, Wintersteiger, since ’10)

Declarative Programs:

Logic Programming (since the 70s)

Term Rewriting (since the 70s)

Transformation of Imperative to Declarative Programs:

Termination Analysis for C (via Polynomial Orders)KITTeL – (Falke, Kapur, Sinz, since ’11)

Termination Analysis for Java (via Path Length, CLP backend)Julia – (Spoto, Mesnard, Payet, since ’08)

COSTA – (Albert, Arenas, Codish, Genaim, Puebla, Zanardini, since ’08)

Page 6: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Automated Termination Analysis

Imperative Programs:

Synthesis of Linear Ranking Functions(Colon & Sipma, ’01), (Podelski & Rybalchenko, ’04), . . .

Termination Analysis for C (via Transition Invariants)Terminator – (Cook, Podelski, Rybalchenko et al., since ’05)

CProver – (Kroening, Sharygina, Tsitovich, Wintersteiger, since ’10)

Declarative Programs:

Logic Programming (since the 70s)

Term Rewriting (since the 70s)

Transformation of Imperative to Declarative Programs:

Termination Analysis for C (via Polynomial Orders)KITTeL – (Falke, Kapur, Sinz, since ’11)

Termination Analysis for Java (via Path Length, CLP backend)Julia – (Spoto, Mesnard, Payet, since ’08)

COSTA – (Albert, Arenas, Codish, Genaim, Puebla, Zanardini, since ’08)

Page 7: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Automated Termination Analysis

Imperative Programs:

Synthesis of Linear Ranking Functions(Colon & Sipma, ’01), (Podelski & Rybalchenko, ’04), . . .

Termination Analysis for C (via Transition Invariants)Terminator – (Cook, Podelski, Rybalchenko et al., since ’05)

CProver – (Kroening, Sharygina, Tsitovich, Wintersteiger, since ’10)

Declarative Programs:

Logic Programming (since the 70s)

Term Rewriting (since the 70s)

Transformation of Imperative to Declarative Programs:

Termination Analysis for C (via Polynomial Orders)KITTeL – (Falke, Kapur, Sinz, since ’11)

Termination Analysis for Java (via Path Length, CLP backend)Julia – (Spoto, Mesnard, Payet, since ’08)

COSTA – (Albert, Arenas, Codish, Genaim, Puebla, Zanardini, since ’08)

Page 8: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Automated Termination Analysis

Imperative Programs:

Synthesis of Linear Ranking Functions(Colon & Sipma, ’01), (Podelski & Rybalchenko, ’04), . . .

Termination Analysis for C (via Transition Invariants)Terminator – (Cook, Podelski, Rybalchenko et al., since ’05)

CProver – (Kroening, Sharygina, Tsitovich, Wintersteiger, since ’10)

Declarative Programs:

Logic Programming (since the 70s)

Term Rewriting (since the 70s)

Transformation of Imperative to Declarative Programs:

Termination Analysis for C (via Polynomial Orders)KITTeL – (Falke, Kapur, Sinz, since ’11)

Termination Analysis for Java (via Path Length, CLP backend)Julia – (Spoto, Mesnard, Payet, since ’08)

COSTA – (Albert, Arenas, Codish, Genaim, Puebla, Zanardini, since ’08)

Page 9: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Automated Termination Analysis

Imperative Programs:

Synthesis of Linear Ranking Functions(Colon & Sipma, ’01), (Podelski & Rybalchenko, ’04), . . .

Termination Analysis for C (via Transition Invariants)Terminator – (Cook, Podelski, Rybalchenko et al., since ’05)

CProver – (Kroening, Sharygina, Tsitovich, Wintersteiger, since ’10)

Declarative Programs:

Logic Programming (since the 70s)

Term Rewriting (since the 70s)

Transformation of Imperative to Declarative Programs:

Termination Analysis for C (via Polynomial Orders)KITTeL – (Falke, Kapur, Sinz, since ’11)

Termination Analysis for Java (via Path Length, CLP backend)Julia – (Spoto, Mesnard, Payet, since ’08)

COSTA – (Albert, Arenas, Codish, Genaim, Puebla, Zanardini, since ’08)

Page 10: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Automated Termination Analysis

Imperative Programs:

Synthesis of Linear Ranking Functions(Colon & Sipma, ’01), (Podelski & Rybalchenko, ’04), . . .

Termination Analysis for C (via Transition Invariants)Terminator – (Cook, Podelski, Rybalchenko et al., since ’05)

CProver – (Kroening, Sharygina, Tsitovich, Wintersteiger, since ’10)

Declarative Programs:

Logic Programming (since the 70s)

Term Rewriting (since the 70s)

Transformation of Imperative to Declarative Programs:

Termination Analysis for C (via Polynomial Orders)KITTeL – (Falke, Kapur, Sinz, since ’11)

Termination Analysis for Java (via Path Length, CLP backend)Julia – (Spoto, Mesnard, Payet, since ’08)

COSTA – (Albert, Arenas, Codish, Genaim, Puebla, Zanardini, since ’08)

Page 11: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Rewriting-backed approach: Idea

Programming languages hard y Simpler representation needed

Symbolic Evaluation Graphs: Simpler, contain all information

Term Rewrite Systems (TRSs) generated from Symbolic Evaluation

Prove TRS termination using existing provers

Haskell

Prolog

Java

C

SymbolicEvaluation

Graph

Page 12: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Rewriting-backed approach: Idea

Programming languages hard y Simpler representation needed

Symbolic Evaluation Graphs: Simpler, contain all information

Term Rewrite Systems (TRSs) generated from Symbolic Evaluation

Prove TRS termination using existing provers

Haskell

Prolog

Java

C

SymbolicEvaluation

Graph

Page 13: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Rewriting-backed approach: Idea

Programming languages hard y Simpler representation needed

Symbolic Evaluation Graphs: Simpler, contain all information

Term Rewrite Systems (TRSs) generated from Symbolic Evaluation

Prove TRS termination using existing provers

Haskell

Prolog

Java

C

SymbolicEvaluation

Graph

TRS

Page 14: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Rewriting-backed approach: Idea

Programming languages hard y Simpler representation needed

Symbolic Evaluation Graphs: Simpler, contain all information

Term Rewrite Systems (TRSs) generated from Symbolic Evaluation

Prove TRS termination using existing provers

Haskell

Prolog

Java

C

SymbolicEvaluation

Graph

TRS

Termination

Page 15: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Rewriting-backed approach: Idea

Programming languages hard y Simpler representation needed

Symbolic Evaluation Graphs: Simpler, contain all information

Term Rewrite Systems (TRSs) generated from Symbolic Evaluation

Prove TRS termination using existing provers

Haskell

Prolog

Java

C

SymbolicEvaluation

Graph

TRS

Termination

Complexity

Page 16: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Rewriting-backed approach: Idea

Programming languages hard y Simpler representation needed

Symbolic Evaluation Graphs: Simpler, contain all information

Term Rewrite Systems (TRSs) generated from Symbolic Evaluation

Prove TRS termination using existing provers

Haskell

Prolog

Java

C

SymbolicEvaluation

Graph

TRS

Termination

Complexity

Non-Termination

Bug Detection

. . .

Page 17: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Rewriting-backed approach: Advantages

Handling of user-defined acyclic data structures:public class List {

int value;

List next;

}

Page 18: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Rewriting-backed approach: Advantages

Handling of user-defined acyclic data structures:public class List {

int value;

List next;

}Other techniques:Fixed abstraction to number

List [2, 4, 6] abstracted tolength 3

Our technique:Abstraction to terms

List [2, 4, 6] becomesList(2, List(4, List(6, null) ) )

TRS techniques search for suitable orders automatically

⇒ Complex orders for user-defined data structures possible

Page 19: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Rewriting-backed approach: Advantages

Handling of user-defined acyclic data structures:public class List {

int value;

List next;

}Other techniques:Fixed abstraction to number

List [2, 4, 6] abstracted tolength 3

Our technique:Abstraction to terms

List [2, 4, 6] becomesList(2, List(4, List(6, null) ) )

TRS techniques search for suitable orders automatically

⇒ Complex orders for user-defined data structures possible

Page 20: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Rewriting-backed approach: Advantages

Handling of user-defined acyclic data structures:public class List {

int value;

List next;

}Other techniques:Fixed abstraction to number

List [2, 4, 6] abstracted tolength 3

Our technique:Abstraction to terms

List [2, 4, 6] becomesList(2, List(4, List(6, null) ) )

TRS techniques search for suitable orders automatically

⇒ Complex orders for user-defined data structures possible

Page 21: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

length: the example

class L {L p, n;

static int length(L x) {int r = 1;

while (x != null) {x = x.n;

r++;

}return r; }}

Page 22: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

length: the example

class L {L p, n;

static int length(L x) {int r = 1;

while (x != null) {x = x.n;

r++;

}return r; }}

null null

n n n

ppp

Page 23: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

length: the example

class L {L p, n;

static int length(L x) {int r = 1;

while (x != null) {x = x.n;

r++;

}return r; }}

null null

x

n n n

ppp

Page 24: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

length: the example

class L {L p, n;

static int length(L x) {int r = 1;

while (x != null) {x = x.n;

r++;

}return r; }}

null null

x

n n n

ppp

Page 25: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

length: the example

class L {L p, n;

static int length(L x) {int r = 1;

while (x != null) {x = x.n;

r++;

}return r; }}

null null

x

n n n

ppp

Page 26: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

length: the example

class L {L p, n;

static int length(L x) {int r = 1;

while (x != null) {x = x.n;

r++;

}return r; }}

null null

x

n n n

ppp

Page 27: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

length: the example

class L {L p, n;

static int length(L x) {int r = 1;

while (x != null) {x = x.n;

r++;

}return r; }}

00: iconst 1 #load 1

01: istore 1 #store to r

02: aload 0 #load x

03: ifnull 17 #jump if x null

06: aload 0 #load x

07: getfield n #get n from x

10: astore 0 #store to x

11: iinc 1, 1 #increment r

14: goto 2

17: iload 1 #load r

18: ireturn #return r

Page 28: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Abstract Java virtual machine states

class L {L p, n;

static int length(L x) {int r = 1;

while (x != null) {x = x.n;

r++;

}return r; }}

00: iconst 1 #load 1

01: istore 1 #store to r

02: aload 0 #load x

03: ifnull 17 #jump if x null

06: aload 0 #load x

07: getfield n #get n from x

10: astore 0 #store to x

11: iinc 1, 1 #increment r

14: goto 2

17: iload 1 #load r

18: ireturn #return r

Page 29: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Abstract Java virtual machine states

class L {L p, n;

static int length(L x) {int r = 1;

while (x != null) {x = x.n;

r++;

}return r; }}

00: iconst 1 #load 1

01: istore 1 #store to r

02: aload 0 #load x

03: ifnull 17 #jump if x null

06: aload 0 #load x

07: getfield n #get n from x

10: astore 0 #store to x

11: iinc 1, 1 #increment r

14: goto 2

17: iload 1 #load r

18: ireturn #return r

00 | x :o1 | εo1:L(?) o1{p,n}Stack frame:

Next program instruction

Local variables

Operand stack

Heap information:

o1 is L object or null

Known L object: o2 : L(n=o3)

Unknown integer: i1 : ZHeap predicates:

Two references may be equal: o1 =? o2

Two references may share: o1%$o2Reference might have cyclescontaining all fields F : o1F

Page 30: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Abstract Java virtual machine states

class L {L p, n;

static int length(L x) {int r = 1;

while (x != null) {x = x.n;

r++;

}return r; }}

00: iconst 1 #load 1

01: istore 1 #store to r

02: aload 0 #load x

03: ifnull 17 #jump if x null

06: aload 0 #load x

07: getfield n #get n from x

10: astore 0 #store to x

11: iinc 1, 1 #increment r

14: goto 2

17: iload 1 #load r

18: ireturn #return r

00 | x :o1 | εo1:L(?) o1{p,n}Stack frame:

Next program instruction

Local variables

Operand stack

Heap information:

o1 is L object or null

Known L object: o2 : L(n=o3)

Unknown integer: i1 : ZHeap predicates:

Two references may be equal: o1 =? o2

Two references may share: o1%$o2Reference might have cyclescontaining all fields F : o1F

Page 31: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Abstract Java virtual machine states

class L {L p, n;

static int length(L x) {int r = 1;

while (x != null) {x = x.n;

r++;

}return r; }}

00: iconst 1 #load 1

01: istore 1 #store to r

02: aload 0 #load x

03: ifnull 17 #jump if x null

06: aload 0 #load x

07: getfield n #get n from x

10: astore 0 #store to x

11: iinc 1, 1 #increment r

14: goto 2

17: iload 1 #load r

18: ireturn #return r

00 | x :o1 | εo1:L(?) o1{p,n}Stack frame:

Next program instruction

Local variables

Operand stack

Heap information:

o1 is L object or null

Known L object: o2 : L(n=o3)

Unknown integer: i1 : ZHeap predicates:

Two references may be equal: o1 =? o2

Two references may share: o1%$o2Reference might have cyclescontaining all fields F : o1F

Page 32: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Abstract Java virtual machine states

class L {L p, n;

static int length(L x) {int r = 1;

while (x != null) {x = x.n;

r++;

}return r; }}

00: iconst 1 #load 1

01: istore 1 #store to r

02: aload 0 #load x

03: ifnull 17 #jump if x null

06: aload 0 #load x

07: getfield n #get n from x

10: astore 0 #store to x

11: iinc 1, 1 #increment r

14: goto 2

17: iload 1 #load r

18: ireturn #return r

00 | x :o1 | εo1:L(?) o1{p,n}Stack frame:

Next program instruction

Local variables

Operand stack

Heap information:

o1 is L object or null

Known L object: o2 : L(n=o3)

Unknown integer: i1 : ZHeap predicates:

Two references may be equal: o1 =? o2

Two references may share: o1%$o2Reference might have cyclescontaining all fields F : o1F

Page 33: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Abstract Java virtual machine states

class L {L p, n;

static int length(L x) {int r = 1;

while (x != null) {x = x.n;

r++;

}return r; }}

00: iconst 1 #load 1

01: istore 1 #store to r

02: aload 0 #load x

03: ifnull 17 #jump if x null

06: aload 0 #load x

07: getfield n #get n from x

10: astore 0 #store to x

11: iinc 1, 1 #increment r

14: goto 2

17: iload 1 #load r

18: ireturn #return r

00 | x :o1 | εo1:L(?) o1{p,n}Stack frame:

Next program instruction

Local variables

Operand stack

Heap information:

o1 is L object or null

Known L object: o2 : L(n=o3)

Unknown integer: i1 : ZHeap predicates:

Two references may be equal: o1 =? o2

Two references may share: o1%$o2Reference might have cyclescontaining all fields F : o1F

Page 34: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Abstract Java virtual machine states

class L {L p, n;

static int length(L x) {int r = 1;

while (x != null) {x = x.n;

r++;

}return r; }}

00: iconst 1 #load 1

01: istore 1 #store to r

02: aload 0 #load x

03: ifnull 17 #jump if x null

06: aload 0 #load x

07: getfield n #get n from x

10: astore 0 #store to x

11: iinc 1, 1 #increment r

14: goto 2

17: iload 1 #load r

18: ireturn #return r

00 | x :o1 | εo1:L(?) o1{p,n}Stack frame:

Next program instruction

Local variables

Operand stack

Heap information:

o1 is L object or null

Known L object: o2 : L(n=o3)

Unknown integer: i1 : Z

Heap predicates:

Two references may be equal: o1 =? o2

Two references may share: o1%$o2Reference might have cyclescontaining all fields F : o1F

Page 35: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Abstract Java virtual machine states

class L {L p, n;

static int length(L x) {int r = 1;

while (x != null) {x = x.n;

r++;

}return r; }}

00: iconst 1 #load 1

01: istore 1 #store to r

02: aload 0 #load x

03: ifnull 17 #jump if x null

06: aload 0 #load x

07: getfield n #get n from x

10: astore 0 #store to x

11: iinc 1, 1 #increment r

14: goto 2

17: iload 1 #load r

18: ireturn #return r

00 | x :o1 | εo1:L(?) o1{p,n}Stack frame:

Next program instruction

Local variables

Operand stack

Heap information:

o1 is L object or null

Known L object: o2 : L(n=o3)

Unknown integer: i1 : Z

Heap predicates:

Two references may be equal: o1 =? o2

Two references may share: o1%$o2Reference might have cyclescontaining all fields F : o1F

Only explicit sharing

Page 36: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Abstract Java virtual machine states

class L {L p, n;

static int length(L x) {int r = 1;

while (x != null) {x = x.n;

r++;

}return r; }}

00: iconst 1 #load 1

01: istore 1 #store to r

02: aload 0 #load x

03: ifnull 17 #jump if x null

06: aload 0 #load x

07: getfield n #get n from x

10: astore 0 #store to x

11: iinc 1, 1 #increment r

14: goto 2

17: iload 1 #load r

18: ireturn #return r

00 | x :o1 | εo1:L(?) o1{p,n}Stack frame:

Next program instruction

Local variables

Operand stack

Heap information:

o1 is L object or null

Known L object: o2 : L(n=o3)

Unknown integer: i1 : ZHeap predicates:

Two references may be equal: o1 =? o2

Two references may share: o1%$o2Reference might have cyclescontaining all fields F : o1F

Only explicit sharing

Page 37: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Abstract Java virtual machine states

class L {L p, n;

static int length(L x) {int r = 1;

while (x != null) {x = x.n;

r++;

}return r; }}

00: iconst 1 #load 1

01: istore 1 #store to r

02: aload 0 #load x

03: ifnull 17 #jump if x null

06: aload 0 #load x

07: getfield n #get n from x

10: astore 0 #store to x

11: iinc 1, 1 #increment r

14: goto 2

17: iload 1 #load r

18: ireturn #return r

00 | x :o1 | εo1:L(?) o1{p,n}Stack frame:

Next program instruction

Local variables

Operand stack

Heap information:

o1 is L object or null

Known L object: o2 : L(n=o3)

Unknown integer: i1 : ZHeap predicates:

Two references may be equal: o1 =? o2

Two references may share: o1%$o2

Reference might have cyclescontaining all fields F : o1F

Only explicit sharing

Page 38: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Abstract Java virtual machine states

class L {L p, n;

static int length(L x) {int r = 1;

while (x != null) {x = x.n;

r++;

}return r; }}

00: iconst 1 #load 1

01: istore 1 #store to r

02: aload 0 #load x

03: ifnull 17 #jump if x null

06: aload 0 #load x

07: getfield n #get n from x

10: astore 0 #store to x

11: iinc 1, 1 #increment r

14: goto 2

17: iload 1 #load r

18: ireturn #return r

00 | x :o1 | εo1:L(?) o1{p,n}Stack frame:

Next program instruction

Local variables

Operand stack

Heap information:

o1 is L object or null

Known L object: o2 : L(n=o3)

Unknown integer: i1 : ZHeap predicates:

Two references may be equal: o1 =? o2

Two references may share: o1%$o2Reference might have cyclescontaining all fields F : o1F

Only explicit sharing

Page 39: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

00: iconst 1

01: istore 1

02: aload 0

03: ifnull 17

06: aload 0

07: getfield n

10: astore 0

11: iinc 1, 1

14: goto 2

17: iload 1

18: ireturn

00 |x :o1 |εo1:L(?) o1{p,n}

A

State A:

x some list, might contain cycles using p and n

State B:

Initialized variable r to 1

State

s

C , D, E :

x (o1) null? We do not know!

⇒ Refinement

In D: o1 is null (y program ends)In E : o1 replaced by o2, which exists and has fields:

Field values can share (y add %$)Field values can be cyclic again (y add )

int length(L x) {int r = 1;

while (x != null) {x = x.n; r++; }

return r; }

Page 40: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

00: iconst 1

01: istore 1

02: aload 0

03: ifnull 17

06: aload 0

07: getfield n

10: astore 0

11: iinc 1, 1

14: goto 2

17: iload 1

18: ireturn

00 |x :o1 |εo1:L(?) o1{p,n}

A

02 |x :o1, r : 1 |εo1:L(?) o1{p,n}

B

State A:

x some list, might contain cycles using p and n

State B:

Initialized variable r to 1

State

s

C , D, E :

x (o1) null? We do not know!

⇒ Refinement

In D: o1 is null (y program ends)In E : o1 replaced by o2, which exists and has fields:

Field values can share (y add %$)Field values can be cyclic again (y add )

int length(L x) {int r = 1;

while (x != null) {x = x.n; r++; }

return r; }

Page 41: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

00: iconst 1

01: istore 1

02: aload 0

03: ifnull 17

06: aload 0

07: getfield n

10: astore 0

11: iinc 1, 1

14: goto 2

17: iload 1

18: ireturn

00 |x :o1 |εo1:L(?) o1{p,n}

A

02 |x :o1, r : 1 |εo1:L(?) o1{p,n}

B

03 |x :o1, r : 1 |o1o1:L(?) o1{p,n}

C

State A:

x some list, might contain cycles using p and n

State B:

Initialized variable r to 1

State

s

C :

x (o1) null? We do not know!

⇒ Refinement

In D: o1 is null (y program ends)In E : o1 replaced by o2, which exists and has fields:

Field values can share (y add %$)Field values can be cyclic again (y add )

int length(L x) {int r = 1;

while (x != null) {x = x.n; r++; }

return r; }

Page 42: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

00: iconst 1

01: istore 1

02: aload 0

03: ifnull 17

06: aload 0

07: getfield n

10: astore 0

11: iinc 1, 1

14: goto 2

17: iload 1

18: ireturn

00 |x :o1 |εo1:L(?) o1{p,n}

A

02 |x :o1, r : 1 |εo1:L(?) o1{p,n}

B

03 |x :o1, r : 1 |o1o1:L(?) o1{p,n}

C

03 |x :null, r : 1 |null D

03 |x :o2, r : 1 |o2o2:L(p=o3, n=o4)o3:L(?) o4:L(?)o2%$o3 o2%$o4 o3%$o4o2, o3, o4{p,n}

E

State A:

x some list, might contain cycles using p and n

State B:

Initialized variable r to 1

States C , D, E :

x (o1) null? We do not know!

⇒ Refinement

In D: o1 is null (y program ends)In E : o1 replaced by o2, which exists and has fields:

Field values can share (y add %$)Field values can be cyclic again (y add )

int length(L x) {int r = 1;

while (x != null) {x = x.n; r++; }

return r; }

Page 43: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

00: iconst 1

01: istore 1

02: aload 0

03: ifnull 17

06: aload 0

07: getfield n

10: astore 0

11: iinc 1, 1

14: goto 2

17: iload 1

18: ireturn

00 |x :o1 |εo1:L(?) o1{p,n}

A

02 |x :o1, r : 1 |εo1:L(?) o1{p,n}

B

03 |x :o1, r : 1 |o1o1:L(?) o1{p,n}

C

03 |x :null, r : 1 |null D

03 |x :o2, r : 1 |o2o2:L(p=o3, n=o4)o3:L(?) o4:L(?)o2%$o3 o2%$o4 o3%$o4o2, o3, o4{p,n}

E 11 |x :o4, r : 1 |εo4:L(?) o4{p,n}

F

State F :

Stored x.n to x (allowing for GC)

State

s

G , B ′:

Incremented r, back to position 02 (as B)

⇒ Generalization: “Merge” states B, G

States C ′,G ′:

Repetition of C ,G

int length(L x) {int r = 1;

while (x != null) {x = x.n; r++; }

return r; }

Page 44: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

00: iconst 1

01: istore 1

02: aload 0

03: ifnull 17

06: aload 0

07: getfield n

10: astore 0

11: iinc 1, 1

14: goto 2

17: iload 1

18: ireturn

00 |x :o1 |εo1:L(?) o1{p,n}

A

02 |x :o1, r : 1 |εo1:L(?) o1{p,n}

B

03 |x :o1, r : 1 |o1o1:L(?) o1{p,n}

C

03 |x :null, r : 1 |null D

03 |x :o2, r : 1 |o2o2:L(p=o3, n=o4)o3:L(?) o4:L(?)o2%$o3 o2%$o4 o3%$o4o2, o3, o4{p,n}

E 11 |x :o4, r : 1 |εo4:L(?) o4{p,n}

F

02 |x :o4, r : 2 |εo4:L(?) o4{p,n}

G

State F :

Stored x.n to x (allowing for GC)

State

s

G :

Incremented r, back to position 02 (as B)

⇒ Generalization: “Merge” states B, G

States C ′,G ′:

Repetition of C ,G

int length(L x) {int r = 1;

while (x != null) {x = x.n; r++; }

return r; }

Page 45: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

00: iconst 1

01: istore 1

02: aload 0

03: ifnull 17

06: aload 0

07: getfield n

10: astore 0

11: iinc 1, 1

14: goto 2

17: iload 1

18: ireturn

00 |x :o1 |εo1:L(?) o1{p,n}

A

02 |x :o1, r : 1 |εo1:L(?) o1{p,n}

B

03 |x :o1, r : 1 |o1o1:L(?) o1{p,n}

C

03 |x :null, r : 1 |null D

03 |x :o2, r : 1 |o2o2:L(p=o3, n=o4)o3:L(?) o4:L(?)o2%$o3 o2%$o4 o3%$o4o2, o3, o4{p,n}

E 11 |x :o4, r : 1 |εo4:L(?) o4{p,n}

F

02 |x :o4, r : 2 |εo4:L(?) o4{p,n}

G02 |x :o′1, r : i1 |εo′1:L(?) o′1{p,n} i1: [>0]

B′

State F :

Stored x.n to x (allowing for GC)

States G , B ′:

Incremented r, back to position 02 (as B)

⇒ Generalization: “Merge” states B, G

States C ′,G ′:

Repetition of C ,G

int length(L x) {int r = 1;

while (x != null) {x = x.n; r++; }

return r; }

Page 46: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

00: iconst 1

01: istore 1

02: aload 0

03: ifnull 17

06: aload 0

07: getfield n

10: astore 0

11: iinc 1, 1

14: goto 2

17: iload 1

18: ireturn

00 |x :o1 |εo1:L(?) o1{p,n}

A

02 |x :o1, r : 1 |εo1:L(?) o1{p,n}

B

03 |x :o1, r : 1 |o1o1:L(?) o1{p,n}

C

03 |x :null, r : 1 |null D

03 |x :o2, r : 1 |o2o2:L(p=o3, n=o4)o3:L(?) o4:L(?)o2%$o3 o2%$o4 o3%$o4o2, o3, o4{p,n}

E 11 |x :o4, r : 1 |εo4:L(?) o4{p,n}

F

02 |x :o4, r : 2 |εo4:L(?) o4{p,n}

G02 |x :o′1, r : i1 |εo′1:L(?) o′1{p,n} i1: [>0]

B′

03 |x :o′1, r : i1 |o′1

o′1:L(?) o′1{p,n} i1: [>0]C ′02 |x :o′4, r : i2 |o

′4

o′4:L(?) o′4{p,n} i2: [>1]

G ′

i2= i1 + 1

State F :

Stored x.n to x (allowing for GC)

States G , B ′:

Incremented r, back to position 02 (as B)

⇒ Generalization: “Merge” states B, G

States C ′,G ′:

Repetition of C ,G

int length(L x) {int r = 1;

while (x != null) {x = x.n; r++; }

return r; }

Page 47: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

00: iconst 1

01: istore 1

02: aload 0

03: ifnull 17

06: aload 0

07: getfield n

10: astore 0

11: iinc 1, 1

14: goto 2

17: iload 1

18: ireturn

00 |x :o1 |εo1:L(?) o1{p,n}

A

02 |x :o1, r : 1 |εo1:L(?) o1{p,n}

B

03 |x :o1, r : 1 |o1o1:L(?) o1{p,n}

C

03 |x :null, r : 1 |null D

03 |x :o2, r : 1 |o2o2:L(p=o3, n=o4)o3:L(?) o4:L(?)o2%$o3 o2%$o4 o3%$o4o2, o3, o4{p,n}

E 11 |x :o4, r : 1 |εo4:L(?) o4{p,n}

F

02 |x :o4, r : 2 |εo4:L(?) o4{p,n}

G02 |x :o′1, r : i1 |εo′1:L(?) o′1{p,n} i1: [>0]

B′

03 |x :o′1, r : i1 |o′1

o′1:L(?) o′1{p,n} i1: [>0]C ′02 |x :o′4, r : i2 |o

′4

o′4:L(?) o′4{p,n} i2: [>1]

G ′

i2= i1 + 1

State F :

Stored x.n to x (allowing for GC)

States G , B ′:

Incremented r, back to position 02 (as B)

⇒ Generalization: “Merge” states B, G

States C ′,G ′:

Repetition of C ,G

int length(L x) {int r = 1;

while (x != null) {x = x.n; r++; }

return r; }

Page 48: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Transforming values to terms

03 |x :o2, r :1 |o2o2:L(p=o3, n=o4)o3:L(?) o4:L(?)o2%$o3 o2%$o4 o3%$o4o2, o3, o4{p,n}

E

Known integers transformed to themselves

Unknown values transformed to variables

Data structures transformed to nested constructor terms:Class Cl with n fields y symbol Cl of arity n

fE (

o2︷ ︸︸ ︷

L(

o3,

o4), 1,

o2︷ ︸︸ ︷L(

o3,

o4)

) → fF (o4

, 1)

Page 49: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Transforming values to terms

03 |x :o2, r :1 |o2o2:L(p=o3, n=o4)o3:L(?) o4:L(?)o2%$o3 o2%$o4 o3%$o4o2, o3, o4{p,n}

E

Known integers transformed to themselves

Unknown values transformed to variables

Data structures transformed to nested constructor terms:Class Cl with n fields y symbol Cl of arity n

fE (

o2︷ ︸︸ ︷

L(

o3,

o4),

1

,

o2︷ ︸︸ ︷L(

o3,

o4)

) → fF (o4

, 1)

Page 50: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Transforming values to terms

03 |x :o2, r :1 |o2o2:L(p=o3, n=o4)o3:L(?) o4:L(?)o2%$o3 o2%$o4 o3%$o4o2, o3, o4{p,n}

E

Known integers transformed to themselves

Unknown values transformed to variables

Data structures transformed to nested constructor terms:Class Cl with n fields y symbol Cl of arity n

fE (

o2︷ ︸︸ ︷

L(

o3, o4

),

1

,

o2︷ ︸︸ ︷L(

o3,

o4)

) → fF (o4

, 1)

Page 51: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Transforming values to terms

03 |x :o2, r :1 |o2o2:L(p=o3, n=o4)o3:L(?) o4:L(?)o2%$o3 o2%$o4 o3%$o4o2, o3, o4{p,n}

E

Known integers transformed to themselves

Unknown values transformed to variables

Data structures transformed to nested constructor terms:Class Cl with n fields y symbol Cl of arity n

fE (

o2︷ ︸︸ ︷L(o3, o4)

,

1

,

o2︷ ︸︸ ︷L(

o3,

o4)

) → fF (o4

, 1)

Page 52: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Transforming states to terms

03 |x :o2, r :1 |o2o2:L(p=o3, n=o4)o3:L(?) o4:L(?)o2%$o3 o2%$o4 o3%$o4o2, o3, o4{p,n}

E

State s transformed to term with symbol fs

All local variables, stack entrys as arguments

Evaluation edges: Encode states, put in →Problem: Terms cannot represent cycles y free var on rhs

Solution: Only encode non-cyclic parts!

Refinement edges: Encode target state twice, relabel

Instantiation edges: Encode source state twice, relabel

fE (

o2︷ ︸︸ ︷L(o3, o4), 1,

o2︷ ︸︸ ︷L(o3, o4))

→ fF (o4

, 1)

Page 53: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Transforming edges to rules

03 |x :o2, r :1 |o2o2:L(p=o3, n=o4)o3:L(?) o4:L(?)o2%$o3 o2%$o4 o3%$o4o2, o3, o4{p,n}

E 11 |x :o4, r :1 |εo4:L(?) o4{p,n}

F

State s transformed to term with symbol fs

All local variables, stack entrys as arguments

Evaluation edges: Encode states, put in →Problem: Terms cannot represent cycles y free var on rhs

Solution: Only encode non-cyclic parts!

Refinement edges: Encode target state twice, relabel

Instantiation edges: Encode source state twice, relabel

fE (

o2︷ ︸︸ ︷L(o3, o4), 1,

o2︷ ︸︸ ︷L(o3, o4))

→ fF (o4

, 1)

Page 54: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Transforming edges to rules

03 |x :o2, r :1 |o2o2:L(p=o3, n=o4)o3:L(?) o4:L(?)o2%$o3 o2%$o4 o3%$o4o2, o3, o4{p,n}

E 11 |x :o4, r :1 |εo4:L(?) o4{p,n}

F

State s transformed to term with symbol fs

All local variables, stack entrys as arguments

Evaluation edges: Encode states, put in →

Problem: Terms cannot represent cycles y free var on rhs

Solution: Only encode non-cyclic parts!

Refinement edges: Encode target state twice, relabel

Instantiation edges: Encode source state twice, relabel

fE (

o2︷ ︸︸ ︷L(o3, o4), 1,

o2︷ ︸︸ ︷L(o3, o4)) → fF (o4

, 1)

Page 55: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Transforming edges to rules

03 |x :o2, r :1 |o2o2:L(p=o3, n=o4)o3:L(?) o4:L(?)o2%$o3 o2%$o4 o3%$o4o2, o3, o4{p,n}

E 11 |x :o4, r :1 |εo4:L(?) o4{p,n}

F

State s transformed to term with symbol fs

All local variables, stack entrys as arguments

Evaluation edges: Encode states, put in →Problem: Terms cannot represent cycles y free var on rhs

Solution: Only encode non-cyclic parts!

Refinement edges: Encode target state twice, relabel

Instantiation edges: Encode source state twice, relabel

fE (

o2︷ ︸︸ ︷L(o3, o4), 1,

o2︷ ︸︸ ︷L(o3, o4)) → fF (o4

′, 1)

Page 56: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Transforming edges to rules

03 |x :o2, r :1 |o2o2:L(p=o3, n=o4)o3:L(?) o4:L(?)o2%$o3 o2%$o4 o3%$o4o2, o3, o4{p,n}

E 11 |x :o4, r :1 |εo4:L(?) o4{p,n}

F

State s transformed to term with symbol fs

All local variables, stack entrys as arguments

Evaluation edges: Encode states, put in →Problem: Terms cannot represent cycles y free var on rhs

Solution: Only encode non-cyclic parts!

Refinement edges: Encode target state twice, relabel

Instantiation edges: Encode source state twice, relabel

fE (

o2︷ ︸︸ ︷L(

o3,

o4), 1,

o2︷ ︸︸ ︷L(

o3,

o4)) → fF (o4

, 1)

Page 57: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Transforming edges to rules

03 |x :o1, r :1 |o1o1:L(?) o1{p,n}

C

03 |x :o2, r :1 |o2o2:L(p=o3, n=o4)o3:L(?) o4:L(?)o2%$o3 o2%$o4 o3%$o4o2, o3, o4{p,n}

E

State s transformed to term with symbol fs

All local variables, stack entrys as arguments

Evaluation edges: Encode states, put in →Problem: Terms cannot represent cycles y free var on rhs

Solution: Only encode non-cyclic parts!

Refinement edges: Encode target state twice, relabel

Instantiation edges: Encode source state twice, relabel

fC (L(o4), 1, L(o4)) → fE (L(o4), 1, L(o4))

Page 58: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Transforming edges to rules

02 |x :o4, r :2 |εo4:L(?) o4{p,n}

G 02 |x :o ′1, r : i1 |εo ′1:L(?) o ′1{p,n} i1: [>0]

B ′

State s transformed to term with symbol fs

All local variables, stack entrys as arguments

Evaluation edges: Encode states, put in →Problem: Terms cannot represent cycles y free var on rhs

Solution: Only encode non-cyclic parts!

Refinement edges: Encode target state twice, relabel

Instantiation edges: Encode source state twice, relabel

fG (o4, 2) → fB′(o4, 2)

Page 59: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

The example TRS

00: iconst 1

01: istore 1

02: aload 0

03: ifnull 17

06: aload 0

07: getfield n

10: astore 0

11: iinc 1, 1

14: goto 2

17: iload 1

18: ireturn

00 |x :o1 |εo1:L(?) o1{p,n}

A

02 |x :o1, r : 1 |εo1:L(?) o1{p,n}

B

03 |x :o1, r : 1 |o1o1:L(?) o1{p,n}

C

03 |x :null, r : 1 |null D

03 |x :o2, r : 1 |o2o2:L(p=o3, n=o4)o3:L(?) o4:L(?)o2%$o3 o2%$o4 o3%$o4o2, o3, o4{p,n}

E 11 |x :o4, r : 1 |εo4:L(?) o4{p,n}

F

02 |x :o4, r : 2 |εo4:L(?) o4{p,n}

G02 |x :o′1, r : i1 |εo′1:L(?) o′1{p,n} i1: [>0]

B′

03 |x :o′1, r : i1 |o′1

o′1:L(?) o′1{p,n} i1: [>0]C ′02 |x :o′4, r : i2 |o

′4

o′4:L(?) o′4{p,n} i2: [>1]

G ′

i2= i1 + 1

1 Only consider SCCs!

2 Transform all edges as before, simplify:

fB′(L(o ′4), i1) → fB′(o ′4, i1 + 1)

o ′4 + 1 > o ′4

3 Termination trivially proven with

JfB′K(x1, x2) = x1 JLK(x1) = x1 + 1

Page 60: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

The example TRS

00: iconst 1

01: istore 1

02: aload 0

03: ifnull 17

06: aload 0

07: getfield n

10: astore 0

11: iinc 1, 1

14: goto 2

17: iload 1

18: ireturn

02 |x :o′1, r : i1 |εo′1:L(?) o′1{p,n} i1: [>0]

B′

03 |x :o′1, r : i1 |o′1

o′1:L(?) o′1{p,n} i1: [>0]C ′02 |x :o′4, r : i2 |o

′4

o′4:L(?) o′4{p,n} i2: [>1]

G ′

i2= i1 + 1

1 Only consider SCCs!

2 Transform all edges as before, simplify:

fB′(L(o ′4), i1) → fB′(o ′4, i1 + 1)

o ′4 + 1 > o ′4

3 Termination trivially proven with

JfB′K(x1, x2) = x1 JLK(x1) = x1 + 1

Page 61: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

The example TRS

00: iconst 1

01: istore 1

02: aload 0

03: ifnull 17

06: aload 0

07: getfield n

10: astore 0

11: iinc 1, 1

14: goto 2

17: iload 1

18: ireturn

02 |x :o′1, r : i1 |εo′1:L(?) o′1{p,n} i1: [>0]

B′

03 |x :o′1, r : i1 |o′1

o′1:L(?) o′1{p,n} i1: [>0]C ′02 |x :o′4, r : i2 |o

′4

o′4:L(?) o′4{p,n} i2: [>1]

G ′

i2= i1 + 1

1 Only consider SCCs!

2 Transform all edges as before, simplify:

fB′(L(o ′4), i1) → fB′(o ′4, i1 + 1)

o ′4 + 1 > o ′4

3 Termination trivially proven with

JfB′K(x1, x2) = x1 JLK(x1) = x1 + 1

Page 62: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

The example TRS

00: iconst 1

01: istore 1

02: aload 0

03: ifnull 17

06: aload 0

07: getfield n

10: astore 0

11: iinc 1, 1

14: goto 2

17: iload 1

18: ireturn

02 |x :o′1, r : i1 |εo′1:L(?) o′1{p,n} i1: [>0]

B′

03 |x :o′1, r : i1 |o′1

o′1:L(?) o′1{p,n} i1: [>0]C ′02 |x :o′4, r : i2 |o

′4

o′4:L(?) o′4{p,n} i2: [>1]

G ′

i2= i1 + 1

1 Only consider SCCs!

2 Transform all edges as before, simplify:

fB′(L(o ′4), i1) → fB′(o ′4, i1 + 1)

o ′4 + 1 > o ′4

3 Termination trivially proven with

JfB′K(x1, x2) = x1 JLK(x1) = x1 + 1

Page 63: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

The example TRS

00: iconst 1

01: istore 1

02: aload 0

03: ifnull 17

06: aload 0

07: getfield n

10: astore 0

11: iinc 1, 1

14: goto 2

17: iload 1

18: ireturn

02 |x :o′1, r : i1 |εo′1:L(?) o′1{p,n} i1: [>0]

B′

03 |x :o′1, r : i1 |o′1

o′1:L(?) o′1{p,n} i1: [>0]C ′02 |x :o′4, r : i2 |o

′4

o′4:L(?) o′4{p,n} i2: [>1]

G ′

i2= i1 + 1

1 Only consider SCCs!

2 Transform all edges as before, simplify:

fB′(L(o ′4), i1) → fB′(o ′4, i1 + 1)

o ′4 + 1 > o ′4

3 Termination trivially proven with

JfB′K(x1, x2) = x1 JLK(x1) = x1 + 1

Page 64: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

AProVE features for Java

Implementation for full Java without reflection and multithreading

Correctness proof w.r.t. JINJA [VITA’10]

Built-in, implicit analyses for nullness, aliasing, sharing, cyclicity

Termination analysis for algorithms

on integers [RTA’10]on acyclic user-defined data structures (trees, DAGs, . . . ) [RTA’10]using recursion [RTA’11]on cyclic data [CAV’12]

by detecting (and ignoring) irrelevant cyclicityby automatically finding and counting markers

Non-termination analysis [FoVeOOS’11]

Page 65: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

AProVE features for Java

Implementation for full Java without reflection and multithreading

Correctness proof w.r.t. JINJA [VITA’10]

Built-in, implicit analyses for nullness, aliasing, sharing, cyclicity

Termination analysis for algorithms

on integers [RTA’10]on acyclic user-defined data structures (trees, DAGs, . . . ) [RTA’10]using recursion [RTA’11]on cyclic data [CAV’12]

by detecting (and ignoring) irrelevant cyclicityby automatically finding and counting markers

Non-termination analysis [FoVeOOS’11]

Page 66: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

AProVE features for Java

Implementation for full Java without reflection and multithreading

Correctness proof w.r.t. JINJA [VITA’10]

Built-in, implicit analyses for nullness, aliasing, sharing, cyclicity

Termination analysis for algorithms

on integers [RTA’10]on acyclic user-defined data structures (trees, DAGs, . . . ) [RTA’10]

using recursion [RTA’11]on cyclic data [CAV’12]

by detecting (and ignoring) irrelevant cyclicityby automatically finding and counting markers

Non-termination analysis [FoVeOOS’11]

Page 67: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

AProVE features for Java

Implementation for full Java without reflection and multithreading

Correctness proof w.r.t. JINJA [VITA’10]

Built-in, implicit analyses for nullness, aliasing, sharing, cyclicity

Termination analysis for algorithms

on integers [RTA’10]on acyclic user-defined data structures (trees, DAGs, . . . ) [RTA’10]using recursion [RTA’11]

on cyclic data [CAV’12]

by detecting (and ignoring) irrelevant cyclicityby automatically finding and counting markers

Non-termination analysis [FoVeOOS’11]

Page 68: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

AProVE features for Java

Implementation for full Java without reflection and multithreading

Correctness proof w.r.t. JINJA [VITA’10]

Built-in, implicit analyses for nullness, aliasing, sharing, cyclicity

Termination analysis for algorithms

on integers [RTA’10]on acyclic user-defined data structures (trees, DAGs, . . . ) [RTA’10]using recursion [RTA’11]on cyclic data [CAV’12]

by detecting (and ignoring) irrelevant cyclicityby automatically finding and counting markers

Non-termination analysis [FoVeOOS’11]

Page 69: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

AProVE features for Java

Implementation for full Java without reflection and multithreading

Correctness proof w.r.t. JINJA [VITA’10]

Built-in, implicit analyses for nullness, aliasing, sharing, cyclicity

Termination analysis for algorithms

on integers [RTA’10]on acyclic user-defined data structures (trees, DAGs, . . . ) [RTA’10]using recursion [RTA’11]on cyclic data [CAV’12]

by detecting (and ignoring) irrelevant cyclicityby automatically finding and counting markers

Non-termination analysis [FoVeOOS’11]

Page 70: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Plans for AProVE

Integrate existing shape analyses

Modularize analysis: pre-compute information for common libraries

Handle bounded integers properly

Extend to C with pointer arithmetic

Asymptotic runtime complexity analysis (via TRS)

Provide to developers as Eclipse plugin

Page 71: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Plans for AProVE

Integrate existing shape analyses

Modularize analysis: pre-compute information for common libraries

Handle bounded integers properly

Extend to C with pointer arithmetic

Asymptotic runtime complexity analysis (via TRS)

Provide to developers as Eclipse plugin

Page 72: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Plans for AProVE

Integrate existing shape analyses

Modularize analysis: pre-compute information for common libraries

Handle bounded integers properly

Extend to C with pointer arithmetic

Asymptotic runtime complexity analysis (via TRS)

Provide to developers as Eclipse plugin

Page 73: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Plans for AProVE

Integrate existing shape analyses

Modularize analysis: pre-compute information for common libraries

Handle bounded integers properly

Extend to C with pointer arithmetic

Asymptotic runtime complexity analysis (via TRS)

Provide to developers as Eclipse plugin

Page 74: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Plans for AProVE

Integrate existing shape analyses

Modularize analysis: pre-compute information for common libraries

Handle bounded integers properly

Extend to C with pointer arithmetic

Asymptotic runtime complexity analysis (via TRS)

Provide to developers as Eclipse plugin

Page 75: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Plans for AProVE

Integrate existing shape analyses

Modularize analysis: pre-compute information for common libraries

Handle bounded integers properly

Extend to C with pointer arithmetic

Asymptotic runtime complexity analysis (via TRS)

Provide to developers as Eclipse plugin

Page 76: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Proving Java Termination: Reducing the Ugly to the Bad

Evaluated on collection of 387 programs (including the TerminationProblem Data Base):

Yes No Fail Run (s)

AProVE 276 88 22 8.4Julia 191 22 174 4.7COSTA 160 0 227 11.0

Won Termination Competition 2012

Symbolic Evaluation Graphs facilitate and simplify complex analyses

Page 77: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Proving Java Termination: Reducing the Ugly to the Bad

Evaluated on collection of 387 programs (including the TerminationProblem Data Base):

Yes No Fail Run (s)

AProVE 276 88 22 8.4Julia 191 22 174 4.7COSTA 160 0 227 11.0

Won Termination Competition 2012

Symbolic Evaluation Graphs facilitate and simplify complex analyses

Page 78: Proving Java Termination: Reducing the Ugly to the Bad · 2015. 4. 16. · Terminator{(Cook, Podelski, Rybalchenko et al., since ’05) CProver{(Kroening, Sharygina, Tsitovich, Wintersteiger,

Proving Java Termination: Reducing the Ugly to the Bad

Evaluated on collection of 387 programs (including the TerminationProblem Data Base):

Yes No Fail Run (s)

AProVE 276 88 22 8.4Julia 191 22 174 4.7COSTA 160 0 227 11.0

Won Termination Competition 2012

Symbolic Evaluation Graphs facilitate and simplify complex analyses