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

svm: fix for JDK 21.0.4 after the downport of "8315373: Change VirtualThread to unmount after freezing, re-mount before thawing" and dependent changes #736

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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

Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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:
Expand All @@ -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();
}
Expand Down
Loading