@@ -2459,21 +2459,53 @@ public State getState() {
24592459 return threadState ();
24602460 }
24612461
2462+ /**
2463+ * Returns the translation from a J9VMThread state to a Thread::State.
2464+ *
2465+ * @param status thread status value set by VM.
2466+ * @return this thread's state.
2467+ *
2468+ * @see State
2469+ */
2470+ private State translateJ9VMThreadStateToThreadState (int status ) {
2471+ switch (status ) {
2472+ case 0x1 : // J9VMTHREAD_STATE_RUNNING
2473+ return State .RUNNABLE ;
2474+ case 0x2 : // J9VMTHREAD_STATE_BLOCKED
2475+ return State .BLOCKED ;
2476+ case 0x4 : // J9VMTHREAD_STATE_WAITING
2477+ case 0x80 : // J9VMTHREAD_STATE_PARKED
2478+ return State .WAITING ;
2479+ case 0x8 : // J9VMTHREAD_STATE_SLEEPING
2480+ case 0x40 : // J9VMTHREAD_STATE_WAITING_TIMED
2481+ case 0x100 : // J9VMTHREAD_STATE_PARKED_TIMED
2482+ return State .TIMED_WAITING ;
2483+ case 0x20 : // J9VMTHREAD_STATE_DEAD
2484+ return State .TERMINATED ;
2485+ default :
2486+ synchronized (interruptLock ) {
2487+ if (eetop == NO_REF ) {
2488+ return State .TERMINATED ;
2489+ }
2490+ return State .values ()[getStateImpl (eetop )];
2491+ }
2492+ }
2493+ }
2494+
24622495 /**
24632496 * Returns the state of this thread.
24642497 * This method can be used instead of getState as getState is not final and
24652498 * so can be overridden to run arbitrary code.
24662499 */
24672500 State threadState () {
2468- synchronized ( interruptLock ) {
2501+ if ( started ) {
24692502 if (eetop == NO_REF ) {
2470- if (isDead ()) {
2471- return State .TERMINATED ;
2472- }
2473- return State .NEW ;
2503+ return State .TERMINATED ;
24742504 }
2475- return State .values ()[getStateImpl (eetop )];
2505+ return translateJ9VMThreadStateToThreadState (
2506+ (holder != null ) ? holder .threadStatus : 0 );
24762507 }
2508+ return State .NEW ;
24772509 }
24782510
24792511 /**
0 commit comments