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 University of Madrid (Spain) 2009 Workshop on Quantitative Analysis of Software (QA’09) Grenoble, June 28, 2009 upm-seal ucm-seal unm-seal Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 1 / 17
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. upm-seal ucm-seal unm-seal Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 2 / 17
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 upm-seal ucm-seal unm-seal Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 2 / 17
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. upm-seal ucm-seal unm-seal Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 2 / 17
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) upm-seal ucm-seal unm-seal ◮ asymptotic (or macro-analysis) Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 2 / 17
COSTA: Cost Analyzer for Java Bytecode COSTA: Cost Analyzer for Java Bytecode THE COSTA SYSTEM BYTECODE PROGRAM Cons.copy() Size 0: new Cons CFG RBR UPPER BOUND Relations 3: dup 4: invokespecial a a C(a) = 8*2 O(2) 7: astore . . . Cost Relations . . . 27: aload 28: areturn SOLVER COST MODEL upm-seal ucm-seal unm-seal Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 3 / 17
COSTA: Cost Analyzer for Java Bytecode COSTA: Cost Analyzer for Java Bytecode THE COSTA SYSTEM BYTECODE PROGRAM Cons.copy() Size 0: new Cons CFG RBR UPPER BOUND Relations 3: dup 4: invokespecial a a C(a) = 8*2 O(2) 7: astore . . . Cost Relations . . . 27: aload 28: areturn SOLVER COST MODEL For mobile code, we do not have access to source code. Java Bytecode: widely used (mobile systems), platform indep., etc upm-seal ucm-seal unm-seal Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 3 / 17
COSTA: Cost Analyzer for Java Bytecode COSTA: Cost Analyzer for Java Bytecode THE COSTA SYSTEM BYTECODE PROGRAM Cons.copy() Size 0: new Cons CFG RBR UPPER BOUND Relations 3: dup 4: invokespecial a a C(a) = 8*2 O(2) 7: astore . . . Cost Relations . . . 27: aload 28: areturn SOLVER COST MODEL For mobile code, we do not have access to source code. Java Bytecode: widely used (mobile systems), platform indep., etc upm-seal ucm-seal unm-seal 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
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. upm-seal ucm-seal unm-seal Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 4 / 17
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: Reclaims unreachable memory when methods return. This assumption 1 can be refined up to an ideal GC. Collects unreachable objects which have been created during the 2 execution of the corresponding method call and not before. Much tighter estimation in presence of GC. upm-seal ucm-seal unm-seal Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 4 / 17
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); upm-seal ucm-seal unm-seal } } Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 5 / 17
Running Example From Java to Intermediate representation class Test { m ( � n � , � r � )::= f ( � n � , � r � )::= static Tree m( int n) { n > 0 , a := 0 , if ( n > 0 ) return new Tree(m(n-1),m(n-1),f(n)); s 0 := new Tree 1 ; i := n , else return null ; s 1 := n − 1 , f c ( � n , a � , � n , a � ) , } m ( � s 1 � , � s 1 � ) , f d ( � i , a � , � i , a � ) , s 2 := n − 1 , r := a . static int f( int n) { int a=0,i=n; m ( � s 2 � , � s 2 � ) , for (; n > 1 ; n=n/2 ) f ( � n � , � s 3 � ) , a += g(n).intValue(); init ( � s 0 , s 1 , s 2 , s 3 � , �� ) , f c ( � n , a � , � n , a � )::= for (; i > 1; i=i/2) r = s 0 . n > 1 , a *= h(i).intValue(); return a; g ( � n � , � s 0 � ) , } m ( � n � , � r � )::= intValue 1 ( � s 0 � , � s 0 � ) n ≤ 0 , a := a + s 0 , static Integer g(int n) { r := null . n := n / 2 , Integer x= new Integer(n); return new Integer(x.intValue()+1); f c ( � n , a � , � n , a � ) . } static Long h(int n) { f c ( � n , a � , � n , a � )::= return new Long(n-1); upm-seal ucm-seal unm-seal } n ≤ 1 . } Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 5 / 17
Running Example From Java to Intermediate representation class Test { m ( � n � , � r � )::= f ( � n � , � r � )::= static Tree m( int n) { n > 0 , a := 0 , if ( n > 0 ) return new Tree(m(n-1),m(n-1),f(n)); s 0 := new Tree 1 ; i := n , else return null ; s 1 := n − 1 , f c ( � n , a � , � n , a � ) , } m ( � s 1 � , � s 1 � ) , f d ( � i , a � , � i , a � ) , s 2 := n − 1 , r := a . static int f( int n) { int a=0,i=n; m ( � s 2 � , � s 2 � ) , for (; n > 1 ; n=n/2 ) f ( � n � , � s 3 � ) , a += g(n).intValue(); init ( � s 0 , s 1 , s 2 , s 3 � , �� ) , f c ( � n , a � , � n , a � )::= for (; i > 1; i=i/2) r = s 0 . n > 1 , a *= h(i).intValue(); return a; g ( � n � , � s 0 � ) , } m ( � n � , � r � )::= intValue 1 ( � s 0 � , � s 0 � ) n ≤ 0 , a := a + s 0 , static Integer g(int n) { r := null . n := n / 2 , Integer x= new Integer(n); return new Integer(x.intValue()+1); f c ( � n , a � , � n , a � ) . } static Long h(int n) { f c ( � n , a � , � n , a � )::= return new Long(n-1); upm-seal ucm-seal unm-seal } n ≤ 1 . } Elvira Albert (UCM) Upper Bounds on Memory Usage Grenoble, June 28, 2009 5 / 17
Recommend
More recommend