serialization and rematerialization of CompiledMethods,assistance needed!
Stephen Pair
spair at advantive.com
Thu Feb 21 19:08:41 UTC 2002
It might be useful to come up with a "semi-compiled" format for compiled
methods. You could store the literals in source or some other encoded
form. I imagine that such a thing might be desirable at some point for
quickly loading modules (i.e. if you wanted to quickly build an image up
from nothing but a bare bones image and modules).
- Stephen
> -----Original Message-----
> From: squeak-dev-admin at lists.squeakfoundation.org
> [mailto:squeak-dev-admin at lists.squeakfoundation.org] On
> Behalf Of John.Maloney at disney.com
> Sent: Thursday, February 21, 2002 1:34 PM
> To: squeak-dev at lists.squeakfoundation.org
> Subject: Re: serialization and rematerialization of
> CompiledMethods,assistance needed!
>
>
> Chris,
>
> CompiledMethods are a little tricky, because they are a
> hybrid of a bytes object and a pointer-field object. The
> method's "literals" (i.e., literal objects such as strings,
> points, floats, etc. that appear in the method text, as well
> as references to class and global variables which are
> Association objects) are stored in the first part of the
> CompiledMethod. These are actual object pointers. If you
> simply serialize and deserialize the CompiledMethod as bytes,
> you'll end up with garbage literal object pointers on the
> other side, which would be Very Bad.
>
> The easiest thing would be to follow Bob's suggestion and use
> some form of source code. Alternatively, you could use the
> image segment machinery, although that's trickier. If you
> don't want to save the comments and local variable names, you
> could use the decompiler to produce a generic source string
> for the method.
>
> -- John
>
>
> At 9:20 PM -0800 2/20/02, Chris Muller wrote:
> >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
>
>
>
>
More information about the Squeak-dev
mailing list
|