How to serialize/externalize Scheme procedures
oliver.flasch@cs.uni-dortmund.de
oliver.flasch@cs.uni-dortmund.de
Sat Mar 24 23:31:00 GMT 2007
Hi,
I need to serialize procedures (and later closures) via XStream
(http://xstream.codehaus.org/) at the Kawa toplevel to save them to disk
and to transfer them over a network.
In order to get this to work, I modified gnu.bytecode.ArrayClassLoader
(from kawa-1.9.1.tar.gz, source code attached) to keep the compiled
bytecodes, which seems to work fine.
I then serialized the module class of a simple procedure "foo" to XML
(at the toplevel):
# (define (foo a) (+ a 42)) ; a simple procedure
# (define module-class (invoke foo:module 'getClass)) ; the procedure's
module class ("atEvalLevel")
# (define module-classloader (invoke module-class 'getClassLoader))
# (module-class:foo 3) ; => 45, works OK
# (export-to-xml (module-classloader:getBytecodeMap)
"/home/oflasch/bcm.xml") ; serialize the "bytecode map" of my modified
ArrayClassLoader
...and finally tried to de-serialize the module class again, which
failed quite miserably:
# (define acl
(make <gnu.bytecode.ArrayClassLoader>
((<java.lang.Thread>:currentThread):getContextClassLoader)
(import-from-xml "/home/oflasch/bcm.xml"))) ; make a new
ArrayClassLoader to load the de-serialized bytecodes
# (define imported-class (acl:loadClass (make <java.lang.String>
"atEvalLevel")))
# imported-class:foo ; => java.lang.Object
atEvalLevel.foo(java.lang.Object), OK, the "foo" method seems to be
there
# (make imported-class) ; throws an
java.lang.ExceptionInInitializerError
# (imported-class:foo 1) ; always throws an
java.lang.NoClassDefFoundError
The ExceptionInInitializerError gave me the following stack trace:
<StackTrace>
java.lang.ExceptionInInitializerError
(message:) java.lang.ExceptionInInitializerError
(caused by...)
java.lang.ExceptionInInitializerError
(message:) null
(caused by...)
java.lang.NullPointerException
(message:) null
gnu.expr.Compilation.findForImmediateLiterals(Compilation.java:2826)
gnu.expr.Compilation.setupLiterals(Compilation.java:2781)
atEvalLevel.<clinit>(<string>)
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
java.lang.reflect.Constructor.newInstance(Constructor.java:494)
gnu.expr.PrimProcedure.apply(PrimProcedure.java:238)
gnu.mapping.CallContext.runUntilDone(CallContext.java:251)
gnu.mapping.CallContext.runUntilValue(CallContext.java:315)
gnu.kawa.reflect.Invoke.applyN(Invoke.java:199)
gnu.kawa.reflect.Invoke.apply(Invoke.java:98)
gnu.mapping.CallContext.runUntilDone(CallContext.java:251)
gnu.expr.ModuleExp.evalModule(ModuleExp.java:296)
kawa.lang.Eval.evalBody(Eval.java:99)
kawa.lang.Eval.evalBody(Eval.java:42)
kawa.standard.Scheme.eval(Scheme.java:847)
kawa.standard.Scheme.eval(Scheme.java:830)
</StackTrace>
I must confess that I'm still not very comfortable with Kawa's
internals, although the Website and especially Per Bothner's "Kawa
internals" papers have been a great help. I would of cause be happy to
contribute my code, if I get the procedure serialization to work. :)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ArrayClassLoader.java
Type: text/x-java
Size: 3162 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/kawa/attachments/20070324/d7f8e51b/attachment.bin>
More information about the Kawa
mailing list