Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University."— 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. Introduction of garbage collectors for uniprocessors. Clarify basic issues in the field. Clarify basic issues in the field.

3 Motivation Modular programming. Modular programming. Unreclaimed memory leads to slow memory leaks. Unreclaimed memory leads to slow memory leaks. Reclaiming too soon may cause unpredictable results. Reclaiming too soon may cause unpredictable results. GC should be built into a language implementation. GC should be built into a language implementation.

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

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

6 Reference Counting

7

8

9 Unreclaimable Cycle

10 Cons Conservative approximation of true liveness. Conservative approximation of true liveness. Efficiency cost proportional to the number of objects allocated in runtime. Efficiency cost proportional to the number of objects allocated in runtime. - a real pointer points to another object - short lived stack variables Fragmentation. Fragmentation.

11 Pros Used in distributed systems combined with other techniques. Used in distributed systems combined with other techniques.

12 Mark-Sweep Collection

13 Root Page Object Mark-swept

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

15 Mark Compact Collection Compact after mark Pros Solves fragmentation. Solves fragmentation. Saves locality. Saves locality.Cons Cost: Several passes over the data: Cost: Several passes over the data: Mark, compute new locations, update pointers and move the objects.

16 Copying Garbage Collection

17 Before garbage collection

18 After garbage collection

19 Cheney breath-first copying

20 Efficiency of Copying Collection Proportional to the live data during collection. Proportional to the live data during collection. Decrease of collection frequency, decreases collection effort. Decrease of collection frequency, decreases collection effort. Need increased heap memory. Need increased heap memory. Objects that die before GC needn’t be copied. Objects that die before GC needn’t be copied.

21 Basic Techniques - Conclusions High performance systems use hybrid techniques. High performance systems use hybrid techniques. Copy collectors use a separate large objects area. 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. In-place collectors (mark-sweep, treadmill) are conservative in respect to untyped objects, a copying collector must identify pointers.

22 Problems with basic GC Not large memory, causes excessive paging. Not large memory, causes excessive paging. A copying collection might cause paging. A copying collection might cause paging. Locality in cache memory is important. Locality in cache memory is important. Time consuming, not usable for real time applications. Time consuming, not usable for real time applications.

23 Incremental Tracing Collectors

24 Incremental tracing for garbage detection. Incremental tracing for garbage detection. The running program may mutate the graph of reachable objects. The running program may mutate the graph of reachable objects. - keep track of changes. - keep track of changes. - floating garbage. - floating garbage.

25 Tricolor Marking Before After a violation D is not reachable

26 Incremental Approaches Coordinates the collector with the mutator. Coordinates the collector with the mutator. Read barrier Read barrier A mutator access a pointer to a white object, colors the object grey. Write barrier - a direct method 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.

27 Baker’s Incremental Copying The best known real-time garbage collector. The best known real-time garbage collector. Free list(tospace), Live list (fromspace). Free list(tospace), Live list (fromspace). Object: two pointers (next,prev) and a color (for the set). Object: two pointers (next,prev) and a color (for the set). Fast allocation: copying in Cheney fashion. Fast allocation: copying in Cheney fashion. Read Barrier. Read Barrier.

28 Baker’s Incremental Copying (cont’) Tricolors: 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.

29 Baker’s Incremental Copying (cont’) Rule: Scanned objects in tospace(black) cannot point to objects in fromspace(white). 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. 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. Allocation of new objects during GC is done in tospace, they are live - black.

30 Baker’s Incremental Copying implementation Rate of copy is tied to the rate of runtime allocation. Rate of copy is tied to the rate of runtime allocation. Read barrier: compiled in software or Read barrier: compiled in software or implemented by hardware checks and/or microcode routines (Lisp Machines) Order of 20% time overheads. Order of 20% time overheads.

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

32 The Treadmill (cont’) During allocation

33 The Treadmill Conservatism Allocated objects are marked live, but might die before the collection finishes. Allocated objects are marked live, but might die before the collection finishes. Pre-existing object marked live, might die after being reached. 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.

34 Snapshot-at-Beginning Write-Barrier (Yuasa) Cheaper then read barrier, as heap writes are less common then heap reads. Cheaper then read barrier, as heap writes are less common then heap reads. The graph of reachable objects is fixed from the beginning. The graph of reachable objects is fixed from the beginning. All objects are accessed by the GC during collection (saves overwritten values). All objects are accessed by the GC during collection (saves overwritten values). more conservative then Baker,all pointers retained, no free during GC. more conservative then Baker,all pointers retained, no free during GC.

35 Tricolor Marking Before D is reachable

36 Incremental Update Write-Barrier(Dijkstra) Heuristically retain live objects at the end of GC. Heuristically retain live objects at the end of GC. Objects that die during GC and before reached by GC, may be reclaimed. 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) Records a pointer that escapes into an already reached object (black  white)  (grey  white)

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

38 Comparison of Incremental GCs

39 Generational Garbage Collection (copying)

40 Before GC

41 After GC

42 Generational Garbage Collection New objects are allocated in the New Gen. New objects are allocated in the New Gen. When full, New Gen only is scavenged, then old objects are copied to the Old 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. Include a pointer Old Gen  New Gen in the Root Set. Does not copy all live data at a collection. Does not copy old objects repeatedly.

43 Generational Garbage Collection Cont’ Copy Collector: all pointers to moved objects are updated. 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. Conservative true liveness, not all pointers Old Gen  New Gen are live, they will float until the Old Gen will be scavenged.

44 Generational Garbage Collection Cont’ Newer generations are usually smaller then older, so scanning them is faster. Newer generations are usually smaller then older, so scanning them is faster. Better locality. Better locality. Record of intergenerational pointers is not tied to the rate of object creation, but still might slow the program. Record of intergenerational pointers is not tied to the rate of object creation, but still might slow the program.

45 Conclusions Generational techniques reduce cost as objects tend to die fast. Generational techniques reduce cost as objects tend to die fast. Generational techniques with write barrier can support incremental update collection. Generational techniques with write barrier can support incremental update collection. We studied several kinds of GCs. We studied several kinds of GCs. Most important characteristics of GCs. Most important characteristics of GCs. Constant factors of cost (locality effects). Constant factors of cost (locality effects). Understanding current research. Understanding current research.


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

Similar presentations


Ads by Google