---------- Forwarded message ----------
From: Henry Rich <[email protected]>
Date: 30 April 2016 at 08:45
Subject: Tall stack crash fixed; design review needed
To: [email protected]
I have made progress on the years-old crash that occurred sometimes when a
recursive definition went too deep, for example
p=: 3 : 0
m=.(3 #:@:+ [: i.@<:&.-: 2^#) y
c=.m <@:p;.2"1 y
)
p;:'a b c'
The JE problem was a buffer overrun caused by an off-by-one error, and an
ASSERT erroneously placed between an FDEPINC/FDEPDEC pair; also an
underestimate of the stack size required by an explicit recursion.
With those bugs fixed, I can handle the case above, but better analysis is
required, and maybe a design change.
In the example above, the part that gets repeated is <@:p;.2"1. From
measurement, I find that increasing the stack size by 12MB allows 3400 more
recursions before failure. That means each recursion takes around 3500
bytes on the stack. That seemed high, so I looked into it, and counting
the space for stacked variables I found that (") uses around 600 bytes,
(;.) around 400, calling an explicit definition around 800. There are
other miscellaneous function to take up the rest of the stack space used.
Most functions take around 50-100 bytes.
The problem, then, is that a recursion to an explicit definition takes
who-knows-how-much space. I don't see any good way to figure that out, so
I have changed the allowed numbers of explicit/tacit recursions from
10000/20000 to 2000/20000. I hope that's OK. It leaves ample headroom
with a 12MB stack on the program shown above. It won't be enough if the
explicit recursion occurs deep inside an expression.
Should I try to calculate the maximum amount of stack-space used by a
recursion, and adjust the allowed stack depth accordingly?
While testing, an interesting case arose. The program correctly detected
stack error and signaled, but one of the things on the stack was execution
on a cell of fills. This captured the error and reset it, using a 0 for
the result. This result caused the rest of the recursion to end without
error, so the result was empty with no error.
I changed the fill-cell code to treat stack error as fatal and causing an
error even when it is executed on a cell of fills.
Henry
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm