java溢出 事件触发,如何扩展Java堆栈跟踪的大小看堆栈的底部? (触发堆栈溢出)...

In Java, is there any way to view the complete, untruncated stack trace (e.g. by increasing the number of frames recorded), or otherwise get at the bottom of a stack trace? Normally the stack trace is truncated from the top at 1024 frames worth, but for a stack overflow problem this is fairly worthless as you really need to see who made the call that triggered the recursion, down near the bottom. Much better would truncation in the middle of the stack, but evidently Sun's JVM isn't smart enough to do this.

Perhaps even some special Sun-specific flags? I tried reducing the stack size to the minimum allowable (-Xss1000) but that's still more than 1024 frames worth.

In my case, I'm trying to debug a stack overflow that occurs in a Hadoop mapper, but only when running on really large input. I assume the problem comes because a recursive operation (Scala's foldRight) is being done on a really, really large linked list, and I need to rewrite it non-recursively ... but I need to know who made the call to foldRight. This is a basic routine called directly and indirectly in a lot of places and there's lots and lots of code out there that I'm working with, so this is highly non-obvious.

解决方案

Try the -XX:MaxJavaStackTraceDepth JVM option.

Here is a description from Stas's Blog

Max. no. of lines in the stack trace for Java exceptions (0 means all).

With Java > 1.6, value 0 really means 0. value -1 or any negative number must be specified to print all the stack (tested with 1.6.0_22, 1.7.0 on Windows).

With Java <= 1.5, value 0 means everything, JVM chokes on negative number (tested with 1.5.0_22 on Windows).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值