<br><br><div class="gmail_quote">On Sun, Nov 16, 2008 at 7:11 PM, Igor Stasenko <span dir="ltr"><<a href="mailto:siguctua@gmail.com">siguctua@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
2008/11/17 Hernán Morales Durand <<a href="mailto:hernan.morales@gmail.com">hernan.morales@gmail.com</a>>:<br>
<div><div></div><div class="Wj3C7c">> Dear all,<br>
> In the attachment you will find an implementation of Lightweight Classes<br>
> for Squeak that follows the original paper "Debugging Objects" of Hinkle et<br>
> al. However I was unable to set up the #class method in the LightweightClass<br>
> to answer the real class of the lightwighted object, is this possible<br>
> currently in Squeak?.<br>
><br>
> What I did:<br>
> -Created the LightweightClass as in the old VisualWorks implementation. The<br>
> only difference here was CompiledMethod's cannot be copied, so I used<br>
> #clone.<br>
> -Created and installed an UnstoredMethod (a CompiledMethod subclass) in the<br>
> LightweightClass's methodDictionary. Since I want to store the source code<br>
> but not through the changes log, I borrowed the MethodWrappers idea of<br>
> storing the state (sourceCode) in a class instance variable, and compile<br>
> without logging. The methods I borrowed from MW are:<br>
><br>
> -#copyWithTrailerBytes: - I think the superimplementor in CompiledMethod<br>
> could use "self class" to avoid reimplementors.<br>
> -#tweakClassFormat - which set the format but I don't know why and cannot<br>
> find documentation on this.<br>
> -#objectAt: I suspected the class literal was stored in the literal frame<br>
> everytime I accepted a method, but for the simple test below still answer<br>
> the LightweightClass and not the real class.<br>
><br>
> Here is the test:<br>
><br>
> | aDate |<br>
> aDate := Date today.<br>
> aDate becomeLightweight.<br>
> aDate dispatchingClass compile: 'day ^43' notifying: nil.<br>
> aDate day. " 43 (works) "<br>
> aDate perform: #class. " Date ------> (works) "<br>
> aDate class. " {Date} ------> LightweightClass (wrong) "<br>
><br>
<br>
</div></div>The only cause of this can be compiler.<br>
Instead of generating an instruction for sending #class message, it<br>
generates a bytecode to fetch the class from receiver oop , instead of<br>
sending real message.</blockquote><div><br></div><div>IMO the bug is in the VM. The compiler generates bytecode 199, the special selector class send. But it is the VM that decides to short-cut this send and implement it by accessing the receiver's class directly instead of actually sending the message. I doubt very much this short-circuiting has any impact on performance (VisualWorks has never inlined this special selector send), and it is very easy to fix in the VM. A number of other special selector bytecodes become ordinary sends (e.g. next nextPut: etc). </div>
<div><br></div><div>If class were important for performance one could implement something analogous to the at cache that speeds up at:, at:put: and size for special selectors. The special selector bytecode would check that the receiver of the class message had the standard implementation (primitive in Object) and answer the class directly. But this isn't going to save significant time.</div>
<div><br></div><div>To fix this change</div><div><div>bytecodePrimClass</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>| rcvr |</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>rcvr := self internalStackTop.</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>self internalPop: 1 thenPush: (self fetchClassOf: rcvr).</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>self fetchNextBytecode.</div>
<div>to</div><div><div>bytecodePrimClass</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>messageSelector := self specialSelector: 23.</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>argumentCount := 0.</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>self normalSend.</div><div><br></div></div></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div class="Wj3C7c">> Any hint would be appreciated.<br>
> Best regards.<br>
><br>
> Hernán<br>
><br>
> PS: Just to avoid duplicate efforts, I wrote a LightweightClasses Browser<br>
> which will be available as soon as I find a solution to the problem above.<br>
><br>
<br>
</div></div><font color="#888888">--<br>
Best regards,<br>
Igor Stasenko AKA sig.<br>
</font><br><br>
<br></blockquote></div><br>