Incrementalized Pointer and Escape Analysis Frdric Vivien Martin - - PowerPoint PPT Presentation

incrementalized pointer and escape analysis
SMART_READER_LITE
LIVE PREVIEW

Incrementalized Pointer and Escape Analysis Frdric Vivien Martin - - PowerPoint PPT Presentation

Incrementalized Pointer and Escape Analysis Frdric Vivien Martin Rinard ICPS/LSIIT Laboratory for Computer Science Universit Louis Pasteur Massachusetts Institute of Technology Strasbourg, France Cambridge, MA, USA Start with a


slide-1
SLIDE 1

Incrementalized Pointer and Escape Analysis

Frédéric Vivien

ICPS/LSIIT Université Louis Pasteur Strasbourg, France

Martin Rinard

Laboratory for Computer Science Massachusetts Institute of Technology Cambridge, MA, USA

slide-2
SLIDE 2

void compute(d,e) ———— ———— ———— void multiplyAdd(a,b,c) ————————— ————————— ————————— void multiply(m) ———— ———— ———— void add(u,v) —————— —————— void main(i,j) ——————— ——————— ——————— void evaluate(i,j) —————— —————— —————— void abs(r) ———— ———— ———— void scale(n,m) —————— ——————

Start with a program

slide-3
SLIDE 3

void compute(d,e) ———— ———— ———— void multiplyAdd(a,b,c) ————————— ————————— ————————— void multiply(m) ———— ———— ———— void add(u,v) —————— —————— void main(i,j) ——————— ——————— ——————— void evaluate(i,j) —————— —————— —————— void abs(r) ———— ———— ———— void scale(n,m) —————— ——————

Lots of allocation sites

slide-4
SLIDE 4

void compute(d,e) ———— ———— ———— void multiplyAdd(a,b,c) ————————— ————————— ————————— void multiply(m) ———— ———— ———— void add(u,v) —————— —————— void main(i,j) ——————— ——————— ——————— void evaluate(i,j) —————— —————— —————— void abs(r) ———— ———— ———— void scale(n,m) —————— ——————

Stack Allocation Optimization

slide-5
SLIDE 5

void compute(d,e) ———— ———— ———— void multiplyAdd(a,b,c) ————————— ————————— ————————— void multiply(m) ———— ———— ———— void add(u,v) —————— —————— void main(i,j) ——————— ——————— ——————— void evaluate(i,j) —————— —————— —————— void abs(r) ———— ———— ———— void scale(n,m) —————— ——————

Stack Allocation Optimization Precise Whole-Program Pointer and Escape Analysis

slide-6
SLIDE 6

Drawbacks to Whole-Program Analysis

  • Resource Intensive
  • Large analysis times
  • Large memory consumption
  • Unsuitable for partial programs
slide-7
SLIDE 7

void compute(d,e) ———— ———— ———— void multiplyAdd(a,b,c) ————————— ————————— ————————— void multiply(m) ———— ———— ———— void add(u,v) —————— —————— void main(i,j) ——————— ——————— ——————— void evaluate(i,j) —————— —————— —————— void abs(r) ———— ———— ———— void scale(n,m) —————— ——————

Key Observation Number One: Most

  • ptimizations

require only the analysis of a small part of program surrounding the

  • bject allocation

site

slide-8
SLIDE 8

void compute(d,e) ———— ———— ———— void multiplyAdd(a,b,c) ————————— ————————— ————————— void multiply(m) ———— ———— ———— void add(u,v) —————— —————— void main(i,j) ——————— ——————— ——————— void evaluate(i,j) —————— —————— —————— void abs(r) ———— ———— ———— void scale(n,m) —————— ——————

Key Observation Number Two: Most of the

  • ptimization

benefit comes from a small percentage of the allocation sites 99% of objects allocated at these two sites

slide-9
SLIDE 9

