Upper Bounds on Memory Usage for Garbage-Collected Languages Elvira - - PowerPoint PPT Presentation

upper bounds on memory usage for garbage collected
SMART_READER_LITE
LIVE PREVIEW

Upper Bounds on Memory Usage for Garbage-Collected Languages Elvira - - PowerPoint PPT Presentation

Upper Bounds on Memory Usage for Garbage-Collected Languages Elvira Albert 1 , Samir Genaim 1 , Miguel G omez-Zamalloa 1 an Puebla 2 and Damiano Zanardini 2 Puri Arenas 1 , Germ (1)Complutense University of Madrid (Spain) (2) Technical


slide-1
SLIDE 1

ucm-seal upm-seal unm-seal

Upper Bounds on Memory Usage for Garbage-Collected Languages

Elvira Albert1, Samir Genaim1, Miguel G´

  • mez-Zamalloa1

Puri Arenas1, Germ´ an Puebla2 and Damiano Zanardini2

(1)Complutense University of Madrid (Spain) (2) Technical University of Madrid (Spain) 2009 Workshop on Quantitative Analysis of Software (QA’09)

Grenoble, June 28, 2009

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 1 / 17

slide-2
SLIDE 2

ucm-seal upm-seal unm-seal Introduction

Introduction

Cost Analysis is the automatic study of program efficiency (or the resource consumption).

◮ Its aim is to statically estimate the cost of a program execution in

terms of the size of its input args.

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 2 / 17

slide-3
SLIDE 3

ucm-seal upm-seal unm-seal Introduction

Introduction

Cost Analysis is the automatic study of program efficiency (or the resource consumption).

◮ Its aim is to statically estimate the cost of a program execution in

terms of the size of its input args.

The cost can be defined w.r.t. different cost models:

◮ number of instructions executed ◮ memory allocated ◮ number calls to certain methods: billable events on a mobile Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 2 / 17

slide-4
SLIDE 4

ucm-seal upm-seal unm-seal Introduction

Introduction

Cost Analysis is the automatic study of program efficiency (or the resource consumption).

◮ Its aim is to statically estimate the cost of a program execution in

terms of the size of its input args.

The cost can be defined w.r.t. different cost models:

◮ number of instructions executed ◮ memory allocated ◮ number calls to certain methods: billable events on a mobile

Finding the exact cost of programs is undecidable, but it is possible to infer useful information (bounds):

◮ Upper bounds: a program runs within the resources available. ◮ Lower bounds: useful for scheduling distributed execution. Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 2 / 17

slide-5
SLIDE 5

ucm-seal upm-seal unm-seal Introduction

Introduction

Cost Analysis is the automatic study of program efficiency (or the resource consumption).

◮ Its aim is to statically estimate the cost of a program execution in

terms of the size of its input args.

The cost can be defined w.r.t. different cost models:

◮ number of instructions executed ◮ memory allocated ◮ number calls to certain methods: billable events on a mobile

Finding the exact cost of programs is undecidable, but it is possible to infer useful information (bounds):

◮ Upper bounds: a program runs within the resources available. ◮ Lower bounds: useful for scheduling distributed execution.

Two classes of upper bounds can be considered:

◮ non-asymptotic (or concrete, or micro-analysis) ◮ asymptotic (or macro-analysis) Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 2 / 17

slide-6
SLIDE 6

ucm-seal upm-seal unm-seal COSTA: Cost Analyzer for Java Bytecode

COSTA: Cost Analyzer for Java Bytecode

0: new Cons Cons.copy() 3: dup 7: astore 4: invokespecial . . . . . . 27: aload 28: areturn Size SOLVER CFG Relations Cost Relations

BYTECODE PROGRAM

RBR

COST MODEL

THE COSTA SYSTEM UPPER BOUND a

C(a) = 8*2 O(2)

a

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 3 / 17

slide-7
SLIDE 7

ucm-seal upm-seal unm-seal COSTA: Cost Analyzer for Java Bytecode

COSTA: Cost Analyzer for Java Bytecode

0: new Cons Cons.copy() 3: dup 7: astore 4: invokespecial . . . . . . 27: aload 28: areturn Size SOLVER CFG Relations Cost Relations

BYTECODE PROGRAM

RBR

COST MODEL

THE COSTA SYSTEM UPPER BOUND a

C(a) = 8*2 O(2)

a

For mobile code, we do not have access to source code. Java Bytecode: widely used (mobile systems), platform indep., etc

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 3 / 17

slide-8
SLIDE 8

ucm-seal upm-seal unm-seal COSTA: Cost Analyzer for Java Bytecode

COSTA: Cost Analyzer for Java Bytecode

0: new Cons Cons.copy() 3: dup 7: astore 4: invokespecial . . . . . . 27: aload 28: areturn Size SOLVER CFG Relations Cost Relations

BYTECODE PROGRAM

RBR

COST MODEL

THE COSTA SYSTEM UPPER BOUND a

C(a) = 8*2 O(2)

a

For mobile code, we do not have access to source code. Java Bytecode: widely used (mobile systems), platform indep., etc

I will focus on the main components and on cost models heap and peak.

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 3 / 17

slide-9
SLIDE 9

ucm-seal upm-seal unm-seal COSTA: Cost Analyzer for Java Bytecode Heap Space Analysis

HEAP: Total Allocation Analysis Symbolic cost model for heap consumption, size(Tree), size(Integer).. We get upper bounds of the total allocated memory. In presence of garbage collection (GC), it is a too pessimistic estimation of the actual memory consumption.

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 4 / 17

slide-10
SLIDE 10

ucm-seal upm-seal unm-seal COSTA: Cost Analyzer for Java Bytecode Heap Space Analysis

HEAP: Total Allocation Analysis Symbolic cost model for heap consumption, size(Tree), size(Integer).. We get upper bounds of the total allocated memory. In presence of garbage collection (GC), it is a too pessimistic estimation of the actual memory consumption. PEAK: Live Heap Space Analysis Aims at approximating the maximum or peak heap usage. Scope-based GC model:

1

Reclaims unreachable memory when methods return. This assumption can be refined up to an ideal GC.

2

Collects unreachable objects which have been created during the execution of the corresponding method call and not before.

Much tighter estimation in presence of GC.

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 4 / 17

slide-11
SLIDE 11

ucm-seal upm-seal unm-seal Running Example

From Java to Intermediate representation

