Java: Stackoverflow in finite recursion

I wrote a javaCC parser for some propositional boolean expressions. Expressions can be quite long, 30k characters.

When I parse such large expressions, I get an exception.

Could there be some VM parameter that determines the stack size?

Or what would you do in such cases?

thank

0


source to share


2 answers


Yes, use the parameter -Xss

. eg:.

java -Xss4m Blah

      



sets the stack size to 4 MB.

+4


source


While you can resize the stack as per Oli's answer, I would encourage you to try and find an alternative approach that is not as deeply recursive. For example, you might want to create a stack or a "results so far" queue or something else to simulate recursion, but using empty space instead of using stack space. Increasing the VM stack size always strikes me as a "solution" that delays the problem a bit.



(This also means that if you end the stack trace, they will be monstrous ... whereas if you use the appropriate diagnostics for the "things you are looking at" stack, you can end up with data diagnostics instead of units based on stack frames. )

+1


source







All Articles