[Pharo-project] Reliable method change detection
alexandre.bergel at me.com
Wed Mar 21 10:09:09 EDT 2012
This is interesting. If we have this method on Object, can it be used to keep track of side effects? It looks like to isn't it?
Le 19 mars 2012 à 23:35, Martin Dias <tinchodias at gmail.com> a écrit :
> 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 >>
> "Answer a 16-bit checksum of the bytecodes."
> ^ self adler16from: self initialPC to: self endPC
> On Sat, Mar 17, 2012 at 2:17 AM, Martin Dias <tinchodias at gmail.com> wrote:
> 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?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Pharo-dev