Download presentation
Presentation is loading. Please wait.
1
Compile-Time Deallocation of Individual Objects Sigmund 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
SafetyPrecision Overhead
4
SafetyPrecision Overhead No MM
5
SafetyPrecision Overhead Manual MM
6
SafetyPrecision Overhead Dynamic MM
7
SafetyPrecision Overhead Dynamic MM Compile-Time MM
8
SafetyPrecision Overhead Hybrid MM Dynamic MM Compile-Time MM
9
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 pc nnn ddd …… … 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; }
13
Running Example pc n n n ddd …… … 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; }
14
Running Example pc n n ddd …… … 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; }
15
… 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; } Running Example pc n n ddd ……
16
… 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; } Running Example p n n ddd …… c
17
… 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; } Running Example pc n n ddd ……
18
p n n ddd …… c … 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; }
19
Running Example p n n ddd …… c p,c nnn ddd …… … 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; }
20
Running Example p n n ddd …… c p,c nnn ddd …… … 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; }
21
Running Example p n n ddd …… c … 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; }
22
Running Example p n n ddd …… c … 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; }
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
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 Reference Count Analysis x nn dddd n x y
27
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 Reference Count Analysis x nn dddd n x y y, n 1
28
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 Reference Count Analysis x nn dddd n xn1n1 y y, n 1
29
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 Reference Count Analysis x nn dddd n xn1n1 y y, n 1
30
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 Reference Count Analysis x nn dddd n xn1n1 d1d1 y y, n 1
31
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 Reference Count Analysis x nn dddd n xn1n1 d1d1 y y, n 1
32
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 Reference Count Analysis x nn dddd n xn1n1 d1d1 y y, n 1 (x.n)
33
Running Example pc …… … while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … c = p.n; c, n 1 (p.n)
34
Running Example … while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … c = p.n; pc …… c c, n 1 (p.n)
35
Running Example … while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … c = p.n; pc …… c c c, n 1 (p.n)
36
… while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … c = p.n; Running Example pc …… c c c c, n 1 (p.n)
37
… while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … c = p.n; Running Example p c …… c c c c, n 1 (p.n)
38
… while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … /* free(c); */ c = p.n; Running Example c p c …… c c c, n 1 (p.n)
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, n 1 (p.n) cc, p, n 1
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, n 1 (p.n) cc, p, n 1
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, n 1 (p.n) cc, p, n 1
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
51
Experimental Evaluation
52
Settings and Analysis Times Jfree Compiler System Soot infrastructure 2.2.2 SPECjvm98 Benchmarks Parameters for tuning speed and precision E.g. time cut-off to limit analysis time Compile-time statistics Average application size: 547 methods Average analysis time:1 ’ 37 ’’ (default parameters) Libraries code is analyzed, but not transformed JfreeVM Runtime System JikesRVM 2.3.5, MMTk
53
Memory Freed % of total allocated memory Default parameters
54
Memory Freed % of total allocated memory Best parameters
55
Integration with GC 1 2 3 4 5 1.25 1.5 123451.161.331.66 Normalized Memory Size Normalized Application Time MS Free + MS
56
Related Work Stack Allocation Blanchet OOPLSA ’ 99, Choi et al. OOPSLA ’ 99, Whaley and Rinard OOPSLA ’ 99, Bogda and Hoelzle OOPSLA ’ 99, Gay/Steensgard CC ’ 00 Regions Tofte and Talpin POPL ’ 94, AFL PLDI ’ 95, Cherem and Rugina ISMM ’ 04, Chin et al. PLDI ’ 04 Individual Object Deallocation Three-valued logic: Shaham et al. SAS ’ 03 Pointer analysis: Guyer et al. PLDI ’ 06 Shape Analysis Sagiv et al. POPL ’ 99, Hackett and Rugina POPL ’ 05
57
Conclusions Reference Count Analysis in Java Extensions to Shape Analysis w/Local Reasoning Inserting free statements Conditional deallocation Reclaiming structures Compiler results 50% of memory can be reclaimed statically Integration with GC 31% faster for small heaps
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.