Basics of Garbage Collection Merlin Laue Universitt zu Lbeck 9. - - PowerPoint PPT Presentation

basics of garbage collection
SMART_READER_LITE
LIVE PREVIEW

Basics of Garbage Collection Merlin Laue Universitt zu Lbeck 9. - - PowerPoint PPT Presentation

Motivation Problems Algorithms Exact vs. Conservative Conclusion Basics of Garbage Collection Merlin Laue Universitt zu Lbeck 9. November 2015 Merlin Laue (Uni Lbeck) Basics of Garbage Collection 9. November 2015 1 Motivation


slide-1
SLIDE 1

Motivation Problems Algorithms Exact vs. Conservative Conclusion

Basics of Garbage Collection

Merlin Laue

Universität zu Lübeck

  • 9. November 2015

Merlin Laue (Uni Lübeck) Basics of Garbage Collection

  • 9. November 2015

1

slide-2
SLIDE 2

Motivation Problems Algorithms Exact vs. Conservative Conclusion

Table of Contents

1

Motivation

2

Problems

3

Algorithms

4

Exact vs. Conservative

5

Conclusion

Merlin Laue (Uni Lübeck) Basics of Garbage Collection

  • 9. November 2015

2

slide-3
SLIDE 3

Motivation Problems Algorithms Exact vs. Conservative Conclusion

Motivation

Managing memory manually is time consuming Very precise work required to prevent memory leaks Solution → Automatic memory management

Merlin Laue (Uni Lübeck) Basics of Garbage Collection

  • 9. November 2015

3

slide-4
SLIDE 4

Motivation Problems Algorithms Exact vs. Conservative Conclusion

Basic Terms

Definition (Mutator)

A mutator is part of a running program which executes application

  • code. Its name is based on the fact that from the collector’s point of

view it mutates the graph of objects.

Definition (Free-list)

A free-list works by linking unallocated regions of memory together in a linked list. Newly freed memory is added to the list.

Merlin Laue (Uni Lübeck) Basics of Garbage Collection

  • 9. November 2015

4

slide-5
SLIDE 5

Motivation Problems Algorithms Exact vs. Conservative Conclusion

Timings

Merlin Laue (Uni Lübeck) Basics of Garbage Collection

  • 9. November 2015

5

slide-6
SLIDE 6

Motivation Problems Algorithms Exact vs. Conservative Conclusion

Problems

1 Memory Usage 2 Fragmentation 3 Determinism 4 Time Effiency Merlin Laue (Uni Lübeck) Basics of Garbage Collection

  • 9. November 2015

6

slide-7
SLIDE 7

Motivation Problems Algorithms Exact vs. Conservative Conclusion

Memory Usage

Free-lists or tables Overhead consisting of state, location, or size of an object Copy spaces and Barriers Finalization Cyclic data structures

Merlin Laue (Uni Lübeck) Basics of Garbage Collection

  • 9. November 2015

7

slide-8
SLIDE 8

Motivation Problems Algorithms Exact vs. Conservative Conclusion

Fragmentation

Method of collection is a big influence Performance can drop drasticially. Countering fragmentation is expensive if it is not inherently implemented

Merlin Laue (Uni Lübeck) Basics of Garbage Collection

  • 9. November 2015

8

slide-9
SLIDE 9

Motivation Problems Algorithms Exact vs. Conservative Conclusion

Determinism

Finalization most important influence Destructor → Immediate freeing Finalization → Unforseeable Occupation of shared resources can be problematic

Merlin Laue (Uni Lübeck) Basics of Garbage Collection

  • 9. November 2015

9

slide-10
SLIDE 10

Motivation Problems Algorithms Exact vs. Conservative Conclusion

Time Efficiency

Garbage collection show close affinity to the amount of allocated memory Number of collection cycles < Mutator Locality with contiguous allocation

Merlin Laue (Uni Lübeck) Basics of Garbage Collection

  • 9. November 2015

10

slide-11
SLIDE 11

Motivation Problems Algorithms Exact vs. Conservative Conclusion

Algorithms

1 Semi Space 2 Reference Counting 3 Mark and Sweep 4 Mark and Compact 5 Generational Merlin Laue (Uni Lübeck) Basics of Garbage Collection

  • 9. November 2015

11

slide-12
SLIDE 12

Motivation Problems Algorithms Exact vs. Conservative Conclusion

Semi Space

Requires 2 spaces : To-Space and From-Space Collection time is proportional to the number of survivors inhabiting the full copy space Collects the entire heap everytime ’Stop the World’ - collector

Merlin Laue (Uni Lübeck) Basics of Garbage Collection

  • 9. November 2015

12

slide-13
SLIDE 13

Motivation Problems Algorithms Exact vs. Conservative Conclusion 1 Swaps both spaces 2 Traces all root referents and copies uncopied objects to the

complementary half

3 Leaves forwarding pointers in the old object 4 Adjusts references to point towards the new adress. Merlin Laue (Uni Lübeck) Basics of Garbage Collection

  • 9. November 2015

13

slide-14
SLIDE 14

Motivation Problems Algorithms Exact vs. Conservative Conclusion

Reference Counting

