diff --git a/substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/Target_jdk_internal_foreign_Utils_BaseAndScale.java b/substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/Target_jdk_internal_foreign_Utils_BaseAndScale.java index 58124feb47da..d5d4ec65255d 100644 --- a/substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/Target_jdk_internal_foreign_Utils_BaseAndScale.java +++ b/substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/Target_jdk_internal_foreign_Utils_BaseAndScale.java @@ -32,7 +32,6 @@ import com.oracle.svm.core.config.ConfigurationValues; import com.oracle.svm.core.util.VMError; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; import jdk.internal.foreign.Utils; import jdk.vm.ci.meta.JavaKind; @@ -66,9 +65,6 @@ public Object transform(Object receiver, Object originalValue) { throw VMError.shouldNotReachHere("Unexpected BaseAndScale instance: " + receiver); } int offset = ConfigurationValues.getObjectLayout().getArrayBaseOffset(kind); - if (JavaVersionUtil.JAVA_SPEC <= 21) { - return offset; - } return (long) offset; } } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateUtil.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateUtil.java index 570f45d2ebec..5daf4453825d 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateUtil.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateUtil.java @@ -30,7 +30,6 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Executable; import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Member; import java.lang.reflect.Method; import java.util.List; @@ -90,26 +89,12 @@ public static String getArchitectureName() { }; } - /* - * [GR-55515]: Accessing isTerminal() reflectively only for 21 JDK compatibility. After dropping - * JDK 21, use it directly. - */ - private static final Method IS_TERMINAL_METHOD = ReflectionUtil.lookupMethod(true, Console.class, "isTerminal"); - private static boolean isTTY() { Console console = System.console(); if (console == null) { return false; } - if (IS_TERMINAL_METHOD != null) { - try { - return (boolean) IS_TERMINAL_METHOD.invoke(console); - } catch (IllegalAccessException | InvocationTargetException e) { - throw new Error(e); - } - } else { - return true; - } + return console.isTerminal(); } public static boolean isNonInteractiveTerminal() { diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/bootstrap/BootstrapMethodConfiguration.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/bootstrap/BootstrapMethodConfiguration.java index 5b0bbeab806c..8032a8914085 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/bootstrap/BootstrapMethodConfiguration.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/bootstrap/BootstrapMethodConfiguration.java @@ -40,13 +40,11 @@ import java.util.concurrent.ConcurrentMap; import org.graalvm.nativeimage.ImageSingletons; -import org.graalvm.nativeimage.hosted.RuntimeReflection; import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature; import com.oracle.svm.core.feature.InternalFeature; import com.oracle.svm.util.ReflectionUtil; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; import jdk.vm.ci.meta.ResolvedJavaMethod; /** @@ -107,37 +105,12 @@ public BootstrapMethodConfiguration() { Method enumSwitch = ReflectionUtil.lookupMethod(SwitchBootstraps.class, "enumSwitch", MethodHandles.Lookup.class, String.class, MethodType.class, Object[].class); /* Bootstrap method used for retrieving the value of static final processors. */ - if (JavaVersionUtil.JAVA_SPEC < 23) { - Class templateRuntime = ReflectionUtil.lookupClass(false, "java.lang.runtime.TemplateRuntime"); - Method processStringTemplate = ReflectionUtil.lookupMethod(templateRuntime, "processStringTemplate", MethodHandles.Lookup.class, String.class, MethodType.class, MethodHandle.class, - String[].class); - indyBuildTimeAllowList = Set.of(metafactory, altMetafactory, makeConcat, makeConcatWithConstants, bootstrap, typeSwitch, enumSwitch, processStringTemplate); - } else { - // JDK-8329948 removed the String Template feature - indyBuildTimeAllowList = Set.of(metafactory, altMetafactory, makeConcat, makeConcatWithConstants, bootstrap, typeSwitch, enumSwitch); - } + indyBuildTimeAllowList = Set.of(metafactory, altMetafactory, makeConcat, makeConcatWithConstants, bootstrap, typeSwitch, enumSwitch); /* Set of bootstrap methods for constant dynamic allowed at build time is empty for now */ condyBuildTimeAllowList = Set.of(); } - @Override - public void beforeAnalysis(BeforeAnalysisAccess a) { - if (JavaVersionUtil.JAVA_SPEC < 23) { - /* - * Those methods are used by ObjectMethods.bootstrap to combine the Strings of the - * records into one String - */ - - Class stringConcatHelper = ReflectionUtil.lookupClass(false, "java.lang.StringConcatHelper"); - Class formatConcatItem = ReflectionUtil.lookupClass(false, "jdk.internal.util.FormatConcatItem"); - RuntimeReflection.register(ReflectionUtil.lookupMethod(stringConcatHelper, "prepend", long.class, byte[].class, formatConcatItem, String.class)); - RuntimeReflection.register(ReflectionUtil.lookupMethod(stringConcatHelper, "mix", long.class, formatConcatItem)); - } else { - // JDK-8329948 removed the String Template feature - } - } - /** * Check if the provided method is allowed to be executed at build time. */ diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/Target_jdk_internal_ref_Cleaner.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/Target_jdk_internal_ref_Cleaner.java index 3beb6cee16d6..309d4c8ca954 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/Target_jdk_internal_ref_Cleaner.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/Target_jdk_internal_ref_Cleaner.java @@ -39,7 +39,6 @@ import com.oracle.svm.core.thread.VMThreads; import com.oracle.svm.util.ReflectionUtil; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; import jdk.internal.misc.InnocuousThread; @TargetClass(className = "jdk.internal.ref.Cleaner") @@ -146,7 +145,7 @@ public Object transform(Object receiver, Object originalValue) { } final class Target_jdk_internal_ref_CleanerImpl_CleanableList_Singleton { - static final Object list = JavaVersionUtil.JAVA_SPEC > 21 ? ReflectionUtil.newInstance(ReflectionUtil.lookupClass("jdk.internal.ref.CleanerImpl$CleanableList")) : null; + static final Object list = ReflectionUtil.newInstance(ReflectionUtil.lookupClass("jdk.internal.ref.CleanerImpl$CleanableList")); } final class GetCleanableListSingletonTransformer implements FieldValueTransformer { diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java index ca505f803539..9c8b8bdd5eb9 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java @@ -134,7 +134,6 @@ import jdk.graal.compiler.core.common.SuppressFBWarnings; import jdk.graal.compiler.nodes.java.FinalFieldBarrierNode; import jdk.graal.compiler.replacements.ReplacementsUtil; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; import jdk.internal.access.JavaLangReflectAccess; import jdk.internal.misc.Unsafe; import jdk.internal.reflect.CallerSensitive; @@ -2343,27 +2342,13 @@ private Constructor generateConstructor(Class cl, Constructor construct * mutated, as it is not cached. To cache this constructor, setAccessible call must be done * on a copy and return that copy instead. */ - Constructor ctor = Helper_jdk_internal_reflect_ReflectionFactory.newConstructorWithAccessor(this, constructorToCall, acc); + Constructor ctor = langReflectAccess.newConstructorWithAccessor(constructorToCall, acc); ctor.setAccessible(true); return ctor; } } -/** - * Reflectively access {@code JavaLangReflectAccess.newConstructorWithAccessor}. Once we drop JDK - * 21, this can be replaced by a direct call to the method. (GR-55515) - */ -final class Helper_jdk_internal_reflect_ReflectionFactory { - private static final Method NEW_CONSTRUCTOR_WITH_ACCESSOR = JavaVersionUtil.JAVA_SPEC > 21 - ? ReflectionUtil.lookupMethod(JavaLangReflectAccess.class, "newConstructorWithAccessor", Constructor.class, ConstructorAccessor.class) - : null; - - static Constructor newConstructorWithAccessor(Target_jdk_internal_reflect_ReflectionFactory reflectionFactory, Constructor constructorToCall, ConstructorAccessor acc) { - return ReflectionUtil.invokeMethod(NEW_CONSTRUCTOR_WITH_ACCESSOR, reflectionFactory.langReflectAccess, constructorToCall, acc); - } -} - /** * Ensure that we are not accidentally using the method handle based constructor accessor. */ diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/AccessControllerUtil.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/AccessControllerUtil.java index 188662982abb..4bd340d18490 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/AccessControllerUtil.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/AccessControllerUtil.java @@ -25,14 +25,9 @@ package com.oracle.svm.core.jdk; import java.security.AccessControlContext; -import java.security.ProtectionDomain; import java.util.ArrayDeque; import java.util.Objects; -import com.oracle.svm.util.ReflectionUtil; - -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; - /** * Stack for storing AccessControlContexts. Used in conjunction with * {@code StackAccessControlContextVisitor}. @@ -93,19 +88,3 @@ public static int length() { return getStack().size(); } } - -@SuppressWarnings({"unused"}) -public class AccessControllerUtil { - - /** - * Instance that is used to mark contexts that were disallowed in - * {@code AccessControlContextReplacerFeature.replaceAccessControlContext()} If this marker is - * passed to {@code AccessController.doPrivileged()} a runtime error will be thrown. - */ - public static final AccessControlContext DISALLOWED_CONTEXT_MARKER; - - static { - DISALLOWED_CONTEXT_MARKER = JavaVersionUtil.JAVA_SPEC > 21 ? null - : ReflectionUtil.newInstance(ReflectionUtil.lookupConstructor(AccessControlContext.class, ProtectionDomain[].class, boolean.class), new ProtectionDomain[0], true); - } -} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/DeferredCommonPool.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/DeferredCommonPool.java index c5a476928682..30adfe00a003 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/DeferredCommonPool.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/DeferredCommonPool.java @@ -24,7 +24,6 @@ */ package com.oracle.svm.core.jdk; -import java.lang.reflect.Method; import java.util.Collection; import java.util.List; import java.util.concurrent.Callable; @@ -36,18 +35,11 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import com.oracle.svm.core.util.VMError; -import com.oracle.svm.util.ReflectionUtil; - -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; - /** * Pure delegate implementation to ForkJoinPool.commonPool(). */ public final class DeferredCommonPool extends ForkJoinPool { - private static final Method methodInvokeAllUninterruptibly = JavaVersionUtil.JAVA_SPEC >= 22 ? ReflectionUtil.lookupMethod(ForkJoinPool.class, "invokeAllUninterruptibly", Collection.class) : null; - public DeferredCommonPool() { super(1, new DisallowingForkJoinWorkerThreadFactory(), null, false); } @@ -89,12 +81,7 @@ public ForkJoinTask submit(Runnable task) { @SuppressWarnings({"unchecked", "static-method", "all"}) public List> invokeAllUninterruptibly(Collection> tasks) { - VMError.guarantee(JavaVersionUtil.JAVA_SPEC >= 22, "invokeAllUninterruptibly only exists in JDK 22+"); - try { - return (List>) methodInvokeAllUninterruptibly.invoke(ForkJoinPool.commonPool(), tasks); - } catch (ReflectiveOperationException e) { - throw VMError.shouldNotReachHere(e); - } + return ForkJoinPool.commonPool().invokeAllUninterruptibly(tasks); } @Override diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDKContainerSubstitutions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDKContainerSubstitutions.java index c1b39b19bce1..2a6c22d5c65b 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDKContainerSubstitutions.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDKContainerSubstitutions.java @@ -35,9 +35,8 @@ import com.oracle.svm.core.annotate.RecomputeFieldValue; import com.oracle.svm.core.annotate.RecomputeFieldValue.Kind; import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.jfr.Name_jdk_jfr_internal_JDKEvents_helper; -@TargetClass(classNameProvider = Name_jdk_jfr_internal_JDKEvents_helper.class) +@TargetClass(jdk.jfr.internal.JDKEvents.class) @Platforms(LINUX.class) final class Target_jdk_jfr_internal_JDKEvents { @Alias // diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/PlatformNativeLibrarySupport.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/PlatformNativeLibrarySupport.java index e840539073df..2c7a44c53825 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/PlatformNativeLibrarySupport.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/PlatformNativeLibrarySupport.java @@ -39,8 +39,6 @@ import com.oracle.svm.core.feature.InternalFeature; import com.oracle.svm.core.util.VMError; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; - public abstract class PlatformNativeLibrarySupport { public static final String[] defaultBuiltInLibraries = { @@ -128,14 +126,11 @@ public abstract class PlatformNativeLibrarySupport { "java_lang_invoke_VarHandle_set", "java_lang_invoke_VarHandle_compareAndExchange", "java_lang_invoke_VarHandle_getAcquire", - "java_lang_invoke_VarHandle_getAndSetAcquire"); - if (JavaVersionUtil.JAVA_SPEC > 21) { - Collections.addAll(blocklist, - "java_nio_MappedMemoryUtils_load0", - "java_nio_MappedMemoryUtils_unload0", - "java_nio_MappedMemoryUtils_isLoaded0", - "java_nio_MappedMemoryUtils_force0"); - } + "java_lang_invoke_VarHandle_getAndSetAcquire", + "java_nio_MappedMemoryUtils_load0", + "java_nio_MappedMemoryUtils_unload0", + "java_nio_MappedMemoryUtils_isLoaded0", + "java_nio_MappedMemoryUtils_force0"); defaultBuiltInPkgNativesBlocklist = blocklist.toArray(new String[0]); } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_util_StaticProperty.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_util_StaticProperty.java index c36e407a1db9..bb72eee8511c 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_util_StaticProperty.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_util_StaticProperty.java @@ -33,8 +33,6 @@ import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; - /** * This class provides JDK-internal access to values that are also available via system properties. * However, it must not return values changed by the user. We do not want to query the values during @@ -198,40 +196,38 @@ final class Target_jdk_internal_util_StaticProperty { SUN_JNU_ENCODING = p.getInitialProperty("sun.jnu.encoding"); JAVA_LOCALE_USE_OLD_ISO_CODES = p.getInitialProperty("java.locale.useOldISOCodes", ""); - if (JavaVersionUtil.JAVA_SPEC > 21) { - OS_ARCH = p.getInitialProperty("os.arch"); - - USER_LANGUAGE = p.getInitialProperty(UserSystemProperty.LANGUAGE, "en"); - USER_LANGUAGE_DISPLAY = p.getInitialProperty(UserSystemProperty.LANGUAGE_DISPLAY, USER_LANGUAGE); - USER_LANGUAGE_FORMAT = p.getInitialProperty(UserSystemProperty.LANGUAGE_FORMAT, USER_LANGUAGE); - // for compatibility, check for old user.region property - USER_REGION = p.getInitialProperty(UserSystemProperty.REGION, ""); - if (!USER_REGION.isEmpty()) { - // region can be of form country, country_variant, or _variant - int i = USER_REGION.indexOf('_'); - if (i >= 0) { - USER_COUNTRY = USER_REGION.substring(0, i); - USER_VARIANT = USER_REGION.substring(i + 1); - } else { - USER_COUNTRY = USER_REGION; - USER_VARIANT = ""; - } - USER_SCRIPT = ""; + OS_ARCH = p.getInitialProperty("os.arch"); + + USER_LANGUAGE = p.getInitialProperty(UserSystemProperty.LANGUAGE, "en"); + USER_LANGUAGE_DISPLAY = p.getInitialProperty(UserSystemProperty.LANGUAGE_DISPLAY, USER_LANGUAGE); + USER_LANGUAGE_FORMAT = p.getInitialProperty(UserSystemProperty.LANGUAGE_FORMAT, USER_LANGUAGE); + // for compatibility, check for old user.region property + USER_REGION = p.getInitialProperty(UserSystemProperty.REGION, ""); + if (!USER_REGION.isEmpty()) { + // region can be of form country, country_variant, or _variant + int i = USER_REGION.indexOf('_'); + if (i >= 0) { + USER_COUNTRY = USER_REGION.substring(0, i); + USER_VARIANT = USER_REGION.substring(i + 1); } else { - USER_SCRIPT = p.getInitialProperty(UserSystemProperty.SCRIPT, ""); - USER_COUNTRY = p.getInitialProperty(UserSystemProperty.COUNTRY, ""); - USER_VARIANT = p.getInitialProperty(UserSystemProperty.VARIANT, ""); + USER_COUNTRY = USER_REGION; + USER_VARIANT = ""; } - USER_SCRIPT_DISPLAY = p.getInitialProperty(UserSystemProperty.SCRIPT_DISPLAY, USER_SCRIPT); - USER_SCRIPT_FORMAT = p.getInitialProperty(UserSystemProperty.SCRIPT_FORMAT, USER_SCRIPT); - USER_COUNTRY_DISPLAY = p.getInitialProperty(UserSystemProperty.COUNTRY_DISPLAY, USER_COUNTRY); - USER_COUNTRY_FORMAT = p.getInitialProperty(UserSystemProperty.COUNTRY_FORMAT, USER_COUNTRY); - USER_VARIANT_DISPLAY = p.getInitialProperty(UserSystemProperty.VARIANT_DISPLAY, USER_VARIANT); - USER_VARIANT_FORMAT = p.getInitialProperty(UserSystemProperty.VARIANT_FORMAT, USER_VARIANT); - USER_EXTENSIONS = p.getInitialProperty(UserSystemProperty.EXTENSIONS, ""); - USER_EXTENSIONS_DISPLAY = p.getInitialProperty(UserSystemProperty.EXTENSIONS_DISPLAY, USER_EXTENSIONS); - USER_EXTENSIONS_FORMAT = p.getInitialProperty(UserSystemProperty.EXTENSIONS_FORMAT, USER_EXTENSIONS); + USER_SCRIPT = ""; + } else { + USER_SCRIPT = p.getInitialProperty(UserSystemProperty.SCRIPT, ""); + USER_COUNTRY = p.getInitialProperty(UserSystemProperty.COUNTRY, ""); + USER_VARIANT = p.getInitialProperty(UserSystemProperty.VARIANT, ""); } + USER_SCRIPT_DISPLAY = p.getInitialProperty(UserSystemProperty.SCRIPT_DISPLAY, USER_SCRIPT); + USER_SCRIPT_FORMAT = p.getInitialProperty(UserSystemProperty.SCRIPT_FORMAT, USER_SCRIPT); + USER_COUNTRY_DISPLAY = p.getInitialProperty(UserSystemProperty.COUNTRY_DISPLAY, USER_COUNTRY); + USER_COUNTRY_FORMAT = p.getInitialProperty(UserSystemProperty.COUNTRY_FORMAT, USER_COUNTRY); + USER_VARIANT_DISPLAY = p.getInitialProperty(UserSystemProperty.VARIANT_DISPLAY, USER_VARIANT); + USER_VARIANT_FORMAT = p.getInitialProperty(UserSystemProperty.VARIANT_FORMAT, USER_VARIANT); + USER_EXTENSIONS = p.getInitialProperty(UserSystemProperty.EXTENSIONS, ""); + USER_EXTENSIONS_DISPLAY = p.getInitialProperty(UserSystemProperty.EXTENSIONS_DISPLAY, USER_EXTENSIONS); + USER_EXTENSIONS_FORMAT = p.getInitialProperty(UserSystemProperty.EXTENSIONS_FORMAT, USER_EXTENSIONS); } } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrJdkCompatibility.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrJdkCompatibility.java index c0d35b3ba7af..e663f931ccf9 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrJdkCompatibility.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrJdkCompatibility.java @@ -24,7 +24,6 @@ */ package com.oracle.svm.core.jfr; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.time.Duration; import java.time.LocalDateTime; @@ -40,9 +39,7 @@ import com.oracle.svm.core.util.VMError; import com.oracle.svm.util.ReflectionUtil; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; import jdk.jfr.Recording; -import jdk.jfr.internal.JVM; import jdk.jfr.internal.JVMSupport; /** @@ -66,42 +63,12 @@ public static String formatTimespan(Duration dValue, String separation) { @Platforms(Platform.HOSTED_ONLY.class) public static void createNativeJFR() { try { - if (JavaVersionUtil.JAVA_SPEC >= 22) { - Method createJFR = ReflectionUtil.lookupMethod(JVMSupport.class, "createJFR"); - createJFR.invoke(null); - } else { - Method createNativeJFR = ReflectionUtil.lookupMethod(JVM.class, "createNativeJFR"); - createNativeJFR.invoke(getJVMOrNull()); - } + Method createJFR = ReflectionUtil.lookupMethod(JVMSupport.class, "createJFR"); + createJFR.invoke(null); } catch (ReflectiveOperationException | ClassCastException e) { throw VMError.shouldNotReachHere(e); } } - - @Platforms(Platform.HOSTED_ONLY.class) - public static void retransformClasses(Class[] classes) { - try { - // call JVM.retransformClasses(classes) - Method retransformClasses = ReflectionUtil.lookupMethod(JVM.class, "retransformClasses", Class[].class); - retransformClasses.invoke(getJVMOrNull(), (Object) classes); - } catch (ReflectiveOperationException | ClassCastException e) { - throw VMError.shouldNotReachHere(e); - } - } - - /** - * Gets a {@link JVM} object or {@code null} in case of JDK 22+, where the methods of - * {@link JVM} are static (JDK-8310661). - */ - @Platforms(Platform.HOSTED_ONLY.class) - public static JVM getJVMOrNull() throws IllegalAccessException, InvocationTargetException { - if (JavaVersionUtil.JAVA_SPEC >= 22) { - return null; - } else { - Method getJVM = ReflectionUtil.lookupMethod(JVM.class, "getJVM"); - return (JVM) getJVM.invoke(null); - } - } } @TargetClass(className = "jdk.jfr.internal.JVMSupport", onlyWith = HasJfrSupport.class) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Name_jdk_jfr_internal_JDKEvents_helper.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Name_jdk_jfr_internal_JDKEvents_helper.java deleted file mode 100644 index 0bf0117657fb..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Name_jdk_jfr_internal_JDKEvents_helper.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2024, 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.jfr; - -import java.util.function.Function; - -import org.graalvm.nativeimage.Platform; -import org.graalvm.nativeimage.Platforms; - -import com.oracle.svm.core.annotate.TargetClass; - -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; - -@Platforms(Platform.HOSTED_ONLY.class) -public final class Name_jdk_jfr_internal_JDKEvents_helper implements Function { - - @Override - public String apply(TargetClass annotation) { - if (JavaVersionUtil.JAVA_SPEC >= 23) { - return "jdk.jfr.internal.JDKEvents"; - } else { - return "jdk.jfr.internal.instrument.JDKEvents"; - } - } -} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_instrument_JDKEvents.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_JDKEvents.java similarity index 91% rename from substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_instrument_JDKEvents.java rename to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_JDKEvents.java index 88255ea4c718..09cf22de3889 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_instrument_JDKEvents.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_JDKEvents.java @@ -31,8 +31,8 @@ import jdk.jfr.events.ActiveRecordingEvent; import jdk.jfr.events.ActiveSettingEvent; -@TargetClass(classNameProvider = Name_jdk_jfr_internal_JDKEvents_helper.class, onlyWith = HasJfrSupport.class) -final class Target_jdk_jfr_internal_instrument_JDKEvents { +@TargetClass(value = jdk.jfr.internal.JDKEvents.class, onlyWith = HasJfrSupport.class) +final class Target_jdk_jfr_internal_JDKEvents { @Alias // @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FromAlias, isFinal = true) // diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/functions/JNIFunctionTables.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/functions/JNIFunctionTables.java index b0c92c2ae42e..a1d4ea043620 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/functions/JNIFunctionTables.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/functions/JNIFunctionTables.java @@ -47,7 +47,6 @@ import com.oracle.svm.core.jni.headers.JNINativeInterfaceJDKLatest; import com.oracle.svm.core.util.VMError; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; import jdk.graal.compiler.word.Word; import jdk.internal.misc.Unsafe; @@ -75,7 +74,7 @@ public static JNIFunctionTables singleton() { private final CIsolateData jniJavaVM = CIsolateDataFactory.createStruct("jniJavaVM", JNIJavaVM.class); private static int getFunctionTableSize() { - return JavaVersionUtil.JAVA_SPEC > 21 ? SizeOf.get(JNINativeInterfaceJDKLatest.class) : SizeOf.get(JNINativeInterface.class); + return SizeOf.get(JNINativeInterfaceJDKLatest.class); } @Platforms(Platform.HOSTED_ONLY.class) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/functions/JNIFunctions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/functions/JNIFunctions.java index f8562b7d8c60..d9f55dc7c5fe 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/functions/JNIFunctions.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/functions/JNIFunctions.java @@ -108,7 +108,6 @@ import com.oracle.svm.core.jni.headers.JNIObjectHandle; 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.JNIVersionJDKLatest; import com.oracle.svm.core.log.Log; import com.oracle.svm.core.monitor.MonitorInflationCause; @@ -126,7 +125,6 @@ import jdk.graal.compiler.core.common.SuppressFBWarnings; import jdk.graal.compiler.nodes.java.ArrayLengthNode; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; import jdk.graal.compiler.word.Word; import jdk.internal.misc.Unsafe; import jdk.vm.ci.meta.JavaKind; @@ -169,11 +167,7 @@ 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) { - if (JavaVersionUtil.JAVA_SPEC == 21) { - return JNIVersion.JNI_VERSION_21(); - } else { - return JNIVersionJDKLatest.JNI_VERSION_LATEST(); - } + return JNIVersionJDKLatest.JNI_VERSION_LATEST(); } /* diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNIVersion.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNIVersion.java index 14ae1dd56237..93b7e197f77b 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNIVersion.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNIVersion.java @@ -29,16 +29,12 @@ import com.oracle.svm.core.Uninterruptible; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; - @CContext(JNIHeaderDirectives.class) public final class JNIVersion { @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) public static boolean isSupported(int version, boolean builtInLibrary) { - if (JavaVersionUtil.JAVA_SPEC > 21 && version == JNIVersionJDKLatest.JNI_VERSION_LATEST()) { - return true; - } - if (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()) { + if (version == JNIVersionJDKLatest.JNI_VERSION_LATEST() || 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()) { return true; } if (builtInLibrary) { diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNIVersionJDKLatest.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNIVersionJDKLatest.java index aa071c603f17..934528afb4f6 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNIVersionJDKLatest.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/headers/JNIVersionJDKLatest.java @@ -29,13 +29,7 @@ import com.oracle.svm.core.util.BasedOnJDKFile; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; - final class JNIHeaderDirectivesJDKLatest extends JNIHeaderDirectives { - @Override - public boolean isInConfiguration() { - return JavaVersionUtil.JAVA_SPEC > 21; - } } @CContext(JNIHeaderDirectivesJDKLatest.class) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmti/JvmtiFunctions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmti/JvmtiFunctions.java index 6db829b1dc42..f1b82d450482 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmti/JvmtiFunctions.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmti/JvmtiFunctions.java @@ -54,6 +54,7 @@ import com.oracle.svm.core.SubstrateOptions; import com.oracle.svm.core.Uninterruptible; +import com.oracle.svm.core.c.BooleanPointer; import com.oracle.svm.core.c.function.CEntryPointActions; import com.oracle.svm.core.c.function.CEntryPointErrors; import com.oracle.svm.core.c.function.CEntryPointOptions; @@ -70,7 +71,6 @@ import com.oracle.svm.core.jni.headers.JNINativeInterface; import com.oracle.svm.core.jni.headers.JNINativeInterfacePointer; import com.oracle.svm.core.jni.headers.JNIObjectHandle; -import com.oracle.svm.core.c.BooleanPointer; import com.oracle.svm.core.jvmti.headers.JClass; import com.oracle.svm.core.jvmti.headers.JClassPointer; import com.oracle.svm.core.jvmti.headers.JClassPointerPointer; @@ -112,7 +112,6 @@ import com.oracle.svm.core.memory.NullableNativeMemory; import com.oracle.svm.core.nmt.NmtCategory; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; import jdk.graal.compiler.word.Word; /** @@ -1445,7 +1444,7 @@ public boolean getAsBoolean() { public static final class JvmtiEnabledAndJDKLatest implements BooleanSupplier { @Override public boolean getAsBoolean() { - return SubstrateOptions.JVMTI.getValue() && JavaVersionUtil.JAVA_SPEC > 21; + return SubstrateOptions.JVMTI.getValue(); } } } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/monitor/MultiThreadedMonitorSupport.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/monitor/MultiThreadedMonitorSupport.java index ec98c22df2d1..11d43bf3a7f7 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/monitor/MultiThreadedMonitorSupport.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/monitor/MultiThreadedMonitorSupport.java @@ -55,7 +55,6 @@ import com.oracle.svm.core.util.VMError; import jdk.graal.compiler.core.common.SuppressFBWarnings; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; import jdk.graal.compiler.word.BarrieredAccess; import jdk.internal.misc.Unsafe; @@ -117,9 +116,7 @@ public class MultiThreadedMonitorSupport extends MonitorSupport { * java.lang.ref.ReferenceQueue internally. The ReferenceQueue uses the inner static * class Lock for all its locking needs. */ - if (JavaVersionUtil.JAVA_SPEC > 21) { - monitorTypes.put(Class.forName("java.lang.ref.ReferenceQueue$Lock"), false); - } + monitorTypes.put(Class.forName("java.lang.ref.ReferenceQueue$Lock"), false); /* The WeakIdentityHashMap also synchronizes on its internal ReferenceQueue field. */ monitorTypes.put(java.lang.ref.ReferenceQueue.class, false); diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/serialize/SerializationSupport.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/serialize/SerializationSupport.java index d20b8382277a..807931bccb9e 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/serialize/SerializationSupport.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/serialize/SerializationSupport.java @@ -46,7 +46,6 @@ import com.oracle.svm.core.util.VMError; import jdk.graal.compiler.java.LambdaUtils; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; public class SerializationSupport implements SerializationRegistry { @@ -146,9 +145,7 @@ public void setStubConstructor(Constructor stubConstructor) { @Platforms(Platform.HOSTED_ONLY.class) public Object addConstructorAccessor(Class declaringClass, Class targetConstructorClass, Object constructorAccessor) { - if (JavaVersionUtil.JAVA_SPEC > 21) { - VMError.guarantee(constructorAccessor instanceof SubstrateConstructorAccessor, "Not a SubstrateConstructorAccessor: %s", constructorAccessor); - } + VMError.guarantee(constructorAccessor instanceof SubstrateConstructorAccessor, "Not a SubstrateConstructorAccessor: %s", constructorAccessor); SerializationLookupKey key = new SerializationLookupKey(declaringClass, targetConstructorClass); return constructorAccessors.putIfAbsent(key, constructorAccessor); } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaThreads.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaThreads.java index 33e94158fc0f..c717508bb9f1 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaThreads.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaThreads.java @@ -60,7 +60,6 @@ import jdk.graal.compiler.api.directives.GraalDirectives; import jdk.graal.compiler.core.common.SuppressFBWarnings; import jdk.graal.compiler.replacements.ReplacementsUtil; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; import jdk.graal.compiler.word.Word; /** @@ -416,16 +415,6 @@ public static Object getCurrentThreadLockHelper() { return toTarget(Thread.currentThread()).lockHelper; } - static void blockedOn(Target_sun_nio_ch_Interruptible b) { - assert JavaVersionUtil.JAVA_SPEC <= 21 : "blockedOn in newer JDKs uses safe disableSuspendAndPreempt"; - - if (isCurrentThreadVirtual()) { - VirtualThreadHelper.blockedOn(b); - } else { - PlatformThreads.blockedOn(b); - } - } - /** * Returns the result of calling {@link #getThreadId} on {@link Thread#currentThread}, but from * a thread-local cache with potentially fewer accesses. diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaThreadsFeature.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaThreadsFeature.java index ac80b9c4a0d6..138ceb962b63 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaThreadsFeature.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaThreadsFeature.java @@ -27,15 +27,10 @@ import com.oracle.svm.core.feature.InternalFeature; import com.oracle.svm.util.ReflectionUtil; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; - public abstract class JavaThreadsFeature implements InternalFeature { protected static long threadId(Thread thread) { if (thread == PlatformThreads.singleton().mainThread) { - if (JavaVersionUtil.JAVA_SPEC <= 21) { - return 1; - } return ReflectionUtil.readStaticField(Thread.class, "PRIMORDIAL_TID"); } return JavaThreads.getThreadId(thread); 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 e4cb29b1555d..4d164525419f 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 @@ -32,7 +32,6 @@ import org.graalvm.nativeimage.hosted.FieldValueTransformer; -import com.oracle.svm.core.SubstrateUtil; import com.oracle.svm.core.Uninterruptible; import com.oracle.svm.core.annotate.Alias; import com.oracle.svm.core.annotate.AnnotateOriginal; @@ -44,13 +43,10 @@ import com.oracle.svm.core.annotate.TargetClass; import com.oracle.svm.core.jfr.HasJfrSupport; import com.oracle.svm.core.jfr.SubstrateJVM; -import com.oracle.svm.core.monitor.MonitorInflationCause; import com.oracle.svm.core.monitor.MonitorSupport; import com.oracle.svm.core.util.VMError; import com.oracle.svm.util.ReflectionUtil; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; - @TargetClass(className = "java.lang.VirtualThread") public final class Target_java_lang_VirtualThread { // Checkstyle: stop @@ -346,79 +342,9 @@ Thread.State threadState() { @AnnotateOriginal @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) native boolean isTerminated(); - - /** - * Only uses the interrupt lock when called from a different thread, therefore does not need to - * be substituted to use {@link VirtualThreadHelper#acquireInterruptLockMaybeSwitch}. - */ - @Alias - native void interrupt(); - - /** - * Only uses the interrupt lock when pinned, therefore does not need to be substituted to use - * {@link VirtualThreadHelper#acquireInterruptLockMaybeSwitch}. - */ - @Alias - native void unpark(); } final class VirtualThreadHelper { - static void blockedOn(Target_sun_nio_ch_Interruptible b) { - assert JavaVersionUtil.JAVA_SPEC <= 21 : "blockedOn in newer JDKs uses safe disableSuspendAndPreempt"; - - Target_java_lang_VirtualThread self = asVTarget(Thread.currentThread()); - Object token = acquireInterruptLockMaybeSwitch(self); - try { - self.nioBlocker = b; - } finally { - releaseInterruptLockMaybeSwitchBack(self, token); - } - } - - /** - * Must be used instead of {@code synchronized(interruptLock)} in all contexts where it is - * possible that {@code VirtualThread.this == Thread.currentThread()} in order to avoid a - * deadlock between virtual thread and carrier thread. - * - * @see #releaseInterruptLockMaybeSwitchBack - */ - static Object acquireInterruptLockMaybeSwitch(Target_java_lang_VirtualThread self) { - assert JavaVersionUtil.JAVA_SPEC <= 21 : "newer JDKs provide disableSuspendAndPreempt"; - - Object token = null; - if (SubstrateUtil.cast(self, Object.class) == Thread.currentThread()) { - /* - * If we block on our interrupt lock, we yield, for which we first unmount. Unmounting - * also tries to acquire our interrupt lock, so we likely block again, this time on the - * carrier thread. Then, the virtual thread cannot continue to yield, and the carrier - * thread might never get unparked, in which case both threads are stuck. - */ - Thread carrier = self.carrierThread; - JavaThreads.setCurrentThread(carrier, carrier); - token = self; - } - Object lock = asTarget(self).interruptLock; - MonitorSupport.singleton().monitorEnter(lock, MonitorInflationCause.VM_INTERNAL); - return token; - } - - /** @see #acquireInterruptLockMaybeSwitch */ - static void releaseInterruptLockMaybeSwitchBack(Target_java_lang_VirtualThread self, Object token) { - assert JavaVersionUtil.JAVA_SPEC <= 21 : "newer JDKs provide enableSuspendAndPreempt"; - - Object lock = asTarget(self).interruptLock; - MonitorSupport.singleton().monitorExit(lock, MonitorInflationCause.VM_INTERNAL); - if (token != null) { - assert token == self; - Thread carrier = asVTarget(token).carrierThread; - assert Thread.currentThread() == carrier; - JavaThreads.setCurrentThread(carrier, asThread(token)); - } - } - - static Target_java_lang_VirtualThread asVTarget(Object obj) { - return (Target_java_lang_VirtualThread) obj; - } static Target_java_lang_Thread asTarget(Object obj) { return (Target_java_lang_Thread) obj; diff --git a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/MemoryUtil.java b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/MemoryUtil.java index f895e329a8d5..e41628977a71 100644 --- a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/MemoryUtil.java +++ b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/MemoryUtil.java @@ -27,7 +27,6 @@ import java.io.BufferedReader; import java.io.InputStreamReader; import java.lang.management.ManagementFactory; -import java.lang.reflect.Method; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; @@ -40,11 +39,9 @@ import com.oracle.svm.core.SubstrateOptions; import com.oracle.svm.core.SubstrateUtil; import com.oracle.svm.core.util.ExitStatus; -import com.oracle.svm.core.util.VMError; import com.oracle.svm.driver.NativeImage.NativeImageError; -import com.oracle.svm.util.ReflectionUtil; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; +import jdk.jfr.internal.JVM; class MemoryUtil { private static final long KiB_TO_BYTES = 1024L; @@ -66,23 +63,6 @@ class MemoryUtil { */ private static final long MAX_HEAP_BYTES = 32_000_000_000L; - private static final Method IS_CONTAINERIZED_METHOD; - private static final Object IS_CONTAINERIZED_RECEIVER; - - static { - IS_CONTAINERIZED_METHOD = ReflectionUtil.lookupMethod(jdk.jfr.internal.JVM.class, "isContainerized"); - if (JavaVersionUtil.JAVA_SPEC == 21) { // non-static - var jvmField = ReflectionUtil.lookupField(jdk.jfr.internal.JVM.class, "jvm"); - try { - IS_CONTAINERIZED_RECEIVER = jvmField.get(null); - } catch (IllegalAccessException e) { - throw VMError.shouldNotReachHere(e); - } - } else { - IS_CONTAINERIZED_RECEIVER = null; // static - } - } - public static List determineMemoryFlags(NativeImage.HostFlags hostFlags) { List flags = new ArrayList<>(); if (hostFlags.hasUseParallelGC()) { @@ -170,15 +150,7 @@ private static boolean isContainerized() { if (!OS.LINUX.isCurrent()) { return false; } - /* - * [GR-55515]: Accessing isContainerized() reflectively only for 21 JDK compatibility - * (non-static vs static method). After dropping JDK 21, use it directly. - */ - try { - return (boolean) IS_CONTAINERIZED_METHOD.invoke(IS_CONTAINERIZED_RECEIVER); - } catch (ReflectiveOperationException | ClassCastException e) { - throw VMError.shouldNotReachHere(e); - } + return JVM.isContainerized(); } private static double getAvailableMemorySize() { diff --git a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java index 85eeeeb54657..3b9834a826d8 100644 --- a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java +++ b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java @@ -617,27 +617,6 @@ public List getBuilderJavaArgs() { builderJavaArgs.add("-XX:+UseJVMCINativeLibrary"); } else if (getHostFlags().hasUseJVMCICompiler()) { builderJavaArgs.add("-XX:-UseJVMCICompiler"); - - if (JavaVersionUtil.JAVA_SPEC == 21) { - Runtime.Version version = Runtime.version(); - if (version.interim() == 0 && version.update() < 4) { - /* - * Native Image regularly crashes due to JDK-8328702. In JDK 21, the fix - * only landed in 20.0.4 so in earlier JDK 21 versions, disable C2. This - * workaround can be removed when GR-55515, GR-60648 or GR-60669 is - * resolved. - */ - builderJavaArgs.add("-XX:TieredStopAtLevel=1"); - - /* - * From the java man page section on ReservedCodeCacheSize: "the default - * maximum code cache size is 240 MB; if you disable tiered compilation ... - * then the default size is 48 MB". Experience shows that Native Image needs - * the larger code cache, even when C2 is disabled. - */ - builderJavaArgs.add("-XX:ReservedCodeCacheSize=240M"); - } - } } return builderJavaArgs; diff --git a/substratevm/src/com.oracle.svm.hosted.foreign/src/com/oracle/svm/hosted/foreign/ForeignFunctionsFeature.java b/substratevm/src/com.oracle.svm.hosted.foreign/src/com/oracle/svm/hosted/foreign/ForeignFunctionsFeature.java index 4d797effd44a..4c97dce2e178 100644 --- a/substratevm/src/com.oracle.svm.hosted.foreign/src/com/oracle/svm/hosted/foreign/ForeignFunctionsFeature.java +++ b/substratevm/src/com.oracle.svm.hosted.foreign/src/com/oracle/svm/hosted/foreign/ForeignFunctionsFeature.java @@ -108,7 +108,6 @@ import jdk.graal.compiler.phases.common.CanonicalizerPhase; import jdk.graal.compiler.phases.common.IterativeConditionalEliminationPhase; import jdk.graal.compiler.phases.tiers.MidTierContext; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; import jdk.internal.foreign.MemorySessionImpl; import jdk.internal.foreign.abi.AbstractLinker; import jdk.internal.foreign.abi.LinkerOptions; @@ -276,7 +275,6 @@ public boolean isInConfiguration(IsInConfigurationAccess access) { if (!SubstrateOptions.ForeignAPISupport.getValue()) { return false; } - UserError.guarantee(JavaVersionUtil.JAVA_SPEC >= 22, "Support for the Foreign Function and Memory API is available only with JDK 22 and later."); UserError.guarantee(!SubstrateOptions.useLLVMBackend(), "Support for the Foreign Function and Memory API is not available with the LLVM backend."); return true; } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageClassLoader.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageClassLoader.java index 27abafffd212..e0a47a2a9f05 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageClassLoader.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageClassLoader.java @@ -24,15 +24,12 @@ */ package com.oracle.svm.hosted; -import java.io.File; -import java.io.FilePermission; import java.io.IOException; import java.lang.module.Configuration; import java.lang.module.ModuleDescriptor; import java.lang.module.ModuleReader; import java.lang.module.ModuleReference; import java.lang.module.ResolvedModule; -import java.lang.reflect.Method; import java.net.MalformedURLException; import java.net.URI; import java.net.URL; @@ -40,8 +37,6 @@ import java.nio.file.Path; import java.security.CodeSigner; import java.security.CodeSource; -import java.security.Permission; -import java.security.PermissionCollection; import java.security.SecureClassLoader; import java.util.ArrayList; import java.util.Collections; @@ -58,9 +53,7 @@ import java.util.stream.Stream; import com.oracle.svm.core.util.UserError; -import com.oracle.svm.util.ReflectionUtil; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; import jdk.internal.access.SharedSecrets; import jdk.internal.loader.ClassLoaders; import jdk.internal.loader.Resource; @@ -140,11 +133,6 @@ CodeSource codeSource() { } } - // Use reflection for JDK21 compatibility - private final Method findResource; - private final Method findResources; - private final Method getResource; - /** * See {@code jdk.internal.loader.Loader#Loader} and * {@code java.net.URLClassLoader#URLClassLoader}. @@ -182,15 +170,6 @@ CodeSource codeSource() { /* Initialize URLClassPath that is used to lookup classes from class-path. */ ucp = new URLClassPath(classpath.stream().map(NativeImageClassLoader::toURL).toArray(URL[]::new), null); - if (JavaVersionUtil.JAVA_SPEC == 21) { - findResource = ReflectionUtil.lookupMethod(URLClassPath.class, "findResource", String.class, boolean.class); - findResources = ReflectionUtil.lookupMethod(URLClassPath.class, "findResources", String.class, boolean.class); - getResource = ReflectionUtil.lookupMethod(URLClassPath.class, "getResource", String.class, boolean.class); - } else { - findResource = ReflectionUtil.lookupMethod(URLClassPath.class, "findResource", String.class); - findResources = ReflectionUtil.lookupMethod(URLClassPath.class, "findResources", String.class); - getResource = ReflectionUtil.lookupMethod(URLClassPath.class, "getResource", String.class); - } } public static URL toURL(Path p) { @@ -280,14 +259,6 @@ private static Optional findModuleLayer(ModuleLayer moduleLayer, Co .findAny(); } - private URL findResourceByName(String name) { - if (JavaVersionUtil.JAVA_SPEC == 21) { - return ReflectionUtil.invokeMethod(findResource, ucp, name, false); - } else { - return ReflectionUtil.invokeMethod(findResource, ucp, name); - } - } - /** * See {@code jdk.internal.loader.Loader#findResource(String mn, String name)}. */ @@ -295,7 +266,7 @@ private URL findResourceByName(String name) { protected URL findResource(String mn, String name) throws IOException { /* For unnamed module, search for resource in class-path */ if (mn == null) { - return findResourceByName(name); + return ucp.findResource(name); } /* otherwise search in specific module */ @@ -324,7 +295,7 @@ public URL findResource(String name) { String pn = Resources.toPackageName(name); /* Search for resource in class-path ... */ - URL urlOnClasspath = findResourceByName(name); + URL urlOnClasspath = ucp.findResource(name); if (urlOnClasspath != null) { return urlOnClasspath; } @@ -408,14 +379,6 @@ public URL nextElement() { }; } - private Enumeration findResourcesByName(String name) { - if (JavaVersionUtil.JAVA_SPEC == 21) { - return ReflectionUtil.invokeMethod(findResources, ucp, name, false); - } else { - return ReflectionUtil.invokeMethod(findResources, ucp, name); - } - } - /** * See {@code jdk.internal.loader.Loader#findResourcesAsList}. */ @@ -425,7 +388,7 @@ private List findResourcesAsList(String name) throws IOException { List urls = new ArrayList<>(); /* Search for resource in class-path ... */ - Enumeration classPathResources = findResourcesByName(name); + Enumeration classPathResources = ucp.findResources(name); while (classPathResources.hasMoreElements()) { urls.add(classPathResources.nextElement()); } @@ -467,21 +430,13 @@ protected Class findClass(String cn) throws ClassNotFoundException { return c; } - private Resource getResourceByPath(String path) { - if (JavaVersionUtil.JAVA_SPEC == 21) { - return ReflectionUtil.invokeMethod(getResource, ucp, path, false); - } else { - return ReflectionUtil.invokeMethod(getResource, ucp, path); - } - } - /** * See {@code java.net.URLClassLoader#findClass(java.lang.String)}. */ private Class findClassViaClassPath(String name) throws ClassNotFoundException { Class result; String path = name.replace('.', '/').concat(".class"); - Resource res = getResourceByPath(path); + Resource res = ucp.getResource(path); if (res != null) { try { result = defineClass(name, res); @@ -727,42 +682,6 @@ private Class defineClass(String cn, LoadedModule loadedModule) { } } - /** - * See {@code jdk.internal.loader.Loader#getPermissions}. - * - * The override was removed in JDK 24 by JDK-8343982. - */ - @SuppressWarnings("deprecation") - @Override - protected PermissionCollection getPermissions(CodeSource cs) { - PermissionCollection perms = super.getPermissions(cs); - if (JavaVersionUtil.JAVA_SPEC > 21) { - return perms; - } - - URL url = cs.getLocation(); - if (url == null) { - return perms; - } - - try { - Permission p = url.openConnection().getPermission(); - if (p != null) { - if (p instanceof FilePermission) { - String path = p.getName(); - if (path.endsWith(File.separator)) { - path += "-"; - p = new FilePermission(path, "read"); - } - } - perms.add(p); - } - } catch (IOException ioe) { - } - - return perms; - } - /** * See {@code jdk.internal.loader.Loader#findLoadedModule}. */ diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGeneratorRunner.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGeneratorRunner.java index 3ac7a4f509ea..7b09a0891d79 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGeneratorRunner.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGeneratorRunner.java @@ -475,7 +475,7 @@ private int buildImage(ImageClassLoader classLoader) { } try { /* - * First look for an main method with the C-level signature for arguments. + * First look for a main method with the C-level signature for arguments. */ mainEntryPoint = mainClass.getDeclaredMethod(mainEntryPointName, int.class, CCharPointerPointer.class); } catch (NoSuchMethodException ignored2) { @@ -493,7 +493,7 @@ private int buildImage(ImageClassLoader classLoader) { * * MainMethodFinder will perform all the necessary checks */ - String mainMethodFinderClassName = JavaVersionUtil.JAVA_SPEC >= 22 ? "jdk.internal.misc.MethodFinder" : "jdk.internal.misc.MainMethodFinder"; + String mainMethodFinderClassName = "jdk.internal.misc.MethodFinder"; Class mainMethodFinder = ReflectionUtil.lookupClass(false, mainMethodFinderClassName); Method findMainMethod = ReflectionUtil.lookupMethod(mainMethodFinder, "findMainMethod", Class.class); javaMainMethod = (Method) findMainMethod.invoke(null, mainClass); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageOptions.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageOptions.java index 55dd9a597bf0..ad8b706ff679 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageOptions.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageOptions.java @@ -54,7 +54,6 @@ import jdk.graal.compiler.options.OptionStability; import jdk.graal.compiler.options.OptionValues; import jdk.graal.compiler.serviceprovider.GraalServices; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; public class NativeImageOptions { @@ -202,16 +201,11 @@ public static CStandards getCStandard() { public static int getActualNumberOfThreads() { int commonThreadParallelism = ForkJoinPool.getCommonPoolParallelism(); if (NumberOfThreads.getValue() == 1) { - if (JavaVersionUtil.JAVA_SPEC <= 24) { - /* Overriding zero parallelism must ensure at least one worker. */ - assert commonThreadParallelism == 1 : "The common pool with zero parallelism has one worker thread."; - } else { - /* - * Overriding zero parallelism must ensure at least one worker, but due to other - * backward compatibility constraints, it ensures two. - */ - assert commonThreadParallelism == 2 : "The common pool with zero parallelism has two worker threads."; - } + /* + * Overriding zero parallelism must ensure at least one worker, but due to other + * backward compatibility constraints, it ensures two. + */ + assert commonThreadParallelism == 2 : "The common pool with zero parallelism has two worker threads."; /* The common pool with zero parallelism has no actual threads. */ commonThreadParallelism = 0; } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SecurityServicesFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SecurityServicesFeature.java index 1e97695676ff..7334c354f2a8 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SecurityServicesFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SecurityServicesFeature.java @@ -43,7 +43,6 @@ import java.security.KeyPairGenerator; import java.security.KeyStore; import java.security.MessageDigest; -import java.security.Policy; import java.security.Provider; import java.security.Provider.Service; import java.security.SecureRandom; @@ -80,8 +79,6 @@ import javax.security.auth.callback.CallbackHandler; import javax.security.auth.login.Configuration; -import com.oracle.svm.hosted.analysis.Inflation; -import com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.hosted.RuntimeJNIAccess; import org.graalvm.nativeimage.hosted.RuntimeReflection; @@ -105,14 +102,15 @@ import com.oracle.svm.hosted.FeatureImpl.BeforeAnalysisAccessImpl; import com.oracle.svm.hosted.FeatureImpl.DuringAnalysisAccessImpl; import com.oracle.svm.hosted.FeatureImpl.DuringSetupAccessImpl; +import com.oracle.svm.hosted.analysis.Inflation; import com.oracle.svm.hosted.c.NativeLibraries; +import com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor; import com.oracle.svm.util.ModuleSupport; import com.oracle.svm.util.ReflectionUtil; import com.oracle.svm.util.TypeResult; import jdk.graal.compiler.debug.Assertions; import jdk.graal.compiler.options.Option; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; import sun.security.jca.ProviderList; import sun.security.provider.NativePRNG; import sun.security.x509.OIDMap; @@ -170,10 +168,6 @@ public static class Options { KeyGenerator.class, KeyManagerFactory.class, KeyPairGenerator.class, KeyStore.class, Mac.class, MessageDigest.class, SSLContext.class, SecretKeyFactory.class, SecureRandom.class, Signature.class, TrustManagerFactory.class)); - if (JavaVersionUtil.JAVA_SPEC <= 21) { - // JDK-8338411: Implement JEP 486: Permanently Disable the Security Manager - classList.add(Policy.class); - } if (ModuleLayer.boot().findModule("java.security.sasl").isPresent()) { classList.add(ReflectionUtil.lookupClass(false, "javax.security.sasl.SaslClientFactory")); @@ -693,7 +687,7 @@ private static boolean isValid(Service s) { private static Function> getConstructorParameterClassAccessor(ImageClassLoader loader) { Map knownEngines = ReflectionUtil.readStaticField(Provider.class, "knownEngines"); Class clazz = loader.findClassOrFail("java.security.Provider$EngineDescription"); - Field consParamClassField = ReflectionUtil.lookupField(clazz, JavaVersionUtil.JAVA_SPEC >= 23 ? "constructorParameterClass" : "constructorParameterClassName"); + Field consParamClassField = ReflectionUtil.lookupField(clazz, "constructorParameterClass"); /* * The returned lambda captures the value of the Provider.knownEngines map retrieved above @@ -718,13 +712,7 @@ private static Function> getConstructorParameterClassAccessor(I if (engineDescription == null) { return null; } - if (JavaVersionUtil.JAVA_SPEC >= 23) { - return (Class) consParamClassField.get(engineDescription); - } - String constrParamClassName = (String) consParamClassField.get(engineDescription); - if (constrParamClassName != null) { - return loader.findClass(constrParamClassName).get(); - } + return (Class) consParamClassField.get(engineDescription); } catch (IllegalAccessException e) { VMError.shouldNotReachHere(e); } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SystemInOutErrFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SystemInOutErrFeature.java index c27978d41f74..57b5510bf316 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SystemInOutErrFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SystemInOutErrFeature.java @@ -27,11 +27,7 @@ import java.io.InputStream; import java.io.PrintStream; -import java.lang.reflect.Field; -import com.oracle.svm.core.util.VMError; -import com.oracle.svm.util.ReflectionUtil; -import jdk.internal.access.SharedSecrets; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.hosted.Feature; @@ -44,6 +40,8 @@ import com.oracle.svm.core.layeredimagesingleton.FeatureSingleton; import com.oracle.svm.hosted.imagelayer.CrossLayerConstantRegistry; +import jdk.internal.access.SharedSecrets; + /** * We use an {@link Feature.DuringSetupAccess#registerObjectReplacer object replacer} because the * streams can be cached in other instance and static fields in addition to the fields in @@ -64,18 +62,7 @@ public SystemInOutErrFeature() { hostedOut = wrappers.outWrapper; hostedErr = wrappers.errWrapper; hostedInitialIn = SharedSecrets.getJavaLangAccess().initialSystemIn(); - /* - * GR-55515: Migrate to JavaLangAccess#initialSystemErr(). The method - * JavaLangAccess#initialSystemErr() and the System#initialErr field were both introduced in - * JDK 23. Once JDK 21 compatibility is no longer required, consider switching to - * SharedSecrets.getJavaLangAccess().initialSystemErr(). - */ - Field initialErrField = ReflectionUtil.lookupField(true, System.class, "initialErr"); - try { - hostedInitialErr = initialErrField != null ? (PrintStream) initialErrField.get(null) : null; - } catch (IllegalAccessException illegalAccess) { - throw VMError.shouldNotReachHere(illegalAccess); - } + hostedInitialErr = SharedSecrets.getJavaLangAccess().initialSystemErr(); } private SystemInOutErrSupport runtime; diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/imagelayer/SVMImageLayerSnapshotUtil.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/imagelayer/SVMImageLayerSnapshotUtil.java index 02ed26fb5e02..dc8f59d4705f 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/imagelayer/SVMImageLayerSnapshotUtil.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/imagelayer/SVMImageLayerSnapshotUtil.java @@ -85,7 +85,6 @@ import jdk.graal.compiler.nodes.EncodedGraph; import jdk.graal.compiler.nodes.FieldLocationIdentity; import jdk.graal.compiler.nodes.NodeClassMap; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; import jdk.graal.compiler.util.ObjectCopier; import jdk.graal.compiler.util.ObjectCopierInputStream; import jdk.graal.compiler.util.ObjectCopierOutputStream; @@ -123,8 +122,7 @@ public class SVMImageLayerSnapshotUtil { protected static final Set dynamicHubCompanionRelinkedFields = Set.of(classInitializationInfo, superHub, arrayHub); private static final Class sourceRoots = ReflectionUtil.lookupClass("com.oracle.svm.hosted.image.sources.SourceCache$SourceRoots"); - private static final Class completableFuture = JavaVersionUtil.JAVA_SPEC <= 21 ? ReflectionUtil.lookupClass("com.oracle.svm.core.jdk.CompletableFutureJDK21FieldHolder") - : ReflectionUtil.lookupClass("com.oracle.svm.core.jdk.CompletableFutureFieldHolder"); + private static final Class completableFuture = ReflectionUtil.lookupClass("com.oracle.svm.core.jdk.CompletableFutureFieldHolder"); /** * This map stores the field indexes that should be relinked using the hosted value of a diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/AccessControlContextReplacerFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/AccessControlContextReplacerFeature.java deleted file mode 100644 index 53535d322192..000000000000 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/AccessControlContextReplacerFeature.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (c) 2021, 2021, 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.hosted.jdk; - -import java.security.AccessControlContext; -import java.security.DomainCombiner; -import java.security.Permission; -import java.security.ProtectionDomain; -import java.util.HashMap; -import java.util.Map; - -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; - -import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature; -import com.oracle.svm.core.feature.InternalFeature; -import com.oracle.svm.core.jdk.AccessControllerUtil; -import com.oracle.svm.core.util.VMError; -import com.oracle.svm.util.ReflectionUtil; - -@AutomaticallyRegisteredFeature -@SuppressWarnings({"unused"}) -class AccessControlContextReplacerFeature implements InternalFeature { - - @Override - public boolean isInConfiguration(IsInConfigurationAccess access) { - return JavaVersionUtil.JAVA_SPEC == 21; - } - - static Map allowedContexts = new HashMap<>(); - - static void allowContextIfExists(String className, String fieldName) { - try { - // Checkstyle: stop - Class clazz = Class.forName(className); - // Checkstyle: resume - String description = className + "." + fieldName; - try { - AccessControlContext acc = ReflectionUtil.readStaticField(clazz, fieldName); - allowedContexts.put(description, acc); - } catch (ReflectionUtil.ReflectionUtilError e) { - throw VMError.shouldNotReachHere("Following field isn't present in JDK" + JavaVersionUtil.JAVA_SPEC + ": " + description); - } - - } catch (ReflectiveOperationException e) { - throw VMError.shouldNotReachHere("Following class isn't present in JDK" + JavaVersionUtil.JAVA_SPEC + ": " + className); - } - } - - @Override - public void duringSetup(DuringSetupAccess access) { - /* - * Following AccessControlContexts are allowed in the image heap since they cannot leak - * sensitive information. They originate from JDK's static final fields, and they do not - * feature CodeSources, DomainCombiners etc. - * - * New JDK versions will remove old contexts (since AccessControlContext is marked as - * deprecated since JDK 17), so this method should be kept up-to-date. When a listed context - * is removed from JDK, an error message will be thrown from - * AccessControlContextReplacerFeature.allowContextIfExists, so maintaining this list should - * not be difficult (just adding upper bound for JAVA_SPEC in if statements below). - * - * In addition to these contexts, only the very simple contexts are permitted in the image - * heap (see isSimpleContext method). - */ - allowContextIfExists("java.util.Calendar$CalendarAccessControlContext", "INSTANCE"); - allowContextIfExists("javax.management.monitor.Monitor", "noPermissionsACC"); - - allowContextIfExists("java.security.AccessController$AccHolder", "innocuousAcc"); - access.registerObjectReplacer(AccessControlContextReplacerFeature::replaceAccessControlContext); - } - - private static boolean isSimpleContext(AccessControlContext ctx) { - /* - * In addition to aforementioned allow-listed contexts we also allow inclusion of very - * strict subset of contexts that couldn't possibly leak sensitive information in the image - * heap. This set of rules is overly strict on purpose as we want to be on a safe side. - * - * Issues could arise only in cases where end-users manually marked classes that rely on - * doPrivileged invocation in static initializers for initialization at build time. At that - * point they will be presented with an error message from - * Target_java_security_AccessController.checkContext that will inform them about potential - * fixes. - */ - ProtectionDomain[] context = ReflectionUtil.readField(AccessControlContext.class, "context", ctx); - AccessControlContext privilegedContext = ReflectionUtil.readField(AccessControlContext.class, "privilegedContext", ctx); - DomainCombiner combiner = ReflectionUtil.readField(AccessControlContext.class, "combiner", ctx); - Permission[] permissions = ReflectionUtil.readField(AccessControlContext.class, "permissions", ctx); - AccessControlContext parent = ReflectionUtil.readField(AccessControlContext.class, "parent", ctx); - ProtectionDomain[] limitedContext = ReflectionUtil.readField(AccessControlContext.class, "limitedContext", ctx); - - if (context != null && context.length > 0) { - return checkPD(context); - } - if (combiner != null) { - return false; - } - if (parent != null) { - return isSimpleContext(parent); - } - if (limitedContext != null && limitedContext.length > 0) { - return checkPD(limitedContext); - } - if (privilegedContext != null) { - return isSimpleContext(privilegedContext); - } - return true; - } - - private static boolean checkPD(ProtectionDomain[] list) { - for (ProtectionDomain pd : list) { - if (pd.getCodeSource() != null) { - return false; - } - if (pd.getPrincipals().length > 0) { - return false; - } - if (pd.getPermissions() != null) { - return false; - /* - * Technically we could allow certain permissions but this could be fragile. - * Contexts from user code should be reinitialized at runtime anyways. - */ - } - } - return true; - } - - private static Object replaceAccessControlContext(Object obj) { - if (obj instanceof AccessControlContext && obj != AccessControllerUtil.DISALLOWED_CONTEXT_MARKER) { - if (allowedContexts.containsValue(obj)) { - return obj; - } else if (isSimpleContext((AccessControlContext) obj)) { - return obj; - } else { - return AccessControllerUtil.DISALLOWED_CONTEXT_MARKER; - } - } - return obj; - } -} diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JDKInitializationFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JDKInitializationFeature.java index 1def6abd3495..a6f5fb32c145 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JDKInitializationFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JDKInitializationFeature.java @@ -26,11 +26,11 @@ import java.lang.reflect.Field; -import com.oracle.svm.core.FutureDefaultsOptions; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.impl.RuntimeClassInitializationSupport; +import com.oracle.svm.core.FutureDefaultsOptions; import com.oracle.svm.core.ParsingReason; import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature; import com.oracle.svm.core.feature.InternalFeature; @@ -46,7 +46,6 @@ import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugins; import jdk.graal.compiler.nodes.util.ConstantFoldUtil; import jdk.graal.compiler.phases.util.Providers; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; import jdk.vm.ci.meta.JavaConstant; import jdk.vm.ci.meta.JavaKind; import jdk.vm.ci.meta.ResolvedJavaMethod; @@ -239,9 +238,7 @@ public void afterRegistration(AfterRegistrationAccess access) { rci.initializeAtRunTime("jdk.internal.logger.LoggerFinderLoader", "Contains a static field with a FilePermission value"); - if (JavaVersionUtil.JAVA_SPEC >= 23) { - rci.initializeAtRunTime("jdk.internal.markdown.MarkdownTransformer", "Contains a static field with a DocTreeScanner which is initialized at run time"); - } + rci.initializeAtRunTime("jdk.internal.markdown.MarkdownTransformer", "Contains a static field with a DocTreeScanner which is initialized at run time"); /* * The local class Holder in FallbackLinker#getInstance fails the build time initialization diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationAWTSupport.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationAWTSupport.java index c9f05068bf7b..626205c390ec 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationAWTSupport.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationAWTSupport.java @@ -32,8 +32,6 @@ import com.oracle.svm.core.jdk.JNIRegistrationUtil; import com.oracle.svm.hosted.FeatureImpl.BeforeImageWriteAccessImpl; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; - @Platforms({Platform.WINDOWS.class, Platform.LINUX.class}) @AutomaticallyRegisteredFeature public class JNIRegistrationAWTSupport extends JNIRegistrationUtil implements InternalFeature { @@ -42,11 +40,8 @@ public void afterAnalysis(AfterAnalysisAccess access) { JNIRegistrationSupport jniRegistrationSupport = JNIRegistrationSupport.singleton(); if (jniRegistrationSupport.isRegisteredLibrary("awt")) { jniRegistrationSupport.addJvmShimExports( - "jio_snprintf"); - if (JavaVersionUtil.JAVA_SPEC > 21) { - jniRegistrationSupport.addJvmShimExports( - "JVM_IsStaticallyLinked"); - } + "jio_snprintf", + "JVM_IsStaticallyLinked"); jniRegistrationSupport.addJavaShimExports( "JNU_CallMethodByName", "JNU_CallStaticMethodByName", diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJava.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJava.java index f39d573488ef..570b5c468744 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJava.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJava.java @@ -30,7 +30,6 @@ import java.util.List; import java.util.function.Consumer; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.hosted.RuntimeJNIAccess; import org.graalvm.nativeimage.impl.InternalPlatform; @@ -121,13 +120,8 @@ public void beforeAnalysis(BeforeAnalysisAccess a) { PlatformNativeLibrarySupport.singleton().addBuiltinPkgNativePrefix("sun_security_provider_NativeSeedGenerator"); } if (isDarwin()) { - Class[] scanKeychainParameterTypes = {}; - if (JavaVersionUtil.JAVA_SPEC >= 23) { - // JDK-8320362 - scanKeychainParameterTypes = new Class[]{String.class}; - } List darwinMethods = Arrays.asList( - method(a, "apple.security.KeychainStore", "_scanKeychain", scanKeychainParameterTypes), + method(a, "apple.security.KeychainStore", "_scanKeychain", String.class), // JDK-8320362 method(a, "apple.security.KeychainStore", "_releaseKeychainItemRef", long.class), method(a, "apple.security.KeychainStore", "_addItemToKeychain", String.class, boolean.class, byte[].class, char[].class), method(a, "apple.security.KeychainStore", "_removeItemFromKeychain", long.class), diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNio.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNio.java index ed27eead6ff7..822ad1096119 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNio.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNio.java @@ -38,8 +38,6 @@ import com.oracle.svm.core.feature.InternalFeature; import com.oracle.svm.core.jdk.JNIRegistrationUtil; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; - /** * Registration of classes, methods, and fields accessed via JNI by C code of the JDK. */ @@ -106,9 +104,6 @@ public void beforeAnalysis(BeforeAnalysisAccess a) { // JDK-8220738 a.registerReachabilityHandler(JNIRegistrationJavaNio::registerNetInitIDs, method(a, "sun.nio.ch.Net", "initIDs")); - if (JavaVersionUtil.JAVA_SPEC <= 21) { - a.registerReachabilityHandler(JNIRegistrationJavaNio::registerFileKeyInitIDs, method(a, "sun.nio.ch.FileKey", "initIDs")); - } if (isPosix()) { a.registerReachabilityHandler(JNIRegistrationJavaNio::registerUnixNativeDispatcherInit, method(a, "sun.nio.fs.UnixNativeDispatcher", "init")); @@ -135,14 +130,6 @@ private static void registerNetInitIDs(DuringAnalysisAccess a) { RuntimeJNIAccess.register(constructor(a, "java.net.InetSocketAddress", InetAddress.class, int.class)); } - private static void registerFileKeyInitIDs(DuringAnalysisAccess a) { - if (isPosix()) { - RuntimeJNIAccess.register(fields(a, "sun.nio.ch.FileKey", "st_dev", "st_ino")); - } else if (isWindows()) { - RuntimeJNIAccess.register(fields(a, "sun.nio.ch.FileKey", "dwVolumeSerialNumber", "nFileIndexHigh", "nFileIndexLow")); - } - } - private static void registerUnixNativeDispatcherInit(DuringAnalysisAccess a) { RuntimeJNIAccess.register(clazz(a, "sun.nio.fs.UnixFileAttributes")); RuntimeJNIAccess.register(fields(a, "sun.nio.fs.UnixFileAttributes", @@ -150,9 +137,7 @@ private static void registerUnixNativeDispatcherInit(DuringAnalysisAccess a) { "st_atime_sec", "st_atime_nsec", "st_mtime_sec", "st_mtime_nsec", "st_ctime_sec", "st_ctime_nsec")); if (isDarwin() || isLinux()) { RuntimeJNIAccess.register(fields(a, "sun.nio.fs.UnixFileAttributes", "st_birthtime_sec")); - if (JavaVersionUtil.JAVA_SPEC > 21) { - RuntimeJNIAccess.register(fields(a, "sun.nio.fs.UnixFileAttributes", "birthtime_available")); - } + RuntimeJNIAccess.register(fields(a, "sun.nio.fs.UnixFileAttributes", "birthtime_available")); } if (isLinux()) { RuntimeJNIAccess.register(fields(a, "sun.nio.fs.UnixFileAttributes", "st_birthtime_nsec")); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/localization/LocalizationFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/localization/LocalizationFeature.java index b9750af8e9bd..2d670c874e49 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/localization/LocalizationFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/localization/LocalizationFeature.java @@ -93,7 +93,6 @@ import jdk.graal.compiler.options.Option; import jdk.graal.compiler.options.OptionStability; import jdk.graal.compiler.options.OptionType; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; import jdk.internal.access.SharedSecrets; import jdk.vm.ci.meta.ResolvedJavaField; import jdk.vm.ci.meta.ResolvedJavaMethod; @@ -292,16 +291,9 @@ public void duringSetup(DuringSetupAccess a) { } langAliasesCacheField = access.findField(CLDRLocaleProviderAdapter.class, "langAliasesCache"); parentLocalesMapField = access.findField(CLDRLocaleProviderAdapter.class, "parentLocalesMap"); - - if (JavaVersionUtil.JAVA_SPEC >= 23) { - baseLocaleCacheField = access.findField("sun.util.locale.BaseLocale$1InterningCache", "CACHE"); - localeCacheField = access.findField("java.util.Locale$LocaleCache", "LOCALE_CACHE"); - localeObjectCacheMapField = null; - } else { - baseLocaleCacheField = access.findField("sun.util.locale.BaseLocale$Cache", "CACHE"); - localeCacheField = access.findField("java.util.Locale$Cache", "LOCALECACHE"); - localeObjectCacheMapField = access.findField("sun.util.locale.LocaleObjectCache", "map"); - } + baseLocaleCacheField = access.findField("sun.util.locale.BaseLocale$1InterningCache", "CACHE"); + localeCacheField = access.findField("java.util.Locale$LocaleCache", "LOCALE_CACHE"); + localeObjectCacheMapField = null; candidatesCacheField = access.findField("java.util.ResourceBundle$Control", "CANDIDATES_CACHE"); String reason = "All ResourceBundleControlProvider that are registered as services end up as objects in the image heap, and are therefore registered to be initialized at image build time"; diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jfr/JfrEventFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jfr/JfrEventFeature.java index 92b93efbbc55..7d9fd1cede9f 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jfr/JfrEventFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jfr/JfrEventFeature.java @@ -27,7 +27,6 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.RandomAccessFile; -import java.lang.reflect.Method; import java.util.Collection; import java.util.List; @@ -45,11 +44,9 @@ import com.oracle.svm.core.hub.DynamicHubSupport; import com.oracle.svm.core.jfr.JfrFeature; import com.oracle.svm.core.jfr.JfrJavaEvents; -import com.oracle.svm.core.jfr.JfrJdkCompatibility; import com.oracle.svm.core.jfr.traceid.JfrTraceId; import com.oracle.svm.core.jfr.traceid.JfrTraceIdMap; import com.oracle.svm.core.meta.SharedType; -import com.oracle.svm.core.util.VMError; import com.oracle.svm.hosted.FeatureImpl; import com.oracle.svm.hosted.ameta.FieldValueInterceptionSupport; import com.oracle.svm.hosted.reflect.ReflectionFeature; @@ -132,16 +129,11 @@ public void beforeCompilation(BeforeCompilationAccess a) { } /* Store the event configuration in the dynamic hub companion. */ - try { - FeatureImpl.CompilationAccessImpl accessImpl = ((FeatureImpl.CompilationAccessImpl) a); - Method getConfiguration = JVM.class.getDeclaredMethod("getConfiguration", Class.class); - for (var newEventClass : JfrJavaEvents.getAllEventClasses()) { - Object ec = getConfiguration.invoke(JfrJdkCompatibility.getJVMOrNull(), newEventClass); - DynamicHub dynamicHub = accessImpl.getMetaAccess().lookupJavaType(newEventClass).getHub(); - dynamicHub.setJrfEventConfiguration(ec); - } - } catch (ReflectiveOperationException ex) { - throw VMError.shouldNotReachHere(ex); + FeatureImpl.CompilationAccessImpl accessImpl = ((FeatureImpl.CompilationAccessImpl) a); + for (var newEventClass : JfrJavaEvents.getAllEventClasses()) { + Object ec = JVM.getConfiguration(newEventClass); + DynamicHub dynamicHub = accessImpl.getMetaAccess().lookupJavaType(newEventClass).getHub(); + dynamicHub.setJrfEventConfiguration(ec); } } } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jfr/JfrEventSubstitution.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jfr/JfrEventSubstitution.java index d5d79088927e..21ed0a45a415 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jfr/JfrEventSubstitution.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jfr/JfrEventSubstitution.java @@ -24,13 +24,8 @@ */ package com.oracle.svm.hosted.jfr; -import java.lang.annotation.Annotation; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import org.graalvm.nativeimage.AnnotationAccess; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; @@ -39,16 +34,10 @@ import com.oracle.graal.pointsto.infrastructure.SubstitutionProcessor; import com.oracle.svm.core.BuildPhaseProvider; import com.oracle.svm.core.jfr.JfrJavaEvents; -import com.oracle.svm.core.jfr.JfrJdkCompatibility; -import com.oracle.svm.core.util.ObservableImageHeapMapProvider; import com.oracle.svm.core.util.VMError; -import com.oracle.svm.util.ReflectionUtil; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; -import jdk.internal.event.Event; import jdk.jfr.internal.JVM; import jdk.jfr.internal.MetadataRepository; -import jdk.jfr.internal.SecuritySupport; import jdk.vm.ci.meta.MetaAccessProvider; import jdk.vm.ci.meta.ResolvedJavaField; import jdk.vm.ci.meta.ResolvedJavaMethod; @@ -68,10 +57,6 @@ public class JfrEventSubstitution extends SubstitutionProcessor { private final ConcurrentHashMap typeSubstitution; private final ConcurrentHashMap methodSubstitutions; private final ConcurrentHashMap fieldSubstitutions; - private final Map> mirrorEventMapping; - - private static final Method registerMirror = JavaVersionUtil.JAVA_SPEC < 22 ? ReflectionUtil.lookupMethod(SecuritySupport.class, "registerMirror", Class.class) : null; - private static final Method getConfiguration = ReflectionUtil.lookupMethod(JVM.class, "getConfiguration", Class.class); JfrEventSubstitution(MetaAccessProvider metaAccess, ImageHeapScanner heapScanner) { this.heapScanner = heapScanner; @@ -79,11 +64,6 @@ public class JfrEventSubstitution extends SubstitutionProcessor { typeSubstitution = new ConcurrentHashMap<>(); methodSubstitutions = new ConcurrentHashMap<>(); fieldSubstitutions = new ConcurrentHashMap<>(); - if (JavaVersionUtil.JAVA_SPEC < 22) { - mirrorEventMapping = createMirrorEventsMapping(); - } else { - mirrorEventMapping = null; - } } @Override @@ -161,28 +141,15 @@ private Boolean initEventClass(ResolvedJavaType eventType) throws RuntimeExcepti Class newEventClass = OriginalClassProvider.getJavaClass(eventType).asSubclass(jdk.internal.event.Event.class); eventType.initialize(); - if (JavaVersionUtil.JAVA_SPEC < 22) { - /* - * It is crucial that mirror events are registered before the actual events. - * Starting with JDK 22, this is no longer necessary because - * MetadataRepository.register(...) handles that directly, see code that uses - * MirrorEvents.find(...). - */ - Class mirrorEventClass = mirrorEventMapping.get(newEventClass.getName()); - if (mirrorEventClass != null) { - registerMirror.invoke(null, mirrorEventClass); - } - } - - registerEventInMetadataRepository(newEventClass); + MetadataRepository.getInstance().register(newEventClass); JfrJavaEvents.registerEventClass(newEventClass); // the reflection registration for the event handler field is delayed to the JfrFeature // duringAnalysis callback so it does not race/interfere with other retransforms - JfrJdkCompatibility.retransformClasses(new Class[]{newEventClass}); + JVM.retransformClasses(new Class[]{newEventClass}); // make sure the EventConfiguration object is fully scanned - heapScanner.rescanObject(getConfiguration.invoke(JfrJdkCompatibility.getJVMOrNull(), newEventClass)); + heapScanner.rescanObject(JVM.getConfiguration(newEventClass)); return Boolean.TRUE; } catch (Throwable ex) { @@ -190,40 +157,7 @@ private Boolean initEventClass(ResolvedJavaType eventType) throws RuntimeExcepti } } - private static void registerEventInMetadataRepository(Class newEventClass) throws IllegalAccessException, InvocationTargetException { - if (JavaVersionUtil.JAVA_SPEC == 21) { - ReflectionUtil.lookupMethod(SecuritySupport.class, "registerEvent", Class.class).invoke(null, newEventClass); - } else { - ReflectionUtil.lookupMethod(MetadataRepository.class, "register", Class.class).invoke(MetadataRepository.getInstance(), newEventClass); - } - } - private boolean needsClassRedefinition(ResolvedJavaType type) { return !type.isAbstract() && baseEventType.isAssignableFrom(type) && !baseEventType.equals(type); } - - /* - * Mirror events contain the JFR-specific annotations. The mirrored event does not have any - * dependency on JFR-specific classes. If the mirrored event is used, we must ensure that the - * mirror event is registered as well. Otherwise, incorrect JFR metadata would be emitted. - */ - @SuppressWarnings("unchecked") - private static Map> createMirrorEventsMapping() { - Map> result = ObservableImageHeapMapProvider.create(); - Class mirrorEventAnnotationClass = (Class) ReflectionUtil.lookupClass(false, "jdk.jfr.internal.MirrorEvent"); - Class jdkEventsClass = ReflectionUtil.lookupClass(false, "jdk.jfr.internal.instrument.JDKEvents"); - Class[] mirrorEventClasses = ReflectionUtil.readStaticField(jdkEventsClass, "mirrorEventClasses"); - for (int i = 0; i < mirrorEventClasses.length; i++) { - Class mirrorEventClass = (Class) mirrorEventClasses[i]; - Annotation mirrorEvent = AnnotationAccess.getAnnotation(mirrorEventClass, mirrorEventAnnotationClass); - Method m = ReflectionUtil.lookupMethod(mirrorEventAnnotationClass, "className"); - try { - String className = (String) m.invoke(mirrorEvent); - result.put(className, mirrorEventClass); - } catch (Exception e) { - throw VMError.shouldNotReachHere(e); - } - } - return result; - } } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jni/JNIFunctionTablesFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jni/JNIFunctionTablesFeature.java index 871362c9c649..5e4e222b6ad8 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jni/JNIFunctionTablesFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jni/JNIFunctionTablesFeature.java @@ -62,7 +62,6 @@ import com.oracle.svm.hosted.meta.HostedMethod; import com.oracle.svm.hosted.meta.HostedType; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; import jdk.vm.ci.meta.JavaKind; import jdk.vm.ci.meta.MetaAccessProvider; import jdk.vm.ci.meta.ResolvedJavaMethod; @@ -112,16 +111,14 @@ public void beforeAnalysis(BeforeAnalysisAccess arg) { invokeInterfaceMetadata = (StructInfo) nativeLibraries.findElementInfo(invokeInterface); AnalysisType functionTable = metaAccess.lookupJavaType(JNINativeInterface.class); functionTableMetadata = (StructInfo) nativeLibraries.findElementInfo(functionTable); - if (JavaVersionUtil.JAVA_SPEC > 21) { - functionTableMetadataJDKLatest = (StructInfo) nativeLibraries.findElementInfo(metaAccess.lookupJavaType(JNINativeInterfaceJDKLatest.class)); - } + functionTableMetadataJDKLatest = (StructInfo) nativeLibraries.findElementInfo(metaAccess.lookupJavaType(JNINativeInterfaceJDKLatest.class)); // Manually add functions as entry points so this is only done when JNI features are enabled AnalysisType invokes = metaAccess.lookupJavaType(JNIInvocationInterface.class); AnalysisType exports = metaAccess.lookupJavaType(JNIInvocationInterface.Exports.class); AnalysisType functions = metaAccess.lookupJavaType(JNIFunctions.class); - AnalysisType functionsJDKLatest = JavaVersionUtil.JAVA_SPEC > 21 ? metaAccess.lookupJavaType(JNIFunctionsJDKLatest.class) : null; - Stream analysisMethods = Stream.of(invokes, functions, functionsJDKLatest, exports).filter(type -> type != null).flatMap(type -> Stream.of(type.getDeclaredMethods(false))); + AnalysisType functionsJDKLatest = metaAccess.lookupJavaType(JNIFunctionsJDKLatest.class); + Stream analysisMethods = Stream.of(invokes, functions, functionsJDKLatest, exports).flatMap(type -> Stream.of(type.getDeclaredMethods(false))); Stream unimplementedMethods = Stream.of((AnalysisMethod) getSingleMethod(metaAccess, UnimplementedWithJNIEnvArgument.class), (AnalysisMethod) getSingleMethod(metaAccess, UnimplementedWithJavaVMArgument.class)); Stream.concat(analysisMethods, unimplementedMethods).forEach(method -> { @@ -187,13 +184,11 @@ private void fillJNIFunctionsTable(CompilationAccessImpl access) { int offset = field.getOffsetInfo().getProperty(); tables.initFunctionEntry(offset, getStubFunctionPointer(access, method)); } - if (JavaVersionUtil.JAVA_SPEC > 21) { - HostedType functionsJDKLatest = access.getMetaAccess().lookupJavaType(JNIFunctionsJDKLatest.class); - for (HostedMethod method : functionsJDKLatest.getDeclaredMethods(false)) { - StructFieldInfo field = findFieldFor(functionTableMetadataJDKLatest, method.getName()); - int offset = field.getOffsetInfo().getProperty(); - tables.initFunctionEntry(offset, getStubFunctionPointer(access, method)); - } + HostedType functionsJDKLatest = access.getMetaAccess().lookupJavaType(JNIFunctionsJDKLatest.class); + for (HostedMethod method : functionsJDKLatest.getDeclaredMethods(false)) { + StructFieldInfo field = findFieldFor(functionTableMetadataJDKLatest, method.getName()); + int offset = field.getOffsetInfo().getProperty(); + tables.initFunctionEntry(offset, getStubFunctionPointer(access, method)); } for (CallVariant variant : CallVariant.values()) { CFunctionPointer trampoline = prepareCallTrampoline(access, variant, false); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/methodhandles/MethodHandleFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/methodhandles/MethodHandleFeature.java index 448ab4dabee0..a8d47159d3a1 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/methodhandles/MethodHandleFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/methodhandles/MethodHandleFeature.java @@ -55,7 +55,6 @@ import com.oracle.svm.hosted.FeatureImpl.DuringSetupAccessImpl; import com.oracle.svm.util.ReflectionUtil; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; import sun.invoke.util.ValueConversions; import sun.invoke.util.Wrapper; @@ -122,28 +121,12 @@ public void duringSetup(DuringSetupAccess access) { Class makersClass = ReflectionUtil.lookupClass("java.lang.invoke.MethodHandleImpl$Makers"); typedCollectors = ReflectionUtil.lookupField(makersClass, "TYPED_COLLECTORS"); - if (JavaVersionUtil.JAVA_SPEC >= 22) { - try { - Class referencedKeySetClass = ReflectionUtil.lookupClass("jdk.internal.util.ReferencedKeySet"); - // The following call must match the static initializer of MethodType#internTable. - if (JavaVersionUtil.JAVA_SPEC >= 24) { - Method create = ReflectionUtil.lookupMethod(referencedKeySetClass, "create", boolean.class, Supplier.class); - runtimeMethodTypeInternTable = create.invoke(null, - /* isSoft */ false, (Supplier) () -> new ConcurrentHashMap<>(512)); - } else { - Method create = ReflectionUtil.lookupMethod(referencedKeySetClass, "create", boolean.class, boolean.class, Supplier.class); - runtimeMethodTypeInternTable = create.invoke(null, - /* isSoft */ false, /* useNativeQueue */ true, (Supplier) () -> new ConcurrentHashMap<>(512)); - } - referencedKeySetAdd = ReflectionUtil.lookupMethod(referencedKeySetClass, "add", Object.class); - } catch (ReflectiveOperationException e) { - throw VMError.shouldNotReachHere(e); - } - } else { - Class concurrentWeakInternSetClass = ReflectionUtil.lookupClass("java.lang.invoke.MethodType$ConcurrentWeakInternSet"); - runtimeMethodTypeInternTable = ReflectionUtil.newInstance(concurrentWeakInternSetClass); - referencedKeySetAdd = ReflectionUtil.lookupMethod(concurrentWeakInternSetClass, "add", Object.class); - } + Class referencedKeySetClass = ReflectionUtil.lookupClass("jdk.internal.util.ReferencedKeySet"); + // The following call must match the static initializer of MethodType#internTable. + Method create = ReflectionUtil.lookupMethod(referencedKeySetClass, "create", boolean.class, Supplier.class); + runtimeMethodTypeInternTable = ReflectionUtil.invokeMethod(create, null, + /* isSoft */ false, (Supplier) () -> new ConcurrentHashMap<>(512)); + referencedKeySetAdd = ReflectionUtil.lookupMethod(referencedKeySetClass, "add", Object.class); var accessImpl = (DuringSetupAccessImpl) access; substitutionProcessor = new MethodHandleInvokerRenamingSubstitutionProcessor(accessImpl.getBigBang()); @@ -243,51 +226,48 @@ public Object transform(Object receiver, Object originalValue) { access.registerFieldValueTransformer(ReflectionUtil.lookupField(ReflectionUtil.lookupClass("java.lang.invoke.ClassSpecializer$SpeciesData"), "transformHelpers"), methodHandleArrayTransformer); access.registerFieldValueTransformer(ReflectionUtil.lookupField(ReflectionUtil.lookupClass("java.lang.invoke.MethodHandleImpl"), "ARRAYS"), methodHandleArrayTransformer); - if (JavaVersionUtil.JAVA_SPEC >= 24) { - /* - * StringConcatFactory$InlineHiddenClassStrategy was added in JDK 24, as well as its - * CACHE field, so there is no need to filter for previous JDK versions. - */ - Class referencedKeyMapClazz = ReflectionUtil.lookupClass("jdk.internal.util.ReferencedKeyMap"); - Method createMethod = ReflectionUtil.lookupMethod(referencedKeyMapClazz, "create", boolean.class, Supplier.class); - Method concurrentHashMapSupplierMethod = ReflectionUtil.lookupMethod(referencedKeyMapClazz, "concurrentHashMapSupplier"); - Class methodHandlePair = ReflectionUtil.lookupClass("java.lang.invoke.StringConcatFactory$InlineHiddenClassStrategy$MethodHandlePair"); - Method constructorGetter = ReflectionUtil.lookupMethod(methodHandlePair, "constructor"); - Method concatenatorGetter = ReflectionUtil.lookupMethod(methodHandlePair, "concatenator"); - - /* - * StringConcatFactory$InlineHiddenClassStrategy.CACHE is a cache like - * SpeciesData.transformHelpers, so it needs a similar transformation for the same - * reasons. - */ - access.registerFieldValueTransformer( - ReflectionUtil.lookupField(ReflectionUtil.lookupClass("java.lang.invoke.StringConcatFactory$InlineHiddenClassStrategy"), "CACHE"), - new FieldValueTransformerWithAvailability() { - @Override - public boolean isAvailable() { - return BuildPhaseProvider.isHostedUniverseBuilt(); - } + /* + * StringConcatFactory$InlineHiddenClassStrategy was added in JDK 24, as well as its CACHE + * field, so there is no need to filter for previous JDK versions. + */ + Class referencedKeyMapClazz = ReflectionUtil.lookupClass("jdk.internal.util.ReferencedKeyMap"); + Method createMethod = ReflectionUtil.lookupMethod(referencedKeyMapClazz, "create", boolean.class, Supplier.class); + Method concurrentHashMapSupplierMethod = ReflectionUtil.lookupMethod(referencedKeyMapClazz, "concurrentHashMapSupplier"); + Class methodHandlePair = ReflectionUtil.lookupClass("java.lang.invoke.StringConcatFactory$InlineHiddenClassStrategy$MethodHandlePair"); + Method constructorGetter = ReflectionUtil.lookupMethod(methodHandlePair, "constructor"); + Method concatenatorGetter = ReflectionUtil.lookupMethod(methodHandlePair, "concatenator"); - @Override - @SuppressWarnings("unchecked") - public Object transform(Object receiver, Object originalValue) { - Map> cache = (Map>) originalValue; - Map result = ReflectionUtil.invokeMethod(createMethod, null, true, ReflectionUtil.invokeMethod(concurrentHashMapSupplierMethod, null)); - - for (var entry : cache.entrySet()) { - SoftReference value = entry.getValue(); - Object object = value.get(); - MethodHandle constructor = ReflectionUtil.invokeMethod(constructorGetter, object); - MethodHandle concatenator = ReflectionUtil.invokeMethod(concatenatorGetter, object); - if (constructor != null && concatenator != null && heapScanner.isObjectReachable(constructor) && heapScanner.isObjectReachable(concatenator)) { - result.put(entry.getKey(), value); - } - } + /* + * StringConcatFactory$InlineHiddenClassStrategy.CACHE is a cache like + * SpeciesData.transformHelpers, so it needs a similar transformation for the same reasons. + */ + access.registerFieldValueTransformer( + ReflectionUtil.lookupField(ReflectionUtil.lookupClass("java.lang.invoke.StringConcatFactory$InlineHiddenClassStrategy"), "CACHE"), + new FieldValueTransformerWithAvailability() { + @Override + public boolean isAvailable() { + return BuildPhaseProvider.isHostedUniverseBuilt(); + } - return result; + @Override + @SuppressWarnings("unchecked") + public Object transform(Object receiver, Object originalValue) { + Map> cache = (Map>) originalValue; + Map result = ReflectionUtil.invokeMethod(createMethod, null, true, ReflectionUtil.invokeMethod(concurrentHashMapSupplierMethod, null)); + + for (var entry : cache.entrySet()) { + SoftReference value = entry.getValue(); + Object object = value.get(); + MethodHandle constructor = ReflectionUtil.invokeMethod(constructorGetter, object); + MethodHandle concatenator = ReflectionUtil.invokeMethod(concatenatorGetter, object); + if (constructor != null && concatenator != null && heapScanner.isObjectReachable(constructor) && heapScanner.isObjectReachable(concatenator)) { + result.put(entry.getKey(), value); + } } - }); - } + + return result; + } + }); /* * Retrieve all six basic types from the java.lang.invoke.LambdaForm$BasicType class (void, @@ -300,8 +280,7 @@ public Object transform(Object receiver, Object originalValue) { */ Class lambdaFormClass = ReflectionUtil.lookupClass("java.lang.invoke.LambdaForm"); Class basicTypeClass = ReflectionUtil.lookupClass("java.lang.invoke.LambdaForm$BasicType"); - Method createFormsForMethod = JavaVersionUtil.JAVA_SPEC == 21 ? ReflectionUtil.lookupMethod(lambdaFormClass, "createFormsFor", basicTypeClass) - : ReflectionUtil.lookupMethod(lambdaFormClass, "createIdentityForm", basicTypeClass); + Method createFormsForMethod = ReflectionUtil.lookupMethod(lambdaFormClass, "createIdentityForm", basicTypeClass); try { for (Object type : (Object[]) ReflectionUtil.readStaticField(basicTypeClass, "ALL_TYPES")) { createFormsForMethod.invoke(null, type); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/methodhandles/MethodHandleInvokerRenamingSubstitutionProcessor.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/methodhandles/MethodHandleInvokerRenamingSubstitutionProcessor.java index 7cc61958930b..185ba7101106 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/methodhandles/MethodHandleInvokerRenamingSubstitutionProcessor.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/methodhandles/MethodHandleInvokerRenamingSubstitutionProcessor.java @@ -46,7 +46,6 @@ import com.oracle.svm.core.util.VMError; import com.oracle.svm.util.ReflectionUtil; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; import jdk.vm.ci.meta.ResolvedJavaType; /** @@ -101,10 +100,6 @@ public class MethodHandleInvokerRenamingSubstitutionProcessor extends Substituti private static final Method BOUND_METHOD_HANDLE_SPECIES_DATA_METHOD = ReflectionUtil.lookupMethod(BOUND_METHOD_HANDLE_CLASS, "speciesData"); private static final Class DIRECT_METHOD_HANDLE_CLASS = ReflectionUtil.lookupClass(false, "java.lang.invoke.DirectMethodHandle"); private static final Method DIRECT_METHOD_HANDLE_INTERNAL_MEMBER_NAME_METHOD = ReflectionUtil.lookupMethod(DIRECT_METHOD_HANDLE_CLASS, "internalMemberName"); - private static final Class METHOD_HANDLE_IMPL_INTRINSIC_METHOD_HANDLE_CLASS = JavaVersionUtil.JAVA_SPEC > 21 ? null - : ReflectionUtil.lookupClass("java.lang.invoke.MethodHandleImpl$IntrinsicMethodHandle"); - private static final Method METHOD_HANDLE_IMPL_INTRINSIC_METHOD_HANDLE_INTRINSIC_DATA_METHOD = JavaVersionUtil.JAVA_SPEC > 21 ? null - : ReflectionUtil.lookupMethod(METHOD_HANDLE_IMPL_INTRINSIC_METHOD_HANDLE_CLASS, "intrinsicData"); private static final String DMH_CLASS_NAME_SUBSTRING = "LambdaForm$DMH"; private static final String DMH_STABLE_NAME_TEMPLATE = "Ljava/lang/invoke/LambdaForm$DMH.s"; @@ -318,13 +313,6 @@ private int getUniqueStableHash(Object lambdaForm) throws ReflectiveOperationExc Object resolvedHandle = NAMED_FUNCTION_RESOLVED_HANDLE_METHOD.invoke(function); MethodType methodType = ((MethodHandle) resolvedHandle).type(); hash = hash * 31 + methodType.descriptorString().hashCode(); - if (JavaVersionUtil.JAVA_SPEC <= 21) { - if (METHOD_HANDLE_IMPL_INTRINSIC_METHOD_HANDLE_CLASS.isInstance(resolvedHandle)) { - if (METHOD_HANDLE_IMPL_INTRINSIC_METHOD_HANDLE_INTRINSIC_DATA_METHOD.invoke(resolvedHandle) instanceof Integer integer) { - hash = hash * 31 + integer; - } - } - } if (BOUND_METHOD_HANDLE_CLASS.isInstance(resolvedHandle)) { /* diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/serialize/SerializationFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/serialize/SerializationFeature.java index 49e27e17a6e3..e9959b5b76e7 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/serialize/SerializationFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/serialize/SerializationFeature.java @@ -93,7 +93,6 @@ import jdk.graal.compiler.nodes.ConstantNode; import jdk.graal.compiler.nodes.StructuredGraph; import jdk.graal.compiler.options.OptionValues; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; import jdk.internal.access.JavaLangReflectAccess; import jdk.internal.reflect.ConstructorAccessor; import jdk.internal.reflect.ReflectionFactory; @@ -599,13 +598,6 @@ private static void registerForDeserialization(ConfigurationCondition cnd, Class } private Constructor newConstructorForSerialization(Class serializationTargetClass, Constructor customConstructorToCall) { - if (JavaVersionUtil.JAVA_SPEC <= 21) { - if (customConstructorToCall == null) { - return ReflectionFactory.getReflectionFactory().newConstructorForSerialization(serializationTargetClass); - } else { - return ReflectionFactory.getReflectionFactory().newConstructorForSerialization(serializationTargetClass, customConstructorToCall); - } - } Constructor constructorToCall; if (customConstructorToCall == null) { constructorToCall = getConstructorForSerialization(serializationTargetClass); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/snippets/SubstrateGraphBuilderPlugins.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/snippets/SubstrateGraphBuilderPlugins.java index e371cedcc9ed..d3525db19854 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/snippets/SubstrateGraphBuilderPlugins.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/snippets/SubstrateGraphBuilderPlugins.java @@ -166,7 +166,6 @@ import jdk.graal.compiler.replacements.nodes.MacroNode.MacroParams; import jdk.graal.compiler.replacements.nodes.VectorizedHashCodeNode; import jdk.graal.compiler.replacements.nodes.VectorizedMismatchNode; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; import jdk.graal.compiler.word.WordCastNode; import jdk.internal.foreign.MemorySessionImpl; import jdk.vm.ci.code.Architecture; @@ -1126,17 +1125,14 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return false; } }); - if (JavaVersionUtil.JAVA_SPEC > 21) { - // In JDK 21, the same plugin is registered in StandardGraphBuilderPlugins - r.register(new InvocationPlugin("isArray", Receiver.class) { - @Override - public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) { - LogicNode isArray = b.add(ClassIsArrayNode.create(b.getConstantReflection(), receiver.get(true))); - b.addPush(JavaKind.Boolean, ConditionalNode.create(isArray, NodeView.DEFAULT)); - return true; - } - }); - } + r.register(new InvocationPlugin("isArray", Receiver.class) { + @Override + public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) { + LogicNode isArray = b.add(ClassIsArrayNode.create(b.getConstantReflection(), receiver.get(true))); + b.addPush(JavaKind.Boolean, ConditionalNode.create(isArray, NodeView.DEFAULT)); + return true; + } + }); registerClassDesiredAssertionStatusPlugin(plugins); } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/xml/JavaxXmlClassAndResourcesLoaderFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/xml/JavaxXmlClassAndResourcesLoaderFeature.java index 52e8deeda0b5..0a83ca6d2958 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/xml/JavaxXmlClassAndResourcesLoaderFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/xml/JavaxXmlClassAndResourcesLoaderFeature.java @@ -41,8 +41,6 @@ import com.oracle.svm.core.jdk.JNIRegistrationUtil; import com.oracle.svm.util.ReflectionUtil; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; - @AutomaticallyRegisteredFeature public class JavaxXmlClassAndResourcesLoaderFeature extends JNIRegistrationUtil implements InternalFeature { @@ -81,9 +79,6 @@ public void beforeAnalysis(BeforeAnalysisAccess access) { * XMLSecurityManager#prepareCatalog (JDK-8350189). */ private static void initializeJdkCatalog() { - if (JavaVersionUtil.JAVA_SPEC <= 21) { - return; - } if (ModuleLayer.boot().findModule("java.xml").isPresent()) { // Ensure the JdkCatalog#catalog field is initialized. Class xmlSecurityManager = ReflectionUtil.lookupClass(false, "jdk.xml.internal.XMLSecurityManager"); diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestContainerEvent.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestContainerEvent.java index dc43e13bd8ad..18778d738a0c 100644 --- a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestContainerEvent.java +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestContainerEvent.java @@ -36,7 +36,6 @@ import com.oracle.svm.core.container.Container; import com.oracle.svm.test.jfr.events.ThreadEvent; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; import jdk.jfr.Recording; import jdk.jfr.consumer.RecordedEvent; @@ -68,9 +67,7 @@ private static void validateEvents(List events) { long hostTotalMem = re.getValue("hostTotalMemory"); assertTrue(hostTotalMem > 0); - if (JavaVersionUtil.JAVA_SPEC >= 23) { - long hostTotalSwap = re.getValue("hostTotalSwapMemory"); - assertTrue("Host swap not implemented", hostTotalSwap < 0); - } + long hostTotalSwap = re.getValue("hostTotalSwapMemory"); + assertTrue("Host swap not implemented", hostTotalSwap < 0); } } diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestJavaLevelVirtualThreadEvents.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestJavaLevelVirtualThreadEvents.java index 6a0e950e19d8..11d10608bad2 100644 --- a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestJavaLevelVirtualThreadEvents.java +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestJavaLevelVirtualThreadEvents.java @@ -41,7 +41,6 @@ import com.oracle.svm.core.thread.Target_jdk_internal_vm_Continuation; import com.oracle.svm.test.jfr.events.StringEvent; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; import jdk.jfr.Recording; import jdk.jfr.consumer.RecordedEvent; import jdk.jfr.consumer.RecordedThread; @@ -56,11 +55,7 @@ public class TestJavaLevelVirtualThreadEvents extends JfrRecordingTest { @Test public void test() throws Throwable { String[] events; - if (JavaVersionUtil.JAVA_SPEC <= 21) { - events = new String[]{"jdk.ThreadSleep", "jdk.VirtualThreadStart", "jdk.VirtualThreadEnd", "jdk.VirtualThreadPinned", "com.jfr.String"}; - } else { - events = new String[]{"jdk.ThreadSleep", "jdk.VirtualThreadStart", "jdk.VirtualThreadEnd", "com.jfr.String"}; - } + events = new String[]{"jdk.ThreadSleep", "jdk.VirtualThreadStart", "jdk.VirtualThreadEnd", "com.jfr.String"}; Recording recording = startRecording(events); Runnable r = () -> { try { diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestSocketChannelEvents.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestSocketChannelEvents.java index eea7f8171347..379d62c0ee8f 100644 --- a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestSocketChannelEvents.java +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestSocketChannelEvents.java @@ -27,7 +27,6 @@ package com.oracle.svm.test.jfr; import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeTrue; import java.io.IOException; import java.net.InetSocketAddress; @@ -36,10 +35,8 @@ import java.nio.channels.SocketChannel; import java.util.List; -import org.junit.BeforeClass; import org.junit.Test; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; import jdk.jfr.Recording; import jdk.jfr.consumer.RecordedEvent; @@ -49,11 +46,6 @@ public class TestSocketChannelEvents extends JfrRecordingTest { public static int PORT = 9876; public static String HOST = "127.0.0.1"; - @BeforeClass - public static void checkJavaVersion() { - assumeTrue("skipping JFR socket channel test", JavaVersionUtil.JAVA_SPEC >= 22); - } - @Test public void test() throws Throwable { String[] events = new String[]{"jdk.SocketRead", "jdk.SocketWrite"}; diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestSocketEvents.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestSocketEvents.java index d8ffbf60a9ef..06b0bc230267 100644 --- a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestSocketEvents.java +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestSocketEvents.java @@ -27,7 +27,6 @@ package com.oracle.svm.test.jfr; import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeTrue; import java.io.BufferedReader; import java.io.IOException; @@ -37,10 +36,8 @@ import java.net.Socket; import java.util.List; -import org.junit.BeforeClass; import org.junit.Test; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; import jdk.jfr.Recording; import jdk.jfr.consumer.RecordedEvent; @@ -49,11 +46,6 @@ public class TestSocketEvents extends JfrRecordingTest { public static int PORT = 9876; public static String HOST = "127.0.0.1"; - @BeforeClass - public static void checkJavaVersion() { - assumeTrue("skipping JFR socket test", JavaVersionUtil.JAVA_SPEC >= 22); - } - @Test public void test() throws Throwable { String[] events = new String[]{"jdk.SocketRead", "jdk.SocketWrite"}; diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestVirtualThreadsBasic.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestVirtualThreadsBasic.java index 5adc8fe23a73..d58c88a97103 100644 --- a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestVirtualThreadsBasic.java +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestVirtualThreadsBasic.java @@ -29,7 +29,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeTrue; import java.util.Collections; import java.util.HashSet; @@ -37,12 +36,10 @@ import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; -import org.junit.Before; import org.junit.Test; import com.oracle.svm.core.jfr.JfrEvent; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; import jdk.jfr.Recording; import jdk.jfr.consumer.RecordedClass; import jdk.jfr.consumer.RecordedEvent; @@ -60,11 +57,6 @@ public class TestVirtualThreadsBasic extends JfrRecordingTest { private final AtomicInteger emittedEventsPerType = new AtomicInteger(0); private final Set expectedThreads = Collections.synchronizedSet(new HashSet<>()); - @Before - public void checkJavaVersion() { - assumeTrue("skipping JFR virtual thread tests", JavaVersionUtil.JAVA_SPEC >= 19); - } - @Test public void test() throws Throwable { String[] events = new String[]{JfrEvent.JavaMonitorWait.getName()}; diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestVirtualThreadsChunkRotation.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestVirtualThreadsChunkRotation.java index 095843aeaa55..ae327a50d943 100644 --- a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestVirtualThreadsChunkRotation.java +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestVirtualThreadsChunkRotation.java @@ -29,7 +29,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeTrue; import java.util.Collections; import java.util.HashSet; @@ -37,12 +36,10 @@ import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; -import org.junit.Before; import org.junit.Test; import com.oracle.svm.core.jfr.JfrEvent; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; import jdk.jfr.Recording; import jdk.jfr.consumer.RecordedClass; import jdk.jfr.consumer.RecordedEvent; @@ -63,11 +60,6 @@ public class TestVirtualThreadsChunkRotation extends JfrRecordingTest { private volatile boolean proceed; - @Before - public void checkJavaVersion() { - assumeTrue("skipping JFR virtual thread tests", JavaVersionUtil.JAVA_SPEC >= 19); - } - @Test public void test() throws Throwable { String[] events = new String[]{JfrEvent.JavaMonitorWait.getName()}; diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestVirtualThreadsJfrStreaming.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestVirtualThreadsJfrStreaming.java index 61cc21c6432d..33b5abb4a33f 100644 --- a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestVirtualThreadsJfrStreaming.java +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestVirtualThreadsJfrStreaming.java @@ -27,19 +27,16 @@ package com.oracle.svm.test.jfr; import static org.junit.Assert.assertNotNull; -import static org.junit.Assume.assumeTrue; import java.util.Collections; import java.util.HashSet; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; -import org.junit.Before; import org.junit.Test; import com.oracle.svm.core.jfr.JfrEvent; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; import jdk.jfr.consumer.RecordedClass; import jdk.jfr.consumer.RecordedThread; import jdk.jfr.consumer.RecordingStream; @@ -57,11 +54,6 @@ public class TestVirtualThreadsJfrStreaming extends JfrStreamingTest { private final AtomicInteger emittedEventsPerType = new AtomicInteger(0); private final Set expectedThreads = Collections.synchronizedSet(new HashSet<>()); - @Before - public void checkJavaVersion() { - assumeTrue("skipping JFR virtual thread tests", JavaVersionUtil.JAVA_SPEC >= 19); - } - @Test public void test() throws Throwable { String[] events = new String[]{JfrEvent.JavaMonitorWait.getName()}; diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/utils/poolparsers/ThreadConstantPoolParser.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/utils/poolparsers/ThreadConstantPoolParser.java index e3082a791085..279ea54059ff 100644 --- a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/utils/poolparsers/ThreadConstantPoolParser.java +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/utils/poolparsers/ThreadConstantPoolParser.java @@ -28,7 +28,6 @@ import java.io.IOException; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; import org.junit.Assert; import com.oracle.svm.core.jfr.JfrType; @@ -50,9 +49,7 @@ public void parse(RecordingInput input) throws IOException { input.readUTF(); // JavaThreadName. Assert.assertTrue("JavaThreadId is not correct!", input.readLong() >= 0); // JavaThreadId. addExpectedId(JfrType.ThreadGroup, input.readLong()); // ThreadGroupId. - if (JavaVersionUtil.JAVA_SPEC >= 19) { - input.readBoolean(); - } + input.readBoolean(); } } }