It's a bit dangerous to change the hash without rehashing the collections which contain CompiledMethods as keys. For example DebuggerMethodMap's MapCache uses CompiledMethods as keys.
Levente
On Sun, 27 May 2012, commits@source.squeak.org wrote:
Eliot Miranda uploaded a new version of Kernel to project The Trunk: http://source.squeak.org/trunk/Kernel-eem.692.mcz
==================== Summary ====================
Name: Kernel-eem.692 Author: eem Time: 27 May 2012, 3:08:41.389 pm UUID: 72f75218-3cfc-4575-b159-8de0e44aa479 Ancestors: Kernel-nice.691
Implement CompiledMethod>>#hash, both to accord with CompiledMethod>>#= and to override ByteArray>>#hash which looks at all bytes of the receiver and hence may produce a variable hash if the GC moves literals in a method.
=============== Diff against Kernel-nice.691 ===============
Item was added:
- ----- Method: CompiledMethod>>hash (in category 'comparing') -----
- hash
- "CompiledMethod>>#= compares code, i.e. same literals and same bytecode.
So we look at the header, methodClass and some bytes between initialPC and endPC,
but /not/ the selector because the equal method does not compare selectors.
Note that we must override ByteArray>hash which looks at all bytes of the receiver.
Using bytes from the pointer part of a COmpiledmethod can lead to a variable hash
if and when when the GC moves literals in the receiver."
- | initialPC endPC hash |
- initialPC := self initialPC.
- endPC := self endPC.
- hash := self species hash + self header + initialPC + endPC + self methodClass hash bitAnd: 16rFFFFFFF.
- "sample approximately 20 bytes"
- initialPC to: endPC by: (endPC - initialPC // 20 max: 1) do:
[:i| hash := hash + (self at: i)].
- ^hash
- "(CompiledMethod>>#hash) hash"!
On Sun, May 27, 2012 at 8:37 PM, Levente Uzonyi leves@elte.hu wrote:
It's a bit dangerous to change the hash without rehashing the collections which contain CompiledMethods as keys. For example DebuggerMethodMap's MapCache uses CompiledMethods as keys.
Good point. I'll fix this when I fix the methods comment ( COmpiledmethod => CompiledMethod)
Levente
On Sun, 27 May 2012, commits@source.squeak.org wrote:
Eliot Miranda uploaded a new version of Kernel to project The Trunk:
http://source.squeak.org/**trunk/Kernel-eem.692.mczhttp://source.squeak.org/trunk/Kernel-eem.692.mcz
==================== Summary ====================
Name: Kernel-eem.692 Author: eem Time: 27 May 2012, 3:08:41.389 pm UUID: 72f75218-3cfc-4575-b159-**8de0e44aa479 Ancestors: Kernel-nice.691
Implement CompiledMethod>>#hash, both to accord with CompiledMethod>>#= and to override ByteArray>>#hash which looks at all bytes of the receiver and hence may produce a variable hash if the GC moves literals in a method.
=============== Diff against Kernel-nice.691 ===============
Item was added:
- ----- Method: CompiledMethod>>hash (in category 'comparing') -----
- hash
"CompiledMethod>>#= compares code, i.e. same literals and same
bytecode.
So we look at the header, methodClass and some bytes between
initialPC and endPC,
but /not/ the selector because the equal method does not compare
selectors.
Note that we must override ByteArray>hash which looks at all
bytes of the receiver.
Using bytes from the pointer part of a COmpiledmethod can lead
to a variable hash
if and when when the GC moves literals in the receiver."
| initialPC endPC hash |
initialPC := self initialPC.
endPC := self endPC.
hash := self species hash + self header + initialPC + endPC +
self methodClass hash bitAnd: 16rFFFFFFF.
"sample approximately 20 bytes"
initialPC to: endPC by: (endPC - initialPC // 20 max: 1) do:
[:i| hash := hash + (self at: i)].
^hash
"(CompiledMethod>>#hash) hash"!
I recently added a rehashAll in Kernel postscript due to a change in dataAndTime>>hash
Nicolas
2012/5/30 Eliot Miranda eliot.miranda@gmail.com:
On Sun, May 27, 2012 at 8:37 PM, Levente Uzonyi leves@elte.hu wrote:
It's a bit dangerous to change the hash without rehashing the collections which contain CompiledMethods as keys. For example DebuggerMethodMap's MapCache uses CompiledMethods as keys.
Good point. I'll fix this when I fix the methods comment ( COmpiledmethod => CompiledMethod)
Levente
On Sun, 27 May 2012, commits@source.squeak.org wrote:
Eliot Miranda uploaded a new version of Kernel to project The Trunk: http://source.squeak.org/trunk/Kernel-eem.692.mcz
==================== Summary ====================
Name: Kernel-eem.692 Author: eem Time: 27 May 2012, 3:08:41.389 pm UUID: 72f75218-3cfc-4575-b159-8de0e44aa479 Ancestors: Kernel-nice.691
Implement CompiledMethod>>#hash, both to accord with CompiledMethod>>#= and to override ByteArray>>#hash which looks at all bytes of the receiver and hence may produce a variable hash if the GC moves literals in a method.
=============== Diff against Kernel-nice.691 ===============
Item was added:
- ----- Method: CompiledMethod>>hash (in category 'comparing') -----
- hash
- "CompiledMethod>>#= compares code, i.e. same literals and same
bytecode.
- So we look at the header, methodClass and some bytes between
initialPC and endPC,
- but /not/ the selector because the equal method does not compare
selectors.
- Note that we must override ByteArray>hash which looks at all
bytes of the receiver.
- Using bytes from the pointer part of a COmpiledmethod can lead
to a variable hash
- if and when when the GC moves literals in the receiver."
- | initialPC endPC hash |
- initialPC := self initialPC.
- endPC := self endPC.
- hash := self species hash + self header + initialPC + endPC +
self methodClass hash bitAnd: 16rFFFFFFF.
- "sample approximately 20 bytes"
- initialPC to: endPC by: (endPC - initialPC // 20 max: 1) do:
- [:i| hash := hash + (self at: i)].
- ^hash
- "(CompiledMethod>>#hash) hash"!
-- best, Eliot
On 30.05.2012, at 01:43, Nicolas Cellier wrote:
I recently added a rehashAll in Kernel postscript due to a change in dataAndTime>>hash
Nicolas
Just keep in mind that like all other MC definitions, postscripts will only be executed if they were modified.
- Bert -
2012/5/30 Bert Freudenberg bert@freudenbergs.de:
On 30.05.2012, at 01:43, Nicolas Cellier wrote:
I recently added a rehashAll in Kernel postscript due to a change in dataAndTime>>hash
Nicolas
Just keep in mind that like all other MC definitions, postscripts will only be executed if they were modified.
- Bert -
Ah thanks, that always bugs me.
squeak-dev@lists.squeakfoundation.org