[squeak-dev] [Bug & design issue] Messages understood or not understood by ProtoObject

Eliot Miranda eliot.miranda at gmail.com
Fri Feb 14 18:42:33 UTC 2020


Hi Christoph,

On Feb 14, 2020, at 9:51 AM, Thiede, Christoph <
Christoph.Thiede at student.hpi.uni-potsdam.de> wrote:



Hi Eliot,


> Or provide a vm flag which controls whether special selector #class (the
bytecode for sending #class) is inlined or not.  This flag can also control
#== & #~~.

Could you give me some (code) pointers about this inlining? :-)


This is something I first did in VW 3.0 so that people working with proxies
could avoid the inlining of #== & #class.  See primitive 537 in VW. The
blue book definition for special selector #class & special selector #== has
them inlined.  See pp 618 (640 in the online pdf) through 619 in the blue
book, and methods specialSelectorPrimitiveResponse and
commonSelectorPrimitiveResponse.  In the VM sources see bytecodePrimClass,
bytecodePrimIdentical et al
in initializeBytecodeTableForSqueakV3PlusClosures,
initializeBytecodeTableForSistaV1
and the implementations in StackInterpreter.

The other special selector send bytecodes either apply only to a specific
set of classes (e.g. arithmetic is inlined for any combination of
SmallInteger and float) or simply function as a space saver (1 byte for the
bytecode instead of 1 byte for the send bytecode plus 4 or 8 bytes for the
literal selector).  But #class, #== & #~~ are inlined.  They apply to any
and all objects.  This is how the system has been defined.  IMO it is a
mistake and no longer justified on performance grounds.  But t is the
reality on the ground.  And changing it will take some effort.

self systemNavigation browseAllSelect: [:m| (m selector beginsWith:
'bytecodePrim') and: [(m messages includes: #normalSend) not]] localTo:
StackInterpreter

(and in the Cogit see implementations of genSpecialSelectorEqualsEquals,
genSpecialSelectorClass, genSpecialSelectorNotEqualsEquals).

What I propose is adding a flag bit that persists in the image header,
queryable/settable via a vmParameterAt: that turns off this inlining, and
turns them into true sends.  I think we'll see slow downs in the 5% to 10%
range because of the cost of looking up #== (used heavily in ifNotNil: et
al) and we can reduce this by e.g. inlining for nil as a receiver and
having the bytecode compiler generate pushNil pushFoo send #== for ifNotNil
et al.

Note that Nicolas did something very similar recently to provide control
over mixed mode arithmetic.  He added the primitiveDoMixedArithmetic flag,
controlled by flag bit 6 in the VM primitive flags (vm parameter 48).
Something like noInlineCommonSelectors would be controlled by bit 7.


> There is a good solution to this.  Low-level Inspectors *should not* use
instVarAt: et al.  Instead they should access object intervals via “the
mirror protocol”, see the methods in Context, #object:instVarAt:[put:]
#object:at:[put:] #objectClass:

I like and do agree to your vision for tidying up ProtoObject!
Maybe we could also consider some "MetaDecorator" that inherits from
ProtoObject and implements #class, #instVarAt: etc. for arbitrary targets?
This might simplify the access to the mirror protocol, and it would be a
bit more object-oriented:

(MetaDecorator on: aMorph) class "--> Morph"
(MetaDecorator on: aProxy) class "--> Proxy"
(MetaDecorator on: aProxy) instVarsInclude: 'target' "--> true"

Sounds good.


> Hopefully I’ve answered your questions and given you pointers.  I’m
interested in collaborating to make this a reality in the next major
release.

You did. I'm too.

Cool. Let's do it :-)  I'm of course busy until next week.  But come
Tuesday I should be able to have at it.


Best,
Christoph

------------------------------
*Von:* Squeak-dev <squeak-dev-bounces at lists.squeakfoundation.org> im
Auftrag von Eliot Miranda <eliot.miranda at gmail.com>
*Gesendet:* Freitag, 14. Februar 2020 18:27:14
*An:* The general-purpose Squeak developers list
*Betreff:* Re: [squeak-dev] [Bug & design issue] Messages understood or not
understood by ProtoObject

Hi Christoph,

On Feb 14, 2020, at 5:18 AM, Thiede, Christoph <
Christoph.Thiede at student.hpi.uni-potsdam.de> wrote:



Hi all! :-)

When we were fiddling around with some proxy implementations today, Marcel
and I discovered an interesting set of issues regarding ProtoObjects.

Let's start with a concrete bug:


*Code to reproduce <do it>:*

ProtoObject new class.


*Expected behavior:*

DNU exception, because #class is implemented on Object only.


*Actual behavior:*

Outputs ProtoObject.

Even stranger: If you debug the method instead and simulate the #class
send, you get a "simulated message class not understood" error.

If you subclass ProtoObject and override/forward #class, the results will
deviate based on whether you are debugging or executing the code.


*Some thoughts:*

There are two options: Either to implement #class on ProtoObject (by moving
the primitive definition up from Object), or to remove it from the
specialObjectsArray so that a send to #class is not compiled differently
than a send to any other regular message.


