RFR: 8344165: Trace exceptions with a complete call-stack [v5]

Ioi Lam iklam at openjdk.org
Mon Jun 9 23:21:46 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.038s][info][exceptions           ] Exception <a 'java/lang/RuntimeException'{0x0000000474019b70}: Test exception 2 for logging>
> [                                   ]  thrown in interpreter method <{method} {0x00007113d0400718} 'bar2' '()V' in 'ExceptionsTest$InternalClass'>
> [                                   ]  at bci 9 for thread 0x000071142c02c7b0 (main)
> [0.038s][info][exceptions,stacktrace] 	at ExceptionsTest$InternalClass.bar2(ExceptionsTest.java:127)
> [0.038s][info][exceptions,stacktrace] 	at ExceptionsTest$InternalClass.foo2(ExceptionsTest.java:120)
> [0.038s][info][exceptions,stacktrace] 	at ExceptionsTest$InternalClass.main(ExceptionsTest.java:103)
> [0.038s][info][exceptions           ] Exception <a 'java/lang/RuntimeException'{0x0000000474019b70}: Test exception 2 for logging>
> [                                   ]  thrown in interpreter method <{method} {0x00007113d0400650} 'foo2' '()V' in 'ExceptionsTest$InternalClass'>
> [                                   ]  at bci 0 for thread 0x000071142c02c7b0 (main)
> [0.038s][info][exceptions           ] Found matching handler for exception of type "java.lang.RuntimeException" in method "foo2" at BCI: 6
> Exception 2 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 `foo()`), the `[exceptions]` log terminates, and we do not know about the `main()` method.
> 
> - The `[exceptions,stacktrace]` log tries to omit duplicated stack traces -- the stack is printed only the first time when the exception is seen by the logging code (inside `bar2()`).
> 
> **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.
> 
> **Remaining Issues**
> 
> 1. `_last_logged_exception` remembers only one exception. Concurrent exceptions may cause the stack to be printed repeatedly. This can be fixed by remembering the exception for each thread (by adding a field into `JavaThread`). Probably i...

Ioi Lam has updated the pull request incrementally with one additional commit since the last revision:

  Avoid printing the same stack trace over and over again

-------------

Changes:
  - all: https://git.openjdk.org/jdk/pull/25522/files
  - new: https://git.openjdk.org/jdk/pull/25522/files/39839d51..540b2da3

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=25522&range=04
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=25522&range=03-04

  Stats: 55 lines in 4 files changed: 45 ins; 0 del; 10 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