As an update, I created https://github.com/rgoers/stackwalker-vs-Reflection_getCallerClass to compare Java 8 to Java 9. The openjdk team has opened an issue as Throwable is indeed slower in Java 9. However, walking the stack to locate the caller's StackTraceElement with StackWalker is significantly faster than walking the Throwable in Java 8, at least on my computer. |