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
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.
Elvira Albert The COSTA Group
UCM UCM UCM UCM UCM UPM UPM
UCM UCM UPM UPM UPM UPM
Elvira Albert The COSTA Group
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
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´
Simple complexity classes Memory consumption Libraries
Elvira Albert The COSTA Group
Elvira Albert The COSTA Group
Elvira Albert The COSTA Group
Elvira Albert The COSTA Group
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
worst case → upper bound average case → requires probabilistic study best case → lower bound
Elvira Albert The COSTA Group
worst case → upper bound average case → requires probabilistic study best case → lower bound
non-asymptotic (or concrete, or micro-analysis) asymptotic (or macro-analysis)
Elvira Albert The COSTA Group
worst case → upper bound average case → requires probabilistic study best case → lower bound
non-asymptotic (or concrete, or micro-analysis) asymptotic (or macro-analysis)
platform-independent platform-dependent → WCET
Elvira Albert The COSTA Group
interesting results, but for restricted class of functional programs
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
PROGRAM COST ANALYSIS
RELATIONS RECURRENCE
SOLVER FORM CLOSED
1 expressing the cost of a program part in terms of other
2 solving the relations by obtaining a closed-form for the cost in
Elvira Albert The COSTA Group
PROGRAM COST ANALYSIS
RELATIONS RECURRENCE
SOLVER FORM CLOSED
1 expressing the cost of a program part in terms of other
2 solving the relations by obtaining a closed-form for the cost in
Elvira Albert The COSTA Group
Elvira Albert The COSTA Group
List f(String x[]) { List l=null; int i=0; while (i<x.length) { a
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(x[i]); r += t.intValue (); } c
return
new Integer(r); }
Elvira Albert The COSTA Group
List f(String x[]) { List l=null; int i=0; while (i<x.length) { a
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(x[i]); r += t.intValue (); } c
return
new Integer(r); }
Elvira Albert The COSTA Group
List f(String x[]) { List l=null; int i=0; while (i<x.length) { a
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(x[i]); r += t.intValue (); } c
return
new Integer(r); }
Elvira Albert The COSTA Group
List f(String x[]) { List l=null; int i=0; while (i<x.length) { a
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(x[i]); r += t.intValue (); } c
return
new Integer(r); }
Elvira Albert The COSTA Group
List f(String x[]) { List l=null; int i=0; while (i<x.length) { a
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(x[i]); r += t.intValue (); } c
return
new Integer(r); }
Elvira Albert The COSTA Group
List f(String x[]) { List l=null; int i=0; while (i<x.length) { a
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(x[i]); r += t.intValue (); } c
return
new Integer(r); }
Elvira Albert The COSTA Group
List f(String x[]) { List l=null; int i=0; while (i<x.length) { a
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(x[i]); r += t.intValue (); } c
return
new Integer(r); }
Elvira Albert The COSTA Group
List f(String x[]) { List l=null; int i=0; while (i<x.length) { a
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(x[i]); r += t.intValue (); } c
return
new Integer(r); }
Elvira Albert The COSTA Group
List f(String x[]) { List l=null; int i=0; while (i<x.length) { a
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(x[i]); r += t.intValue (); } c
return
new Integer(r); }
b
x ( x + 1 ) 2
c
a
Elvira Albert The COSTA Group
List f(String x[]) { List l=null; int i=0; while (i<x.length) { a
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(x[i]); r += t.intValue (); } c
return
new Integer(r); }
b
x ( x + 1 ) 2
c
a
∗x(x+3)
18
∗ x
3+ a
∗x
3
Elvira Albert The COSTA Group
Program
Cost Relations
Best/Worst Case
Elvira Albert The COSTA Group
Program Program
Cost Relations
Best/Worst Case
List f(String x[]) { List l=null; int i=0; while (i<x.length) { a
List(g(x,i),l); i += COND ?1:3; } return l; }
Elvira Albert The COSTA Group
Program
Cost Relations
Best/Worst Case
List f(String x[]) { List l=null; int i=0; while (i<x.length) { a
List(g(x,i),l); i += COND ?1:3; } return l; }
Elvira Albert The COSTA Group
Program
Cost Relations Cost Relations
Best/Worst Case
List f(String x[]) { List l=null; int i=0; while (i<x.length) { a
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
B(i, j) =0 {j≥i} B(i, j) = b
+B(i, j′)
{j<i, j′ = j+1}
Elvira Albert The COSTA Group
Program
Cost Relations Cost Relations
Best/Worst Case
List f(String x[]) { List l=null; int i=0; while (i<x.length) { a
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
B(i, j) =0 {j≥i} B(i, j) = b
+B(i, j′)
{j<i, j′ = j+1}
Elvira Albert The COSTA Group
Program
Cost Relations Cost Relations
Best/Worst Case
List f(String x[]) { List l=null; int i=0; while (i<x.length) { a
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
B(i, j) =0 {j≥i} B(i, j) = b
+B(i, j′)
{j<i, j′ = j+1}
Elvira Albert The COSTA Group
Program
Cost Relations Cost Relations
Best/Worst Case
List f(String x[]) { List l=null; int i=0; while (i<x.length) { a
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
B(i, j) =0 {j≥i} B(i, j) = b
+B(i, j′)
{j<i, j′ = j+1}
Elvira Albert The COSTA Group
Program
Cost Relations Cost Relations
Best/Worst Case
List f(String x[]) { List l=null; int i=0; while (i<x.length) { a
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
B(i, j) =0 {j≥i} B(i, j) = b
+B(i, j′)
{j<i, j′ = j+1}
Elvira Albert The COSTA Group
Program
Cost Relations Cost Relations
Best/Worst Case
Integer g(String x[], int i) { int r=0; for(int j=0; j<i; j++) { b
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
B(i, j) =0 {j≥i} B(i, j) = b
+B(i, j′)
{j<i, j′ = j+1}
Elvira Albert The COSTA Group
Program
Cost Relations Cost Relations
Best/Worst Case
Integer g(String x[], int i) { int r=0; for(int j=0; j<i; j++) { b
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
B(i, j) =0 {j≥i} B(i, j) = b
+B(i, j′)
{j<i, j′ = j+1}
Elvira Albert The COSTA Group
Program
Cost Relations
Best/Worst Case
Integer g(String x[], int i) { int r=0; for(int j=0; j<i; j++) { b
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
B(i, j) =0 {j≥i} B(i, j) = b
+B(i, j′)
{j<i, j′ = j+1}
Elvira Albert The COSTA Group
Program
Cost Relations
Best/Worst Case Best/Worst Case
Integer g(String x[], int i) { int r=0; for(int j=0; j<i; j++) { b
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
B(i, j) =0 {j≥i} B(i, j) = b
+B(i, j′)
{j<i, j′ = j+1}
b
2
c
a
b
c
a
b
c
b
Elvira Albert The COSTA Group
Program
Cost Relations
Best/Worst Case
Integer g(String x[], int i) { int r=0; for(int j=0; j<i; j++) { b
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
B(i, j) =0 {j≥i} B(i, j) = b
+B(i, j′)
{j<i, j′ = j+1}
Elvira Albert The COSTA Group
+A(x, i′) {i<x, i + 1≤i′≤i+3}
+B(i, j′)
Elvira Albert The COSTA Group
+A(x, i′) {i<x, i + 1≤i′≤i+3}
+B(i, j′)
Elvira Albert The COSTA Group
+A(x, i′) {i<x, i + 1≤i′≤i+3}
+B(i, j′)
Elvira Albert The COSTA Group
+A(x, i′) {i<x, i + 1≤i′≤i+3}
+B(i, j′)
Elvira Albert The COSTA Group
+A(x, i′) {i<x, i + 1≤i′≤i+3}
+B(i, j′)
Elvira Albert The COSTA Group
+A(x, i′) {i<x, i + 1≤i′≤i+3}
+B(i, j′)
Elvira Albert The COSTA Group
+A(x, i′) {i<x, i + 1≤i′≤i+3}
+B(i, j′)
Elvira Albert The COSTA Group
+A(x, i′) {i<x, i + 1≤i′≤i+3}
+B(i, j′)
Elvira Albert The COSTA Group
+A(x, i′) {i<x, i + 1≤i′≤i+3}
+B(i, j′)
Elvira Albert The COSTA Group
+A(x, i′)
+B(i, j′)
Elvira Albert The COSTA Group
+A(x, i′)
+B(i, j′)
b
The COSTA Group
+A(x, i′)
+B(i, j′)
b
b
The COSTA Group
+A(x, i′)
+B(i, j′)
b
b
Elvira Albert The COSTA Group
+A(x, i′)
+B(i, j′)
b
b
Elvira Albert The COSTA Group
+A(x, i′)
+B(i, j′)
b
b
Elvira Albert The COSTA Group
+A(x, i′)
+B(i, j′)
b
b
b
The COSTA Group
+A(x, i′)
+B(i, j′)
b
b
b
Elvira Albert The COSTA Group
+A(x, i′)
Elvira Albert The COSTA Group
+A(x, i′)
∗ nat(i−j)+ c
Elvira Albert The COSTA Group
+A(x, i′)
∗ nat(i−j)+ c
∗nat(i0)+ c
Elvira Albert The COSTA Group
+A(x, i′)
∗ nat(i−j)+ c
∗nat(i0)+ c
Elvira Albert The COSTA Group
∗ nat(i)+ c + a +A(x, i′) {i<x, i + 1≤i′≤i+3}
∗ nat(i−j)+ c
Elvira Albert The COSTA Group
∗ nat(i)+ c + a +A(x, i′) {i<x, i + 1≤i′≤i+3}
∗ nat(i−j)+ c
Elvira Albert The COSTA Group
∗ nat(i)+ c + a +A(x, i′) {i<x, i + 1≤i′≤i+3}
∗ nat(i−j)+ c
Elvira Albert The COSTA Group
∗ nat(i)+ c + a +A(x, i′) {i<x, i + 1≤i′≤i+3}
∗ nat(i−j)+ c
Elvira Albert The COSTA Group
∗ nat(i)+ c + a +A(x, i′) {i<x, i + 1≤i′≤i+3}
∗ nat(i−j)+ c
Elvira Albert The COSTA Group
∗ nat(i)+ c + a +A(x, i′) {i<x, i + 1≤i′≤i+3}
∗ nat(i−j)+ c
Elvira Albert The COSTA Group
∗ nat(i)+ c + a +A(x, i′) {i<x, i + 1≤i′≤i+3}
∗ nat(i−j)+ c
Elvira Albert The COSTA Group
∗ nat(i)+ c + a +A(x, i′) {i<x, i + 1≤i′≤i+3}
∗ nat(i−j)+ c
Elvira Albert The COSTA Group
∗ nat(i)+ c + a +A(x, i′) {i<x, i + 1≤i′≤i+3}
∗ nat(i−j)+ c
∗nat(x0)+ c + a )∗nat(x0−i0)
Elvira Albert The COSTA Group
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
Termination: find ranking functions for all loops in the program Termination → Bounded resource consumption Cost (for number of instructions) → Termination
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
Termination: find ranking functions for all loops in the program Termination → Bounded resource consumption Cost (for number of instructions) → Termination
It deals with Java libraries It checks termination and computes upper bounds It allows assertions on upper bounds (and thus termination)
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
HATS(March 1, 2009 - February 28, 2013) “Highly Adaptable and Trustworthy Software using Formal Methods” UPM (Germ´ an Puebla) + UCM (Elvira Albert, Lou 83)
DOVES (January 1, 2009 - December 31, 2013) “Development Of Verifiable and Efficient Software” UPM (Manuel Hermenegildo)
PROMETIDOS-CM (Jan. 2010 - Dec. 2013) “Madrid Program in Rigorous Methods for the Development of Software” UCM (Francisco J. L´
Elvira Albert The COSTA Group
X10 language (Java-like syntax, different concurrency) ABS (succesor of Creol)
Elvira Albert The COSTA Group
Elvira Albert The COSTA Group