[squeak-dev] use of pointsTo: for includesSelector:

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Fri Oct 25 21:53:18 UTC 2013


Ouch! bad bug!
I don't know if we need the speed, but we need the correctness.

To add to weirdness, I tested that (Object canUnderstand: Object
methodDictionary size) is true, but I have (Object canUnderstand: Object
selectors size) answering false, because it has two non nil slot less than
the tally...



2013/10/25 Eliot Miranda <eliot.miranda at gmail.com>

> Hi All,
>
>     I just got a little burned.  I was searching through an Array of
> symbols and integers (it is the PrimitiveTable from the VM), wanting to
> filter-out methods with a with a certain pragma.  The code looks like:
>
> anArray doWithIndex:
> [:entry :index|
> (self whichClassIncludesSelector: entry) ifNotNil:
>  [:c| | m |
> m := c >> entry.
> (m pragmaAt: #option:) ifNotNil:
>  [:pragma|
> (initializationOptions at: (pragma arguments first) ifAbsent: [true])
> ifFalse:
>  [anArray at: index put: 0]]]]
>
> the error was a keyNotFound error for c >> entry.  Turns out entry was the
> integer 306, a code for a quick primitive that returns some inst var.  The
> question is why did (self whichClassIncludesSelector: entry) evaluate to
> other than nil given that 306 is /not/ a selector in any of the classes
> from self on up.  Well, it's MethodDictionary's use of pointsTo: that is at
> fault:
>
> MethodDictionary>>includesKey: aSymbol
> "This override assumes that pointsTo is a fast primitive"
>
>  aSymbol ifNil: [^ false].
> ^ self pointsTo: aSymbol
>
> ProtoObject>>pointsTo: anObject
> "This method returns true if self contains a pointer to anObject,
> and returns false otherwise"
>  <primitive: 132>
> 1 to: self class instSize do:
> [:i | (self instVarAt: i) == anObject ifTrue: [^ true]].
>  1 to: self basicSize do:
> [:i | (self basicAt: i) == anObject ifTrue: [^ true]].
>  ^ false
>
> Turns out that 306 was the tally of one of the method dictionaries along
> self's superclass chain.  This seems to be to be completely bogus.  Do we
> really need crude performance hacks like this any more?
> --
> best,
> Eliot
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20131025/b5a78baf/attachment-0001.htm


More information about the Squeak-dev mailing list