COSTA: A COSt and Termination Analyzer for Java (bytecode) Programs - - PowerPoint PPT Presentation

costa a cost and termination analyzer for java bytecode
SMART_READER_LITE
LIVE PREVIEW

COSTA: A COSt and Termination Analyzer for Java (bytecode) Programs - - PowerPoint PPT Presentation

COSTA: A COSt and Termination Analyzer for Java (bytecode) Programs Elvira Albert and Germ an Puebla Ecole Normale Sup erieure (ENS) Paris, Sept 2, 2011 Elvira Albert The COSTA Group The COSTA Team Staff: E. Albert P. Arenas J.


slide-1
SLIDE 1

COSTA: A COSt and Termination Analyzer for Java (bytecode) Programs Elvira Albert and Germ´ an Puebla

´ Ecole Normale Sup´ erieure (ENS)

Paris, Sept 2, 2011

Elvira Albert The COSTA Group

slide-2
SLIDE 2

The COSTA Team

Staff:

  • E. Albert P. Arenas J. Correas S. Genaim G-Zamalloa G. Puebla Zanardini

UCM UCM UCM UCM UCM UPM UPM

PhD Students:

  • D. Alonso A. Flores
  • A. Masud
  • D. Ramirez J. Rojas
  • G. Roman

UCM UCM UPM UPM UPM UPM

Elvira Albert The COSTA Group

slide-3
SLIDE 3

Outline of the Talk

1 Part 1: Resource Usage Analysis (Elvira)

Introduction to Resource Usage Analysis Overview of COSTA Generation of cost relations Closed-form upper and lower bounds Conclusions Future work Main publications

Elvira Albert The COSTA Group

slide-4
SLIDE 4

Outline of the Talk

1 Part 1: Resource Usage Analysis (Elvira)

Introduction to Resource Usage Analysis Overview of COSTA Generation of cost relations Closed-form upper and lower bounds Conclusions Future work Main publications

2 Part 2: Tool Demo (Germ´

an)

Simple complexity classes Memory consumption Libraries

Elvira Albert The COSTA Group

slide-5
SLIDE 5

Introduction: Resource Usage Analysis

Part 1: Resource Usage Analysis

Elvira Albert The COSTA Group

slide-6
SLIDE 6

Introduction: Resource Usage Analysis

static cost analysis bound the cost of executing program P on any input data x without having to actually run P(x)

Elvira Albert The COSTA Group

slide-7
SLIDE 7

Introduction: Resource Usage Analysis

static cost analysis bound the cost of executing program P on any input data x without having to actually run P(x) reasoning about execution cost is difficult and error-prone cost analysis, or resource analysis or complexity analysis should be automatic

Elvira Albert The COSTA Group

slide-8
SLIDE 8

Introduction: Resource Usage Analysis

static cost analysis bound the cost of executing program P on any input data x without having to actually run P(x) reasoning about execution cost is difficult and error-prone cost analysis, or resource analysis or complexity analysis should be automatic The resources considered

number of executed (bytecode) instructions memory usage billable events (number of calls to a specific method) Termination (it guarantees the existence of an upper bound)

Elvira Albert The COSTA Group

slide-9
SLIDE 9

Kinds of Cost Analysis

Different kinds of cost can be considered:

worst case → upper bound average case → requires probabilistic study best case → lower bound

Elvira Albert The COSTA Group

slide-10
SLIDE 10

Kinds of Cost Analysis

Different kinds of cost can be considered:

worst case → upper bound average case → requires probabilistic study best case → lower bound

Two classes of upper bounds can be considered:

non-asymptotic (or concrete, or micro-analysis) asymptotic (or macro-analysis)

Elvira Albert The COSTA Group

slide-11
SLIDE 11

Kinds of Cost Analysis

Different kinds of cost can be considered:

worst case → upper bound average case → requires probabilistic study best case → lower bound

Two classes of upper bounds can be considered:

non-asymptotic (or concrete, or micro-analysis) asymptotic (or macro-analysis)

Analysis results can be

platform-independent platform-dependent → WCET

Elvira Albert The COSTA Group

slide-12
SLIDE 12

State of the Art in Automatic Cost Analysis

Work on automatic cost analysis dates back to 1975, with the seminal work of Wegbreit. His system, metric was able to compute:

interesting results, but for restricted class of functional programs

Also, the seminal work on abstract interpretation [Cousot & Cousot’77] mentions performance analysis as an application. Since then, a number of analyses and systems have been built which extend the capabilities of cost analysis:

functional programs [Le Metayer’88, Rosendahl’89, Wadler’88, Sands’95, Benzinger’04] logic programs [Debray and Lin’93, Navas et al’07] imperative programs [Adachi et al’79, Albert et al’07]

Elvira Albert The COSTA Group

slide-13
SLIDE 13

