Skip to content

Commit

Permalink
fix: CtQueryImpl handles well preallocated exceptions done by JVM opt…
Browse files Browse the repository at this point in the history
…imization (#1759)
  • Loading branch information
pvojtechovsky authored and monperrus committed Nov 29, 2017
1 parent 9e92cc8 commit 24e7672
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/main/java/spoon/reflect/visitor/chain/CtQueryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,22 @@ protected void onClassCastException(ClassCastException e, Object input) {
}
//we can detect whether CCE was thrown in client's code (unexpected - must be rethrown) or Query engine (expected - has to be ignored)
StackTraceElement[] stackEles = e.getStackTrace();
if (stackEles.length == 0) {
/*
* The java runtime detected that this ClassCastException is thrown often and recompiled code to use faster pre-alocated exception,
* which doesn't provide stacktrace.
* So exceptions, which doesn't provide stacktrace can be ignored too, because they were already ignored before many times.
*
* See http://www.oracle.com/technetwork/java/javase/relnotes-139183.html#vm
*---------------------------------------------------------------------------------------------------------------
* 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.
*---------------------------------------------------------------------------------------------------------------
*/
return;
}
StackTraceElement stackEle = stackEles[indexOfCallerInStack];
if (stackEle.getMethodName().equals(cceStacktraceMethodName) && stackEle.getClassName().equals(cceStacktraceClass)) {
/*
Expand Down

0 comments on commit 24e7672

Please sign in to comment.