[squeak-dev] Re: Using #= for integer comparison instead of #==

Levente Uzonyi leves at elte.hu
Wed Nov 17 04:05:31 UTC 2010


On Tue, 16 Nov 2010, Andreas Raab wrote:

> On 11/16/2010 4:21 PM, Levente Uzonyi wrote:
>> On Tue, 16 Nov 2010, Eliot Miranda wrote:
>> 
>>> Um, on Cog it sends a message if the method containing the #= has been
>>> jitted. But the issue is /not/ whether there is a send or not. The issue
>> 
>> Does it mean, that #= can't be used in "atomic" code anymore?
>
> It never was. In the old (pre-closure) days you might have gotten away with 
> using #= only because of the context cache which would avoid creating a new 
> context if a previous one could be recycled. But code like:
>
> 	obj := self someObject.
> 	[0 = obj nextObject] whileFalse:[count := count + 1].

I wasn't clear when I said atomic code. I expected #= (and #<, #>, etc) to 
_not_ be a real message send when both the receiver and the argument are 
SmallIntegers. Otherwise what's the point of having separate bytecodes for 
them?

Here's some example code which I expected to be atomic:

| x |
x := aSmallInteger. "really a SmallInteger"
x > 0
 	ifTrue: [ x := x - 1 ]
 	ifFalse: [
 		x = 0 ifFalse: [ x := 0 ] ]

>
> really should never have worked to begin with because:
> * sending #= will create a context (unless recycled)
> * the plus in the counter will create a context (unless count is in SmallInt 
> range)
> * the addition may create a new object (unless count in SmallInt range)
> * either one of the blocks should create contexts (unless optimized)
>
> There's a long list of reasons why code such as the above is simply broken. 
> You *must* use an end marker, i.e.,
>
> 	last := Object new. "end marker"
> 	obj := self someObject.
> 	[last == obj] whileFalse:[
> 		count := count + 1.
> 		obj := obj nextObject.
> 	].
>
> This will work because it counts between the beginning of memory and the 
> (arbitrary) end marker. Anything else basically should not be relied on to 
> work, jit or no.

To make it clear: I didn't want to change this code at all, I was just 
discussing about the current and previous implenetation with Juan.


Levente

>
> Cheers,
>  - Andreas
>
>



More information about the Squeak-dev mailing list