RE:: [ sisc-Bugs-1091312 ] java.lang.OutOfMemoryError: Java heap space
Ken Anderson <[email protected]> Tue, 28 Dec 2004 12:38:45 -0500
| Newsgroups | gmane.comp.java.sisc.devel |
|---|---|
| Message-ID | <[email protected]> |
To: "SourceForge.net" <[email protected]> Subject: Re: [SISC-devel] [ sisc-Bugs-1091312 ] java.lang.OutOfMemoryError: Java heap space Cc: [email protected] The out of memory occurs because of how SICP does laziness. See http://srfi.schemers.org/srfi-45/srfi-45.html At 05:43 AM 12/26/2004, SourceForge.net wrote: >Bugs item #1091312, was opened at 2004-12-26 11:43 >Message generated for change (Tracker Item Submitted) made by Item Submitter >You can respond by visiting: >https://sourceforge.net/tracker/?func=detail&atid=379534&aid=1091312&group_id=23735 > >Category: None >Group: None >Status: Open >Resolution: None >Priority: 5 >Submitted By: gni (gni) >Assigned to: Nobody/Anonymous (nobody) >Summary: java.lang.OutOfMemoryError: Java heap space > >Initial Comment: >I get such message while trying an example from SICP >book about an infinite stream of primes. >Delayed evaluation and memoization techniques are used >in the example. >The final stream of primes is called "primes". >To get n-th prime from such stream I use function >"stream-ref". >With DrScheme running as Standard R5RS i.e. I can >compute (stream-ref primes 1000) with easy. >Under sisc I get error java.lang.OutOfMemoryError. > >The output I get is the following: >541 >1223 >1987 >Exception in thread "main" java.lang.OutOfMemoryError: >Java heap space > >This is the code that generates the error, divided in >two java classes: > uNLPBotScheme that is a dirty wrapper around sisc >interpreter > SchemeDemo where is a main that run the example about >infinite stream of primes > > >uNLPBotScheme.java >----------------------------------------------------- >package net.sf.unlpbot.scheme; >import sisc.interpreter.*; >import sisc.ser.*; >import sisc.data.*; > >public class uNLPBotScheme { > public AppContext ctx=null; > public Interpreter r = null; > public String heap = "F:/sisc.shp"; > public String cname = "myapp"; > public uNLPBotScheme() { > this.ctx = new AppContext(); > Context.register(this.cname, this.ctx); > this.r = Context.enter(this.cname); > try { > this.ctx.loadEnv(this.r, new >SeekableDataInputStream(new >BufferedRandomAccessInputStream(this.heap,"r"))); > } catch (Exception e) {//TODO > } > } > public uNLPBotScheme(String cname) { > this.cname=cname; > this.ctx = new AppContext(); > Context.register(this.cname, this.ctx); > this.r = Context.enter(this.cname); > try { > this.ctx.loadEnv(this.r, new >SeekableDataInputStream(new >BufferedRandomAccessInputStream(this.heap,"r"))); > } catch (Exception e) { // TODO > } > } > public String eval(String arg) { > String result = null; > try { > result = this.r.eval(arg).toString(); > } catch (Exception e) {} > return result; > } > public Value eval(Value val) { > Value result = null; > try { > result = this.r.eval(val); > } catch (Exception e) {} > return result; > } >} > > > >SchemeDemo.java >----------------------------------------------------- >package net.sf.unlpbot.sandbox.demos; >import net.sf.unlpbot.scheme.*; > >public class SchemeDemo { > > public static void main(String[] args) { > uNLPBotScheme scheme = new uNLPBotScheme(); > scheme.eval("(define false #f)"); > scheme.eval("(define true #t)"); > scheme.eval("(define-syntax cons-stream (syntax-rules >() ((cons-stream value-expr call-expr) (cons value-expr >(delay call-expr)))))"); > scheme.eval("(define-syntax delay (syntax-rules () >((delay exp) (memo-proc (lambda () exp)))))"); > scheme.eval("(define (stream-car s) (car s))"); > scheme.eval("(define (stream-cdr s) (force (cdr s)))"); > scheme.eval("(define the-empty-stream '())"); > scheme.eval("(define (stream-null? s) (null? s))"); > scheme.eval("(define (stream-ref s n) (if (< n 2) >(stream-car s) (stream-ref (stream-cdr s) (- n 1))))"); > scheme.eval("(define (stream-map proc s) (if >(stream-null? s) the-empty-stream (cons-stream (proc >(stream-car s)) (stream-map proc (stream-cdr s)))))"); > scheme.eval("(define (stream-for-each proc s) (if >(stream-null? s) 'done (begin (proc (stream-car s)) >(stream-for-each proc (stream-cdr s)))))"); > scheme.eval("(define (display-stream s) >(stream-for-each display-line s))"); > scheme.eval("(define (display-line x) (newline) >(display x))"); > scheme.eval("(define (stream-filter pred stream) >(cond ((stream-null? stream) the-empty-stream) ((pred >(stream-car stream)) (cons-stream (stream-car stream) >(stream-filter pred (stream-cdr stream)))) (else >(stream-filter pred (stream-cdr stream)))))"); > scheme.eval("(define (stream-enumerate-interval low >high) (if (> low high) the-empty-stream (cons-stream >low (stream-enumerate-interval (+ low 1) high))))"); > scheme.eval("(define (memo-proc proc) (let >((already-run? false) (result false)) (lambda () (if >(not already-run?) (begin (set! result (proc)) (set! >already-run? true) result) result))))"); > scheme.eval("(define (force delayed-object) >(delayed-object))"); > scheme.eval("(define (integers-starting-from n) >(cons-stream n (integers-starting-from (+ n 1))))"); > scheme.eval("(define (divisible? x y) (= (remainder x >y) 0))"); > scheme.eval("(define (sieve stream) (cons-stream >(stream-car stream) (sieve (stream-filter (lambda (x) >(not (divisible? x (stream-car stream)))) (stream-cdr >stream)))))"); > scheme.eval("(define primes (sieve >(integers-starting-from 2)))"); > scheme.eval("(define (fibgen a b) (cons-stream a >(fibgen b (+ a b))))"); > scheme.eval("(define fibs (fibgen 0 1))"); > System.out.println(scheme.eval("(stream-ref primes >100)")); > System.out.println(scheme.eval("(stream-ref primes >200)")); > System.out.println(scheme.eval("(stream-ref primes >300)")); > System.out.println(scheme.eval("(stream-ref primes >1000)")); > } >} ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://productguide.itmanagersjournal.com/