<div dir="ltr">Hi again,<div><br></div><div>answers inlined again.<br><br><div class="gmail_quote"><div dir="ltr">On Wed, Oct 10, 2018 at 11:45 AM 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"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">well, I have the same problem but with the message #lengthOf:, but now the behavior is weird.</div><div>If I have the following code, everything works fine:</div><div><div>typesSize := (objectMemory lengthOf: types) - 1.</div></div><div><br></div><div>If I remove the - 1, like this:</div><div><div>typesSize := objectMemory lengthOf: types.</div></div><div><br></div><div>I get redefinition of labels errors:</div><div><div>../../spurstack64src/vm/gcc3x-interp.c:4879:2: error: redefinition of label 'l46'</div><div>        l46:    /* end lengthOf:format: */;</div><div>        ^</div><div>../../spurstack64src/vm/gcc3x-interp.c:4693:2: note: previous definition is here</div><div>        l46:    /* end lengthOf:format: */;</div><div>        ^</div><div><br></div><div>The thing is that in the first case #lengthOf: is not inlined but in the second it is and it looks like that the label is not regenerated every time it gets inlined.<br></div></div><div> Is there a well know workaround for this? I mean, I could do:</div><div><div><div>typesSize := (objectMemory lengthOf: types) - 0.</div></div></div></div></div></div></div></blockquote><div><br></div><div>Looks like a bug in the slang inliner. The Slang to C compiler is able to compile the VM, and that's it, so if you do anything that's not already used, it basically has undefined behavior (may or may not work). That's probably known and it would be better if Eliot answers about that.</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"><div> </div><div> and it will compile but that is not the point.</div><div> Also, why in the first case the code generator decides not to inline #lengthOf: but it does in the second case?</div><div><br></div></div></div></div></div></blockquote><div>There's two inlining strategies. On the JIT side it's explicit, so inline: true will inline, anything else is not inlined. The key aspect there is to inline non C compatible code (closures, alloca interactions). On the interpreter side it's heuristic based. It's quite tricky because you want to control carefully what is inlined in the main interpreter loop & on performance critical functions, while keeping enough information for profiling. You can fine-tune the heuristics with inline: false/true. You can look into the details in the CCodeGenerator class. Then there are the work-arounds, for instance since linking time optimizations are not enabled, quick calls across files are typically defined as macros to be inlined. Again, it would be better if Eliot answers about that, he has better knowledge on this.</div><div><br></div><div><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"><div></div><div>Thanks!</div><div>Hernan.</div><div><br></div><div><br></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Oct 9, 2018 at 8:40 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"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hi,<div> I got compile errors when setting <inline: true> in a method I created.</div><div> The errors where a label redefinition such as:</div><div><div>../../spurstack64src/vm/gcc3x-interp.c:4790:2: error: redefinition of label 'l35'</div><div>        l35:    /* end classAtIndex: */;</div><div>        ^</div><div>../../spurstack64src/vm/gcc3x-interp.c:4634:2: note: previous definition is here</div><div>        l35:    /* end classAtIndex: */;</div><div>        ^</div><div><br></div><div> After some research I concluded that the problem was at SpurMemoryManager>>#classAtIndex: due to how it returns:</div><div>...</div><div><div><span style="white-space:pre-wrap">     </span>classTablePage = nilObj ifTrue:</div><div><span style="white-space:pre-wrap">          </span>[^nil].</div><div><span style="white-space:pre-wrap">  </span>^self</div><div><span style="white-space:pre-wrap">            </span>fetchPointer: (classIndex bitAnd: self classTableMinorIndexMask)</div><div><span style="white-space:pre-wrap">         </span>ofObject: classTablePage</div></div><div><br></div><div> I think the source code generator does not support correctly returning at different points when inlining the same method more than once. </div><div> So I changed that implementation to:</div><div>...</div><div><div><span style="white-space:pre-wrap">       </span>^classTablePage = nilObj </div><div><span style="white-space:pre-wrap">               </span>ifTrue: [nil]</div><div><span style="white-space:pre-wrap">            </span>ifFalse: [ self</div><div><span style="white-space:pre-wrap">                  </span>fetchPointer: (classIndex bitAnd: self classTableMinorIndexMask)</div><div><span style="white-space:pre-wrap">                 </span>ofObject: classTablePage ]</div></div><div><div><br></div></div><div> Doing so the compile errors were gone and the VM keeps working correctly.</div><div> Is this fix correct or does it have some performance hit I do not know?</div><div> Should I inform about this change with a PR? (Sorry about this question but I'm new to this vm stuff :-) )</div><div><br></div><div> Here is the complete code of the method:</div><div><div>classAtIndex: classIndex</div><div><span style="white-space:pre-wrap">      </span><api></div><div><span style="white-space:pre-wrap">      </span><inline: true></div><div><span style="white-space:pre-wrap">     </span>| classTablePage |</div><div><span style="white-space:pre-wrap">       </span>self assert: (classIndex >= 0 and: [classIndex <= self tagMask or: [classIndex >= self arrayClassIndexPun and: [classIndex <= self classIndexMask]]]).</div><div><span style="white-space:pre-wrap">       </span>classTablePage := self fetchPointer: classIndex >> self classTableMajorIndexShift</div><div><span style="white-space:pre-wrap">                                                  </span>ofObject: hiddenRootsObj.</div><div><span style="white-space:pre-wrap">        </span>^classTablePage = nilObj </div><div><span style="white-space:pre-wrap">               </span>ifTrue: [nil]</div><div><span style="white-space:pre-wrap">            </span>ifFalse: [ self</div><div><span style="white-space:pre-wrap">                  </span>fetchPointer: (classIndex bitAnd: self classTableMinorIndexMask)</div><div><span style="white-space:pre-wrap">                 </span>ofObject: classTablePage ]</div></div><div><br></div><div> Cheers!</div><div> Hernan.</div>-- <br><div dir="ltr" class="m_-8862943208804038376m_-1860032461183732376gmail_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></div></div></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="m_-8862943208804038376gmail_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></div></div>