About sp and thisContext->spOffset

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

About sp and thisContext->spOffset

Mathieu Suen-2
Hi,

AFAIK sp in a context take in account the temporaries.
This mean the if you have 1 temp sp is equal to 1 at the beginning of the
function (minus the fact the is lazily sync but that is not my point)
From that there is something I don't understand:
In smalltalk I got the following example:

    | method |
    method := (STInST.RBParser parseMethod: 'foo ^12') jitMethodIn: A.
    A methodDictionary at: #foo put: method.
    A new foo printNl


From the VM I got the following code
Note the below printf occure just before the #foo message send and after the
#new:

void
_gst_send_message_internal (OOP sendSelector,
                int sendArgs,
                OOP receiver,
                OOP method_class)
{
..snip..

      switch (header.headerFlag)
    {

..snip..

    case MTH_UNUSED:
      {
..snip..
        newContext = activate_new_context (header.stack_depth, sendArgs);
        ...call to unwind_context ...
        oldContext = (gst_method_context)OOP_TO_OBJ(_gst_this_context_oop);
        printf("SpOffset after: %d\n", oldContext->spOffset);



     }

..snip..
}

I got the following result:

SpOffset before: 3 TO_INT -> 1

I would expected to be FROM_INT(2) aka 5 since you have (A new) push on the
stack.
What did I miss-understood?

Thanks

Mathieu





_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: About sp and thisContext->spOffset

Paolo Bonzini-2
On 08/26/2010 05:45 PM, Mathieu Suen wrote:

> Hi,
>
> AFAIK sp in a context take in account the temporaries.
> This mean the if you have 1 temp sp is equal to 1 at the beginning of the
> function (minus the fact the is lazily sync but that is not my point)
>  From that there is something I don't understand:
> In smalltalk I got the following example:
>
>      | method |
>      method := (STInST.RBParser parseMethod: 'foo ^12') jitMethodIn: A.
>      A methodDictionary at: #foo put: method.
>      A new foo printNl
>
> I would expected to be FROM_INT(2) aka 5 since you have (A new) push on the
> stack.
> What did I miss-understood?

Temporaries in the REPL are kind of special because they must survive
multiple evaluations.  So, they are treated as globals (or as instance
variables in VisualGST).

Try wrapping your test with Eval [ ... ], which will delimit the scope
of the "method" variable, and sp will be 2 as expected.

Paolo

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re : [Help-smalltalk] About sp and thisContext->spOffset

Mathieu Suen-2




----- Message d'origine ----

> De : Paolo Bonzini <[hidden email]>
> Objet : Re: [Help-smalltalk] About sp and thisContext->spOffset
>
> On 08/26/2010 05:45 PM, Mathieu Suen wrote:
> > Hi,
> >
> > AFAIK sp  in a context take in account the temporaries.
> > This mean the if you have  1 temp sp is equal to 1 at the beginning of the
> > function (minus the fact  the is lazily sync but that is not my point)
> >  From that there is  something I don't understand:
> > In smalltalk I got the following  example:
> >
> >      | method |
> >       method := (STInST.RBParser parseMethod: 'foo ^12') jitMethodIn:  A.
> >      A methodDictionary at: #foo put:  method.
> >      A new foo printNl
> >
> > I would  expected to be FROM_INT(2) aka 5 since you have (A new) push on the
> >  stack.
> > What did I miss-understood?
>
> Temporaries in the REPL are  kind of special because they must survive
> multiple evaluations.  So,  they are treated as globals (or as instance
> variables in  VisualGST).
>
> Try wrapping your test with Eval [ ... ], which will delimit  the scope
> of the "method" variable, and sp will be 2 as  expected.

Sorry I didn't mention it but the test above is written in a unit test:

    testReturn [
     | method |
    method := (STInST.RBParser parseMethod: 'foo ^12') jitMethodIn:  A.
    A methodDictionary at: #foo put:  method.
    A new foo printNl
    ]


But from this :

/* activate_new_context */
thisContext->spOffset =
    FROM_INT ((sp - thisContext->contextStack) - sendArgs);


It seems normal that spOffset is equal to FROM_INT(1).
So it mean also the the push if it were using spOffset should be:

push: object
memory storePointer: stackPointer
 ofObject: activeContext
 withValue: object.
stackPointer := stackPointer + 1.
Instead of:

push: object
stackPointer := stackPointer + 1.
memory storePointer: stackPointer
 ofObject: activeContext
 withValue: object

>
> Paolo
>




_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk