1 / 97

Incrementalized Pointer and Escape Analysis

This talk presents an algorithm for incrementalized pointer and escape analysis that optimizes stack allocation by analyzing a small fraction of the program, resulting in improved performance and reduced resource consumption.

pjulio
Télécharger la présentation

Incrementalized Pointer and Escape Analysis

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Frédéric Vivien ICPS/LSIIT Université Louis Pasteur Strasbourg, France Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology Cambridge, MA, USA Incrementalized Pointer and Escape Analysis

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

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

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

  5. Stack Allocation Optimization void main(i,j) ——————— ——————— ——————— Precise Whole-Program Pointer and Escape Analysis void compute(d,e) ———— ———— ———— void evaluate(i,j) —————— —————— —————— void multiplyAdd(a,b,c) ————————— ————————— ————————— void abs(r) ———— ———— ———— void scale(n,m) —————— —————— void multiply(m) ———— ———— ———— void add(u,v) —————— ——————

  6. Drawbacks to Whole-Program Analysis • Resource Intensive • Large analysis times • Large memory consumption • Unsuitable for partial programs

  7. Key Observation Number One: void main(i,j) ——————— ——————— ——————— Most optimizations require only the analysis of a small part of program surrounding the object allocation site void compute(d,e) ———— ———— ———— void evaluate(i,j) —————— —————— —————— void multiplyAdd(a,b,c) ————————— ————————— ————————— void abs(r) ———— ———— ———— void scale(n,m) —————— —————— void multiply(m) ———— ———— ———— void add(u,v) —————— ——————

  8. Key Observation Number Two: void main(i,j) ——————— ——————— ——————— Most of the optimization benefit comes from a small percentage of the allocation sites void compute(d,e) ———— ———— ———— void evaluate(i,j) —————— —————— —————— void multiplyAdd(a,b,c) ————————— ————————— ————————— void abs(r) ———— ———— ———— void scale(n,m) —————— —————— void multiply(m) ———— ———— ———— void add(u,v) —————— —————— 99% of objects allocated at these two sites

  9. Intuition for Better Analysis void main(i,j) ——————— ——————— ——————— Locate important allocation sites Use demand-driven approach to analyze region surrounding site Somehow avoid sinking analysis resources into sites that can’t be optimized void compute(d,e) ———— ———— ———— void evaluate(i,j) —————— —————— —————— void multiplyAdd(a,b,c) ————————— ————————— ————————— void abs(r) ———— ———— ———— void scale(n,m) —————— —————— void multiply(m) ———— ———— ———— void add(u,v) —————— —————— 99% of objects allocated at these two sites

  10. What This Talk is About How we turned this intuition into an algorithm that usually • 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

  11. Structure of Talk • Motivating Example • Base whole program analysis (Whaley and Rinard, OOPSLA 99) • Incrementalized analysis • Analysis policy • Experimental results • Conclusion

  12. Motivating Example

  13. Employee Database Example • Read in database of employee records • Extract statistics like max salary

  14. Vector John Doe Ben Bit Jane Roe $45,000 $30,000 $55,000 Employee Database Example • Read in database of employee records • Extract statistics like max salary Name Salary

  15. Computing Max Salary • Traverse Records to Find Max Salary Vector Name John Doe Ben Bit Jane Roe Salary $45,000 $30,000 $55,000 max = $0

  16. Computing Max Salary • Traverse Records to Find Max Salary Vector Name John Doe Ben Bit Jane Roe Salary $45,000 $30,000 $55,000 max = $45,000 who = John Doe

  17. Computing Max Salary • Traverse Records to Find Max Salary Vector Name John Doe Ben Bit Jane Roe Salary $45,000 $30,000 $55,000 max = $45,000 who = John Doe

  18. Computing Max Salary • Traverse Records to Find Max Salary Vector Name John Doe Ben Bit Jane Roe Salary $45,000 $30,000 $55,000 max = $55,000 who = Jane Roe

  19. Computing Max Salary • Traverse Records to Find Max Salary Vector Name John Doe Ben Bit Jane Roe Salary $45,000 $30,000 $55,000 max salary = $55,000 highest paid = Jane Roe

  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; } } } }

  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; } } } }

  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

  23. Basic Idea Use pointer and escape analysis to recognize captured objects Transform program to allocate captured objects on stack

  24. Base Analysis

  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

  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 enum database highestPaid this e

  27. Edge Types • Inside Edges: • created in currently analyzed part of program • Outside Edges: • created outside currently analyzed part of program [ ] vector elementData enum database highestPaid dashed = outside this e solid = inside

  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 enum database highestPaid dashed = outside this e solid = inside

  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 enum database highestPaid green = escaped this e white = captured

  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) Can allocate enum object on stack [ ] vector elementData enum database highestPaid green = escaped this e white = captured

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

  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); } [ ] database elementData graph before call site e

  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); } [ ] database elementData graph before call site e [ ] elementData database this highestPaid Enum object is not present because it was captured in the callee

  34. Map formals to actuals void printStatistics(BufferedReader r) { EmployeeDatabase e = new EmployeeDatabase(r); e.computeMax(); System.out.println(“max salary = “ + e.highestPaid); } [ ] database elementData graph before call site e [ ] elementData database this highestPaid

  35. Match corresponding inside and outside edges to complete mapping void printStatistics(BufferedReader r) { EmployeeDatabase e = new EmployeeDatabase(r); e.computeMax(); System.out.println(“max salary = “ + e.highestPaid); } [ ] database elementData graph before call site e [ ] elementData database this highestPaid

  36. Match corresponding inside and outside edges to complete mapping void printStatistics(BufferedReader r) { EmployeeDatabase e = new EmployeeDatabase(r); e.computeMax(); System.out.println(“max salary = “ + e.highestPaid); } [ ] database elementData graph before call site e [ ] elementData database this highestPaid

  37. Match corresponding inside and outside edges to complete mapping void printStatistics(BufferedReader r) { EmployeeDatabase e = new EmployeeDatabase(r); e.computeMax(); System.out.println(“max salary = “ + e.highestPaid); } [ ] database elementData graph before call site e [ ] elementData database this highestPaid

  38. Match corresponding inside and outside edges to complete mapping void printStatistics(BufferedReader r) { EmployeeDatabase e = new EmployeeDatabase(r); e.computeMax(); System.out.println(“max salary = “ + e.highestPaid); } [ ] database elementData graph before call site e [ ] elementData database this highestPaid

  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); } [ ] database elementData graph before call site e [ ] elementData database this highestPaid [ ] graph after call site elementData e highestPaid

  40. Continue analysis after call site void printStatistics(BufferedReader r) { EmployeeDatabase e = new EmployeeDatabase(r); e.computeMax(); System.out.println(“max salary = “ + e.highestPaid); } [ ] database elementData graph before call site e [ ] graph after call site elementData e highestPaid

  41. Whole Program Analysis void printStatistics() ——————— ——————— ——————— void computeMax() ———— ———— ———— Enumeration elements() ——— ——— ——— boolean hasMoreElements() —————— —————— —————— Employee nextElement() —————— —————— int salary() —————— —————— Vector elementData() ———— ———— ————

  42. Whole Program Analysis void printStatistics() ——————— ——————— ——————— void computeMax() ———— ———— ———— Enumeration elements() ——— ——— ——— boolean hasMoreElements() —————— —————— —————— Employee nextElement() —————— —————— int salary() —————— —————— Vector elementData() ———— ———— ————

  43. Whole Program Analysis void printStatistics() ——————— ——————— ——————— void computeMax() ———— ———— ———— Enumeration elements() ——— ——— ——— boolean hasMoreElements() —————— —————— —————— Employee nextElement() —————— —————— int salary() —————— —————— Vector elementData() ———— ———— ————

  44. Whole Program Analysis void printStatistics() ——————— ——————— ——————— void computeMax() ———— ———— ———— Enumeration elements() ——— ——— ——— boolean hasMoreElements() —————— —————— —————— Employee nextElement() —————— —————— int salary() —————— —————— Vector elementData() ———— ———— ————

  45. Whole Program Analysis void printStatistics() ——————— ——————— ——————— void computeMax() ———— ———— ———— Enumeration elements() ——— ——— ——— boolean hasMoreElements() —————— —————— —————— Employee nextElement() —————— —————— int salary() —————— —————— Vector elementData() ———— ———— ————

  46. Whole Program Analysis void printStatistics() ——————— ——————— ——————— void computeMax() ———— ———— ———— Enumeration elements() ——— ——— ——— boolean hasMoreElements() —————— —————— —————— Employee nextElement() —————— —————— int salary() —————— —————— Vector elementData() ———— ———— ————

  47. Whole Program Analysis void printStatistics() ——————— ——————— ——————— void computeMax() ———— ———— ———— Enumeration elements() ——— ——— ——— boolean hasMoreElements() —————— —————— —————— Employee nextElement() —————— —————— int salary() —————— —————— Vector elementData() ———— ———— ————

  48. Whole Program Analysis void printStatistics() ——————— ——————— ——————— void computeMax() ———— ———— ———— Enumeration elements() ——— ——— ——— boolean hasMoreElements() —————— —————— —————— Employee nextElement() —————— —————— int salary() —————— —————— Vector elementData() ———— ———— ————

  49. Incrementalized Analysis

  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

More Related