Top Banner
Alternation for Termination William Harris, Akash Lal, Aditya Nori Sriram Rajamani 1 1 2 2 2 2
37

Alternation for Termination

Feb 10, 2016

Download

Documents

slade

Alternation for Termination. 1. 2. 2. 2. William Harris , Akash Lal , Aditya Nori Sriram Rajamani. 1. 2. Termination bugs are a real problem in systems and application code. A Quick Search “bug code hangs”:. “Gecko mediaplayer hangs the browser” - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Alternation for Termination

Alternation for Termination

William Harris, Akash Lal, Aditya NoriSriram Rajamani

1

1

2

2

2

2

Page 2: Alternation for Termination

Termination bugs are a real problem in systems and application code.

Page 3: Alternation for Termination

“Gecko mediaplayer hangs the browser”

“Eclipse hangs after 5 minutes or so of working”

“BUG: Silverlight makes browser hang after BeginSaveChanges on some machines”

“BUG: VB Hangs While Automating Excel Using OLE Control”

A Quick Search “bug code hangs”:

Page 4: Alternation for Termination

Key challenge to proving termination:

Analyzing the context of a loop

Page 5: Alternation for Termination

An Example with Non-Trivial Contextf(int d, z) { int x, y;

while (x > 0 && y > 0) {if (*) {

x := x – d;y := *;z := z – 1;

} else {y := y – d;

}} }

main() { int k; int z = 1; while (z < k) { z := 2 * z; }

f(1, z); f(2, z);}

Page 6: Alternation for Termination

Local Termination Provers

For a fixed over-approximation of a loop, find a proof of termination

Page 7: Alternation for Termination

Local Provers Succeeding

while (x > 0 && y > 0) {assume(d > 0);if (*) {

x := x – d;y := *;z := z – 1;

} else {y := y – d;

}}

yx

Page 8: Alternation for Termination

Local Provers Failingf(int d) {

int x, y;while (x > 0 && y > 0) { assume(d > 0);

if (*) {x := x – d;y := *;z := z – 1;

} else {y := y – d;

} } }

main() { f(1); f(2);}??

Page 9: Alternation for Termination

Transition Invariants

From stem and cycle of a loop,guess and check a proof of termination

Page 10: Alternation for Termination

Advantage of Transition Invariants

A stem to a loop can include information about the loop’s context.

Page 11: Alternation for Termination

Transition Invariants Succeedingf(int d) {

while (x > 0 && y > 0) {if (*) {

x := x – d;y := *;

} else {y := y – d;

}} }

main() {f(1);f(2); }

while (x > 0 && y > 0) {

x := x – d; y := *;

}

x

Page 12: Alternation for Termination

Transition Invariants Succeedingf(int d) {

while (x > 0 && y > 0) {if (*) {

x := x – d;y := *;

} else {y := y – d;

}} }

main() {f(1);f(2); }

while (x > 0 && y > 0) {

y := y - d;}

y

Page 13: Alternation for Termination

Disadvantage of Transition Invariants

Stem and cycle can lead to incorrect guesses for proof of termination.

Page 14: Alternation for Termination

