Re: store and resume
"Scott G. Miller" <[email protected]> Fri, 3 Apr 2009 11:09:00 -0500
| Newsgroups | gmane.comp.java.sisc.user |
|---|---|
| Message-ID | <[email protected]> |
--===============5619333534340222505== Content-Type: multipart/alternative; boundary=000e0cd37592526b630466a8c4de --000e0cd37592526b630466a8c4de Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit On Fri, Apr 3, 2009 at 9:10 AM, Johannes Bruegmann <[email protected]>wrote: > Hello, > > i am trying to get "store and resume" to work. I want to do some > computation and when a certain point of computation is reached store > the state of *everything* onto disk, in order to resume from thereon > later in a new session/repl. > ..snip.. Given the resulting size of the stored environment, it looks like you're serializing more than just the modifications you've made. My guess without looking much further into it, is that there are unserializable values on the stack, such as ports or in your latter example Java proxy objects. Unfortunately you need to store these differently. SISCWeb, afaik, puts these in parameter objects, and reinitializes them on startup. Additionally, there are known problems with syntax environments not being completely contained within user-defined environments. In the simpler example, its possible that serializing your *environment* winds up serializing the global syntax environment and then some other stuff that it shouldn't. See if you can separate your base library code and load it normally before deserializing your environment. Scott > > The toy example looks like this and it works: > > bruegmann@vmax:scm# cat store-and-resume.scm > (import file-manipulation) > (import serial-io) > > (define (serialize-to-file fname val) > (if (not (file-exists? fname)) > (call-with-serial-output-file fname (lambda (p) (serialize val > p))) > #f)) > > (define (deserialize-from-file fname) > (if (file-exists? fname) > (call-with-serial-input-file fname deserialize) > #f)) > > (define-syntax with-environment > (lambda (f) > (syntax-case f () > ((_ env exp0 exp1 ...) > (syntax (begin > (eval 'exp0 env) > (eval 'exp1 env) > ... > )))))) > > (define *environment* > (make-child-environment (interaction-environment))) > > (let ((fname "foo.env")) > (putprop 'fname *environment* fname) > (if (not (file-exists? fname)) > (with-environment *environment* > (define foo 12345) > (serialize-to-file fname *environment*)) > (set! *environment* (deserialize-from-file fname)) > )) > bruegmann@vmax:scm# sisc > SISC (1.16.6) > > (load "store-and-resume.scm") > > (with-environment *environment* foo) > 12345 > > ^D > bruegmann@vmax:scm# ls -l foo.env > -rw-r--r-- 1 bruegmann bruegmann 6535 3 Apr 13:50 foo.env > bruegmann@vmax:scm# sisc > SISC (1.16.6) > > (load "store-and-resume.scm") > > (with-environment *environment* foo) > 12345 > > ^D > bruegmann@vmax:scm# ls -l foo.env > -rw-r--r-- 1 bruegmann bruegmann 6535 3 Apr 13:50 foo.env > > A little more complex example like the following throws a > JavaNullPointerException: > > (require-library 'sisc/libs/srfi) > (require-library 'sisc/misc/misc) > > (module bar > (baz make-frob frob? frob-a frob-b frob-c (color) > color? colors color-name color-index (color-set) > color-set? make-color-set color color? colors color-index) > > (import srfi-1) > (import srfi-9) > (import finite-types) > (import enum-sets) > > (define baz #f) > (define-record-type :frob > (make-frob a b c) > frob? > (a frob-a) > (b frob-b) > (c frob-c)) > > (define-enumerated-type color :color > color? > colors > color-name > color-index > (black white purple maroon)) > > (define-enum-set-type color-set :color-set > color-set? > make-color-set > color color? colors color-index) > > (set! baz (apply make-frob (fold-right (lambda (x unit) (cons x > unit)) '() (list 1 2 3)))) > ) > > bruegmann@vmax:scm# sisc > SISC (1.16.6) > > (load "store-and-resume.scm") > > (with-environment *environment* (import bar) (color? (color red))) > Error: invalid syntax (color red) > --------------------------- > Some stack trace entries may have been suppressed. To see all entries > set the dynamic parameter suppressed-stack-trace-source-kinds to '(). > > (with-environment *environment* (import bar) (color? (color red))) > Error: invalid syntax (color red) > > (with-environment *environment* (import bar) (color? (color black))) > #t > > ^D > bruegmann@vmax:scm# ls -l foo.env > -rw-r--r-- 1 bruegmann bruegmann 997712 3 Apr 15:48 foo.env > bruegmann@vmax:scm# sisc > SISC (1.16.6) > > (load "store-and-resume.scm") > > (with-environment *environment* (import bar) (color? (color black))) > java.lang.NullPointerException > at sisc.io.PortValueWriter.append(Unknown Source) > at sisc.io.PortValueWriter.displayOrWrite(Unknown Source) > at sisc.io.PortValueWriter.display(Unknown Source) > at sisc.modules.io.IO.displayOrWrite(Unknown Source) > at sisc.modules.io.IO.doApply(Unknown Source) > at sisc.nativefun.NativeProcedure.apply(Unknown Source) > at sisc.exprs.AppEval.eval(Unknown Source) > at sisc.interpreter.Interpreter.next(Unknown Source) > at sisc.exprs.AppExp.eval(Unknown Source) > at sisc.interpreter.Interpreter.next(Unknown Source) > at sisc.exprs.EvalExp.eval(Unknown Source) > at sisc.interpreter.Interpreter.interpret(Unknown Source) > at sisc.interpreter.Interpreter.interpret(Unknown Source) > at sisc.interpreter.Interpreter.interpret(Unknown Source) > at sisc.interpreter.Interpreter.eval(Unknown Source) > at sisc.data.SchemeThread.run(Unknown Source) > at java.lang.Thread.run(Thread.java:595) > Uncaught error: ((message . <java.lang.NullPointerException>: null) > (location . eqv?) (java-exception . #<java java.lang.NullPointerException > java.lang.NullPointerException>)) > Please report this error to [email protected] > > > While the real application i want to work with throwed this here: > > Error in load: evaluation error at > file:/home/bruegmann/du/cvs-modules/traffic-nrw-ca/scm/store-and-resume.scm:29:1 > --------------------------- > console:1:1: <from call to load> > --------------------------- > Some stack trace entries may have been suppressed. To see all entries > set the dynamic parameter suppressed-stack-trace-source-kinds to '(). > =========================== > Caused by Error in deserialize: error reading from port > 'sisc.io.DeserializerStream@3aa42c31': java.lang.ClassNotFoundException: > $Proxy1 > --------------------------- > > file:/home/bruegmann/du/cvs-modules/traffic-nrw-ca/scm/store-and-resume.scm:13:7: > <from call to @serial-io::call-with-serial-input-file> > > file:/home/bruegmann/du/cvs-modules/traffic-nrw-ca/scm/store-and-resume.scm:36:27: > <from call to deserialize-from-file> > > What am i doing wrong? Is there a better way to do it? > > Regards, > Johannes > > -- > Jesus said: Unless a grain of wheat falls into the earth and dies, > it > remains alone; but if it dies, it bears much fruit. > > John 12:24 (ESV) > > > ------------------------------------------------------------------------------ > _______________________________________________ > Sisc-users mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/sisc-users > --000e0cd37592526b630466a8c4de Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <br><div class=3D"gmail_quote">On Fri, Apr 3, 2009 at 9:10 AM, Johannes Bru= egmann <span dir=3D"ltr"><<a href=3D"mailto:[email protected]">johann= [email protected]</a>></span> wrote:<br><blockquote class=3D"gmail_quote" s= tyle=3D"border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8e= x; padding-left: 1ex;"> Hello,<br> <br> i am trying to get "store and resume" to work. I want to do some<= br> computation and when a certain point of computation is reached store<br> the state of *everything* onto disk, in order to resume from thereon<br> later in a new session/repl.<br> </blockquote><div><br><br>..snip..<br><br>Given the resulting size of the s= tored environment, it looks like you're serializing more than just the = modifications you've made.=A0 My guess without looking much further int= o it, is that there are unserializable values on the stack, such as ports o= r in your latter example Java proxy objects.=A0 Unfortunately you need to s= tore these differently.=A0 SISCWeb, afaik, puts these in parameter objects,= and reinitializes them on startup.=A0 <br> <br>Additionally, there are known problems with syntax environments not bei= ng completely contained within user-defined environments.=A0 In the simpler= example, its possible that serializing your *environment* winds up seriali= zing the global syntax environment and then some other stuff that it should= n't.=A0 See if you can separate your base library code and load it norm= ally before deserializing your environment.<br> <br>Scott<br>=A0</div><blockquote class=3D"gmail_quote" style=3D"border-lef= t: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1= ex;"><br> The toy example looks like this and it works:<br> <br> =A0 =A0 =A0bruegmann@vmax:scm# cat store-and-resume.scm<br> =A0 =A0 =A0(import file-manipulation)<br> =A0 =A0 =A0(import serial-io)<br> <br> =A0 =A0 =A0(define (serialize-to-file fname val)<br> =A0 =A0 =A0 =A0(if (not (file-exists? fname))<br> =A0 =A0 =A0 =A0 =A0 =A0(call-with-serial-output-file fname (lambda (p) (se= rialize val p)))<br> =A0 =A0 =A0 =A0 =A0 =A0#f))<br> <br> =A0 =A0 =A0(define (deserialize-from-file fname)<br> =A0 =A0 =A0 =A0(if (file-exists? fname)<br> =A0 =A0 =A0 =A0 =A0 =A0(call-with-serial-input-file fname deserialize)<br> =A0 =A0 =A0 =A0 =A0 =A0#f))<br> <br> =A0 =A0 =A0(define-syntax with-environment<br> =A0 =A0 =A0 =A0(lambda (f)<br> =A0 =A0 =A0 =A0 =A0(syntax-case f ()<br> =A0 =A0 =A0 =A0 =A0 =A0((_ env exp0 exp1 ...)<br> =A0 =A0 =A0 =A0 =A0 =A0 (syntax (begin<br> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (eval 'exp0 env)<br> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (eval 'exp1 env)<br> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ...<br> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ))))))<br> <br> =A0 =A0 =A0(define *environment*<br> =A0 =A0 =A0 =A0(make-child-environment (interaction-environment)))<br> <br> =A0 =A0 =A0(let ((fname "foo.env"))<br> =A0 =A0 =A0 =A0(putprop 'fname *environment* fname)<br> =A0 =A0 =A0 =A0(if (not (file-exists? fname))<br> =A0 =A0 =A0 =A0 =A0 =A0(with-environment *environment*<br> =A0 =A0 =A0 =A0 =A0 =A0 =A0(define foo 12345)<br> =A0 =A0 =A0 =A0 =A0 =A0 =A0(serialize-to-file fname *environment*))<br> =A0 =A0 =A0 =A0 =A0 =A0(set! *environment* (deserialize-from-file fname))<= br> =A0 =A0 =A0 =A0 =A0 =A0))<br> =A0 =A0 =A0bruegmann@vmax:scm# sisc<br> =A0 =A0 =A0SISC (1.16.6)<br> =A0 =A0 =A0> (load "store-and-resume.scm")<br> =A0 =A0 =A0> (with-environment *environment* foo)<br> =A0 =A0 =A012345<br> =A0 =A0 =A0> ^D<br> =A0 =A0 =A0bruegmann@vmax:scm# ls -l foo.env<br> =A0 =A0 =A0-rw-r--r-- =A01 bruegmann =A0bruegmann =A06535 =A03 Apr 13:50 f= oo.env<br> =A0 =A0 =A0bruegmann@vmax:scm# sisc<br> =A0 =A0 =A0SISC (1.16.6)<br> =A0 =A0 =A0> (load "store-and-resume.scm")<br> =A0 =A0 =A0> (with-environment *environment* foo)<br> =A0 =A0 =A012345<br> =A0 =A0 =A0> ^D<br> =A0 =A0 =A0bruegmann@vmax:scm# ls -l foo.env<br> =A0 =A0 =A0-rw-r--r-- =A01 bruegmann =A0bruegmann =A06535 =A03 Apr 13:50 f= oo.env<br> <br> A little more complex example like the following throws a<br> JavaNullPointerException:<br> <br> =A0 =A0 =A0(require-library 'sisc/libs/srfi)<br> =A0 =A0 =A0(require-library 'sisc/misc/misc)<br> <br> =A0 =A0 =A0(module bar<br> =A0 =A0 =A0 =A0 =A0(baz make-frob frob? frob-a frob-b frob-c (color)<br> =A0 =A0 =A0 =A0 =A0 color? colors color-name color-index (color-set)<br> =A0 =A0 =A0 =A0 =A0 color-set? make-color-set color color? colors color-in= dex)<br> <br> =A0 =A0 =A0 =A0(import srfi-1)<br> =A0 =A0 =A0 =A0(import srfi-9)<br> =A0 =A0 =A0 =A0(import finite-types)<br> =A0 =A0 =A0 =A0(import enum-sets)<br> <br> =A0 =A0 =A0 =A0(define baz #f)<br> =A0 =A0 =A0 =A0(define-record-type :frob<br> =A0 =A0 =A0 =A0 =A0(make-frob a b c)<br> =A0 =A0 =A0 =A0 =A0frob?<br> =A0 =A0 =A0 =A0 =A0(a frob-a)<br> =A0 =A0 =A0 =A0 =A0(b frob-b)<br> =A0 =A0 =A0 =A0 =A0(c frob-c))<br> <br> =A0 =A0 =A0 =A0(define-enumerated-type color :color<br> =A0 =A0 =A0 =A0 =A0color?<br> =A0 =A0 =A0 =A0 =A0colors<br> =A0 =A0 =A0 =A0 =A0color-name<br> =A0 =A0 =A0 =A0 =A0color-index<br> =A0 =A0 =A0 =A0 =A0(black white purple maroon))<br> <br> =A0 =A0 =A0 =A0(define-enum-set-type color-set :color-set<br> =A0 =A0 =A0 =A0 =A0color-set?<br> =A0 =A0 =A0 =A0 =A0make-color-set<br> =A0 =A0 =A0 =A0 =A0color color? colors color-index)<br> <br> =A0 =A0 =A0 =A0(set! baz (apply make-frob (fold-right (lambda (x unit) (co= ns x unit)) '() (list 1 2 3))))<br> =A0 =A0 =A0)<br> <br> =A0 =A0 =A0bruegmann@vmax:scm# sisc<br> =A0 =A0 =A0SISC (1.16.6)<br> =A0 =A0 =A0> (load "store-and-resume.scm")<br> =A0 =A0 =A0> (with-environment *environment* (import bar) (color? (colo= r red)))<br> =A0 =A0 =A0Error: invalid syntax (color red)<br> =A0 =A0 =A0---------------------------<br> =A0 =A0 =A0Some stack trace entries may have been suppressed. To see all e= ntries set the dynamic parameter suppressed-stack-trace-source-kinds to = 9;().<br> =A0 =A0 =A0> (with-environment *environment* (import bar) (color? (colo= r red)))<br> =A0 =A0 =A0Error: invalid syntax (color red)<br> =A0 =A0 =A0> (with-environment *environment* (import bar) (color? (colo= r black)))<br> =A0 =A0 =A0#t<br> =A0 =A0 =A0> ^D<br> =A0 =A0 =A0bruegmann@vmax:scm# ls -l foo.env<br> =A0 =A0 =A0-rw-r--r-- =A01 bruegmann =A0bruegmann =A0997712 =A03 Apr 15:48= foo.env<br> =A0 =A0 =A0bruegmann@vmax:scm# sisc<br> =A0 =A0 =A0SISC (1.16.6)<br> =A0 =A0 =A0> (load "store-and-resume.scm")<br> =A0 =A0 =A0> (with-environment *environment* (import bar) (color? (colo= r black)))<br> =A0 =A0 =A0java.lang.NullPointerException<br> =A0 =A0 =A0 =A0 =A0 =A0 =A0at sisc.io.PortValueWriter.append(Unknown Sourc= e)<br> =A0 =A0 =A0 =A0 =A0 =A0 =A0at sisc.io.PortValueWriter.displayOrWrite(Unkno= wn Source)<br> =A0 =A0 =A0 =A0 =A0 =A0 =A0at sisc.io.PortValueWriter.display(Unknown Sour= ce)<br> =A0 =A0 =A0 =A0 =A0 =A0 =A0at sisc.modules.io.IO.displayOrWrite(Unknown So= urce)<br> =A0 =A0 =A0 =A0 =A0 =A0 =A0at sisc.modules.io.IO.doApply(Unknown Source)<b= r> =A0 =A0 =A0 =A0 =A0 =A0 =A0at sisc.nativefun.NativeProcedure.apply(Unknown= Source)<br> =A0 =A0 =A0 =A0 =A0 =A0 =A0at sisc.exprs.AppEval.eval(Unknown Source)<br> =A0 =A0 =A0 =A0 =A0 =A0 =A0at sisc.interpreter.Interpreter.next(Unknown So= urce)<br> =A0 =A0 =A0 =A0 =A0 =A0 =A0at sisc.exprs.AppExp.eval(Unknown Source)<br> =A0 =A0 =A0 =A0 =A0 =A0 =A0at sisc.interpreter.Interpreter.next(Unknown So= urce)<br> =A0 =A0 =A0 =A0 =A0 =A0 =A0at sisc.exprs.EvalExp.eval(Unknown Source)<br> =A0 =A0 =A0 =A0 =A0 =A0 =A0at sisc.interpreter.Interpreter.interpret(Unkno= wn Source)<br> =A0 =A0 =A0 =A0 =A0 =A0 =A0at sisc.interpreter.Interpreter.interpret(Unkno= wn Source)<br> =A0 =A0 =A0 =A0 =A0 =A0 =A0at sisc.interpreter.Interpreter.interpret(Unkno= wn Source)<br> =A0 =A0 =A0 =A0 =A0 =A0 =A0at sisc.interpreter.Interpreter.eval(Unknown So= urce)<br> =A0 =A0 =A0 =A0 =A0 =A0 =A0at sisc.data.SchemeThread.run(Unknown Source)<b= r> =A0 =A0 =A0 =A0 =A0 =A0 =A0at java.lang.Thread.run(Thread.java:595)<br> =A0 =A0 =A0Uncaught error: ((message . <java.lang.NullPointerException&= gt;: null) (location . eqv?) (java-exception . #<java java.lang.NullPoin= terException java.lang.NullPointerException>))<br> =A0 =A0 =A0Please report this error to <a href=3D"mailto:sisc-devel@lists.= sourceforge.net">[email protected]</a><br> <br> <br> While the real application i want to work with throwed this here:<br> <br> =A0 =A0 =A0Error in load: evaluation error at file:/home/bruegmann/du/cvs-= modules/traffic-nrw-ca/scm/store-and-resume.scm:29:1<br> =A0 =A0 =A0---------------------------<br> =A0 =A0 =A0console:1:1: <from call to load><br> =A0 =A0 =A0---------------------------<br> =A0 =A0 =A0Some stack trace entries may have been suppressed. To see all e= ntries set the dynamic parameter suppressed-stack-trace-source-kinds to = 9;().<br> =A0 =A0 =A0=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D<br> =A0 =A0 =A0Caused by Error in deserialize: error reading from port 'si= sc.io.DeserializerStream@3aa42c31': java.lang.ClassNotFoundException: $= Proxy1<br> =A0 =A0 =A0---------------------------<br> =A0 =A0 =A0file:/home/bruegmann/du/cvs-modules/traffic-nrw-ca/scm/store-an= d-resume.scm:13:7: <from call to @serial-io::call-with-serial-input-file= ><br> =A0 =A0 =A0file:/home/bruegmann/du/cvs-modules/traffic-nrw-ca/scm/store-an= d-resume.scm:36:27: <from call to deserialize-from-file><br> <br> What am i doing wrong? Is there a better way to do it?<br> <br> Regards,<br> Johannes<br> <br> --<br> =A0 =A0 =A0 Jesus =A0said: =A0Unless a grain of wheat falls into the earth= and dies, it<br> =A0 =A0 =A0 remains alone; but if it dies, it bears much fruit.<br> <br> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 John 12:24 (ESV)<br> <br> ---------------------------------------------------------------------------= ---<br> _______________________________________________<br> Sisc-users mailing list<br> <a href=3D"mailto:[email protected]">[email protected]= forge.net</a><br> <a href=3D"https://lists.sourceforge.net/lists/listinfo/sisc-users" target= =3D"_blank">https://lists.sourceforge.net/lists/listinfo/sisc-users</a><br> </blockquote></div><br> --000e0cd37592526b630466a8c4de-- --===============5619333534340222505== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------------ --===============5619333534340222505== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Sisc-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/sisc-users --===============5619333534340222505==--