diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK21u3OrEarlier.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK21u3OrEarlier.java new file mode 100644 index 000000000000..972e645957ae --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK21u3OrEarlier.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.svm.core.jdk; + +import java.util.function.BooleanSupplier; + +import org.graalvm.compiler.serviceprovider.JavaVersionUtil; + +public class JDK21u3OrEarlier implements BooleanSupplier { + + public static final boolean jdk21u3OrEarlier = JavaVersionUtil.JAVA_SPEC < 21 || + (JavaVersionUtil.JAVA_SPEC == 21 && Runtime.version().update() <= 3); + + @Override + public boolean getAsBoolean() { + return jdk21u3OrEarlier; + } +} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK21u4OrLater.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK21u4OrLater.java new file mode 100644 index 000000000000..cae248622c82 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK21u4OrLater.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.svm.core.jdk; + +import java.util.function.BooleanSupplier; + +import org.graalvm.compiler.serviceprovider.JavaVersionUtil; + +public class JDK21u4OrLater implements BooleanSupplier { + + public static final boolean jdk21u4OrLater = JavaVersionUtil.JAVA_SPEC > 21 || + (JavaVersionUtil.JAVA_SPEC == 21 && Runtime.version().update() >= 4); + + @Override + public boolean getAsBoolean() { + return jdk21u4OrLater; + } +} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_VirtualThread.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_VirtualThread.java index 9d9935dd0be6..6fe180ddb54d 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_VirtualThread.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_VirtualThread.java @@ -43,6 +43,8 @@ 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.JDK21u3OrEarlier; +import com.oracle.svm.core.jdk.JDK21u4OrLater; import com.oracle.svm.core.jdk.LoomJDK; import com.oracle.svm.core.jfr.HasJfrSupport; import com.oracle.svm.core.jfr.SubstrateJVM; @@ -55,15 +57,20 @@ public final class Target_java_lang_VirtualThread { // Checkstyle: stop @Alias static int NEW; @Alias static int STARTED; - @Alias static int RUNNABLE; + @Alias // + @TargetElement(onlyWith = JDK21u3OrEarlier.class) static int RUNNABLE; @Alias static int RUNNING; @Alias static int PARKING; @Alias static int PARKED; @Alias static int PINNED; @Alias static int YIELDING; + @TargetElement(onlyWith = JDK21u4OrLater.class) @Alias static int YIELDED; @Alias static int TERMINATED; - @Alias static int RUNNABLE_SUSPENDED; - @Alias static int PARKED_SUSPENDED; + @Alias static int SUSPENDED; + @TargetElement(onlyWith = JDK21u4OrLater.class) @Alias static int TIMED_PARKING; + @TargetElement(onlyWith = JDK21u4OrLater.class) @Alias static int TIMED_PARKED; + @TargetElement(onlyWith = JDK21u4OrLater.class) @Alias static int TIMED_PINNED; + @TargetElement(onlyWith = JDK21u4OrLater.class) @Alias static int UNPARKED; @Alias static Target_jdk_internal_vm_ContinuationScope VTHREAD_SCOPE; // Checkstyle: resume @@ -155,7 +162,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) { @@ -164,7 +171,9 @@ Thread.State threadState() { } else { return Thread.State.RUNNABLE; } - } else if (state == RUNNABLE || state == RUNNABLE_SUSPENDED) { + } else if (JDK21u3OrEarlier.jdk21u3OrEarlier && state == RUNNABLE) { + return Thread.State.RUNNABLE; + } else if (JDK21u4OrLater.jdk21u4OrLater && (state == UNPARKED || state == YIELDED)) { return Thread.State.RUNNABLE; } else if (state == RUNNING) { Object token = VirtualThreadHelper.acquireInterruptLockMaybeSwitch(this); @@ -179,7 +188,7 @@ Thread.State threadState() { return Thread.State.RUNNABLE; } else if (state == PARKING || state == YIELDING) { return Thread.State.RUNNABLE; - } else if (state == PARKED || 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: @@ -192,6 +201,12 @@ Thread.State threadState() { } } else if (state == TERMINATED) { return Thread.State.TERMINATED; + } else if (JDK21u4OrLater.jdk21u4OrLater) { + if (state == TIMED_PARKING) { + return Thread.State.RUNNABLE; + } else if (state == TIMED_PARKED || state == TIMED_PINNED) { + return Thread.State.TIMED_WAITING; + } } throw new InternalError(); }