Parametric Heap Usage Analysis for Functional Programs - PowerPoint PPT Presentation

1 / 27
About This Presentation
Title:

Parametric Heap Usage Analysis for Functional Programs

Description:

selection-sort(ls) Yes. Sis(lss) = 2lss 1. insertion-sort(ls) Yes. Srev ... Region-based memory management models heap recovery. Derives polynomial bounds. 21 ... – PowerPoint PPT presentation

Number of Views:32
Avg rating:3.0/5.0
Slides: 28
Provided by: nirmal5
Category:

less

Transcript and Presenter's Notes

Title: Parametric Heap Usage Analysis for Functional Programs


1
Parametric Heap Usage Analysis for Functional
Programs
  • Leena Unnikrishnan
  • Scott D. Stoller

2
Motivation
  • Goal upper bound on live heap usage.
  • Understanding memory usage of programs.
  • Guiding automatic methods, e.g., help program
    transformations select space-efficient programs.
  • Required for time analysis running times depend
    on memory allocation, garbage collection, etc.
  • Determining/verifying space usage of embedded
    applications.

3
Challenges
  • Determine live heap usage over entire program
    execution, and over multiple execution paths.
  • Unlike running times, live heap space increases
    and decreases during execution.
  • Static determination of liveness of objects.

4
Overview
  • Input Program P in a functional language with
    lists.
  • Output worst-case live heap usage of P expressed
    in terms of sizes of Ps inputs.
  • Example
  • Input program reverse(ls) to reverse a list
  • Output Max live heap usage 2ls - 1, if
    ls gt 0
  • Method
  • Transform functions in P into bound functions
    that describe their heap space usage and related
    metrics.
  • Simplify and rewrite bound functions into
    recurrences.
  • Solve recurrences into closed forms.

5
Outline
  • Bound functions
  • Recurrences containing the max operator
  • Soundness checks for R functions
  • Examples
  • Related work
  • Conclusion

6
Bound Functions
  • Construct three bound functions for each function
    f in program P.
  • Arguments of each bound function for f(v1,,vn)
    are the sizes v1s,,vns, of v1,,vn.
  • Size of a boolean or number its value
  • Size of a flat list its length

7
Bound Functions
  • For f(v1,,vn) in the input program, construct
  • Live heap space bound function, Sf(v1s,,vns)
    upper bound on live heap use of f, for all
    possible arguments v1,,vn, of sizes v1s,,vns.
  • New result-space bound function,
    Nf(v1s,,vns,v1w,,vnw) upper bound on amount of
    newly allocated space in the result of f, for all
    possible arguments v1,,vn, of sizes v1s,,vns.
    viw is the amount of new space in vi.
  • New is w.r.t. start of evaluation of call to f.
  • Size bound function, Rf(v1s,,vns) upper bound
    on size of result of f, for all possible
    arguments v1,,vn, of sizes v1s,,vns.

8
Live Heap Space Bound Functions
  • For f(v1,,vn) e, Sf(v1s,,vns) Se.
  • Example clauses in the definition of S..
  • Sv 0, Scons(e1, e2) 1 max(Se1,
    Se2)
  • Sf(e1, e2) max(Se1,
  • Ne1 Se2,
  • Ne1 Ne2
    Sf(Re1, Re2))

9
Size Bound Functions
  • For f(v1,,vn) e, Rf(v1s,,vns) Re.
  • Example clauses in the definition of R..
  • Rv vs , Rcons(e1, e2) 1 Re2
  • Rif p then e1 else e2
  • max(Re1, Re2), if p contains car
  • if Rp then Re1 else Re2
  • Rf(e1,,en) Rf(Re1,, Ren)


10
New Result-Space Bound Functions
  • For f(v) in the input, the N function is Nf(vs,
    vw).
  • f(e) in input program yields Nf(Re, Ne) in
    bound functions.
  • New is w.r.t. the start of evaluation of
    f(e).
  • vw is the part of v created in e.
  • Nf() is the part of the result created in e or
    the body of f.
  • For f(v) e, Nf(vs, vw) Ne.
  • Example clauses in the definition of N..
  • Nv vw , Ncons(e1, e2) 1 Ne2
  • Nf(e1,,en) Nf(Re1,,Ren, Ne1,,Nen)

11
New Result-Space Bound Functions
12
Outline
  • Bound functions
  • Recurrences containing the max operator
  • Soundness checks for R functions
  • Examples
  • Related work
  • Conclusion

13
Composite Recurrences
  • Bound functions are simplified into recurrences
    that may contain max. We call these composite
    recurrences.
  • Example For insert in insertion sort,
  • Rins(n) max(1n, 1Rins(n-1)), if
    ngt0
  • Solve composite recurrences using a library of
    solution templates.