class Test {

static Tree m(int n) { if ( n>0 ) return new Tree(m(n-1),m(n-1),f(n)); else return null; } static int f(int n) { int a=0,i=n; for (; n>1 ; n=n/2 ) a += g(n).intValue(); for(; i>1; i=i/2) a *= h(i).intValue(); return a; } static Integer g(int n) { Integer x=new Integer(n); return new Integer(x.intValue()+1); } static Long h(int n) { return new Long(n-1); } } Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 5 / 17

slide-12
SLIDE 12

ucm-seal upm-seal unm-seal Running Example

From Java to Intermediate representation

class Test {

static Tree m(int n) { if ( n>0 ) return new Tree(m(n-1),m(n-1),f(n)); else return null; } static int f(int n) { int a=0,i=n; for (; n>1 ; n=n/2 ) a += g(n).intValue(); for(; i>1; i=i/2) a *= h(i).intValue(); return a; } static Integer g(int n) { Integer x=new Integer(n); return new Integer(x.intValue()+1); } static Long h(int n) { return new Long(n-1); } }

m(n, r)::= n > 0, s0 := new Tree1; s1 := n − 1, m(s1, s1), s2 := n − 1, m(s2, s2), f(n, s3), init(s0, s1, s2, s3, ), r = s0. m(n, r)::= n ≤ 0, r := null. f(n, r)::= a := 0, i := n, fc(n, a, n, a), fd(i, a, i, a), r := a. fc(n, a, n, a)::= n > 1, g(n, s0), intValue1(s0, s0) a := a + s0, n := n/2, fc(n, a, n, a). fc(n, a, n, a)::= n ≤ 1.

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 5 / 17

slide-13
SLIDE 13

ucm-seal upm-seal unm-seal Running Example

From Java to Intermediate representation

class Test {

static Tree m(int n) { if ( n>0 ) return new Tree(m(n-1),m(n-1),f(n)); else return null; } static int f(int n) { int a=0,i=n; for (; n>1 ; n=n/2 ) a += g(n).intValue(); for(; i>1; i=i/2) a *= h(i).intValue(); return a; } static Integer g(int n) { Integer x=new Integer(n); return new Integer(x.intValue()+1); } static Long h(int n) { return new Long(n-1); } }

m(n, r)::= n > 0, s0 := new Tree1; s1 := n − 1, m(s1, s1), s2 := n − 1, m(s2, s2), f(n, s3), init(s0, s1, s2, s3, ), r = s0. m(n, r)::= n ≤ 0, r := null. f(n, r)::= a := 0, i := n, fc(n, a, n, a), fd(i, a, i, a), r := a. fc(n, a, n, a)::= n > 1, g(n, s0), intValue1(s0, s0) a := a + s0, n := n/2, fc(n, a, n, a). fc(n, a, n, a)::= n ≤ 1.

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 5 / 17

slide-14
SLIDE 14

ucm-seal upm-seal unm-seal Running Example

From Java to Intermediate representation

class Test {

static Tree m(int n) { if ( n>0 ) return new Tree(m(n-1),m(n-1),f(n)); else return null; } static int f(int n) { int a=0,i=n; for (; n>1 ; n=n/2 ) a += g(n).intValue(); for(; i>1; i=i/2) a *= h(i).intValue(); return a; } static Integer g(int n) { Integer x=new Integer(n); return new Integer(x.intValue()+1); } static Long h(int n) { return new Long(n-1); } }

m(n, r)::= n > 0, s0 := new Tree1; s1 := n − 1, m(s1, s1), s2 := n − 1, m(s2, s2), f(n, s3), init(s0, s1, s2, s3, ), r = s0. m(n, r)::= n ≤ 0, r := null. f(n, r)::= a := 0, i := n, fc(n, a, n, a), fd(i, a, i, a), r := a. fc(n, a, n, a)::= n > 1, g(n, s0), intValue1(s0, s0) a := a + s0, n := n/2, fc(n, a, n, a). fc(n, a, n, a)::= n ≤ 1.

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 5 / 17

slide-15
SLIDE 15

ucm-seal upm-seal unm-seal Running Example

From Java to Intermediate representation

class Test {

static Tree m(int n) { if ( n>0 ) return new Tree(m(n-1),m(n-1),f(n)); else return null; } static int f(int n) { int a=0,i=n; for (; n>1 ; n=n/2 ) a += g(n).intValue(); for(; i>1; i=i/2) a *= h(i).intValue(); return a; } static Integer g(int n) { Integer x=new Integer(n); return new Integer(x.intValue()+1); } static Long h(int n) { return new Long(n-1); } }

m(n, r)::= n > 0, s0 := new Tree1; s1 := n − 1, m(s1, s1), s2 := n − 1, m(s2, s2), f(n, s3), init(s0, s1, s2, s3, ), r = s0. m(n, r)::= n ≤ 0, r := null. f(n, r)::= a := 0, i := n, fc(n, a, n, a), fd(i, a, i, a), r := a. fc(n, a, n, a)::= n > 1, g(n, s0), intValue1(s0, s0) a := a + s0, n := n/2, fc(n, a, n, a). fc(n, a, n, a)::= n ≤ 1.

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 5 / 17

slide-16
SLIDE 16

ucm-seal upm-seal unm-seal Running Example

From Java to Intermediate representation

class Test {

static Tree m(int n) { if ( n>0 ) return new Tree(m(n-1),m(n-1),f(n)); else return null; } static int f(int n) { int a=0,i=n; for (; n>1 ; n=n/2 ) a += g(n).intValue(); for(; i>1; i=i/2) a *= h(i).intValue(); return a; } static Integer g(int n) { Integer x=new Integer(n); return new Integer(x.intValue()+1); } static Long h(int n) { return new Long(n-1); } }

m(n, r)::= n > 0, s0 := new Tree1; s1 := n − 1, m(s1, s1), s2 := n − 1, m(s2, s2), f(n, s3), init(s0, s1, s2, s3, ), r = s0. m(n, r)::= n ≤ 0, r := null. f(n, r)::= a := 0, i := n, fc(n, a, n, a), fd(i, a, i, a), r := a. fc(n, a, n, a)::= n > 1, g(n, s0), intValue1(s0, s0) a := a + s0, n := n/2, fc(n, a, n, a). fc(n, a, n, a)::= n ≤ 1.

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 5 / 17

