Skip to content

Commit

Permalink
[GR-48899] Support TIMED_WAITING for virtual threads.
Browse files Browse the repository at this point in the history
(cherry picked from commit 4fad6c2)
  • Loading branch information
peter-hofer authored and zakkak committed May 22, 2024
1 parent 1e48201 commit be359a8
Showing 1 changed file with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import com.oracle.svm.core.jdk.JDK20OrEarlier;
import com.oracle.svm.core.jdk.JDK20OrLater;
import com.oracle.svm.core.jdk.JDK21OrLater;
import com.oracle.svm.core.jdk.JDK22OrLater;
import com.oracle.svm.core.jdk.LoomJDK;
import com.oracle.svm.core.jfr.HasJfrSupport;
import com.oracle.svm.core.jfr.SubstrateJVM;
Expand All @@ -64,12 +65,10 @@ public final class Target_java_lang_VirtualThread {
@Alias static int PINNED;
@Alias static int YIELDING;
@Alias static int TERMINATED;
@Alias //
@TargetElement(onlyWith = JDK21OrEarlier.class) //
static int RUNNABLE_SUSPENDED;
@Alias //
@TargetElement(onlyWith = JDK21OrEarlier.class) //
static int PARKED_SUSPENDED;
@Alias static int SUSPENDED;
@TargetElement(onlyWith = JDK22OrLater.class) @Alias static int TIMED_PARKING;
@TargetElement(onlyWith = JDK22OrLater.class) @Alias static int TIMED_PARKED;
@TargetElement(onlyWith = JDK22OrLater.class) @Alias static int TIMED_PINNED;
@Alias static Target_jdk_internal_vm_ContinuationScope VTHREAD_SCOPE;
// Checkstyle: resume

Expand Down Expand Up @@ -161,7 +160,7 @@ void unmount() {

@Substitute
Thread.State threadState() {
int state = state();
int state = state() & ~SUSPENDED;
if (state == NEW) {
return Thread.State.NEW;
} else if (state == STARTED) {
Expand All @@ -170,7 +169,7 @@ Thread.State threadState() {
} else {
return Thread.State.RUNNABLE;
}
} else if (state == RUNNABLE || (JavaVersionUtil.JAVA_SPEC <= 21 && state == RUNNABLE_SUSPENDED)) {
} else if (state == RUNNABLE) {
return Thread.State.RUNNABLE;
} else if (state == RUNNING) {
Object token = VirtualThreadHelper.acquireInterruptLockMaybeSwitch(this);
Expand All @@ -185,7 +184,7 @@ Thread.State threadState() {
return Thread.State.RUNNABLE;
} else if (state == PARKING || state == YIELDING) {
return Thread.State.RUNNABLE;
} else if (state == PARKED || (JavaVersionUtil.JAVA_SPEC <= 21 && state == PARKED_SUSPENDED) || state == PINNED) {
} else if (state == PARKED || state == PINNED) {
int parkedThreadStatus = MonitorSupport.singleton().getParkedThreadStatus(asThread(this), false);
switch (parkedThreadStatus) {
case ThreadStatus.BLOCKED_ON_MONITOR_ENTER:
Expand All @@ -198,6 +197,12 @@ Thread.State threadState() {
}
} else if (state == TERMINATED) {
return Thread.State.TERMINATED;
} else if (JavaVersionUtil.JAVA_SPEC >= 22) {
if (state == TIMED_PARKING) {
return Thread.State.RUNNABLE;
} else if (state == TIMED_PARKED || state == TIMED_PINNED) {
return Thread.State.TIMED_WAITING;
}
}
throw new InternalError();
}
Expand Down

0 comments on commit be359a8

Please sign in to comment.