A Classical Approach to Cost Analysis

PROGRAM COST ANALYSIS

RELATIONS RECURRENCE

SOLVER FORM CLOSED

A classical approach [Wegbreit’75] to cost analysis consists of:

1 expressing the cost of a program part in terms of other

program parts, thus obtaining recurrence relations

2 solving the relations by obtaining a closed-form for the cost in

terms of the input arguments

Elvira Albert The COSTA Group

slide-14
SLIDE 14

A Classical Approach to Cost Analysis

PROGRAM COST ANALYSIS

RELATIONS RECURRENCE

SOLVER FORM CLOSED

A classical approach [Wegbreit’75] to cost analysis consists of:

1 expressing the cost of a program part in terms of other

program parts, thus obtaining recurrence relations

2 solving the relations by obtaining a closed-form for the cost in

terms of the input arguments The current situation is that Most work has concentrated on the first phase The difficulties of the second phase have been overseen Practical usage of cost analysis requires both! In COSTA we address both phases.

Elvira Albert The COSTA Group

slide-15
SLIDE 15

The COSTA System

COSTA: COSt and Termination analyzer for Java Bytecode INPUT: bytecode + cost model OUPUT: upper bound on resource consumption + termination info

Elvira Albert The COSTA Group

slide-16
SLIDE 16

Worked Example on Cost Analysis

· · · ·

List f(String x[]) { List l=null; int i=0; while (i<x.length) { a

  • l = new

List(g(x,i),l); i += COND ?1:3; } return l; } Integer g(String x[], int i) { int r=0; for(int j=0; j<i; j++) { b

  • Integer t = new

Integer(x[i]); r += t.intValue (); } c

return

new Integer(r); }

Elvira Albert The COSTA Group

slide-17
SLIDE 17

Worked Example on Cost Analysis

· · · ·

List f(String x[]) { List l=null; int i=0; while (i<x.length) { a

  • l = new

List(g(x,i),l); i += COND ?1:3; } return l; } Integer g(String x[], int i) { int r=0; for(int j=0; j<i; j++) { b

  • Integer t = new

Integer(x[i]); r += t.intValue (); } c

return

new Integer(r); }

Elvira Albert The COSTA Group

slide-18
SLIDE 18

Worked Example on Cost Analysis

· · · ·

List f(String x[]) { List l=null; int i=0; while (i<x.length) { a

  • l = new

List(g(x,i),l); i += COND ?1:3; } return l; } Integer g(String x[], int i) { int r=0; for(int j=0; j<i; j++) { b

  • Integer t = new

Integer(x[i]); r += t.intValue (); } c

return

new Integer(r); }

Elvira Albert The COSTA Group

slide-19
SLIDE 19

Worked Example on Cost Analysis

· · · ·

List f(String x[]) { List l=null; int i=0; while (i<x.length) { a

  • l = new

List(g(x,i),l); i += COND ?1:3; } return l; } Integer g(String x[], int i) { int r=0; for(int j=0; j<i; j++) { b

  • Integer t = new

Integer(x[i]); r += t.intValue (); } c

return

new Integer(r); }

Elvira Albert The COSTA Group

slide-20
SLIDE 20

Worked Example on Cost Analysis

· · · ·

List f(String x[]) { List l=null; int i=0; while (i<x.length) { a

  • l = new

List(g(x,i),l); i += COND ?1:3; } return l; } Integer g(String x[], int i) { int r=0; for(int j=0; j<i; j++) { b

  • Integer t = new

Integer(x[i]); r += t.intValue (); } c

return

new Integer(r); }

Elvira Albert The COSTA Group

slide-21
SLIDE 21

Worked Example on Cost Analysis

· · · ·

List f(String x[]) { List l=null; int i=0; while (i<x.length) { a

  • l = new

List(g(x,i),l); i += COND ?1:3; } return l; } Integer g(String x[], int i) { int r=0; for(int j=0; j<i; j++) { b

  • Integer t = new

Integer(x[i]); r += t.intValue (); } c

return

new Integer(r); }

Elvira Albert The COSTA Group

slide-22
SLIDE 22

Worked Example on Cost Analysis

· · · ·

List f(String x[]) { List l=null; int i=0; while (i<x.length) { a

  • l = new

List(g(x,i),l); i += COND ?1:3; } return l; } Integer g(String x[], int i) { int r=0; for(int j=0; j<i; j++) { b

  • Integer t = new

Integer(x[i]); r += t.intValue (); } c

return

new Integer(r); }

Elvira Albert The COSTA Group

slide-23
SLIDE 23

Worked Example on Cost Analysis

· · · ·

List f(String x[]) { List l=null; int i=0; while (i<x.length) { a

  • l = new

List(g(x,i),l); i += COND ?1:3; } return l; } Integer g(String x[], int i) { int r=0; for(int j=0; j<i; j++) { b

  • Integer t = new

Integer(x[i]); r += t.intValue (); } c

return

new Integer(r); }

