RFR: 7903526: jtreg should handle all exceptions

Jaikiran Pai jpai at openjdk.org
Tue Oct 31 06:41:00 UTC 2023


On Tue, 31 Oct 2023 06:34:18 GMT, Jaikiran Pai <jpai at openjdk.org> wrote:

>> Currently, jtreg executes a test in MainThreadGroup and checks uncaught exceptions for this group. So it handles all exceptions if the test doesn't create new thread groups.
>> However, the virtual threads don't belong to MainThreadGroup and jtreg silently ignores all exceptions thrown by virtual threads.
>> 
>> The testing shows that we have already some problems in jdk/jdk and probably in UR releases. There are 13 test failures in tier1 and several tens in the execution of tests that use secutiry-manager and run with a virtual thread.
>> 
>> It wonder if it makes sense to have this check conditional using some java property and start fixing tests after jtreg is release and smoothly switch execution to the new version.
>
> src/share/classes/com/sun/javatest/regtest/agent/MainWrapper.java line 76:
> 
>> 74:         MainThreadGroup tg = new MainThreadGroup();
>> 75: 
>> 76:         Thread.setDefaultUncaughtExceptionHandler((t, e) -> {
> 
> I think if we do decide to set a JVM level default uncaught exception handler then it has to be done only for the case where the `Thread` instance returned by the test thread factory (if there is one) is a virtual thread. So something like:
> 
> 
> if (t.isVirtual()) {
>   Thread.setDefaultUncaughtExceptionHandler(.....)
> }
> 
> That way we don't interfere with uncaught exception handlers when platform thread is being used.

Finally, the major issue with setting a JVM level uncaught exception handler is that, tests will no longer be able to expect the `Thread.getDefaultUncaughtExceptionHandler()` to ever be `null`, even if they launch in `/othervm` mode. I think that's a problem. I can't recollect if jtreg testing framework has other similar cases where it interferes with the tests even with the usage of `/othervm`.

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

PR Review Comment: https://git.openjdk.org/jtreg/pull/172#discussion_r1377113189


More information about the jtreg-dev mailing list