[Pharo-project] Little change for Objects As Methods

Mariano Martinez Peck marianopeck at gmail.com
Tue Oct 19 07:33:12 EDT 2010


On Tue, Oct 19, 2010 at 1:25 PM, Fernando olivero
<fernando.olivero at usi.ch>wrote:

> Just by curiosity, why does MethodDictionary>>at:put: has to send
> #flushCache at all?
>

I am not sure, but I guess that cleaning.

The method comment of CompiledMethod >> flushChache says:

"Tell the interpreter to remove all references to this method from its
method lookup cache, if it has one.  This primitive must be called whenever
a method is defined or removed"

So...when you do a aClass methodDict at: #xxx  put: aNewCompiledMethod

nobody else "would"  (Sometimes I think there are MCMethodDefinition
instances pointing to methods that were even replaced by another ones) point
to the original compiled method, at least no here. Thus....the vm cleans the
cache for the method lookup.


cheers

mariano


>
> Fernando
>
> On Oct 19, 2010, at 1:14 PM, Stéphane Ducasse wrote:
>
> > Hi mariano
> >
> > I do not really like your solution. Implementing flushCache is not that
> bad in your class. It is not a bad compromise.
> > May be it should be better documented.
> >
> > Stef
> >
> >
> >> When you are using Objects as methods, MethodWrappers, or whatever with
> run:with:in, you have to implement not only  that method, but also
> flushCache doing nothing because it is used in:
> >>
> >> MethodDictionary >> at: put:
> >>
> >> at: key put: value
> >>    "Set the value at key to be value."
> >>    | index |
> >>    index := self findElementOrNil: key.
> >>    (self basicAt: index) == nil
> >>        ifTrue:
> >>            [tally := tally + 1.
> >>            self basicAt: index put: key]
> >>        ifFalse:
> >>            [(array at: index) flushCache].
> >>    array at: index put: value.
> >>    self fullCheck.
> >>    ^ value
> >>
> >>
> >> Ok, I can implement that in my classes, and in MethodWrappers, but I
> think it would be nicer and cleanly if you only have to implement
> run:with:in:  since flushChache doesn't make sense for normal objects.
> >>
> >> So, I would like to change that code to
> >>
> >> at: key put: value
> >>    "Set the value at key to be value."
> >>    | index |
> >>    index := self findElementOrNil: key.
> >>    (self basicAt: index) == nil
> >>        ifTrue:
> >>            [tally := tally + 1.
> >>            self basicAt: index put: key]
> >>        ifFalse:
> >>            [(array at: index) isCompiledMethod ifTrue: [flushCache]].
> >>    array at: index put: value.
> >>    self fullCheck.
> >>    ^ value
> >>
> >>
> >> Yes, yes, I know the if is ugly, but it gives us a cleaner way to define
> objects as methods.
> >> The other option is to implement flushCache in Object doing nothing but
> I like it less than this.
> >>
> >> opinions?
> >>
> >> thanks
> >>
> >> mariano
> >> _______________________________________________
> >> Pharo-project mailing list
> >> Pharo-project at lists.gforge.inria.fr
> >> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
> >
> >
> > _______________________________________________
> > Pharo-project mailing list
> > Pharo-project at lists.gforge.inria.fr
> > http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>
>
> _______________________________________________
> Pharo-project mailing list
> Pharo-project at lists.gforge.inria.fr
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-dev_lists.pharo.org/attachments/20101019/0ac23f8a/attachment-0001.html>


More information about the Pharo-dev mailing list