slide-17
SLIDE 17

ucm-seal upm-seal unm-seal Running Example

From Java to Intermediate representation

class Test {

static Tree m(int n) { if ( n>0 ) return new Tree(m(n-1),m(n-1),f(n)); else return null; } static int f(int n) { int a=0,i=n; for (; n>1 ; n=n/2 ) a += g(n).intValue(); for(; i>1; i=i/2) a *= h(i).intValue(); return a; } static Integer g(int n) { Integer x=new Integer(n); return new Integer(x.intValue()+1); } static Long h(int n) { return new Long(n-1); } }

m(n, r)::= n > 0, s0 := new Tree1; s1 := n − 1, m(s1, s1), s2 := n − 1, m(s2, s2), f(n, s3), init(s0, s1, s2, s3, ), r = s0. m(n, r)::= n ≤ 0, r := null. f(n, r)::= a := 0, i := n, fc(n, a, n, a), fd(i, a, i, a), r := a. fc(n, a, n, a)::= n > 1, g(n, s0), intValue1(s0, s0) a := a + s0, n := n/2, fc(n, a, n, a). fc(n, a, n, a)::= n ≤ 1.

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 5 / 17

slide-18
SLIDE 18

ucm-seal upm-seal unm-seal Running Example

From Java to Intermediate representation

class Test {

static Tree m(int n) { if ( n>0 ) return new Tree(m(n-1),m(n-1),f(n)); else return null; } static int f(int n) { int a=0,i=n; for (; n>1 ; n=n/2 ) a += g(n).intValue(); for(; i>1; i=i/2) a *= h(i).intValue(); return a; } static Integer g(int n) { Integer x=new Integer(n); return new Integer(x.intValue()+1); } static Long h(int n) { return new Long(n-1); } }

m(n, r)::= n > 0, s0 := new Tree1; s1 := n − 1, m(s1, s1), s2 := n − 1, m(s2, s2), f(n, s3), init(s0, s1, s2, s3, ), r = s0. m(n, r)::= n ≤ 0, r := null. f(n, r)::= a := 0, i := n, fc(n, a, n, a), fd(i, a, i, a), r := a. fc(n, a, n, a)::= n > 1, g(n, s0), intValue1(s0, s0) a := a + s0, n := n/2, fc(n, a, n, a). fc(n, a, n, a)::= n ≤ 1.

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 5 / 17

slide-19
SLIDE 19

ucm-seal upm-seal unm-seal Running Example

From Intermediate representation to cost equations

m(n, r)::= n > 0, s0 := new Tree1; s1 := n − 1, m(s1, s1), s2 := n − 1, m(s2, s2), f(n, s3), init(s0, s1, s2, s3, ), r = s0. m(n, r)::= n ≤ 0, r := null. m(n)=size(Tree1)+ {n>0} m(n−1)+m(n−1)+f(n)+ init(1, n−1, n−1, s3) m(n)=0 {n≤0}

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 6 / 17

slide-20
SLIDE 20

ucm-seal upm-seal unm-seal Running Example

From Intermediate representation to cost equations

m(n, r)::= n > 0, s0 := new Tree1; s1 := n − 1, m(s1, s1), s2 := n − 1, m(s2, s2), f(n, s3), init(s0, s1, s2, s3, ), r = s0. m(n, r)::= n ≤ 0, r := null. m(n)=size(Tree1)+ {n>0} m(n−1)+m(n−1)+f(n)+ init(1, n−1, n−1, s3) m(n)=0 {n≤0}

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 6 / 17

slide-21
SLIDE 21

ucm-seal upm-seal unm-seal Running Example

From Intermediate representation to cost equations

m(n, r)::= n > 0, s0 := new Tree1; s1 := n − 1, m(s1, s1), s2 := n − 1, m(s2, s2), f(n, s3), init(s0, s1, s2, s3, ), r = s0. m(n, r)::= n ≤ 0, r := null. m(n)=size(Tree1)+ {n>0} m(n−1)+m(n−1)+f(n)+ init(1, n−1, n−1, s3) m(n)=0 {n≤0}

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 6 / 17

slide-22
SLIDE 22

ucm-seal upm-seal unm-seal Running Example

From Intermediate representation to cost equations

m(n, r)::= n > 0, s0 := new Tree1; s1 := n − 1, m(s1, s1), s2 := n − 1, m(s2, s2), f(n, s3), init(s0, s1, s2, s3, ), r = s0. m(n, r)::= n ≤ 0, r := null. m(n)=size(Tree1)+ {n>0} m(n−1)+m(n−1)+f(n)+ init(1, n−1, n−1, s3) m(n)=0 {n≤0}

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 6 / 17

slide-23
SLIDE 23

ucm-seal upm-seal unm-seal Running Example

From Intermediate representation to cost equations

m(n, r)::= n > 0, s0 := new Tree1; s1 := n − 1, m(s1, s1), s2 := n − 1, m(s2, s2), f(n, s3), init(s0, s1, s2, s3, ), r = s0. m(n, r)::= n ≤ 0, r := null. m(n)=size(Tree1)+ {n>0} m(n−1)+m(n−1)+f(n)+ init(1, n−1, n−1, s3) m(n)=0 {n≤0}

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 6 / 17

slide-24
SLIDE 24

ucm-seal upm-seal unm-seal Running Example

From Intermediate representation to cost equations

m(n, r)::= n > 0, s0 := new Tree1; s1 := n − 1, m(s1, s1), s2 := n − 1, m(s2, s2), f(n, s3), init(s0, s1, s2, s3, ), r = s0. m(n, r)::= n ≤ 0, r := null. m(n)=size(Tree1)+ {n>0} m(n−1)+m(n−1)+f(n)+ init(1, n−1, n−1, s3) m(n)=0 {n≤0} f(n)=fc(n, 0) + fd(n, a′) {} fc(n, a)=g(n)+fc(n/2, a′) {n>1} fc(n, a)=0 {n≤1} fd(i, a)=h(i)+fd(i/2, a′) {i>1} fd(i, a)=0 {i≤0} g(n)=size(Integer2)+size(Integer3) {} h(n)=size(Long4) {} init(this, l, r, d)=0 {}

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 6 / 17

slide-25
SLIDE 25

ucm-seal upm-seal unm-seal Running Example

From Cost Relations to Upper Bounds

solutions computed for f

