ConnectivityBased Garbage Collection Martin Hirzel University of Colorado
Connectivity-Based Garbage Collection Martin Hirzel University of Colorado at Boulder Collaborators: Amer Diwan, Michael Hind, Hal Gabow, Johannes Henkel, Matthew Hertz
Garbage Collection Benefits Garbage collection leads to simpler • Design no complex deallocation protocols • Implementation automatic deallocation • Maintenance fewer bugs Benefits are widely accepted • Java, C#, Python, … 2
Garbage Collection: Haven’t we solved this problem yet? • For a state-of-the-art garbage collector: – time ~14% of execution time – space 3 x high watermark – pauses 0. 8 seconds • Can reduce any one cost • Challenge: reduce all three costs 3
Example Heap s 1 o 2 o 3 s 2 Boxes: heap objects o 4 o 5 o 6 o 7 Arrows: pointers o 8 o 9 g o 10 o 13 o 15 o 11 o 14 o 12 Long box: stack + global variables 4
Thesis o 1 o 2 o 3 o 4 o 5 o 6 o 7 o 8 o 9 o 10 o 13 stack + globals o 15 o 11 o 14 1. Objects form distinct data structures 2. Connected objects die together 3. Garbage collectors can exploit 1. and 2. to reclaim objects efficiently o 12 5
Experimental Infrastructure Jikes. RVM Research Virtual Machine – From IBM Research – Written in Java – Application and runtime system share heap Good garbage collection even more important Benchmarks – SPECjvm 98 suite and SPECjbb 2000 – Java Olden suite – xalan, ipsixql, nfc, jigsaw 6
Outline • • Garbage Collector Design Principles Family of Garbage Collectors Design Space Exploration Pointer Analysis for Java 7
Garbage Collector Design Principles “Do partial collections. ” o 1 o 2 o 3 o 4 o 5 o 6 o 7 Don’t collect the full heap every time Shorter pause times o 8 o 9 o 10 o 13 stack + globals o 15 o 11 o 14 o 12 8
Garbage Collector Design Principles “Predict lifetime based on age. ” o 1 o 2 o 3 o 4 o 5 o 6 o 7 Generational hypothesis: Most objects die young Generational garbage collection: – Partition by age – Collect young objects most often o 8 o 9 o 10 o 13 stack + globals o 15 o 11 o 12 young generation o 14 Low time overhead That’s the state of the art. old generation 9
Garbage Collector Design Principles Generational GC Problems o 1 o 2 o 3 o 4 o 5 o 6 o 7 o 8 o 9 o 10 o 13 stack + globals o 15 o 11 Regular full collections Long peak pause Old-to-young pointers Need bookkeeping ~37. 5% long-lived objects Pig in the python o 14 o 12 young generation old generation 10
Garbage Collector Design Principles “Collect connected objects together. ” Likelihood that two objects die at the same time: Connectivity Example Any pair o 1 Weakly connected Likelihood o 2 33. 1% o 1 o 2 46. 3% Strongly connected o 1 o 2 72. 4% Direct pointer o 1 o 2 76. 4% ? 11
Garbage Collector Design Principles “Focus on objects with few ancestors. ” Median number of Lifetime ancestor objects Short 2 objects Long 83, 324 objects Shortlived objects are easy to collect 12
Garbage Collector Design Principles “Predict lifetime based on roots. ” o 1 s o 2 g o 3 Lifetime Objects reachable … Short Long indirectly from stack 25. 6% 16. 2% only directly from stack 32. 9% o 4 from globals 0. 8% 4. 0% 20. 5% Total 62. 5% 37. 5% stack + globals For details, see our [ISMM’ 02] paper. 13
Outline • • Garbage Collector Design Principles Family of Garbage Collectors Design Space Exploration Pointer Analysis for Java 14
CBGC Family of Garbage Collectors: Connectivity-Based Garbage Collection p 1 o 2 p 2 o 3 o 4 o 5 o 6 o 7 o 8 o 9 p 3 o 10 o 13 stack + globals o 15 o 11 o 12 o 14 p 4 • Do partial collections. • Collect connected objects together. • Predict lifetime based on age. • Focus on objects with few ancestors. • Predict lifetime based on roots. 15
Family of Garbage Collectors Components of CBGC Before allocation: 1. Partitioning Decide into which partition to put each object Collection algorithm: 2. Estimator Estimate dead + live objects for each partition 3. Chooser Choose “good” set of partitions 4. Partial collection Collect chosen partitions 16
Family of Garbage Collectors Partitioning Problem p 1 o 2 p 2 o 3 o 4 o 5 o 6 o 7 o 8 o 9 p 3 o 10 o 13 stack + globals o 15 o 11 o 12 Find fine-grained partitions, where • Partition edges respect pointers • Objects don’t move between partitions o 14 p 4 17
Family of Garbage Collectors Partitioning Solutions p 1 o 2 p 2 o 3 o 4 – o 1 may point to o 2 if o 1 has a field of a type compatible to o 2 o 5 o 6 o 7 o 8 o 9 p 3 o 10 o 13 stack + globals o 15 o 11 o 12 Pointer analysis • Type-based [Harris] o 14 p 4 • Constraint-based [Andersen] – We will discuss this later in the talk 18
Family of Garbage Collectors Estimator Problem p 1 1 dead + 2 live p 2 3 dead + 3 live p 3 2 dead + 2 live stack + globals For each partition guess dead – Objects that can be reclaimed – Pay-off live 2 dead + 0 live p 4 – Objects that must be traversed – Cost 19
Family of Garbage Collectors Estimator Solutions p 1 1 dead + 2 live p 2 3 dead + 3 live p 3 2 dead + 2 live stack + globals 2 dead + 0 live p 4 Heuristics • Connected objects die together • Most objects die young • Objects reachable from globals live long • The past predicts the future 20
Family of Garbage Collectors Chooser Problem p 1 1 dead + 2 live p 2 3 dead + 3 live p 3 7 dead + 5 live 2 dead + 2 live stack + globals 2 dead + 0 live Pick subset of partitions • Maximize total dead • Minimize total live • Closed under predecessor relation No bookkeeping for external pointers p 4 21
Family of Garbage Collectors Chooser Solutions p 1 1 dead + 2 live p 2 3 dead + 3 live p 3 7 dead + 5 live 2 dead + 2 live stack + globals Optimal algorithm based on network flow [TR] Simpler, greedy algorithm 2 dead + 0 live p 4 22
Family of Garbage Collectors Partial Collection Problem rest of heap o 2 p 2 o 55 o 6 o 7 o 88 o 9 p 3 o 10 10 o 13 stack + globals o 15 o 11 11 o 12 Look only at chosen partitions Traverse o reachable objects o Reclaim unreachable objects o 14 p 4 23
Family of Garbage Collectors Partial Collection Solutions rest of heap o 2 p 2 o 55 o 6 o 7 o 88 o 9 p 3 o 10 10 o 13 stack + globals o 15 o 11 11 o 12 o 14 p 4 Generalize canonical full -heap algorithms • Mark and sweep [Mc. Carthy’ 60] • Semi-space copying [Cheney’ 70] • Treadmill [Baker’ 92] 24
Outline • • Garbage Collector Design Principles Family of Garbage Collectors Design Space Exploration Pointer Analysis for Java 25
Design Space Exploration Questions How good is a naïve CBGC? How good could CBGC be in 20 years? How well does CBGC do in a JVM? 26
Design Space Exploration Simulator Methodology Garbage collection simulator (under GPL) – Uses traces of allocations and pointer writes from our benchmark runs Simulator advantages – Easier to implement variety of collector algorithms – Know entire trace beforehand: can use that for “in 20 years” experiments Simulator disadvantages – No bottom-line performance numbers Currently adding CBGC to Jikes. RVM 27
Design Space Exploration How good is a naïve CBGC? jack xalan jbb javac Cost in time 1. 72 0 0. 87 Cost in space 0 0. 22 Pause times Full-heap CBGC-naïve Semi-space copying • Type-based partitioning [Harris] • Heuristics estimator Appel 0 Copying generational 28
Design Space Exploration How good could CBGC be in 20 years? jack xalan jbb javac Cost in time 1. 72 0 0. 87 Cost in space 0 0. 22 Pause times Full-heap CBGC-oracles Appel Semi-space copying Partitioning and estimator based on trace Copying generational 0 29
Design Space Exploration How good could CBGC be in 20 years? CBGC with oracles beats Appel – We did not find a “performance wall” – CBGC has potential The performance gap between CBGC with oracles and naïve CBGC is large – Research challenges 30
How well does CBGC do in a Java virtual machine? Implementation in progress Need a pointer analysis for the partitioning 31
Outline • • Garbage Collector Design Principles Family of Garbage Collectors Design Space Exploration Pointer Analysis for Java 32
Pointer Analysis for Java Which analysis do we need? Cost in time jack xalan jbb javac jack xalan jbb javac 1. 7 0 Full-heap Semi-space copying CBGC Type-based partitioning [Harris] Type-based partitioning (oracles) Appel Allocation site partitioning (oracles) [Andersen] Copying generational 33
Pointer Analysis for Java Andersen’s Analysis • Allocation-site granularity • Set-inclusion constraints • Flow and context insensitive can’t analyze Java ahead of time! What When Constraint generation Model flow of pointers Ahead-of-time compilation Constraint propagation Find fixed-point solution Ahead-of-time compilation 34
Pointer Analysis for Java Andersen for all of Java Do as little as possible as late as possible What Constraint generation Model flow of pointers Constraint propagation Find next fixedpoint solution When • • • VM build and start-up Class loading Type resolution Method compilation (JIT) Execution of reflection Execution of native code Points-to information used (before garbage collection) 35
Pointer Analysis for Java Correctness Properties … Constraint propagation Constraint generation … time If there is a pointer then the results predict it Can not do any better for Java! 36
Pointer Analysis for Java Analysis Cost Constraint generation Constraint propagation Eager At GC At End Seconds Count Seconds compress 21. 4 130 3. 2 5 40. 4 1 67. 4 db 20. 1 143 3. 6 5 42. 9 1 71. 4 mtrt 20. 3 265 2. 1 5 46. 2 1 68. 1 mpegaudio 20. 6 319 2. 2 5 46. 1 1 66. 6 jack 21. 2 397 4. 2 7 49. 0 1 78. 2 jess 22. 3 733 6. 8 8 49. 7 1 85. 7 javac 21. 1 1, 107 5. 9 10 87. 4 1 187. 6 xalan 20. 1 1, 728 4. 9 8 85. 7 1 215. 7 Expensive, but once behavior stabilizes, costs diminish to zero 37
Pointer Analysis for Java Validation Lots of corner cases – Dynamic class loading – Reflection – Native code Missing any one leads to nasty bugs – CBGC relies on conservative results We performed validation runs – Check analysis results against pointers in heap during garbage collection 38
Wrapping Up 39
Related Work: Using Program Analysis for Garbage Collection Stack allocation [Park. Goldberg’ 92, …] Regions [Tofte. Talpin’ 97, …] Liveness analysis [Agesen. Detlefs. Moss’ 98, …] Early reclamation [Harris’ 99] Thread-local heaps [Steensgaard’ 00, …] Object inlining [Dolby. Chien’ 00] Write-barrier removal [Zee. Rinard’ 02, Shuf’ 02] … 40
Related Work: Pointer analyses for Java Andersen’s analysis for “static Java” [Rountev. Milanova. Ryder’ 01] [Liang. Pennings. Harrold’ 01] [Whaley. Lam’ 02] [Lhotak. Hendren’ 03] Weaker analyses with dynamic class loading DOIT – [Pechtchanski. Sarkar’ 01] XTA – [Qian. Hendren’ 04] Ruf’s escape analysis – [Bogda. Singh’ 01, King’ 03] Demand-driven / incremental analysis 41
Other Research Interests Accuracy of Garbage Collection [M. S. Thesis, ISMM’ 00, ECOOP’ 01, TOPLAS’ 02] Profiling [FDDO’ 01, Patent’ 01 a] Dynamic Optimizations, Prefetching [PLDI’ 02, Patent’ 02 b] Future directions: More techniques for performance improvement Reducing bugs, improving productivity 42
Contributions presented in this talk Connectivity-based GC design principles [ISMM’ 02] CBGC, a new family of garbage collectors; Design space exploration with simulator [OOPSLA’ 03] First non-trivial pointer analysis for Java [ECOOP’ 04 (to appear)] http: //www. cs. colorado. edu/~hirzel 43
- Slides: 43