Presentation is loading. Please wait.

Presentation is loading. Please wait.

Incremental Garbage Collection

Similar presentations


Presentation on theme: "Incremental Garbage Collection"— Presentation transcript:

1 Incremental Garbage Collection
Baker’s Incremental Copying Collector Nels Beckman

2 Background Two forms of memory:
From Space: Contains the ‘white’ colored objects. To Space: Contains the ‘black’ and ‘grey’ colored objects.

3 When it’s ‘time to garbage collect’
Move the objects referenced by the roots into the ‘to space’ These roots include registers, global variables, stack, and instruction pointer Root Root To Space From Space

4 When it’s ‘time to garbage collect’
Move the objects referenced by the roots into the ‘to space’ These roots include registers, global variables, stack, and instruction pointer Root Root To Space From Space (Forwarding pointers)

5 Until All Garbage is Collected
Mutator and Garbage Collector threads alternate

6 During a GC ‘Turn’ CG follows references from objects in to-space
Referred Objects are colored grey When every reference from a grey object is grey, color that object black. Root Root To Space From Space

7 During a GC ‘Turn’ CG follows references from objects in to-space
Referred Objects are colored grey When every reference from a grey object is grey, color that object black. Root Root To Space From Space

8 During a Mutator ‘Turn’
If mutator tries to get a reference to a ‘white’ object, that object is copied to the ‘from space.’ This way, the mutator never has a reference to a white object. Root Root To Space From Space

9 During a Mutator ‘Turn’
If mutator tries to get a reference to a ‘white’ object, that object is copied to the ‘from space.’ This way, the mutator never has a reference to a white object. Root Root To Space From Space

10 During a Mutator ‘Turn’
Also, if the mutator allocates an object, this new object goes in the to-space marked black. Root Root To Space From Space malloc()

11 Afterwards… When all objects in the to-space are ‘black’, ‘white’ objects can be reclaimed. Root Root To Space From Space

12 Summary Baker’s incremental copying algorithm can be used for real-time garbage collection, because GC and mutator threads are intertwined (This algorithm uses a read barrier). Caveats: If mutator tries to reference many white objects in a row, performance slows because of all the copying. Garbage Collection must finish before to-space is filled with newly allocated objects.


Download ppt "Incremental Garbage Collection"

Similar presentations


Ads by Google