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 [hidden email] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project |
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 > [hidden email] > http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project _______________________________________________ Pharo-project mailing list [hidden email] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project |
Just by curiosity, why does MethodDictionary>>at:put: has to send #flushCache at all?
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 >> [hidden email] >> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project > > > _______________________________________________ > Pharo-project mailing list > [hidden email] > http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project _______________________________________________ Pharo-project mailing list [hidden email] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project |
On Tue, Oct 19, 2010 at 1:25 PM, Fernando olivero <[hidden email]> 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
_______________________________________________ Pharo-project mailing list [hidden email] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project |
In reply to this post by Stéphane Ducasse
Yes. An "object as method" is a placeholder. It should support the same API as CompiledMethods.
Noury On 19 oct. 2010, at 13:14, 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 >> [hidden email] >> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project > > > _______________________________________________ > Pharo-project mailing list > [hidden email] > http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project _______________________________________________ Pharo-project mailing list [hidden email] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project |
Free forum by Nabble | Edit this page |