<br><br><div class="gmail_quote">On Tue, Oct 5, 2010 at 12:00 PM, Mariano Martinez Peck <span dir="ltr">&lt;<a href="mailto:marianopeck@gmail.com">marianopeck@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;">
 <br><br><br><div class="gmail_quote">On Tue, Oct 5, 2010 at 8:48 PM, Eliot Miranda <span dir="ltr">&lt;<a href="mailto:eliot.miranda@gmail.com" target="_blank">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, Oct 5, 2010 at 11:20 AM, 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><br><br><div class="gmail_quote">On Tue, Oct 5, 2010 at 7:50 PM, Eliot Miranda <span dir="ltr">&lt;<a href="mailto:eliot.miranda@gmail.com" target="_blank">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, Oct 5, 2010 at 9:23 AM, 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. So....if I want to intercept ALL message sends....going to #normalSend is not enough since I have #class, #==, Float&gt;&gt;#+   etc that are executed directly like bytecodes. So...my questions are now:<br><br>1) Those special selectors are those that are in &quot;Smalltalk specialSelectors&quot; ?  are there more?  all from there are special?<br>





<br>2) All those &quot;Smalltalk specialSelectors&quot;  have their associated bytecode primitive in Interpreter??  If true, then I should modify all bytecodePrim*  in Interpreter. I am right?   If I do that, that&#39;s all ? I am intercepting everything?<br>




</blockquote><div><br></div><div>Right.  Just modify all of them to eliminate the optimized code and to revert to normalSend.  </div></div></blockquote><div><br>Thanks Eliot. I didn&#39;t understand. What is the optimized code?   I checked all bytecodePrim* and the ones that DO NOT send &quot;self normalSend&quot; at the end, are very few. The problem is that some return before returning &quot;self normalSend&quot;. So...I should modify all those who DO NOT call &quot;self normalSend&quot; at the end and those which return before. <br>


</div></div></blockquote><div><br></div><div>Change them all so they do a normalSend and nothing else, e.g.</div><div><br></div><div>bytecodePrimAdd</div><div><span style="white-space:pre-wrap">        </span>messageSelector := self specialSelector: 0.</div>


<div><span style="white-space:pre-wrap">        </span>argumentCount := 1.</div><div><span style="white-space:pre-wrap">        </span>self normalSend</div><div><br></div></div></blockquote><div><br>Ok, but suppose I DON&#39;T want to slow down the system.... what if I change to this for example<br>

<br>bytecodePrimAdd<br>    | rcvr arg result |<br>    rcvr := self internalStackValue: 1.<br>    arg := self internalStackValue: 0.<br>    (self areIntegers: rcvr and: arg)<br>        ifTrue: [result := (self integerValueOf: rcvr) + (self integerValueOf: arg).<br>

                (self isIntegerValue: result) ifTrue:<br>                    [self internalPop: 2 thenPush: (self integerObjectOf: result).<br>                    <span style="background-color:rgb(255, 0, 0)">self markObjectUsage: rcvr.</span><br>

                    ^ self fetchNextBytecode &quot;success&quot;]]<br>        ifFalse: [successFlag := true.<br>                self externalizeIPandSP.<br>                self primitiveFloatAdd: rcvr toArg: arg.<br>                self internalizeIPandSP.<br>

                successFlag ifTrue: [<span style="background-color:rgb(255, 0, 0)">self markObjectUsage: 
rcvr.</span> ^ self fetchNextBytecode &quot;success&quot;]].<br><br>    messageSelector := self specialSelector: 0.<br>    argumentCount := 1.<br>    self normalSend<br><br>Ok...I have to manually check each method, but I don&#39;t have problem.<br>

<br>Should that work and be almost as fast as normally?<br></div></div></blockquote><div><br></div><div>But it doesn&#39;t mark the method right?  It only marks the objects.  However if you analyse the bytecodePrimFoo implementations you should be able to work out which methods are used, SmallInteger&gt;&gt;#+, Float&gt;&gt;#+ et al.</div>
<div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="gmail_quote"><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>Or change the part of the bytecode table that specifies the special selector primitives to read</div>
<div><div><span style="white-space:pre-wrap">                </span>(176 207 sendSpecialSelectorBytecode)</div><div><br></div><div><div>sendSpecialSelectorBytecode</div><div><span style="white-space:pre-wrap">        </span>| selectorIndex specialSelectors |</div>


<div><span style="white-space:pre-wrap">        </span>selectorIndex := (currentBytecode - 176) * 2.</div><div><span style="white-space:pre-wrap">        </span>specialSelectors := self splObj: SpecialSelectors.</div>
<div><span style="white-space:pre-wrap">        </span>messageSelector := self fetchPointer: selectorIndex</div><div><span style="white-space:pre-wrap">                                                        </span>ofObject: specialSelectors.</div>
<div><span style="white-space:pre-wrap">        </span>argumentCount := self fetchInteger: selectorIndex + 1</div><div><span style="white-space:pre-wrap">                                                        </span>ofObject: specialSelectors.</div>
<div><span style="white-space:pre-wrap">        </span>self normalSend</div></div><div><br></div><div>But most of all try and slow down and understand what is going on; then you will be able to answer your own questions.  Reading the <a href="http://www.mirandabanda.org/bluebook/bluebook_imp_toc.html" target="_blank">blue book</a> will help.</div>


</div><div> </div></div></blockquote><div><br>hehehehehe what an idea :) I didn&#39;t know I could do that. Thanks for the blue book. I read the vm chapters but several months ago. I should read it again since the first time I didn&#39;t understand very much hehehehe. <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"><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>
<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>Providing you also look at the perform and method evaluation primitives I think you&#39;ll get all sends. </div>




<div><br></div></div></blockquote><div><br>#primitivePerform*   and #primitiveExecuteMethod*    ???<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>There is another way.  Modify the Smalltalk compiler to to use the special selector sends.</div><div><br></div></div></blockquote><div><br>Thanks Eliot for the idea. Can you explain me a little more (sorry, newbie here!). You mean that with the Compiler I can do that all method sends use the normal send instead of special bytecodes or primitives?<br>


</div></div></blockquote><div><br></div><div>Yes.  If you modify the compiler not to use the StdSelectors then the compiler will emit normal sends for all the special selectors.   Again I think if you slowed down and started playing ore you would discover this for yourself and in the end be more productive.  I know its hard and frustrating initially.  But my own competence comes directly from having played around in this way.</div>


<div><br></div></div></blockquote><div><br>Thanks Eliot. I will consider this alternative also.<br><br>Best regards.<br><br>Mariano<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>best,</div><div>Eliot</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"><div class="gmail_quote">

<div>
<br>Thank you very much.<br><br>Mariano<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><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex">





<br>Thanks a lot in advance,<br><br>Mariano<br><br><br><br><div class="gmail_quote">On Sun, Oct 3, 2010 at 11:09 PM, Craig Latta <span dir="ltr">&lt;<a href="mailto:craig@netjam.org" target="_blank">craig@netjam.org</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>
&gt; Craig Latta has done all this work, talk to him.<br>
<br>
     Sure, I&#39;d be happy to discuss it.<br>
<br>
<br>
-C<br>
<font color="#888888"><br>
--<br>
Craig Latta<br>
<a href="http://www.netjam.org" target="_blank">www.netjam.org</a><br>
+ 31 020 894 6247<br>
+  1 415 287 3547<br>
<br>
<br>
<br>
</font></blockquote></div><br>
<br></blockquote></div><br>
<br></blockquote></div><br>
<br></blockquote></div><br>
<br></blockquote></div><br>
<br></blockquote></div><br>