[Vm-dev] Why "object becomeForward: 3" is not working?

Mariano Martinez Peck marianopeck at gmail.com
Thu Mar 17 14:54:23 UTC 2016


On Thu, Mar 17, 2016 at 11:42 AM, Bert Freudenberg <bert at freudenbergs.de>
wrote:

>
>
> > On 17.03.2016, at 13:52, David T. Lewis <lewis at mail.msen.com> wrote:
> >
> >
> > On Thu, Mar 17, 2016 at 09:57:51AM +0100, Denis Kudriashov wrote:
> >>
> >> Hi.
> >>
> >> I investigate that #becomeForward: is not working for SmallInteger
> args. It
> >> is mentioned in method comment:
> >>
> >> Fails if either argument is a SmallInteger.
> >>
> >>
> >> I guess that it is not working for any immediate argument. For example
> it
> >> is failed for Character too.
> >>
> >> So I am interesting why it is not supported?
> >
> > The become mechanism is swapping references to objects, such that the
> > object pointers that pointed to one object are all now pointing to
> another.
> > An immediate object such as SmallInteger is hiding its value within the
> > object pointer itself (so it not really a pointer when used in this way).
> > The immediate object "pointer" is therefore not able to participate in
> > reference swapping.
>
> Well, that’s no reason we couldn’t just replace all references to the
> object with the immediate value.
>
> There’s only one technical reason I am aware of, and that is that
> becomeForward actually does change the argument’s identityHash:
>
>

Couldn't that be solved using the #becomeForward:copyHash: flavor (passing
`false` to copyHas:) ?




> old := ‘old'.
> new := ’new'.
> idold := old identityHash.
> idnew := new identityHash.
> old becomeForward: new.
> {idold. idnew. new identityHash}
>
> ==> #(153 3753 153)
>
> In this case, b’s identity hash changed from 3753 to 153.
>
> This mechanism exists so that if ‘old’ was used as key in an
> IdentityDictionary before, then now ‘new’ can be found at the same position
> because it uses the same hash. And since there is no way to change the
> identity hash of an immediate value, this can not work.
>
>
> > On 17.03.2016, at 14:35, Denis Kudriashov <dionisiydk at gmail.com> wrote:
> >
> > So to implement becomeForward: with integer argument it is needed to
> scan all references to receiver and change pointers body to hold integer
> value.
> > Am I right?
>
> What *does* work, however (at least in Cog and SqueakJS, although not in
> the interpreter) is to use 'becomeForward: new copyHash: false’:
>
> old := 'hi'.
> old becomeForward: 3 copyHash: false.
> old
> ==> 3
>
> ... because in the “copyHash: false” case the argument object is not
> modified in any way.
>
> - Bert -
>
>
>


-- 
Mariano
http://marianopeck.wordpress.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20160317/7369c80b/attachment.htm


More information about the Vm-dev mailing list