强制要求JVM始终抛出含堆栈的异常(-XX:-OmitStackTraceInFastThrow)
2015-07-27 16:55
232 查看
问题描述:生产环境抛异常,但却没有将堆栈信息输出到日志,可以确定的是日志输出时用的是log.error("xx发生错误", e)
问题分析:它跟JDK5的一个新特性有关,对于一些频繁抛出的异常,JDK为了性能会做一个优化,即JIT重新编译后会抛出没有堆栈的异常
而在使用-server模式时,该优化选项是开启的,因此在频繁抛出某个异常一段时间后,该优化开始起作用,即只抛出没有堆栈的异常信息
问题解决:由于该优化是在JIT重新编译后才起作用,因此起初抛出的异常还是有堆栈的,所以可以查看较旧的日志,寻找完整的堆栈信息
另一个解决办法是暂时禁用该优化,即强制要求每次都要抛出有堆栈的异常,幸好JDK提供了通过配置JVM参数的方式来关闭该优化
即-XX:-OmitStackTraceInFastThrow,便可禁用该优化了(注意选项中的减号,加号则表示启用)
官方说明:The compiler in the server VM now provides correct stack backtraces for all "cold" built-in exceptions.
For performance purposes, when such an exception is thrown a few times, the method may be recompiled.
After recompilation, the compiler may choose a faster tactic using preallocated exceptions that do not provide a stack trace.
To disable completely the use of preallocated exceptions, use this new flag: -XX:-OmitStackTraceInFastThrow.
问题分析:它跟JDK5的一个新特性有关,对于一些频繁抛出的异常,JDK为了性能会做一个优化,即JIT重新编译后会抛出没有堆栈的异常
而在使用-server模式时,该优化选项是开启的,因此在频繁抛出某个异常一段时间后,该优化开始起作用,即只抛出没有堆栈的异常信息
问题解决:由于该优化是在JIT重新编译后才起作用,因此起初抛出的异常还是有堆栈的,所以可以查看较旧的日志,寻找完整的堆栈信息
另一个解决办法是暂时禁用该优化,即强制要求每次都要抛出有堆栈的异常,幸好JDK提供了通过配置JVM参数的方式来关闭该优化
即-XX:-OmitStackTraceInFastThrow,便可禁用该优化了(注意选项中的减号,加号则表示启用)
官方说明:The compiler in the server VM now provides correct stack backtraces for all "cold" built-in exceptions.
For performance purposes, when such an exception is thrown a few times, the method may be recompiled.
After recompilation, the compiler may choose a faster tactic using preallocated exceptions that do not provide a stack trace.
To disable completely the use of preallocated exceptions, use this new flag: -XX:-OmitStackTraceInFastThrow.
相关文章推荐
- 好久不发blog
- 【HDU 5312】Sequence(数学问题)
- python中string的操作函数
- 获取当前系统的时间
- bzoj2844: albus就是要第一个出场
- HttpContext
- Universal Extractor各类流氓安装程序克星
- Souvenir
- 随机排列问题
- 2008 Asia Regional Beijing (网络流+树状数组+贪心)hdu2485 - 2494
- 杭电1022 Train Problem I
- 数字滤波器实现(mantlab+C语言)
- 使用nodejs+mongodb+百度开放云开发微信或web应用
- (初识)UrlRewriteFilter的使用
- ios UITableview 刷新某一个cell 或 section
- Spring MVC之@RequestMapping 详解
- 人性化显示发布时间
- CodeForces 296C Greg and Array (线段树)
- 指向字符串的指针为何不能用来修改此字符串(c语言)http://blog.sina.com.cn/s/blog_68ff96b70101him1.html
- 操作系统调度算法分析