无法打印出Error堆栈信息

  • 现象,在查看线上的错误日志的时候,看到一些报空指针的异常,却没有堆栈信息,赶紧去看代码是谁写的,捕获异常不打印堆栈信息,还让怎么修复。一看惊呆了,居然是自己。而且,明明已经是logger.error("xxxxxxxError", e),为什么不打印堆栈呢。
  • 经过查询资料才发现:JIT编译器对异常进行了优化,如果在同一个位置多次抛出相同的异常,则会采用FastThrow的方案来处理——抛出一个之前分配好的,类型匹配的异常对象。优点也很明显,抛出速度特别快,对服务器影响很小,不需要额外的分配内存。成本就是看不到堆栈信息了。
  • 解决:
    1. 知道了原理,当然可以直接去找上一次服务器重启的时间节点,向后找最早出现异常的点,那里是有堆栈信息的;
    2. 也可以禁止这种模式,添加额外的JVM参数:-XX:-OmitStackTraceInFastThrow ;(不推荐)
  • 附:
    1. 官方解释:
      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.

       

转载于:https://www.cnblogs.com/cooqer/p/10991050.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值