<br><br><div class="gmail_quote">On Sun, Nov 16, 2008 at 7:11 PM, Igor Stasenko <span dir="ltr">&lt;<a href="mailto:siguctua@gmail.com">siguctua@gmail.com</a>&gt;</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 &lt;<a href="mailto:hernan.morales@gmail.com">hernan.morales@gmail.com</a>&gt;:<br>
<div><div></div><div class="Wj3C7c">&gt; Dear all,<br>
&gt; &nbsp; In the attachment you will find an implementation of Lightweight Classes<br>
&gt; for Squeak that follows the original paper &quot;Debugging Objects&quot; of Hinkle et<br>
&gt; al. However I was unable to set up the #class method in the LightweightClass<br>
&gt; to answer the real class of the lightwighted object, is this possible<br>
&gt; currently in Squeak?.<br>
&gt;<br>
&gt; What I did:<br>
&gt; -Created the LightweightClass as in the old VisualWorks implementation. The<br>
&gt; only difference here was CompiledMethod&#39;s cannot be copied, so I used<br>
&gt; #clone.<br>
&gt; -Created and installed an UnstoredMethod (a CompiledMethod subclass) in the<br>
&gt; LightweightClass&#39;s methodDictionary. Since I want to store the source code<br>
&gt; but not through the changes log, I borrowed the MethodWrappers idea of<br>
&gt; storing the state (sourceCode) in a class instance variable, and compile<br>
&gt; without logging. The methods I borrowed from MW are:<br>
&gt;<br>
&gt; -#copyWithTrailerBytes: - I think the superimplementor in CompiledMethod<br>
&gt; could use &quot;self class&quot; to avoid reimplementors.<br>
&gt; -#tweakClassFormat - which set the format but I don&#39;t know why and cannot<br>
&gt; find documentation on this.<br>
&gt; -#objectAt: I suspected the class literal was stored in the literal frame<br>
&gt; everytime I accepted a method, but for the simple test below still answer<br>
&gt; the LightweightClass and not the real class.<br>
&gt;<br>
&gt; Here is the test:<br>
&gt;<br>
&gt; | aDate |<br>
&gt; aDate := Date today.<br>
&gt; aDate becomeLightweight.<br>
&gt; aDate dispatchingClass compile: &#39;day ^43&#39; notifying: nil.<br>
&gt; aDate day. &quot; 43 (works) &quot;<br>
&gt; aDate perform: #class. &quot; Date ------&gt; (works) &quot;<br>
&gt; aDate class. &quot; {Date} ------&gt; LightweightClass (wrong) &quot;<br>
&gt;<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. &nbsp;The compiler generates bytecode 199, the special selector class send. &nbsp;But it is the VM that decides to short-cut this send and implement it by accessing the receiver&#39;s class directly instead of actually sending the message. &nbsp;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. &nbsp;A number of other special selector bytecodes become ordinary sends (e.g. next nextPut: etc). &nbsp;</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. &nbsp;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. &nbsp;But this isn&#39;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">&gt; Any hint would be appreciated.<br>
&gt; Best regards.<br>
&gt;<br>
&gt; Hernán<br>
&gt;<br>
&gt; PS: Just to avoid duplicate efforts, I wrote a LightweightClasses Browser<br>
&gt; which will be available as soon as I find a solution to the problem above.<br>
&gt;<br>
<br>
</div></div><font color="#888888">--<br>
Best regards,<br>
Igor Stasenko AKA sig.<br>
</font><br><br>
<br></blockquote></div><br>