[squeak-dev] Re: Getting back to push/pop remappable oop

Igor Stasenko siguctua at gmail.com
Tue Nov 11 16:51:58 UTC 2008


2008/11/11 Andreas Raab <andreas.raab at gmx.de>:
> Igor Stasenko wrote:
>>
>> - there was no need in having these methods from the very start.
>> Any oop at any time can be temporary pushed on stack and then popped
>> back again using #pop:/#push: methods.
>> Of course, primitives need to be careful to not override the
>> arguments, which can be reused in method when primitive fails - so
>> they should push values past the arguments.
>
> This won't work. Stack frames are limited in size and sized in the image
> based on however much space is required by the byte codes without any
> regards of potential additional space needed by primitives (which is
> variable). And, since primitives are executed before activation (meaning
> that the "primitive stack" would have to share the frame with the caller
> method) every frame would have to reserve the maximum additional stack space
> any single primitive might require.
>

Okay, but what about reusing the arguments stack slots?
In most cases, when primitive generating response its:
- already checked everything (can't fail)
- already evaluated results
- arguments no more in use

And , since primitive should return only single object, its easy to
prove, that it requires MAXIMUM SINGLE temp value on stack, which
needs to be remapped.

(in primitiveSoundGetVolume)
       ....
	interpreterProxy pushRemappableOop: (right asOop: Float).
	interpreterProxy pushRemappableOop: (left asOop: Float).
	interpreterProxy pushRemappableOop: (interpreterProxy
instantiateClass: (interpreterProxy classArray) indexableSize: 2).
	results := interpreterProxy popRemappableOop.
	interpreterProxy storePointer: 0 ofObject: results withValue:
interpreterProxy popRemappableOop.
	interpreterProxy storePointer: 1 ofObject: results withValue:
interpreterProxy popRemappableOop.
do:

| oop |
...
interpreterProxy pop: 1. "pop the receiver from stack"
interpreterProxy push: (interpreterProxy instantiateClass:
(interpreterProxy classArray) indexableSize: 2).
oop :=  right asOop: Float. "may cause GC"
interpreterProxy storePointer: 0 ofObject: (interpreterProxy stackTop)
withValue: oop.
oop :=  left asOop: Float. "may cause GC"
interpreterProxy storePointer: 1 ofObject: (interpreterProxy stackTop)
withValue: oop.
"result already on stack.. nothing else to do"


same in BalloonEngineBase>>primitiveGetClipRect
 ...
	interpreterProxy pushRemappableOop: rectOop.
	pointOop := interpreterProxy makePointwithxValue: self clipMinXGet
yValue: self clipMinYGet.
	rectOop := interpreterProxy popRemappableOop.
	interpreterProxy storePointer: 0 ofObject: rectOop withValue: pointOop.
	interpreterProxy pushRemappableOop: rectOop.
	pointOop := interpreterProxy makePointwithxValue: self clipMaxXGet
yValue: self clipMaxYGet.
	rectOop := interpreterProxy popRemappableOop.
	interpreterProxy storePointer: 1 ofObject: rectOop withValue: pointOop.

	interpreterProxy pop: 2.
	interpreterProxy push: rectOop.

rewrite:
...

	interpreterProxy pop: 2.
	interpreterProxy push: rectOop.

	pointOop := interpreterProxy makePointwithxValue: self clipMinXGet
yValue: self clipMinYGet.
	interpreterProxy storePointer: 0 ofObject: (interpreterProxy
stackTop) withValue: pointOop.
	pointOop := interpreterProxy makePointwithxValue: self clipMaxXGet
yValue: self clipMaxYGet.
	interpreterProxy storePointer: 1 ofObject: (interpreterProxy
stackTop) withValue: pointOop.

see? its even less lines of code :)

> Cheers,
>  - Andreas

-- 
Best regards,
Igor Stasenko AKA sig.



More information about the Squeak-dev mailing list