<div dir="ltr">Hi,<div><br></div><div>Not sure there is documentation specifically about that. I think the 2 sentences in the previous mail I wrote basically cover the whole idea, there are not really hidden tricks.</div><div><br></div><div>There's documentation about the context to stack mapping in the interpreter though which involves a lot of internal/external code, but it's a more complicated concept.</div><div><br></div><div>I think the general problem is that interpreters are very different from standard C programs and C compilers struggle really hard to produce good code for any interpreter that anyone writes. For good interpreter performance you need to write the exact good sequence of native instructions that execute each bytecode instruction. So people tend to write interpreters in their own abstract assembly (See V8's ignition, JSC LLInt or the openJDK assembly templates) to work around the C compiler. In OpenSmalltalkVM, it was decided to use C + GNU extension. GNU extensions allow to fix registers (IP/SP/FP) in the main interpreter loop. You can see the Gnuifier>>gnuify method in VMMaker which basically does the GNU transformation in the C code. That solves part of the problem. The StackInterpreter is between 0% and 20% slower than the OpenJDK interpreter on a wide range of benchmarks, so I'd say it's quite a good trick given the engineering power we have compared to the OpenJDK. Obviously the difference is higher in the JIT.</div><div><br></div><div>One of my dream is to rewrite the interpreter on top of Cog's back-end in a similar way that ignition is built on top of Turbofan backend in V8. That would allow us to boost interpreter performance but also to have quick interactions between the interpreter and jitted code allowing to use the interpreter more extensively for non frequently used code and that way we could share more code between the interpreter and the JIT. That would mean we won't really have those internal/external code. But there are so many things to do :-). </div><div><br></div><div>I'm glad I could help,</div><div><br></div><div>Best!</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Oct 9, 2018 at 1:47 PM Hernan Wilkinson <<a href="mailto:hernan.wilkinson@10pines.com">hernan.wilkinson@10pines.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <div dir="ltr">Thanks Clément! it worked perfectly!<div>I did not know about the externalize/internalize stuff, I saw them everywhere but I did not understand it :-)</div><div>I there documentation or something to read about those kind of things?</div><div><br></div><div>Thanks!</div><div>Hernan</div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Oct 8, 2018 at 4:12 PM Clément Béra <<a href="mailto:bera.clement@gmail.com" target="_blank">bera.clement@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <div dir="ltr"><div dir="ltr"><div dir="ltr">Hi,<div><br></div><div>I think the general idea is that only the methods inlined in interpret can use localSP/localFP which are mapped to registers but only in the interpret method to make the interpreter quicker. In the rest of the code you need to used framePointer/stackPointer. Getting out of inlining in the interpreter requires a call to a method such as externalizeFPandSP which moves from the registers the value to variables, and internalizeIPandSP does the other way around.</div><div><br></div><div>So in your case you need to see if for interpreter performance you want your code to be inlined if the main interpreter loop, if so, then use localSP, else, use stackPointer.</div><div><br></div><div>Hope this helps!</div><div><br></div><div>Best!</div><div><br></div></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Oct 8, 2018 at 8:51 PM Hernan Wilkinson <<a href="mailto:hernan.wilkinson@10pines.com" target="_blank">hernan.wilkinson@10pines.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hi,<div> In the implementation of the dynamically typed vm I'm doing (to give it a name) I need to get the parameters when a method gets activated.</div><div> To do it I implemented a not-inlined method that sends the message #internalStackValue: </div><div> The problem is that the code for that method is not generated. The method gets removed from the methods to generate code because it access "localSP" although not directly but due to inlining #internalStackValue:</div><div> </div><div> How should I access the arguments then? Why I can not use "localSP"?</div><div><br></div><div> The method source is:</div><div><div>keepArgumentTypes<br></div><div><br></div><div><span style="white-space:pre-wrap">  </span><inline: false></div><div><span style="white-space:pre-wrap">    </span></div><div><span style="white-space:pre-wrap"> </span>| additionalMethodState tempVarsTypes |</div><div><span style="white-space:pre-wrap">  </span></div><div><span style="white-space:pre-wrap"> </span>additionalMethodState := self additionalMethodStateOf: newMethod.</div><div><span style="white-space:pre-wrap">        </span>additionalMethodState = objectMemory nilObject ifTrue: [ ^self ].</div><div><span style="white-space:pre-wrap">        </span>tempVarsTypes := objectMemory followObjField: 2 ofObject: additionalMethodState.</div><div><span style="white-space:pre-wrap"> </span>tempVarsTypes = objectMemory nilObject ifTrue: [ ^self ].</div><div><span style="white-space:pre-wrap">        </span></div><div><span style="white-space:pre-wrap"> </span>0 to: argumentCount-1 do: [ :argIndex | </div><div><span style="white-space:pre-wrap">                </span>self keepTypeInformationIn: tempVarsTypes at: argIndex for: (self internalStackValue: argIndex) ].</div><div><span style="white-space:pre-wrap">       </span></div></div><div> I manage to solve the problem passing localSP as parameter and doing the following, but I should not be doing that:</div><div><div>keepArgumentTypes: sp</div><div><br></div><div><span style="white-space:pre-wrap"> </span><inline: false></div><div><span style="white-space:pre-wrap">    </span></div><div><span style="white-space:pre-wrap"> </span>| additionalMethodState tempVarsTypes |</div><div><span style="white-space:pre-wrap">  </span></div><div><span style="white-space:pre-wrap"> </span>additionalMethodState := self additionalMethodStateOf: newMethod.</div><div><span style="white-space:pre-wrap">        </span>additionalMethodState = objectMemory nilObject ifTrue: [ ^self ].</div><div><span style="white-space:pre-wrap">        </span>tempVarsTypes := objectMemory followObjField: 2 ofObject: additionalMethodState.</div><div><span style="white-space:pre-wrap"> </span>tempVarsTypes = objectMemory nilObject ifTrue: [ ^self ].</div><div><span style="white-space:pre-wrap">        </span></div><div><span style="white-space:pre-wrap"> </span>0 to: argumentCount-1 do: [ :argIndex | </div><div><span style="white-space:pre-wrap">                </span>self keepTypeInformationIn: tempVarsTypes at: argIndex for: (stackPages longAtPointer: sp + (argIndex * objectMemory bytesPerOop)) ].</div><div><span style="white-space:pre-wrap">    </span></div></div><div><div><br></div>-- <br><div dir="ltr" class="m_586528549339795315m_-5616300412049136969m_5624783209409155131gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div><span style="font-family:tahoma,sans-serif;font-size:xx-small;border-collapse:collapse"><strong><span style="font-size:8pt"><span><span style="font-size:small"><font size="2"><span style="font-weight:normal"><span style="font-weight:bold">Hernán Wilkinson</span><br>Agile Software Development, Teaching & Coaching</span></font></span></span></span></strong></span></div><div><span style="font-family:tahoma,sans-serif;font-size:xx-small;border-collapse:collapse"><strong><span style="font-size:8pt"><span><span style="font-size:small"><font size="2"><span style="font-weight:normal">Phone: +54-011</span></font></span></span></span></strong></span><font face="tahoma, sans-serif" size="2">-4893-2057</font></div><div><strong style="font-family:tahoma,sans-serif;font-size:xx-small"><span style="font-size:8pt"><span style="font-size:small"><font size="2"><span style="font-weight:normal">Twitter: @HernanWilkinson</span></font></span></span></strong></div><div><span style="font-family:tahoma,sans-serif;font-size:xx-small;border-collapse:collapse"><strong><span style="font-size:8pt"><span><span style="font-size:small"><font size="2"><span style="font-weight:normal">site: <a href="http://www.10pines.com/" style="color:rgb(17,65,112)" target="_blank">http://www.10Pines.com</a></span></font></span></span></span></strong></span></div><div><font face="tahoma, sans-serif"><span style="border-collapse:collapse">Address: Alem 896</span></font>, Floor 6, Buenos Aires, Argentina</div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="m_586528549339795315m_-5616300412049136969gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><span style="font-size:12.8px">Clément Béra<br></span><span style="color:rgb(0,0,238)"><a href="https://clementbera.github.io/" target="_blank">https://clementbera.github.io/</a></span><div style="font-size:12.8px"><a href="https://clementbera.wordpress.com/" target="_blank">https://clementbera.wordpress.com/</a></div></div></div></div></div></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="m_586528549339795315gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div><span style="font-family:tahoma,sans-serif;font-size:xx-small;border-collapse:collapse"><strong><span style="font-size:8pt"><span><span style="font-size:small"><font size="2"><span style="font-weight:normal"><span style="font-weight:bold">Hernán Wilkinson</span><br>Agile Software Development, Teaching & Coaching</span></font></span></span></span></strong></span></div><div><span style="font-family:tahoma,sans-serif;font-size:xx-small;border-collapse:collapse"><strong><span style="font-size:8pt"><span><span style="font-size:small"><font size="2"><span style="font-weight:normal">Phone: +54-011</span></font></span></span></span></strong></span><font face="tahoma, sans-serif" size="2">-4893-2057</font></div><div><strong style="font-family:tahoma,sans-serif;font-size:xx-small"><span style="font-size:8pt"><span style="font-size:small"><font size="2"><span style="font-weight:normal">Twitter: @HernanWilkinson</span></font></span></span></strong></div><div><span style="font-family:tahoma,sans-serif;font-size:xx-small;border-collapse:collapse"><strong><span style="font-size:8pt"><span><span style="font-size:small"><font size="2"><span style="font-weight:normal">site: <a href="http://www.10pines.com/" style="color:rgb(17,65,112)" target="_blank">http://www.10Pines.com</a></span></font></span></span></span></strong></span></div><div><font face="tahoma, sans-serif"><span style="border-collapse:collapse">Address: Alem 896</span></font>, Floor 6, Buenos Aires, Argentina</div></div></div></div></div></div></div></div></div></div></div></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><span style="font-size:12.8px">Clément Béra<br></span><span style="color:rgb(0,0,238)"><a href="https://clementbera.github.io/" target="_blank">https://clementbera.github.io/</a></span><div style="font-size:12.8px"><a href="https://clementbera.wordpress.com/" target="_blank">https://clementbera.wordpress.com/</a></div></div></div></div></div></div>