<div dir="ltr">Hi Esteban, Hi Igor, Hi All,<div class="gmail_extra"><br><div class="gmail_quote">On Fri, Mar 10, 2017 at 7:35 AM, Esteban Lorenzano <span dir="ltr"><<a href="mailto:estebanlm@gmail.com" target="_blank">estebanlm@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br>
Hi,<br>
<br>
I’m tumbling into an error in Pharo, because we use callbacks intensively, in Athens(cairo)-to-World conversion in particular, and people is sending always their crash reports… we made the whole conversion a lot more robust since problems started to arise, but now I hit a wall I cannot solve: I think problem is in something in callbacks.<br>
<br>
And problem is showing very easy on 64bits (while in 32bits it takes time and is more random).<br></blockquote><div><br></div><div> I responded in the "image not opening" thread, but it's the same problem.  I really want to hear what y'all think because I'll happily implement a fix, but I want to know which one y'all think is a good idea.  Here's my reply (edits between [ & ] to add information):</div><div><br></div><div><br></div><div>On Mon, Mar 13, 2017 at 9:11 PM, Eliot Miranda <span dir="ltr"><<a href="mailto:eliot.miranda@gmail.com" target="_blank">eliot.miranda@gmail.com</a>></span> wrote:<br></div><div><br></div><div><div style="color:rgb(0,0,0);font-size:14px">I'm pretty confident [I know] this is to do with bugs in the Athens surface code which assumes that callbacks can be made in the existing copyBits and warpBits primitive.  They can't do this safely because a GC (scavenge) can happen during a callback, which then causes chaos when the copyBits primitive tries to access objects that have been moved under its feet.</div><div style="color:rgb(0,0,0);font-size:14px"><br></div><div style="color:rgb(0,0,0);font-size:14px">I've done work to fix callbacks so that when there is a failure it is the copyBits primitive that fails, instead of apparently the callback return primitive.  One of the apparent effects of this fix is to stop the screen opening up too small; another is getting the background colour right, and yet another is eliminating bogus pixels in the VGTigerDemo demo.  But more work is required to fix the copyBits and warpBits primitives.  There are a few approaches one might take:</div><div style="color:rgb(0,0,0);font-size:14px"><br></div><div style="color:rgb(0,0,0);font-size:14px">a)  fixing the primitive so that it saves and restores oops around the callbacks using the external oop table [InterpreterProxy>>addGCRoot: & removeGCRoot:].  That's a pain but possible. [It's a pain because all the derived pointers (the start of the destForm, sourceForm, halftoneForm and colorMapTable) must be recomputed also, and of course most of the time the objects don't move; we only scavenge about once every 2 seconds in normal running]</div><div style="color:rgb(0,0,0);font-size:14px"><br></div><div style="color:rgb(0,0,0);font-size:14px">b) fixing the primitive so that it pins the objects it needs before ever invoking a callback [this is a pain because pinning an object causes it to be tenured to old space if it is in new space; objects can't be pinned in new space, so instead the pin operation forwards the new space object to an old space copy if required and answers its location in old space, so a putative withPinnedObjectsDo: operation for the copyBits primitive looks like</div><div style="color:rgb(0,0,0);font-size:14px"><div><span class="gmail-Apple-tab-span" style="white-space:pre">          </span>withPinnedFormsDo: aBlock</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                      </span><inline: #always></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                        </span>self cppIf: SPURVM & false</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                         </span>ifTrue:</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                                        </span>[| bitBltOopWasPinned destWasPinned sourceWasPinned halftoneWasPinned |</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                                        </span> (bitBltOopWasPinned := interpreterProxy isPinned: bitBltOop) ifFalse:</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                                               </span>[bitBltOop := interpreterProxy pinObject: bitBltOop].</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                                        </span> (destWasPinned := interpreterProxy isPinned: destForm) ifFalse:</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                                               </span>[destForm := interpreterProxy pinObject: destForm].</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                                    </span> (sourceWasPinned := interpreterProxy isPinned: sourceForm) ifFalse:</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                                           </span>[sourceForm := interpreterProxy pinObject: sourceForm].</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                                        </span> (halftoneWasPinned := interpreterProxy isPinned: halftoneForm) ifFalse:</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                                               </span>[halftoneForm := interpreterProxy pinObject: halftoneForm].</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                                    </span> aBlock value.</div><span class="gmail-Apple-tab-span" style="white-space:pre">                                    </span> bitBltOopWasPinned ifFalse: [interpreterProxy unpinObject: bitBltOop].<div><span class="gmail-Apple-tab-span" style="white-space:pre">                                 </span> destWasPinned ifFalse: [interpreterProxy unpinObject: destForm].</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                                      </span> sourceWasPinned ifFalse: [interpreterProxy unpinObject: sourceForm].</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                                  </span> halftoneWasPinned ifFalse: [interpreterProxy unpinObject: halftoneForm]]</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                              </span>ifFalse: [aBlock value]</div><div>   and tenuring objects to old space is not ideal because they are only collected by a full GC, so doing this would at least tenure the bitBltOop which is very likely to be in new space]</div></div><div style="color:rgb(0,0,0);font-size:14px"><br></div><div style="color:rgb(0,0,0);font-size:14px">c) fixing the primitive so that it uses the scavenge and fullGC counters in the VM to detect if a GC occurred during one of the callbacks and would fail the primitive [if it detected that a GC had occurred in any of the surface functions].   The primitive would then simply be retried. </div><div style="color:rgb(0,0,0);font-size:14px"><br></div><div style="color:rgb(0,0,0);font-size:14px">d) ?</div><div style="color:rgb(0,0,0);font-size:14px"><br></div><div style="color:rgb(0,0,0);font-size:14px">I like c) as it's very lightweight, but it has issues.  It is fine to use for callbacks *before* cop[yBits and warpBits move any bits (the lockSurface and querySurface functions).  But it's potentially erroneous after the unlockSurface primitive.  For example, a primitive which does an xor with the screen can't simply be retried as the first, falling pass, would have updated the destination bits but not displayed them via unlockSurface.  But I think it could be arranged that no objects are accessed after unlockSurface, which should naturally be the last call in the primitive (or do I mean showSurface?).  So the approach would be to check for GCs occurring during querySurface and lockSurface, failing if so, and then caching any and all state needed by unlockSurface and showSurface in local variables.  This way no object state is accessed to make the unlockSurface and showSurface calls, and no bits are moved before the queryDurface and lockSurface calls.</div><div style="color:rgb(0,0,0);font-size:14px"><br></div><div style="color:rgb(0,0,0);font-size:14px">If we used a failure code such as #'object may move' then the primitives could answer this when a GC during callbacks is detected and then the primitive could be retried only when required.</div></div><div><br></div><div><br></div><div>[Come on folks, please comment.  I want to know which idea you like best.  We could fix this quickly.  But right now it feels like I'm talking to myself.]</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
Here is the easiest way to reproduce it (in mac):<br>
<br>
wget <a href="http://files.pharo.org/get-files/60/pharo64-mac-latest.zip" rel="noreferrer" target="_blank">files.pharo.org/get-files/60/p<wbr>haro64-mac-latest.zip</a><br>
wget <a href="http://files.pharo.org/get-files/60/pharo64.zip" rel="noreferrer" target="_blank">files.pharo.org/get-files/60/p<wbr>haro64.zip</a><br>
wget <a href="http://files.pharo.org/get-files/60/sources.zip" rel="noreferrer" target="_blank">files.pharo.org/get-files/60/s<wbr>ources.zip</a><br>
unzip pharo64-mac-latest.zip<br>
unzip pharo64.zip<br>
unzip sources.zip<br>
./Pharo.app/Contents/MacOS/Pha<wbr>ro ./Pharo64-60438.image eval "VGTigerDemo runDemo"<br>
<br>
eventually (like 5-6 seconds after, if not immediately), you will have a stack like this:<br>
<br>
SmallInteger(Object)>>primitiv<wbr>eFailed:<br>
SmallInteger(Object)>>primitiv<wbr>eFailed<br>
SmallInteger(VMCallbackContext<wbr>64)>>primSignal:andReturnAs:fr<wbr>omContext:<br>
GrafPort>>copyBits<br>
GrafPort>>image:at:sourceRect:<wbr>rule:<br>
FormCanvas>>image:at:sourceRec<wbr>t:rule:<br>
FormCanvas(Canvas)>>drawImage:<wbr>at:sourceRect:<br>
FormCanvas(Canvas)>>drawImage:<wbr>at:<br>
VGTigerDemo>>runDemo<br>
VGTigerDemo class>>runDemo<br>
UndefinedObject>>DoIt<br>
OpalCompiler>>evaluate<br>
OpalCompiler(AbstractCompiler)<wbr>>>evaluate:<br>
[ result := Smalltalk compiler evaluate: aStream.<br>
self hasSessionChanged<br>
        ifFalse: [ self stdout<br>
                        print: result;<br>
                        lf ] ] in EvaluateCommandLineHandler>>ev<wbr>aluate: in Block: [ result := Smalltalk compiler evaluate: aStream....<br>
BlockClosure>>on:do:<br>
EvaluateCommandLineHandler>>ev<wbr>aluate:<br>
EvaluateCommandLineHandler>>ev<wbr>aluateArguments<br>
EvaluateCommandLineHandler>>ac<wbr>tivate<br>
EvaluateCommandLineHandler class(CommandLineHandler class)>>activateWith:<br>
[ aCommandLinehandler activateWith: commandLine ] in PharoCommandLineHandler(BasicC<wbr>ommandLineHandler)>>activateSu<wbr>bCommand: in Block: [ aCommandLinehandler activateWith: commandLine ]<br>
BlockClosure>>on:do:<br>
PharoCommandLineHandler(BasicC<wbr>ommandLineHandler)>>activateSu<wbr>bCommand:<br>
PharoCommandLineHandler(BasicC<wbr>ommandLineHandler)>>handleSubc<wbr>ommand<br>
PharoCommandLineHandler(BasicC<wbr>ommandLineHandler)>>handleArgu<wbr>ment:<br>
[ self<br>
        handleArgument:<br>
                (self arguments<br>
                        ifEmpty: [ '' ]<br>
                        ifNotEmpty: [ :arguments | arguments first ]) ] in PharoCommandLineHandler(BasicC<wbr>ommandLineHandler)>>activate in Block: [ self...<br>
BlockClosure>>on:do:<br>
PharoCommandLineHandler(BasicC<wbr>ommandLineHandler)>>activate<br>
PharoCommandLineHandler>>activ<wbr>ate<br>
PharoCommandLineHandler class(CommandLineHandler class)>>activateWith:<br>
[ super activateWith: aCommandLine ] in PharoCommandLineHandler class>>activateWith: in Block: [ super activateWith: aCommandLine ]<br>
<br>
Any idea?<br>
<br>
thanks!<br>
<span class="gmail-m_-1598783338454182085gmail-m_1311796669999849906HOEnZb"><font color="#888888">Esteban</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail-m_-1598783338454182085gmail-m_1311796669999849906gmail_signature"><div dir="ltr"><div><span style="font-size:small;border-collapse:separate"><div>_,,,^..^,,,_<br></div><div>best, Eliot</div></span></div></div></div>
</div></div>