Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update getState() API to use holder.threadStatus field #927

Open
wants to merge 2 commits into
base: openj9
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 42 additions & 5 deletions src/java.base/share/classes/java/lang/Thread.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

/*
* ===========================================================================
* (c) Copyright IBM Corp. 2021, 2024 All Rights Reserved
* (c) Copyright IBM Corp. 2021, 2025 All Rights Reserved
* ===========================================================================
*/

Expand Down Expand Up @@ -2426,21 +2426,58 @@ public State getState() {
return threadState();
}

/**
* Returns the translation from a J9VMThread state to a Thread::State.
*
* @param status thread status value set by VM.
* @return this thread's state.
*
* @see State
*/
private State translateJ9VMThreadStateToThreadState(int status) {
switch (status) {
case 1: // J9VMTHREAD_STATE_RUNNING
return State.RUNNABLE;
case 2: // J9VMTHREAD_STATE_BLOCKED
return State.BLOCKED;
case 4: // J9VMTHREAD_STATE_WAITING
case 0x80: // J9VMTHREAD_STATE_PARKED
return State.WAITING;
case 8: // J9VMTHREAD_STATE_SLEEPING
case 64: // J9VMTHREAD_STATE_WAITING_TIMED
case 0x100: // J9VMTHREAD_STATE_PARKED_TIMED
return State.TIMED_WAITING;
case 32: // J9VMTHREAD_STATE_DEAD
return State.TERMINATED;
default:
synchronized (interruptLock) {
if (eetop == NO_REF) {
return State.TERMINATED;
}
return State.values()[getStateImpl(eetop)];
}
}
}

/**
* Returns the state of this thread.
* This method can be used instead of getState as getState is not final and
* so can be overridden to run arbitrary code.
*/
State threadState() {
synchronized (interruptLock) {
if (started) {
if (eetop == NO_REF) {
if (isDead()) {
return State.TERMINATED;
}
if (holder == null) {
if (eetop == NO_REF) {
return State.TERMINATED;
}
return State.NEW;
return State.values()[getStateImpl(eetop)];
}
return State.values()[getStateImpl(eetop)];
return translateJ9VMThreadStateToThreadState(holder.threadStatus);
}
return State.NEW;
}

/**
Expand Down