Elvira Albert The COSTA Group

slide-24
SLIDE 24

Worked Example on Cost Analysis

· · · ·

List f(String x[]) { List l=null; int i=0; while (i<x.length) { a

  • l = new

List(g(x,i),l); i += COND ?1:3; } return l; } Integer g(String x[], int i) { int r=0; for(int j=0; j<i; j++) { b

  • Integer t = new

Integer(x[i]); r += t.intValue (); } c

return

new Integer(r); }

f ( x ) =

b

x ( x + 1 ) 2

+

c

x +

a

x W

  • r

s t

  • C

a s e ( U B )

Elvira Albert The COSTA Group

slide-25
SLIDE 25

Worked Example on Cost Analysis

· · · ·

List f(String x[]) { List l=null; int i=0; while (i<x.length) { a

  • l = new

List(g(x,i),l); i += COND ?1:3; } return l; } Integer g(String x[], int i) { int r=0; for(int j=0; j<i; j++) { b

  • Integer t = new

Integer(x[i]); r += t.intValue (); } c

return

new Integer(r); }

f ( x ) =

b

x ( x + 1 ) 2

+

c

x +

a

x W

  • r

s t

  • C

a s e ( U B ) f ( x ) = b

∗x(x+3)

18

+ c

∗ x

3+ a

∗x

3

B e s t

  • C

a s e ( L B )

Elvira Albert The COSTA Group

slide-26
SLIDE 26

COSTA - Worst/Best Case

· · · ·

Program

Static Analysis

Cost Relations

CRs Solver

Best/Worst Case

Elvira Albert The COSTA Group

slide-27
SLIDE 27

COSTA - Worst/Best Case

· · · ·

Program Program

Static Analysis

Cost Relations

CRs Solver

Best/Worst Case

List f(String x[]) { List l=null; int i=0; while (i<x.length) { a

  • l = new

List(g(x,i),l); i += COND ?1:3; } return l; }

Elvira Albert The COSTA Group

slide-28
SLIDE 28

COSTA - Worst/Best Case

· · · ·

Program

Static Analysis Static Analysis

Cost Relations

CRs Solver

Best/Worst Case

List f(String x[]) { List l=null; int i=0; while (i<x.length) { a

  • l = new

List(g(x,i),l); i += COND ?1:3; } return l; }

Elvira Albert The COSTA Group

slide-29
SLIDE 29

COSTA - Worst/Best Case

· · · ·

Program

Static Analysis

Cost Relations Cost Relations

CRs Solver

Best/Worst Case

List f(String x[]) { List l=null; int i=0; while (i<x.length) { a

  • l = new

List(g(x,i),l); i += COND ?1:3; } return l; } f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) =g(x, i)+ a

+A(x, i′) {i<x, i+1≤i′≤i+3}

g(x, i) =B(i, j)+ c

  • {j=0}

B(i, j) =0 {j≥i} B(i, j) = b

+B(i, j′)

{j<i, j′ = j+1}

Elvira Albert The COSTA Group

slide-30
SLIDE 30

COSTA - Worst/Best Case

· · · ·

Program

Static Analysis

Cost Relations Cost Relations

CRs Solver

Best/Worst Case

List f(String x[]) { List l=null; int i=0; while (i<x.length) { a

  • l = new

List(g(x,i),l); i += COND ?1:3; } return l; } f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) =g(x, i)+ a

+A(x, i′) {i<x, i+1≤i′≤i+3}

g(x, i) =B(i, j)+ c

  • {j=0}

B(i, j) =0 {j≥i} B(i, j) = b

+B(i, j′)

{j<i, j′ = j+1}

Elvira Albert The COSTA Group

slide-31
SLIDE 31

COSTA - Worst/Best Case

· · · ·

Program

Static Analysis

Cost Relations Cost Relations

CRs Solver

Best/Worst Case

List f(String x[]) { List l=null; int i=0; while (i<x.length) { a

  • l = new

List(g(x,i),l); i += COND ?1:3; } return l; } f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) =g(x, i)+ a

+A(x, i′) {i<x, i+1≤i′≤i+3}

g(x, i) =B(i, j)+ c

  • {j=0}

B(i, j) =0 {j≥i} B(i, j) = b

+B(i, j′)

{j<i, j′ = j+1}

Elvira Albert The COSTA Group

slide-32
SLIDE 32

COSTA - Worst/Best Case

· · · ·

Program

Static Analysis

Cost Relations Cost Relations

CRs Solver

Best/Worst Case

List f(String x[]) { List l=null; int i=0; while (i<x.length) { a

  • l = new

List(g(x,i),l); i += COND ?1:3; } return l; } f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) =g(x, i)+ a

