[Pharo-project] Reliable method change detection

Martin Dias tinchodias at gmail.com
Tue Mar 20 00:35:18 EDT 2012


Finally I tried with a bytecodes checksum to detect changes. I chose a
16-bit variant of Adler-32 (http://en.wikipedia.org/wiki/Adler-32). Was
easy and worked fine.

ByteArray >>
adler16from: start to: end
"Answer a checksum over the values of the specified interval, calculated
using Adler-16 algorithm."
 | a b |
a := 1.
b := 0.
 start to: end do: [ :index |
a := (a + (self at: index)) \\ 251.
b := (b + a) \\ 251. ].
 ^(b bitShift: 8) bitOr: a

CompiledMethod >>
bytecodesHash
"Answer a 16-bit checksum of the bytecodes."
 ^ self adler16from: self initialPC to: self endPC


cheers,
Martín

On Sat, Mar 17, 2012 at 2:17 AM, Martin Dias <tinchodias at gmail.com> wrote:

> Hi
>
> In Fuel (bleeding edge), a compiled method can be serialized as a global.
> Basically, we store the class name and selector, so loading it is
> straightforward... this can be fine if we suppose there were not any change
> in the system between save and load time. This can be a huge supposition,
> but maybe it's acceptable in some uses, for example to "log" exceptions.
>
> Well, actually we can discuss if this is a good approach, but anyway I am
> interested on how to detect a BIG change, for example the one I show in the
> following code (which produces a vm crash):
>
> | byteArray aClass aClosure materializedClosure |
>
> aClass := Object subclass: #A.
>  aClass compileSilently: 'methodWithClosure  ^ [ 42 ] '.
>
> aClosure := aClass new perform: #methodWithClosure.
>
> byteArray := FLSerializer serializeToByteArray: aClosure.
>
> aClass compileSilently: 'methodWithClosure  ^ 42'.
>
> materializedClosure := FLMaterializer materializeFromByteArray: byteArray.
> materializedClosure value.
>
>
> What can we do to detect this change?
> - generate a checksum with bytecodes
> - just compare the size
> - something else?
>
> Thanks,
> Martín
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-dev_lists.pharo.org/attachments/20120320/8155004a/attachment-0001.html>


More information about the Pharo-dev mailing list