Tips and tricks?

Peter van Rooijen peter at vanrooijen.com
Thu Mar 11 15:37:37 UTC 2004


From: "Alexandre Bergel" <bergel at iam.unibe.ch>
> With Squeak if you add an instance variable to a class,
> it is placed before the IVs present in the subclasses.
> For instance if you a class A with no IV, and a class B
> with iv1 as IV, iv1 has the offset 0.
> It you add a variable iv2 in A, iv1 get the offset 1.
>
> Perhaps the issue of adding IV to Object can be
> resolved if the offset of already existing IV are preserved.
> Like that the problem with the class definition would
> be avoided....

It would also avoid the need to recompile existing methods in the hierarchy
on instvar addition.

> Is it doable?

I haven't thought about this in depth or ever tried it out, so I could be
totally off, but it seems possible. But it would be terribly inefficient
storage-wise or otherwise require an extra per-class mapping from instance
variable index to slot index.

Think about it this way: Add and extra instvar to Object. Scan all the
subclasses for the highest instvar index. it is 18 (say). Add your new
instance variable at index 19. All old methods stay valid. Wonderful! But
you haven't used the new instance variable yet!!

Now you make a method accessing this new instance variable (because you do
want to use it, right?). The byte codes for reading and writing the variable
use the equivalent of instVarAt: 19 and instVarAt: 19 put: newValue.

Now, do you want 18 empty named instance variable slots in each instance of
Object or each subclass that doesn't add any instance variables? Or do you
want to go, on each instance variable access, through an indirection that
translates 19 to the appropriate offset for the particular class?

It would all seem to get terribly complicated.

But it might work as an intermediate step in a scheme that indeed allows
adding instvars to Object.

Cheers,

Peter

> Alexandre
>
>
> > work, but in practice often becomes impractical.  I don't think any
> > Smalltalk system in that era (late 80s-early 90s) could actually do this
> > (there is a deep hard problem with changing the shape of objects whose
> > layout is know to the vm-implementation itself--but these are quite few
> > in number).  But their failure modes were quite interesting: ranging
> > from notifiers saying sorry can't do that, to infinite looping, to
> > recursive does not understand, to process and or machine lockups and
> > crashes.
> >
> > -----Original Message-----
> > From: squeak-dev-bounces at lists.squeakfoundation.org
> > [mailto:squeak-dev-bounces at lists.squeakfoundation.org] On Behalf Of
> > ducasse
> > Sent: Wednesday, March 10, 2004 9:27 AM
> > To: The general-purpose Squeak developers list
> > Subject: Re: Tips and tricks?
> >
> > romain
> > no reread my email. the problem is that reference to instance variables
> > are converted to offset in the bytecode. So this is not sure that if
> > you allow to add a method that the right offset will be found
> > especially because you do not want
> > to recompile all the code. (may be there is a trick or heuristic
> > sorting the
> > iv but I did not go deep enough into it)
> >
> > Stef
> >
> > On 10 mars 04, at 16:38, Romain Robbes wrote:
> >
> > > Hi stef,
> > >
> > > Would the AddInstanceVariableRefactoring solve your
> > > problem ?
> > > Just wondering ...
> >
> >
> >
>
> -- 
> _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
> Alexandre Bergel  http://www.iam.unibe.ch/~bergel
> ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
>
>




More information about the Squeak-dev mailing list