+A(x, i′) {i<x, i+1≤i′≤i+3}

g(x, i) =B(i, j)+ c

  • {j=0}

B(i, j) =0 {j≥i} B(i, j) = b

+B(i, j′)

{j<i, j′ = j+1}

Elvira Albert The COSTA Group

slide-33
SLIDE 33

COSTA - Worst/Best Case

· · · ·

Program

Static Analysis

Cost Relations Cost Relations

CRs Solver

Best/Worst Case

List f(String x[]) { List l=null; int i=0; while (i<x.length) { a

  • l = new

List(g(x,i),l); i += COND ?1:3; } return l; } f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) =g(x, i)+ a

+A(x, i′) {i<x, i+1≤i′≤i+3}

g(x, i) =B(i, j)+ c

  • {j=0}

B(i, j) =0 {j≥i} B(i, j) = b

+B(i, j′)

{j<i, j′ = j+1}

Elvira Albert The COSTA Group

slide-34
SLIDE 34

COSTA - Worst/Best Case

· · · ·

Program

Static Analysis

Cost Relations Cost Relations

CRs Solver

Best/Worst Case

Integer g(String x[], int i) { int r=0; for(int j=0; j<i; j++) { b

  • Integer t = new

Integer(x[i]); r += t.intValue (); } c

return

new Integer(r); } f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) =g(x, i)+ a

+A(x, i′) {i<x, i+1≤i′≤i+3}

g(x, i) =B(i, j)+ c

  • {j=0}

B(i, j) =0 {j≥i} B(i, j) = b

+B(i, j′)

{j<i, j′ = j+1}

Elvira Albert The COSTA Group

slide-35
SLIDE 35

COSTA - Worst/Best Case

· · · ·

Program

Static Analysis

Cost Relations Cost Relations

CRs Solver

Best/Worst Case

Integer g(String x[], int i) { int r=0; for(int j=0; j<i; j++) { b

  • Integer t = new

Integer(x[i]); r += t.intValue (); } c

return

new Integer(r); } f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) =g(x, i)+ a

+A(x, i′) {i<x, i+1≤i′≤i+3}

g(x, i) =B(i, j)+ c

  • {j=0}

B(i, j) =0 {j≥i} B(i, j) = b

+B(i, j′)

{j<i, j′ = j+1}

Elvira Albert The COSTA Group

slide-36
SLIDE 36

COSTA - Worst/Best Case

· · · ·

Program

Static Analysis

Cost Relations

CRs Solver CRs Solver

Best/Worst Case

Integer g(String x[], int i) { int r=0; for(int j=0; j<i; j++) { b

  • Integer t = new

Integer(x[i]); r += t.intValue (); } c

return

new Integer(r); } f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) =g(x, i)+ a

+A(x, i′) {i<x, i+1≤i′≤i+3}

g(x, i) =B(i, j)+ c

  • {j=0}

B(i, j) =0 {j≥i} B(i, j) = b

+B(i, j′)

{j<i, j′ = j+1}

Elvira Albert The COSTA Group

slide-37
SLIDE 37

COSTA - Worst/Best Case

· · · ·

Program

Static Analysis

Cost Relations

CRs Solver

Best/Worst Case Best/Worst Case

Integer g(String x[], int i) { int r=0; for(int j=0; j<i; j++) { b

  • Integer t = new

Integer(x[i]); r += t.intValue (); } c

return

new Integer(r); } f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) =g(x, i)+ a

+A(x, i′) {i<x, i+1≤i′≤i+3}

g(x, i) =B(i, j)+ c

  • {j=0}

B(i, j) =0 {j≥i} B(i, j) = b

+B(i, j′)

{j<i, j′ = j+1}

f ( x ) =

b

x

2

+

c

x +

a

x A ( x , i ) =

b

( x − i ) ∗ x +

c

( x − i ) +

a

x g ( x , i ) =

b

i +

c

  • B

( i , j ) =

b

( i − j ) W

  • r

s t

  • C

a s e ( U B )

Elvira Albert The COSTA Group

slide-38
SLIDE 38

COSTA - Worst/Best Case

· · · ·

Program

Static Analysis Static Analysis

Cost Relations

CRs Solver CRs Solver

Best/Worst Case

Integer g(String x[], int i) { int r=0; for(int j=0; j<i; j++) { b

  • Integer t = new

Integer(x[i]); r += t.intValue (); } c

return

new Integer(r); } f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) =g(x, i)+ a

+A(x, i′) {i<x, i+1≤i′≤i+3}

g(x, i) =B(i, j)+ c

  • {j=0}

B(i, j) =0 {j≥i} B(i, j) = b

+B(i, j′)

{j<i, j′ = j+1}

Elvira Albert The COSTA Group

slide-39
SLIDE 39

Solving CRs - Computer Algebra Systems

