push object onto stack

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

push object onto stack

Ang BeePeng
Hi,

In SqueakVM(C), I have a pointer to an object which I wish to push it onto the stack, so that I can use that object in Squeak.


Says oop is the pointer to the object, I tried with popthenPush(oop), push(oop), pushRemappableOop(oop), push(oopForPointer(oop)). All of these seem to give wrong object back to Squeak. Any advise where might be the mistake? Which one should I use?


oop that I have is a float object, I won't want to use pushFloat() because oop is a pointer. Also, what is the usage of pushRemappableOop()?


Thanks.

Ang Beepeng
Reply | Threaded
Open this post in threaded view
|

Re: push object onto stack

Ang BeePeng
Hi,

I found that my object might have been moved by garbage collector. That's why pushing oop gives a wrong object. What can I do to stop GC from touching my object?

Thanks.

Ang Beepeng
Reply | Threaded
Open this post in threaded view
|

Re: push object onto stack

Bert Freudenberg
On 20.04.2010, at 11:45, Ang BeePeng wrote:
>
>
> Hi,
>
> I found that my object might have been moved by garbage collector. That's
> why pushing oop gives a wrong object. What can I do to stop GC from touching
> my object?

You can't.

That's what pushRemappableOop: is for. Before invoking any function that can cause a GC you need to push the oops you are holding onto. After the function returns, pop them.

Just browse senders of #pushRemappableOop: to see lots of examples. Here is one:

        "remap methodContext in case GC happens during allocation"
        self pushRemappableOop: methodContext.
        newContext := self instantiateContext: (self splObj: ClassBlockContext) sizeInBytes: contextSize.
        methodContext := self popRemappableOop.

- Bert -


Reply | Threaded
Open this post in threaded view
|

Re: push object onto stack

Ang BeePeng
Hi, thank you so much for your help.

From example, most(probably all) of them use #popRemappableOop and #pushRemappableOop in a single method(function).

        "remap methodContext in case GC happens during allocation"
        self pushRemappableOop: methodContext.
        newContext := self instantiateContext: (self splObj: ClassBlockContext) sizeInBytes: contextSize.
        methodContext := self popRemappableOop.

Is it possible to use them in two function? i.e. one push and the other pop.

Is it possible that other method pop the object that I just pushed? It sounds impossible if every method, do their push and pop before return. But while I'm debugging, I actually saw my object on remappableOop being remove, changed.

What change objects on remappable-stack?

Thanks.

Ang Beepeng
Reply | Threaded
Open this post in threaded view
|

Re: push object onto stack

Bert Freudenberg
On 21.04.2010, at 08:10, Ang BeePeng wrote:
>
> From example, most(probably all) of them use #popRemappableOop and
> #pushRemappableOop in a single method(function).

Of course. That's how it is designed, to wrap functions that can cause a GC. Push, call "dangerous" function, pop.

> Is it possible to use them in two function? i.e. one push and the other pop.

You should not do this. It's way to easy to unbalance the remap stack otherwise.

> What change objects on remappable-stack?

GC

- Bert -