From d411373be14e0704be9a84563baa7a9a63e4388e Mon Sep 17 00:00:00 2001 From: Babneet Singh Date: Mon, 5 Dec 2022 12:45:52 -0800 Subject: [PATCH] Check for illegal bits in SelfSuspendDisablerTest Fixes: eclipse-openj9/openj9#16276 Signed-off-by: Babneet Singh --- .../SelfSuspendDisablerTest.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/test/hotspot/jtreg/serviceability/jvmti/vthread/SelfSuspendDisablerTest/SelfSuspendDisablerTest.java b/test/hotspot/jtreg/serviceability/jvmti/vthread/SelfSuspendDisablerTest/SelfSuspendDisablerTest.java index 6a8942d4e75..81a68c88c2d 100644 --- a/test/hotspot/jtreg/serviceability/jvmti/vthread/SelfSuspendDisablerTest/SelfSuspendDisablerTest.java +++ b/test/hotspot/jtreg/serviceability/jvmti/vthread/SelfSuspendDisablerTest/SelfSuspendDisablerTest.java @@ -66,10 +66,27 @@ private static void sleep(long millis) { private static void testJvmtiThreadState(Thread thread, int expectedState) { String kindStr = thread.isVirtual()? "virtual " : "platform"; int state = getThreadState(thread); + boolean pass = true; System.out.printf("Expected %s thread state: %06X got: %06X\n", kindStr, expectedState, state); - if ((state & expectedState) != expectedState) { + if (expectedState == SUSPENDED) { + if ((state & expectedState) != expectedState) { + /* Fail if the required bits are not set. */ + pass = false; + } + /* SUSPENDED_OPTIONAL = JVMTI_THREAD_STATE_INTERRUPTED | JVMTI_THREAD_STATE_IN_NATIVE */ + int SUSPENDED_OPTIONAL = 0x200000 | 0x400000; + if ((state & ~(SUSPENDED | SUSPENDED_OPTIONAL)) != 0) { + /* Fail if any unexpected bit is set. */ + pass = false; + } + } else { + if (state != expectedState) { + pass = false; + } + } + if (!pass) { throw new RuntimeException("Test FAILED: Unexpected thread state"); } }