· · · · f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) =g(x, i)+ a

+A(x, i′) {i<x, i + 1≤i′≤i+3}

g(x, i) =B(i, j)+ c

  • {j=0}

B(i, j) =0 {j≥i} B(i, j) = b

+B(i, j′)

{j<i, j′ = j+1}

Elvira Albert The COSTA Group

slide-40
SLIDE 40

Solving CRs - Computer Algebra Systems

· · · · f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) =g(x, i)+ a

+A(x, i′) {i<x, i + 1≤i′≤i+3}

g(x, i) =B(i, j)+ c

  • {j=0}

B(i, j) =0 {j≥i} B(i, j) = b

+B(i, j′)

{j<i, j′ = j+1}

Why not using directly Computer Algebra Systems?

Elvira Albert The COSTA Group

slide-41
SLIDE 41

Solving CRs - Computer Algebra Systems

· · · · f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) =g(x, i)+ a

+A(x, i′) {i<x, i + 1≤i′≤i+3}

g(x, i) =B(i, j)+ c

  • {j=0}

B(i, j) =0 {j≥i} B(i, j) = b

+B(i, j′)

{j<i, j′ = j+1}

Why not using directly Computer Algebra Systems?

CAS can obtain an exact closed-form solution for: P(0) = 0 P(n) = E + P(n − 1) + · · · + P(n − 1) deterministic, 1 base-case, 1 recursive case, 1 argument

Elvira Albert The COSTA Group

slide-42
SLIDE 42

Solving CRs - Computer Algebra Systems

· · · · f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) =g(x, i)+ a

+A(x, i′) {i<x, i + 1≤i′≤i+3}

g(x, i) =B(i, j)+ c

  • {j=0}

B(i, j) =0 {j≥i} B(i, j) = b

+B(i, j′)

{j<i, j′ = j+1}

Why not using directly Computer Algebra Systems? CRs are not deterministic

Elvira Albert The COSTA Group

slide-43
SLIDE 43

Solving CRs - Computer Algebra Systems

· · · · f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) =g(x, i)+ a

+A(x, i′) {i<x, i + 1≤i′≤i+3}

g(x, i) =B(i, j)+ c

  • {j=0}

B(i, j) =0 {j≥i} B(i, j) = b

+B(i, j′)

{j<i, j′ = j+1}

Why not using directly Computer Algebra Systems? CRs are not deterministic

Two possible runs for A(10, 0) A(10, 0) → A(10, 1) → A(10, 4) → · · · A(10, 0) → A(10, 4) → A(10, 6) → · · ·

Elvira Albert The COSTA Group

slide-44
SLIDE 44

Solving CRs - Computer Algebra Systems

· · · · f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) =g(x, i)+ a

+A(x, i′) {i<x, i + 1≤i′≤i+3}

g(x, i) =B(i, j)+ c

  • {j=0}

B(i, j) =0 {j≥i} B(i, j) = b

+B(i, j′)

{j<i, j′ = j+1}

Why not using directly Computer Algebra Systems? CRs are not deterministic CRs have multiple arguments

Elvira Albert The COSTA Group

slide-45
SLIDE 45

Solving CRs - Computer Algebra Systems

· · · · f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) =g(x, i)+ a

+A(x, i′) {i<x, i + 1≤i′≤i+3}

g(x, i) =B(i, j)+ c

  • {j=0}

B(i, j) =0 {j≥i} B(i, j) = b

+B(i, j′)

{j<i, j′ = j+1}

Why not using directly Computer Algebra Systems? CRs are not deterministic CRs have multiple arguments CRs have multiple (not mutually exclusive) equations

Elvira Albert The COSTA Group

slide-46
SLIDE 46

Solving CRs - Computer Algebra Systems

· · · · f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) =g(x, i)+ a

+A(x, i′) {i<x, i + 1≤i′≤i+3}

g(x, i) =B(i, j)+ c

  • {j=0}

B(i, j) =0 {j≥i} B(i, j) = b

+B(i, j′)

{j<i, j′ = j+1}

Why not using directly Computer Algebra Systems? CRs are not deterministic CRs have multiple arguments CRs have multiple (not mutually exclusive) equations Thus, CRs often do not have an exact solution

Elvira Albert The COSTA Group

slide-47
SLIDE 47

Solving CRs - Computer Algebra Systems

· · · · f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) =g(x, i)+ a

+A(x, i′) {i<x, i + 1≤i′≤i+3}

g(x, i) =B(i, j)+ c

  • {j=0}

B(i, j) =0 {j≥i} B(i, j) = b

+B(i, j′)

{j<i, j′ = j+1}

Why not using directly Computer Algebra Systems? CRs are not deterministic CRs have multiple arguments CRs have multiple (not mutually exclusive) equations Thus, CRs often do not have an exact solution