void compute(d,e) ———— ———— ———— void multiplyAdd(a,b,c) ————————— ————————— ————————— void multiply(m) ———— ———— ———— void add(u,v) —————— —————— void main(i,j) ——————— ——————— ——————— void evaluate(i,j) —————— —————— —————— void abs(r) ———— ———— ———— void scale(n,m) —————— ——————

Intuition for Better Analysis

  • Locate important

allocation sites

  • Use demand-

driven approach to analyze region surrounding site

  • Somehow avoid

sinking analysis resources into sites that can’t be

  • ptimized

99% of objects allocated at these two sites

slide-10
SLIDE 10

What This Talk is About

How we turned this intuition into an algorithm that usually 1) obtains almost all the benefit of the whole program analysis 2) analyzes a small fraction of program 3) consumes a small fraction of whole program analysis time

slide-11
SLIDE 11

Structure of Talk

  • Motivating Example
  • Base whole program analysis

(Whaley and Rinard, OOPSLA 99)

  • Incrementalized analysis
  • Analysis policy
  • Experimental results
  • Conclusion
slide-12
SLIDE 12

Motivating Example

slide-13
SLIDE 13

Employee Database Example

  • Read in database of employee records
  • Extract statistics like max salary
slide-14
SLIDE 14

Employee Database Example

  • Read in database of employee records
  • Extract statistics like max salary

Name Salary John Doe $45,000 Ben Bit $30,000 Jane Roe $55,000 Vector

slide-15
SLIDE 15

Computing Max Salary

  • Traverse Records to Find Max Salary

John Doe $45,000 Name Salary Ben Bit $30,000 Jane Roe $55,000 Vector max = $0

slide-16
SLIDE 16

Computing Max Salary

  • Traverse Records to Find Max Salary

John Doe $45,000 Name Salary Ben Bit $30,000 Jane Roe $55,000 Vector max = $45,000 who = John Doe

slide-17
SLIDE 17

Computing Max Salary

  • Traverse Records to Find Max Salary

John Doe $45,000 Name Salary Ben Bit $30,000 Jane Roe $55,000 Vector max = $45,000 who = John Doe

slide-18
SLIDE 18

Computing Max Salary

  • Traverse Records to Find Max Salary

John Doe $45,000 Name Salary Ben Bit $30,000 Jane Roe $55,000 Vector max = $55,000 who = Jane Roe

slide-19
SLIDE 19

Computing Max Salary

  • Traverse Records to Find Max Salary

John Doe $45,000 Name Salary Ben Bit $30,000 Jane Roe $55,000 Vector max salary = $55,000 highest paid = Jane Roe

slide-20
SLIDE 20

Coding Max Computation (in Java)

class EmployeeDatabase { Vector database = new Vector(); Employee highestPaid; void computeMax() { int max = 0; Enumeration enum = database.elements(); while (enum.hasMoreElements()) { Employee e = enum.nextElement(); if (max < e.salary()) { max = e.salary(); highestPaid = e; } } } }

slide-21
SLIDE 21

Coding Max Computation (in Java)

class EmployeeDatabase { Vector database = new Vector(); Employee highestPaid; void computeMax() { int max = 0; Enumeration enum = database.elements(); while (enum.hasMoreElements()) { Employee e = enum.nextElement(); if (max < e.salary()) { max = e.salary(); highestPaid = e; } } } }

slide-22
SLIDE 22

Issues In Implementation

  • Enumeration object allocated on heap
  • Increases heap memory usage
  • Increases garbage collection frequency
  • Heap allocation is unnecessary
  • Enumeration object allocated inside max
  • Not accessible outside max
  • Should be able to use stack allocation
slide-23
SLIDE 23

Basic Idea

Use pointer and escape analysis to recognize captured objects Transform program to allocate captured objects

  • n stack
slide-24
SLIDE 24

Base Analysis

slide-25
SLIDE 25

Base Analysis

  • Basic Abstraction: Points-to Escape Graph
  • Intraprocedural Analysis
  • Flow sensitive abstract interpretation
  • Produces points-to escape graph at each