Or provide a vm flag which controls whether special selector #class (the
bytecode for sending #class) is inlined or not.  This flag can also control
#== & #~~.


This leads us to the rather general question: *What special messages should
an instance of ProtoObject understand?*


IMO *only* #doesNotUnderstand:

See below on the mirror protocol

We don't answer this question completely consistent at the moment: For
example, #instVarAt: is implemented on Object, but #instVarsInclude: is
implemented on ProtoObject. Again, it is a bit weird that the
implementation of #instVarsInclude: calls #class which is implemented on
Object only. And so it goes on:


   - #someObject is implemented on Object, but #nextObject is available
   in ProtoObject.
   - #withArgs:executeMethod: is implemented on ProtoObject, whereas
   #perform:withArguments: is on Object.
   - #ifNotNil: is implemented on ProtoObject; however, #ifNotNilDo: is
   implemented on Object. (btw: does the latter still have any raison
   d'être?)
   - #flag: exists on ProtoObject, and #yourself exists on Object only.
   Isn't #yourself rather a syntactical element we would like to behave
   exactly the same way for every possible message receiver? (btw: Is there a
   good reason not to speed up #yourself via specialObjectsArray)?
   - (I don't claim for completeness)


And just some other problems regarding to ProtoObject (just collecting them
here instead of forgetting them forever):

   - ObjectTracer is broken due to several reasons. Will fix this soon.
   - Inspectors cannot inspect ProtoObjects correctly (for example: Inspector
   openOn: (ObjectTracer on: Display)). This is because #instVarAt: is
   implemented on Object only so this message is forwarded.
   Maybe we should replace these critical calls from Inspector by something
   like #tryPrimitive:173withArgs:? But should we do so in Inspector or rather
   in a new subclass named ProtoInspector or similar? Hm, then we would need
   to implement #inspectorClass on ProtoObject, which is bad either ... We
   will keep investigating this issue.


There is a good solution to this.  Low-level Inspectors *should not* use
instVarAt: et al.  Instead they should access object intervals via “the
mirror protocol”, see the methods in Context, #object:instVarAt:[put:]
#object:at:[put:] #objectClass:

You see hacks everywhere (the xxxFoo messages in serialization) because we
don’t have a well-defined notion of what is in a proxy.  Having one that is
as minimal as possible is IMNERHO the clearest definition possible, and the
most minimal is just having a #doesNotUnderstand: that prevents recursive
does not understand vm exit and displays a stack trace without sending
further messages to the proxy (because it uses the mirror primitives).

Note that the mirror primitives are what the execution machinery in Context
use to ensure that bytecodes do what they are expected to do.  An I et car
access should *not* send instVarAt: to a proxy; it should access the inst
var of the proxy, etc.


However, the crucial question is: What special messages should an instance
of ProtoObject understand? On the one hand, the idea of ProtoObjects is to
work as total proxies with a maximum amount of forwarding potential, which
implies a minimum number of methods. On the other hand, certain aspects
such as accessing instvars or executing messages are really
identity-related. Looking forward to your comments :-)


Hopefully I’ve answered your questions and given you pointers.  I’m
interested in collaborating to make this a reality in the next major
release.


Best,
Christoph
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200214/fa62e8b2/attachment.html>


More information about the Squeak-dev mailing list