CAS can obtain an exact closed-form solution for: P(0) = 0 P(n) = E + P(n − 1) + · · · + P(n − 1) deterministic, 1 base-case, 1 recursive case, 1 argument

Elvira Albert The COSTA Group

slide-48
SLIDE 48

Solving CRs (UBs) - PUBS

· · · · f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) =g(x, i)+ a

+A(x, i′)

{i<x, i + 1≤i′≤i+3} g(x, i) =B(i, j)+ c

  • {j=0}

B(i, j) =0 {j≥i} B(i, j) = b

+B(i, j′)

{j<i, j′ = j+1}

Elvira Albert The COSTA Group

slide-49
SLIDE 49

Solving CRs (UBs) - PUBS

· · · · f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) =g(x, i)+ a

+A(x, i′)

{i<x, i + 1≤i′≤i+3} g(x, i) =B(i, j)+ c

  • {j=0}

B(i, j) =0 {j≥i} B(i, j) = b

+B(i, j′)

{j<i, j′ = j+1}

  • An evaluation for B(i0, j0) looks like:

b

  • b
  • b
  • b
  • b
  • Elvira Albert

The COSTA Group

slide-50
SLIDE 50

Solving CRs (UBs) - PUBS

· · · · f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) =g(x, i)+ a

+A(x, i′)

{i<x, i + 1≤i′≤i+3} g(x, i) =B(i, j)+ c

  • {j=0}

B(i, j) =0 {j≥i} B(i, j) = b

+B(i, j′)

{j<i, j′ = j+1}

  • An evaluation for B(i0, j0) looks like:

b

  • b
  • b
  • b
  • b
  • How many

has this chain ?

b

  • Elvira Albert

The COSTA Group

slide-51
SLIDE 51

Solving CRs (UBs) - PUBS

· · · · f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) =g(x, i)+ a

+A(x, i′)

{i<x, i + 1≤i′≤i+3} g(x, i) =B(i, j)+ c

  • {j=0}

B(i, j) =0 {j≥i} B(i, j) = b

+B(i, j′)

{j<i, j′ = j+1}

  • An evaluation for B(i0, j0) looks like:

b

  • b
  • b
  • b
  • b
  • How many

has this chain ?

b

  • ϕ

Elvira Albert The COSTA Group

slide-52
SLIDE 52

Solving CRs (UBs) - PUBS

· · · · f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) =g(x, i)+ a

+A(x, i′)

{i<x, i + 1≤i′≤i+3} g(x, i) =B(i, j)+ c

  • {j=0}

B(i, j) =0 {j≥i} B(i, j) = b

+B(i, j′)

{j<i, j′ = j+1}

  • An evaluation for B(i0, j0) looks like:

b

  • b
  • b
  • b
  • b
  • How many

has this chain ?

b

  • ϕ

∃ˆ f .∀i, j, j′. ϕ | = ˆ f (i, j) ≥ 0 ∧ ˆ f (i, j) − ˆ f (i, j′) ≥ 1 Ranking function

Elvira Albert The COSTA Group

slide-53
SLIDE 53

Solving CRs (UBs) - PUBS

· · · · f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) =g(x, i)+ a

+A(x, i′)

{i<x, i + 1≤i′≤i+3} g(x, i) =B(i, j)+ c

  • {j=0}

B(i, j) =0 {j≥i} B(i, j) = b

+B(i, j′)

{j<i, j′ = j+1}

  • An evaluation for B(i0, j0) looks like:

b

  • b
  • b
  • b
  • b
  • How many

has this chain ?

b

  • ˆ

f (i0, j0) = nat(i0 − j0)

Elvira Albert The COSTA Group

slide-54
SLIDE 54

Solving CRs (UBs) - PUBS

· · · · f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) =g(x, i)+ a

+A(x, i′)

{i<x, i + 1≤i′≤i+3} g(x, i) =B(i, j)+ c

  • {j=0}

B(i, j) =0 {j≥i} B(i, j) = b

+B(i, j′)

{j<i, j′ = j+1}

  • An evaluation for B(i0, j0) looks like:

b

  • b
  • b
  • b
  • b
  • How many

has this chain ?

b

  • ˆ

f (i0, j0) = nat(i0 − j0) B(i0, j0) = ∗ Worst-Case nat(i0 − j0)

b

  • Elvira Albert

The COSTA Group

slide-55
SLIDE 55

Solving CRs (UBs) - PUBS

· · · · f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) =g(x, i)+ a

+A(x, i′)

{i<x, i + 1≤i′≤i+3} g(x, i) =B(i, j)+ c

  • {j=0}

B(i, j) =0 {j≥i} B(i, j) = b

+B(i, j′)

{j<i, j′ = j+1}

  • An evaluation for B(i0, j0) looks like:

b

  • b
  • b
  • b
  • b
  • How many

