VM & Runtime stack

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

VM & Runtime stack

Bergel, Alexandre
Hi!

In Squeak, the stack is reified upon the execution of the thisContext  
bytecode. Else, the stack is not reified. So comes my question: Where  
is the stack stored ? Is there a dedicated part of the memory ?

Cheers,
Alexandre

--
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.




Reply | Threaded
Open this post in threaded view
|

Re: VM & Runtime stack

Adrian Lienhard
Hi Alex,

No, there is no real reification (depending on the definition of  
course). The contexts used by the VM are the very same objects you  
get at the image level. Plain old Smalltalk objects...

The only special thing about contexts is that they are recycled, if  
possible. The VM holds a list of contexts that can be reused. If you  
access thisContext (through the special bytecode), this context and  
any other context not returned from (i.e., still on the stack of the  
active process) cannot be recycled anymore. As far as I remember,  
also when switching process or when doing a GC, the cache is flushed.  
(I once did a statistic about how many contexts are actually recycled  
compared to being newly instantiated, and only got around 6-10%,  
which is much less than what I expected.)

Cheers,
Adrian

___________________
Adrian Lienhard
www.adrian-lienhard.ch

On Jul 16, 2007, at 12:47 , Bergel, Alexandre wrote:

> Hi!
>
> In Squeak, the stack is reified upon the execution of the  
> thisContext bytecode. Else, the stack is not reified. So comes my  
> question: Where is the stack stored ? Is there a dedicated part of  
> the memory ?
>
> Cheers,
> Alexandre
>
> --
> _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
> Alexandre Bergel  http://www.bergel.eu
> ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
>
>
>
>




Reply | Threaded
Open this post in threaded view
|

Re: VM & Runtime stack

Bergel, Alexandre
Thanks Adrian,

Alexandre


On 16 Jul 2007, at 14:01, Adrian Lienhard wrote:

> Hi Alex,
>
> No, there is no real reification (depending on the definition of  
> course). The contexts used by the VM are the very same objects you  
> get at the image level. Plain old Smalltalk objects...
>
> The only special thing about contexts is that they are recycled, if  
> possible. The VM holds a list of contexts that can be reused. If  
> you access thisContext (through the special bytecode), this context  
> and any other context not returned from (i.e., still on the stack  
> of the active process) cannot be recycled anymore. As far as I  
> remember, also when switching process or when doing a GC, the cache  
> is flushed. (I once did a statistic about how many contexts are  
> actually recycled compared to being newly instantiated, and only  
> got around 6-10%, which is much less than what I expected.)
>
> Cheers,
> Adrian
>
> ___________________
> Adrian Lienhard
> www.adrian-lienhard.ch
>
> On Jul 16, 2007, at 12:47 , Bergel, Alexandre wrote:
>
>> Hi!
>>
>> In Squeak, the stack is reified upon the execution of the  
>> thisContext bytecode. Else, the stack is not reified. So comes my  
>> question: Where is the stack stored ? Is there a dedicated part of  
>> the memory ?
>>
>> Cheers,
>> Alexandre
>>
>> --
>> _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
>> Alexandre Bergel  http://www.bergel.eu
>> ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
>>
>>
>>
>>
>
>
>
>

--
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.




Reply | Threaded
Open this post in threaded view
|

Re: VM & Runtime stack

Klaus D. Witzel
In reply to this post by Adrian Lienhard
On Mon, 16 Jul 2007 14:01:35 +0200, Adrian Lienhard wrote:

> Hi Alex,
>
> No, there is no real reification (depending on the definition of  
> course). The contexts used by the VM are the very same objects you get  
> at the image level. Plain old Smalltalk objects...
>
> The only special thing about contexts is that they are recycled, if  
> possible. The VM holds a list of contexts that can be reused. If you  
> access thisContext (through the special bytecode), this context and any  
> other context not returned from (i.e., still on the stack of the active  
> process) cannot be recycled anymore. As far as I remember, also when  
> switching process or when doing a GC, the cache is flushed. (I once did  
> a statistic about how many contexts are actually recycled compared to  
> being newly instantiated, and only got around 6-10%, which is much less  
> than what I expected.)

FWIW, over in the newcompiler list we recently discussed various  
implementation details, from the new compiler down to the VM level, of  
full BlockClosures. It turned out that as soon as BlockClosures receive  
full (performant) support from the VM then breaking the recycleable  
context rule no longer occurs and recycling can happen 100%[tm]. We  
haven't looked at process switch and GC (adaptation is possibly easy).

/Klaus

> Cheers,
> Adrian
>
> ___________________
> Adrian Lienhard
> www.adrian-lienhard.ch
>
> On Jul 16, 2007, at 12:47 , Bergel, Alexandre wrote:
>
>> Hi!
>>
>> In Squeak, the stack is reified upon the execution of the thisContext  
>> bytecode. Else, the stack is not reified. So comes my question: Where  
>> is the stack stored ? Is there a dedicated part of the memory ?
>>
>> Cheers,
>> Alexandre
>>
>> --_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
>> Alexandre Bergel  http://www.bergel.eu
>> ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
>>
>>
>>
>>
>
>
>
>
>