total(f ) = total(fc) + total(fd) for (; n>1 ; n=n/2 ) a += g(n).intValue(); for (; i>1 ; i=i/2 ) a *= h(i).intValue(); fc(n) = log(n) ∗ (size(Integer3) + size(Integer2)) fd(i) = log(i) ∗ size(Long4)

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 7 / 17

slide-26
SLIDE 26

ucm-seal upm-seal unm-seal Running Example

From Cost Relations to Upper Bounds

solutions computed for f

total(f ) = total(fc) + total(fd) for (; n>1 ; n=n/2 ) a += g(n).intValue(); for (; i>1 ; i=i/2 ) a *= h(i).intValue(); fc(n) = log(n) ∗ (size(Integer3) + size(Integer2)) fd(i) = log(i) ∗ size(Long4)

solutions computed for m

m(n) = 2n∗(total(f )

exp times

+size(Tree1)) new Tree(m(n-1),m(n-1),f(n));

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 7 / 17

slide-27
SLIDE 27

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different?

Why Live Heap Space Analysis is Different?

Basic idea in total allocation:

total({m1; m2}) = total(m1) + total(m2)

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 8 / 17

slide-28
SLIDE 28

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different?

Why Live Heap Space Analysis is Different?

Basic idea in total allocation:

total({m1; m2}) = total(m1) + total(m2) While total memory allocation is an accumulative resource, the live heap space increases and decreases along an execution

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 8 / 17

slide-29
SLIDE 29

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different?

Why Live Heap Space Analysis is Different?

Basic idea in total allocation:

total({m1; m2}) = total(m1) + total(m2) While total memory allocation is an accumulative resource, the live heap space increases and decreases along an execution

Basic idea in live Heap Space Analysis:

peak({m1; m2}) = max(peak(m1), escaped(m1) + peak(m2))

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 8 / 17

slide-30
SLIDE 30

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different?

Why Live Heap Space Analysis is Different?

Basic idea in total allocation:

total({m1; m2}) = total(m1) + total(m2) While total memory allocation is an accumulative resource, the live heap space increases and decreases along an execution

Basic idea in live Heap Space Analysis:

peak({m1; m2}) = max(peak(m1), escaped(m1) + peak(m2))

1 STEP 1: Escaped memory analysis 2 STEP 2: Peak consumption cost relations Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 8 / 17

slide-31
SLIDE 31

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Example

Example

class Test {

static Tree m(int n) { if ( n>0 ) return new Tree(m(n-1),m(n-1),f(n)); else return null; } static int f(int n) { int a=0,i=n;

  • for (;n>1;n=n/2)
  • a += g(n).intValue();
  • for(; i>1; i=i/2)
  • a *= h(i).intValue();
  • return a;

} static Integer g(int n) { Integer x=new Integer(n); return new Integer(x.intValue()+1); } static Long h(int n) { return new Long(n-1); } } Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 9 / 17

slide-32
SLIDE 32

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Example

Example

class Test {

static Tree m(int n) { if ( n>0 ) return new Tree(m(n-1),m(n-1),f(n)); else return null; } static int f(int n) { int a=0,i=n;

  • for (;n>1;n=n/2)
  • a += g(n).intValue();
  • for(; i>1; i=i/2)
  • a *= h(i).intValue();
  • return a;

} static Integer g(int n) { Integer x=new Integer(n); return new Integer(x.intValue()+1); } static Long h(int n) { return new Long(n-1); } }

1

g peak

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 9 / 17

slide-33
SLIDE 33

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Example

Example

class Test {

static Tree m(int n) { if ( n>0 ) return new Tree(m(n-1),m(n-1),f(n)); else return null; } static int f(int n) { int a=0,i=n;

  • for (;n>1;n=n/2)
  • a += g(n).intValue();
  • for(; i>1; i=i/2)
  • a *= h(i).intValue();
  • return a;

} static Integer g(int n) { Integer x=new Integer(n); return new Integer(x.intValue()+1); } static Long h(int n) { return new Long(n-1); } }

1 2

g peak g escaped

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 9 / 17

slide-34
SLIDE 34

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Example

Example

class Test {

static Tree m(int n) { if ( n>0 ) return new Tree(m(n-1),m(n-1),f(n)); else return null; } static int f(int n) { int a=0,i=n;

  • for (;n>1;n=n/2)
  • a += g(n).intValue();
  • for(; i>1; i=i/2)
  • a *= h(i).intValue();
  • return a;

} static Integer g(int n) { Integer x=new Integer(n); return new Integer(x.intValue()+1); } static Long h(int n) { return new Long(n-1); } }

1 2

g peak g escaped

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 9 / 17

slide-35
SLIDE 35

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Example

Example

class Test {

static Tree m(int n) { if ( n>0 ) return new Tree(m(n-1),m(n-1),f(n)); else return null; } static int f(int n) { int a=0,i=n;

  • for (;n>1;n=n/2)
  • a += g(n).intValue();
  • for(; i>1; i=i/2)
  • a *= h(i).intValue();
  • return a;

} static Integer g(int n) { Integer x=new Integer(n); return new Integer(x.intValue()+1); } static Long h(int n) { return new Long(n-1); } }

1 2 3

g peak g escaped

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 9 / 17

slide-36
SLIDE 36

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Example

Example

class Test {

static Tree m(int n) { if ( n>0 ) return new Tree(m(n-1),m(n-1),f(n)); else return null; } static int f(int n) { int a=0,i=n;

  • for (;n>1;n=n/2)
  • a += g(n).intValue();
  • for(; i>1; i=i/2)
  • a *= h(i).intValue();
  • return a;

} static Integer g(int n) { Integer x=new Integer(n); return new Integer(x.intValue()+1); } static Long h(int n) { return new Long(n-1); } }

1 2 3

g peak g escaped

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 9 / 17

slide-37
SLIDE 37

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Example

Example

class Test {

static Tree m(int n) { if ( n>0 ) return new Tree(m(n-1),m(n-1),f(n)); else return null; } static int f(int n) { int a=0,i=n;

  • for (;n>1;n=n/2)
  • a += g(n).intValue();
  • for(; i>1; i=i/2)
  • a *= h(i).intValue();
  • return a;

} static Integer g(int n) { Integer x=new Integer(n); return new Integer(x.intValue()+1); } static Long h(int n) { return new Long(n-1); } }

1 2 3

log(n)

g peak g escaped

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 9 / 17

