Java: Stackoverflow in finite recursion

妖精的绣舞 提交于 2019-12-12 04:27:59

问题


I wrote a javaCC parser for some propositional logic expressions. The expressions can get pretty long, 30k many characters.

When I parse such big expressions, I get a stack-overflow exception.

Is there maybe some VM parameter which determines the stack size?

Or what would you do in such cases?

Thanks


回答1:


Yes, use the -Xss parameter. e.g.:

java -Xss4m Blah

sets the stack-size to 4MB.




回答2:


While you can alter the stack size as per Oli's answer, I would suggest you try to look for an alternative approach which doesn't recurse so deeply. For example, you might want to build a stack or queue of "results so far" or whatever, to mimic the recursion but using heap space instead of using stack space. Increasing the VM stack size always strikes me as a "solution" which is just delaying the problem a bit.

(It also means that if you end up with stack traces, they'll be monstrous... whereas if you use appropriate diagnostics for the stack of "things you're looking at" you can end up with data-driven diagnostics instead of ones based on stack frames.)



来源:https://stackoverflow.com/questions/7214309/java-stackoverflow-in-finite-recursion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!