[Pharo-project] About CompiledMethod category returning nil sometimes

Mariano Martinez Peck marianopeck at gmail.com
Tue May 10 10:35:03 EDT 2011


Hi Stef. From what I can see, the category can be nil only when
CompiledMethods are created for DoIts but not for regular CompiledMethods.
Even those which are under 'as yet unclassified'  answer that and not nil.

(CompiledMethod allInstances select: [ :each | (each category isNil and:
     [(each selector beginsWith: #DoIt) not]) ])  size

answers 0 in my image.

(CompiledMethod allInstances select: [ :each | each category isNil ]
thenCollect: [:each | each selector]) asSet
-->>  a Set(#DoIt #DoItIn:)

So...only those guys answers nil. Is that important?   If so, we already
have the message:

CompiledMethod >> isSelfEvaluating
    ^self methodClass notNil and: [(#(#DoIt #DoItIn: nil) includes: self
selector) not]

that answers false for those do its. Hence, we could patch  to something
like this:

CompiledMethod >> category
    self isSelfEvaluating ifFalse: [^ 'evaluating'].
    ^self methodClass organization categoryOfElement:self selector


There is another solution:  the CM to answers its category delegates to
"^self methodClass organization categoryOfElement:self selector"   for
do-its, the methodClass is always "UndefinedObject"

So.....I can create a category called "evaluation" in UndefinedObject and
put  these two new methods:

DoIt
    "When execution code from a workspace or similar places the Compiler
creates a dummy CompiledMethod whose methodClass is UndefinedObject. When
such CompiledMethods are ask its category, it answers nil, since the
selector is search in the organization of the methodClass, which in this
case is UndefinedObject.  Hence, implementing this mehtod here will make
such CompiledMethods to answer the category where this method is. "

DoItIn: nonImportant
    "When execution code from a workspace or similar places the Compiler
creates a dummy CompiledMethod whose methodClass is UndefinedObject. When
such CompiledMethods are ask its category, it answers nil, since the
selector is search in the organization of the methodClass, which in this
case is UndefinedObject.  Hence, implementing this mehtod here will make
such CompiledMethods to answer the category where this method is. "

So....now:

(CompiledMethod allInstances select: [ :each | each isSelfEvaluating not ]
thenCollect: [:each| each category ]) asSet
 --->a Set(#evaluation)


I am not sure which of the both solution is the best nor the impact of them,

Cheers

Mariano


On Mon, May 9, 2011 at 11:35 AM, Stéphane Ducasse <stephane.ducasse at inria.fr
> wrote:

> Hi guys
>
> With cyrille we experience sometimes CompiledMethod with nil category and
> this can break hard some problem.
> We were thinking but not sure that it would be good to make sure that nil
> is not returned but 'as yet unclassified'
> What do you think?
> Do you have any idea of potential problem?
>
> Stef
>



-- 
Mariano
http://marianopeck.wordpress.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-dev_lists.pharo.org/attachments/20110510/12794ff8/attachment.html>


More information about the Pharo-dev mailing list