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

Set java.lang.Thread state on transitions #879

Draft
wants to merge 1 commit into
base: openj9
Choose a base branch
from
Draft
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
42 changes: 35 additions & 7 deletions src/java.base/share/classes/java/lang/Thread.java
Original file line number Diff line number Diff line change
Expand Up @@ -2724,21 +2724,49 @@ public State getState() {
return threadState();
}

/**
* Returns the translation from a J9VMThread state to a Thread::State.
*
* @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:
// Fallback case: evaluate the state lazily.
synchronized (interruptLock) {
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 (eetop == NO_REF) {
if (isDead()) {
return State.TERMINATED;
}
return State.NEW;
if (eetop == NO_REF) {
if (isDead()) {
return State.TERMINATED;
}
return State.values()[getStateImpl(eetop)];
return State.NEW;
}
return translateJ9VMThreadStateToThreadState(holder.threadStatus);
}

/**
Expand Down