@@ -94,14 +94,15 @@ private static final class TidLock {
9494 */
9595 private volatile boolean deadInterrupt ;
9696 /*[ENDIF] JAVA_SPEC_VERSION >= 14 */
97- private volatile boolean started ; // If !isAlive(), tells if Thread died already or hasn't even started
98- private String name ; // The Thread's name
99- private int priority = NORM_PRIORITY ; // The Thread's current priority
97+ private volatile boolean started ; // If !isAlive(), tells if Thread died already or hasn't even started
98+ private String name ; // The Thread's name
99+ private int priority = NORM_PRIORITY ; // The Thread's current priority
100100 private boolean isDaemon ; // Tells if the Thread is a daemon thread or not.
101+ private volatile int threadStatus ; // The Thread's state.
101102
102- ThreadGroup group ; // A Thread belongs to exactly one ThreadGroup
103+ ThreadGroup group ; // A Thread belongs to exactly one ThreadGroup
103104 private Runnable runnable ; // Target (optional) runnable object
104- private boolean stopCalled = false ; // Used by the VM
105+ private boolean stopCalled = false ; // Used by the VM
105106/*[PR 1FENTZW]*/
106107 private ClassLoader contextClassLoader ; // Used to find classes and resources in this Thread
107108 ThreadLocal .ThreadLocalMap threadLocals ;
@@ -1488,6 +1489,39 @@ public static enum State {
14881489 */
14891490 TERMINATED }
14901491
1492+ /**
1493+ * Returns the translation from a J9VMThread state to a Thread::State.
1494+ *
1495+ * @param status thread status value set by VM.
1496+ * @return this thread's state.
1497+ *
1498+ * @see State
1499+ */
1500+ private State translateJ9VMThreadStateToThreadState (int status ) {
1501+ switch (status ) {
1502+ case 1 : // J9VMTHREAD_STATE_RUNNING
1503+ return State .RUNNABLE ;
1504+ case 2 : // J9VMTHREAD_STATE_BLOCKED
1505+ return State .BLOCKED ;
1506+ case 4 : // J9VMTHREAD_STATE_WAITING
1507+ case 0x80 : // J9VMTHREAD_STATE_PARKED
1508+ return State .WAITING ;
1509+ case 8 : // J9VMTHREAD_STATE_SLEEPING
1510+ case 64 : // J9VMTHREAD_STATE_WAITING_TIMED
1511+ case 0x100 : // J9VMTHREAD_STATE_PARKED_TIMED
1512+ return State .TIMED_WAITING ;
1513+ case 32 : // J9VMTHREAD_STATE_DEAD
1514+ return State .TERMINATED ;
1515+ default :
1516+ synchronized (lock ) {
1517+ if (threadRef == NO_REF ) {
1518+ return State .TERMINATED ;
1519+ }
1520+ return State .values ()[getStateImpl (threadRef )];
1521+ }
1522+ }
1523+ }
1524+
14911525/**
14921526 * Returns the current Thread state.
14931527 *
@@ -1496,15 +1530,13 @@ public static enum State {
14961530 * @see State
14971531 */
14981532public State getState () {
1499- synchronized ( lock ) {
1533+ if ( started ) {
15001534 if (threadRef == NO_REF ) {
1501- if (isDead ()) {
1502- return State .TERMINATED ;
1503- }
1504- return State .NEW ;
1535+ return State .TERMINATED ;
15051536 }
1506- return State . values ()[ getStateImpl ( threadRef )] ;
1537+ return translateJ9VMThreadStateToThreadState ( threadStatus ) ;
15071538 }
1539+ return State .NEW ;
15081540}
15091541
15101542private native int getStateImpl (long threadRef );
0 commit comments