[Vm-dev] Problem with Proxies, objects and MethoDict

Eliot Miranda eliot.miranda at gmail.com
Wed Sep 29 01:42:25 UTC 2010


On Tue, Sep 28, 2010 at 1:29 PM, Mariano Martinez Peck <
marianopeck at gmail.com> wrote:

>
> Hi folks. I am trying to do something and I found a VM crash. Suppose I
> want to swap out a class, do a become with a proxy (that with the DNU will
> load the class back). In addition, I have instances of the swapped class.
>
> Example of code (will crash in the last line):
>
> o := MyObject new.
> o foo: 123.
> p := ClassProxy new.
> p become: MyObject.
> o == nil.
> o foo.
>
>
> My Object just extends Object, has an instVar 'foo',  and implements the
> accessors.
>
> ClassProxy implements:
>
> become: aClass
>     className := aClass name.
>     aClass fileOut.
>     super become: aClass
>
> and
>
> doesNotUnderstand: aMessage
>     | reloadedClass |
>     (FileStream fileNamed: className, '.st') fileIn.
>     reloadedClass := Smalltalk at: className.
>     self becomeForward: reloadedClass.
>     ^aMessage sendTo: reloadedClass
>
>
> So....does someone know why the crash?
>

I'm not sure but here are some possible reasons...

1. you didn't flush the method lookup cache after doing the becomeForward:
and the perform in sentTo: found a stale method and boom.
2. you became from a class with N inst vars to one with N+M inst vars and
the methods of the new class accessed inst vars > N which are off the end of
your instance, causing the VM to read invalid oops and boom.

So a) always flush the method lookup cache and b) /never/ cause the VM to
read past an object by changing the class underneath an object such that the
class accesses more inst vars than the instance has.


> how can I solve it ?
>
> Thanks in advance
>
> Mariano
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20100928/4de3e184/attachment.htm


More information about the Vm-dev mailing list