program point

  • Interprocedural Analysis
  • Bottom Up and Compositional
  • Analyzes each method once to obtain a

single parameterized analysis result

  • Result is specialized for use at each call site
slide-26
SLIDE 26

Points-to Escape Graph in Example

void computeMax() { int max = 0; Enumeration enum = database.elements(); while (enum.hasMoreElements()) { Employee e = enum.nextElement(); if (max < e.salary()) { max = e.salary(); highestPaid = e; } } }

vector elementData [ ]

this enum e

database highestPaid

slide-27
SLIDE 27

Edge Types

  • Inside Edges:
  • created in currently analyzed part of

program

  • Outside Edges:
  • created outside currently analyzed part of

program

vector elementData [ ]

this enum e

database highestPaid

dashed = outside solid = inside

slide-28
SLIDE 28

Node Types

  • Inside Nodes:
  • Represent objects created in currently

analyzed part of program

  • Outside Nodes:
  • Parameter nodes – represent parameters
  • Load nodes - represent objects accessed via

pointers created outside analyzed part

vector elementData [ ]

this enum e

database highestPaid

dashed = outside solid = inside

slide-29
SLIDE 29

Escaped Nodes

  • Escaped nodes
  • parameter nodes
  • thread nodes
  • returned nodes
  • nodes reachable from other escaped nodes
  • Captured is the opposite of escaped

vector elementData [ ]

this enum e

database highestPaid

green = escaped white = captured

slide-30
SLIDE 30

Stack Allocation Optimization

  • Examine graph from end of method
  • If a node is captured in this graph
  • Allocate corresponding objects on stack (may

need to inline methods to apply optimization)

vector elementData [ ]

this enum e

database highestPaid

green = escaped white = captured

Can allocate enum object on stack

slide-31
SLIDE 31

Interprocedural Analysis

void printStatistics(BufferedReader r) { EmployeeDatabase e = new EmployeeDatabase(r); e.computeMax(); System.out.println(“max salary = “ + e.highestPaid); }

slide-32
SLIDE 32

Start with graph before call site

void printStatistics(BufferedReader r) { EmployeeDatabase e = new EmployeeDatabase(r); e.computeMax(); System.out.println(“max salary = “ + e.highestPaid); } e

graph before call site

elementData [ ] database

slide-33
SLIDE 33

Retrieve graph from end of callee

void printStatistics(BufferedReader r) { EmployeeDatabase e = new EmployeeDatabase(r); e.computeMax(); System.out.println(“max salary = “ + e.highestPaid); } e

graph before call site

elementData [ ] database elementData [ ]

this

database highestPaid

Enum object is not present because it was captured in the callee

slide-34
SLIDE 34

Map formals to actuals

void printStatistics(BufferedReader r) { EmployeeDatabase e = new EmployeeDatabase(r); e.computeMax(); System.out.println(“max salary = “ + e.highestPaid); } e

graph before call site

elementData [ ] database elementData [ ]

this

database highestPaid

slide-35
SLIDE 35

Match corresponding inside and

  • utside edges to complete mapping

void printStatistics(BufferedReader r) { EmployeeDatabase e = new EmployeeDatabase(r); e.computeMax(); System.out.println(“max salary = “ + e.highestPaid); } e

graph before call site

elementData [ ] database elementData [ ]

this

database highestPaid

slide-36
SLIDE 36

Match corresponding inside and

  • utside edges to complete mapping

void printStatistics(BufferedReader r) { EmployeeDatabase e = new EmployeeDatabase(r); e.computeMax(); System.out.println(“max salary = “ + e.highestPaid); } e

graph before call site

elementData [ ] database elementData [ ]

this

database highestPaid

slide-37
SLIDE 37

Match corresponding inside and

  • utside edges to complete mapping

void printStatistics(BufferedReader r) { EmployeeDatabase e = new EmployeeDatabase(r); e.computeMax(); System.out.println(“max salary = “ + e.highestPaid); } e

graph before call site

elementData [ ] database elementData [ ]

