Content deleted Content added
→References: rm dead link (used to be java applet with visualization) |
|||
Line 1:
{{Use dmy dates|date=September 2021}}
{{more footnotes|date=April 2014}}
'''Cheney's algorithm''', first described in a 1970 [[Association for Computing Machinery|ACM]] paper by C.J. Cheney, is a [[stop and copy]] method of [[tracing garbage collection]] in computer software systems. In this scheme, the [[Memory management#Dynamic memory allocation|heap]] is divided into two equal halves, only one of which is in use at any one time. Garbage collection is performed by copying live objects from one semispace (the from-space) to the other (the to-space), which then becomes the new heap. The entire old heap is then discarded in one piece.
Cheney's algorithm reclaims items as follows:
* '''Object references on the stack.''' Object references on the stack are checked. One of the two following actions is taken for each object reference that points to an object in from-space:
** If the object has not yet been moved to the to-space, this is done by creating an identical copy in the to-space, and then replacing the from-space version with a forwarding pointer to the to-space copy.
** If the object has already been moved to the to-space, simply update the reference from the forwarding pointer in from-space.
* '''Objects in the to-space.''' The garbage collector examines all object references ''in the objects that have been migrated to the to-space'', and performs one of the above two actions on the referenced objects.
Line 44:
swap(fromspace, tospace)
allocPtr = tospace
scanPtr
-- scan every root you've got
Line 56:
r = copy(r)
EndForEach
scanPtr = scanPtr
EndWhile
</pre>
Line 69:
EndIf
return forwarding-address(o)
</pre>
Line 78 ⟶ 77:
== Equivalence to tri-color abstraction ==
Cheney's algorithm is an example of a [[
The algorithm moves any white objects (equivalent to objects in the from-space without forwarding pointers) to the gray set by copying them to the to-space. Objects that are between the scanning pointer and the free-space pointer on the to-space area are members of the gray set still to be scanned. Objects below the scanning pointer belong to the black set. Objects are moved to the black set by simply moving the scanning pointer over them.
Line 86 ⟶ 85:
== References ==
* {{cite journal
* {{cite journal
▲ | first2 = Jerome C.
▲ | s2cid = 36616954
▲ }}
* {{cite journal
{{Memory management}}
[[Category:Automatic memory management]]
|