Jens Rieks wrote:
Hi,

the examples in examples/streams are not working with --gc-debug,
FileLines.imc crashes even without it.

Any idea why?

Nasty. After spending some hours with gdb and thinking up, down, and in circles, I could eventually boil it down to the code below.


The continuation created in sub2 has in its context a snapshot of the register backing stacks. After returning from sub2, this context is still alive in the continuation. Now when calling another sub, the interpreter's context changes. The register preserving code is attaching different register backing stacks to the context (simulated by "pushi" below). Now, when these new stack chunks happen to have the same address as the stack saved in the context of the continuation, Bad Things happen.

In this case (and in FileLines.imc) the piece of stack is an IntReg stack, which gets marked by Continuation mark as a PMC stack. But 0x1 or 0x2 isn't a good looking pointer ;)

The primary reason is of course the immediate reusal of stack chunks (the "pushi" get's the popped of PMC reg chunk of the function return). But not reusing register stacks could cause the problem too, only a DOD run later and still much harder to track down, because it would be more unlikely that a certain chunk address gets reused in that way.

The real problem is that the Continuation holds a snapshot of an interpreter context that just doesn't exist any more.

I don't know how to fix this, though.

But the proposed change in calling conventions (swapping in and out interpreter structures) should not have this very problem. There are no register backing stacks any more, the interpreter structure is it's own context. A continuation that exists somwhere should therefore always point to a valid context aka interpreter, because the continuation would mark that context as being alive. Only if the continuation goes out of scope, that context would be invalidated and possibly reused.

.sub main @MAIN
    print "main 1\n"
    sub1()
    print "main 2\n"
    sub3()
.end

.sub sub1 prototyped
    print "sub1 1\n"
    $P5 = sub2()
    P25 = $P5
    print "sub1 2\n"
.end

.sub sub2 prototyped
    print "sub2 1\n"
    .local pmc cont
    cont = new .Continuation
    .pcc_begin_return
        .return cont
    .pcc_end_return
.end

.sub sub3 prototyped
    pushi
    print "sub3 1\n"
    sweep 1
    popi
.end

leo



Reply via email to