this

database highestPaid

slide-38
SLIDE 38

Match corresponding inside and

  • utside edges to complete mapping

void printStatistics(BufferedReader r) { EmployeeDatabase e = new EmployeeDatabase(r); e.computeMax(); System.out.println(“max salary = “ + e.highestPaid); } e

graph before call site

elementData [ ] database elementData [ ]

this

database highestPaid

slide-39
SLIDE 39

Combine graphs to obtain new graph after call site

void printStatistics(BufferedReader r) { EmployeeDatabase e = new EmployeeDatabase(r); e.computeMax(); System.out.println(“max salary = “ + e.highestPaid); } e

graph before call site

elementData [ ] database elementData [ ]

this

database highestPaid

graph after call site

e

elementData [ ] highestPaid

slide-40
SLIDE 40

Continue analysis after call site

void printStatistics(BufferedReader r) { EmployeeDatabase e = new EmployeeDatabase(r); e.computeMax(); System.out.println(“max salary = “ + e.highestPaid); } e

graph before call site

elementData [ ] database

graph after call site

e

elementData [ ] highestPaid

slide-41
SLIDE 41

Whole Program Analysis

void computeMax() ———— ———— ———— Enumeration elements() ——— ——— ——— Vector elementData() ———— ———— ———— boolean hasMoreElements() —————— —————— —————— void printStatistics() ——————— ——————— ——————— Employee nextElement() —————— —————— int salary() —————— ——————

slide-42
SLIDE 42

Whole Program Analysis

void computeMax() ———— ———— ———— Enumeration elements() ——— ——— ——— Vector elementData() ———— ———— ———— boolean hasMoreElements() —————— —————— —————— void printStatistics() ——————— ——————— ——————— Employee nextElement() —————— —————— int salary() —————— ——————

slide-43
SLIDE 43

Whole Program Analysis

void computeMax() ———— ———— ———— Enumeration elements() ——— ——— ——— Vector elementData() ———— ———— ———— boolean hasMoreElements() —————— —————— —————— void printStatistics() ——————— ——————— ——————— Employee nextElement() —————— —————— int salary() —————— ——————

slide-44
SLIDE 44

Whole Program Analysis

void computeMax() ———— ———— ———— Enumeration elements() ——— ——— ——— Vector elementData() ———— ———— ———— boolean hasMoreElements() —————— —————— —————— void printStatistics() ——————— ——————— ——————— Employee nextElement() —————— —————— int salary() —————— ——————

slide-45
SLIDE 45

Whole Program Analysis

void computeMax() ———— ———— ———— Enumeration elements() ——— ——— ——— Vector elementData() ———— ———— ———— boolean hasMoreElements() —————— —————— —————— void printStatistics() ——————— ——————— ——————— Employee nextElement() —————— —————— int salary() —————— ——————

slide-46
SLIDE 46

Whole Program Analysis

void computeMax() ———— ———— ———— Enumeration elements() ——— ——— ——— Vector elementData() ———— ———— ———— boolean hasMoreElements() —————— —————— —————— void printStatistics() ——————— ——————— ——————— Employee nextElement() —————— —————— int salary() —————— ——————

slide-47
SLIDE 47

Whole Program Analysis

void computeMax() ———— ———— ———— Enumeration elements() ——— ——— ——— Vector elementData() ———— ———— ———— boolean hasMoreElements() —————— —————— —————— void printStatistics() ——————— ——————— ——————— Employee nextElement() —————— —————— int salary() —————— ——————

slide-48
SLIDE 48

Whole Program Analysis

void computeMax() ———— ———— ———— Enumeration elements() ——— ——— ——— Vector elementData() ———— ———— ———— boolean hasMoreElements() —————— —————— —————— void printStatistics() ——————— ——————— ——————— Employee nextElement() —————— —————— int salary() —————— ——————

slide-49
SLIDE 49

Incrementalized Analysis

slide-50
SLIDE 50

Incrementalized Analysis Requirements

