【JVM】JVM异常不打印堆栈信息 [ -XX:-OmitStackTraceInFastThrow ]
文章目录
- 一、背景
- 二、原因
- 三、 代码验证
一、背景
生产环境日志突然膨胀到100G+, 为了定位问题,所以截取了部分报错日志,
问题是 堆栈信息呢? 哪里报的NPE在哪???
信息如下:
[ERROR] 2020-12-09 09:41:50.053 - [taskAppId=TASK-1919-33805-97659]:[156] - wait task quit failed, instance id:33805, task id:97659
[ERROR] 2020-12-09 09:41:50.053 - [taskAppId=TASK-1919-34759-100696]:[154] - exception
java.lang.NullPointerException: null
[ERROR] 2020-12-09 09:41:50.053 - [taskAppId=TASK-1919-34759-100696]:[156] - wait task quit failed, instance id:34759, task id:100696
[ERROR] 2020-12-09 09:41:50.059 - [taskAppId=TASK-1917-7841-18206]:[154] - exception
java.lang.NullPointerException: null
[ERROR] 2020-12-09 09:41:50.059 - [taskAppId=TASK-1917-7841-18206]:[156] - wait task quit failed, instance id:7841, task id:18206
[ERROR] 2020-12-09 09:41:50.059 - [taskAppId=TASK-1919-33805-97659]:[154] - exception
java.lang.NullPointerException: null
二、原因
JVM中有个参数:OmitStackTraceInFastThrow,省略异常栈信息从而快速抛出异常.
JVM对一些特定的异常类型做了Fast Throw优化,如果检测到在代码里某个位置连续多次抛出同一类型异常的话,C2会决定用FastThrow方式来抛出异常,而异常Trace即详细的异常栈信息会被清空。这种异常抛出速度非常快,因为不需要在堆里分配内存,也不需要构造完整的异常栈信息。
如果禁用则使用下面的命令:
-XX:-OmitStackTraceInFastThrow
JVM源码:
//------------------------------builtin_throw----------------------------------
void GraphKit::builtin_throw(Deoptimization::DeoptReason reason, Node* arg) {bool must_throw = true;if (env()->jvmti_can_post_on_exceptions()) {// check if we must post exception events, take uncommon trap if souncommon_trap_if_should_post_on_exceptions(reason, must_throw);// here if should_post_on_exceptions is false// continue on with the normal codegen}// // If this particular condition has not yet happened at this// bytecode, then use the uncommon trap mechanism, and allow for// a future recompilation if several traps occur here.// If the throw is hot, try to use a more complicated inline mechanism// which keeps execution inside the compiled code.bool treat_throw_as_hot = false;ciMethodData* md = method()->method_data();if (ProfileTraps) {if (too_many_traps(reason)) {treat_throw_as_hot = true;}// (If there is no MDO at all, assume it is early in// execution, and that any deopts are part of the// startup transient, and don't need to be remembered.)// Also, if there is a local exception handler, treat all throws// as hot if there has been at least one in this method.if (C->trap_count(reason) != 0&& method()->method_data()->trap_count(reason) != 0&& has_ex_handler()) {treat_throw_as_hot = true;}}// If this throw happens frequently, an uncommon trap might cause// a performance pothole. If there is a local exception handler,// and if this particular bytecode appears to be deoptimizing often,// let us handle the throw inline, with a preconstructed instance.// Note: If the deopt count has blown up, the uncommon trap// runtime is going to flush this nmethod, not matter what.if (treat_throw_as_hot&& (!StackTraceInThrowable || OmitStackTraceInFastThrow)) {// If the throw is local, we use a pre-existing instance and// punt on the backtrace. This would lead to a missing backtrace// (a repeat of 4292742) if the backtrace object is ever asked// for its backtrace.// Fixing this remaining case of 4292742 requires some flavor of// escape analysis. Leave that for the future.ciInstance* ex_obj = NULL;switch (reason) {case Deoptimization::Reason_null_check:ex_obj = env()->NullPointerException_instance();break;case Deoptimization::Reason_div0_check:ex_obj = env()->ArithmeticException_instance();break;case Deoptimization::Reason_range_check:ex_obj = env()->ArrayIndexOutOfBoundsException_instance();break;case Deoptimization::Reason_class_check:if (java_bc() == Bytecodes::_aastore) {ex_obj = env()->ArrayStoreException_instance();} else {ex_obj = env()->ClassCastException_instance();}break;}if (failing()) { stop(); return; } // exception allocation might failif (ex_obj != NULL) {// Cheat with a preallocated exception object.if (C->log() != NULL)C->log()->elem("hot_throw preallocated='1' reason='%s'",Deoptimization::trap_reason_name(reason));const TypeInstPtr* ex_con = TypeInstPtr::make(ex_obj);Node* ex_node = _gvn.transform( ConNode::make(C, ex_con) );// Clear the detail message of the preallocated exception object.// Weblogic sometimes mutates the detail message of exceptions// using reflection.int offset = java_lang_Throwable::get_detailMessage_offset();const TypePtr* adr_typ = ex_con->add_offset(offset);Node *adr = basic_plus_adr(ex_node, ex_node, offset);const TypeOopPtr* val_type = TypeOopPtr::make_from_klass(env()->String_klass());// Conservatively release stores of object references.Node *store = store_oop_to_object(control(), ex_node, adr, adr_typ, null(), val_type, T_OBJECT, MemNode::release);add_exception_state(make_exception_state(ex_node));return;}}// %%% Maybe add entry to OptoRuntime which directly throws the exc.?// It won't be much cheaper than bailing to the interp., since we'll// have to pass up all the debug-info, and the runtime will have to// create the stack trace.// Usual case: Bail to interpreter.// Reserve the right to recompile if we haven't seen anything yet.assert(!Deoptimization::reason_is_speculate(reason), "unsupported");Deoptimization::DeoptAction action = Deoptimization::Action_maybe_recompile;if (treat_throw_as_hot&& (method()->method_data()->trap_recompiled_at(bci(), NULL)|| C->too_many_traps(reason))) {// We cannot afford to take more traps here. Suffer in the interpreter.if (C->log() != NULL)C->log()->elem("hot_throw preallocated='0' reason='%s' mcount='%d'",Deoptimization::trap_reason_name(reason),C->trap_count(reason));action = Deoptimization::Action_none;}// "must_throw" prunes the JVM state to include only the stack, if there// are no local exception handlers. This should cut down on register// allocation time and code size, by drastically reducing the number// of in-edges on the call to the uncommon trap.uncommon_trap(reason, action, (ciKlass*)NULL, (char*)NULL, must_throw);
}
三、 代码验证
测试代码:
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;public class OmitStackTraceInFastThrowTest {public static void main(String[] args) throws InterruptedException {NPEThread npeThread = new NPEThread();ExecutorService executorService = Executors.newFixedThreadPool(20);for (int i=0; i<Integer.MAX_VALUE; i++) {executorService.execute(npeThread);// 稍微sleep一下, 是为了不要让异常抛出太快, 导致控制台输出太快, 把有异常栈信息冲掉, 只留下fast throw方式抛出的异常Thread.sleep(2);}}
}
class NPEThread extends Thread {private static int count = 0;@Overridepublic void run() {try{System.out.println(this.getClass().getSimpleName()+"--"+(++count));String str = null;// 制造空指针NPESystem.out.println(str.length());}catch (Throwable e){e.printStackTrace();}}
}
运行时间长之后,不再打印堆栈信息,日志如下:
NPEThread--467
NPEThread--468
NPEThread--469
NPEThread--470
NPEThread--471
NPEThread--472
NPEThread--473
NPEThread--474
NPEThread--475
NPEThread--476
NPEThread--477
java.lang.NullPointerExceptionat org.apache.dolphinscheduler.api.utils.NPEThread.run(OmitStackTraceInFastThrowTest.java:28)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)at java.lang.Thread.run(Thread.java:748)
java.lang.NullPointerExceptionat org.apache.dolphinscheduler.api.utils.NPEThread.run(OmitStackTraceInFastThrowTest.java:28)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)at java.lang.Thread.run(Thread.java:748)
java.lang.NullPointerExceptionat org.apache.dolphinscheduler.api.utils.NPEThread.run(OmitStackTraceInFastThrowTest.java:28)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)at java.lang.Thread.run(Thread.java:748)
java.lang.NullPointerExceptionat org.apache.dolphinscheduler.api.utils.NPEThread.run(OmitStackTraceInFastThrowTest.java:28)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)at java.lang.Thread.run(Thread.java:748)
java.lang.NullPointerExceptionat org.apache.dolphinscheduler.api.utils.NPEThread.run(OmitStackTraceInFastThrowTest.java:28)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)at java.lang.Thread.run(Thread.java:748)
java.lang.NullPointerExceptionat org.apache.dolphinscheduler.api.utils.NPEThread.run(OmitStackTraceInFastThrowTest.java:28)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)at java.lang.Thread.run(Thread.java:748)
java.lang.NullPointerExceptionat org.apache.dolphinscheduler.api.utils.NPEThread.run(OmitStackTraceInFastThrowTest.java:28)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)at java.lang.Thread.run(Thread.java:748)
java.lang.NullPointerExceptionat org.apache.dolphinscheduler.api.utils.NPEThread.run(OmitStackTraceInFastThrowTest.java:28)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)at java.lang.Thread.run(Thread.java:748)
java.lang.NullPointerExceptionat org.apache.dolphinscheduler.api.utils.NPEThread.run(OmitStackTraceInFastThrowTest.java:28)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)at java.lang.Thread.run(Thread.java:748)
java.lang.NullPointerExceptionat org.apache.dolphinscheduler.api.utils.NPEThread.run(OmitStackTraceInFastThrowTest.java:28)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)at java.lang.Thread.run(Thread.java:748)
java.lang.NullPointerExceptionat org.apache.dolphinscheduler.api.utils.NPEThread.run(OmitStackTraceInFastThrowTest.java:28)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)at java.lang.Thread.run(Thread.java:748)
java.lang.NullPointerExceptionat org.apache.dolphinscheduler.api.utils.NPEThread.run(OmitStackTraceInFastThrowTest.java:28)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)at java.lang.Thread.run(Thread.java:748)
java.lang.NullPointerExceptionat org.apache.dolphinscheduler.api.utils.NPEThread.run(OmitStackTraceInFastThrowTest.java:28)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)at java.lang.Thread.run(Thread.java:748)
运行时间长之后,不再打印堆栈信息,日志如下:
NPEThread--9030
NPEThread--9031
NPEThread--9032
NPEThread--9033
NPEThread--9034
NPEThread--9035
NPEThread--9036
NPEThread--9037
NPEThread--9038
NPEThread--9039
NPEThread--9040
NPEThread--9041
java.lang.NullPointerException
java.lang.NullPointerException
java.lang.NullPointerException
java.lang.NullPointerException
java.lang.NullPointerException
java.lang.NullPointerException
java.lang.NullPointerException
java.lang.NullPointerException
java.lang.NullPointerException
java.lang.NullPointerException
java.lang.NullPointerException
java.lang.NullPointerException
java.lang.NullPointerException
相关文章:
【JVM】JVM异常不打印堆栈信息 [ -XX:-OmitStackTraceInFastThrow ]
文章目录 一、背景二、原因三、 代码验证 一、背景 生产环境日志突然膨胀到100G, 为了定位问题,所以截取了部分报错日志, 问题是 堆栈信息呢? 哪里报的NPE在哪??? 信息如下: [ERROR] 2020-12-09 09:41:50.053 - [taskAppIdTASK-1919-33805-97659]:[156] - wait task qu…...
第十一章 目标检测中的NMS
精度提升 众所周知,非极大值抑制NMS是目标检测常用的后处理算法,用于剔除冗余检测框,本文将对可以提升精度的各种NMS方法及其变体进行阶段性总结。 总体概要: 对NMS进行分类,大致可分为以下六种,这里是依…...
vue项目中使用vant轮播图组件(桌面端)
一. 内容简介 vue使用vant轮播图组件(桌面端) 二. 软件环境 2.1 Visual Studio Code 1.75.0 2.2 chrome浏览器 2.3 node v18.14.0 三.主要流程 3.1 安装环境 3.2 添加代码 3.3 结果展示 四.具体步骤 4.1 安装环境 先安装包 # Vue 3 项目,安装最新版 Va…...
如何做好性能压测 —— 压测环境设计和搭建!
简介:一般来说,保证执行性能压测的环境和生产环境高度一致是执行一次有效性能压测的首要原则。有时候,即便是压测环境和生产环境有很细微的差别,都有可能导致整个压测活动评测出来的结果不准确。 1. 性能环境要考虑的要素 1.1 系…...
手机弱网测试工具:Charles
我们在测试app的时候,需要测试弱网情况下的一些场景,那么使用Charles如何设置弱网呢,请看以下步骤: 前提条件: 手机和电脑要在同一局域网内 Charles连接手机抓包 一、打开Charles,点击代理,…...
Axios七大特性
Axios是一个基于Promise的HTTP客户端,用于浏览器和Node.js环境中发起HTTP请求。它有许多强大的特性,下面将介绍Axios的七大特性。 1. 支持浏览器和Node.js Axios既可以在浏览器中使用,也可以在Node.js环境中使用,提供了统一的AP…...
【机器学习基础】K-Means聚类算法
🚀个人主页:为梦而生~ 关注我一起学习吧! 💡专栏:机器学习 欢迎订阅!相对完整的机器学习基础教学! ⭐特别提醒:针对机器学习,特别开始专栏:机器学习python实战…...
Vite - 配置 - 自动修改 index.html 中的title
需求描述 在Vue3项目的开发过程中,我们为了能区分正式环境和测试环境, 通常会进行环境配置文件的区分, 例如,开发环境一个配置文件、生产环境一个配置文件。因此,我们就希望 在项目的index.html 的 title 标签中&…...
基于安卓android微信小程序美容理发店预约系统app
项目介绍 为美容院设计一个系统以减少员工的工作量就成为了想法的初始状态。紧接着对美容院进行进一步的调查发现我的想法已然落后。基本上每个美容院都以有了自己的信息系统,并且做的已经较完善了。 在这时我突然想到,现在关注美容养生的人越来越多&am…...
*** stack smashing detected ***: terminated
有一个函数返回值是bool类型,但忘了return了,编译可以通过,但是运行的时候报这个错误。...
鸿蒙系统扫盲(二):再谈鸿蒙是不是安卓套壳?
最近小米发布了澎湃OS,vivo发布了蓝OS,好像自从华为回归后,大伙都开始写自己的OS了,小米官方承认是套壳安卓,然后被大家喷了,于是鸿蒙是不是安卓套壳的话题又回到了大众的视野,今天在讨论下这个…...
PG数据中DBeaver上传csv文件作为数据表
DBeaver 是一个开源的数据库工具,还是蛮好用的,有时候需要我们上传数据做表,数据为CSV格式的,DBeaver本身自带有功能实现的。 可打开连着的数据库,找到模式,点到下面的表里,选择一个表直接导入…...
第十七篇-Awesome ChatGPT Prompts-备份-百度翻译
Awesome ChatGPT Prompts——一个致力于提供挖掘ChatGPT能力的Prompt收集网站 https://prompts.chat/ 第十六篇-Awesome ChatGPT Prompts-备份【英文】 第十七篇-Awesome ChatGPT Prompts-备份-百度翻译 【中文】 高效提示词请参考,各种场景,2023-11-16内容如下(百…...
[Android] Amazon 的 android 音视频开发文档
https://developer.amazon.com/zh/docs/fire-tv/audio-video-synchronization.html#22-getplaybackheadposition-api-level-3https://developer.amazon.com/zh/docs/fire-tv/audio-video-synchronization.html#22-getplaybackheadposition-api-level-3...
UE4基础篇十六:自定义 EQS 生成器
UE4 中的 EQS 带有一组很好的查询项生成器,但在某些情况下,您可能更喜欢根据需要创建生成器。我决定编写自己的生成器,因为我必须编写一个查询来找到查询器周围的最佳位置,但又不能太靠近它。我知道我可以添加一个距离测试来随着距离增加分数,但我什至不想考虑距查询器一定…...
轿车5+1汽车变速器变速箱同步器操纵机构机械结构设计CAD汽车工程
wx供重浩:创享日记 对话框发送:汽车变速器 获取完整论文报告说明书工程源文件 变速器工程图 操纵机构3D图 一、机械式变速器的概述及其方案的确定 1.1 变速器的功用和要求 变速器的功用是根据汽车在不同的行驶条件下提出的要求,改变发动机…...
STM32F4移植SPI注意事项
一、注意事项 可以看我之前移植的文章,那些就不提了,记得要复用,把IO复用成对应的功能io,然后还要注意时钟,看你需要的功能,去调对应的时钟,把时钟调匹配了,基本上不会有问题。 比如…...
CV计算机视觉每日开源代码Paper with code速览-2023.11.16
点击CV计算机视觉,关注更多CV干货 论文已打包,点击进入—>下载界面 点击加入—>CV计算机视觉交流群 1.【基础网络架构】ConvNet vs Transformer, Supervised vs CLIP: Beyond ImageNet Accuracy 论文地址:https://arxiv.org//pdf/23…...
Git 简介及使用(1)
目录 一、在 Linux 环境中安装 Git 1. 先检查当前服务器中是否有 Git(如果有显示如下图) 2. 安装Git 3. 然后重复第一步:查看 Git 的版本信息即可 二、Git 的初始化及配置 1. 创建目录 2. 对仓库进行初始化 3. 新增两个配置项(…...
HTTPS流量抓包分析中出现无法加载key
HTTPS流量抓包分析(TLSv1.2),这篇文章分析的比较透彻,就不班门弄斧了 https://zhuanlan.zhihu.com/p/635420027 写个小问题:RSA密钥对话框加载rsa key文件的时候注意不要在中文目录下,否则会提示:“Enter the passwor…...
eNSP-Cloud(实现本地电脑与eNSP内设备之间通信)
说明: 想象一下,你正在用eNSP搭建一个虚拟的网络世界,里面有虚拟的路由器、交换机、电脑(PC)等等。这些设备都在你的电脑里面“运行”,它们之间可以互相通信,就像一个封闭的小王国。 但是&#…...
多云管理“拦路虎”:深入解析网络互联、身份同步与成本可视化的技术复杂度
一、引言:多云环境的技术复杂性本质 企业采用多云策略已从技术选型升维至生存刚需。当业务系统分散部署在多个云平台时,基础设施的技术债呈现指数级积累。网络连接、身份认证、成本管理这三大核心挑战相互嵌套:跨云网络构建数据…...
Linux 文件类型,目录与路径,文件与目录管理
文件类型 后面的字符表示文件类型标志 普通文件:-(纯文本文件,二进制文件,数据格式文件) 如文本文件、图片、程序文件等。 目录文件:d(directory) 用来存放其他文件或子目录。 设备…...
【CSS position 属性】static、relative、fixed、absolute 、sticky详细介绍,多层嵌套定位示例
文章目录 ★ position 的五种类型及基本用法 ★ 一、position 属性概述 二、position 的五种类型详解(初学者版) 1. static(默认值) 2. relative(相对定位) 3. absolute(绝对定位) 4. fixed(固定定位) 5. sticky(粘性定位) 三、定位元素的层级关系(z-i…...
【python异步多线程】异步多线程爬虫代码示例
claude生成的python多线程、异步代码示例,模拟20个网页的爬取,每个网页假设要0.5-2秒完成。 代码 Python多线程爬虫教程 核心概念 多线程:允许程序同时执行多个任务,提高IO密集型任务(如网络请求)的效率…...
多模态大语言模型arxiv论文略读(108)
CROME: Cross-Modal Adapters for Efficient Multimodal LLM ➡️ 论文标题:CROME: Cross-Modal Adapters for Efficient Multimodal LLM ➡️ 论文作者:Sayna Ebrahimi, Sercan O. Arik, Tejas Nama, Tomas Pfister ➡️ 研究机构: Google Cloud AI Re…...
大语言模型(LLM)中的KV缓存压缩与动态稀疏注意力机制设计
随着大语言模型(LLM)参数规模的增长,推理阶段的内存占用和计算复杂度成为核心挑战。传统注意力机制的计算复杂度随序列长度呈二次方增长,而KV缓存的内存消耗可能高达数十GB(例如Llama2-7B处理100K token时需50GB内存&a…...
laravel8+vue3.0+element-plus搭建方法
创建 laravel8 项目 composer create-project --prefer-dist laravel/laravel laravel8 8.* 安装 laravel/ui composer require laravel/ui 修改 package.json 文件 "devDependencies": {"vue/compiler-sfc": "^3.0.7","axios": …...
佰力博科技与您探讨热释电测量的几种方法
热释电的测量主要涉及热释电系数的测定,这是表征热释电材料性能的重要参数。热释电系数的测量方法主要包括静态法、动态法和积分电荷法。其中,积分电荷法最为常用,其原理是通过测量在电容器上积累的热释电电荷,从而确定热释电系数…...
算法:模拟
1.替换所有的问号 1576. 替换所有的问号 - 力扣(LeetCode) 遍历字符串:通过外层循环逐一检查每个字符。遇到 ? 时处理: 内层循环遍历小写字母(a 到 z)。对每个字母检查是否满足: 与…...
