diff --git a/substratevm/mx.substratevm/suite.py b/substratevm/mx.substratevm/suite.py index 01390484a55a..a1596b009ce4 100644 --- a/substratevm/mx.substratevm/suite.py +++ b/substratevm/mx.substratevm/suite.py @@ -287,6 +287,7 @@ "jdk.jfr": [ "jdk.jfr.events", "jdk.jfr.internal", + "jdk.jfr.internal.event", "jdk.jfr.internal.jfc", ], "jdk.internal.vm.ci": [ @@ -623,6 +624,7 @@ ], "jdk.jfr": [ "jdk.jfr.internal", + "jdk.jfr.internal.event", "jdk.jfr.internal.jfc", ], }, diff --git a/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsNativeLibrarySupport.java b/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsNativeLibrarySupport.java index 0e751c203d73..ab78c022ee71 100644 --- a/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsNativeLibrarySupport.java +++ b/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsNativeLibrarySupport.java @@ -26,7 +26,6 @@ import java.io.FileDescriptor; -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.c.type.CCharPointer; @@ -56,9 +55,7 @@ class WindowsNativeLibraryFeature implements InternalFeature { @Override public void duringSetup(DuringSetupAccess access) { - if (JavaVersionUtil.JAVA_SPEC >= 19) { - NativeLibrarySupport.singleton().preregisterUninitializedBuiltinLibrary("extnet"); - } + NativeLibrarySupport.singleton().preregisterUninitializedBuiltinLibrary("extnet"); } } @@ -100,10 +97,8 @@ private static void loadNetLibrary() { } else { NativeLibrarySupport.singleton().registerInitializedBuiltinLibrary("net"); } - if (JavaVersionUtil.JAVA_SPEC >= 19) { - NativeLibrarySupport.singleton().registerInitializedBuiltinLibrary("extnet"); - System.loadLibrary("extnet"); - } + NativeLibrarySupport.singleton().registerInitializedBuiltinLibrary("extnet"); + System.loadLibrary("extnet"); } @Override diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/JavaMainWrapper.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/JavaMainWrapper.java index 9eed46291285..c685dfa5a41f 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/JavaMainWrapper.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/JavaMainWrapper.java @@ -35,7 +35,6 @@ import java.util.List; import java.util.function.BooleanSupplier; -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.compiler.word.Word; import org.graalvm.nativeimage.CurrentIsolate; import org.graalvm.nativeimage.ImageSingletons; @@ -188,9 +187,6 @@ public static void invokeMain(String[] args) throws Throwable { * 445: Unnamed Classes and Instance Main Methods (Preview). */ public static boolean instanceMainMethodSupported() { - if (JavaVersionUtil.JAVA_SPEC < 21) { - return false; - } var previewFeature = ReflectionUtil.lookupClass(true, "jdk.internal.misc.PreviewFeatures"); try { return previewFeature != null && (Boolean) previewFeature.getDeclaredMethod("isEnabled").invoke(null); 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 238a351ac3b1..ab9493571f17 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 @@ -100,8 +100,6 @@ import com.oracle.svm.core.config.ObjectLayout; import com.oracle.svm.core.heap.UnknownObjectField; import com.oracle.svm.core.heap.UnknownPrimitiveField; -import com.oracle.svm.core.jdk.JDK19OrLater; -import com.oracle.svm.core.jdk.JDK21OrLater; import com.oracle.svm.core.jdk.JDK22OrLater; import com.oracle.svm.core.jdk.Resources; import com.oracle.svm.core.meta.SharedType; @@ -862,7 +860,7 @@ void setClassLoaderAtRuntime(ClassLoader loader) { private native boolean isAnonymousClass(); @KeepOriginal - @TargetElement(onlyWith = JDK21OrLater.class) + @TargetElement private native boolean isUnnamedClass(); @Substitute @@ -1305,7 +1303,6 @@ private static Class forName(String className) throws Throwable { } @Substitute - @TargetElement(onlyWith = JDK19OrLater.class) @Platforms(InternalPlatform.NATIVE_ONLY.class) private static Class forName(String className, Class caller) throws Throwable { return forName(className, true, caller.getClassLoader(), caller); @@ -1318,7 +1315,6 @@ private static Class forName(Module module, String className) throws Throwabl } @Substitute - @TargetElement(onlyWith = JDK19OrLater.class) @Platforms(InternalPlatform.NATIVE_ONLY.class) private static Class forName(@SuppressWarnings("unused") Module module, String className, Class caller) throws Throwable { /* @@ -1338,7 +1334,6 @@ private static Class forName(String name, boolean initialize, ClassLoader loa } @Substitute - @TargetElement(onlyWith = JDK19OrLater.class) private static Class forName(String name, boolean initialize, ClassLoader loader, @SuppressWarnings("unused") Class caller) throws Throwable { if (name == null) { throw new NullPointerException(); diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/DirectByteBufferUtil.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/DirectByteBufferUtil.java index a77de55a54ac..eed754e88d50 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/DirectByteBufferUtil.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/DirectByteBufferUtil.java @@ -26,19 +26,10 @@ import java.nio.ByteBuffer; -import org.graalvm.compiler.core.common.NumUtil; -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; - import com.oracle.svm.core.SubstrateUtil; public class DirectByteBufferUtil { public static ByteBuffer allocate(long addr, long cap) { - Target_java_nio_DirectByteBuffer result; - if (JavaVersionUtil.JAVA_SPEC <= 20) { - result = new Target_java_nio_DirectByteBuffer(addr, NumUtil.safeToInt(cap)); - } else { - result = new Target_java_nio_DirectByteBuffer(addr, cap); - } - return SubstrateUtil.cast(result, ByteBuffer.class); + return SubstrateUtil.cast(new Target_java_nio_DirectByteBuffer(addr, cap), ByteBuffer.class); } } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/FileSystemProviderSupport.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/FileSystemProviderSupport.java index cd3cbdd37eca..f1d835e11a61 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/FileSystemProviderSupport.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/FileSystemProviderSupport.java @@ -37,7 +37,6 @@ import org.graalvm.nativeimage.hosted.FieldValueTransformer; import com.oracle.svm.core.annotate.Alias; -import com.oracle.svm.core.annotate.Delete; import com.oracle.svm.core.annotate.Inject; import com.oracle.svm.core.annotate.InjectAccessors; import com.oracle.svm.core.annotate.RecomputeFieldValue; @@ -403,43 +402,11 @@ final class Target_java_io_UnixFileSystem { @Alias // @InjectAccessors(UserDirAccessors.class) // private String userDir; - - @Alias // - @RecomputeFieldValue(kind = Kind.NewInstance, declClassName = "java.io.ExpiringCache") // - @TargetElement(onlyWith = JDK20OrEarlier.class)// - private Target_java_io_ExpiringCache cache; - - /* - * The prefix cache on Linux/MacOS only caches elements in the Java home directory, which does - * not exist at image runtime. So we disable that cache completely, which is done by - * substituting the value of FileSystem.useCanonPrefixCache to false in the substitution below. - */ - @Delete // - @TargetElement(onlyWith = JDK20OrEarlier.class)// - private String javaHome; - /* - * Ideally, we would mark this field as @Delete too. However, the javaHomePrefixCache is cleared - * from various methods, and we do not want to change those methods. - */ - @Alias // - @RecomputeFieldValue(kind = Kind.NewInstance, declClassName = "java.io.ExpiringCache") // - @TargetElement(onlyWith = JDK20OrEarlier.class)// - private Target_java_io_ExpiringCache javaHomePrefixCache; } @TargetClass(className = "java.io.FileSystem") final class Target_java_io_FileSystem { - /* - * Linux/MacOS only: disable the usage of the javaHomePrefixCache. On Windows, the prefix cache - * is not specific to the Java home directory and therefore can remain enabled. - */ - @Platforms({Platform.LINUX.class, Platform.DARWIN.class}) // - @Alias // - @RecomputeFieldValue(kind = Kind.FromAlias, isFinal = true) // - @TargetElement(onlyWith = JDK20OrEarlier.class)// - static boolean useCanonPrefixCache = false; - @Alias native String normalize(String path); } @@ -464,18 +431,4 @@ final class Target_java_io_WinNTFileSystem { @Alias // @InjectAccessors(UserDirAccessors.class) // private String userDir; - - @Alias // - @RecomputeFieldValue(kind = Kind.NewInstance, declClassName = "java.io.ExpiringCache") // - @TargetElement(onlyWith = JDK20OrEarlier.class)// - private Target_java_io_ExpiringCache cache; - - @Alias // - @RecomputeFieldValue(kind = Kind.NewInstance, declClassName = "java.io.ExpiringCache") // - @TargetElement(onlyWith = JDK20OrEarlier.class)// - private Target_java_io_ExpiringCache prefixCache; -} - -@TargetClass(className = "java.io.ExpiringCache", onlyWith = JDK20OrEarlier.class) -final class Target_java_io_ExpiringCache { } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK19OrEarlier.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK19OrEarlier.java deleted file mode 100644 index 5b794925d4b1..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK19OrEarlier.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2022, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.svm.core.jdk; - -import java.util.function.BooleanSupplier; - -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; - -public class JDK19OrEarlier implements BooleanSupplier { - @Override - public boolean getAsBoolean() { - return JavaVersionUtil.JAVA_SPEC <= 19; - } -} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK19OrLater.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK19OrLater.java deleted file mode 100644 index fb32c832d2d4..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK19OrLater.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2020, 2020, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.svm.core.jdk; - -import java.util.function.BooleanSupplier; - -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; - -public class JDK19OrLater implements BooleanSupplier { - @Override - public boolean getAsBoolean() { - return JavaVersionUtil.JAVA_SPEC >= 19; - } -} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK20OrEarlier.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK20OrEarlier.java deleted file mode 100644 index 03887f9244ac..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK20OrEarlier.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2023, 2023, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.svm.core.jdk; - -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; - -import java.util.function.BooleanSupplier; - -public class JDK20OrEarlier implements BooleanSupplier { - @Override - public boolean getAsBoolean() { - return JavaVersionUtil.JAVA_SPEC <= 20; - } -} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK20OrLater.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK20OrLater.java deleted file mode 100644 index 8396c4ae3dea..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK20OrLater.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2022, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.svm.core.jdk; - -import java.util.function.BooleanSupplier; - -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; - -public class JDK20OrLater implements BooleanSupplier { - @Override - public boolean getAsBoolean() { - return JavaVersionUtil.JAVA_SPEC >= 20; - } -} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK21OrLater.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK21OrLater.java deleted file mode 100644 index fe20c3530a59..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK21OrLater.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2023, 2023, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.svm.core.jdk; - -import java.util.function.BooleanSupplier; - -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; - -public class JDK21OrLater implements BooleanSupplier { - @Override - public boolean getAsBoolean() { - return JavaVersionUtil.JAVA_SPEC >= 21; - } -} 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 2d7522f34733..e7771fee6b0e 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 @@ -25,8 +25,6 @@ package com.oracle.svm.core.jdk; -import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; @@ -37,7 +35,6 @@ 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.annotate.TargetElement; @TargetClass(className = "jdk.jfr.internal.instrument.JDKEvents") @Platforms(LINUX.class) @@ -51,20 +48,7 @@ final class Target_jdk_jfr_internal_instrument_JDKEvents { private static boolean initializationTriggered; } -@TargetClass(className = "jdk.jfr.internal.RequestEngine", onlyWith = JDK20OrEarlier.class) -@Platforms(LINUX.class) -final class Target_jdk_jfr_internal_RequestEngine { - @Alias // - @TargetElement(onlyWith = JDK20OrLater.class) // - @RecomputeFieldValue(kind = Kind.NewInstance, declClass = ReentrantLock.class) // - private static ReentrantLock lock; - - @Alias // - @RecomputeFieldValue(kind = Kind.NewInstance, declClass = CopyOnWriteArrayList.class) // - private static List entries; -} - -@TargetClass(className = "jdk.jfr.internal.periodic.JVMEventTask", onlyWith = JDK21OrLater.class) +@TargetClass(className = "jdk.jfr.internal.periodic.JVMEventTask") @Platforms(LINUX.class) final class Target_jdk_jfr_internal_periodic_JVMEventTask { @Alias // @@ -73,15 +57,6 @@ final class Target_jdk_jfr_internal_periodic_JVMEventTask { } -// Only present in JDKs without JDK-8268398 -@TargetClass(className = "jdk.jfr.internal.Utils", onlyWith = JDK17OrEarlier.class) -@Platforms(LINUX.class) -final class Target_jdk_jfr_internal_Utils_JDK17 { - @Alias // - @RecomputeFieldValue(kind = Kind.Reset) // - private static Target_jdk_internal_platform_Metrics[] metrics; -} - @TargetClass(className = "jdk.internal.platform.Metrics") @Platforms(LINUX.class) final class Target_jdk_internal_platform_Metrics { diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JavaLangSubstitutions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JavaLangSubstitutions.java index b37a0608cd3a..a61fe0fe92a2 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JavaLangSubstitutions.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JavaLangSubstitutions.java @@ -51,12 +51,8 @@ import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; -import org.graalvm.nativeimage.c.function.CFunction; -import org.graalvm.nativeimage.c.function.CLibrary; import org.graalvm.nativeimage.hosted.FieldValueTransformer; import org.graalvm.nativeimage.impl.InternalPlatform; -import org.graalvm.word.WordBase; -import org.graalvm.word.WordFactory; import com.oracle.svm.core.Containers; import com.oracle.svm.core.NeverInline; @@ -108,7 +104,6 @@ private void waitSubst(long timeoutMillis) throws InterruptedException { } @Delete - @TargetElement(onlyWith = JDK19OrLater.class) private native void wait0(long timeoutMillis); @Substitute @@ -388,23 +383,9 @@ final class Target_java_lang_StackTraceElement { * @param depth ignored */ @Substitute - @TargetElement(onlyWith = JDK19OrLater.class) static StackTraceElement[] of(Object x, int depth) { return StackTraceBuilder.build((long[]) x); } - - /** - * Constructs the {@link StackTraceElement} array from a {@link Throwable}. - * - * @param t the {@link Throwable} object - * @param depth ignored - */ - @Substitute - @TargetElement(onlyWith = JDK17OrEarlier.class) - static StackTraceElement[] of(Target_java_lang_Throwable t, int depth) { - Object x = t.backtrace; - return StackTraceBuilder.build((long[]) x); - } } @TargetClass(java.lang.Runtime.class) @@ -583,159 +564,6 @@ public static double pow(double a, double b) { } } -@TargetClass(value = StrictMath.class, onlyWith = JDK20OrEarlier.class) -@Platforms(InternalPlatform.NATIVE_ONLY.class) -final class Target_java_lang_StrictMath { - - @Substitute - private static double sin(double a) { - return StrictMathInvoker.sin(WordFactory.nullPointer(), WordFactory.nullPointer(), a); - } - - @Substitute - private static double cos(double a) { - return StrictMathInvoker.cos(WordFactory.nullPointer(), WordFactory.nullPointer(), a); - } - - @Substitute - private static double tan(double a) { - return StrictMathInvoker.tan(WordFactory.nullPointer(), WordFactory.nullPointer(), a); - } - - @Substitute - private static double asin(double a) { - return StrictMathInvoker.asin(WordFactory.nullPointer(), WordFactory.nullPointer(), a); - } - - @Substitute - private static double acos(double a) { - return StrictMathInvoker.acos(WordFactory.nullPointer(), WordFactory.nullPointer(), a); - } - - @Substitute - private static double atan(double a) { - return StrictMathInvoker.atan(WordFactory.nullPointer(), WordFactory.nullPointer(), a); - } - - @Substitute - private static double log(double a) { - return StrictMathInvoker.log(WordFactory.nullPointer(), WordFactory.nullPointer(), a); - } - - @Substitute - private static double log10(double a) { - return StrictMathInvoker.log10(WordFactory.nullPointer(), WordFactory.nullPointer(), a); - } - - @Substitute - private static double sqrt(double a) { - return StrictMathInvoker.sqrt(WordFactory.nullPointer(), WordFactory.nullPointer(), a); - } - - // Checkstyle: stop - @Substitute - private static double IEEEremainder(double f1, double f2) { - return StrictMathInvoker.IEEEremainder(WordFactory.nullPointer(), WordFactory.nullPointer(), f1, f2); - } - // Checkstyle: resume - - @Substitute - private static double atan2(double y, double x) { - return StrictMathInvoker.atan2(WordFactory.nullPointer(), WordFactory.nullPointer(), y, x); - } - - @Substitute - private static double sinh(double x) { - return StrictMathInvoker.sinh(WordFactory.nullPointer(), WordFactory.nullPointer(), x); - } - - @Substitute - private static double cosh(double x) { - return StrictMathInvoker.cosh(WordFactory.nullPointer(), WordFactory.nullPointer(), x); - } - - @Substitute - private static double tanh(double x) { - return StrictMathInvoker.tanh(WordFactory.nullPointer(), WordFactory.nullPointer(), x); - } - - @Substitute - private static double expm1(double x) { - return StrictMathInvoker.expm1(WordFactory.nullPointer(), WordFactory.nullPointer(), x); - } - - @Substitute - private static double log1p(double x) { - return StrictMathInvoker.log1p(WordFactory.nullPointer(), WordFactory.nullPointer(), x); - } -} - -@CLibrary(value = "java", requireStatic = true, dependsOn = "fdlibm") -final class StrictMathInvoker { - - @CFunction(value = "Java_java_lang_StrictMath_sin", transition = CFunction.Transition.NO_TRANSITION) - static native double sin(WordBase jnienv, WordBase clazz, double a); - - @CFunction(value = "Java_java_lang_StrictMath_cos", transition = CFunction.Transition.NO_TRANSITION) - static native double cos(WordBase jnienv, WordBase clazz, double a); - - @CFunction(value = "Java_java_lang_StrictMath_tan", transition = CFunction.Transition.NO_TRANSITION) - static native double tan(WordBase jnienv, WordBase clazz, double a); - - @CFunction(value = "Java_java_lang_StrictMath_asin", transition = CFunction.Transition.NO_TRANSITION) - static native double asin(WordBase jnienv, WordBase clazz, double a); - - @CFunction(value = "Java_java_lang_StrictMath_acos", transition = CFunction.Transition.NO_TRANSITION) - static native double acos(WordBase jnienv, WordBase clazz, double a); - - @CFunction(value = "Java_java_lang_StrictMath_atan", transition = CFunction.Transition.NO_TRANSITION) - static native double atan(WordBase jnienv, WordBase clazz, double a); - - @CFunction(value = "Java_java_lang_StrictMath_exp", transition = CFunction.Transition.NO_TRANSITION) - static native double exp(WordBase jnienv, WordBase clazz, double a); - - @CFunction(value = "Java_java_lang_StrictMath_log", transition = CFunction.Transition.NO_TRANSITION) - static native double log(WordBase jnienv, WordBase clazz, double a); - - @CFunction(value = "Java_java_lang_StrictMath_log10", transition = CFunction.Transition.NO_TRANSITION) - static native double log10(WordBase jnienv, WordBase clazz, double a); - - @CFunction(value = "Java_java_lang_StrictMath_sqrt", transition = CFunction.Transition.NO_TRANSITION) - static native double sqrt(WordBase jnienv, WordBase clazz, double a); - - @CFunction(value = "Java_java_lang_StrictMath_cbrt", transition = CFunction.Transition.NO_TRANSITION) - static native double cbrt(WordBase jnienv, WordBase clazz, double a); - - // Checkstyle: stop - @CFunction(value = "Java_java_lang_StrictMath_IEEEremainder", transition = CFunction.Transition.NO_TRANSITION) - static native double IEEEremainder(WordBase jnienv, WordBase clazz, double f1, double f2); - // Checkstyle: resume - - @CFunction(value = "Java_java_lang_StrictMath_atan2", transition = CFunction.Transition.NO_TRANSITION) - static native double atan2(WordBase jnienv, WordBase clazz, double y, double x); - - @CFunction(value = "Java_java_lang_StrictMath_pow", transition = CFunction.Transition.NO_TRANSITION) - static native double pow(WordBase jnienv, WordBase clazz, double a, double b); - - @CFunction(value = "Java_java_lang_StrictMath_sinh", transition = CFunction.Transition.NO_TRANSITION) - static native double sinh(WordBase jnienv, WordBase clazz, double x); - - @CFunction(value = "Java_java_lang_StrictMath_cosh", transition = CFunction.Transition.NO_TRANSITION) - static native double cosh(WordBase jnienv, WordBase clazz, double x); - - @CFunction(value = "Java_java_lang_StrictMath_tanh", transition = CFunction.Transition.NO_TRANSITION) - static native double tanh(WordBase jnienv, WordBase clazz, double x); - - @CFunction(value = "Java_java_lang_StrictMath_hypot", transition = CFunction.Transition.NO_TRANSITION) - static native double hypot(WordBase jnienv, WordBase clazz, double x, double y); - - @CFunction(value = "Java_java_lang_StrictMath_expm1", transition = CFunction.Transition.NO_TRANSITION) - static native double expm1(WordBase jnienv, WordBase clazz, double x); - - @CFunction(value = "Java_java_lang_StrictMath_log1p", transition = CFunction.Transition.NO_TRANSITION) - static native double log1p(WordBase jnienv, WordBase clazz, double x); -} - /** * We do not have dynamic class loading (and therefore no class unloading), so it is not necessary * to keep the complicated code that the JDK uses. However, our simple substitutions have a drawback @@ -789,35 +617,6 @@ private void remove(Class type) { } } -@SuppressWarnings({"deprecation", "unused"}) -@TargetClass(className = "java.lang.Compiler", onlyWith = JDK20OrEarlier.class) -final class Target_java_lang_Compiler { - @Substitute - static Object command(Object arg) { - return null; - } - - @SuppressWarnings({"unused"}) - @Substitute - static boolean compileClass(Class clazz) { - return false; - } - - @SuppressWarnings({"unused"}) - @Substitute - static boolean compileClasses(String string) { - return false; - } - - @Substitute - static void enable() { - } - - @Substitute - static void disable() { - } -} - @TargetClass(java.lang.NullPointerException.class) final class Target_java_lang_NullPointerException { diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JavaNetHttpFeature.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JavaNetHttpFeature.java index 214529d5e477..9cbd634ff899 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JavaNetHttpFeature.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JavaNetHttpFeature.java @@ -26,7 +26,6 @@ import java.util.Optional; -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.hosted.RuntimeReflection; import org.graalvm.nativeimage.impl.ConfigurationCondition; @@ -81,7 +80,7 @@ private static Optional requiredModule() { @Override public boolean isInConfiguration(IsInConfigurationAccess access) { - return JavaVersionUtil.JAVA_SPEC >= 19 && requiredModule().isPresent(); + return requiredModule().isPresent(); } @Override diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/RecomputedFields.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/RecomputedFields.java index f587cd7aad17..c7725ec4aa1b 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/RecomputedFields.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/RecomputedFields.java @@ -49,12 +49,10 @@ import com.oracle.svm.core.StaticFieldsSupport; import com.oracle.svm.core.SubstrateUtil; import com.oracle.svm.core.annotate.Alias; -import com.oracle.svm.core.annotate.Delete; import com.oracle.svm.core.annotate.InjectAccessors; import com.oracle.svm.core.annotate.RecomputeFieldValue; import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.annotate.TargetElement; import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature; import com.oracle.svm.core.feature.InternalFeature; import com.oracle.svm.core.util.VMError; @@ -327,19 +325,13 @@ public static int getCommonPoolParallelism() { return ForkJoinPoolCommonAccessor.get().getParallelism(); } - /* Delete the original static field for common parallelism. */ - @Delete // - @TargetElement(onlyWith = JDK17OrEarlier.class)// - static int COMMON_PARALLELISM; - - @Alias @TargetElement(onlyWith = JDK19OrLater.class) // + @Alias // private static Unsafe U; - @Alias @TargetElement(onlyWith = JDK19OrLater.class) // + @Alias // private static long POOLIDS; @Substitute - @TargetElement(onlyWith = JDK19OrLater.class) // private static int getAndAddPoolIds(int x) { // Original method wrongly uses ForkJoinPool.class instead of calling U.staticFieldBase() return U.getAndAddInt(StaticFieldsSupport.getStaticPrimitiveFields(), POOLIDS, x); diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/SecuritySubstitutions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/SecuritySubstitutions.java index 3c5f4b493879..ac43ce640b93 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/SecuritySubstitutions.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/SecuritySubstitutions.java @@ -45,7 +45,6 @@ import java.util.Map; import java.util.function.Predicate; -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.hosted.FieldValueTransformer; @@ -299,7 +298,7 @@ final class Target_javax_crypto_JceSecurity { private static Map verifyingProviders; @Alias // - @TargetElement(onlyWith = JDK21OrLater.class) // + @TargetElement // private static ReferenceQueue queue; @Substitute @@ -318,9 +317,7 @@ static URL getCodeBase(final Class clazz) { static Exception getVerificationResult(Provider p) { /* Start code block copied from original method. */ /* The verification results map key is an identity wrapper object. */ - Object key = JavaVersionUtil.JAVA_SPEC <= 20 ? // JDK-8168469 - new Target_javax_crypto_JceSecurity_IdentityWrapper(p) : // - new Target_javax_crypto_JceSecurity_WeakIdentityWrapper(p, queue); + Object key = new Target_javax_crypto_JceSecurity_WeakIdentityWrapper(p, queue); Object o = verificationResults.get(key); if (o == PROVIDER_VERIFIED) { return null; @@ -346,15 +343,7 @@ public Object transform(Object receiver, Object originalValue) { } } -@TargetClass(className = "javax.crypto.JceSecurity", innerClass = "IdentityWrapper", onlyWith = JDK20OrEarlier.class) -@SuppressWarnings({"unused"}) -final class Target_javax_crypto_JceSecurity_IdentityWrapper { - @Alias // - Target_javax_crypto_JceSecurity_IdentityWrapper(Provider obj) { - } -} - -@TargetClass(className = "javax.crypto.JceSecurity", innerClass = "WeakIdentityWrapper", onlyWith = JDK21OrLater.class) +@TargetClass(className = "javax.crypto.JceSecurity", innerClass = "WeakIdentityWrapper") @SuppressWarnings({"unused"}) final class Target_javax_crypto_JceSecurity_WeakIdentityWrapper { diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_Shutdown.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_Shutdown.java index 743f12c0207c..e02f8eea04bb 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_Shutdown.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_Shutdown.java @@ -61,7 +61,7 @@ static void beforeHalt() { static native void shutdown(); @Substitute - @TargetElement(onlyWith = JDK21OrLater.class) + @TargetElement @SuppressWarnings("unused") private static void logRuntimeExit(int status) { // Disable exit logging (GR-45418/JDK-8301627) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_nio_DirectByteBuffer.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_nio_DirectByteBuffer.java index 6d2405fb6b9b..e414b25706de 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_nio_DirectByteBuffer.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_nio_DirectByteBuffer.java @@ -24,10 +24,11 @@ */ package com.oracle.svm.core.jdk; +import java.io.FileDescriptor; + import com.oracle.svm.core.annotate.Alias; import com.oracle.svm.core.annotate.RecomputeFieldValue; import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.annotate.TargetElement; import com.oracle.svm.core.heap.Target_jdk_internal_ref_Cleaner; import com.oracle.svm.core.util.VMError; @@ -51,15 +52,13 @@ public final class Target_java_nio_DirectByteBuffer { @Alias @SuppressWarnings("unused") - @TargetElement(onlyWith = JDK20OrEarlier.class) - public Target_java_nio_DirectByteBuffer(long addr, int cap) { + Target_java_nio_DirectByteBuffer(long addr, long cap) { throw VMError.shouldNotReachHere("This is an alias to the original constructor in the target class, so this code is unreachable"); } @Alias - @SuppressWarnings("unused") - @TargetElement(onlyWith = JDK21OrLater.class) - public Target_java_nio_DirectByteBuffer(long addr, long cap) { + Target_java_nio_DirectByteBuffer(int cap, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync, + Target_java_lang_foreign_MemorySegment segment) { throw VMError.shouldNotReachHere("This is an alias to the original constructor in the target class, so this code is unreachable"); } } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_loader_NativeLibraries.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_loader_NativeLibraries.java index 3ba9c9db4f69..6eb6a3e04ce5 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_loader_NativeLibraries.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_loader_NativeLibraries.java @@ -24,14 +24,12 @@ */ package com.oracle.svm.core.jdk; -import java.util.Deque; import java.util.Map; import java.util.Set; import com.oracle.svm.core.annotate.Delete; import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.annotate.TargetElement; import jdk.internal.loader.NativeLibraries; @@ -44,14 +42,6 @@ final class Target_jdk_internal_loader_NativeLibraries { */ @SuppressWarnings("unused") @Substitute// - @TargetElement(onlyWith = JDK17OrEarlier.class) - public static NativeLibraries jniNativeLibraries(ClassLoader loader) { - return null; - } - - @SuppressWarnings("unused") - @Substitute// - @TargetElement(onlyWith = JDK19OrLater.class) public static NativeLibraries newInstance(ClassLoader loader) { return null; } @@ -63,9 +53,6 @@ public static NativeLibraries newInstance(ClassLoader loader) { private Map libraries; @Delete // private static Set loadedLibraryNames; - @Delete // - @TargetElement(onlyWith = JDK17OrEarlier.class)// - private static Deque nativeLibraryContext; /* * We are defensive and also handle private native methods by marking them as deleted. If they @@ -74,23 +61,13 @@ public static NativeLibraries newInstance(ClassLoader loader) { */ @Delete// - @TargetElement(onlyWith = JDK20OrLater.class) private static native boolean load(Target_jdk_internal_loader_NativeLibraries_NativeLibraryImpl impl, String name, boolean isBuiltin, boolean throwExceptionIfFail); @Delete// - @TargetElement(onlyWith = JDK17OrEarlier.class) - private static native void unload(String name, boolean isBuiltin, boolean isJNI, long handle); - - @Delete// - @TargetElement(onlyWith = JDK19OrLater.class) private static native void unload(String name, boolean isBuiltin, long handle); @Delete private static native String findBuiltinLib(String name); - - @Delete// - @TargetElement(onlyWith = JDK17OrEarlier.class) - private static native long findEntry0(Target_jdk_internal_loader_NativeLibraries_NativeLibraryImpl lib, String name); } @TargetClass(value = jdk.internal.loader.NativeLibraries.class, innerClass = "NativeLibraryImpl") diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_loader_NativeLibrary.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_loader_NativeLibrary.java index d42d47e544c1..a06abcba4a72 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_loader_NativeLibrary.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_loader_NativeLibrary.java @@ -27,7 +27,7 @@ import com.oracle.svm.core.annotate.Delete; import com.oracle.svm.core.annotate.TargetClass; -@TargetClass(value = jdk.internal.loader.NativeLibrary.class, onlyWith = JDK19OrLater.class) +@TargetClass(value = jdk.internal.loader.NativeLibrary.class) final class Target_jdk_internal_loader_NativeLibrary { @Delete private static native long findEntry0(long handle, String name); 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 0044154c2910..921c9de63b2a 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 @@ -24,13 +24,11 @@ */ package com.oracle.svm.core.jdk; -import java.nio.charset.Charset; import java.util.function.BooleanSupplier; import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; import com.oracle.svm.core.annotate.TargetElement; -import com.oracle.svm.core.jdk.localization.substitutions.Target_java_nio_charset_Charset; import com.oracle.svm.util.ReflectionUtil; import jdk.internal.util.StaticProperty; @@ -125,27 +123,17 @@ public static String nativeEncoding() { } @Substitute - @TargetElement(onlyWith = JDK19OrLater.class) public static String fileEncoding() { return SystemPropertiesSupport.singleton().savedProperties.get("file.encoding"); } @Substitute - @TargetElement(onlyWith = JDK19OrLater.class) public static String javaPropertiesDate() { return SystemPropertiesSupport.singleton().savedProperties.getOrDefault("java.properties.date", null); } @Substitute - @TargetElement(onlyWith = JDK19OrLater.class) public static String jnuEncoding() { return SystemPropertiesSupport.singleton().savedProperties.get("sun.jnu.encoding"); } - - @Substitute - @TargetElement(onlyWith = {JDK19OrLater.class, JDK20OrEarlier.class}) - public static Charset jnuCharset() { - String jnuEncoding = SystemPropertiesSupport.singleton().savedProperties.get("sun.jnu.encoding"); - return Target_java_nio_charset_Charset.forName(jnuEncoding, Charset.defaultCharset()); - } } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_sun_nio_ch_Util_JDK19OrLater.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_sun_nio_ch_Util.java similarity index 61% rename from substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_sun_nio_ch_Util_JDK19OrLater.java rename to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_sun_nio_ch_Util.java index 48b067b164b7..641b11507d09 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_sun_nio_ch_Util_JDK19OrLater.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_sun_nio_ch_Util.java @@ -32,44 +32,30 @@ import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; -@TargetClass(className = "java.lang.foreign.MemorySegment", onlyWith = JDK19OrLater.class) +@TargetClass(className = "java.lang.foreign.MemorySegment") @SuppressWarnings("unused") -final class Target_java_lang_foreign_MemorySegment_JDK19OrLater { +final class Target_java_lang_foreign_MemorySegment { } -@TargetClass(className = "java.nio.DirectByteBuffer", onlyWith = JDK19OrLater.class) +@TargetClass(className = "java.nio.DirectByteBufferR") @SuppressWarnings("unused") -final class Target_java_nio_DirectByteBuffer_JDK19OrLater { +final class Target_java_nio_DirectByteBufferR { @Alias - protected Target_java_nio_DirectByteBuffer_JDK19OrLater(int cap, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync, - Target_java_lang_foreign_MemorySegment_JDK19OrLater segment) { + protected Target_java_nio_DirectByteBufferR(int cap, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync, Target_java_lang_foreign_MemorySegment segment) { } - } -@TargetClass(className = "java.nio.DirectByteBufferR", onlyWith = JDK19OrLater.class) -@SuppressWarnings("unused") -final class Target_java_nio_DirectByteBufferR_JDK19OrLater { - - @Alias - protected Target_java_nio_DirectByteBufferR_JDK19OrLater(int cap, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync, - Target_java_lang_foreign_MemorySegment_JDK19OrLater segment) { - } - -} - -@TargetClass(className = "sun.nio.ch.Util", onlyWith = JDK19OrLater.class) -final class Target_sun_nio_ch_Util_JDK19OrLater { +@TargetClass(className = "sun.nio.ch.Util") +final class Target_sun_nio_ch_Util { @Substitute private static MappedByteBuffer newMappedByteBuffer(int size, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync) { - return SubstrateUtil.cast(new Target_java_nio_DirectByteBuffer_JDK19OrLater(size, addr, fd, unmapper, isSync, null), MappedByteBuffer.class); + return SubstrateUtil.cast(new Target_java_nio_DirectByteBuffer(size, addr, fd, unmapper, isSync, null), MappedByteBuffer.class); } @Substitute static MappedByteBuffer newMappedByteBufferR(int size, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync) { - return SubstrateUtil.cast(new Target_java_nio_DirectByteBufferR_JDK19OrLater(size, addr, fd, unmapper, isSync, null), MappedByteBuffer.class); + return SubstrateUtil.cast(new Target_java_nio_DirectByteBufferR(size, addr, fd, unmapper, isSync, null), MappedByteBuffer.class); } - } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_sun_nio_ch_Util_JDK17.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_sun_nio_ch_Util_JDK17.java deleted file mode 100644 index e40dad0757b5..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_sun_nio_ch_Util_JDK17.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2019, 2019, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.svm.core.jdk; - -import java.io.FileDescriptor; -import java.nio.MappedByteBuffer; - -import com.oracle.svm.core.SubstrateUtil; -import com.oracle.svm.core.annotate.Alias; -import com.oracle.svm.core.annotate.Substitute; -import com.oracle.svm.core.annotate.TargetClass; - -/* - * GR-43733: All substitutions in this file are for JDK 17 only, i.e., are no longer necessary for - * later JDK versions. This file can be removed when removing JDK 17 support. - */ - -@TargetClass(className = "jdk.internal.access.foreign.MemorySegmentProxy", onlyWith = JDK17OrEarlier.class) -@SuppressWarnings("unused") -final class Target_jdk_internal_access_foreign_MemorySegmentProxy_JDK17 { -} - -@TargetClass(className = "java.nio.DirectByteBuffer", onlyWith = JDK17OrEarlier.class) -@SuppressWarnings("unused") -final class Target_java_nio_DirectByteBuffer_JDK17 { - - @Alias - protected Target_java_nio_DirectByteBuffer_JDK17(int cap, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync, - Target_jdk_internal_access_foreign_MemorySegmentProxy_JDK17 segment) { - } - -} - -@TargetClass(className = "java.nio.DirectByteBufferR", onlyWith = JDK17OrEarlier.class) -@SuppressWarnings("unused") -final class Target_java_nio_DirectByteBufferR_JDK17 { - - @Alias - protected Target_java_nio_DirectByteBufferR_JDK17(int cap, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync, - Target_jdk_internal_access_foreign_MemorySegmentProxy_JDK17 segment) { - } - -} - -@TargetClass(className = "sun.nio.ch.Util", onlyWith = JDK17OrEarlier.class) -final class Target_sun_nio_ch_Util_JDK17 { - - @Substitute - private static MappedByteBuffer newMappedByteBuffer(int size, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync) { - return SubstrateUtil.cast(new Target_java_nio_DirectByteBuffer_JDK17(size, addr, fd, unmapper, isSync, null), MappedByteBuffer.class); - } - - @Substitute - static MappedByteBuffer newMappedByteBufferR(int size, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync) { - return SubstrateUtil.cast(new Target_java_nio_DirectByteBufferR_JDK17(size, addr, fd, unmapper, isSync, null), MappedByteBuffer.class); - } - -} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_nio_charset_Charset.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_nio_charset_Charset.java index cc3e1bb21be4..5499b843f7f3 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_nio_charset_Charset.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_nio_charset_Charset.java @@ -36,8 +36,6 @@ import com.oracle.svm.core.annotate.RecomputeFieldValue; import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.annotate.TargetElement; -import com.oracle.svm.core.jdk.JDK19OrLater; import com.oracle.svm.core.jdk.localization.LocalizationSupport; @TargetClass(java.nio.charset.Charset.class) @@ -67,7 +65,6 @@ private static SortedMap availableCharsets() { } @Alias - @TargetElement(onlyWith = JDK19OrLater.class) public static native Charset forName(String charsetName, Charset fallback); @Substitute diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrEventWriterAccess.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrEventWriterAccess.java index b5491f6c926c..68b07e9b12da 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrEventWriterAccess.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrEventWriterAccess.java @@ -34,30 +34,19 @@ import com.oracle.svm.util.ReflectionUtil; import jdk.internal.misc.Unsafe; +import jdk.jfr.internal.event.EventWriter; /** - * Used to access the Java event writer class, see {@code jdk.jfr.internal.EventWriter}. + * Used to access the Java event writer class, see {@link EventWriter}. */ public final class JfrEventWriterAccess { private static final Unsafe U = Unsafe.getUnsafe(); - /* - * The fields "startPosition" and "startPositionAddress" in the JDK class EventWriter refer to - * the committed position and not to the start of the buffer. - */ - private static final Field COMMITTED_POSITION_FIELD = ReflectionUtil.lookupField(getEventWriterClass(), "startPosition"); - private static final Field CURRENT_POSITION_FIELD = ReflectionUtil.lookupField(getEventWriterClass(), "currentPosition"); - private static final Field MAX_POSITION_FIELD = ReflectionUtil.lookupField(getEventWriterClass(), "maxPosition"); - private static final Field VALID_FIELD = ReflectionUtil.lookupField(getEventWriterClass(), "valid"); + private static final Field VALID_FIELD = ReflectionUtil.lookupField(EventWriter.class, "valid"); @Platforms(Platform.HOSTED_ONLY.class) private JfrEventWriterAccess() { } - @Platforms(Platform.HOSTED_ONLY.class) - public static Class getEventWriterClass() { - return ReflectionUtil.lookupClass(false, "jdk.jfr.internal.event.EventWriter"); - } - public static Target_jdk_jfr_internal_event_EventWriter newEventWriter(JfrBuffer buffer, boolean isCurrentThreadExcluded) { assert JfrBufferAccess.isEmpty(buffer) : "a fresh JFR buffer must be empty"; @@ -77,9 +66,13 @@ public static void update(Target_jdk_jfr_internal_event_EventWriter writer, JfrB Pointer currentPos = committedPos.add(uncommittedSize); Pointer maxPos = JfrBufferAccess.getDataEnd(buffer); - U.putLong(writer, U.objectFieldOffset(COMMITTED_POSITION_FIELD), committedPos.rawValue()); - U.putLong(writer, U.objectFieldOffset(CURRENT_POSITION_FIELD), currentPos.rawValue()); - U.putLong(writer, U.objectFieldOffset(MAX_POSITION_FIELD), maxPos.rawValue()); + /* + * The field "startPosition" in the JDK class EventWriter refers to the committed position + * and not to the start of the buffer. + */ + writer.startPosition = committedPos.rawValue(); + writer.currentPosition = currentPos.rawValue(); + writer.maxPosition = maxPos.rawValue(); if (!valid) { markAsInvalid(writer); } @@ -87,7 +80,12 @@ public static void update(Target_jdk_jfr_internal_event_EventWriter writer, JfrB @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) public static void markAsInvalid(Target_jdk_jfr_internal_event_EventWriter writer) { - /* The VM should never write true (only the JDK code may do that). */ + /* + * The VM should never write true (only the JDK code may do that). + * + * The field EventWriter.valid is not declared volatile, so we use Unsafe to do a volatile + * store. + */ U.putBooleanVolatile(writer, U.objectFieldOffset(VALID_FIELD), false); } } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_event_EventWriter.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_event_EventWriter.java index f299695f5eb4..eb2a95b373d7 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_event_EventWriter.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_event_EventWriter.java @@ -35,6 +35,13 @@ public final class Target_jdk_jfr_internal_event_EventWriter { @Alias // long threadID; + @Alias // + long startPosition; + @Alias // + long currentPosition; + @Alias // + long maxPosition; + @Alias @SuppressWarnings("unused") Target_jdk_jfr_internal_event_EventWriter(long committedPos, long maxPos, long threadID, boolean valid, boolean excluded) { diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/JNILibraryInitializer.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/JNILibraryInitializer.java index fbb4915d69b4..f614dc4b3770 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/JNILibraryInitializer.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/JNILibraryInitializer.java @@ -31,7 +31,6 @@ import org.graalvm.collections.EconomicMap; import org.graalvm.collections.Equivalence; -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.c.function.CFunctionPointer; import org.graalvm.nativeimage.c.function.InvokeCFunctionPointer; @@ -87,7 +86,7 @@ public boolean fillCGlobalDataMap(Collection staticLibNames) { // TODO: This check should be removed when all static libs will have JNI_OnLoad function ArrayList localStaticLibNames = new ArrayList<>(staticLibNames); localStaticLibNames.retainAll(libsWithOnLoad); - if (JavaVersionUtil.JAVA_SPEC >= 19 && Platform.includedIn(Platform.WINDOWS.class)) { + if (Platform.includedIn(Platform.WINDOWS.class)) { /* libextnet on Windows (introduced in Java 19) does not contain an OnLoad method. */ localStaticLibNames.remove("extnet"); } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmstat/Target_jdk_internal_perf_Perf.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmstat/Target_jdk_internal_perf_Perf.java index 76f6edf313f8..fdc320804947 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmstat/Target_jdk_internal_perf_Perf.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmstat/Target_jdk_internal_perf_Perf.java @@ -30,22 +30,12 @@ import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.annotate.TargetElement; -import com.oracle.svm.core.jdk.JDK17OrEarlier; -import com.oracle.svm.core.jdk.JDK19OrLater; @TargetClass(className = "jdk.internal.perf.Perf") @SuppressWarnings({"unused", "static-method"}) public final class Target_jdk_internal_perf_Perf { @Substitute - @TargetElement(name = "attach", onlyWith = JDK17OrEarlier.class) - public ByteBuffer attachJDK17(String user, int lvmid, int mode) { - return ImageSingletons.lookup(PerfDataSupport.class).attach(lvmid); - } - - @Substitute - @TargetElement(name = "attach", onlyWith = JDK19OrLater.class) - public ByteBuffer attachJDK19(int lvmid) { + public ByteBuffer attach(int lvmid) { return ImageSingletons.lookup(PerfDataSupport.class).attach(lvmid); } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/methodhandles/Target_java_lang_invoke_MethodHandle.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/methodhandles/Target_java_lang_invoke_MethodHandle.java index 8d582a200ec4..50c16ff19c47 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/methodhandles/Target_java_lang_invoke_MethodHandle.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/methodhandles/Target_java_lang_invoke_MethodHandle.java @@ -42,11 +42,9 @@ import com.oracle.svm.core.annotate.RecomputeFieldValue; import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.annotate.TargetElement; import com.oracle.svm.core.classinitialization.EnsureClassInitializedNode; import com.oracle.svm.core.invoke.MethodHandleUtils; import com.oracle.svm.core.invoke.Target_java_lang_invoke_MemberName; -import com.oracle.svm.core.jdk.JDK21OrLater; import com.oracle.svm.core.reflect.SubstrateMethodAccessor; import com.oracle.svm.core.reflect.target.Target_java_lang_reflect_AccessibleObject; import com.oracle.svm.core.reflect.target.Target_java_lang_reflect_Method; @@ -139,7 +137,6 @@ static Object linkToSpecial(Object... args) throws Throwable { } @Substitute(polymorphicSignature = true) - @TargetElement(onlyWith = JDK21OrLater.class) static Object linkToNative(Object... args) throws Throwable { if (LinkToNativeSupport.isAvailable()) { return LinkToNativeSupport.singleton().linkToNative(args); diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/methodhandles/Target_java_lang_invoke_MethodHandleNatives.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/methodhandles/Target_java_lang_invoke_MethodHandleNatives.java index e50234f4ac46..324eff55c82d 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/methodhandles/Target_java_lang_invoke_MethodHandleNatives.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/methodhandles/Target_java_lang_invoke_MethodHandleNatives.java @@ -49,10 +49,8 @@ import com.oracle.svm.core.annotate.RecomputeFieldValue.Kind; import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.annotate.TargetElement; import com.oracle.svm.core.hub.DynamicHub; import com.oracle.svm.core.invoke.Target_java_lang_invoke_MemberName; -import com.oracle.svm.core.jdk.JDK20OrEarlier; import com.oracle.svm.core.reflect.target.Target_java_lang_reflect_Field; import com.oracle.svm.core.util.VMError; import com.oracle.svm.util.ReflectionUtil; @@ -121,10 +119,6 @@ private static void expand(Target_java_lang_invoke_MemberName self) { throw unsupportedFeature("MethodHandleNatives.expand()"); } - @Delete - @TargetElement(onlyWith = {JDK20OrEarlier.class}) - private static native int getMembers(Class defc, String matchName, String matchSig, int matchFlags, Class caller, int skip, Target_java_lang_invoke_MemberName[] results); - @Substitute private static long objectFieldOffset(Target_java_lang_invoke_MemberName self) { if (self.reflectAccess == null && self.intrinsic == null) { @@ -370,13 +364,6 @@ final class Target_java_lang_invoke_MethodHandleNatives_Constants { @Alias @RecomputeFieldValue(isFinal = true, kind = Kind.None) static int MN_IS_TYPE; @Alias @RecomputeFieldValue(isFinal = true, kind = Kind.None) static int MN_CALLER_SENSITIVE; @Alias @RecomputeFieldValue(isFinal = true, kind = Kind.None) static int MN_REFERENCE_KIND_SHIFT; - @TargetElement(onlyWith = {JDK20OrEarlier.class})// - @Alias @RecomputeFieldValue(isFinal = true, kind = Kind.None) static int MN_REFERENCE_KIND_MASK; - // The SEARCH_* bits are not for MN.flags but for the matchFlags argument of MHN.getMembers: - @TargetElement(onlyWith = {JDK20OrEarlier.class})// - @Alias @RecomputeFieldValue(isFinal = true, kind = Kind.None) static int MN_SEARCH_SUPERCLASSES; - @TargetElement(onlyWith = {JDK20OrEarlier.class})// - @Alias @RecomputeFieldValue(isFinal = true, kind = Kind.None) static int MN_SEARCH_INTERFACES; /** * Constant pool reference-kind codes, as used by CONSTANT_MethodHandle CP entries. 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 66026bf4f61b..8203007de1d7 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 @@ -24,7 +24,6 @@ */ package com.oracle.svm.core.monitor; -import java.lang.ref.ReferenceQueue; import java.util.Collections; import java.util.HashSet; import java.util.Map; @@ -35,7 +34,6 @@ import java.util.concurrent.locks.ReentrantLock; import org.graalvm.compiler.core.common.SuppressFBWarnings; -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.compiler.word.BarrieredAccess; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; @@ -48,8 +46,6 @@ import com.oracle.svm.core.heap.RestrictHeapAccess.Access; import com.oracle.svm.core.hub.DynamicHub; import com.oracle.svm.core.hub.DynamicHubCompanion; -import com.oracle.svm.core.jdk.JDK17OrEarlier; -import com.oracle.svm.core.jdk.JDK19OrLater; import com.oracle.svm.core.jfr.JfrTicks; import com.oracle.svm.core.jfr.events.JavaMonitorInflateEvent; import com.oracle.svm.core.monitor.JavaMonitorQueuedSynchronizer.JavaMonitorConditionObject; @@ -118,13 +114,6 @@ public class MultiThreadedMonitorSupport extends MonitorSupport { * java.lang.ref.ReferenceQueue internally. */ HashSet> monitorTypes = new HashSet<>(); - if (JavaVersionUtil.JAVA_SPEC <= 17) { - /* - * Until JDK 17, the ReferenceQueue uses the inner static class Lock for all its - * locking needs. - */ - monitorTypes.add(Class.forName("java.lang.ref.ReferenceQueue$Lock")); - } /* The WeakIdentityHashMap also synchronizes on its internal ReferenceQueue field. */ monitorTypes.add(java.lang.ref.ReferenceQueue.class); @@ -328,7 +317,7 @@ public boolean isLockedByAnyThread(Object obj) { @Override protected void doWait(Object obj, long timeoutMillis) throws InterruptedException { /* - * JDK 19 and later: our monitor implementation does not pin virtual threads, so avoid + * Our monitor implementation does not pin virtual threads, so avoid * jdk.internal.misc.Blocker which expects and asserts that a virtual thread is pinned * unless the thread is pinned for other reasons. Also, we get interrupted on the virtual * thread instead of the carrier thread, which clears the carrier thread's interrupt status @@ -336,7 +325,7 @@ protected void doWait(Object obj, long timeoutMillis) throws InterruptedExceptio * clear the virtual thread interrupt. */ long compensation = -1; - boolean pinned = JavaVersionUtil.JAVA_SPEC >= 19 && VirtualThreads.isSupported() && + boolean pinned = VirtualThreads.isSupported() && VirtualThreads.singleton().isVirtual(Thread.currentThread()) && VirtualThreads.singleton().isCurrentPinned(); if (pinned) { compensation = Target_jdk_internal_misc_Blocker.begin(); @@ -448,8 +437,6 @@ protected JavaMonitor getOrCreateMonitorFromObject(Object obj, boolean createIfN } protected JavaMonitor getOrCreateMonitorFromMap(Object obj, boolean createIfNotExisting, MonitorInflationCause cause) { - assert JavaVersionUtil.JAVA_SPEC > 17 || - obj.getClass() != Target_java_lang_ref_ReferenceQueue_Lock.class : "ReferenceQueue.Lock must have a monitor field or we can deadlock accessing WeakIdentityHashMap below"; VMError.guarantee(!additionalMonitorsLock.isHeldByCurrentThread(), "Recursive manipulation of the additionalMonitors map can lead to table corruptions and double insertion of a monitor for the same object"); @@ -479,11 +466,7 @@ protected JavaMonitor newMonitorLock() { } } -@TargetClass(value = ReferenceQueue.class, innerClass = "Lock", onlyWith = JDK17OrEarlier.class) -final class Target_java_lang_ref_ReferenceQueue_Lock { -} - -@TargetClass(className = "jdk.internal.misc.Blocker", onlyWith = JDK19OrLater.class) +@TargetClass(className = "jdk.internal.misc.Blocker") final class Target_jdk_internal_misc_Blocker { @Alias public static native long begin(); diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/target/Target_java_lang_reflect_Executable.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/target/Target_java_lang_reflect_Executable.java index b083809d458a..e98df3fcc6f5 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/target/Target_java_lang_reflect_Executable.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/target/Target_java_lang_reflect_Executable.java @@ -38,22 +38,14 @@ import com.oracle.svm.core.annotate.RecomputeFieldValue.Kind; import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.annotate.TargetElement; -import com.oracle.svm.core.jdk.JDK19OrEarlier; -import com.oracle.svm.core.jdk.JDK20OrLater; import com.oracle.svm.core.reflect.ReflectionMetadataDecoder; @TargetClass(value = Executable.class) public final class Target_java_lang_reflect_Executable { - @TargetElement(onlyWith = JDK20OrLater.class)// @Alias @RecomputeFieldValue(kind = Kind.Reset)// Target_java_lang_reflect_Executable_ParameterData parameterData; - @TargetElement(onlyWith = JDK19OrEarlier.class)// - @Alias @RecomputeFieldValue(kind = Kind.Reset)// - Parameter[] parameters; - @Alias @RecomputeFieldValue(kind = Kind.Reset)// Map, Annotation> declaredAnnotations; @@ -81,6 +73,6 @@ public Object transform(Object receiver, Object originalValue) { } } -@TargetClass(value = Executable.class, innerClass = "ParameterData", onlyWith = JDK20OrLater.class) +@TargetClass(value = Executable.class, innerClass = "ParameterData") final class Target_java_lang_reflect_Executable_ParameterData { } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/target/Target_java_lang_reflect_Field.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/target/Target_java_lang_reflect_Field.java index e639a3ad8fdb..05385d4c63ab 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/target/Target_java_lang_reflect_Field.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/target/Target_java_lang_reflect_Field.java @@ -42,8 +42,6 @@ import com.oracle.svm.core.annotate.TargetClass; import com.oracle.svm.core.annotate.TargetElement; import com.oracle.svm.core.fieldvaluetransformer.FieldValueTransformerWithAvailability; -import com.oracle.svm.core.jdk.JDK17OrEarlier; -import com.oracle.svm.core.jdk.JDK19OrLater; import com.oracle.svm.core.util.VMError; import sun.reflect.generics.repository.FieldRepository; @@ -83,16 +81,10 @@ public final class Target_java_lang_reflect_Field { @Alias native Target_java_lang_reflect_Field copy(); - @Alias - @TargetElement(onlyWith = JDK17OrEarlier.class) - native Target_jdk_internal_reflect_FieldAccessor acquireFieldAccessor(boolean overrideFinalCheck); - @Alias// - @TargetElement(onlyWith = JDK19OrLater.class) native Target_jdk_internal_reflect_FieldAccessor acquireFieldAccessor(); @Alias// - @TargetElement(onlyWith = JDK19OrLater.class) native Target_jdk_internal_reflect_FieldAccessor acquireOverrideFieldAccessor(); @Alias @@ -101,23 +93,6 @@ public final class Target_java_lang_reflect_Field { native void constructor(Class declaringClass, String name, Class type, int modifiers, boolean trustedFinal, int slot, String signature, byte[] annotations); @Substitute - @TargetElement(onlyWith = JDK17OrEarlier.class) - Target_jdk_internal_reflect_FieldAccessor getFieldAccessor(@SuppressWarnings("unused") Object obj) { - boolean ov = override; - Target_jdk_internal_reflect_FieldAccessor accessor = (ov) ? overrideFieldAccessor : fieldAccessor; - if (accessor != null) { - return accessor; - } - if (deletedReason != null) { - Field field = SubstrateUtil.cast(this, Field.class); - throw VMError.unsupportedFeature("Unsupported field " + field.getDeclaringClass().getTypeName() + - "." + field.getName() + " is reachable: " + deletedReason); - } - return acquireFieldAccessor(ov); - } - - @Substitute - @TargetElement(onlyWith = JDK19OrLater.class) Target_jdk_internal_reflect_FieldAccessor getFieldAccessor() { Target_jdk_internal_reflect_FieldAccessor accessor = fieldAccessor; if (accessor != null) { @@ -132,7 +107,6 @@ Target_jdk_internal_reflect_FieldAccessor getFieldAccessor() { } @Substitute - @TargetElement(onlyWith = JDK19OrLater.class) Target_jdk_internal_reflect_FieldAccessor getOverrideFieldAccessor() { Target_jdk_internal_reflect_FieldAccessor accessor = overrideFieldAccessor; if (accessor != null) { diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/target/Target_jdk_internal_reflect_AccessorGenerator.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/target/Target_jdk_internal_reflect_AccessorGenerator.java index 282e1ddd8689..9ab61ef033de 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/target/Target_jdk_internal_reflect_AccessorGenerator.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/target/Target_jdk_internal_reflect_AccessorGenerator.java @@ -33,9 +33,6 @@ import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.annotate.TargetElement; -import com.oracle.svm.core.jdk.JDK19OrEarlier; -import com.oracle.svm.core.jdk.JDK20OrLater; import com.oracle.svm.core.reflect.serialize.SerializationRegistry; @TargetClass(className = "jdk.internal.reflect.AccessorGenerator") @@ -46,22 +43,10 @@ public final class Target_jdk_internal_reflect_AccessorGenerator { final class Target_jdk_internal_reflect_SerializationConstructorAccessorGenerator { @Substitute - @TargetElement(onlyWith = JDK20OrLater.class) public Target_jdk_internal_reflect_SerializationConstructorAccessorImpl generateSerializationConstructor(Class declaringClass, @SuppressWarnings("unused") Class[] parameterTypes, @SuppressWarnings("unused") int modifiers, Class targetConstructorClass) { - return generateSerializationConstructor(declaringClass, parameterTypes, null, modifiers, targetConstructorClass); - } - - @SuppressWarnings("static-method") - @Substitute - @TargetElement(onlyWith = JDK19OrEarlier.class) - public Target_jdk_internal_reflect_SerializationConstructorAccessorImpl generateSerializationConstructor(Class declaringClass, - @SuppressWarnings("unused") Class[] parameterTypes, - @SuppressWarnings("unused") Class[] checkedExceptions, - @SuppressWarnings("unused") int modifiers, - Class targetConstructorClass) { SerializationRegistry serializationRegistry = ImageSingletons.lookup(SerializationRegistry.class); Object constructorAccessor = serializationRegistry.getSerializationConstructorAccessor(declaringClass, targetConstructorClass); return (Target_jdk_internal_reflect_SerializationConstructorAccessorImpl) constructorAccessor; diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/target/Target_jdk_internal_reflect_MethodHandleFieldAccessorImpl.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/target/Target_jdk_internal_reflect_MethodHandleFieldAccessorImpl.java index 025d12a110f0..e02b532b4fd1 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/target/Target_jdk_internal_reflect_MethodHandleFieldAccessorImpl.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/target/Target_jdk_internal_reflect_MethodHandleFieldAccessorImpl.java @@ -26,7 +26,6 @@ import com.oracle.svm.core.annotate.Delete; import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.jdk.JDK21OrLater; /** * Method handle base field accessor. This class must not become reachable because we have our own @@ -35,7 +34,7 @@ * * @see com.oracle.svm.core.reflect.fieldaccessor */ -@TargetClass(className = "jdk.internal.reflect.MethodHandleFieldAccessorImpl", onlyWith = JDK21OrLater.class) +@TargetClass(className = "jdk.internal.reflect.MethodHandleFieldAccessorImpl") @Delete public final class Target_jdk_internal_reflect_MethodHandleFieldAccessorImpl { } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaLangThreadGroupSubstitutions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaLangThreadGroupSubstitutions.java index 6c2ced32de59..5ae8ac905bab 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaLangThreadGroupSubstitutions.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaLangThreadGroupSubstitutions.java @@ -27,7 +27,6 @@ import java.lang.ref.WeakReference; import java.util.Arrays; -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.hosted.FieldValueTransformer; @@ -40,10 +39,7 @@ import com.oracle.svm.core.annotate.InjectAccessors; import com.oracle.svm.core.annotate.RecomputeFieldValue; import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.annotate.TargetElement; import com.oracle.svm.core.heap.Heap; -import com.oracle.svm.core.jdk.JDK17OrEarlier; -import com.oracle.svm.core.jdk.JDK19OrLater; import com.oracle.svm.core.jdk.UninterruptibleUtils; import com.oracle.svm.core.jfr.JfrThreadRepository; import com.oracle.svm.util.ReflectionUtil; @@ -51,17 +47,6 @@ @TargetClass(ThreadGroup.class) final class Target_java_lang_ThreadGroup { - @Alias @TargetElement(onlyWith = JDK17OrEarlier.class)// - @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Custom, declClass = ThreadGroupNUnstartedThreadsRecomputation.class, disableCaching = true)// - private int nUnstartedThreads; - @Alias @TargetElement(onlyWith = JDK17OrEarlier.class)// - @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Custom, declClass = ThreadGroupNThreadsRecomputation.class)// - private int nthreads; - - @Alias @TargetElement(onlyWith = JDK17OrEarlier.class) // - @InjectAccessors(ThreadGroupThreadsAccessor.class) // - private Thread[] threads; - @Inject // @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Custom, declClass = ThreadGroupThreadsRecomputation.class)// Thread[] injectedThreads; @@ -82,10 +67,8 @@ final class Target_java_lang_ThreadGroup { * All ThreadGroups in the image heap are strong and will be stored in ThreadGroup.groups. */ @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset)// - @TargetElement(onlyWith = JDK19OrLater.class)// private int nweaks; @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset)// - @TargetElement(onlyWith = JDK19OrLater.class)// private WeakReference[] weaks; @Inject @InjectAccessors(ThreadGroupIdAccessor.class) // @@ -94,14 +77,6 @@ final class Target_java_lang_ThreadGroup { @Inject @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset)// long injectedId; - @Alias - @TargetElement(onlyWith = JDK17OrEarlier.class)// - native void addUnstarted(); - - @Alias - @TargetElement(onlyWith = JDK17OrEarlier.class)// - native void add(Thread t); - @AnnotateOriginal @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) public native String getName(); @@ -156,7 +131,6 @@ public Object transform(Object receiver, Object originalValue) { class ThreadHolderRecomputation implements FieldValueTransformer { @Override public Object transform(Object receiver, Object originalValue) { - assert JavaVersionUtil.JAVA_SPEC >= 19 : "ThreadHolder only exists on JDK 19+"; int threadStatus = ReflectionUtil.readField(ReflectionUtil.lookupClass(false, "java.lang.Thread$FieldHolder"), "threadStatus", receiver); if (threadStatus == ThreadStatus.TERMINATED) { return ThreadStatus.TERMINATED; 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 431c3cb439df..b9f86b1d4ac4 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 @@ -34,18 +34,16 @@ import org.graalvm.compiler.api.replacements.Fold; import org.graalvm.compiler.core.common.SuppressFBWarnings; import org.graalvm.compiler.replacements.ReplacementsUtil; -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.nativeimage.CurrentIsolate; import org.graalvm.nativeimage.IsolateThread; +import org.graalvm.nativeimage.Platforms; +import org.graalvm.nativeimage.impl.InternalPlatform; import org.graalvm.word.Pointer; import com.oracle.svm.core.AlwaysInline; import com.oracle.svm.core.NeverInline; 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.TargetClass; -import com.oracle.svm.core.jdk.JDK19OrLater; import com.oracle.svm.core.snippets.KnownIntrinsics; import com.oracle.svm.core.stack.StackFrameVisitor; import com.oracle.svm.util.ReflectionUtil; @@ -92,6 +90,16 @@ static Target_java_lang_Thread toTarget(Thread thread) { return Target_java_lang_Thread.class.cast(thread); } + @Platforms(InternalPlatform.NATIVE_ONLY.class) + static long nextThreadID() { + return JavaThreads.threadSeqNumber.incrementAndGet(); + } + + @Platforms(InternalPlatform.NATIVE_ONLY.class) + static int nextThreadNum() { + return JavaThreads.threadInitNumber.incrementAndGet(); + } + /** * Returns the unique identifier of this thread. This method is necessary because * {@code Thread#getId()} is a non-final method that can be overridden. @@ -268,7 +276,6 @@ static void initializeNewThread( String name, long stackSize, AccessControlContext acc, - boolean allowThreadLocals, boolean inheritThreadLocals) { if (name == null) { throw new NullPointerException("The name cannot be null"); @@ -292,63 +299,28 @@ static void initializeNewThread( if (!VirtualThreads.isSupported() || !VirtualThreads.singleton().isVirtual(fromTarget(tjlt))) { PlatformThreads.setThreadStatus(fromTarget(tjlt), ThreadStatus.NEW); - if (JavaVersionUtil.JAVA_SPEC < 19) { - JavaThreads.toTarget(group).addUnstarted(); - } } tjlt.inheritedAccessControlContext = acc != null ? acc : AccessController.getContext(); - initNewThreadLocalsAndLoader(tjlt, allowThreadLocals, inheritThreadLocals, parent); + initNewThreadLocalsAndLoader(tjlt, inheritThreadLocals, parent); /* Set thread ID */ - tjlt.tid = Target_java_lang_Thread.nextThreadID(); + tjlt.tid = nextThreadID(); } static void initThreadFields(Target_java_lang_Thread tjlt, ThreadGroup group, Runnable target, long stackSize, int priority, boolean daemon) { - if (JavaVersionUtil.JAVA_SPEC >= 19) { - assert tjlt.holder == null; - tjlt.holder = new Target_java_lang_Thread_FieldHolder(group, target, stackSize, priority, daemon); - } else { - tjlt.group = group; - tjlt.priority = priority; - tjlt.daemon = daemon; - tjlt.target = target; - tjlt.setPriority(priority); - - /* Stash the specified stack size in case the VM cares */ - tjlt.stackSize = stackSize; - } + assert tjlt.holder == null; + tjlt.holder = new Target_java_lang_Thread_FieldHolder(group, target, stackSize, priority, daemon); } - static void initNewThreadLocalsAndLoader(Target_java_lang_Thread tjlt, boolean allowThreadLocals, boolean inheritThreadLocals, Thread parent) { - if (JavaVersionUtil.JAVA_SPEC >= 19 && JavaVersionUtil.JAVA_SPEC <= 20 && !allowThreadLocals) { - tjlt.threadLocals = Target_java_lang_ThreadLocal_ThreadLocalMap.NOT_SUPPORTED; - tjlt.inheritableThreadLocals = Target_java_lang_ThreadLocal_ThreadLocalMap.NOT_SUPPORTED; - tjlt.contextClassLoader = Target_java_lang_Thread_Constants.NOT_SUPPORTED_CLASSLOADER; - } else if (inheritThreadLocals) { + static void initNewThreadLocalsAndLoader(Target_java_lang_Thread tjlt, boolean inheritThreadLocals, Thread parent) { + if (inheritThreadLocals) { Target_java_lang_ThreadLocal_ThreadLocalMap parentMap = toTarget(parent).inheritableThreadLocals; - if (parentMap != null) { - boolean inherit = false; - if (JavaVersionUtil.JAVA_SPEC < 19) { - inherit = true; - } else if (parentMap.size() > 0) { - if (JavaVersionUtil.JAVA_SPEC > 20) { - inherit = true; - } else { - inherit = parentMap != Target_java_lang_ThreadLocal_ThreadLocalMap.NOT_SUPPORTED; - } - } - if (inherit) { - tjlt.inheritableThreadLocals = Target_java_lang_ThreadLocal.createInheritedMap(parentMap); - } - } - ClassLoader parentLoader = parent.getContextClassLoader(); - if (JavaVersionUtil.JAVA_SPEC < 19 || JavaVersionUtil.JAVA_SPEC > 20 || parentLoader != Target_java_lang_Thread_Constants.NOT_SUPPORTED_CLASSLOADER) { - tjlt.contextClassLoader = parentLoader; - } else { - tjlt.contextClassLoader = ClassLoader.getSystemClassLoader(); + if (parentMap != null && parentMap.size() > 0) { + tjlt.inheritableThreadLocals = Target_java_lang_ThreadLocal.createInheritedMap(parentMap); } + tjlt.contextClassLoader = parent.getContextClassLoader(); } else { tjlt.contextClassLoader = ClassLoader.getSystemClassLoader(); } @@ -409,18 +381,3 @@ public static long getCurrentThreadIdOrZero() { return 0L; } } - -/* GR-43733: this class can be removed when we drop the JDK 17 support. */ -@TargetClass(className = "jdk.internal.event.ThreadSleepEvent", onlyWith = JDK19OrLater.class) -final class Target_jdk_internal_event_ThreadSleepEvent { - @Alias public long time; - - @Alias - public static native boolean isTurnedOn(); - - @Alias - public native void begin(); - - @Alias - public native void commit(); -} 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 4440c78dec76..9972cee08744 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,7 +27,6 @@ import java.util.Arrays; import java.util.Map; -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; @@ -68,12 +67,8 @@ public void duringSetup(DuringSetupAccess access) { * This currently only means that we don't support setting custom values for * java.lang.ScopedValue.cacheSize at runtime. */ - if (JavaVersionUtil.JAVA_SPEC <= 20) { - RuntimeClassInitialization.initializeAtBuildTime("jdk.incubator.concurrent"); - } else { - RuntimeClassInitialization.initializeAtBuildTime("java.lang.ScopedValue"); - RuntimeClassInitialization.initializeAtBuildTime("java.lang.ScopedValue$Cache"); - } + RuntimeClassInitialization.initializeAtBuildTime("java.lang.ScopedValue"); + RuntimeClassInitialization.initializeAtBuildTime("java.lang.ScopedValue$Cache"); } private Object collectReachableObjects(Object original) { diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/PlatformThreads.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/PlatformThreads.java index 8783c586fe71..89bd50765d42 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/PlatformThreads.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/PlatformThreads.java @@ -51,7 +51,6 @@ import org.graalvm.compiler.api.replacements.Fold; import org.graalvm.compiler.core.common.SuppressFBWarnings; -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.nativeimage.CurrentIsolate; import org.graalvm.nativeimage.ImageInfo; import org.graalvm.nativeimage.ImageSingletons; @@ -88,6 +87,7 @@ import com.oracle.svm.core.heap.VMOperationInfos; import com.oracle.svm.core.jdk.StackTraceUtils; import com.oracle.svm.core.jdk.UninterruptibleUtils; +import com.oracle.svm.core.jfr.HasJfrSupport; import com.oracle.svm.core.locks.VMMutex; import com.oracle.svm.core.log.Log; import com.oracle.svm.core.monitor.MonitorSupport; @@ -104,6 +104,7 @@ import com.oracle.svm.core.util.VMError; import com.oracle.svm.util.ReflectionUtil; +import jdk.internal.event.ThreadSleepEvent; import jdk.internal.misc.Unsafe; /** @@ -113,12 +114,9 @@ * @see JavaThreads */ public abstract class PlatformThreads { - private static final Field FIELDHOLDER_STATUS_FIELD = (JavaVersionUtil.JAVA_SPEC >= 19 && ImageInfo.inImageCode()) + private static final Field FIELDHOLDER_STATUS_FIELD = ImageInfo.inImageCode() ? ReflectionUtil.lookupField(Target_java_lang_Thread_FieldHolder.class, "threadStatus") : null; - private static final Field THREAD_STATUS_FIELD = (JavaVersionUtil.JAVA_SPEC < 19 && ImageInfo.inImageCode()) - ? ReflectionUtil.lookupField(Target_java_lang_Thread.class, "threadStatus") - : null; @Fold public static PlatformThreads singleton() { @@ -388,7 +386,7 @@ public static long getRequestedStackSize(Thread thread) { /* Return a stack size based on parameters and command line flags. */ long stackSize; Target_java_lang_Thread tjlt = toTarget(thread); - long threadSpecificStackSize = (JavaVersionUtil.JAVA_SPEC >= 19) ? tjlt.holder.stackSize : tjlt.stackSize; + long threadSpecificStackSize = tjlt.holder.stackSize; if (threadSpecificStackSize != 0) { /* If the user set a thread stack size at thread creation, then use that. */ stackSize = threadSpecificStackSize; @@ -470,12 +468,6 @@ static void assignCurrent(Thread thread, boolean manuallyStarted) { /* If the thread was manually started, finish initializing it. */ if (manuallyStarted) { - final ThreadGroup group = thread.getThreadGroup(); - if (JavaVersionUtil.JAVA_SPEC < 19 && !(VirtualThreads.isSupported() && VirtualThreads.singleton().isVirtual(thread))) { - toTarget(group).addUnstarted(); - toTarget(group).add(thread); - } - if (!thread.isDaemon()) { nonDaemonThreads.incrementAndGet(); } @@ -647,7 +639,7 @@ private static boolean tearDownPlatformThreads() { } } else { Target_java_lang_Thread tjlt = toTarget(thread); - Runnable target = JavaVersionUtil.JAVA_SPEC >= 19 ? tjlt.holder.task : tjlt.target; + Runnable target = tjlt.holder.task; if (Target_java_util_concurrent_ThreadPoolExecutor_Worker.class.isInstance(target)) { ThreadPoolExecutor executor = SubstrateUtil.cast(target, Target_java_util_concurrent_ThreadPoolExecutor_Worker.class).executor; if (executor != null && (executor.getClass() == ThreadPoolExecutor.class || executor.getClass() == ScheduledThreadPoolExecutor.class)) { @@ -963,8 +955,8 @@ static void unpark(Thread thread) { */ static void sleep(long nanos) throws InterruptedException { assert !isCurrentThreadVirtual(); - if (com.oracle.svm.core.jfr.HasJfrSupport.get() && Target_jdk_internal_event_ThreadSleepEvent.isTurnedOn()) { - Target_jdk_internal_event_ThreadSleepEvent event = new Target_jdk_internal_event_ThreadSleepEvent(); + if (HasJfrSupport.get() && ThreadSleepEvent.isTurnedOn()) { + ThreadSleepEvent event = new ThreadSleepEvent(); try { event.time = nanos; event.begin(); @@ -1052,25 +1044,17 @@ static void interruptSleep(Thread thread) { @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) public static int getThreadStatus(Thread thread) { assert !isVirtual(thread); - return (JavaVersionUtil.JAVA_SPEC >= 19) ? toTarget(thread).holder.threadStatus : toTarget(thread).threadStatus; + return toTarget(thread).holder.threadStatus; } public static void setThreadStatus(Thread thread, int threadStatus) { assert !isVirtual(thread); - if (JavaVersionUtil.JAVA_SPEC >= 19) { - toTarget(thread).holder.threadStatus = threadStatus; - } else { - toTarget(thread).threadStatus = threadStatus; - } + toTarget(thread).holder.threadStatus = threadStatus; } static boolean compareAndSetThreadStatus(Thread thread, int expectedStatus, int newStatus) { assert !isVirtual(thread); - if (JavaVersionUtil.JAVA_SPEC >= 19) { - return Unsafe.getUnsafe().compareAndSetInt(toTarget(thread).holder, Unsafe.getUnsafe().objectFieldOffset(FIELDHOLDER_STATUS_FIELD), expectedStatus, newStatus); - } else { - return Unsafe.getUnsafe().compareAndSetInt(thread, Unsafe.getUnsafe().objectFieldOffset(THREAD_STATUS_FIELD), expectedStatus, newStatus); - } + return Unsafe.getUnsafe().compareAndSetInt(toTarget(thread).holder, Unsafe.getUnsafe().objectFieldOffset(FIELDHOLDER_STATUS_FIELD), expectedStatus, newStatus); } static boolean isAlive(Thread thread) { @@ -1222,14 +1206,8 @@ public void operate() { static void blockedOn(Target_sun_nio_ch_Interruptible b) { assert !isCurrentThreadVirtual(); Target_java_lang_Thread me = toTarget(currentThread.get()); - if (JavaVersionUtil.JAVA_SPEC >= 19) { - synchronized (me.interruptLock) { - me.nioBlocker = b; - } - } else { - synchronized (me.blockerLock) { - me.blocker = b; - } + synchronized (me.interruptLock) { + me.nioBlocker = b; } } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_BaseVirtualThread.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_BaseVirtualThread.java index 8cd27940017e..69740b971d28 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_BaseVirtualThread.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_BaseVirtualThread.java @@ -25,8 +25,7 @@ package com.oracle.svm.core.thread; import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.jdk.JDK19OrLater; -@TargetClass(className = "java.lang.BaseVirtualThread", onlyWith = JDK19OrLater.class) +@TargetClass(className = "java.lang.BaseVirtualThread") public final class Target_java_lang_BaseVirtualThread { } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Thread.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Thread.java index 1ce2a6fd7a41..ce9cc4050859 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Thread.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Thread.java @@ -34,7 +34,6 @@ import org.graalvm.compiler.api.directives.GraalDirectives; import org.graalvm.compiler.replacements.ReplacementsUtil; -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.nativeimage.IsolateThread; import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.impl.InternalPlatform; @@ -53,18 +52,11 @@ import com.oracle.svm.core.deopt.DeoptimizationSupport; import com.oracle.svm.core.jdk.ContinuationsNotSupported; import com.oracle.svm.core.jdk.ContinuationsSupported; -import com.oracle.svm.core.jdk.JDK17OrEarlier; -import com.oracle.svm.core.jdk.JDK19OrEarlier; -import com.oracle.svm.core.jdk.JDK19OrLater; -import com.oracle.svm.core.jdk.JDK20OrEarlier; -import com.oracle.svm.core.jdk.JDK20OrLater; import com.oracle.svm.core.jdk.JDK21OrEarlier; -import com.oracle.svm.core.jdk.JDK21OrLater; import com.oracle.svm.core.jdk.JDK22OrLater; import com.oracle.svm.core.jdk.LoomJDK; import com.oracle.svm.core.jdk.NotLoomJDK; import com.oracle.svm.core.monitor.MonitorSupport; -import com.oracle.svm.core.util.TimeUtils; import com.oracle.svm.core.util.VMError; @TargetClass(Thread.class) @@ -76,15 +68,9 @@ public final class Target_java_lang_Thread { public static StackTraceElement[] EMPTY_STACK_TRACE; @Alias // - @TargetElement(onlyWith = {JDK19OrLater.class, JDK20OrEarlier.class}) // - static int NO_THREAD_LOCALS; - - @Alias // - @TargetElement(onlyWith = JDK19OrLater.class) // static int NO_INHERIT_THREAD_LOCALS; @Alias // - @TargetElement(onlyWith = JDK20OrLater.class) // static Object NEW_THREAD_BINDINGS; // Checkstyle: resume @@ -115,41 +101,13 @@ public final class Target_java_lang_Thread { @Alias// volatile String name; - @Alias // - @TargetElement(onlyWith = JDK17OrEarlier.class)// - int priority; - - /* Whether or not the thread is a daemon . */ - @Alias // - @TargetElement(onlyWith = JDK17OrEarlier.class)// - boolean daemon; - - /* What will be run. */ - @Alias // - @TargetElement(onlyWith = JDK17OrEarlier.class)// - Runnable target; - - /* The group of this thread */ - @Alias // - @TargetElement(onlyWith = JDK17OrEarlier.class)// - ThreadGroup group; - @Alias// Target_java_lang_ThreadLocal_ThreadLocalMap threadLocals = null; @Alias// Target_java_lang_ThreadLocal_ThreadLocalMap inheritableThreadLocals = null; - /* - * The requested stack size for this thread, or 0 if the creator did not specify a stack size. - * It is up to the VM to do whatever it likes with this number; some VMs will ignore it. - */ - @Alias // - @TargetElement(onlyWith = JDK17OrEarlier.class)// - long stackSize; - @Alias // - @TargetElement(onlyWith = JDK19OrLater.class)// Target_java_lang_Thread_FieldHolder holder; /* Thread ID */ @@ -157,15 +115,6 @@ public final class Target_java_lang_Thread { @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Custom, declClass = ThreadIdRecomputation.class) // public long tid; - /** We have our own atomic number in {@link JavaThreads#threadSeqNumber}. */ - @Delete // - @TargetElement(onlyWith = JDK17OrEarlier.class)// - static long threadSeqNumber; - /** We have our own atomic number in {@link JavaThreads#threadInitNumber}. */ - @Delete// - @TargetElement(onlyWith = JDK17OrEarlier.class) // - static int threadInitNumber; - /* * For unstarted threads created during image generation like the main thread, we do not want to * inherit a (more or less random) access control context. @@ -175,23 +124,9 @@ public final class Target_java_lang_Thread { public AccessControlContext inheritedAccessControlContext; @Alias // - @TargetElement(onlyWith = JDK17OrEarlier.class) // - @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Custom, declClass = ThreadStatusRecomputation.class) // - volatile int threadStatus; - - @Alias // - @TargetElement(onlyWith = JDK17OrEarlier.class) // - Object blockerLock; - @Alias // - @TargetElement(onlyWith = JDK19OrLater.class) // Object interruptLock; @Alias // - @TargetElement(onlyWith = JDK17OrEarlier.class) // - volatile Target_sun_nio_ch_Interruptible blocker; - - @Alias // - @TargetElement(onlyWith = JDK19OrLater.class) // volatile Target_sun_nio_ch_Interruptible nioBlocker; /** @see JavaThreads#setCurrentThreadLockHelper */ @@ -201,57 +136,18 @@ public final class Target_java_lang_Thread { Object lockHelper; @Inject // - @TargetElement(onlyWith = JDK19OrLater.class) // @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset) // Object[] scopedValueCache; @Alias // - @TargetElement(onlyWith = JDK20OrLater.class) // Object scopedValueBindings; @Alias @Platforms(InternalPlatform.NATIVE_ONLY.class) native void setPriority(int newPriority); - @Alias - @TargetElement(onlyWith = {JDK19OrLater.class, JDK20OrEarlier.class}) - static native boolean isSupportedClassLoader(ClassLoader loader); - - @Substitute - public ClassLoader getContextClassLoader() { - if (JavaVersionUtil.JAVA_SPEC >= 19 && JavaVersionUtil.JAVA_SPEC <= 20 && !isSupportedClassLoader(contextClassLoader)) { - return ClassLoader.getSystemClassLoader(); - } - return contextClassLoader; - } - - @Substitute - public void setContextClassLoader(ClassLoader cl) { - if (JavaVersionUtil.JAVA_SPEC >= 19 && JavaVersionUtil.JAVA_SPEC <= 20 && !isSupportedClassLoader(contextClassLoader)) { - throw new UnsupportedOperationException("The context class loader cannot be set"); - } - contextClassLoader = cl; - } - - /** Replace "synchronized" modifier with delegation to an atomic increment. */ - @Substitute - @TargetElement(onlyWith = JDK17OrEarlier.class) // - @Platforms(InternalPlatform.NATIVE_ONLY.class) - static long nextThreadID() { - return JavaThreads.threadSeqNumber.incrementAndGet(); - } - - /** Replace "synchronized" modifier with delegation to an atomic increment. */ - @Substitute - @TargetElement(onlyWith = JDK17OrEarlier.class) // - @Platforms(InternalPlatform.NATIVE_ONLY.class) - private static int nextThreadNum() { - return JavaThreads.threadInitNumber.incrementAndGet(); - } - @AnnotateOriginal @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) - @TargetElement(onlyWith = JDK19OrLater.class) public native boolean isVirtual(); @Alias @@ -269,14 +165,9 @@ private static int nextThreadNum() { JavaThreads.initThreadFields(this, nonnullGroup, null, 0, Thread.NORM_PRIORITY, asDaemon); PlatformThreads.setThreadStatus(JavaThreads.fromTarget(this), ThreadStatus.RUNNABLE); - if (JavaVersionUtil.JAVA_SPEC >= 19) { - tid = Target_java_lang_Thread_ThreadIdentifiers.next(); - interruptLock = new Object(); - } else { - tid = nextThreadID(); - blockerLock = new Object(); - } - name = (withName != null) ? withName : ("System-" + nextThreadNum()); + tid = Target_java_lang_Thread_ThreadIdentifiers.next(); + interruptLock = new Object(); + name = (withName != null) ? withName : ("System-" + JavaThreads.nextThreadNum()); contextClassLoader = ClassLoader.getSystemClassLoader(); } @@ -292,7 +183,6 @@ public long getId() { @AnnotateOriginal @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) - @TargetElement(onlyWith = JDK19OrLater.class) static native ThreadGroup virtualThreadGroup(); @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) @@ -313,7 +203,6 @@ static Thread currentThread() { } @Substitute - @TargetElement(onlyWith = JDK19OrLater.class) static Thread currentCarrierThread() { Thread thread = PlatformThreads.currentThread.get(); assert thread != null : "Thread has not been set yet"; @@ -337,33 +226,12 @@ static Thread currentVThread() { @SuppressWarnings("static-method") @Substitute - @TargetElement(onlyWith = JDK19OrLater.class) void setCurrentThread(Thread thread) { PlatformThreads.setCurrentThread(JavaThreads.fromTarget(this), thread); } @Substitute @SuppressWarnings({"unused"}) - @TargetElement(onlyWith = JDK17OrEarlier.class) - @Platforms(InternalPlatform.NATIVE_ONLY.class) - private Target_java_lang_Thread( - ThreadGroup g, - Runnable target, - String name, - long stackSize, - AccessControlContext acc, - boolean inheritThreadLocals) { - /* Non-0 instance field initialization. */ - this.blockerLock = new Object(); - /* Injected Target_java_lang_Thread instance field initialization. */ - this.threadData = new ThreadData(); - /* Initialize the rest of the Thread object. */ - JavaThreads.initializeNewThread(this, g, target, name, stackSize, acc, true, inheritThreadLocals); - } - - @Substitute - @SuppressWarnings({"unused"}) - @TargetElement(onlyWith = JDK19OrLater.class) @Platforms(InternalPlatform.NATIVE_ONLY.class) private Target_java_lang_Thread( ThreadGroup g, @@ -378,24 +246,19 @@ private Target_java_lang_Thread( this.threadData = new ThreadData(); String nameLocal = (name != null) ? name : genThreadName(); - boolean allowThreadLocals = JavaVersionUtil.JAVA_SPEC >= 21 || (characteristics & NO_THREAD_LOCALS) == 0; boolean inheritThreadLocals = (characteristics & NO_INHERIT_THREAD_LOCALS) == 0; - JavaThreads.initializeNewThread(this, g, target, nameLocal, stackSize, acc, allowThreadLocals, inheritThreadLocals); + JavaThreads.initializeNewThread(this, g, target, nameLocal, stackSize, acc, inheritThreadLocals); - if (JavaVersionUtil.JAVA_SPEC >= 20) { - this.scopedValueBindings = NEW_THREAD_BINDINGS; - } + this.scopedValueBindings = NEW_THREAD_BINDINGS; } @Substitute - @TargetElement(onlyWith = JDK19OrLater.class) static String genThreadName() { return "Thread-" + JavaThreads.threadInitNumber.incrementAndGet(); } /** This constructor is called only by {@code VirtualThread}. */ @Substitute - @TargetElement(onlyWith = JDK19OrLater.class) private Target_java_lang_Thread(String name, int characteristics, boolean bound) { VMError.guarantee(!bound, "Bound virtual threads are not supported"); @@ -406,13 +269,10 @@ private Target_java_lang_Thread(String name, int characteristics, boolean bound) this.tid = Target_java_lang_Thread_ThreadIdentifiers.next(); this.inheritedAccessControlContext = Target_java_lang_Thread_Constants.NO_PERMISSIONS_ACC; - boolean allowThreadLocals = JavaVersionUtil.JAVA_SPEC >= 21 || (characteristics & NO_THREAD_LOCALS) == 0; boolean inheritThreadLocals = (characteristics & NO_INHERIT_THREAD_LOCALS) == 0; - JavaThreads.initNewThreadLocalsAndLoader(this, allowThreadLocals, inheritThreadLocals, Thread.currentThread()); + JavaThreads.initNewThreadLocalsAndLoader(this, inheritThreadLocals, Thread.currentThread()); - if (JavaVersionUtil.JAVA_SPEC >= 20) { - this.scopedValueBindings = NEW_THREAD_BINDINGS; - } + this.scopedValueBindings = NEW_THREAD_BINDINGS; } @SuppressWarnings("hiding") @@ -500,27 +360,6 @@ void interrupt0() { PlatformThreads.wakeUpVMConditionWaiters(thread); } - @Substitute - @TargetElement(onlyWith = JDK19OrEarlier.class) - @SuppressWarnings({"static-method"}) - private void stop0(Object o) { - throw VMError.unsupportedFeature("The deprecated method Thread.stop is not supported"); - } - - @Substitute - @TargetElement(onlyWith = JDK19OrEarlier.class) - @SuppressWarnings({"static-method"}) - private void suspend0() { - throw VMError.unsupportedFeature("The deprecated method Thread.suspend is not supported"); - } - - @Substitute - @TargetElement(onlyWith = JDK19OrEarlier.class) - @SuppressWarnings({"static-method"}) - private void resume0() { - throw VMError.unsupportedFeature("The deprecated method Thread.resume is not supported"); - } - @Substitute @TargetElement(onlyWith = JDK21OrEarlier.class) @SuppressWarnings({"static-method"}) @@ -544,54 +383,18 @@ private int countStackFrames() { private static native Thread[] getThreads(); @Substitute - @TargetElement(onlyWith = JDK17OrEarlier.class) - @Platforms(InternalPlatform.NATIVE_ONLY.class) - private boolean isAlive() { - return PlatformThreads.isAlive(JavaThreads.fromTarget(this)); - } - - @Substitute - @TargetElement(onlyWith = {JDK19OrLater.class, JDK20OrEarlier.class}) - private boolean isAlive0() { - return PlatformThreads.isAlive(JavaThreads.fromTarget(this)); - } - - @Substitute - @TargetElement(onlyWith = JDK21OrLater.class) private boolean alive() { return PlatformThreads.isAlive(JavaThreads.fromTarget(this)); } @Substitute - @TargetElement(onlyWith = JDK17OrEarlier.class) - @Platforms(InternalPlatform.NATIVE_ONLY.class) - private static void yield() { - PlatformThreads.singleton().yieldCurrent(); - } - - @Substitute - @TargetElement(onlyWith = JDK19OrLater.class) private static void yield0() { // Virtual threads are handled in yield() PlatformThreads.singleton().yieldCurrent(); } @Substitute - @TargetElement(onlyWith = JDK17OrEarlier.class) - @Platforms(InternalPlatform.NATIVE_ONLY.class) - private static void sleep(long millis) throws InterruptedException { - PlatformThreads.sleep(TimeUtils.millisToNanos(millis)); - } - - @Substitute - @TargetElement(name = "sleep0", onlyWith = {JDK19OrLater.class, JDK20OrEarlier.class}) - private static void sleep0JDK20(long millis) throws InterruptedException { - // Virtual threads are handled in sleep() - PlatformThreads.sleep(TimeUtils.millisToNanos(millis)); - } - - @Substitute - @TargetElement(onlyWith = {JDK21OrLater.class, JDK21OrEarlier.class}) + @TargetElement(onlyWith = JDK21OrEarlier.class) private static void sleep0(long nanos) throws InterruptedException { // Virtual threads are handled in sleep() PlatformThreads.sleep(nanos); @@ -629,7 +432,6 @@ private StackTraceElement[] getStackTrace() { /** @see com.oracle.svm.core.jdk.StackTraceUtils#asyncGetStackTrace */ @Delete - @TargetElement(onlyWith = JDK19OrLater.class) native StackTraceElement[] asyncGetStackTrace(); @Substitute @@ -639,7 +441,6 @@ private static Map getAllStackTraces() { } @Substitute - @TargetElement(onlyWith = JDK19OrLater.class) private static Thread[] getAllThreads() { return PlatformThreads.getAllThreads(); } @@ -654,11 +455,9 @@ private static void clearInterruptEvent() { } @Alias - @TargetElement(onlyWith = JDK19OrLater.class) native void setInterrupt(); @Alias // - @TargetElement(onlyWith = JDK19OrLater.class) native void clearInterrupt(); /** Carrier threads only: the current innermost continuation. */ @@ -671,7 +470,7 @@ private static void clearInterruptEvent() { public static native Target_java_lang_Thread_Builder_OfVirtual ofVirtual(); @Substitute - @TargetElement(name = "ofVirtual", onlyWith = {JDK19OrLater.class, NotLoomJDK.class}) + @TargetElement(name = "ofVirtual", onlyWith = NotLoomJDK.class) public static Target_java_lang_Thread_Builder_OfVirtual ofVirtualWithoutLoom() { if (Target_jdk_internal_misc_PreviewFeatures.isEnabled()) { if (DeoptimizationSupport.enabled()) { @@ -687,7 +486,7 @@ public static Target_java_lang_Thread_Builder_OfVirtual ofVirtualWithoutLoom() { } @Substitute - @TargetElement(name = "startVirtualThread", onlyWith = {JDK19OrLater.class, NotLoomJDK.class}) + @TargetElement(name = "startVirtualThread", onlyWith = NotLoomJDK.class) static Thread startVirtualThreadWithoutLoom(Runnable task) { Objects.requireNonNull(task); ofVirtualWithoutLoom(); // throws @@ -695,31 +494,16 @@ static Thread startVirtualThreadWithoutLoom(Runnable task) { } @Substitute - @TargetElement(onlyWith = {JDK19OrLater.class, JDK19OrEarlier.class}) - static Object[] extentLocalCache() { - return JavaThreads.toTarget(currentCarrierThread()).scopedValueCache; - } - - @Substitute - @TargetElement(onlyWith = {JDK19OrLater.class, JDK19OrEarlier.class}) - static void setExtentLocalCache(Object[] cache) { - JavaThreads.toTarget(currentCarrierThread()).scopedValueCache = cache; - } - - @Substitute - @TargetElement(onlyWith = JDK20OrLater.class) static Object[] scopedValueCache() { return JavaThreads.toTarget(currentCarrierThread()).scopedValueCache; } @Substitute - @TargetElement(onlyWith = JDK20OrLater.class) static void setScopedValueCache(Object[] cache) { JavaThreads.toTarget(currentCarrierThread()).scopedValueCache = cache; } @Alias - @TargetElement(onlyWith = JDK20OrLater.class) static native Object scopedValueBindings(); /** @@ -743,7 +527,6 @@ static void setScopedValueCache(Object[] cache) { */ @Substitute @Uninterruptible(reason = "Must not call other methods which can trigger a stack overflow.", callerMustBe = true) - @TargetElement(onlyWith = JDK20OrLater.class) static void setScopedValueBindings(Object bindings) { Target_java_lang_Thread thread = SubstrateUtil.cast(PlatformThreads.currentThread.get(), Target_java_lang_Thread.class); if (LoomSupport.isEnabled() && thread.vthread != null) { @@ -763,7 +546,6 @@ static void setScopedValueBindings(Object bindings) { * method. */ @Delete - @TargetElement(onlyWith = JDK20OrLater.class) static native Object findScopedValueBindings(); @Substitute @@ -772,7 +554,6 @@ static void blockedOn(Target_sun_nio_ch_Interruptible b) { } @Alias - @TargetElement(onlyWith = JDK19OrLater.class) native Thread.State threadState(); /** @@ -786,7 +567,6 @@ static void blockedOn(Target_sun_nio_ch_Interruptible b) { * be made uninterruptible. */ @Substitute - @TargetElement(onlyWith = JDK19OrLater.class) boolean isTerminated() { return (holder.threadStatus & JVMTI_THREAD_STATE_TERMINATED) != 0; } @@ -796,37 +576,31 @@ boolean isTerminated() { static volatile UncaughtExceptionHandler defaultUncaughtExceptionHandler; @Alias - @TargetElement(onlyWith = JDK19OrLater.class) native Target_jdk_internal_vm_ThreadContainer threadContainer(); @Alias - @TargetElement(onlyWith = JDK19OrLater.class) native long threadId(); } -@TargetClass(value = Thread.class, innerClass = "Builder", onlyWith = JDK19OrLater.class) +@TargetClass(value = Thread.class, innerClass = "Builder") interface Target_java_lang_Thread_Builder { @Alias ThreadFactory factory(); } -@TargetClass(value = Thread.class, innerClass = {"Builder", "OfVirtual"}, onlyWith = JDK19OrLater.class) +@TargetClass(value = Thread.class, innerClass = {"Builder", "OfVirtual"}) interface Target_java_lang_Thread_Builder_OfVirtual { } -@TargetClass(value = Thread.class, innerClass = "Constants", onlyWith = JDK19OrLater.class) +@TargetClass(value = Thread.class, innerClass = "Constants") final class Target_java_lang_Thread_Constants { // Checkstyle: stop @SuppressWarnings("removal") // @Alias static AccessControlContext NO_PERMISSIONS_ACC; - - @Alias // - @TargetElement(onlyWith = JDK20OrEarlier.class) // - static ClassLoader NOT_SUPPORTED_CLASSLOADER; // Checkstyle: resume } -@TargetClass(value = Thread.class, innerClass = "FieldHolder", onlyWith = JDK19OrLater.class) +@TargetClass(value = Thread.class, innerClass = "FieldHolder") @SuppressWarnings("unused") final class Target_java_lang_Thread_FieldHolder { @Alias // @@ -867,7 +641,7 @@ interface Target_sun_nio_ch_Interruptible { void interrupt(Thread t); } -@TargetClass(className = "jdk.internal.misc.PreviewFeatures", onlyWith = JDK19OrLater.class) +@TargetClass(className = "jdk.internal.misc.PreviewFeatures") final class Target_jdk_internal_misc_PreviewFeatures { @Alias static native boolean isEnabled(); diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_ThreadLocal.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_ThreadLocal.java index 2739a1d33e8a..326ea4b08d0f 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_ThreadLocal.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_ThreadLocal.java @@ -26,9 +26,6 @@ import com.oracle.svm.core.annotate.Alias; import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.annotate.TargetElement; -import com.oracle.svm.core.jdk.JDK19OrLater; -import com.oracle.svm.core.jdk.JDK20OrEarlier; @TargetClass(ThreadLocal.class) @SuppressWarnings({"unused"}) @@ -40,12 +37,6 @@ public final class Target_java_lang_ThreadLocal { @TargetClass(value = ThreadLocal.class, innerClass = "ThreadLocalMap") @SuppressWarnings({"unused"}) final class Target_java_lang_ThreadLocal_ThreadLocalMap { - // Checkstyle: stop - @Alias @TargetElement(onlyWith = {JDK19OrLater.class, JDK20OrEarlier.class}) // - static Target_java_lang_ThreadLocal_ThreadLocalMap NOT_SUPPORTED; - // Checkstyle: resume - @Alias - @TargetElement(onlyWith = JDK19OrLater.class) native int size(); } 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 ad753d0248f6..c05e65e35814 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 @@ -35,26 +35,17 @@ import com.oracle.svm.core.annotate.Alias; import com.oracle.svm.core.annotate.AnnotateOriginal; import com.oracle.svm.core.annotate.Delete; -import com.oracle.svm.core.annotate.RecomputeFieldValue; import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.annotate.TargetElement; -import com.oracle.svm.core.jdk.JDK20OrEarlier; -import com.oracle.svm.core.jdk.JDK20OrLater; -import com.oracle.svm.core.jdk.JDK21OrLater; import com.oracle.svm.core.jdk.LoomJDK; +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.core.jfr.SubstrateJVM; -import com.oracle.svm.core.jfr.HasJfrSupport; @TargetClass(className = "java.lang.VirtualThread", onlyWith = LoomJDK.class) public final class Target_java_lang_VirtualThread { - @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset)// - @TargetElement(onlyWith = JDK20OrEarlier.class)// - private static boolean notifyJvmtiEvents; - // Checkstyle: stop @Alias static int NEW; @Alias static int STARTED; @@ -75,52 +66,35 @@ private static void registerNatives() { } @Substitute - @TargetElement(onlyWith = JDK21OrLater.class) @SuppressWarnings({"static-method", "unused"}) private void notifyJvmtiStart() { // unimplemented (GR-46126) } @Substitute - @TargetElement(onlyWith = JDK21OrLater.class) @SuppressWarnings({"static-method", "unused"}) private void notifyJvmtiEnd() { // unimplemented (GR-46126) } @Substitute - @TargetElement(onlyWith = JDK21OrLater.class) @SuppressWarnings({"static-method", "unused"}) private void notifyJvmtiMount(boolean hide) { // unimplemented (GR-45392) } @Substitute - @TargetElement(onlyWith = JDK21OrLater.class) @SuppressWarnings({"static-method", "unused"}) private void notifyJvmtiUnmount(boolean hide) { // unimplemented (GR-45392) } @Substitute - @TargetElement(onlyWith = JDK21OrLater.class) @SuppressWarnings({"static-method", "unused"}) private void notifyJvmtiHideFrames(boolean hide) { // unimplemented (GR-45392) } - @Substitute - @TargetElement(onlyWith = {JDK20OrLater.class, JDK20OrEarlier.class}, name = "notifyJvmtiHideFrames") - @SuppressWarnings({"static-method", "unused"}) - private void notifyJvmtiHideFramesJDK20(boolean hide) { - /* - * Unfortunately, resetting the `notifyJvmtiEvents` field is not enough to completely remove - * calls to this method due to the way it's used from the `switchToVirtualThread` method, so - * unlike the other `notifyJvmti*` methods, we need a substitution to prevent linker errors. - */ - throw VMError.shouldNotReachHereSubstitution(); - } - @Alias Executor scheduler; @Alias volatile Thread carrierThread; diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_jdk_internal_vm_Continuation.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_jdk_internal_vm_Continuation.java index f84f921e6251..78ddc4b0d1e6 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_jdk_internal_vm_Continuation.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_jdk_internal_vm_Continuation.java @@ -33,14 +33,13 @@ import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; import com.oracle.svm.core.jdk.InternalVMMethod; -import com.oracle.svm.core.jdk.JDK19OrLater; import com.oracle.svm.core.jdk.LoomJDK; import com.oracle.svm.core.jdk.NotLoomJDK; import com.oracle.svm.core.stack.JavaFrameAnchor; import com.oracle.svm.core.stack.JavaFrameAnchors; import com.oracle.svm.core.util.VMError; -@TargetClass(className = "Continuation", classNameProvider = Package_jdk_internal_vm_helper.class, onlyWith = {JDK19OrLater.class, NotLoomJDK.class}) +@TargetClass(className = "Continuation", classNameProvider = Package_jdk_internal_vm_helper.class, onlyWith = NotLoomJDK.class) @Substitute @SuppressWarnings("unused") final class Target_jdk_internal_vm_Continuation__WithoutLoom { diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_jdk_internal_vm_ContinuationScope.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_jdk_internal_vm_ContinuationScope.java index 0fad4c284c7c..8cd20f6da792 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_jdk_internal_vm_ContinuationScope.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_jdk_internal_vm_ContinuationScope.java @@ -25,8 +25,7 @@ package com.oracle.svm.core.thread; import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.jdk.JDK19OrLater; -@TargetClass(className = "ContinuationScope", classNameProvider = Package_jdk_internal_vm_helper.class, onlyWith = JDK19OrLater.class) +@TargetClass(className = "ContinuationScope", classNameProvider = Package_jdk_internal_vm_helper.class) public final class Target_jdk_internal_vm_ContinuationScope { } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_jdk_internal_vm_ThreadContainers.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_jdk_internal_vm_ThreadContainers.java index b9901913fb7c..6b9df32ac583 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_jdk_internal_vm_ThreadContainers.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_jdk_internal_vm_ThreadContainers.java @@ -32,13 +32,12 @@ import com.oracle.svm.core.annotate.Delete; import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.jdk.JDK19OrLater; /** * We currently don't provide/expose means for debugging and monitoring of threads, so we replace * these methods with an empty implementation. */ -@TargetClass(className = "jdk.internal.vm.ThreadContainers", onlyWith = JDK19OrLater.class) +@TargetClass(className = "jdk.internal.vm.ThreadContainers") @SuppressWarnings("unused") final class Target_jdk_internal_vm_ThreadContainers { // Checkstyle: stop @@ -61,6 +60,6 @@ static Stream children(Target_jdk_intern } } -@TargetClass(className = "jdk.internal.vm.ThreadContainer", onlyWith = JDK19OrLater.class) +@TargetClass(className = "jdk.internal.vm.ThreadContainer") final class Target_jdk_internal_vm_ThreadContainer { } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ModuleLayerFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ModuleLayerFeature.java index e013c0d086af..b13641cd40af 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ModuleLayerFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ModuleLayerFeature.java @@ -56,7 +56,6 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; @@ -506,10 +505,6 @@ private void replicateVisibilityModifications(ModuleLayer runtimeBootLayer, Afte } private void replicateNativeAccess(AfterAnalysisAccessImpl accessImpl, Set analysisReachableNamedModules) { - if (JavaVersionUtil.JAVA_SPEC < 19) { - return; - } - Map modulePairs = analysisReachableNamedModules .stream() .collect(Collectors.toMap(m -> m, m -> moduleLayerFeatureUtils.getRuntimeModuleForHostedModule(m, false))); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/EarlyClassInitializerAnalysis.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/EarlyClassInitializerAnalysis.java index a576cd5fb2ee..b6eab87e34d6 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/EarlyClassInitializerAnalysis.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/EarlyClassInitializerAnalysis.java @@ -58,7 +58,6 @@ import org.graalvm.compiler.phases.OptimisticOptimizations; import org.graalvm.compiler.phases.tiers.HighTierContext; import org.graalvm.compiler.phases.util.Providers; -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.impl.RuntimeClassInitializationSupport; @@ -123,7 +122,7 @@ final class EarlyClassInitializerAnalysis { @SuppressWarnings("try") boolean canInitializeWithoutSideEffects(Class clazz, Set> existingAnalyzedClasses) { - if (JavaVersionUtil.JAVA_SPEC >= 19 && Proxy.isProxyClass(clazz)) { + if (Proxy.isProxyClass(clazz)) { /* * The checks below consider proxy class initialization as of JDK 19 to have side * effects because it accesses Class.classLoader and System.allowSecurityManager, but diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/CCLinkerInvocation.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/CCLinkerInvocation.java index 17c94dcc4e19..02f56faf95aa 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/CCLinkerInvocation.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/CCLinkerInvocation.java @@ -39,7 +39,6 @@ import org.graalvm.compiler.options.Option; import org.graalvm.compiler.options.OptionStability; -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.Platform; @@ -519,10 +518,8 @@ public List getCommand() { cmd.add("secur32.lib"); cmd.add("iphlpapi.lib"); cmd.add("userenv.lib"); - if (JavaVersionUtil.JAVA_SPEC >= 20) { - /* JDK-8295231 removed implicit linking via pragma directives in source files. */ - cmd.add("mswsock.lib"); - } + /* JDK-8295231 removed implicit linking via pragma directives in source files. */ + cmd.add("mswsock.lib"); if (SubstrateOptions.EnableWildcardExpansion.getValue() && imageKind == AbstractImage.NativeImageKind.EXECUTABLE) { /* 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 index 336746da252a..5aecf8c9e951 100644 --- 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 @@ -83,11 +83,6 @@ public void duringSetup(DuringSetupAccess access) { allowContextIfExists("javax.management.monitor.Monitor", "noPermissionsACC"); allowContextIfExists("java.security.AccessController$AccHolder", "innocuousAcc"); - if (JavaVersionUtil.JAVA_SPEC < 19) { - allowContextIfExists("java.util.concurrent.ForkJoinPool$DefaultForkJoinWorkerThreadFactory", "ACC"); - allowContextIfExists("java.util.concurrent.ForkJoinPool$WorkQueue", "INNOCUOUS_ACC"); - allowContextIfExists("java.util.concurrent.ForkJoinPool$DefaultCommonPoolForkJoinWorkerThreadFactory", "ACC"); - } access.registerObjectReplacer(AccessControlContextReplacerFeature::replaceAccessControlContext); } 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 cdfd8456fe6d..1e771cd3bad0 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 @@ -24,13 +24,12 @@ */ package com.oracle.svm.hosted.jdk; -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.impl.RuntimeClassInitializationSupport; -import com.oracle.svm.core.feature.InternalFeature; import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature; +import com.oracle.svm.core.feature.InternalFeature; @AutomaticallyRegisteredFeature public class JDKInitializationFeature implements InternalFeature { @@ -174,8 +173,6 @@ public void afterRegistration(AfterRegistrationAccess access) { rci.rerunInitialization("jdk.internal.misc.InnocuousThread", "Contains a thread group INNOCUOUSTHREADGROUP."); - if (JavaVersionUtil.JAVA_SPEC >= 19) { - rci.rerunInitialization("sun.nio.ch.Poller", "Contains an InnocuousThread."); - } + rci.rerunInitialization("sun.nio.ch.Poller", "Contains an InnocuousThread."); } } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JDKRegistrations.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JDKRegistrations.java index db0d8335ca16..26173dab50b5 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JDKRegistrations.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JDKRegistrations.java @@ -87,8 +87,8 @@ public void beforeAnalysis(BeforeAnalysisAccess access) { private static void registerInfoCmpResources(BeforeAnalysisAccess access) { /* - * GR-43733: Replace reflective class lookup with class literal when removing JDK 17 - * support. + * A JDK reduced via jlink might not have this class, so we must use a reflective class + * lookup. */ Class infoCmpClazz = ReflectionUtil.lookupClass(true, "jdk.internal.org.jline.utils.InfoCmp"); 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 cb7dbe062097..d4d9a5f6307d 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 org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.hosted.RuntimeJNIAccess; import org.graalvm.nativeimage.impl.InternalPlatform; @@ -109,17 +108,9 @@ public void beforeAnalysis(BeforeAnalysisAccess a) { RuntimeJNIAccess.register(java.nio.charset.Charset.class); RuntimeJNIAccess.register(constructor(a, "java.lang.String", byte[].class)); RuntimeJNIAccess.register(method(a, "java.lang.String", "getBytes")); - if (JavaVersionUtil.JAVA_SPEC >= 21) { - // Needed for JDK 21+20 and later which include JDK-8305746. - RuntimeJNIAccess.register(method(a, "java.nio.charset.Charset", "forName", String.class)); - RuntimeJNIAccess.register(constructor(a, "java.lang.String", byte[].class, java.nio.charset.Charset.class)); - RuntimeJNIAccess.register(method(a, "java.lang.String", "getBytes", java.nio.charset.Charset.class)); - } - if (JavaVersionUtil.JAVA_SPEC < 21) { - RuntimeJNIAccess.register(method(a, "java.nio.charset.Charset", "isSupported", String.class)); - RuntimeJNIAccess.register(constructor(a, "java.lang.String", byte[].class, String.class)); - RuntimeJNIAccess.register(method(a, "java.lang.String", "getBytes", String.class)); - } + RuntimeJNIAccess.register(method(a, "java.nio.charset.Charset", "forName", String.class)); + RuntimeJNIAccess.register(constructor(a, "java.lang.String", byte[].class, java.nio.charset.Charset.class)); + RuntimeJNIAccess.register(method(a, "java.lang.String", "getBytes", java.nio.charset.Charset.class)); RuntimeJNIAccess.register(method(a, "java.lang.String", "concat", String.class)); RuntimeJNIAccess.register(fields(a, "java.lang.String", "coder", "value")); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNet.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNet.java index 711a10fbe9fa..d8fbc0877e53 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNet.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNet.java @@ -28,7 +28,6 @@ import java.net.Proxy; import java.net.SocketAddress; -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.hosted.RuntimeJNIAccess; import org.graalvm.nativeimage.hosted.RuntimeReflection; @@ -55,26 +54,8 @@ public void duringSetup(DuringSetupAccess a) { rerunClassInit(a, "java.net.DatagramPacket", "java.net.InetAddress", "java.net.NetworkInterface", /* Stores a default SSLContext in a static field. */ "javax.net.ssl.SSLContext"); - if (JavaVersionUtil.JAVA_SPEC < 19) { - /* Removed by https://bugs.openjdk.java.net/browse/JDK-8253119 */ - rerunClassInit(a, "java.net.SocketInputStream", "java.net.SocketOutputStream", - /* Caches networking properties. */ - "java.net.DefaultDatagramSocketImplFactory"); - if (isWindows()) { - /* Caches networking properties. */ - rerunClassInit(a, "java.net.PlainSocketImpl", "java.net.DualStackPlainDatagramSocketImpl", "java.net.TwoStacksPlainDatagramSocketImpl"); - } else { - assert isPosix(); - rerunClassInit(a, "java.net.PlainDatagramSocketImpl", "java.net.PlainSocketImpl"); - rerunClassInit(a, "java.net.AbstractPlainDatagramSocketImpl", "java.net.AbstractPlainSocketImpl"); - } - } - if (this.hasPlatformSocketOptions && (isPosix() || JavaVersionUtil.JAVA_SPEC >= 19)) { - /* - * The libextnet was actually introduced in Java 9, but the support for Linux, Darwin - * and Windows was added later in Java 10, Java 11 and Java 19 respectively. - */ + if (this.hasPlatformSocketOptions) { rerunClassInit(a, "jdk.net.ExtendedSocketOptions", "jdk.net.ExtendedSocketOptions$PlatformSocketOptions", "sun.net.ext.ExtendedSocketOptions"); } if (isDarwin()) { @@ -99,57 +80,16 @@ public void beforeAnalysis(BeforeAnalysisAccess a) { * InetAddress, Inet4Address, and Inet6Address are registered from many places in the JDK, * so it does not make sense to separate them. */ - if (JavaVersionUtil.JAVA_SPEC < 19) { - a.registerReachabilityHandler(JNIRegistrationJavaNet::registerInitInetAddressIDs, - method(a, "java.net.InetAddress", "init"), - /* The next two methods call initInetAddressIDs directly. */ - method(a, "java.net.Inet4AddressImpl", "lookupAllHostAddr", String.class), - method(a, "java.net.Inet6AddressImpl", "lookupAllHostAddr", String.class)); - } else { - a.registerReachabilityHandler(JNIRegistrationJavaNet::registerInitInetAddressIDs, - method(a, "java.net.InetAddress", "init"), - /* The next two methods call initInetAddressIDs directly. */ - method(a, "java.net.Inet4AddressImpl", "lookupAllHostAddr", String.class), - method(a, "java.net.Inet6AddressImpl", "lookupAllHostAddr", String.class, int.class)); - } - if (JavaVersionUtil.JAVA_SPEC < 19) { - a.registerReachabilityHandler(JNIRegistrationJavaNet::registerInetAddressLoadImpl, - method(a, "java.net.InetAddress", "loadImpl", String.class)); - } + a.registerReachabilityHandler(JNIRegistrationJavaNet::registerInitInetAddressIDs, + method(a, "java.net.InetAddress", "init"), + /* The next two methods call initInetAddressIDs directly. */ + method(a, "java.net.Inet4AddressImpl", "lookupAllHostAddr", String.class), + method(a, "java.net.Inet6AddressImpl", "lookupAllHostAddr", String.class, int.class)); a.registerReachabilityHandler(JNIRegistrationJavaNet::registerNetworkInterfaceInit, method(a, "java.net.NetworkInterface", "init")); - if (JavaVersionUtil.JAVA_SPEC < 19) { - a.registerReachabilityHandler(JNIRegistrationJavaNet::registerDatagramPacketInit, - method(a, "java.net.DatagramPacket", "init")); - } - - if (JavaVersionUtil.JAVA_SPEC < 19) { - /* Removed by https://bugs.openjdk.java.net/browse/JDK-8253119 */ - String plainDatagramSocketImpl = isWindows() ? "TwoStacksPlainDatagramSocketImpl" : "PlainDatagramSocketImpl"; - a.registerReachabilityHandler(JNIRegistrationJavaNet::registerPlainDatagramSocketImplInit, - method(a, "java.net." + plainDatagramSocketImpl, "init")); - a.registerReachabilityHandler(JNIRegistrationJavaNet::registerPlainDatagramSocketImplSocketGetOption, - method(a, "java.net." + plainDatagramSocketImpl, "socketGetOption", int.class)); - - if (isPosix()) { - String plainSocketImpl = isWindows() ? "TwoStacksPlainSocketImpl" : "PlainSocketImpl"; - a.registerReachabilityHandler(JNIRegistrationJavaNet::registerPlainSocketImplInitProto, - method(a, "java.net." + plainSocketImpl, "initProto")); - a.registerReachabilityHandler(JNIRegistrationJavaNet::registerPlainSocketImplSocketGetOption, - method(a, "java.net." + plainSocketImpl, "socketGetOption", int.class, Object.class)); - } - if (isWindows()) { - a.registerReachabilityHandler(JNIRegistrationJavaNet::registerDualStackPlainDatagramSocketImplInitIDs, - method(a, "java.net.DualStackPlainDatagramSocketImpl", "initIDs")); - a.registerReachabilityHandler(JNIRegistrationJavaNet::registerDualStackPlainSocketImplInitIDs, - method(a, "java.net.PlainSocketImpl", "initIDs")); - a.registerReachabilityHandler(JNIRegistrationJavaNet::registerDualStackPlainSocketImplLocalAddress, - method(a, "java.net.PlainSocketImpl", "localAddress", int.class, clazz(a, "java.net.InetAddressContainer"))); - } - } - if (this.hasPlatformSocketOptions && (isPosix() || JavaVersionUtil.JAVA_SPEC >= 19)) { + if (this.hasPlatformSocketOptions) { /* Support for the libextnet. */ a.registerReachabilityHandler(JNIRegistrationJavaNet::registerPlatformSocketOptionsCreate, method(a, "jdk.net.ExtendedSocketOptions$PlatformSocketOptions", "create")); @@ -165,9 +105,6 @@ static void registerInitInetAddressIDs(DuringAnalysisAccess a) { /* Java_java_net_InetAddress_init */ RuntimeJNIAccess.register(fields(a, "java.net.InetAddress", "holder")); - if (JavaVersionUtil.JAVA_SPEC <= 17) { - RuntimeJNIAccess.register(fields(a, "java.net.InetAddress", "preferIPv6Address")); - } RuntimeJNIAccess.register(fields(a, "java.net.InetAddress$InetAddressHolder", "address", "family", "hostName", "originalHostName")); /* Java_java_net_Inet4Address_init */ @@ -195,9 +132,6 @@ private static void registerNetworkInterfaceInit(DuringAnalysisAccess a) { RuntimeJNIAccess.register(fields(a, "java.net.NetworkInterface", "name", "displayName", "index", "addrs", "bindings", "childs")); if (isPosix()) { RuntimeJNIAccess.register(fields(a, "java.net.NetworkInterface", "virtual", "parent")); - if (JavaVersionUtil.JAVA_SPEC < 20) { - RuntimeJNIAccess.register(fields(a, "java.net.NetworkInterface", "defaultIndex")); - } } RuntimeJNIAccess.register(constructor(a, "java.net.InterfaceAddress")); 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 9dbb0d7e48f9..013049b618da 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 @@ -29,7 +29,6 @@ import java.nio.ByteBuffer; import java.util.function.Consumer; -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.hosted.RuntimeJNIAccess; import org.graalvm.nativeimage.hosted.RuntimeReflection; @@ -99,9 +98,6 @@ public void beforeAnalysis(BeforeAnalysisAccess a) { // JDK-8220738 a.registerReachabilityHandler(JNIRegistrationJavaNio::registerNetInitIDs, method(a, "sun.nio.ch.Net", "initIDs")); - if (JavaVersionUtil.JAVA_SPEC <= 17) { - a.registerReachabilityHandler(JNIRegistrationJavaNio::registerFileChannelImplInitIDs, method(a, "sun.nio.ch.FileChannelImpl", "initIDs")); - } a.registerReachabilityHandler(JNIRegistrationJavaNio::registerFileKeyInitIDs, method(a, "sun.nio.ch.FileKey", "initIDs")); if (isPosix()) { @@ -122,14 +118,6 @@ public void beforeAnalysis(BeforeAnalysisAccess a) { Consumer registerInitInetAddressIDs = JNIRegistrationJavaNet::registerInitInetAddressIDs; a.registerReachabilityHandler(registerInitInetAddressIDs, method(a, "sun.nio.ch.Net", "initIDs")); - - /* - * In JDK 17, all of the Buffer classes require MemorySegmentProxy which is accessed via - * reflection. - */ - if (JavaVersionUtil.JAVA_SPEC == 17) { - RuntimeReflection.register(clazz(a, "jdk.internal.access.foreign.MemorySegmentProxy")); - } } private static void registerNetInitIDs(DuringAnalysisAccess a) { 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 ebcb2fddbbea..3194e412a48f 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 @@ -37,7 +37,6 @@ import com.oracle.graal.pointsto.infrastructure.OriginalClassProvider; import com.oracle.graal.pointsto.infrastructure.SubstitutionProcessor; -import com.oracle.svm.core.jfr.JfrEventWriterAccess; import com.oracle.svm.core.jfr.JfrJavaEvents; import com.oracle.svm.core.jfr.JfrJdkCompatibility; import com.oracle.svm.core.util.ObservableImageHeapMapProvider; @@ -47,6 +46,7 @@ import jdk.internal.misc.Unsafe; import jdk.jfr.internal.JVM; import jdk.jfr.internal.SecuritySupport; +import jdk.jfr.internal.event.EventWriter; import jdk.vm.ci.meta.MetaAccessProvider; import jdk.vm.ci.meta.ResolvedJavaField; import jdk.vm.ci.meta.ResolvedJavaMethod; @@ -68,7 +68,7 @@ public class JfrEventSubstitution extends SubstitutionProcessor { JfrEventSubstitution(MetaAccessProvider metaAccess) { baseEventType = metaAccess.lookupJavaType(jdk.internal.event.Event.class); - ResolvedJavaType jdkJfrEventWriter = metaAccess.lookupJavaType(JfrEventWriterAccess.getEventWriterClass()); + ResolvedJavaType jdkJfrEventWriter = metaAccess.lookupJavaType(EventWriter.class); changeWriterResetMethod(jdkJfrEventWriter); typeSubstitution = new ConcurrentHashMap<>(); methodSubstitutions = new ConcurrentHashMap<>(); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionFeature.java index 372d1e533162..0dfe2886fa60 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionFeature.java @@ -38,7 +38,6 @@ import org.graalvm.compiler.api.replacements.SnippetReflectionProvider; import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins; import org.graalvm.compiler.phases.util.Providers; -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.nativeimage.AnnotationAccess; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.c.function.CFunctionPointer; @@ -95,16 +94,16 @@ public class ReflectionFeature implements InternalFeature, ReflectionSubstitutionSupport { /** - * The CallerSensitiveAdapter mechanism of the JDK (introduced after JDK 17) is a formalization - * of {@link CallerSensitive} methods: the "caller sensitive adapter for a - * {@link CallerSensitive} method is a method with the same name and same signature (except for - * a trailing Class parameter). When a {@link CallerSensitive} method is invoked via reflection - * or a method handle, then the adapter is invoked instead and the caller class is passed in - * explicitly. This avoids corner cases where {@link Reflection#getCallerClass} returns an - * internal method of the reflection / method handle implementation. + * The CallerSensitiveAdapter mechanism of the JDK is a formalization of {@link CallerSensitive} + * methods: the "caller sensitive adapter for a {@link CallerSensitive} method is a method with + * the same name and same signature (except for a trailing Class parameter). When a + * {@link CallerSensitive} method is invoked via reflection or a method handle, then the adapter + * is invoked instead and the caller class is passed in explicitly. This avoids corner cases + * where {@link Reflection#getCallerClass} returns an internal method of the reflection / method + * handle implementation. */ - private static final Method findCallerSensitiveAdapterMethod = JavaVersionUtil.JAVA_SPEC <= 17 ? null - : ReflectionUtil.lookupMethod(ReflectionUtil.lookupClass(false, "jdk.internal.reflect.DirectMethodHandleAccessor"), "findCSMethodAdapter", Method.class); + private static final Method findCallerSensitiveAdapterMethod = ReflectionUtil.lookupMethod(ReflectionUtil.lookupClass(false, "jdk.internal.reflect.DirectMethodHandleAccessor"), + "findCSMethodAdapter", Method.class); private AnnotationSubstitutionProcessor annotationSubstitutions; @@ -172,16 +171,14 @@ private SubstrateAccessor createAccessor(Executable member) { expandSignature = register(analysisAccess.getMetaAccess().lookupJavaMethod(methodHandleInvokeErrorMethod), "Registered in " + ReflectionFeature.class); } else { Method target = (Method) member; - if (JavaVersionUtil.JAVA_SPEC > 17) { - try { - Method adapter = (Method) findCallerSensitiveAdapterMethod.invoke(null, member); - if (adapter != null) { - target = adapter; - callerSensitiveAdapter = true; - } - } catch (ReflectiveOperationException ex) { - throw VMError.shouldNotReachHere(ex); + try { + Method adapter = (Method) findCallerSensitiveAdapterMethod.invoke(null, member); + if (adapter != null) { + target = adapter; + callerSensitiveAdapter = true; } + } catch (ReflectiveOperationException ex) { + throw VMError.shouldNotReachHere(ex); } expandSignature = createExpandSignatureMethod(target, callerSensitiveAdapter); AnalysisMethod targetMethod = analysisAccess.getMetaAccess().lookupJavaMethod(target); diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleJFRFeature.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleJFRFeature.java index 3aefd10dc3c4..1607b8176bc9 100644 --- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleJFRFeature.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleJFRFeature.java @@ -27,7 +27,6 @@ import java.util.Iterator; import java.util.List; -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.hosted.Feature; @@ -67,10 +66,6 @@ public List> getRequiredFeatures() { } private static boolean isEnabled() { - /* - * GR-38866: Does not work on JDK 17 due to the Truffle module not being open to the JFR - * module, but the problematic code was removed for later JDKs. - */ - return ImageSingletons.contains(TruffleFeature.class) && ImageSingletons.contains(JfrFeature.class) && JavaVersionUtil.JAVA_SPEC > 17; + return ImageSingletons.contains(TruffleFeature.class) && ImageSingletons.contains(JfrFeature.class); } }