slide-38
SLIDE 38

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Example

Example

class Test {

static Tree m(int n) { if ( n>0 ) return new Tree(m(n-1),m(n-1),f(n)); else return null; } static int f(int n) { int a=0,i=n;

  • for (;n>1;n=n/2)
  • a += g(n).intValue();
  • for(; i>1; i=i/2)
  • a *= h(i).intValue();
  • return a;

} static Integer g(int n) { Integer x=new Integer(n); return new Integer(x.intValue()+1); } static Long h(int n) { return new Long(n-1); } }

1 2 3

log(n)

g peak g escaped

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 9 / 17

slide-39
SLIDE 39

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Example

Example

class Test {

static Tree m(int n) { if ( n>0 ) return new Tree(m(n-1),m(n-1),f(n)); else return null; } static int f(int n) { int a=0,i=n;

  • for (;n>1;n=n/2)
  • a += g(n).intValue();
  • for(; i>1; i=i/2)
  • a *= h(i).intValue();
  • return a;

} static Integer g(int n) { Integer x=new Integer(n); return new Integer(x.intValue()+1); } static Long h(int n) { return new Long(n-1); } }

1 2 3

log(n)

1

g peak g escaped

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 9 / 17

slide-40
SLIDE 40

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Example

Example

class Test {

static Tree m(int n) { if ( n>0 ) return new Tree(m(n-1),m(n-1),f(n)); else return null; } static int f(int n) { int a=0,i=n;

  • for (;n>1;n=n/2)
  • a += g(n).intValue();
  • for(; i>1; i=i/2)
  • a *= h(i).intValue();
  • return a;

} static Integer g(int n) { Integer x=new Integer(n); return new Integer(x.intValue()+1); } static Long h(int n) { return new Long(n-1); } }

1 2 3

log(n)

1

g peak g escaped h peak

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 9 / 17

slide-41
SLIDE 41

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Example

Example

class Test {

static Tree m(int n) { if ( n>0 ) return new Tree(m(n-1),m(n-1),f(n)); else return null; } static int f(int n) { int a=0,i=n;

  • for (;n>1;n=n/2)
  • a += g(n).intValue();
  • for(; i>1; i=i/2)
  • a *= h(i).intValue();
  • return a;

} static Integer g(int n) { Integer x=new Integer(n); return new Integer(x.intValue()+1); } static Long h(int n) { return new Long(n-1); } }

1 2 3

log(n)

1 2

g peak g escaped h peak h escaped

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 9 / 17

slide-42
SLIDE 42

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Example

Example

class Test {

static Tree m(int n) { if ( n>0 ) return new Tree(m(n-1),m(n-1),f(n)); else return null; } static int f(int n) { int a=0,i=n;

  • for (;n>1;n=n/2)
  • a += g(n).intValue();
  • for(; i>1; i=i/2)
  • a *= h(i).intValue();
  • return a;

} static Integer g(int n) { Integer x=new Integer(n); return new Integer(x.intValue()+1); } static Long h(int n) { return new Long(n-1); } }

1 2 3

log(n)

1 2

g peak g escaped h peak h escaped

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 9 / 17

slide-43
SLIDE 43

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Example

Example

class Test {

static Tree m(int n) { if ( n>0 ) return new Tree(m(n-1),m(n-1),f(n)); else return null; } static int f(int n) { int a=0,i=n;

  • for (;n>1;n=n/2)
  • a += g(n).intValue();
  • for(; i>1; i=i/2)
  • a *= h(i).intValue();
  • return a;

} static Integer g(int n) { Integer x=new Integer(n); return new Integer(x.intValue()+1); } static Long h(int n) { return new Long(n-1); } }

1 2 3

log(n)

1 2 3

g peak g escaped h peak h escaped

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 9 / 17

slide-44
SLIDE 44

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Example

Example

class Test {

static Tree m(int n) { if ( n>0 ) return new Tree(m(n-1),m(n-1),f(n)); else return null; } static int f(int n) { int a=0,i=n;

  • for (;n>1;n=n/2)
  • a += g(n).intValue();
  • for(; i>1; i=i/2)
  • a *= h(i).intValue();
  • return a;

} static Integer g(int n) { Integer x=new Integer(n); return new Integer(x.intValue()+1); } static Long h(int n) { return new Long(n-1); } }

1 2 3

log(n)

1 2 3

g peak g escaped h peak h escaped

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 9 / 17

slide-45
SLIDE 45

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Example

Example

class Test {

static Tree m(int n) { if ( n>0 ) return new Tree(m(n-1),m(n-1),f(n)); else return null; } static int f(int n) { int a=0,i=n;

  • for (;n>1;n=n/2)
  • a += g(n).intValue();
  • for(; i>1; i=i/2)
  • a *= h(i).intValue();
  • return a;

} static Integer g(int n) { Integer x=new Integer(n); return new Integer(x.intValue()+1); } static Long h(int n) { return new Long(n-1); } }

1 2 3

log(n)

1 2 3

log(n)

g peak g escaped h peak h escaped

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 9 / 17

slide-46
SLIDE 46

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Example

Example

class Test {

static Tree m(int n) { if ( n>0 ) return new Tree(m(n-1),m(n-1),f(n)); else return null; } static int f(int n) { int a=0,i=n;

  • for (;n>1;n=n/2)
  • a += g(n).intValue();
  • for(; i>1; i=i/2)
  • a *= h(i).intValue();
  • return a;

} static Integer g(int n) { Integer x=new Integer(n); return new Integer(x.intValue()+1); } static Long h(int n) { return new Long(n-1); } }

1 2 3

log(n)

1 2 3

log(n)

g peak g escaped h peak h escaped

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 9 / 17

slide-47
SLIDE 47

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Example

Example

class Test {

static Tree m(int n) { if ( n>0 ) return new Tree(m(n-1),m(n-1),f(n)); else return null; } static int f(int n) { int a=0,i=n;

  • for (;n>1;n=n/2)
  • a += g(n).intValue();
  • for(; i>1; i=i/2)
  • a *= h(i).intValue();
  • return a;

} static Integer g(int n) { Integer x=new Integer(n); return new Integer(x.intValue()+1); } static Long h(int n) { return new Long(n-1); } }

1 2 3

log(n)

1 2 3

log(n)

g peak g escaped h peak h escaped

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 9 / 17

