qiuwei / jing-trang

Automatically exported from code.google.com/p/jing-trang
Other
1 stars 1 forks source link

StackOverflowError in IdTypeMapBuilder on large schemas #162

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
When Jing is used with the TEI schemas the following error appears:

Exception in thread "main" java.lang.StackOverflowError
    at com.thaiopensource.relaxng.pattern.IdTypeMapBuilder$BuildFunction.caseChoice(IdTypeMapBuilder.java:101)
    at com.thaiopensource.relaxng.pattern.ChoicePattern.apply(ChoicePattern.java:24)
    at com.thaiopensource.relaxng.pattern.IdTypeMapBuilder$BuildFunction.caseChoice(IdTypeMapBuilder.java:126)
    at com.thaiopensource.relaxng.pattern.IdTypeMapBuilder$BuildFunction.caseChoice(IdTypeMapBuilder.java:101)
    at com.thaiopensource.relaxng.pattern.ChoicePattern.apply(ChoicePattern.java:24)
    at com.thaiopensource.relaxng.pattern.IdTypeMapBuilder$BuildFunction.caseChoice(IdTypeMapBuilder.java:126)
    at com.thaiopensource.relaxng.pattern.IdTypeMapBuilder$BuildFunction.caseChoice(IdTypeMapBuilder.java:101)
    at com.thaiopensource.relaxng.pattern.ChoicePattern.apply(ChoicePattern.java:24)
    at com.thaiopensource.relaxng.pattern.IdTypeMapBuilder$BuildFunction.caseChoice(IdTypeMapBuilder.java:126)
    at com.thaiopensource.relaxng.pattern.IdTypeMapBuilder$BuildFunction.caseChoice(IdTypeMapBuilder.java:101)
    at com.thaiopensource.relaxng.pattern.ChoicePattern.apply(ChoicePattern.java:24)
...
and so on...

That is caused by the way the BuildFunction visits the grammar pattern, on an 
element pattern it visits that pattern from that point instead of recording it, 
and thus we get to consume all the stack. 

The current solution is to increase the stack size for the Java virtual machine 
but as the schema evolves larger values are needed. Also, if used from an 
application that starts multiple threads this solution is not the best, as the 
large stack will be applied to all the threads, although it is not needed for 
most of them. An application can control the stack size per thread but that 
means that the application should implement this specifically for Jing.

We can avoid these issues by recording the element patterns instead of applying 
the a new BuildFunction and then we can iterate the recorded element patterns 
and apply the function for each, thus avoiding the deep recursion that causes 
the stack overflow.

Original issue reported on code.google.com by georgebina76 on 27 Oct 2012 at 5:04

GoogleCodeExporter commented 8 years ago
Fixed in r2361.
We record the element patterns and then apply the build function on them, thus 
avoiding the deep recursion that appeared when applying the build function as 
we encountered them.

Original comment by georgebina76 on 27 Oct 2012 at 6:07