Skip to content

Commit

Permalink
[GR-43733] Remove code for old JDK versions (part 2).
Browse files Browse the repository at this point in the history
PullRequest: graal/15538
  • Loading branch information
Christian Wimmer committed Sep 14, 2023
2 parents d0e20ba + 7db4cec commit 4b869e7
Show file tree
Hide file tree
Showing 22 changed files with 87 additions and 452 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,13 @@

public final class LambdaUtils {

private static final Pattern LAMBDA_PATTERN;
private static final Pattern LAMBDA_PATTERN = Pattern.compile("\\$\\$Lambda[/.][^/]+;");
private static final char[] HEX = "0123456789abcdef".toCharArray();
public static final String LAMBDA_SPLIT_PATTERN;
public static final String LAMBDA_CLASS_NAME_SUBSTRING;
public static final String LAMBDA_SPLIT_PATTERN = "\\$\\$Lambda";
public static final String LAMBDA_CLASS_NAME_SUBSTRING = "$$Lambda";
public static final String SERIALIZATION_TEST_LAMBDA_CLASS_SUBSTRING = "$$Lambda";
public static final String SERIALIZATION_TEST_LAMBDA_CLASS_SPLIT_PATTERN = "\\$\\$Lambda";

static {
if (Runtime.version().feature() < 21) {
LAMBDA_PATTERN = Pattern.compile("\\$\\$Lambda\\$\\d+[/.][^/]+;");
LAMBDA_SPLIT_PATTERN = "\\$\\$Lambda\\$";
LAMBDA_CLASS_NAME_SUBSTRING = "$$Lambda$";
} else {
// JDK-8292914
LAMBDA_PATTERN = Pattern.compile("\\$\\$Lambda[/.][^/]+;");
LAMBDA_SPLIT_PATTERN = "\\$\\$Lambda";
LAMBDA_CLASS_NAME_SUBSTRING = "$$Lambda";
}
}

private static GraphBuilderConfiguration buildLambdaParserConfig(ClassInitializationPlugin cip) {
GraphBuilderConfiguration.Plugins plugins = new GraphBuilderConfiguration.Plugins(new InvocationPlugins());
plugins.setClassInitializationPlugin(cip);
Expand Down
22 changes: 3 additions & 19 deletions substratevm/mx.substratevm/mx_substratevm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1884,30 +1884,14 @@ def config_file_update(self, file_path, lines, file_paths):
# com.oracle.svm.driver.NativeImage.BuildConfiguration.getBuilderJavaArgs().
def compute_graal_compiler_flags_map(self):
graal_compiler_flags_map = dict()
graal_compiler_flags_map['8'] = [
'-d64',
'-XX:-UseJVMCIClassLoader'
]

graal_compiler_flags_map['11'] = [
# Disable the check for JDK-8 graal version.
'-Dsubstratevm.IgnoreGraalVersionCheck=true',
]

# Packages to add-export
distributions_transitive = mx.classpath_entries(self.buildDependencies)
required_exports = mx_javamodules.requiredExports(distributions_transitive, get_jdk())
exports_flags = mx_sdk_vm.AbstractNativeImageConfig.get_add_exports_list(required_exports)
graal_compiler_flags_map['11'].extend(exports_flags)
# Currently JDK 17 and JDK 11 have the same flags
graal_compiler_flags_map['17'] = graal_compiler_flags_map['11']
# Currently JDK 19 and JDK 17 have the same flags
graal_compiler_flags_map['19'] = graal_compiler_flags_map['17']
graal_compiler_flags_map['19-ea'] = graal_compiler_flags_map['19']
# Currently JDK 20 and JDK 19 have the same flags
graal_compiler_flags_map['20'] = graal_compiler_flags_map['19']
# Currently JDK 22, JDK 21 and JDK 20 have the same flags
graal_compiler_flags_map['21'] = graal_compiler_flags_map['20']

graal_compiler_flags_map['21'] = exports_flags
# Currently JDK 22 has the same flags
graal_compiler_flags_map['22'] = graal_compiler_flags_map['21']
# DO NOT ADD ANY NEW ADD-OPENS OR ADD-EXPORTS HERE!
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
import com.oracle.svm.core.util.VMError;

import jdk.vm.ci.amd64.AMD64;
import jdk.vm.ci.amd64.AMD64.CPUFeature;
import jdk.vm.ci.amd64.AMD64Kind;
import jdk.vm.ci.code.CallingConvention;
import jdk.vm.ci.code.CodeCacheProvider;
Expand Down Expand Up @@ -754,8 +755,7 @@ public void emitConvertZeroToNull(AllocatableValue result, Value value) {

@Override
public void emitProcid(AllocatableValue dst) {
// GR-43733: Replace string by feature when we remove support for Java 17
if (supportsCPUFeature("RDPID")) {
if (supportsCPUFeature(CPUFeature.RDPID)) {
append(new AMD64ReadProcid(dst));
} else {
AMD64ReadTimestampCounterWithProcid procid = new AMD64ReadTimestampCounterWithProcid();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import org.graalvm.compiler.serviceprovider.JavaVersionUtil;

@Deprecated(since = "24.0.0", forRemoval = true)
public class JDK17OrEarlier implements BooleanSupplier {
@Override
public boolean getAsBoolean() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
*/
package com.oracle.svm.core.jni.functions;

import org.graalvm.compiler.serviceprovider.JavaVersionUtil;
import org.graalvm.compiler.word.Word;
import org.graalvm.nativeimage.CurrentIsolate;
import org.graalvm.nativeimage.ImageSingletons;
Expand All @@ -38,8 +37,6 @@
import org.graalvm.word.UnsignedWord;
import org.graalvm.word.WordBase;

import jdk.internal.misc.Unsafe;

import com.oracle.svm.core.FrameAccess;
import com.oracle.svm.core.c.CIsolateData;
import com.oracle.svm.core.c.CIsolateDataFactory;
Expand All @@ -48,9 +45,10 @@
import com.oracle.svm.core.jni.headers.JNIInvokeInterface;
import com.oracle.svm.core.jni.headers.JNIJavaVM;
import com.oracle.svm.core.jni.headers.JNINativeInterface;
import com.oracle.svm.core.jni.headers.JNINativeInterfaceJDK19OrLater;
import com.oracle.svm.core.util.VMError;

import jdk.internal.misc.Unsafe;

/**
* Performs the initialization of the JNI function table structures at runtime.
*/
Expand All @@ -75,7 +73,7 @@ public static JNIFunctionTables singleton() {
private final CIsolateData<JNIJavaVM> jniJavaVM = CIsolateDataFactory.createStruct("jniJavaVM", JNIJavaVM.class);

private static int getFunctionTableSize() {
return JavaVersionUtil.JAVA_SPEC <= 17 ? SizeOf.get(JNINativeInterface.class) : SizeOf.get(JNINativeInterfaceJDK19OrLater.class);
return SizeOf.get(JNINativeInterface.class);
}

@Platforms(Platform.HOSTED_ONLY.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,14 @@
import com.oracle.svm.core.jni.headers.JNIObjectRefType;
import com.oracle.svm.core.jni.headers.JNIValue;
import com.oracle.svm.core.jni.headers.JNIVersion;
import com.oracle.svm.core.jni.headers.JNIVersionJDK19OrLater;
import com.oracle.svm.core.jni.headers.JNIVersionJDK20OrLater;
import com.oracle.svm.core.jni.headers.JNIVersionJDK21OrLater;
import com.oracle.svm.core.jni.headers.JNIVersionJDK22OrLater;
import com.oracle.svm.core.log.Log;
import com.oracle.svm.core.monitor.MonitorInflationCause;
import com.oracle.svm.core.monitor.MonitorSupport;
import com.oracle.svm.core.snippets.KnownIntrinsics;
import com.oracle.svm.core.stack.StackOverflowCheck;
import com.oracle.svm.core.thread.JavaThreads;
import com.oracle.svm.core.thread.Target_java_lang_BaseVirtualThread;
import com.oracle.svm.core.thread.VMThreads.SafepointBehavior;
import com.oracle.svm.core.thread.VirtualThreads;
import com.oracle.svm.core.util.Utf8;
Expand Down Expand Up @@ -159,10 +158,14 @@ public final class JNIFunctions {
@CEntryPointOptions(prologue = CEntryPointOptions.NoPrologue.class, epilogue = CEntryPointOptions.NoEpilogue.class)
@Uninterruptible(reason = "No need to enter the isolate and also no way to report errors if unable to.")
static int GetVersion(JNIEnvironment env) {
return JavaVersionUtil.JAVA_SPEC >= 21 ? JNIVersionJDK21OrLater.JNI_VERSION_21()
: JavaVersionUtil.JAVA_SPEC >= 20 ? JNIVersionJDK20OrLater.JNI_VERSION_20()
: JavaVersionUtil.JAVA_SPEC >= 19 ? JNIVersionJDK19OrLater.JNI_VERSION_19()
: JNIVersion.JNI_VERSION_10();
switch (JavaVersionUtil.JAVA_SPEC) {
case 21:
return JNIVersion.JNI_VERSION_21();
case 22:
return JNIVersionJDK22OrLater.JNI_VERSION_22();
default:
throw VMError.shouldNotReachHere("Unsupported Java version " + JavaVersionUtil.JAVA_SPEC);
}
}

/*
Expand Down Expand Up @@ -1122,6 +1125,16 @@ static JNIObjectHandle DefineClass(JNIEnvironment env, CCharPointer cname, JNIOb
return JNIObjectHandles.createLocal(clazz);
}

/*
* jboolean (JNICALL *IsVirtualThread) (JNIEnv *env, jobject obj);
*/
@CEntryPoint(exceptionHandler = JNIExceptionHandlerReturnFalse.class, include = CEntryPoint.NotIncludedAutomatically.class, publishAs = Publish.NotPublished)
@CEntryPointOptions(prologue = JNIEnvEnterFatalOnFailurePrologue.class)
static boolean IsVirtualThread(JNIEnvironment env, JNIObjectHandle handle) {
Object obj = JNIObjectHandles.getObject(handle);
return obj instanceof Target_java_lang_BaseVirtualThread;
}

// Checkstyle: resume

/**
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -1470,4 +1470,9 @@ public interface JNINativeInterface extends PointerBase {

@CField
void setGetModule(CFunctionPointer p);

// Virtual threads

@CField
void setIsVirtualThread(CFunctionPointer p);
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@
public final class JNIVersion {
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
public static boolean isSupported(int version) {
return (JavaVersionUtil.JAVA_SPEC >= 21 && version == JNIVersionJDK21OrLater.JNI_VERSION_21()) ||
(JavaVersionUtil.JAVA_SPEC >= 20 && version == JNIVersionJDK20OrLater.JNI_VERSION_20()) ||
(JavaVersionUtil.JAVA_SPEC >= 19 && version == JNIVersionJDK19OrLater.JNI_VERSION_19()) ||
return (JavaVersionUtil.JAVA_SPEC >= 22 && version == JNIVersionJDK22OrLater.JNI_VERSION_22()) ||
version == JNI_VERSION_21() ||
version == JNI_VERSION_20() ||
version == JNI_VERSION_19() ||
version == JNI_VERSION_10() ||
version == JNI_VERSION_9() ||
version == JNI_VERSION_1_8() ||
Expand Down Expand Up @@ -69,6 +70,15 @@ public static boolean isSupported(int version) {
@CConstant
public static native int JNI_VERSION_10();

@CConstant
public static native int JNI_VERSION_19();

@CConstant
public static native int JNI_VERSION_20();

@CConstant
public static native int JNI_VERSION_21();

// Checkstyle: resume

private JNIVersion() {
Expand Down

This file was deleted.

Loading

0 comments on commit 4b869e7

Please sign in to comment.