Must be able to

  • Analyze method independently of callers
  • Base analysis is compositional
  • Already does this
  • Skip analysis of invoked methods
  • But later incrementally integrate analysis

results if desirable to do so

slide-51
SLIDE 51

First Extension to Base Analysis

  • Skip the analysis of invoked methods
  • Parameters are marked as escaping into

skipped call site Assume analysis skips enum.nextElement()

vector

1

this enum e

database highestPaid

Node 1 escapes into enum.nextElement()

slide-52
SLIDE 52

First Extension Almost Works

  • Can skip analysis of invoked methods
  • If allocation site is captured, great!
  • If not, escape information tells you what

methods you should have analyzed… Should have analyzed enum.nextElement()

vector

1

this enum e

database highestPaid

Node 1 escapes into enum.nextElement()

slide-53
SLIDE 53

Second Extension to Base Algorithm

  • Record enough information to undo skip and

incorporate analysis into existing result

  • Parameter mapping at call site
  • Ordering information for call sites
slide-54
SLIDE 54

void compute() {

—————— ——————

foo(x,y);

——————— ——————— ———————

}

Graph before call site Graph after call site Graph at end

  • f method

Graphs from Whole Program Analysis

Generated during analysis Used to apply stack allocation

  • ptimization
slide-55
SLIDE 55

void compute() {

—————— ——————

foo(x,y);

——————— ——————— ———————

}

Graph before call site Graph after skipped call site Graph at end

  • f method

Graphs from Incrementalized Analysis

Generated during analysis Used to apply stack allocation

  • ptimization
slide-56
SLIDE 56

Incorporating Result from Skipped Call Site

Naive approach: use mapping algorithm directly

  • n graph from end of caller method

Before incorporating result from skipped call site After incorporating result from skipped call site

slide-57
SLIDE 57

Incorporating Result from Skipped Call Site

Naive approach: use mapping algorithm directly

  • n graph from end of caller method

Graph from whole program analysis After incorporating result from skipped call site

slide-58
SLIDE 58

Basic Problem and Solution

  • Problem: additional edges in graph from end
  • f method make result less precise
  • Solution: augment abstraction
  • For each call skipped call site, record
  • Edges which were present in the graph

before the call site

  • Edges which were present after call site
  • Use this information when incorporating

results from skipped call sites

slide-59
SLIDE 59

After Augmenting Abstraction

Graph from whole program analysis After incorporating result from skipped call site

slide-60
SLIDE 60

void computeMax() ———— ———— ———— Enumeration elements() ——— ——— ——— Vector elementData() ———— ———— ———— boolean hasMoreElements() —————— —————— —————— void printStatistics() ——————— ——————— ——————— Employee nextElement() —————— —————— int salary() —————— ——————

Incrementalized Analysis

slide-61
SLIDE 61

void computeMax() ———— ———— ———— Enumeration elements() ——— ——— ——— Vector elementData() ———— ———— ———— boolean hasMoreElements() —————— —————— —————— void printStatistics() ——————— ——————— ——————— Employee nextElement() —————— —————— int salary() —————— ——————

Incrementalized Analysis

Attempt to stack allocate Enumeration object from elements

slide-62
SLIDE 62

void computeMax() ———— ———— ———— Enumeration elements() ——— ——— ——— Vector elementData() ———— ———— ———— boolean hasMoreElements() —————— —————— —————— void printStatistics() ——————— ——————— ——————— Employee nextElement() —————— —————— int salary() —————— ——————

Incrementalized Analysis

Analyze elements

(intraprocedurally)

slide-63
SLIDE 63

void computeMax() ———— ———— ———— Enumeration elements() ——— ——— ——— Vector elementData() ———— ———— ———— boolean hasMoreElements() —————— —————— —————— void printStatistics() ——————— ——————— ——————— Employee nextElement() —————— —————— int salary() —————— ——————

Incrementalized Analysis

Analyze elements

(intraprocedurally)

slide-64
SLIDE 64

