[Vm-dev] Re: [Pharo-project] VM problem?
siguctua at gmail.com
Sun May 27 22:13:40 UTC 2012
On 27 May 2012 23:34, Eliot Miranda <eliot.miranda at gmail.com> wrote:
> Here's a better version. The current definition of #= (at least in Squeak) doesn't compare selectors (since CompiledMethod>>#= is trying to compare code). Any hash method for CompiledMethod should pass the following:
> | ai |
> ai := CompiledMethod allInstances.
> ai do:
> ai do:
> a = b ifTrue: [self assert: a hash = b hash]]]
> find attached this:
> "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."
> | 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)].
> "(CompiledMethod>>#hash) hash"
this one still too slow..
it can serve as a punishment for putting CM as keys in Dictionaries or
in Sets :)
More information about the Vm-dev