has this chain ?

b

  • ˆ

f (i0, j0) = nat(i0 − j0) B(i0, j0) = ∗ Worst-Case 2nat(i0−j0)

b

  • +B(i, j′)

Elvira Albert The COSTA Group

slide-56
SLIDE 56

Solving CRs (UBs) - PUBS

· · · · f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) =g(x, i)+ a

+A(x, i′)

{i<x, i + 1≤i′≤i+3} g(x, i) =B(i, j)+ c

  • {j=0}

Elvira Albert The COSTA Group

slide-57
SLIDE 57

Solving CRs (UBs) - PUBS

· · · · f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) =g(x, i)+ a

+A(x, i′)

{i<x, i + 1≤i′≤i+3} g(x, i) = b

∗ nat(i−j)+ c

  • {j=0}

Elvira Albert The COSTA Group

slide-58
SLIDE 58

Solving CRs (UBs) - PUBS

· · · · f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) =g(x, i)+ a

+A(x, i′)

{i<x, i + 1≤i′≤i+3} g(x, i) = b

∗ nat(i−j)+ c

  • {j=0}

g(x0, i0) = b

∗nat(i0)+ c

  • Worst-Case for g

Elvira Albert The COSTA Group

slide-59
SLIDE 59

Solving CRs (UBs) - PUBS

· · · · f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) =g(x, i)+ a

+A(x, i′)

{i<x, i + 1≤i′≤i+3} g(x, i) = b

∗ nat(i−j)+ c

  • {j=0}

g(x0, i0) = b

∗nat(i0)+ c

  • Worst-Case for g

Elvira Albert The COSTA Group

slide-60
SLIDE 60

Solving CRs (UBs) - PUBS

· · · · f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) = b

∗ nat(i)+ c + a +A(x, i′) {i<x, i + 1≤i′≤i+3}

g(x, i) = b

∗ nat(i−j)+ c

  • {j=0}

Elvira Albert The COSTA Group

slide-61
SLIDE 61

Solving CRs (UBs) - PUBS

· · · · f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) = b

∗ nat(i)+ c + a +A(x, i′) {i<x, i + 1≤i′≤i+3}

g(x, i) = b

∗ nat(i−j)+ c

  • {j=0}
  • An evaluation for A(x0, i0) looks like:

Elvira Albert The COSTA Group

slide-62
SLIDE 62

Solving CRs (UBs) - PUBS

· · · · f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) = b

∗ nat(i)+ c + a +A(x, i′) {i<x, i + 1≤i′≤i+3}

g(x, i) = b

∗ nat(i−j)+ c

  • {j=0}
  • An evaluation for A(x0, i0) looks like:
  • There are at most nat(x0 − i0) circles (ranking function)

Elvira Albert The COSTA Group

slide-63
SLIDE 63

Solving CRs (UBs) - PUBS

· · · · f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) = b

∗ nat(i)+ c + a +A(x, i′) {i<x, i + 1≤i′≤i+3}

g(x, i) = b

∗ nat(i−j)+ c

  • {j=0}
  • An evaluation for A(x0, i0) looks like:
  • There are at most nat(x0 − i0) circles (ranking function)

Elvira Albert The COSTA Group

slide-64
SLIDE 64

Solving CRs (UBs) - PUBS

· · · · f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) = b

∗ nat(i)+ c + a +A(x, i′) {i<x, i + 1≤i′≤i+3}

g(x, i) = b

∗ nat(i−j)+ c

  • {j=0}
  • An evaluation for A(x0, i0) looks like:
  • There are at most nat(x0 − i0) circles (ranking function)
  • Worst-case is

∗nat(x0 − i0)

Elvira Albert The COSTA Group

slide-65
SLIDE 65

Solving CRs (UBs) - PUBS

· · · · f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) = b

∗ nat(i)+ c + a +A(x, i′) {i<x, i + 1≤i′≤i+3}

g(x, i) = b

∗ nat(i−j)+ c

  • {j=0}
  • An evaluation for A(x0, i0) looks like:
  • There are at most nat(x0 − i0) circles (ranking function)
  • Worst-case is

∗nat(x0 − i0)

What is the maximum value that i can take in terms

  • f the initial values x0, i0?. It is x0.

Inferring box (or maximizing expression) ϕ

Elvira Albert The COSTA Group

slide-66
SLIDE 66

Solving CRs (UBs) - PUBS

· · · · f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) = b

∗ nat(i)+ c + a +A(x, i′) {i<x, i + 1≤i′≤i+3}

g(x, i) = b

∗ nat(i−j)+ c

  • {j=0}
  • An evaluation for A(x0, i0) looks like:
  • There are at most nat(x0 − i0) circles (ranking function)
  • Worst-case is

∗nat(x0 − i0)