void computeMax() ———— ———— ———— Enumeration elements() ——— ——— ——— Vector elementData() ———— ———— ———— boolean hasMoreElements() —————— —————— —————— void printStatistics() ——————— ——————— ——————— Employee nextElement() —————— —————— int salary() —————— ——————

Incrementalized Analysis

Analyze elements

(intraprocedurally)

Escapes only into the caller

slide-65
SLIDE 65

void computeMax() ———— ———— ———— Enumeration elements() ——— ——— ——— Vector elementData() ———— ———— ———— boolean hasMoreElements() —————— —————— —————— void printStatistics() ——————— ——————— ——————— Employee nextElement() —————— —————— int salary() —————— ——————

Incrementalized Analysis

Analyze computeMax

(intraprocedurally)

slide-66
SLIDE 66

void computeMax() ———— ———— ———— Enumeration elements() ——— ——— ——— Vector elementData() ———— ———— ———— boolean hasMoreElements() —————— —————— —————— void printStatistics() ——————— ——————— ——————— Employee nextElement() —————— —————— int salary() —————— ——————

Incrementalized Analysis

Analyze computeMax

(intraprocedurally)

slide-67
SLIDE 67

void computeMax() ———— ———— ———— Enumeration elements() ——— ——— ——— Vector elementData() ———— ———— ———— boolean hasMoreElements() —————— —————— —————— void printStatistics() ——————— ——————— ——————— Employee nextElement() —————— —————— int salary() —————— ——————

Incrementalized Analysis

Analyze computeMax

(intraprocedurally)

Escapes to

  • hasMoreElements
  • nextElement
slide-68
SLIDE 68

void computeMax() ———— ———— ———— Enumeration elements() ——— ——— ——— Vector elementData() ———— ———— ———— boolean hasMoreElements() —————— —————— —————— void printStatistics() ——————— ——————— ——————— Employee nextElement() —————— —————— int salary() —————— ——————

Incrementalized Analysis

Analyze hasMoreElements

slide-69
SLIDE 69

void computeMax() ———— ———— ———— Enumeration elements() ——— ——— ——— Vector elementData() ———— ———— ———— boolean hasMoreElements() —————— —————— —————— void printStatistics() ——————— ——————— ——————— Employee nextElement() —————— —————— int salary() —————— ——————

Incrementalized Analysis

Analyze hasMoreElements

slide-70
SLIDE 70

void computeMax() ———— ———— ———— Enumeration elements() ——— ——— ——— Vector elementData() ———— ———— ———— boolean hasMoreElements() —————— —————— —————— void printStatistics() ——————— ——————— ——————— Employee nextElement() —————— —————— int salary() —————— ——————

Incrementalized Analysis

Analyze hasMoreElements Combine results

slide-71
SLIDE 71

void computeMax() ———— ———— ———— Enumeration elements() ——— ——— ——— Vector elementData() ———— ———— ———— boolean hasMoreElements() —————— —————— —————— void printStatistics() ——————— ——————— ——————— Employee nextElement() —————— —————— int salary() —————— ——————

Incrementalized Analysis

Analyze hasMoreElements Combine results Still escaping to

  • nextElement
slide-72
SLIDE 72

void computeMax() ———— ———— ———— Enumeration elements() ——— ——— ——— Vector elementData() ———— ———— ———— boolean hasMoreElements() —————— —————— —————— void printStatistics() ——————— ——————— ——————— Employee nextElement() —————— —————— int salary() —————— ——————

Incrementalized Analysis

Analyze nextElement

slide-73
SLIDE 73

void computeMax() ———— ———— ———— Enumeration elements() ——— ——— ——— Vector elementData() ———— ———— ———— boolean hasMoreElements() —————— —————— —————— void printStatistics() ——————— ——————— ——————— Employee nextElement() —————— —————— int salary() —————— ——————

Incrementalized Analysis

Analyze nextElement

slide-74
SLIDE 74

