In a copying garbage collector, when I copy the objects from the from-space to the to-space, certain objects could be referenced by a pointer stored in a register. When the garbage collection happens, that register needs to be updated to point to the to-space.
The problem is, the garbage collection is executed at specific points during the program (let's say when the user allocates memory) and thus, this will call a function to do the collection. That will, in turn, use registers which might be the ones we actually need to forward. So, that creates multiple problems:
- The register that we need to forward will not contain the address of the object to be forwarded.
- The register will be restored when returning from the garbage collection function, so we cannot forward it at this point anyway.
So how can I do the pointer forwarding for an object whose pointer is stored in a pointer? We can assume the garbage collector is written in C, not in assembly (which would make it easy to not overwrite the registers).