uniprocessor garbage collection techniques paul r. wilson university of texas presented by naomi...

45
UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University

Post on 22-Dec-2015

227 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University

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

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

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

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

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

Reference Counting

Page 7: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University
Page 8: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University
Page 9: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University

Unreclaimable Cycle

Page 10: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University

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

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

Mark-Sweep Collection

Page 13: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University

RootPage

Object

Mark-swept

Page 14: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University

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

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

Copying Garbage Collection

Page 17: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University

Before garbage collection

Page 18: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University

After garbage collection

Page 19: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University

Cheney breath-first copying

Page 20: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University

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

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

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

Incremental Tracing Collectors

Page 24: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University

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

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

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

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

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

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

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

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

The Treadmill (cont’)During allocation

Page 33: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University

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

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

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

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

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

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

Generational Garbage Collection(copying)

Page 40: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University

Before GC

Page 41: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University

After GC

Page 42: UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University

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

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

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

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.