<div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Apr 27, 2012 at 11:28 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <br><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Apr 27, 2012 at 8:01 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <br><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Apr 27, 2012 at 10:51 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <br><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Apr 27, 2012 at 7:34 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <br><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Apr 27, 2012 at 1:33 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <br><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Apr 27, 2012 at 2:00 AM, 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <br><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Apr 26, 2012 at 3:26 PM, 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <br><div class="gmail_extra"><br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">






<div class="gmail_extra"><div><div><br><div class="gmail_quote">
On Thu, Apr 26, 2012 at 10:42 PM, 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Eliot. We are doing a crazy experiment where we serialize almost all PharoCore and we materialize it in a PharoKernel image. During the initialization (after the load), there is one line that crashes Cog:<br>








<br>PolymorphSystemSettings showDesktopLogo: true.<br>
<br></blockquote></div></div></div></div></blockquote><div> </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_extra"><div><div>







<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">For what I can see, I may be related to the fact that #pharoLogoContents is too long or something like that?<br>







</blockquote></div></div></div></div></blockquote><div><br>hehehe now I remember we are putting the source code in the method trailer. And #pharoLogoContents is too much I guess:<br><br>
(PolymorphSystemSettings class &gt;&gt; #pharoLogoContents)  trailer size  -&gt;  49726<br>
<br>so..is this a known limitation?<br></div></div></div></blockquote><div><br></div><div>It&#39;s been invisible until now :)</div><div><br></div><div><br></div><div><span style="border-collapse:collapse;font-family:arial,sans-serif;font-size:13px"><div>






<br></div><div>Ah!  I see.  The JIT compilation process in Cog goes as follows (see Cogit&gt;compileCogMethod:).  Guess the endPC of the method based on its byte size.  Stack allocate space for compilation based on this.  Make an initial pass over the bytecode to a) initialize fixups for the targets of backward jumps, b) count how many blocks the method contains, and c) determine the method&#39;s real endPC.  Fixups are used to generate code for branches; they point from the target instruction back to the jump(s) to this instruction.  Since we scan forward we can create the fixups for forward branches when we encounter the branch.  But backward jumps have to be done up front.</div>






<div><br></div><div>So there&#39;s a chicken-and-egg problem.  The JIT either needs to guess how many fixups it needs before it scans, or it needs to make an extra scan of the bytecocde to determine the actual endPC before it scans to initialize fixups.  I hate to add an extra pass unnecessarily.  So is there a simple criterion the JIT can use to know whether it has to make an extra pass? </div>






<div><br></div></span></div></div></div></blockquote><div><br>Hi Eliot. We thought about different possibilities but I think the easier is to just modify #methodWithHeaderShouldBeCogged: to reject methods &quot;too long&quot;. So apart from checking the number of literals you can also check the total amount of bytes and be sure to be less that the amount that causes the crash in allocateOpcodesbytecodes. ?<br>





<br>Another possibility is to add a word to CompiledMethod header that stores the endPC, so there is not need to guess. But we will need some image-changes and break comptatbilty. <br></div></div></div></blockquote><div>




<br></div><div>I think the right thing to do if for the JIT to do a scan to determine the actual end pc</div></div></div></blockquote><div><br>but how do you determinate the end pc ?<br></div></div></div></blockquote><div>


<br></div><div>Scan the bytecodes.  See Cogit&gt;scanMethod.</div><div> </div></div></div></blockquote><div><br><br>Hi Eliot. It seems I am still far away from understanding scanMethod. I cannot figure out how you get the endPC. I see you only set it in this part:<br>

(descriptor isReturn<br>         and: [pc &gt;= latestContinuation]) ifTrue:<br>            [endPC := pc].<br><br>anyway, I trust you :)<br></div></div></div></blockquote><div><br></div><div>The first return beyond the furthest continuation is the end of the method.  The furthest continuation is the furthest forward we&#39;ve seen a branch.  If we see a return beyond all branches that return must be the end of the method.</div>
<div><br></div><div>e.g.</div><div>    expr ifTrue: [^foo] ifFalse: [self bar]. ^self</div><div><br></div><div>the first ^foo is not the end of the method because there&#39;s a branch around it from the expr test to the start of [self bar].  But the last ^self is the end because there&#39;s no branch past it.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_extra"><div class="gmail_quote"><div><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_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_extra"><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_extra"><div class="gmail_quote"><div> if the method&#39;s byte codes are greater than some limit, e.g. 1024 bytes of bytecodes.  It then rejects the method if the actual end pc is greater than some limit that we find empirically causes the JIT to crash because of the size of the alloca.</div>




<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_extra"><div class="gmail_quote"><div><br>Cheers<br><br><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_extra"><div class="gmail_quote"><div><span style="border-collapse:collapse;font-family:arial,sans-serif;font-size:13px"><div></div></span></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div class="gmail_extra"><div class="gmail_quote"><div><br>thanks!<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_extra"><div><div>
<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">the same experiment with StackVM works fine.<br>Of course in a normal image (without this experiment) I can do PolymorphSystemSettings showDesktopLogo: true. without problems.<br clear="all">









