<br><br><div class="gmail_quote">On Wed, Sep 29, 2010 at 3:42 AM, Eliot Miranda <span dir="ltr">&lt;<a href="mailto:eliot.miranda@gmail.com">eliot.miranda@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
 <br><br><br><div class="gmail_quote">On Tue, Sep 28, 2010 at 1:29 PM, Mariano Martinez Peck <span dir="ltr">&lt;<a href="mailto:marianopeck@gmail.com" target="_blank">marianopeck@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

 <br>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.<br>


<br>Example of code (will crash in the last line):<br><br>o := MyObject new.<br>o foo: 123.<br>p := ClassProxy new.<br>p become: MyObject.<br>o == nil.<br>o foo.<br><br><br>My Object just extends Object, has an instVar &#39;foo&#39;,  and implements the accessors. <br>


<br>ClassProxy implements:<br><br>become: aClass<br>    className := aClass name.<br>    aClass fileOut.<br>    super become: aClass<br><br>and<br><br>doesNotUnderstand: aMessage<br>    | reloadedClass |<br>    (FileStream fileNamed: className, &#39;.st&#39;) fileIn.<br>


    reloadedClass := Smalltalk at: className. <br>    self becomeForward: reloadedClass.<br>    ^aMessage sendTo: reloadedClass<br><br><br>So....does someone know why the crash?<br></blockquote><div><br></div><div>I&#39;m not sure but here are some possible reasons...</div>

<div><br></div><div>1. you didn&#39;t flush the method lookup cache after doing the becomeForward: and the perform in sentTo: found a stale method and boom.</div></div></blockquote><div><br>Thanks Eliot. I was checking the code of the become in #primitiveArrayBecome  and it seems that in #mapPointersInObjectsFrom: self startOfMemory to: <br>
they do the &quot;self flushMethodCacheFrom: memStart to: memEnd.&quot;<br><br>Anyway, I tried it with <br><br>| o p |<br>o := MyClass new.<br>o foo: 123.<br>p := ClassProxy new.<br>p become: MyClass.<br>MyClass flushCache.<br>
ClassProxy flushCache.<br>o == nil.<br>Transcript show: o class name; cr.<br>o foo.<br><br>but same results.<br><br>Now, something interesting is that &quot;Transcript show: o class name; cr.&quot;   prints &quot;MyClass&quot;. Is this correct?  <br>
<br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div class="gmail_quote"><div>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 &gt; N which are off the end of your instance, causing the VM to read invalid oops and boom.</div>

<div><br></div></div></blockquote><div><br>My case is even more complicated. I want to become from a CLASS to an INSTANCE. I mean, I want to become the class MyClass with AN INSTANCE of  PROXY CLASS. Then the proxy class uses te DNU to bring the other back.<br>
<br>Now I was thinking that maybe the proxy class should not extend from ProtoObject but from Behavior or similar?  But I want smaller objects...I don&#39;t want to spend instances in &quot;uperclass methodDict format&#39;&quot;  since the only thing I have to do is with DNU bring back other object. <br>
<br>Finally, I have a question. I tried to look at the #become but I didn&#39;t get it... When I do a become from a class to an object for example, if there were (normal) pointers (slots in other objects) to that class, then they are updated and point to the other object. However, what happens with the instances of that class?  is the class pointer in their object header consider like a normal pointer? are those piointers updated also by the #become?    Maybe they are not and this is why  &quot;Transcript show: o class name; cr.&quot;   prints &quot;MyClass&quot;   ?<br>
<br>Sorry for the newbie question...I am learning all this...<br><br>Cheers<br><br>Mariano<br><br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="gmail_quote"><div></div><div>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.</div>

<div><br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><br>how can I solve it ?<br><br>Thanks in advance<br>
<br>Mariano<br>
<br></blockquote></div><br>
<br></blockquote></div><br>