[Vm-dev] BUG? A problem with callbacks that shows up in 64bits (but is on 32bits too)

Nicolai Hess nicolaihess at gmail.com
Wed Mar 15 13:37:49 UTC 2017


2017-03-15 14:23 GMT+01:00 Ben Coman <btc at openinworld.com>:

>
>
>
> On Tue, Mar 14, 2017 at 11:46 PM, Eliot Miranda <eliot.miranda at gmail.com>
> wrote:
>
>>
>> Hi Esteban, Hi Igor, Hi All,
>>
>> On Fri, Mar 10, 2017 at 7:35 AM, Esteban Lorenzano <estebanlm at gmail.com>
>> wrote:
>>
>>>
>>> Hi,
>>>
>>> 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.
>>>
>>> And problem is showing very easy on 64bits (while in 32bits it takes
>>> time and is more random).
>>>
>>
>>  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):
>>
>>
>> On Mon, Mar 13, 2017 at 9:11 PM, Eliot Miranda <eliot.miranda at gmail.com>
>>  wrote:
>>
>> 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.
>>
>> 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:
>>
>> 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]
>>
>> 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
>> withPinnedFormsDo: aBlock
>> <inline: #always>
>> self cppIf: SPURVM & false
>> ifTrue:
>> [| bitBltOopWasPinned destWasPinned sourceWasPinned halftoneWasPinned |
>>  (bitBltOopWasPinned := interpreterProxy isPinned: bitBltOop) ifFalse:
>> [bitBltOop := interpreterProxy pinObject: bitBltOop].
>> (destWasPinned := interpreterProxy isPinned: destForm) ifFalse:
>> [destForm := interpreterProxy pinObject: destForm].
>> (sourceWasPinned := interpreterProxy isPinned: sourceForm) ifFalse:
>> [sourceForm := interpreterProxy pinObject: sourceForm].
>> (halftoneWasPinned := interpreterProxy isPinned: halftoneForm) ifFalse:
>> [halftoneForm := interpreterProxy pinObject: halftoneForm].
>> aBlock value.
>>  bitBltOopWasPinned ifFalse: [interpreterProxy unpinObject: bitBltOop].
>> destWasPinned ifFalse: [interpreterProxy unpinObject: destForm].
>> sourceWasPinned ifFalse: [interpreterProxy unpinObject: sourceForm].
>> halftoneWasPinned ifFalse: [interpreterProxy unpinObject: halftoneForm]]
>> ifFalse: [aBlock value]
>>    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]
>>
>> 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.
>>
>> d) ?
>>
>
> d) A question and idea in ignorance of Cario infrastructure...
> Do these surfaces persist in the Image after it is saved&quitted?
>

No


> Why not allocate surface memory on the C heap so that GC won't move it?
>

It is not the surface that moves. And the surface memory is on the heap,
that is why we need a surface plugin  to actually work with that data.
It is the Form-Object that moves. If the Forms instance variable "bits"
does not hold a (byte)array with pixeldata, but non-smalltalk integer
value, the BitBlt will access the image data
by calling the  surface plugin (cairo). The problem is, or the callgraph is:

primitive copy bits
-> get source form (ObjectPointer)
-> get dest form (ObjectPointer)
-> get form (image) format
   -> get bits-field (if integer -> call surfaceplugin for surface format
[1] / if object pointer -> get format from the Form-Object)
-> get image data
 -> get bits-field [2] (if integer -> call surfaceplugin for surface data
/ if object pointer -> get data from Form-Object)

The problem is, if [1] calls a callback that can trigger the GC, and the
object pointer and hence the bits-field for [2] is not valid anymore.






>
> cheers -ben
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20170315/8e9cd6e2/attachment-0001.html>


More information about the Vm-dev mailing list