Reply | Threaded
Open this post in threaded view
|

Re: VM & Runtime stack

Bryce Kampjes
Klaus D. Witzel writes:
 > FWIW, over in the newcompiler list we recently discussed various  
 > implementation details, from the new compiler down to the VM level, of  
 > full BlockClosures. It turned out that as soon as BlockClosures receive  
 > full (performant) support from the VM then breaking the recycleable  
 > context rule no longer occurs and recycling can happen 100%[tm]. We  
 > haven't looked at process switch and GC (adaptation is possibly easy).

I just benchmarked with and without context recycling
using tiny benchmarks:

Benchmarks with a vanilla VM:
233,151,183 bytecodes/sec; 7,028,070 sends/sec
Benchmarks without context recycling:
232,939,035 bytecodes/sec; 4,022,730 sends/sec

I remember it being worth more than these figures show but it's still
very significant. I benchmarked on a 2.2GHz Athlon 64 3500+.

I wouldn't be surprised if the benefit changes drastically with
CPU and possibly the send benchmark chosen.

Bryce

Reply | Threaded
Open this post in threaded view
|

Re: VM & Runtime stack

Mathieu SUEN
In reply to this post by Klaus D. Witzel
Actualy not when a precess switch occure or not when thisContext is  
used.
But is true that the from now the block need to push the context and  
this bytecode flush the context cache.
This is not a good things since the context may not be used inside  
the block.
The only case when the context shouldn't be recycle is when the block  
is pass as a return value or assign to an inst var,class var,  global  
var....

This because:
  MethodContext goes to the cache when the VM return from the method.
The BlockContext have a reference to the MethodContext

But there is some block where the context aren't push on the stack.
Actually is for special send that are inlined (#to:do:,  
#ifTrue:ifFalse: #caseOf: and so on) so block aren't created.

        Mth



On Jul 16, 2007, at 4:04 PM, Klaus D. Witzel wrote:

> FWIW, over in the newcompiler list we recently discussed various  
> implementation details, from the new compiler down to the VM level,  
> of full BlockClosures. It turned out that as soon as BlockClosures  
> receive full (performant) support from the VM then breaking the  
> recycleable context rule no longer occurs and recycling can happen  
> 100%[tm].


Reply | Threaded
Open this post in threaded view
|

Re: VM & Runtime stack

Mathieu SUEN
In reply to this post by Bryce Kampjes
Where, how did you get/make those benchmark?

        Mth



On Jul 16, 2007, at 11:02 PM, <[hidden email]>  
<[hidden email]> wrote:

> I just benchmarked with and without context recycling
> using tiny benchmarks:


Reply | Threaded
Open this post in threaded view
|

Re: VM & Runtime stack

Igor Stasenko
type:
1000000000000 tinyBenchmarks :)))

On 17/07/07, Mathieu Suen <[hidden email]> wrote:

> Where, how did you get/make those benchmark?
>
>         Mth
>
>
>
> On Jul 16, 2007, at 11:02 PM, <[hidden email]>
> <[hidden email]> wrote:
>
> > I just benchmarked with and without context recycling
> > using tiny benchmarks:
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: VM & Runtime stack

Igor Stasenko
In reply to this post by Mathieu SUEN
On 17/07/07, Mathieu Suen <[hidden email]> wrote:

> Actualy not when a precess switch occure or not when thisContext is
> used.
> But is true that the from now the block need to push the context and
> this bytecode flush the context cache.
> This is not a good things since the context may not be used inside
> the block.
> The only case when the context shouldn't be recycle is when the block
> is pass as a return value or assign to an inst var,class var,  global
> var....
>
> This because:
>   MethodContext goes to the cache when the VM return from the method.
> The BlockContext have a reference to the MethodContext
>
> But there is some block where the context aren't push on the stack.
> Actually is for special send that are inlined (#to:do:,
> #ifTrue:ifFalse: #caseOf: and so on) so block aren't created.
>
>         Mth
>
Compiler, in most cases, can figure out if block requires MethodContext or not.
I don't know much about Squeak compiler, but inspecting Dolphin
bytecode shows that they having set of flags to indicate if block uses
MethodContext, self e.t.c..
For instance, block like: [ literal message ] , [ SomeClass message ]
] , which don't use any method's temps/args/self/returns
can be executed from anywhere returning same result, thus they can be
prepared for execution differently to avoid unneeded checks/flushes
e.t.c.

>
> On Jul 16, 2007, at 4:04 PM, Klaus D. Witzel wrote:
>
> > FWIW, over in the newcompiler list we recently discussed various
> > implementation details, from the new compiler down to the VM level,
> > of full BlockClosures. It turned out that as soon as BlockClosures
> > receive full (performant) support from the VM then breaking the
> > recycleable context rule no longer occurs and recycling can happen
> > 100%[tm].
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: VM & Runtime stack