void computeMax() ———— ———— ———— Enumeration elements() ——— ——— ——— Vector elementData() ———— ———— ———— boolean hasMoreElements() —————— —————— —————— void printStatistics() ——————— ——————— ——————— Employee nextElement() —————— —————— int salary() —————— ——————

Incrementalized Analysis

Analyze nextElement Combine results

slide-75
SLIDE 75

void computeMax() ———— ———— ———— Enumeration elements() ——— ——— ——— Vector elementData() ———— ———— ———— boolean hasMoreElements() —————— —————— —————— void printStatistics() ——————— ——————— ——————— Employee nextElement() —————— —————— int salary() —————— ——————

Incrementalized Analysis

Analyze nextElement Combine results

slide-76
SLIDE 76

void computeMax() ———— ———— ———— Enumeration elements() ——— ——— ——— Vector elementData() ———— ———— ———— boolean hasMoreElements() —————— —————— —————— void printStatistics() ——————— ——————— ——————— Employee nextElement() —————— —————— int salary() —————— ——————

Incrementalized Analysis

Enumeration object Captured in computeMax

slide-77
SLIDE 77

void computeMax() ———— ———— ———— Enumeration elements() ——— ——— ——— Vector elementData() ———— ———— ———— boolean hasMoreElements() —————— —————— —————— void printStatistics() ——————— ——————— ——————— Employee nextElement() —————— —————— int salary() —————— ——————

Incrementalized Analysis

Enumeration object Captured in computeMax Inline elements Stack allocate enumeration object

slide-78
SLIDE 78

void computeMax() ———— ———— ———— Enumeration elements() ——— ——— ——— Vector elementData() ———— ———— ———— boolean hasMoreElements() —————— —————— —————— void printStatistics() ——————— ——————— ——————— Employee nextElement() —————— —————— int salary() —————— ——————

Incrementalized Analysis

We skipped the analysis of some methods

slide-79
SLIDE 79

void computeMax() ———— ———— ———— Enumeration elements() ——— ——— ——— Vector elementData() ———— ———— ———— boolean hasMoreElements() —————— —————— —————— void printStatistics() ——————— ——————— ——————— Employee nextElement() —————— —————— int salary() —————— ——————

Incrementalized Analysis

We skipped the analysis of some methods We ignored some other methods

slide-80
SLIDE 80

Result

  • We can incrementally analyze
  • Only what is needed
  • For whatever allocation site we want
  • And even temporarily suspend analysis

part of the way through!

slide-81
SLIDE 81

New Issue

  • We can incrementally analyze
  • Only what is needed
  • For whatever allocation site we want
  • And even temporarily suspend analysis

part of the way through! But…

  • Lots of analysis opportunities
  • Not all opportunities are profitable
  • Where to invest analysis resources?
  • How much resources to invest?
slide-82
SLIDE 82

Analysis Policy

Formulate policy as solution to an investment problem Goal Maximize optimization payoff from invested analysis resources

slide-83
SLIDE 83

Analysis Policy Implementation

  • For each allocation site, estimate marginal

return on invested analysis resources

  • Loop
  • Invest a unit of analysis resources (time)

in site that offers best return Expand analyzed region surrounding site

  • When unit expires, recompute marginal

returns (best site may change)

slide-84
SLIDE 84

Marginal Return Estimate

N · P(d) C · T N = Number of objects allocated at the site P(d) = Probability of capturing the site, knowing we explored a region of call depth d C = Number of skipped call sites the allocation site escapes through

T = Average time needed to analyze a call site

slide-85
SLIDE 85

Marginal Return Estimate

N · P(d) C · T As invest analysis resources

  • explore larger regions around allocation sites
  • get more information about sites
  • marginal return estimates improve
  • analysis makes better investment decisions!
slide-86
SLIDE 86

Usage Scenarios

  • Ahead of time compiler
  • Give algorithm an analysis budget
  • Algorithm spends budget
  • Takes whatever optimizations it uncovered
  • Dynamic compiler
  • Algorithm acquires analysis budget as a

