On Tue, May 2, 2017 at 12:50 AM, Eliot Miranda <eliot.miranda@gmail.com> wrote:
 
Tim, John, Bert, et al,

    if you look at e.g. resizing code in the platforms/iOS code (in e.g. platforms/iOS//vm/OSX/sqSqueakOSXOpenGLView.m) the code accesses the display bits by looking up the display object installed via primitiveBeDisplay in the specialObjectsArray:

- (void) performDraw: (CGRect)rect {
    sqInt form = interpreterProxy->displayObject(); // Form

    CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
    CGContextSaveGState(context);

    int width = interpreterProxy->positive32BitValueOf(interpreterProxy->fetchPointerofObject(1, form));
    int height = interpreterProxy->positive32BitValueOf(interpreterProxy->fetchPointerofObject(2, form));
    sqInt formBits = interpreterProxy->fetchPointerofObject(0, form);   // bits
    void* bits = (void*)interpreterProxy->firstIndexableField(formBits); // bits
    int bitSize = interpreterProxy->byteSizeOf(formBits);
    int bytePerRow = 4*width;

This is really unsafe.  If it gets called while the VM is compacting, or doing a become, then potentially boom!

Storing the display in the specialObjectsArray stops it form being GCed, but it doesn't stop it moving around, and it doesn't stop a become altering the location of the objects surrounding it, etc.

Surely a better approach is to inform the VM of the location, depth and extent of the bits via some ioSetDisplayBits function and then cacheing those values somewhere in the VM.  Thoughts?

Wouldn't the display bits still be moved around during GC? Nothing the image can do about that.

You could cache the values in the beDisplay primitive, but I don't see how that would change anything.

The original VM was single-threaded so this was not an issue. Are you trying to make the GC concurrent? I bet there are many many places that would break ... Maybe you need to temporarily pin the involved objects?

- Bert -