1 / 12

Incremental Garbage Collection

Incremental Garbage Collection. Baker’s Incremental Copying Collector. Nels Beckman nbeckman@scs.cmu.edu. Background. Two forms of memory: From Space: Contains the ‘white’ colored objects. To Space: Contains the ‘black’ and ‘grey’ colored objects. When it’s ‘time to garbage collect’.

geraldine
Download Presentation

Incremental Garbage Collection

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. Incremental Garbage Collection Baker’s Incremental Copying Collector Nels Beckman nbeckman@scs.cmu.edu

  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 (Forwardingpointers)

  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.

More Related