When the get_params instruction runs, the arguments are pulled from
the context pointed to by the caller_ctx member of the running context.
After a tailcall, the caller_ctx can be the only pointer left to the
caller's context.  This member is not traced by mark_context, so a GC
before get_params has finished can reclaim arguments prematurely.  The
obvious fix to mark_context (marking the caller_ctx) does indeed solve
the original problem, but introduces a host of other problems in "make
test" that seem to be GC-related, such as segfaults and nontermination.

   To my surprise, I discovered that the ref_count of the caller_ctx was
already zero, even at the start of the tailcall instruction.  This
probably means we're leaking contexts like crazy.  It occurs to me that
if this context refcounting stuff really worked, we wouldn't even need
SUB_FLAG_TAILCALL, because the caller's context would get freed sooner
purely because it was not referenced by the return continuation.

   So I'm going to think on this for a bit.  Suggestions gratefully
accepted.

                                        -- Bob

Reply via email to