<br><br>From gdb i see:<br><br>(gdb) bt<br>#0  0x0000a190 in compileCogMethod (selector=528828260) at /Users/mariano/Pharo/VM/git/cogVMBlessedSSH/blessed/build/../src/vm/cogit.c:<a href="tel:3601" value="+333601" target="_blank">3601</a><br>








#1  0x00009088 in cogselector (aMethodObj=531503072, aSelectorOop=528828260) at /Users/mariano/Pharo/VM/git/cogVMBlessedSSH/blessed/build/../src/vm/cogit.c:<a href="tel:3129" value="+333129" target="_blank">3129</a><br>
#2  0x0003268b in ceSendsupertonumArgs (selector=528828260, superNormalBar=0, rcvr=536158520, numArgs=0) at /Users/mariano/Pharo/VM/git/cogVMBlessedSSH/blessed/build/../src/vm/gcc3x-cointerpmt.c:11007<br>#3  0x1f40006c in ?? ()<br>









#4  0x00067350 in threadSchedulingLoop (vmThread=0x1030c00) at /Users/mariano/Pharo/VM/git/cogVMBlessedSSH/blessed/build/../src/vm/gcc3x-cointerpmt.c:44006<br>#5  0x0003d2cb in initialEnterSmalltalkExecutive () at /Users/mariano/Pharo/VM/git/cogVMBlessedSSH/blessed/build/../src/vm/gcc3x-cointerpmt.c:17788<br>









#6  0x0003df8f in initStackPagesAndInterpret () at /Users/mariano/Pharo/VM/git/cogVMBlessedSSH/blessed/build/../src/vm/gcc3x-cointerpmt.c:18208<br>#7  0x00022618 in interpret () at /Users/mariano/Pharo/VM/git/cogVMBlessedSSH/blessed/build/../src/vm/gcc3x-cointerpmt.c:2066<br>









#8  0x0006dc60 in -[sqSqueakMainApplication runSqueak] (self=0x1d0ca60, _cmd=0x124ebf) at /Users/mariano/Pharo/VM/git/cogVMBlessedSSH/blessed/build/../platforms/iOS/vm/Common/Classes/sqSqueakMainApplication.m:174<br>#9  0x93ad586c in __NSFirePerformWithOrder ()<br>









#10 0x908b8dd2 in __CFRunLoopDoObservers ()<br>#11 0x90874ced in __CFRunLoopRun ()<br>#12 0x908743c4 in CFRunLoopRunSpecific ()<br>#13 0x908741f1 in CFRunLoopRunInMode ()<br>#14 0x97760e04 in RunCurrentEventLoopInMode ()<br>









#15 0x97760af5 in ReceiveNextEventCommon ()<br>#16 0x97760a3e in BlockUntilNextEventMatchingListInMode ()<br>#17 0x96d1a595 in _DPSNextEvent ()<br>#18 0x96d19dd6 in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] ()<br>









#19 0x96cdc1f3 in -[NSApplication run] ()<br>#20 0x96cd4289 in NSApplicationMain ()<br>#21 0x0006b9f9 in main (argc=1, argv=0xbffff688, envp=0xbffff690) at /Users/mariano/Pharo/VM/git/cogVMBlessedSSH/blessed/build/../platforms/iOS/vm/Common/main.m:52<br>









<br><br>And the line that fails is:     allocateOpcodesbytecodes((numBytecodes + extra) * 10, numBytecodes);<br><br>numBytecodes is 49729 and extra is 10.<br><br>Any idea?<br><br>thanks!<span><font color="#888888"><br>
<br>-- <br>Mariano<br><a href="http://marianopeck.wordpress.com" target="_blank">http://marianopeck.wordpress.com</a><br>
<br>
</font></span></blockquote></div><br><br clear="all"><br></div></div><span><font color="#888888">-- <br>Mariano<br><a href="http://marianopeck.wordpress.com" target="_blank">http://marianopeck.wordpress.com</a><br>
<br>
</font></span></div>
</blockquote></div><br><br clear="all"><br>-- <br>Mariano<br><a href="http://marianopeck.wordpress.com" target="_blank">http://marianopeck.wordpress.com</a><br><br>
</div>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br>best,<div>Eliot</div><br>
</div>
<br></blockquote></div><br><br clear="all"><br>-- <br>Mariano<br><a href="http://marianopeck.wordpress.com" target="_blank">http://marianopeck.wordpress.com</a><br><br>
</div>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br>best,<div>Eliot</div><br>
</div>
<br></blockquote></div><br><br clear="all"><br>-- <br>Mariano<br><a href="http://marianopeck.wordpress.com" target="_blank">http://marianopeck.wordpress.com</a><br><br>
</div>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br>best,<div>Eliot</div><br>
</div>
<br></blockquote></div><br><br clear="all"><br>-- <br>Mariano<br><a href="http://marianopeck.wordpress.com" target="_blank">http://marianopeck.wordpress.com</a><br><br>
</div>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br>best,<div>Eliot</div><br>
</div>