|Version 3 (modified by igloo, 3 years ago)|
GHC uses copying GC by default, since while it requires more memory than mark/compact?, it is faster.
- The object is evacuated (copied) to its destination generation. The destination is given by bd->dest pointer in the bdescr of the block in which it lives; typically an object is promoted to the next highest generation, but the basic policy is affected by aging and eager promotion.
- The header word of the original object is replaced by a forwarding pointer. The forwarding pointer is just the pointer to the new copy, with the least significant bit set to 1 so that forwarding pointers can be distinguished from info table pointers.
- We scan objects that have been evacuated, and scavenge each one. Scavenging involves evacuating each of the pointers in the object, replacing each pointer with a pointer to the evacuated copy.
- When there are no more objects to be scavenged, the algorithm is complete. The memory containing the evacuated objects is retained, all the memory containing the old objects and forwarding pointers is discarded.
The principle APIs are
- void evacuate (StgClosure **p)
- which evacuates the object pointed to by the pointer at p, and updates p to point to the new location.
- void scavenge_block (bdescr *bd)
- which scavenges all the objects in the block bd (objects betwee bd->u.scan and bd->free are assumed to be unscavenged so far).