How to overcome stack overflow problems (Was: RE: [xsl] Different Colors for Alternating Rows)

Subject: How to overcome stack overflow problems (Was: RE: [xsl] Different Colors for Alternating Rows)
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Wed, 25 Jun 2003 03:51:40 -0700 (PDT)
> > Jarno, 
> >  
> > Thank you. The second approach did not work. It seemd to  
> > create an endless loop. Here is the error that I got, which  
> > repeated endlessly: 
> >  
> > at  
> > weblogic.apache.xalan.templates.ElemChoose.execute(ElemChoose. 
> > java:152) 
> >         at  
> 
> It's probably a stack overflow rather than an endless loop. Try it on
> Saxon (7.x), which should detect this template as being tail-recursive
> and therefore avoid this problem.

Xalan J starting from version 2.4 has this problem. This is from their FAQ:

"Xalan-Java dies with a java.lang.StackOverflowError when I run a deeply recursive
stylesheet. The same stylesheet worked fine in the past (or on other machines).
What's happening? 
 
  

That may not be our fault. As of JDK 1.3.x, many Java Virtual Machine publishers
reduced the default size of a thread's call stack from 1MB to 256KB. This allows
more threads to run simultaneously, but it means that each thread is more limited in
how deeply its function calls can be nested.

Some JVMs may offer an option that allows you to raise this limit. For example, in
Sun JDK 1.3.1 you can start JVM with the -Xss1m option to allow each thread to use a
full megabyte. In IBM's JDK you can start with the -Xss1m and -Xoss1m options. Other
JVMs may set this in other ways, or may not allow you to control it at all; check
the documentation on your system for details.

Note too that on some platforms 1MB is an architectural upper limit on the stack
size, so setting -Xss2m (or equivalent) may not allow deeper recusion than -Xss1m."

There are two things to note here:

1. Other XSLT processors written in Java like Saxon or JD do not have this problem.
Therefore, I do not believe the statement that "That may not be our fault".

2. One can still eliminate this problem by using DVC-style recursion. More on DVC
(Divide and Conquer) can be found here:

http://www.topxml.com/code/default.asp?p=3&id=v20020107050418

An example of a DVC algorithm for finding the maximum value of any node in a
node-set can be found here:

http://www.topxml.com/code/default.asp?p=3&id=v20030314165921


3. In FXSL-1.2 many calls to recursive templates 
(e.g. in test-strSplit-to-Lines.xsl) have been replaced with calls to their DVC
variants in order to eliminate exactly this problem, that some Xalan users have been
complaining about.





=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread