Why can't I do (aNonSmallInteger becomeFoward: aSmallInteger)?
tim at sumeru.stanford.edu
Tue Apr 2 03:59:14 UTC 2002
Brian Keefer wrote:
> My understanding of become(Foward): was that there would be an (ever so
> dainty) full GC-ish walk through memory, doing s/oldref/newref/ on each
> object's (variable=reference=pointer=literal SmallInteger) list. Under
> this assumption, the only thing really preventing 3 become: 4 would be
> your own sense of sanity.
The oop of SmallInteger 3 is fixed absolutely (in fact, it's 5 :-).
The semantics of #become always used to be to swap the _value_ of the
oops involved. With an ObjectTable this is usually trivial, and you do
little more than swapping the data pointers of the two involved objects.
When you do a no-OT implementation you get to twist things a little and
it changes to be an exchange of oops rather like you assumed. The
partiicular implementation then becomes the arbiter of what you can do
and in the current squeak vm the use of forwarding blocks & a mild
perversion of the gc prevents SmallIntegers from being swappable. A more
naive implementation that really did just scan memory & swap oops would
be able to swap SmallInts. I think my brain is going to explode now.....
More information about the Squeak-dev