What is the maximum value that i can take in terms

  • f the initial values x0, i0?. It is x0.

Infer an invariant A(x0, i0) A(x, i), Ψ Inferring box (or maximizing expression) ϕ

Elvira Albert The COSTA Group

slide-67
SLIDE 67

Solving CRs (UBs) - PUBS

· · · · f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) = b

∗ nat(i)+ c + a +A(x, i′) {i<x, i + 1≤i′≤i+3}

g(x, i) = b

∗ nat(i−j)+ c

  • {j=0}
  • An evaluation for A(x0, i0) looks like:
  • There are at most nat(x0 − i0) circles (ranking function)
  • Worst-case is

∗nat(x0 − i0)

What is the maximum value that i can take in terms

  • f the initial values x0, i0?. It is x0.

Infer an invariant A(x0, i0) A(x, i), Ψ Use (parametric) integer programming to maximize i w.r.t Ψ ∧ ϕ and the parameters x0, i0. Inferring box (or maximizing expression) ϕ

Elvira Albert The COSTA Group

slide-68
SLIDE 68

Solving CRs (UBs) - PUBS

· · · · f (x) =A(x, i) {i=0, x≥0} A(x, i) =0 {i≥x} A(x, i) = b

∗ nat(i)+ c + a +A(x, i′) {i<x, i + 1≤i′≤i+3}

g(x, i) = b

∗ nat(i−j)+ c

  • {j=0}
  • An evaluation for A(x0, i0) looks like:
  • There are at most nat(x0 − i0) circles (ranking function)
  • A(x0, i0) = ( b

∗nat(x0)+ c + a )∗nat(x0−i0)

Elvira Albert The COSTA Group

slide-69
SLIDE 69

Conclusions

Cost and Termination

Termination: find ranking functions for all loops in the program Termination → Bounded resource consumption Cost (for number of instructions) → Termination

Elvira Albert The COSTA Group

slide-70
SLIDE 70

Conclusions

Cost and Termination

Termination: find ranking functions for all loops in the program Termination → Bounded resource consumption Cost (for number of instructions) → Termination

COSTA has been the first cost and termination analyzer for sequential Java Bytecode

It deals with Java libraries It checks termination and computes upper bounds It allows assertions on upper bounds (and thus termination)

Elvira Albert The COSTA Group

slide-71
SLIDE 71

Conclusions

Cost and Termination

Termination: find ranking functions for all loops in the program Termination → Bounded resource consumption Cost (for number of instructions) → Termination

COSTA has been the first cost and termination analyzer for sequential Java Bytecode

It deals with Java libraries It checks termination and computes upper bounds It allows assertions on upper bounds (and thus termination)

PUBS has been the first generic cost relation solver

It is written in Prolog and uses PPL It can be connected to Maxima for further precision in some cases It is currently able to compute upper and lower bounds

Elvira Albert The COSTA Group

slide-72
SLIDE 72

Current Projects

European Projects:

HATS(March 1, 2009 - February 28, 2013) “Highly Adaptable and Trustworthy Software using Formal Methods” UPM (Germ´ an Puebla) + UCM (Elvira Albert, Lou 83)

MEC Projects:

DOVES (January 1, 2009 - December 31, 2013) “Development Of Verifiable and Efficient Software” UPM (Manuel Hermenegildo)

CAM Projects:

PROMETIDOS-CM (Jan. 2010 - Dec. 2013) “Madrid Program in Rigorous Methods for the Development of Software” UCM (Francisco J. L´

  • pez-Fraguas)

Elvira Albert The COSTA Group

slide-73
SLIDE 73

Current and Future Work

Some advanced topics: Modular and incremental analysis Support dynamically allocated data (numeric and reference fields) in cost/termination analysis of OO bytecode Asymptotic upper bound Checking of resource usage specifications Present and future work: Handle concurrency during static analysis

X10 language (Java-like syntax, different concurrency) ABS (succesor of Creol)

Combine static and dynamic techniques Combine testing and resource usage

Elvira Albert The COSTA Group

slide-74
SLIDE 74

Main Publications of COSTA

ESOP’07/LNCS + TCS’11/Elsevier: Generation of cost relations SAS’08/LNCS + JAR’11/Springer: Closed-form upper bounds ISMM’07/ACM + ISMM’09/ACM + ISMM’10/ACM: Memory consumption FM’09/LNCS + SAS’10/LNCS: Treatment of Heap-Allocated Data FOPARA’09/LNCS: Checking upper bounds APLAS’09/LNCS: Asymptotic bounds VMCAI’11/LNCS: Lower-bounds LCTES’11/ACM: Concurrency in cost analysis FM’11/LNCS: Combination of static and dynamic techniques PEPM’11/ACM: Verified resource guarantees Several tool demos and system descriptions: Bytecode, PROLE, etc.

Elvira Albert The COSTA Group