Event-driven Cog still crashing (more observations)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Event-driven Cog still crashing (more observations)

Dimitry Golubovsky
 
Hi,

Looks like I found the reason why longjmp crashes subsequent GC:

StackEvtInterpreter >> initStackPagesAndInterpret

--------------------------------------------------------------
        theStackMemory := self
                                                cCode: 'alloca(stackPagesBytes)'
                                                inSmalltalk:
                                                        [stackPages := self stackPagesClass new.
                                                         stackPages initializeWithByteSize: stackPagesBytes for: self].
--------------------------------------------------------------

Of course longjmp discards this allocation. Next time the interpreter
is entered, this stack space will be overwritten. Hence the bizarre
effects.

I haven't tried to work around this; just wandering whether using
malloc instead of alloca is in any way harmful...

--
Dimitry Golubovsky

Anywhere on the Web
Reply | Threaded
Open this post in threaded view
|

Re: Event-driven Cog still crashing (more observations)

David T. Lewis
 
On Tue, Jul 19, 2011 at 12:22:42AM -0400, Dimitry Golubovsky wrote:

>  
> Hi,
>
> Looks like I found the reason why longjmp crashes subsequent GC:
>
> StackEvtInterpreter >> initStackPagesAndInterpret
>
> --------------------------------------------------------------
> theStackMemory := self
> cCode: 'alloca(stackPagesBytes)'
> inSmalltalk:
> [stackPages := self stackPagesClass new.
> stackPages initializeWithByteSize: stackPagesBytes for: self].
> --------------------------------------------------------------
>
> Of course longjmp discards this allocation. Next time the interpreter
> is entered, this stack space will be overwritten. Hence the bizarre
> effects.
>
> I haven't tried to work around this; just wandering whether using
> malloc instead of alloca is in any way harmful...

If you use malloc(), then you would also need to call free(), which
might be tricky given that you are longjmp'ing over the situation.

Note that alloca is used in various places in the interpreter and
in plugins, both in the slang and in support code for the various
platforms.

I have not looked at any of the code, but in your earlier message
you described your use of longjmp, based on Andreas' earlier work,
as follows:

1. Set a jmp_buf to to hold the jump target at the start of the
interpret() function
2. longjmp to this jmp_buf in the transferTo function if its argument
is 0 (thus exiting the interpreter once no processes are ready to
run).

I wonder if there is some other approach that you could use to
accomplish this?

Dave