percentage of run time

  • Periodically spends budget, delivers

additional optimizations

  • Longer program runs, more optimizations
slide-87
SLIDE 87

Experimental Results

slide-88
SLIDE 88

Methodology

  • Implemented analysis in MIT Flex System
  • Obtained several benchmarks
  • Scientific computations: barnes, water
  • Our lexical analyzer: jlex
  • Spec benchmarks: db, raytrace, compress
slide-89
SLIDE 89

Analysis Times

25 50 75 100 125 150 barnes water jlex db raytrace compress Analysis Time (seconds)

Incrementalized Analysis Whole-Program Analysis

223 645 jdk 1.2

slide-90
SLIDE 90

Allocation Sites Analyzed

Total Allocation Sites Touched

20 40 60 80 100 barnes water jlex db raytrace compress Number of Sites Captured Non-Optimizable Undecided

slide-91
SLIDE 91

Allocation Sites Analyzed

Percentage of Allocation Sites Touched

2 4 6 8 10 barnes water jlex db raytrace compress

slide-92
SLIDE 92

Distribution of Allocated Objects

10 20 30 40 50 60 70 80 90 100 1 2 3 4 5 6 7 8 9 10 % of Allocation Sites % of Allocated Objects barnes water jlex db raytrace compress

slide-93
SLIDE 93

Analysis Time Payoff

Stack allocated by incrementalized analysis Decided Stack allocated by whole-program analysis

20 40 60 80 100

25 50 75

20 40 60 80 100

25 50 75

20 40 60 80 100

1 2 3 4

% of Objects

20 40 60 80 100

0.2 0.4 0.6 0.8 1

20 40 60 80 100

10 20

20 40 60 80 100

0.2 0.4 0.6 0.8

% of Objects

Analysis Time (seconds) Analysis Time (seconds) Analysis Time (seconds)

compress raytrace db

Analysis Time (seconds) Analysis Time (seconds) Analysis Time (seconds)

barnes water jlex

slide-94
SLIDE 94

Stack Allocation

Percentage of Memory Allocated on Stack

20 40 60 80 100 barnes water jlex db raytrace compress

Incrementalized Analysis Whole-Program Analysis

slide-95
SLIDE 95

Normalized Execution Times

20 40 60 80 100 barnes water jlex db raytrace compress

Incrementalized Analysis Whole-Program Analysis

Reference: execution time without optimization

slide-96
SLIDE 96

Experimental Summary

Key Application Properties Most objects allocated at very few allocation sites Can capture objects with an incremental analysis

  • f region surrounding allocation sites

Consequence Most of the benefits of whole-program analysis Fraction of the cost of whole-program analysis

slide-97
SLIDE 97

Related Work

Demand-driven Analyses

  • Horwitz, Reps, Sagiv (FSE 1995)
  • Duesterwald, Soffa, Gupta (TOPLAS 1997)
  • Heintze, Tardieu (PLDI 2001)

Key differences

  • Integration of escape information enables

incrementalized algorithms to suspend partially completed analyses

  • Maintain accurate marginal payoff estimates
  • Avoid overly costly analyses
slide-98
SLIDE 98

Related Work

Previous Escape Analyses

  • Blanchet (OOPSLA 1999)
  • Bogda, Hoelzle (OOPSLA 1999)
  • Choi, Gupta, Serrano, Sreedhar, Midkiff (OOPSLA 1999)
  • Whaley, Rinard (OOPSLA 1999)
  • Ruf (PLDI 2000)

Key Differences

  • Previous algorithms analyze whole program
  • But could incrementalize other analyses
  • Get a range of algorithms with varying

analysis time/precision tradeoffs

slide-99
SLIDE 99

Conclusion

Whole-Program Analysis Incrementalized Analysis

Properties

  • Uses escape information to incrementally analyze

relevant regions of program

  • Analysis policy driven by estimates of optimization

benefits and costs

Results

  • Most of benefits of whole program analysis
  • Fraction of the cost