1. 程式人生 > >NullPointerException列印太多了,就有可能被jdk優化,不列印堆疊資訊

NullPointerException列印太多了,就有可能被jdk優化,不列印堆疊資訊

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

.

這裡的"cold",個人以為是與hotspot VM中hot相對的意思,意思是非熱點內建異常。如果異常被丟擲數次,就變成”hot“了,這時就會丟失異常資訊,因為這時的異常是預先分配的。

在查詢資料的時候,發現淘寶定製的vm對這個功能有個開關,可以動態切換是否禁用此項優化。

https://blog.csdn.net/taotao4/article/details/43918131