14
Solving Composite Recurrences Example
  • For a recurrence of the form
  • where, the arguments of max are equal for
  • (a) base cases, i.e.,
  • e1(n) e2(n) ac(n-b-i1), for
    n in ij1, ijb
  • (b) all other values of n, i.e.
  • e1(n) e2(n) ae1(n-b), for ngt(ijb)
  • the solution is T(n) e1(n), for ngt(ij).

15
Outline
  • Bound functions
  • Recurrences containing the max operator
  • Soundness checks for R functions
  • Examples
  • Related work
  • Conclusion

16
Soundness Checks on Uses of R Functions
  • Intuition It is not necessarily the object with
    the largest size that leads to worst-case live
    heap usage.
  • R function results are arguments to S and N
    functions.
  • Consider the R function, Rf(n), of greaterlist
    in quicksort.
  • Rf(n) is the maximum of a set of values. Rf
    is a complex R function.

17
Soundness Checks on Uses of R functions
  • Using the result of Rf(n) as an argument to a
    bound function, say Sg, yields a true upper bound
    down the line, only if the following hold
  • Case 1 If Sg(Rf(n)) is a recursive call in the
    body of Sg, then using the result of Rf(n) in the
    definition of Sg, yields the maximum result.
    E.g., this holds for recurrences of the form
  • where
  • base values of T are monotonically increasing
  • largest base value lt value at smallest non-base
    input
  • e(n) is monotonically increasing w.r.t. n
  • Case 2 check if the solution of Sg is
    monotonically increasing w.r.t. its single
    argument.

18
Improving Solvability of Recurrences
  • Eliminate unused arguments from bound functions.
  • Simplifies recurrences. May eliminate dependence
    on other recurrences.
  • Use invariants to simplify max expressions.
  • May simplify composite recurrences or make them
    regular.
  • Example Sf(e1,,en) ? Nf(e1,,en,0,,0).
  • So, max(Sf(e1,,en),
    Nf(e1,,en,0,,0)) Sf(e1,,en).
  • Use simpler, approximate definitions of N
    functions.
  • precise Nf(v1s,,vns, v1w,,vnw) Ne
  • approx Nf(v1s,,vns)
    Rf(v1s,,vns)
  • In our examples, even with this simplification,
    we get tight bounds on worst-case space usage.

19
Examples
Program S Function (vs gt c) Tight?
reverse(ls) Srev(lss) 2lss 1 Yes
insertion-sort(ls) Sis(lss) 2lss 1 Yes
selection-sort(ls) Sss(lss) lss(lss1)/2 Yes
merge-sort(ls) Sms(lss) 2lss 1 Yes
quicksort(ls) Sqs(lss) 32lss-1 1 No
longest-common-subseq(ls1, ls2) Slcs(ls1s, ls2s) 2ls2s 2 Yes
string-edit-distance(ls1, ls2) Sse(ls1s, ls2s) 2ls1 2ls2 1 Yes
binomial-coefficient(n, m) Sbc(ns,ms) 2ms2, if msltns Yes
  • Derives linear, quadratic, and exponential
    bounds.
  • Bounds are tight (exact) for all examples except
    quicksort.

20
Related Work
  • Timing analysis using recurrence relations
    Wegbreit 75, LeMetayer 88.
  • Static prediction of heap space Hofmann Jost
    03
  • Applies to a linearly-typed functional language.
  • Derives linear heap bounds.
  • Parametric prediction of heap memory requirements
    Braberman et al 08
  • Java-like language.
  • Region-based memory management models heap
    recovery.
  • Derives polynomial bounds.

21
Related Work
  • Memory resource bounds for low-level programs
    Chin et al 08
  • Assembly-like language.
  • Explicit deallocation to model heap recovery.
  • Derives linear bounds.
  • Cost analysis Albert et al 07
  • Java bytecode.
  • Escape analysis to model heap recovery.
  • Analysis for live heap at ISMM 09!

22
Conclusion
  • Automatic, accurate analysis of live heap usage
    of functional programs.
  • Framework of bound functions that describe live
    heap usage of input programs.
  • Methods to simplify and solve composite
    recurrences.
  • Soundness checks involving monotonicity and
    monotonicitylike properties of recurrences.
  • Results are at source-code level and are easy to
    understand.
  • Results are not restricted to any complexity
    class.

23
Thank You!
24
Extensions to Handle Other Data Types
  • Specialize R functions and size arguments to each
    data type.
  • Binary Trees
  • Possible size measures height, total.
  • R functions Rheight, Rtotal
  • Extend S, N, R transformations to new data type.
  • Rheighttree(e, el, er) 1 max(Rheightel,
    Rheighter)
  • Rtotal tree(e, el, er) 1 Rtotalel
    Rtotaler
  • Live heap usage of a given program may be better
    represented in terms of one specific size
    measure, than others.

25
Example
Input Program
26
Example
Input Program
27
Example
Closed Forms
Write a Comment
User Comments (0)
About PowerShow.com