On Wed, 25 Oct 2023 21:08:01 GMT, Leonid Mesnik <lmes...@openjdk.org> wrote:
> The jtreg starts the main thread in a separate ThreadGroup and checks > unhandled exceptions for this group. However, it doesn't catch all unhandled > exceptions. There is a jtreg issue for this > https://bugs.openjdk.org/browse/CODETOOLS-7903526. > Catching such issues for virtual threads is important because they are not > included in any groups. So this fix implements the handler for the test > thread factory. > > A few tests start failing. > > The test > serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorVMEventsTest.java > has testcases for platform and virtual threads. So, there is there's no need > to run it with the thread factory. > > The test > java/lang/Thread/virtual/ThreadAPI.java > tests UncaughtExceptionHandler and virtual threads. No need to run it with a > thread factory. > > Test > test/jdk/java/util/concurrent/tck/ThreadTest.java is updated to not check the > default empty handler. > > Probably, we need some common approach about dealing with the > UncaughtExceptionHandler in jtreg. > Hello Leonid, looking at the changes in this PR, what's being proposed is > that when jtreg launches tests through a virtual thread, then this wrapping > code will set a JVM level UncaughtExceptionHandler by calling > Thread.setDefaultUncaughtExceptionHandler(...). The implementation of this > UncaughtExceptionHandler calls System.exit(1). Wouldn't that kill the test > VM? I think that would then impact everything else including jtreg report > generation and such for the test, isn't it? The jtreg correctly reports such failures. It is expected that JVM might fail. The only difference is that the reason for failure is System.exit(1) and the exception. > I had a look at https://bugs.openjdk.org/browse/JDK-8318839 but it doesn't > have enough details to help understand what currently happens when a test > launched through a virtual thread from jtreg throws an uncaught exception. > How/what gets reported for that test execution? The jtreg correctly catches and reports failures thrown by the main virtual thread. However, it ignores exceptions thrown by any other threads started by the test. For platform threads, jtreg uses ThreafGroup (AgentVMThreadGroup or MainThreadGroup) to report failures in other threads. However, there is no way to use such an approach to catch exceptions for all test threads when virtual threads are used. See for details: https://github.com/openjdk/jtreg/blob/ef3865581bdfc55c6315a8538222fc3a91b2b872/src/share/classes/com/sun/javatest/regtest/agent/MainWrapper.java#L72 I have a PR to implement the global exception handling here: https://github.com/openjdk/jtreg/pull/172 Now it is the only proposal and might take a long time to complete it. So the current fix helps us to find issues with the virtual thread test factory until jtreg is fixed. ------------- PR Comment: https://git.openjdk.org/jdk/pull/16369#issuecomment-1782021953