baker_incrm_gc.ppt

Download Report

Transcript baker_incrm_gc.ppt

Incremental Garbage
Collection
Baker’s Incremental Copying
Collector
Nels Beckman
[email protected]
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’
• Move the objects referenced by the roots into
the ‘to space’
• These roots include registers, global variables,
stack, and instruction pointer
Root
From Space
Root
To Space
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)
Until All Garbage is Collected
• Mutator and Garbage Collector threads alternate
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
From Space
Root
To Space
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
From Space
Root
To Space
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
From Space
Root
To Space
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
From Space
Root
To Space
During a Mutator ‘Turn’
• Also, if the mutator allocates an object, this new
object goes in the to-space marked black.
Root
From Space
Root
To Space
malloc()
Afterwards…
• When all objects in the to-space are ‘black’,
‘white’ objects can be reclaimed.
Root
From Space
Root
To Space
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 tospace is filled with newly allocated objects.