RFR: 8358080: Print thread stack with -Xlog:exceptions+stacktrace [v4]
David Holmes
dholmes at openjdk.org
Fri May 30 06:49:51 UTC 2025
On Thu, 29 May 2025 23:00:29 GMT, Ioi Lam <iklam at openjdk.org> wrote:
>> This makes it easier to analyze exceptions without modifying the JVM or the app to print call stacks:
>>
>>
>> $ java -Xlog:exceptions,exceptions+stacktrace -cp foo.jar Foo
>> [2.047s][info ][exceptions] Exception <a 'java/lang/NullPointerException'{0x00000004736ab200}>
>> [ ] thrown in interpreter method <{method} {0x000070488c9f2a50} 'isLoggable' '(Ljava/lang/System$Logger$Level;)Z' in 'jdk/internal/logger/AbstractLoggerWrapper'>
>> [ ] at bci 5 for thread 0x000070499802e730 (DestroyJavaVM)
>> [2.048s][info][exceptions,stacktrace] at jdk.internal.logger.AbstractLoggerWrapper.isLoggable([java.base at 25-internal](mailto:java.base at 25-internal)/AbstractLoggerWrapper.java:68)
>> [2.048s][info][exceptions,stacktrace] at java.lang.ProcessBuilder.start([java.base at 25-internal](mailto:java.base at 25-internal)/ProcessBuilder.java:1093)
>> [2.048s][info][exceptions,stacktrace] at java.lang.ProcessBuilder.start([java.base at 25-internal](mailto:java.base at 25-internal)/ProcessBuilder.java:1044)
>> [2.048s][info][exceptions,stacktrace] at jdk.internal.misc.CDS$ProcessLauncher.execWithJavaToolOptions([java.base at 25-internal](mailto:java.base at 25-internal)/CDS.java:548)
>
> Ioi Lam has updated the pull request incrementally with one additional commit since the last revision:
>
> Use -Xlog:exceptions+stacktrace instead; fixed typo in comments
src/hotspot/share/utilities/exceptions.cpp line 620:
> 618: if (st.is_enabled()) {
> 619: Thread* t = Thread::current_or_null();
> 620: if (t != nullptr && t->is_Java_thread()) { // sanity
Do we need this? If we just rely on assertions then all we need is to call `JavaThread::current`.
test/hotspot/jtreg/runtime/logging/ExceptionsTest.java line 48:
> 46: static void analyzeOutputOn(ProcessBuilder pb) throws Exception {
> 47: OutputAnalyzer output = new OutputAnalyzer(pb.start());
> 48: System.out.println(output.getStdout());
Debugging code?
If you really want to always print the output then the more common pattern is to use `out.reportDiagnosticSummary()` after all the checks have been done and so the test has passed (failing tests will print it anyway).
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25522#discussion_r2115247333
PR Review Comment: https://git.openjdk.org/jdk/pull/25522#discussion_r2115249418
More information about the hotspot-dev
mailing list