Discussion:
SRFI 41 "times3" example exhausts memory?
Sudarshan S Chawathe
2018-04-25 21:13:49 UTC
Permalink
I had occasion to revisit the SRFI 41 streams library in Kawa and
decided to try out a problematic "times3" example noted in the SRFI
document. It ran successfully for small values of the argument but gave
a OutOfMemoryError when invoked as (times3 #e1e7). (Details below.)

I am not sure if this is a known limitation of the Kawa implementation
of SRFI 41 or if the problem is elsewhere, which is why I am not
reporting it as a bug/issue on Gitlab.

In any case, I thought I'd mention the issue here on the mailing list to
check if others have any thoughts on the matter.

Regards,

-chaw

** test.scm:

(import (scheme base)
(srfi 41))

(define (times3 n)
(stream-ref
(stream-filter
(lambda (x)
(zero? (modulo x n)))
(stream-from 0))
3))

(display (times3 #e1e7))
(newline)

** trace:

$ time kawa test.scm
Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded
at gnu.expr.CompiledProc.makeResultToObject(CompiledProc.java:41)
at gnu.kawa.slib.StreamsDerived$frame16.<init>(StreamsDerived.scm)
at gnu.kawa.slib.StreamsDerived$frame15.lambda35streamFrom(StreamsDerived.scm:169)
at gnu.kawa.slib.StreamsDerived$frame16.lambda38(StreamsDerived.scm:170)
at gnu.kawa.slib.StreamsDerived$frame16.lambda38$check(StreamsDerived.scm:170)
at java.lang.invoke.LambdaForm$DMH/702846463.invokeStatic_LL_L(LambdaForm$DMH)
at java.lang.invoke.LambdaForm$MH/1169794610.invokeExact_MT(LambdaForm$MH)
at gnu.mapping.CallContext.runUntilValue(CallContext.java:656)
at gnu.mapping.Procedure.apply0(Procedure.java:142)
at gnu.mapping.Promise.getValue(Promise.java:80)
at gnu.kawa.slib.StreamsPrimitive.isStreamNull(StreamsPrimitive.scm:52)
at gnu.kawa.slib.StreamsDerived$frame14.lambda31(StreamsDerived.scm:145)
at gnu.kawa.slib.StreamsDerived$frame14.lambda31$check(StreamsDerived.scm:144)
at java.lang.invoke.LambdaForm$DMH/1316557528.invokeStatic_LL_L(LambdaForm$DMH)
at java.lang.invoke.LambdaForm$MH/1169794610.invokeExact_MT(LambdaForm$MH)
at gnu.mapping.CallContext.runUntilValue(CallContext.java:656)
at gnu.mapping.Procedure.apply0(Procedure.java:142)
at gnu.mapping.Promise.getValue(Promise.java:80)
at gnu.kawa.slib.StreamsPrimitive.isStreamNull(StreamsPrimitive.scm:52)
at gnu.kawa.slib.StreamsDerived.streamRef(StreamsDerived.scm:275)
at test.times3(test.scm:10)
at test.times3$check(test.scm:4)
at java.lang.invoke.LambdaForm$DMH/284720968.invokeStaticInit_LL_L(LambdaForm$DMH)
at java.lang.invoke.LambdaForm$MH/1169794610.invokeExact_MT(LambdaForm$MH)
at gnu.mapping.CallContext.runUntilValue(CallContext.java:656)
at gnu.mapping.Procedure.apply1(Procedure.java:148)
at test.run(test.scm:12)
at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:289)
at gnu.expr.CompiledModule.evalModule(CompiledModule.java:42)
at gnu.expr.CompiledModule.evalModule(CompiledModule.java:60)
at kawa.Shell.runFile(Shell.java:565)
at kawa.Shell.runFileOrClass(Shell.java:468)

real 6m12.696s
user 17m16.376s
sys 0m2.188s

** versions

Kawa 3.0 (git describe: 3.0-87-g5fa934dad-dirty)
Copyright (C) 2018 Per Bothner

openjdk version "1.8.0_162"
OpenJDK Runtime Environment (build 1.8.0_162-8u162-b12-1~deb9u1-b12)
OpenJDK 64-Bit Server VM (build 25.162-b12, mixed mode)

Loading...