Mathieu SUEN
With the NewCompiler we don't need to know if the context is used.
If you use temporaries it will be store in an environment. (ie a  
ClosureEnvironment)

        Mth



On Jul 17, 2007, at 4:16 AM, sig wrote:

> Compiler, in most cases, can figure out if block requires  
> MethodContext or not.
> I don't know much about Squeak compiler, but inspecting Dolphin
> bytecode shows that they having set of flags to indicate if block uses
> MethodContext, self e.t.c..
> For instance, block like: [ literal message ] , [ SomeClass message ]
> ] , which don't use any method's temps/args/self/returns
> can be executed from anywhere returning same result, thus they can be
> prepared for execution differently to avoid unneeded checks/flushes
> e.t.c.


Reply | Threaded
Open this post in threaded view
|

Re: VM & Runtime stack

Klaus D. Witzel
In reply to this post by Igor Stasenko
On Tue, 17 Jul 2007 04:16:28 +0200, sig wrote:

> On 17/07/07, Mathieu Suen <[hidden email]> wrote:
>> Actualy not when a precess switch occure or not when thisContext is
>> used.
>> But is true that the from now the block need to push the context and
>> this bytecode flush the context cache.
>> This is not a good things since the context may not be used inside
>> the block.
>> The only case when the context shouldn't be recycle is when the block
>> is pass as a return value or assign to an inst var,class var,  global
>> var....
>>
>> This because:
>>   MethodContext goes to the cache when the VM return from the method.
>> The BlockContext have a reference to the MethodContext
>>
>> But there is some block where the context aren't push on the stack.
>> Actually is for special send that are inlined (#to:do:,
>> #ifTrue:ifFalse: #caseOf: and so on) so block aren't created.
>>
>>         Mth
>>
> Compiler, in most cases, can figure out if block requires MethodContext  
> or not.

Perhaps you mean BlockContext.

> I don't know much about Squeak compiler, but inspecting Dolphin
> bytecode shows that they having set of flags to indicate if block uses
> MethodContext, self e.t.c..
> For instance, block like: [ literal message ] , [ SomeClass message ]
> ] , which don't use any method's temps/args/self/returns
> can be executed from anywhere returning same result, thus they can be
> prepared for execution differently to avoid unneeded checks/flushes
> e.t.c.
>
>>
>> On Jul 16, 2007, at 4:04 PM, Klaus D. Witzel wrote:
>>
>> > FWIW, over in the newcompiler list we recently discussed various
>> > implementation details, from the new compiler down to the VM level,
>> > of full BlockClosures. It turned out that as soon as BlockClosures
>> > receive full (performant) support from the VM then breaking the
>> > recycleable context rule no longer occurs and recycling can happen
>> > 100%[tm].
>>
>>
>>
>
>



Reply | Threaded
Open this post in threaded view
|

Re: VM & Runtime stack

Igor Stasenko
On 17/07/07, Klaus D. Witzel <[hidden email]> wrote:

> On Tue, 17 Jul 2007 04:16:28 +0200, sig wrote:
>
> > On 17/07/07, Mathieu Suen <[hidden email]> wrote:
> >> Actualy not when a precess switch occure or not when thisContext is
> >> used.
> >> But is true that the from now the block need to push the context and
> >> this bytecode flush the context cache.
> >> This is not a good things since the context may not be used inside
> >> the block.
> >> The only case when the context shouldn't be recycle is when the block
> >> is pass as a return value or assign to an inst var,class var,  global
> >> var....
> >>
> >> This because:
> >>   MethodContext goes to the cache when the VM return from the method.
> >> The BlockContext have a reference to the MethodContext
> >>
> >> But there is some block where the context aren't push on the stack.
> >> Actually is for special send that are inlined (#to:do:,
> >> #ifTrue:ifFalse: #caseOf: and so on) so block aren't created.
> >>
> >>         Mth
> >>
> > Compiler, in most cases, can figure out if block requires MethodContext
> > or not.
>
> Perhaps you mean BlockContext.
>
No, saying MethodContext i mean home context or environment.

Reply | Threaded
Open this post in threaded view
|

Re: VM & Runtime stack

Bryce Kampjes
In reply to this post by Mathieu SUEN
Mathieu Suen writes:
 > Where, how did you get/make those benchmark?
 >
 > Mth
 >
 >
 >
 > On Jul 16, 2007, at 11:02 PM, <[hidden email]>  
 > <[hidden email]> wrote:
 >
 > > I just benchmarked with and without context recycling
 > > using tiny benchmarks:

I used "0 tinyBenchmarks". It's a little too simple for
real decisions but a decent guide.

I disabled context recycling by commenting out the two lines that
incrememnt reclaimableContextCount.

Bryce