serialization and rematerialization of CompiledMethods, assistance needed!

Chris Muller afunkyobject at yahoo.com
Thu Feb 21 05:20:58 UTC 2002


I need to be able to serialize a CompiledMethod to a byteArray and bring it
back and use it.

The serialization is easy since the CompiledMethod already is a ByteArray.

But how do I convert that ByteArray to a usable method again?  The overridden
basicNew: constructor urges "CompiledMethods may only be created with
newMethod:header:".

But I'm not sure where to get that first argument (labelled "numberOfBytes" in
the method code).  I tried using the #size of the original method.  It
functioned, but it did not report = to the original.  See my test script here:

| m copy |
m _ (MyClass >> #test).
copy _ (CompiledMethod newMethod: m size header: m header)
    replaceFrom: 1
    to: m size
    with: m
    startingAt: 1.
MyClass methodDict
    at: #test
    put: copy.
MyClass new test.
^m = copy

I also tried creating a CompiledMethod with basicNew: and then just a
copyFrom:to: from the old method and that seemed to work too!  It then actually
answered true to the =.  This seems to be an improvement but I'm not sure about
the structure of CompiledMethods.

I'm also not sure whether MyClass methodDict at:put: is the appropriate way to
install back into the class or not, but it worked..

Any advice would be greatly appreciated!

Regards,
  Chris Muller


__________________________________________________
Do You Yahoo!?
Yahoo! Sports - Coverage of the 2002 Olympic Games
http://sports.yahoo.com



More information about the Squeak-dev mailing list