slide-48
SLIDE 48

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Step 1: Inference of Escaped Memory Bounds

Step 1: Inference of Escaped Memory Bounds

Infer upper bounds on the total memory consumption Remove from the bounds the collectable objects The set of collectable objects can be approximated from the information computed by escape analysis

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 10 / 17

slide-49
SLIDE 49

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Step 1: Inference of Escaped Memory Bounds

Step 1: Inference of Escaped Memory Bounds

Infer upper bounds on the total memory consumption Remove from the bounds the collectable objects The set of collectable objects can be approximated from the information computed by escape analysis

collectable objects from m

the objects that have been created along the execution of m and will not be in the memory upon exit from m

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 10 / 17

slide-50
SLIDE 50

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Example

Collectable Objects

class Test {

  • static Tree m(int n) {

if ( n>0 ) return new Tree(m(n-1),m(n-1),f(n)); else return null; }

  • static int f(int n) {

int a=0,i=n;

  • for(; n>1;n=n/2 )

a += g(n).intValue();

  • for(; i>1; i=i/2)

a *= h(i).intValue(); return a; }

  • static Integer g(int n) {

Integer x=new Integer2(n); return new Integer3(x.intValue()+1); }

  • static Long h(int n) {

return new Long4(n-1); } } // end of class Test

collectable(g) = {Integer2} collectable(h) = ∅ collectable(f) = {Integer2, Integer3, Long4} collectable(m) = {Integer2, Integer3, Long4}

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 11 / 17

slide-51
SLIDE 51

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Example

Collectable Objects

class Test {

  • static Tree m(int n) {

if ( n>0 ) return new Tree(m(n-1),m(n-1),f(n)); else return null; }

  • static int f(int n) {

int a=0,i=n;

  • for(; n>1;n=n/2 )

a += g(n).intValue();

  • for(; i>1; i=i/2)

a *= h(i).intValue(); return a; }

  • static Integer g(int n) {

Integer x=new Integer2(n); return new Integer3(x.intValue()+1); }

  • static Long h(int n) {

return new Long4(n-1); } } // end of class Test

collectable(g) = {Integer2} collectable(h) = ∅ collectable(f) = {Integer2, Integer3, Long4} collectable(m) = {Integer2, Integer3, Long4}

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 11 / 17

slide-52
SLIDE 52

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Example

Collectable Objects

class Test {

  • static Tree m(int n) {

if ( n>0 ) return new Tree(m(n-1),m(n-1),f(n)); else return null; }

  • static int f(int n) {

int a=0,i=n;

  • for(; n>1;n=n/2 )

a += g(n).intValue();

  • for(; i>1; i=i/2)

a *= h(i).intValue(); return a; }

  • static Integer g(int n) {

Integer x=new Integer2(n); return new Integer3(x.intValue()+1); }

  • static Long h(int n) {

return new Long4(n-1); } } // end of class Test

collectable(g) = {Integer2} collectable(h) = ∅ collectable(f) = {Integer2, Integer3, Long4} collectable(m) = {Integer2, Integer3, Long4}

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 11 / 17

slide-53
SLIDE 53

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Example

Collectable Objects

class Test {

  • static Tree m(int n) {

if ( n>0 ) return new Tree(m(n-1),m(n-1),f(n)); else return null; }

  • static int f(int n) {

int a=0,i=n;

  • for(; n>1;n=n/2 )

a += g(n).intValue();

  • for(; i>1; i=i/2)

a *= h(i).intValue(); return a; }

  • static Integer g(int n) {

Integer x=new Integer2(n); return new Integer3(x.intValue()+1); }

  • static Long h(int n) {

return new Long4(n-1); } } // end of class Test

collectable(g) = {Integer2} collectable(h) = ∅ collectable(f) = {Integer2, Integer3, Long4} collectable(m) = {Integer2, Integer3, Long4}

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 11 / 17

slide-54
SLIDE 54

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Example

Collectable Objects

class Test {

  • static Tree m(int n) {

if ( n>0 ) return new Tree(m(n-1),m(n-1),f(n)); else return null; }

  • static int f(int n) {

int a=0,i=n;

  • for(; n>1;n=n/2 )

a += g(n).intValue();

  • for(; i>1; i=i/2)

a *= h(i).intValue(); return a; }

  • static Integer g(int n) {

Integer x=new Integer2(n); return new Integer3(x.intValue()+1); }

  • static Long h(int n) {

return new Long4(n-1); } } // end of class Test

collectable(g) = {Integer2} collectable(h) = ∅ collectable(f) = {Integer2, Integer3, Long4} collectable(m) = {Integer2, Integer3, Long4}

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 11 / 17

slide-55
SLIDE 55

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Example

Bounds on Escaped Memory

escaped memory of a procedure p

given the set of collectable objects after return from p, collectable(p), given the upper-bound for the total memory allocation total(p) = exp the escaped memory upper-bound: escaped(p) = exp[∀ci ∈ collectable(p).size(ci) → 0].

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 12 / 17

slide-56
SLIDE 56

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Example

Bounds on Escaped Memory

escaped memory of a procedure p

given the set of collectable objects after return from p, collectable(p), given the upper-bound for the total memory allocation total(p) = exp the escaped memory upper-bound: escaped(p) = exp[∀ci ∈ collectable(p).size(ci) → 0]. g(n) =size(Integer2)+size(Integer3) h(n) =size(Long4) f (n) = log2(n)∗(size(Integer2)+size(Integer3)+size(Long4)) m(n) =(2n)∗(size(Tree1)+ log2(n)∗(size(Integer2)+size(Integer3)+size(Long4)))

collectable(g) = {Integer2} collectable(h) = ∅ collectable(f) = {Integer2, Integer3, Long4} collectable(m) = {Integer2, Integer3, Long4}

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 12 / 17

slide-57
SLIDE 57

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Example

Bounds on Escaped Memory

escaped memory of a procedure p

given the set of collectable objects after return from p, collectable(p), given the upper-bound for the total memory allocation total(p) = exp the escaped memory upper-bound: escaped(p) = exp[∀ci ∈ collectable(p).size(ci) → 0]. g(n) =size(Integer2)+size(Integer3) h(n) =size(Long4) f (n) = log2(n)∗(size(Integer2)+size(Integer3)+size(Long4)) m(n) =(2n)∗(size(Tree1)+ log2(n)∗(size(Integer2)+size(Integer3)+size(Long4)))

