<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2017-03-14 16:56 GMT+01:00 Nicolai Hess <span dir="ltr"><<a target="_blank" href="mailto:nicolaihess@gmail.com">nicolaihess@gmail.com</a>></span>:<br><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2017-03-14 16:46 GMT+01:00 Eliot Miranda <span dir="ltr"><<a target="_blank" href="mailto:eliot.miranda@gmail.com">eliot.miranda@gmail.com</a>></span>:<br><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"> <br><div dir="ltr">Hi Esteban, Hi Igor, Hi All,<div class="gmail_extra"><br><div class="gmail_quote"><span class="gmail-">On Fri, Mar 10, 2017 at 7:35 AM, Esteban Lorenzano <span dir="ltr"><<a target="_blank" href="mailto:estebanlm@gmail.com">estebanlm@gmail.com</a>></span> wrote:<br></span><span class="gmail-"><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><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></span><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 target="_blank" href="mailto:eliot.miranda@gmail.com">eliot.miranda@gmail.c<wbr>om</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 style="white-space:pre-wrap" class="gmail-m_4258734833277413431m_2274790238541311056gmail-Apple-tab-span">             </span>withPinnedFormsDo: aBlock</div><div><span style="white-space:pre-wrap" class="gmail-m_4258734833277413431m_2274790238541311056gmail-Apple-tab-span">                 </span><inline: #always></div><div><span style="white-space:pre-wrap" class="gmail-m_4258734833277413431m_2274790238541311056gmail-Apple-tab-span">                   </span>self cppIf: SPURVM & false</div><div><span style="white-space:pre-wrap" class="gmail-m_4258734833277413431m_2274790238541311056gmail-Apple-tab-span">                            </span>ifTrue:</div><div><span style="white-space:pre-wrap" class="gmail-m_4258734833277413431m_2274790238541311056gmail-Apple-tab-span">                                   </span>[| bitBltOopWasPinned destWasPinned sourceWasPinned halftoneWasPinned |</div><div><span style="white-space:pre-wrap" class="gmail-m_4258734833277413431m_2274790238541311056gmail-Apple-tab-span">                                   </span> (bitBltOopWasPinned := interpreterProxy isPinned: bitBltOop) ifFalse:</div><div><span style="white-space:pre-wrap" class="gmail-m_4258734833277413431m_2274790238541311056gmail-Apple-tab-span">                                          </span>[bitBltOop := interpreterProxy pinObject: bitBltOop].</div><div><span style="white-space:pre-wrap" class="gmail-m_4258734833277413431m_2274790238541311056gmail-Apple-tab-span">                                   </span> (destWasPinned := interpreterProxy isPinned: destForm) ifFalse:</div><div><span style="white-space:pre-wrap" class="gmail-m_4258734833277413431m_2274790238541311056gmail-Apple-tab-span">                                          </span>[destForm := interpreterProxy pinObject: destForm].</div><div><span style="white-space:pre-wrap" class="gmail-m_4258734833277413431m_2274790238541311056gmail-Apple-tab-span">                                       </span> (sourceWasPinned := interpreterProxy isPinned: sourceForm) ifFalse:</div><div><span style="white-space:pre-wrap" class="gmail-m_4258734833277413431m_2274790238541311056gmail-Apple-tab-span">                                              </span>[sourceForm := interpreterProxy pinObject: sourceForm].</div><div><span style="white-space:pre-wrap" class="gmail-m_4258734833277413431m_2274790238541311056gmail-Apple-tab-span">                                   </span> (halftoneWasPinned := interpreterProxy isPinned: halftoneForm) ifFalse:</div><div><span style="white-space:pre-wrap" class="gmail-m_4258734833277413431m_2274790238541311056gmail-Apple-tab-span">                                          </span>[halftoneForm := interpreterProxy pinObject: halftoneForm].</div><div><span style="white-space:pre-wrap" class="gmail-m_4258734833277413431m_2274790238541311056gmail-Apple-tab-span">                                       </span> aBlock value.</div><span style="white-space:pre-wrap" class="gmail-m_4258734833277413431m_2274790238541311056gmail-Apple-tab-span">                                       </span> bitBltOopWasPinned ifFalse: [interpreterProxy unpinObject: bitBltOop].<div><span style="white-space:pre-wrap" class="gmail-m_4258734833277413431m_2274790238541311056gmail-Apple-tab-span">                                    </span> destWasPinned ifFalse: [interpreterProxy unpinObject: destForm].</div><div><span style="white-space:pre-wrap" class="gmail-m_4258734833277413431m_2274790238541311056gmail-Apple-tab-span">                                 </span> sourceWasPinned ifFalse: [interpreterProxy unpinObject: sourceForm].</div><div><span style="white-space:pre-wrap" class="gmail-m_4258734833277413431m_2274790238541311056gmail-Apple-tab-span">                                     </span> halftoneWasPinned ifFalse: [interpreterProxy unpinObject: halftoneForm]]</div><div><span style="white-space:pre-wrap" class="gmail-m_4258734833277413431m_2274790238541311056gmail-Apple-tab-span">                         </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></div></div></div></blockquote><div><br></div><div>Wouldn't it be possible to just pause the GC (scavange) when entering a primitive ?<br></div></div></div></div></blockquote><div><br>Wouldn't it be possible to just *disable* the GC (scavange) when entering a primitive ?<br> </div><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div><br> </div><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><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><div class="gmail-h5"><div><br></div><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote">
<br>
Here is the easiest way to reproduce it (in mac):<br>
<br>
wget <a target="_blank" rel="noreferrer" href="http://files.pharo.org/get-files/60/pharo64-mac-latest.zip">files.pharo.org/get-files/60/p<wbr>haro64-mac-latest.zip</a><br>
wget <a target="_blank" rel="noreferrer" href="http://files.pharo.org/get-files/60/pharo64.zip">files.pharo.org/get-files/60/p<wbr>haro64.zip</a><br>
wget <a target="_blank" rel="noreferrer" href="http://files.pharo.org/get-files/60/sources.zip">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_4258734833277413431m_2274790238541311056gmail-m_-1598783338454182085gmail-m_1311796669999849906HOEnZb"><font color="#888888">Esteban</font></span></blockquote></div></div></div><br><br clear="all"><span class="gmail-HOEnZb"><font color="#888888"><div><br></div>-- <br><div class="gmail-m_4258734833277413431m_2274790238541311056gmail-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>
</font></span></div></div><span class="gmail-HOEnZb"><font color="#888888">
<br></font></span></blockquote></div><br></div></div>
</blockquote></div><br></div></div>