RFR: 8344165: Trace exceptions with a complete call-stack [v13]
Ioi Lam
iklam at openjdk.org
Wed Jun 25 22:41:53 UTC 2025
> This PR makes it easier to analyze exceptions without modifying the JVM or the app to print call stacks:
>
> Excerpt from the test case ExceptionsTest.java.
>
>
> [0.042s][info][exceptions] Exception <a 'java/lang/RuntimeException'{0x0000000474019530}: Test exception 1 for logging>
> [ ] thrown in interpreter method <{method} {0x000079e52c4005b0} 'bar' '()V' in 'ExceptionsTest$InternalClass'>
> [ ] at bci 9 for thread 0x000079e58c02c7b0 (main)
> [0.042s][info][exceptions,stacktrace] Exception <a 'java/lang/RuntimeException'{0x0000000474019530}: Test exception 1 for logging>
> [0.042s][info][exceptions,stacktrace] at ExceptionsTest$InternalClass.bar(ExceptionsTest.java:110)
> [0.042s][info][exceptions,stacktrace] at ExceptionsTest$InternalClass.foo(ExceptionsTest.java:105)
> [0.042s][info][exceptions,stacktrace] at ExceptionsTest$InternalClass.main(ExceptionsTest.java:100)
> [0.042s][info][exceptions ] Found matching handler for exception of type "java.lang.RuntimeException" in method "bar" at BCI: 10
> Exception 1 caught.
>
>
> - Note that the old `[exceptions]` log is triggered by `InterpreterRuntime::exception_handler_for_exception()` and prints one level of the stack while the interpreter is looking for a handler. However, once a handler is found (inside `bar()`), the `[exceptions]` log terminates, and we do not know about the `foo()` or `main()` methods.
>
> - The `[exceptions,stacktrace]` log is printed only when an exception is thrown:
> - By an `_athrow` bytecode. See comments around `Exceptions::log_exception_stacktrace(Handle exception, methodHandle method, int bci)`
> - By native code in Exceptions::special_exception() and and Exceptions::_throw()).
>
> **Concurrent Exceptions**
>
> Neither the old `[exceptions]` or the new `[exceptions,stacktrace]` logs distinguish between multiple exceptions that are thrown and handled concurrently. The users should use something like `-Xlog:exceptions,exceptions+stack::tags,tid` to include the thread ID into the log output, and use an external tool (such as a script) to demultiplex the logs.
Ioi Lam has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains 15 additional commits since the last revision:
- Merge branch 'master' into 8358080-print-thread-stack-with-xlog-exceptions-trace
- Fix crash in runtime/logging/RedefineClasses.java: cannot print stack trace in Exceptions::special_exception()
- @coleenp comments: Removed dead code
- @coleenp and @dholmes-ora comments
- @coleenp comments; Also, use ProcessTools.executeProcess() to log the output in files
- refactor
- Reimplement -- print stack trace only when it is a known throwing site
- @dholmes-ora comments -- removed printing of output.getStdout() from test
- Print callstack for rethrown exceptions
- @dholmes-ora comments - use JavaThread::current() instead
- ... and 5 more: https://git.openjdk.org/jdk/compare/963ea0c1...3eb7c622
-------------
Changes:
- all: https://git.openjdk.org/jdk/pull/25522/files
- new: https://git.openjdk.org/jdk/pull/25522/files/6b57611d..3eb7c622
Webrevs:
- full: https://webrevs.openjdk.org/?repo=jdk&pr=25522&range=12
- incr: https://webrevs.openjdk.org/?repo=jdk&pr=25522&range=11-12
Stats: 82332 lines in 1637 files changed: 44217 ins; 24426 del; 13689 mod
Patch: https://git.openjdk.org/jdk/pull/25522.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/25522/head:pull/25522
PR: https://git.openjdk.org/jdk/pull/25522
More information about the hotspot-dev
mailing list