UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi...
-
date post
22-Dec-2015 -
Category
Documents
-
view
232 -
download
1
Transcript of UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi...
![Page 1: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/1.jpg)
UniProcessor Garbage Collection Techniques
Paul R. Wilson
University of Texas
Presented By Naomi Sapir
Tel-Aviv University
![Page 2: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/2.jpg)
Overall Goal
• Introduction of garbage collectors for uniprocessors.
• Clarify basic issues in the field.
![Page 3: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/3.jpg)
Motivation
• Modular programming.
• Unreclaimed memory leads to slow memory leaks.
• Reclaiming too soon may cause unpredictable results.
• GC should be built into a language implementation.
![Page 4: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/4.jpg)
Two Phase Abstraction
• Distinguish live objects from garbage by terms of root set.
- reference counting
- mark sweep
- copying
• Reclaim Garbage storage.
![Page 5: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/5.jpg)
Root Set
• Global variables
• local variables in the activation stack.
• Registers
• Live object: Any object reached from the Root Set.
• What is Garbage ?
![Page 6: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/6.jpg)
Reference Counting
![Page 7: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/7.jpg)
![Page 8: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/8.jpg)
![Page 9: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/9.jpg)
Unreclaimable Cycle
![Page 10: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/10.jpg)
Cons
• Conservative approximation of true liveness.
• Efficiency cost proportional to the number of objects allocated in runtime.
- a real pointer points to another object
- short lived stack variables
• Fragmentation.
![Page 11: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/11.jpg)
Pros
• Used in distributed systems combined with other techniques.
![Page 12: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/12.jpg)
Mark-Sweep Collection
![Page 13: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/13.jpg)
RootPage
Object
Mark-swept
![Page 14: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/14.jpg)
Cons
• Fragmentation - difficult to allocate large objects.
• Locality of reference: interleave of different ages causes many page swaps.
• Cost: proportional to the heap size.
![Page 15: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/15.jpg)
Mark Compact CollectionCompact after mark
Pros
• Solves fragmentation.
• Saves locality.
Cons
• Cost: Several passes over the data:
Mark, compute new locations,
update pointers and move the objects.
![Page 16: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/16.jpg)
Copying Garbage Collection
![Page 17: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/17.jpg)
Before garbage collection
![Page 18: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/18.jpg)
After garbage collection
![Page 19: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/19.jpg)
Cheney breath-first copying
![Page 20: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/20.jpg)
Efficiency of Copying Collection
• Proportional to the live data during collection.
• Decrease of collection frequency, decreases collection effort.
• Need increased heap memory.
• Objects that die before GC needn’t be copied.
![Page 21: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/21.jpg)
Basic Techniques - Conclusions
• High performance systems use hybrid techniques.
• Copy collectors use a separate large objects area.
• In-place collectors (mark-sweep, treadmill) are conservative in respect to untyped objects, a copying collector must identify pointers.
![Page 22: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/22.jpg)
Problems with basic GC
• Not large memory, causes excessive paging.
• A copying collection might cause paging.
• Locality in cache memory is important.
• Time consuming, not usable for real time applications.
![Page 23: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/23.jpg)
Incremental Tracing Collectors
![Page 24: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/24.jpg)
Incremental Tracing Collectors
• Incremental tracing for garbage detection.
• The running program may mutate the graph of reachable objects.
• - keep track of changes.
• - floating garbage.
![Page 25: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/25.jpg)
Tricolor Marking
Before After a violation-D is not reachable
![Page 26: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/26.jpg)
Incremental Approaches• Coordinates the collector with the mutator.
• Read barrier
A mutator access a pointer to a white object, colors the object grey.
• Write barrier - a direct method
- Traps the write of a white pointer into a black object.
- Traps the death of a pointer before it is reached by GC.
![Page 27: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/27.jpg)
Baker’s Incremental Copying
• The best known real-time garbage collector.
• Free list(tospace), Live list (fromspace).
• Object: two pointers (next,prev) and a color (for the set).
• Fast allocation: copying in Cheney fashion.
• Read Barrier.
![Page 28: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/28.jpg)
Baker’s Incremental Copying (cont’)
• Tricolors:
- Black: Scanned area in tospace
- Grey: copied but not scanned.
- White: unreached objects in fromspace.
• Use scan-pointer on unscanned area of tospace, and move referred-to objects from fromspace.
![Page 29: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/29.jpg)
Baker’s Incremental Copying (cont’)
• Rule: Scanned objects in tospace(black) cannot point to objects in fromspace(white).
• If a mutator tries to access a pointer from the fromspace (white), the referent is copied into the tospace (grey) before the access.
• Allocation of new objects during GC is done in tospace, they are live - black.
![Page 30: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/30.jpg)
Baker’s Incremental Copying implementation
• Rate of copy is tied to the rate of runtime allocation.
• Read barrier: compiled in software or
implemented by hardware checks and/or microcode routines (Lisp Machines)
• Order of 20% time overheads.
![Page 31: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/31.jpg)
The Treadmill (Baker)
• Non-copying.
• Doubly linked lists.
![Page 32: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/32.jpg)
The Treadmill (cont’)During allocation
![Page 33: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/33.jpg)
The Treadmill Conservatism
• Allocated objects are marked live, but might die before the collection finishes.
• Pre-existing object marked live, might die after being reached.
• If the mutator destroys all the grey objects that point to a white object, although the white object will not be reachable by the collector, its memory will be reclaimed.
![Page 34: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/34.jpg)
Snapshot-at-Beginning Write-Barrier (Yuasa)
• Cheaper then read barrier, as heap writes are less common then heap reads.
• The graph of reachable objects is fixed from the beginning.
• All objects are accessed by the GC during collection (saves overwritten values).
• more conservative then Baker, all pointers retained, no free during GC.
![Page 35: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/35.jpg)
Tricolor Marking
Before D is reachable
![Page 36: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/36.jpg)
Incremental UpdateWrite-Barrier(Dijkstra)
• Heuristically retain live objects at the end of GC.
• Objects that die during GC and before reached by GC, may be reclaimed.
• Records a pointer that escapes into an already reached object (black white) (grey white)
![Page 37: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/37.jpg)
Incremental UpdateWrite-Barrier(Dijkstra) cont’
• New objects are allocated white: short lived objects will not be traversed early, but will be reclaimed quickly (advantage).
![Page 38: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/38.jpg)
Comparison of Incremental GCs
Write Barrier Read Barrierincremental update
snapshot Treadmill
Efficiency heap writes heap writes heap readsReclaim short lived objects (80% - 98%)
quickly(allocate white)
longer(allocate black)
longer(allocate black)
![Page 39: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/39.jpg)
Generational Garbage Collection(copying)
![Page 40: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/40.jpg)
Before GC
![Page 41: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/41.jpg)
After GC
![Page 42: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/42.jpg)
Generational Garbage Collection
Does not copy all live data at a collection.Does not copy old objects repeatedly.
• New objects are allocated in the New Gen.
• When full, New Gen only is scavenged, then old objects are copied to the Old Gen.
• Include a pointer Old Gen New Gen in the Root Set.
![Page 43: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/43.jpg)
Generational Garbage Collection Cont’
• Copy Collector: all pointers to moved objects are updated.
• Conservative true liveness, not all pointers Old Gen New Gen are live, they will float until the Old Gen will be scavenged.
![Page 44: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/44.jpg)
Generational Garbage Collection Cont’
• Newer generations are usually smaller then older, so scanning them is faster.
• Better locality.
• Record of intergenerational pointers is not tied to the rate of object creation, but still might slow the program.
![Page 45: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.](https://reader036.fdocuments.net/reader036/viewer/2022062407/56649d805503460f94a64dd0/html5/thumbnails/45.jpg)
Conclusions
• Generational techniques reduce cost as objects tend to die fast.
• Generational techniques with write barrier can support incremental update collection.
• We studied several kinds of GCs.
• Most important characteristics of GCs.
• Constant factors of cost (locality effects).
• Understanding current research.