[jdk19] RFR: 8288703: GetThreadState returns 0 for virtual thread that has terminated

Alan Bateman alanb at openjdk.org
Fri Jul 1 18:58:38 UTC 2022


On Fri, 1 Jul 2022 17:47:51 GMT, Serguei Spitsyn <sspitsyn at openjdk.org> wrote:

> This is fixing the JVM TI GetThreadState issue which returns for terminated virtual thread state = 0 instead of 2 (`JVMTI_THREAD_STATE_TERMINATED`). The problem was in the function `JvmtiEnvBase::get_threadOop_and_JavaThread` which does a check and reurns JVMTI_ERROR_THREAD_NOT_ALIVE a little bit early (before the values of `java_thread` and `thread_oop` are set). This was a root cause of the `GetThreadState` incorrect behavior.

The fix looks good but I'm wondering why the SelfSuspendDisabledTest is being used to test this bug. I guess I expected to see a test for GetThreadState instead.

test/hotspot/jtreg/serviceability/jvmti/vthread/SelfSuspendDisablerTest/SelfSuspendDisablerTest.java line 60:

> 58:     }
> 59: 
> 60:     private static void testJvmtiThreadState(Thread thread, int expectedState) throws RuntimeException {

Minor nit, "throws RuntimeException" is not needed here.

test/hotspot/jtreg/serviceability/jvmti/vthread/SelfSuspendDisablerTest/libSelfSuspendDisablerTest.cpp line 68:

> 66: }
> 67: 
> 68: }

it might be helpful to add 

// extern "C" 

after the brace as it confused me initially as to why there are two braces.

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

PR: https://git.openjdk.org/jdk19/pull/102


More information about the serviceability-dev mailing list