Transition Invariants Failingf(int d) {f(int d, int z) { int x, y;

while (x > 0 && y > 0) {if (*) {

x := x – d;y := *;z := z – 1;

} else {y := y – d;

} } }

main() { int k; int z = 1; while (z < k) { z := 2 * z; }

f(1); f(1, z); f(2); f(2, z);}

Page 15: Alternation for Termination

Key Insight of TREX

From cycles through a loop,infer invariants for proving termination.

Page 16: Alternation for Termination

Context Analysis via TREXf(int d, z) { int x, y;

while (x > 0 && y > 0) {assume(d > 0);if (*) {

x := x – d;y := *;z := z – 1;

} else {y := y – d;

} } }

main() { int k; int z = 1; while (z < k) { z := 2 * z; }

f(1, z); f(2, z);}

Page 17: Alternation for Termination

Payoff of TREX’s Approach

TREX can apply local provers to find a proof of termination quickly

Page 18: Alternation for Termination

Analysis via TREXf(int d, z) { int x, y;

while (x > 0 && y > 0) {assume(d > 0);if (*) {

x := x – d;y := *;z := z – 1;

} else {y := y – d;

} } }

main() { int k; int z = 1; while (z < k) { z := 2 * z; }

f(1, z); f(2, z);}

x, y

Page 19: Alternation for Termination

TREX in More Detail

•TREX by example

•Experiments

Page 20: Alternation for Termination

TREX iterativelyfinds a proof of termination,or finds a counterexample to termination, or refines stronger program invariants

The TREX Algorithm

Page 21: Alternation for Termination

TREX Iteration Step 1

Find a proof of terminationby applying a

local termination prover

Page 22: Alternation for Termination

f(int d, z) { int x, y;

while (x > 0 && y > 0) {if (*) {

x := x – d;y := *;z := z – 1;

} else {y := y – d;

} } }

main() { int k; int z = 1; while (z < k) { z := 2 * z; }

f(1, z); f(2, z);}

TREX Iteration Step 1

??

Page 23: Alternation for Termination

TREX Iteration Step 2

If local prover fails, then find a counterexample cycle

Page 24: Alternation for Termination

TREX Iteration Step 2f(int d, z) { int x, y;

while (x > 0 && y > 0) {if (*) {

x := x – d;y := *;z := z – 1;

} else {y := y – d;

} } }

main() { int k; int z = 1; while (z < k) { z := 2 * z; }

f(1, z); f(2, z);}

while (x > 0 && y > 0) { y := y – d;}

Page 25: Alternation for Termination

TREX Iteration Step 3

From the counterexample cycle,find a sufficient condition for

non-termination by applying anon-termination prover (TNT)

Page 26: Alternation for Termination

Applying a Non-Termination Prover

while (x > 0 && y > 0) { y := y – d;}

Non-termination if:y > 0 && d <= 0

Page 27: Alternation for Termination

TREX Iteration Step 4

Check if the sufficient conditionis reachable

Page 28: Alternation for Termination

TREX Iteration Step 4f(int d, z) { int x, y;

while (x > 0 && y > 0) {assert(d > 0);if (*) {

x := x – d;y := *;z := z – 1;

} else {y := y – d;

} } }

main() { int k; int z = 1; while (z < k) { z := 2 * z; }

f(1, z); f(2, z);}

while (x > 0 && y > 0) { y := y – d;}

Non-termination if:y > 0 && d <= 0

Page 29: Alternation for Termination

TREX Iteration Step 5

If the sufficient condition is unreachable, then assume this as an invariant.

Page 30: Alternation for Termination

TREX Iteration Step 5f(int d, z) { int x, y;

while (x > 0 && y > 0) {assert(d > 0);if (*) {

x := x – d;y := *;z := z – 1;

} else {y := y – d;

} } }

main() { int k; int z = 1; while (z < k) { z := 2 * z; }

f(1, z); f(2, z);}

assume(d > 0);

x, y

Page 31: Alternation for Termination

Experiments

Windows Vista driver snippets

Page 32: Alternation for Termination

Vista Driver SnippetsDriverName

TREX time (s) Terminator* time (s) TREX speedup

1 13.8 32.1 2.3

2 15.3 48.0 3.1

3 7.9 5.9 0.7

4 3.1 12.3 3.9

5 6.4 8.8 1.4

6 3.0 13.8 4.6

7 10.2 11.8 1.2

8 9.4 11.0 1.2

9 TO TO ---

10 2.5 10.3 4.1

Page 33: Alternation for Termination

Conclusion

TREX proves termination by using cycles through a loop to infer useful

program invariants

Page 34: Alternation for Termination

Extra slides

Page 35: Alternation for Termination

Transition Invariants Succeedingf(int d) {

while (x > 0 && y > 0) {if (*) {

x := x – d;y := *;

} else {y := y – d;

}} }

main() {f(1);f(2); }

x, y

Page 36: Alternation for Termination

Transition Invariants Failingf(int d) {f(int d, int z) { int x, y;

while (x > 0 && y > 0) {if (*) {

x := x – d;y := *;z := z – 1;

} else {y := y – d;

} } }

main() { int k; int z = 1; while (z < k) { z := 2 * z; }

f(1); f(1, z); f(2); f(2, z);}

while (x > 0 && y > 0) {assume(d = 1 && z = 1);if (*) {

x := x – d;y := *;z := z – 1;

} }

z - 1z = 1;

f(1, z);

Page 37: Alternation for Termination

Transition Invariants Failingf(int d) {f(int d, int z) { int x, y;

while (x > 0 && y > 0) {if (*) {

x := x – d;y := *;z := z – 1;

} else {y := y – d;

} } }

main() { int k; int z = 1; while (z < k) { z := 2 * z; }

f(1); f(1, z); f(2); f(2, z);}

while (x > 0 && y > 0) {assume(d = 1 && z = 2);if (*) {

x := x – d;y := *;z := z – 1;

} }

z - 2z = 1; z := 2 * z;

f(1, z);