@@ -2792,21 +2792,53 @@ public State getState() {
27922792 return threadState ();
27932793 }
27942794
2795+ /**
2796+ * Returns the translation from a J9VMThread state to a Thread::State.
2797+ *
2798+ * @param status thread status value set by VM.
2799+ * @return this thread's state.
2800+ *
2801+ * @see State
2802+ */
2803+ private State translateJ9VMThreadStateToThreadState (int status ) {
2804+ switch (status ) {
2805+ case 0x1 : // J9VMTHREAD_STATE_RUNNING
2806+ return State .RUNNABLE ;
2807+ case 0x2 : // J9VMTHREAD_STATE_BLOCKED
2808+ return State .BLOCKED ;
2809+ case 0x4 : // J9VMTHREAD_STATE_WAITING
2810+ case 0x80 : // J9VMTHREAD_STATE_PARKED
2811+ return State .WAITING ;
2812+ case 0x8 : // J9VMTHREAD_STATE_SLEEPING
2813+ case 0x40 : // J9VMTHREAD_STATE_WAITING_TIMED
2814+ case 0x100 : // J9VMTHREAD_STATE_PARKED_TIMED
2815+ return State .TIMED_WAITING ;
2816+ case 0x20 : // J9VMTHREAD_STATE_DEAD
2817+ return State .TERMINATED ;
2818+ default :
2819+ synchronized (interruptLock ) {
2820+ if (eetop == NO_REF ) {
2821+ return State .TERMINATED ;
2822+ }
2823+ return State .values ()[getStateImpl (eetop )];
2824+ }
2825+ }
2826+ }
2827+
27952828 /**
27962829 * Returns the state of this thread.
27972830 * This method can be used instead of getState as getState is not final and
27982831 * so can be overridden to run arbitrary code.
27992832 */
28002833 State threadState () {
2801- synchronized ( interruptLock ) {
2834+ if ( started ) {
28022835 if (eetop == NO_REF ) {
2803- if (isDead ()) {
2804- return State .TERMINATED ;
2805- }
2806- return State .NEW ;
2836+ return State .TERMINATED ;
28072837 }
2808- return State .values ()[getStateImpl (eetop )];
2838+ return translateJ9VMThreadStateToThreadState (
2839+ (holder != null ) ? holder .threadStatus : 0 );
28092840 }
2841+ return State .NEW ;
28102842 }
28112843
28122844 /**
0 commit comments