Hacker News new | ask | show | jobs
by kazinator 2339 days ago
In this case it won't help, because:

0. We are already in a frame that doesn't take any arguments of the "val" object type; how come that's not good enough?

1. The current stack frame is entered with a bunch of callee-saved registers, some of which contain GC roots.

2. The current stack frame's code saves some of them: those ones that it clobbers locally. It leaves others in their original registers.

3. Thus, if a another stack frame is called, there are still some callee-saved registers, probably containing GC roots, and some of these will go into the area below the locals.

4. You might think that if the save all the necessary registers ourselves into the stack and then make another stack frame, we would be okay. But in fact, no. Because by the time we save registers, the compiler generated function entry has already executed and saved some of those registers into the below-locals save area and clobbered them for its own use! So our snapshot possibly misses GC roots. The compiler generated code always has "first dibs" at the incoming registers, to push them into the below-locals save area, thus kicking the GC roots farther up the stack.