1 / 45

UniProcessor Garbage Collection Techniques

This presentation by Paul R. Wilson from the University of Texas explores various garbage collection techniques for UniProcessors, including reference counting, mark-sweep, copying, and incremental tracing collectors. It also discusses the challenges and advantages of each technique.

sjavier
Download Presentation

UniProcessor Garbage Collection Techniques

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. UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University

  2. Overall Goal • Introduction of garbage collectors for uniprocessors. • Clarify basic issues in the field.

  3. 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.

  4. Two Phase Abstraction • Distinguish live objects from garbage by terms of root set. - reference counting - mark sweep - copying • Reclaim Garbage storage.

  5. Root Set • Global variables • local variables in the activation stack. • Registers • Live object: Any object reached from the Root Set. • What is Garbage ?

  6. Reference Counting

  7. Unreclaimable Cycle

  8. 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.

  9. Pros • Used in distributed systems combined with other techniques.

  10. Mark-Sweep Collection

  11. Page Root Object Mark-swept

  12. Cons • Fragmentation - difficult to allocate large objects. • Locality of reference: interleave of different ages causes many page swaps. • Cost: proportional to the heap size.

  13. 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.

  14. Copying Garbage Collection

  15. Before garbage collection

  16. After garbage collection

  17. Cheney breath-first copying

  18. 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.

  19. 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.

  20. 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.

  21. Incremental Tracing Collectors

  22. Incremental Tracing Collectors • Incremental tracing for garbage detection. • The running program may mutate the graph of reachable objects. • - keep trackof changes. • - floating garbage.

  23. Tricolor Marking Before After a violation-D is not reachable

  24. 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.

  25. 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.

  26. 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.

  27. 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.

  28. 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.

  29. The Treadmill (Baker) • Non-copying. • Doubly linked lists.

  30. The Treadmill (cont’) During allocation

  31. 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.

  32. 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.

  33. Tricolor Marking D is reachable Before

  34. 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)

  35. Incremental UpdateWrite-Barrier(Dijkstra) cont’ • New objects are allocated white: short lived objects will not be traversed early, but will be reclaimed quickly (advantage).

  36. Comparison of Incremental GCs

  37. Generational Garbage Collection(copying)

  38. Before GC

  39. After GC

  40. 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.

  41. 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.

  42. 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.

  43. 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.

More Related