Skip to content

Commit

Permalink
Merge pull request eclipse-openj9#18421 from babsingh/main2
Browse files Browse the repository at this point in the history
Support the new VirtualThread states
  • Loading branch information
hangshao0 authored Nov 10, 2023
2 parents 5e618ab + 04ddc56 commit f4501d1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 26 deletions.
20 changes: 10 additions & 10 deletions runtime/jvmti/jvmtiHelpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ getVirtualThreadState(J9VMThread *currentThread, jthread thread)
/* The mapping from JVMTI_VTHREAD_STATE_XXX to JVMTI_JAVA_LANG_THREAD_STATE_XXX is based
* on j.l.VirtualThread.threadState().
*/
switch (vThreadState) {
switch (vThreadState & ~JVMTI_VTHREAD_STATE_SUSPENDED) {
case JVMTI_VTHREAD_STATE_NEW:
rc = JVMTI_JAVA_LANG_THREAD_STATE_NEW;
break;
Expand Down Expand Up @@ -858,28 +858,28 @@ getVirtualThreadState(J9VMThread *currentThread, jthread thread)
break;
}
case JVMTI_VTHREAD_STATE_RUNNABLE:
rc = JVMTI_JAVA_LANG_THREAD_STATE_RUNNABLE;
break;
case JVMTI_VTHREAD_STATE_RUNNABLE_SUSPENDED:
rc = JVMTI_JAVA_LANG_THREAD_STATE_RUNNABLE | JVMTI_THREAD_STATE_SUSPENDED;
break;
/* Fall Through */
case JVMTI_VTHREAD_STATE_RUNNING:
rc = JVMTI_JAVA_LANG_THREAD_STATE_RUNNABLE;
break;
/* Fall Through */
case JVMTI_VTHREAD_STATE_PARKING:
/* Fall Through */
case JVMTI_VTHREAD_STATE_TIMED_PARKING:
/* Fall Through */
case JVMTI_VTHREAD_STATE_YIELDING:
rc = JVMTI_JAVA_LANG_THREAD_STATE_RUNNABLE;
break;
case JVMTI_VTHREAD_STATE_PARKED:
rc = JVMTI_JAVA_LANG_THREAD_STATE_WAITING | JVMTI_THREAD_STATE_PARKED;
break;
case JVMTI_VTHREAD_STATE_PARKED_SUSPENDED:
rc = JVMTI_JAVA_LANG_THREAD_STATE_WAITING | JVMTI_THREAD_STATE_PARKED | JVMTI_THREAD_STATE_SUSPENDED;
case JVMTI_VTHREAD_STATE_TIMED_PARKED:
rc = JVMTI_JAVA_LANG_THREAD_STATE_TIMED_WAITING | JVMTI_THREAD_STATE_PARKED;
break;
case JVMTI_VTHREAD_STATE_PINNED:
rc = JVMTI_JAVA_LANG_THREAD_STATE_WAITING;
break;
case JVMTI_VTHREAD_STATE_TIMED_PINNED:
rc = JVMTI_JAVA_LANG_THREAD_STATE_TIMED_WAITING;
break;
case JVMTI_VTHREAD_STATE_TERMINATED:
rc = JVMTI_JAVA_LANG_THREAD_STATE_TERMINATED;
break;
Expand Down
7 changes: 4 additions & 3 deletions runtime/oti/jvmtiInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -579,11 +579,12 @@ typedef struct jvmtiGcp_translation {
#define JVMTI_VTHREAD_STATE_PARKING 4
#define JVMTI_VTHREAD_STATE_PARKED 5
#define JVMTI_VTHREAD_STATE_PINNED 6
#define JVMTI_VTHREAD_STATE_YIELDING 7
#define JVMTI_VTHREAD_STATE_TIMED_PARKING 7
#define JVMTI_VTHREAD_STATE_TIMED_PARKED 8
#define JVMTI_VTHREAD_STATE_TIMED_PINNED 9
#define JVMTI_VTHREAD_STATE_YIELDING 10
#define JVMTI_VTHREAD_STATE_TERMINATED 99
#define JVMTI_VTHREAD_STATE_SUSPENDED (1 << 8)
#define JVMTI_VTHREAD_STATE_RUNNABLE_SUSPENDED (JVMTI_VTHREAD_STATE_RUNNABLE | JVMTI_VTHREAD_STATE_SUSPENDED)
#define JVMTI_VTHREAD_STATE_PARKED_SUSPENDED (JVMTI_VTHREAD_STATE_PARKED | JVMTI_VTHREAD_STATE_SUSPENDED)
#endif /* JAVA_SPEC_VERSION >= 19 */

/* The brace mismatches in the macros below are due to the usage pattern:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,12 @@ public void test_verifyJVMTIMacros() {
final int JVMTI_VTHREAD_STATE_PARKING = 4;
final int JVMTI_VTHREAD_STATE_PARKED = 5;
final int JVMTI_VTHREAD_STATE_PINNED = 6;
final int JVMTI_VTHREAD_STATE_YIELDING = 7;
final int JVMTI_VTHREAD_STATE_TIMED_PARKING = 7;
final int JVMTI_VTHREAD_STATE_TIMED_PARKED = 8;
final int JVMTI_VTHREAD_STATE_TIMED_PINNED = 9;
final int JVMTI_VTHREAD_STATE_YIELDING = 10;
final int JVMTI_VTHREAD_STATE_TERMINATED = 99;
final int JVMTI_VTHREAD_STATE_SUSPENDED = (1 << 8);
final int JVMTI_VTHREAD_STATE_RUNNABLE_SUSPENDED = (JVMTI_VTHREAD_STATE_RUNNABLE | JVMTI_VTHREAD_STATE_SUSPENDED);
final int JVMTI_VTHREAD_STATE_PARKED_SUSPENDED = (JVMTI_VTHREAD_STATE_PARKED | JVMTI_VTHREAD_STATE_SUSPENDED);

int value = 0;

Expand Down Expand Up @@ -316,6 +317,21 @@ public void test_verifyJVMTIMacros() {
Assert.fail("JVMTI_VTHREAD_STATE_PINNED (" + JVMTI_VTHREAD_STATE_PINNED + ") does not match VirtualThread.PINNED (" + value + ")");
}

value = readVirtualThreadStates(vthreadCls, "TIMED_PARKING");
if (JVMTI_VTHREAD_STATE_TIMED_PARKING != value) {
Assert.fail("JVMTI_VTHREAD_STATE_TIMED_PARKING (" + JVMTI_VTHREAD_STATE_TIMED_PARKING + ") does not match VirtualThread.TIMED_PARKING (" + value + ")");
}

value = readVirtualThreadStates(vthreadCls, "TIMED_PARKED");
if (JVMTI_VTHREAD_STATE_TIMED_PARKED != value) {
Assert.fail("JVMTI_VTHREAD_STATE_TIMED_PARKED (" + JVMTI_VTHREAD_STATE_TIMED_PARKED + ") does not match VirtualThread.TIMED_PARKED (" + value + ")");
}

value = readVirtualThreadStates(vthreadCls, "TIMED_PINNED");
if (JVMTI_VTHREAD_STATE_TIMED_PINNED != value) {
Assert.fail("JVMTI_VTHREAD_STATE_TIMED_PINNED (" + JVMTI_VTHREAD_STATE_TIMED_PINNED + ") does not match VirtualThread.TIMED_PINNED (" + value + ")");
}

value = readVirtualThreadStates(vthreadCls, "YIELDING");
if (JVMTI_VTHREAD_STATE_YIELDING != value) {
Assert.fail("JVMTI_VTHREAD_STATE_YIELDING (" + JVMTI_VTHREAD_STATE_YIELDING + ") does not match VirtualThread.YIELDING (" + value + ")");
Expand All @@ -330,16 +346,6 @@ public void test_verifyJVMTIMacros() {
if (JVMTI_VTHREAD_STATE_SUSPENDED != value) {
Assert.fail("JVMTI_VTHREAD_STATE_SUSPENDED (" + JVMTI_VTHREAD_STATE_SUSPENDED + ") does not match VirtualThread.SUSPENDED (" + value + ")");
}

value = readVirtualThreadStates(vthreadCls, "RUNNABLE_SUSPENDED");
if (JVMTI_VTHREAD_STATE_RUNNABLE_SUSPENDED != value) {
Assert.fail("JVMTI_VTHREAD_STATE_RUNNABLE_SUSPENDED (" + JVMTI_VTHREAD_STATE_RUNNABLE_SUSPENDED + ") does not match VirtualThread.RUNNABLE_SUSPENDED (" + value + ")");
}

value = readVirtualThreadStates(vthreadCls, "PARKED_SUSPENDED");
if (JVMTI_VTHREAD_STATE_PARKED_SUSPENDED != value) {
Assert.fail("JVMTI_VTHREAD_STATE_PARKED_SUSPENDED (" + JVMTI_VTHREAD_STATE_PARKED_SUSPENDED + ") does not match VirtualThread.PARKED_SUSPENDED (" + value + ")");
}
} catch (Exception e) {
Assert.fail("Unexpected exception occured : " + e.getMessage() , e);
}
Expand Down

0 comments on commit f4501d1

Please sign in to comment.