1 / 57

Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina. International Symposium on Memory Management June, 2006. Motivation. Memory management challenges Effective reclamation of memory (precision) Transparent to users and applications

Download Presentation

Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

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. Compile-Time Deallocation of Individual ObjectsSigmund Cherem and Radu Rugina International Symposium on Memory Management June, 2006

  2. Motivation • Memory management challenges • Effective reclamation of memory (precision) • Transparent to users and applications • Eliminate memory errors (safety) • Minimize run-time overhead (efficiency) • Support real-time systems (predictability) • Automatic memory management • Eliminate user’s responsibilities on MM

  3. Overhead Precision Safety

  4. Overhead No MM Precision Safety

  5. Overhead Manual MM Precision Safety

  6. Overhead Dynamic MM Precision Safety

  7. Overhead Dynamic MM Compile-Time MM Precision Safety

  8. Overhead Dynamic MM Hybrid MM Compile-Time MM Precision Safety

  9. Compile-Time MM • General Idea • Estimate object lifetimes • Reachability: objects reachable from stack variables • Ref-counts: objects with some references into them • Liveness: objects being used • Transform programs to deallocate objects • Regions: deallocate entire group of heap objects • Stack allocation: place objects on stack frames • Free statements: deallocate individual objects • Our Approach • Reference count based reachability • Reclaim individual objects using “free” statements • Flexibility, simplicity and efficiency

  10. Running Example class L { D d; L n; } class D { int val; } L removeVal (L x, int v) { … L p = x, c = p.n; while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … c = p.n; } … return x; }

  11. Running Example … L p = x, c = p.n; while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … c = p.n; }

  12. Running Example … L p = x, c = p.n; while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … c = p.n; } p c n n n … … d d d

  13. Running Example … L p = x, c = p.n; while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … c = p.n; } n p c n n … … d d d

  14. Running Example … L p = x, c = p.n; while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … c = p.n; } n p c n … … d d d

  15. Running Example … L p = x, c = p.n; while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … c = p.n; } n p c n … … d d d

  16. Running Example … L p = x, c = p.n; while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … c = p.n; } n p c n … … d d d

  17. Running Example … L p = x, c = p.n; while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … c = p.n; } n p c n … … d d d

  18. Running Example … L p = x, c = p.n; while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … free(c); ? c = p.n; } n p c n … … d d d

  19. Running Example … L p = x, c = p.n; while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … free(c); ? c = p.n; } n p c n … … d d d p,c n n n … … d d d

  20. Running Example … L p = x, c = p.n; while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … if (p != c) free(c); c = p.n; } n p c n … … d d d p,c n n n … … d d d

  21. Running Example … L p = x, c = p.n; while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … if (p != c) free(c); c = p.n; } n p c n … … d d d

  22. Running Example … L p = x, c = p.n; while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … if (p != c){ free(c.d); free(c); } c = p.n; } n p c n … … d d d

  23. Jfree Compiler Reference Count Analysis Insert Free Statements Java Bytecode Java Bytecode + Free

  24. Reference Count Analysis Insert Free Statements Java Bytecode Java Bytecode + Free

  25. Reference Count Analysis • Determines when objects become unreachable • Compute ref-counts for each object at each program point • Track each object to determine its reference counts: Tracked Object Analysis • Precision: able to distinguish between object instances • Scalability at the inter-procedural level: large reuse of information on method summaries • Extends shape analysis with local reasoning [HR POPL’05] • Taking advantage of type safety in Java • Modeling Java programming practices or idioms

  26. Reference Count Analysis • Example concrete memory • Abstract representation • Use one unit (configuration) to represent individual objects • Use heap reference counts, hit expressions, and more information about the object • Each unit tracked independently x y n n n d d d d x

  27. Reference Count Analysis • Example concrete memory • Abstract representation • Use one unit (configuration) to represent individual objects • Use heap reference counts, hit expressions, and more information about the object • Each unit tracked independently x y n n n d d d d x y, n1

  28. Reference Count Analysis • Example concrete memory • Abstract representation • Use one unit (configuration) to represent individual objects • Use heap reference counts, hit expressions, and more information about the object • Each unit tracked independently x y n n n d d d d x y, n1 n1

  29. Reference Count Analysis • Example concrete memory • Abstract representation • Use one unit (configuration) to represent individual objects • Use heap reference counts, hit expressions, and more information about the object • Each unit tracked independently x y n n n d d d d x y, n1 n1

  30. Reference Count Analysis • Example concrete memory • Abstract representation • Use one unit (configuration) to represent individual objects • Use heap reference counts, hit expressions, and more information about the object • Each unit tracked independently x y n n n d d d d x y, n1 n1 d1

  31. Reference Count Analysis • Example concrete memory • Abstract representation • Use one unit (configuration) to represent individual objects • Use heap reference counts, hit expressions, and more information about the object • Each unit tracked independently x y n n n d d d d x y, n1 n1 d1

  32. Reference Count Analysis • Example concrete memory • Abstract representation • Use one unit (configuration) to represent individual objects • Use heap reference counts, hit expressions, and more information about the object • Each unit tracked independently x y n n n d d d d x y, n1 (x.n) n1 d1

  33. Running Example … while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … c = p.n; c, n1 (p.n) p c … …

  34. Running Example … while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … c = p.n; c, n1 (p.n) c p c … …

  35. Running Example … while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … c = p.n; c, n1 (p.n) c c p c … …

  36. Running Example … while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … c = p.n; c, n1 (p.n) c c c p c … …

  37. Running Example … while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … c = p.n; c, n1 (p.n) c c c p c … …

  38. Running Example … while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … /* free(c); */ c = p.n; c, n1 (p.n) c c c p c … …

  39. Other Analysis Details (I) Abstraction Elements • More than reference counts and hit expressions • Miss expressions: expressions that don’t reference the object • Expression equivalences: alias information about neighbors of tracked object Intra-procedural Analysis • Dataflow analysis that starts at allocation sites • Updates configurations on assignments • Merges some configurations at merge points

  40. Other Analysis Details (II) Inter-procedural Analysis • Split configuration in halves • Filter non-accessed information • No need to analyze a portion not used by the callee • Skip call if accessed portion is empty • Add extended parameters • Helps preserving precise information about equivalences • Analyze callee • Record and use method summaries • Summaries are independent of caller information • Combine • Recover and merge non-accessed information

  41. Reference Count Analysis Insert Free Statements Java Bytecode Java Bytecode + Free

  42. Transformation • Goal : automatically insert free statements to reclaim dead objects • Technique • At points where tracked object becomes unreachable • Extract expression from responsible statement e = g;  free(e); • Determine conditions for deallocation (discriminants) • Look for hit expressions in other configurations • Find a set of expressions that distinguishes them

  43. Running Example … L p = x, c = p.n; while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … c = p.n; } c, n1 (p.n) c c, p, n1

  44. Running Example … L p = x, c = p.n; while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … if ( ??? ) { free(c); } c = p.n; } c, n1 (p.n) c c, p, n1

  45. Running Example … L p = x, c = p.n; while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … if (p != c) { free(c); } c = p.n; } c, n1 (p.n) c c, p, n1

  46. Reference Count Analysis Insert Free Statements Java Bytecode Java Bytecode + Free

  47. Reiteration • Model a cascade effect of deallocations • Deallocate multiple level structures • Model the semantics of deallocation statements • Temporarily add nullifications into code free(x)  x.f = null; • No need to reanalyze whole program • Cleanup and recompute affected part • Limited to finite number of iterations • Can’t deallocate recursive structures

  48. Running Example … L p = x, c = p.n; while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … if (p != c) { c.d = null; free(c); } c = p.n; }

  49. Running Example … L p = x, c = p.n; while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … if (p != c) { free(c.d); free(c); } c = p.n; }

  50. Analysis Enhancements • Variable Equality Analysis • Infer additional equivalences that exist prior to analysis starting point • Variable Liveness Analysis • Increases precision by reducing object lifetimes • Allows to deallocate objects earlier • Variable Uniqueness Analysis • No need for conditional deallocation: decide deallocation in isolation • Escape/effect analysis • Accelerate inter-procedural analysis by improving filtering of information and skipping of calls

More Related