free = starting location of new heap;
for (each object o in heap) {
if (o is not freed) {
NewLocation(o) = free;
free = free + size(o);
}
}
for (each object o in heap) {
if (o is not freed) {
for (each reference o.r in o) {
o.r = NewLocation(o.r);
}
copy o to NewLocation(r);
}
}
// add this to the above implementation
for (each reference r in the root set) {
r = NewLocation(r);
}
delete NewLocation map.
mark and sweep gc
mark and compact
Because the GC runs infrequently, a bump allocator can be used for allocation, which is extremely fast.
Compact
Free = starting location of the new heap
for (each object o in the old heap) {
if (o is reached) {
NewLocation(o) = free;
free = free + sizeof(o);
}
}
// updating the references
for (each object o in the old heap) {
if (o is reached) {
set the reached-bit of o to 0
for (each reference o.r in o) {
o.r = NewLocation(o.r);
}
copy o to NewLocation(o);
}
}
// updating the local or global references
for (each reference r in the root set) {
r = NewLocation(r);
}
copying collector
Concurrent garbage collection
barriers
write_barrier(&head2->next, tmp2);