collectable(g) = {Integer2} collectable(h) = ∅ collectable(f) = {Integer2, Integer3, Long4} collectable(m) = {Integer2, Integer3, Long4}

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 12 / 17

slide-58
SLIDE 58

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Example

Bounds on Escaped Memory

escaped memory of a procedure p

given the set of collectable objects after return from p, collectable(p), given the upper-bound for the total memory allocation total(p) = exp the escaped memory upper-bound: escaped(p) = exp[∀ci ∈ collectable(p).size(ci) → 0]. ˇ g(n) =size(Integer3) h(n) =size(Long4) f (n) = log2(n)∗(size(Integer2)+size(Integer3)+size(Long4)) m(n) =(2n)∗(size(Tree1)+ log2(n)∗(size(Integer2)+size(Integer3)+size(Long4)))

collectable(g) = {Integer2} collectable(h) = ∅ collectable(f) = {Integer2, Integer3, Long4} collectable(m) = {Integer2, Integer3, Long4}

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 12 / 17

slide-59
SLIDE 59

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Example

Bounds on Escaped Memory

escaped memory of a procedure p

given the set of collectable objects after return from p, collectable(p), given the upper-bound for the total memory allocation total(p) = exp the escaped memory upper-bound: escaped(p) = exp[∀ci ∈ collectable(p).size(ci) → 0]. ˇ g(n) =size(Integer3) ˇ h(n) =size(Long4) f (n) = log2(n)∗(size(Integer2)+size(Integer3)+size(Long4)) m(n) =(2n)∗(size(Tree1)+ log2(n)∗(size(Integer2)+size(Integer3)+size(Long4)))

collectable(g) = {Integer2} collectable(h) = ∅ collectable(f) = {Integer2, Integer3, Long4} collectable(m) = {Integer2, Integer3, Long4}

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 12 / 17

slide-60
SLIDE 60

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Example

Bounds on Escaped Memory

escaped memory of a procedure p

given the set of collectable objects after return from p, collectable(p), given the upper-bound for the total memory allocation total(p) = exp the escaped memory upper-bound: escaped(p) = exp[∀ci ∈ collectable(p).size(ci) → 0]. ˇ g(n) =size(Integer3) ˇ h(n) =size(Long4) ˇ f (n) =0 m(n) =(2n)∗(size(Tree1)+ log2(n)∗(size(Integer2)+size(Integer3)+size(Long4)))

collectable(g) = {Integer2} collectable(h) = ∅ collectable(f) = {Integer2, Integer3, Long4} collectable(m) = {Integer2, Integer3, Long4}

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 12 / 17

slide-61
SLIDE 61

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Example

Bounds on Escaped Memory

escaped memory of a procedure p

given the set of collectable objects after return from p, collectable(p), given the upper-bound for the total memory allocation total(p) = exp the escaped memory upper-bound: escaped(p) = exp[∀ci ∈ collectable(p).size(ci) → 0]. ˇ g(n) =size(Integer3) ˇ h(n) =size(Long4) ˇ f (n) =0 ˇ m(n) =(2n)∗size(Tree1)

collectable(g) = {Integer2} collectable(h) = ∅ collectable(f) = {Integer2, Integer3, Long4} collectable(m) = {Integer2, Integer3, Long4}

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 12 / 17

slide-62
SLIDE 62

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Step 2: Inference of Live Memory Bounds

Step 2: Inference of Live Memory Bounds

Build cost relations which capture the basic idea peak({m1; m2}) = max(peak(m1), escaped(m1) + peak(m2))

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 13 / 17

slide-63
SLIDE 63

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Step 2: Inference of Live Memory Bounds

Step 2: Inference of Live Memory Bounds

Build cost relations which capture the basic idea peak({m1; m2}) = max(peak(m1), escaped(m1) + peak(m2)) Consider a rule p::=g, b1, . . . , bn . Its peak consumption equation is peak(p) = T (b1, . . . , bn), ϕr where T is defined as follows:

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 13 / 17

slide-64
SLIDE 64

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Step 2: Inference of Live Memory Bounds

Step 2: Inference of Live Memory Bounds

Build cost relations which capture the basic idea peak({m1; m2}) = max(peak(m1), escaped(m1) + peak(m2)) Consider a rule p::=g, b1, . . . , bn . Its peak consumption equation is peak(p) = T (b1, . . . , bn), ϕr where T is defined as follows:

peak cost relation

T (b1, . . . , bn)::=

◮ if b1 is a call, then max(peak(b1), escaped(b1) + T (b2, . . . , bn)) ◮ if b1 is an instruction, then total(b1) + T (b2, . . . , bn) Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 13 / 17

slide-65
SLIDE 65

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Example

Detailed Example

For the following code in m: new Tree(m(n-1),m(n-1),f(n));

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 14 / 17

slide-66
SLIDE 66

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Example

Detailed Example