Uses free-lists to note the amount of references pointing towards any given object Requires write barriers to count The burden on the mutator is significantly increased Cyclic data structures are a big problem ’Stop the World’ - collector

Merlin Laue (Uni Lübeck) Basics of Garbage Collection

  • 9. November 2015

14

slide-15
SLIDE 15

Motivation Problems Algorithms Exact vs. Conservative Conclusion 1 Upon first allocation an entry in the free-list is created 2 The write barrier records increases and decreases of references 3 Afterwards the amount of references is only buffered in the

free-list

4 If the references of an object reach 0 then a bit in the free-list is

set mand all all references are recursivly decreased

Merlin Laue (Uni Lübeck) Basics of Garbage Collection

  • 9. November 2015

15

slide-16
SLIDE 16

Motivation Problems Algorithms Exact vs. Conservative Conclusion

Mark and Sweep

Uses a free-list with a tracing collection Uses a bitmap to mark objects 2 Phases of collection : Marking and Sweeping, hence its name Handles cycles due to whole heap scanning Severe fragmentation ’Stop the World’ - collector

Merlin Laue (Uni Lübeck) Basics of Garbage Collection

  • 9. November 2015

16

slide-17
SLIDE 17

Motivation Problems Algorithms Exact vs. Conservative Conclusion 1 Stopping of the program and mutator activity 2 Marking of alive objects 3 Sweeping : Scanning the heap for unmarked objects and freeing

these parts

4 Resuming mutator activity when reaching the end of the heap Merlin Laue (Uni Lübeck) Basics of Garbage Collection

  • 9. November 2015

17

slide-18
SLIDE 18

Motivation Problems Algorithms Exact vs. Conservative Conclusion

Mark and Compact

Essentially a Mark and Sweep algorithm Better allocation times due to compact memory Memory efficient if only the objects are observed Overhead for forwarding pointers extremely big 3 runs for each compacing phase

Merlin Laue (Uni Lübeck) Basics of Garbage Collection

  • 9. November 2015

18

slide-19
SLIDE 19

Motivation Problems Algorithms Exact vs. Conservative Conclusion 1 Marking of alive objects 2 Compute forwarding adresses 3 Update pointers for the referents 4 Relocation of objects Merlin Laue (Uni Lübeck) Basics of Garbage Collection

  • 9. November 2015

19

slide-20
SLIDE 20

Motivation Problems Algorithms Exact vs. Conservative Conclusion

A new View : Generational

Theorem (Weak generational Hypothesis)

Newly created objects tend to die very young while old objects persist much longer. Partition the memory in 3 generations:

1

Young (Nursery)

2

mature

3

Permanent

Promote objects who survive collection to an older generation Use the different algorithms to collect each generation (Generational collectors are hybrids)

Merlin Laue (Uni Lübeck) Basics of Garbage Collection

  • 9. November 2015

20

slide-21
SLIDE 21

Motivation Problems Algorithms Exact vs. Conservative Conclusion

Different size policies for the young generation:

1

Flexible - Expands and retracts with collection and allocation

2

Fixed - Fixed size which will never expand or retract

3

Bound - Uses upper and lower boundry

Merlin Laue (Uni Lübeck) Basics of Garbage Collection

  • 9. November 2015

21

slide-22
SLIDE 22

Motivation Problems Algorithms Exact vs. Conservative Conclusion Merlin Laue (Uni Lübeck) Basics of Garbage Collection

  • 9. November 2015

22

slide-23
SLIDE 23

Motivation Problems Algorithms Exact vs. Conservative Conclusion

Worlds collide - Exact vs. Conservative

Definition (Exact)

Exact algorithms are assisted by the compiler and language runtime. In case of strongly typed languages such as C, a shadowstack has to be used for exact collection making them uncooperative exact.

Definition (Conservative)

A conservative collection algorithm ’guesses’ the references. It scans the memory (most notably the execution stack) for words looking like a reference and then makes the conservative assumption that it is a valid reference. These references are called ambigiuous references.

Merlin Laue (Uni Lübeck) Basics of Garbage Collection

  • 9. November 2015

23

slide-24
SLIDE 24

Motivation Problems Algorithms Exact vs. Conservative Conclusion

Leads to 3 major restrictions and drawbacks:

1

Pinning

2

Filtering

3

Excess retention

Pinning incurs fragmentation Filtering adds additional workload Excess retention is space overhead Immix collectors are a recent way to show heavily optimized conservative algorithms

Merlin Laue (Uni Lübeck) Basics of Garbage Collection

  • 9. November 2015

24

slide-25
SLIDE 25

Motivation Problems Algorithms Exact vs. Conservative Conclusion

Conclusion

Locality of the mutator is more important then the number of collections Compiler and language runtime limit the choice of garbage collectors Garbage collection does not necessarily need support. The Performance of garbage collection will steadily increase in the future.

Merlin Laue (Uni Lübeck) Basics of Garbage Collection

  • 9. November 2015

25

slide-26
SLIDE 26

Motivation Problems Algorithms Exact vs. Conservative Conclusion

Thank you for your attention

Feel free to ask questions

Merlin Laue (Uni Lübeck) Basics of Garbage Collection

  • 9. November 2015

26