Relates :
|
|
Relates :
|
|
Relates :
|
In Throwable.getOurStackTrace(), the JDK makes an downcall to the JVM to get the stack trace depth, and once for each element of the stacktrace element. On the vm side, we have to traverse the backtrace chunks for each element. int depth = getStackTraceDepth(); stackTrace = new StackTraceElement[depth]; for (int i = 0; i < depth; i++) stackTrace[i] = getStackTraceElement(i); If we add a depth field in the Throwable object when creating the stack trace, getStackTraceDepth can use that to create an array of StackTraceElement and call the JVM to fill in all the elements: int depth = getStackTraceDepth(); stackTrace = new StackTraceElement[depth]; for (int i = 0; i < depth; i++) { stackTrace[i] = new StackTraceElement(); } getStackTraceElements(stackTrace); This would clean out the native code and allow some sharing with code that's being prototyped in the StackWalk API code using a simplified StackTraceElement::fill_in(). Also walking the internal format for Throwable.backtrace in the jvm can be simplified. It also improves performance of Throwable.getStackTrace() and printStackTrace. Using 100 stack trace elements in the microbenchmark for throwable: JDK8Benchmarks.testThrowableGetStackTrace 100 avgt 20 66830.815 �� 474.345 ns/op vs. JDK8Benchmarks.testThrowableGetStackTrace 100 avgt 20 59471.911 �� 540.100 ns/op