For the following code in m: new Tree(m(n-1),m(n-1),f(n)); We produce a peak consumption relation: peakm(n) = size(Tree1)+ max(peakm(n − 1), escapedm(n − 1)+

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 14 / 17

slide-67
SLIDE 67

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Example

Detailed Example

For the following code in m: new Tree(m(n-1),m(n-1),f(n)); We produce a peak consumption relation: peakm(n) = size(Tree1)+ max(peakm(n − 1), escapedm(n − 1)+ max(peakm(n − 1), escapedm(n − 1)+

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 14 / 17

slide-68
SLIDE 68

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Example

Detailed Example

For the following code in m: new Tree(m(n-1),m(n-1),f(n)); We produce a peak consumption relation: peakm(n) = size(Tree1)+ max(peakm(n − 1), escapedm(n − 1)+ max(peakm(n − 1), escapedm(n − 1)+ max(peakf (n), escapedf (n)) ) )

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 14 / 17

slide-69
SLIDE 69

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Example

Detailed Example

For the following code in m: new Tree(m(n-1),m(n-1),f(n)); We produce a peak consumption relation: peakm(n) = size(Tree1)+ max(peakm(n − 1), escapedm(n − 1)+ max(peakm(n − 1), escapedm(n − 1)+ max(peakf (n), escapedf (n)) ) ) We remove the max operators and replace escm by the formula: peakm(n) = size(Tree1) + peakm(n − 1)

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 14 / 17

slide-70
SLIDE 70

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Example

Detailed Example

For the following code in m: new Tree(m(n-1),m(n-1),f(n)); We produce a peak consumption relation: peakm(n) = size(Tree1)+ max(peakm(n − 1), escapedm(n − 1)+ max(peakm(n − 1), escapedm(n − 1)+ max(peakf (n), escapedf (n)) ) ) We remove the max operators and replace escm by the formula: peakm(n) = size(Tree1) + peakm(n − 1) peakm(n) = size(Tree1) + escm(n − 1) + peakm(n − 1)

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 14 / 17

slide-71
SLIDE 71

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Example

Detailed Example

For the following code in m: new Tree(m(n-1),m(n-1),f(n)); We produce a peak consumption relation: peakm(n) = size(Tree1)+ max(peakm(n − 1), escapedm(n − 1)+ max(peakm(n − 1), escapedm(n − 1)+ max(peakf (n), escapedf (n)) ) ) We remove the max operators and replace escm by the formula: peakm(n) = size(Tree1) + peakm(n − 1) peakm(n) = size(Tree1) + escm(n − 1) + peakm(n − 1) peakm(n) = size(Tree1) + escm(n − 1) + escm(n − 1) + peakf (n)

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 14 / 17

slide-72
SLIDE 72

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Example

Detailed Example

For the following code in m: new Tree(m(n-1),m(n-1),f(n)); We produce a peak consumption relation: peakm(n) = size(Tree1)+ max(peakm(n − 1), escapedm(n − 1)+ max(peakm(n − 1), escapedm(n − 1)+ max(peakf (n), escapedf (n)) ) ) We remove the max operators and replace escm by the formula: peakm(n) = size(Tree1) + peakm(n − 1) peakm(n) = size(Tree1) + escm(n − 1) + peakm(n − 1) peakm(n) = size(Tree1) + escm(n − 1) + escm(n − 1) + peakf (n) An upper bound of the equations:

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 14 / 17

slide-73
SLIDE 73

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Example

Detailed Example

For the following code in m: new Tree(m(n-1),m(n-1),f(n)); We produce a peak consumption relation: peakm(n) = size(Tree1)+ max(peakm(n − 1), escapedm(n − 1)+ max(peakm(n − 1), escapedm(n − 1)+ max(peakf (n), escapedf (n)) ) ) We remove the max operators and replace escm by the formula: peakm(n) = size(Tree1) + peakm(n − 1) peakm(n) = size(Tree1) + escm(n − 1) + peakm(n − 1) peakm(n) = size(Tree1) + escm(n − 1) + escm(n − 1) + peakf (n) An upper bound of the equations: peakm(n) = 2n∗size(Tree1) + peakf (n)

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 14 / 17

slide-74
SLIDE 74

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Live Heap Bounds vs. Total Memory Bounds

Live Heap Bounds vs. Total Memory Bounds

solutions computed from peak cost relation

new Tree(m(n-1),m(n-1),f(n));

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 15 / 17

slide-75
SLIDE 75

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Live Heap Bounds vs. Total Memory Bounds

Live Heap Bounds vs. Total Memory Bounds

solutions computed from peak cost relation

new Tree(m(n-1),m(n-1),f(n)); total(m) = 2n∗(total(f )

exp times

+size(Tree1))

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 15 / 17

slide-76
SLIDE 76

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Live Heap Bounds vs. Total Memory Bounds

Live Heap Bounds vs. Total Memory Bounds

solutions computed from peak cost relation

new Tree(m(n-1),m(n-1),f(n)); total(m) = 2n∗(total(f )

exp times

+size(Tree1)) peak(m) = 2n∗size(Tree1) +

  • nly once

peak(f )

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 15 / 17

slide-77
SLIDE 77

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Live Heap Bounds vs. Total Memory Bounds

Live Heap Bounds vs. Total Memory Bounds

solutions computed from peak cost relation

new Tree(m(n-1),m(n-1),f(n)); total(m) = 2n∗(total(f )

exp times

+size(Tree1)) peak(m) = 2n∗size(Tree1) +

  • nly once

peak(f )

tighter bound for f

for (; n>1 ; n=n/2 ) a += g(n).intValue();

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 15 / 17

slide-78
SLIDE 78

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Live Heap Bounds vs. Total Memory Bounds

Live Heap Bounds vs. Total Memory Bounds

solutions computed from peak cost relation

new Tree(m(n-1),m(n-1),f(n)); total(m) = 2n∗(total(f )

exp times

+size(Tree1)) peak(m) = 2n∗size(Tree1) +

  • nly once

peak(f )

tighter bound for f

for (; n>1 ; n=n/2 ) a += g(n).intValue(); total(fc) = log(n) ∗ (size(Integer3) + size(Integer2))

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 15 / 17

slide-79
SLIDE 79

ucm-seal upm-seal unm-seal Why Live Heap Space Analysis is Different? Live Heap Bounds vs. Total Memory Bounds

Live Heap Bounds vs. Total Memory Bounds

solutions computed from peak cost relation

new Tree(m(n-1),m(n-1),f(n)); total(m) = 2n∗(total(f )

exp times

+size(Tree1)) peak(m) = 2n∗size(Tree1) +

  • nly once

peak(f )

tighter bound for f

for (; n>1 ; n=n/2 ) a += g(n).intValue(); total(fc) = log(n) ∗ (size(Integer3) + size(Integer2)) peak(fc) = log(n) ∗ size(Integer3) + size(Integer2)

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 15 / 17

slide-80
SLIDE 80

ucm-seal upm-seal unm-seal Conclusions and Future Work

Conclusions We have presented an automatic live heap space analysis for garbage-collected languages. It generates at compile-time cost relations which define the peak consumption of a program as a function of its input data size. The CRs obtained can be solved with standard UBs solvers (PUBS). We have successfully analyzed the JOlden benchmark suite. Applications: verification, certification (embedded systems, critical/real-time apps), program optimization and understanding, etc. Future Work Adapt our techniques to region-based garbage collection The idea could be used to estimate other non-accumulative resources.

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 16 / 17

slide-81
SLIDE 81

ucm-seal upm-seal unm-seal Conclusions and Future Work

Info on Costa: http://costa.ls.fi.upm.es Technical Details: Set up recurrence relations ESOP’07 Solve recurrence relations SAS’08 Peak memory usage ISMM’09 Gentle description of COSTA FOSAD’09 summer school

Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 17 / 17