From f96e3eafec8fcd04438251c2a6c40beab685d0ed Mon Sep 17 00:00:00 2001 From: Christian Wimmer Date: Sat, 1 Apr 2023 19:24:24 -0700 Subject: [PATCH 1/8] Remove jdk17 projects --- substratevm/mx.substratevm/suite.py | 68 +------------------ .../core/jdk17/RecordSupportJDK17OrLater.java | 0 .../jdk17/SealedClassSupportJDK17OrLater.java | 0 ...et_java_lang_ClassLoader_JDK17OrLater.java | 0 .../Target_java_lang_Module_JDK17OrLater.java | 0 ...arget_java_nio_DirectByteBuffer_JDK17.java | 0 ...ava_nio_DirectByteBuffer_JDK19OrLater.java | 0 ...ternal_loader_BootLoader_JDK17OrLater.java | 0 .../Target_sun_nio_ch_UnixDomainSockets.java | 0 .../JNIRegistrationSupport_JDK17OrLater.java | 0 .../reflect-config.json | 0 .../svm/test/jdk17/recordannotations/F.java | 0 .../svm/test/jdk17/recordannotations/RCA.java | 0 .../test/jdk17/recordannotations/RCA2.java | 0 .../RecordAnnotationsTest.java | 6 +- 15 files changed, 4 insertions(+), 70 deletions(-) rename substratevm/src/{com.oracle.svm.core.jdk17 => com.oracle.svm.core}/src/com/oracle/svm/core/jdk17/RecordSupportJDK17OrLater.java (100%) rename substratevm/src/{com.oracle.svm.core.jdk17 => com.oracle.svm.core}/src/com/oracle/svm/core/jdk17/SealedClassSupportJDK17OrLater.java (100%) rename substratevm/src/{com.oracle.svm.core.jdk17 => com.oracle.svm.core}/src/com/oracle/svm/core/jdk17/Target_java_lang_ClassLoader_JDK17OrLater.java (100%) rename substratevm/src/{com.oracle.svm.core.jdk17 => com.oracle.svm.core}/src/com/oracle/svm/core/jdk17/Target_java_lang_Module_JDK17OrLater.java (100%) rename substratevm/src/{com.oracle.svm.core.jdk17 => com.oracle.svm.core}/src/com/oracle/svm/core/jdk17/Target_java_nio_DirectByteBuffer_JDK17.java (100%) rename substratevm/src/{com.oracle.svm.core.jdk17 => com.oracle.svm.core}/src/com/oracle/svm/core/jdk17/Target_java_nio_DirectByteBuffer_JDK19OrLater.java (100%) rename substratevm/src/{com.oracle.svm.core.jdk17 => com.oracle.svm.core}/src/com/oracle/svm/core/jdk17/Target_jdk_internal_loader_BootLoader_JDK17OrLater.java (100%) rename substratevm/src/{com.oracle.svm.core.jdk17 => com.oracle.svm.core}/src/com/oracle/svm/core/jdk17/Target_sun_nio_ch_UnixDomainSockets.java (100%) rename substratevm/src/{com.oracle.svm.hosted.jdk17 => com.oracle.svm.hosted}/src/com/oracle/svm/hosted/jdk17/JNIRegistrationSupport_JDK17OrLater.java (100%) rename substratevm/src/{com.oracle.svm.test.jdk17 => com.oracle.svm.test}/src/META-INF/native-image/com.oracle.svm.test.jdk17/reflect-config.json (100%) rename substratevm/src/{com.oracle.svm.test.jdk17 => com.oracle.svm.test}/src/com/oracle/svm/test/jdk17/recordannotations/F.java (100%) rename substratevm/src/{com.oracle.svm.test.jdk17 => com.oracle.svm.test}/src/com/oracle/svm/test/jdk17/recordannotations/RCA.java (100%) rename substratevm/src/{com.oracle.svm.test.jdk17 => com.oracle.svm.test}/src/com/oracle/svm/test/jdk17/recordannotations/RCA2.java (100%) rename substratevm/src/{com.oracle.svm.test.jdk17 => com.oracle.svm.test}/src/com/oracle/svm/test/jdk17/recordannotations/RecordAnnotationsTest.java (95%) diff --git a/substratevm/mx.substratevm/suite.py b/substratevm/mx.substratevm/suite.py index 28b222996f02..4621810c7bac 100644 --- a/substratevm/mx.substratevm/suite.py +++ b/substratevm/mx.substratevm/suite.py @@ -328,30 +328,6 @@ }, - "com.oracle.svm.core.jdk17": { - "subDir": "src", - "sourceDirs": ["src"], - "dependencies": ["com.oracle.svm.core"], - "requiresConcealed" : { - "java.base" : [ - "jdk.internal.access.foreign", - "jdk.internal.loader", - "jdk.internal.misc", - "jdk.internal.platform", - "sun.invoke.util", - ], - }, - "javaCompliance": "17+", - "annotationProcessors": [ - "compiler:GRAAL_PROCESSOR", - "SVM_PROCESSOR", - ], - "checkstyle": "com.oracle.svm.core", - "workingSets": "SVM", - "jacoco" : "exclude", - }, - - "com.oracle.svm.core.genscavenge": { "subDir": "src", "sourceDirs": [ @@ -620,6 +596,7 @@ "java.base" : [ "jdk.internal", "jdk.internal.event", + "jdk.internal.loader", "jdk.internal.misc", "jdk.internal.vm.annotation", "jdk.internal.org.objectweb.asm", @@ -661,26 +638,6 @@ "jacoco" : "include", }, - "com.oracle.svm.hosted.jdk17": { - "subDir": "src", - "sourceDirs": ["src"], - "dependencies": [ - "com.oracle.svm.hosted", - ], - "requiresConcealed" : { - "java.base" : - ["jdk.internal.loader"], - "jdk.internal.vm.ci" : - ["jdk.vm.ci.meta"], - }, - "javaCompliance": "17+", - "annotationProcessors": [ - "compiler:GRAAL_PROCESSOR", - "SVM_PROCESSOR", - ], - "workingSets": "SVM", - "jacoco" : "exclude", - }, # Native libraries below explicitly set _FORTIFY_SOURCE to 0. This constant controls how glibc handles some # functions that can cause a stack overflow like snprintf. If set to 1 or 2, it causes glibc to use internal # functions with extra checking that are not available in all libc implementations. Different distros use @@ -879,26 +836,6 @@ "jacoco" : "exclude", }, - "com.oracle.svm.test.jdk17": { - "subDir": "src", - "sourceDirs": ["src"], - "dependencies": [ - "mx:JUNIT_TOOL", - "sdk:GRAAL_SDK", - "SVM", - ], - "checkstyle": "com.oracle.svm.test", - "workingSets": "SVM", - "annotationProcessors": [ - "compiler:GRAAL_PROCESSOR", - "SVM_PROCESSOR", - ], - "javaCompliance": "17+", - "spotbugs": "false", - "testProject": True, - "jacoco" : "exclude", - }, - "com.oracle.svm.configure.test": { "subDir": "src", "sourceDirs": ["src"], @@ -1306,9 +1243,7 @@ "com.oracle.svm.graal", "com.oracle.svm.truffle", "com.oracle.svm.hosted", - "com.oracle.svm.hosted.jdk17", "com.oracle.svm.core", - "com.oracle.svm.core.jdk17", "com.oracle.svm.core.graal.amd64", "com.oracle.svm.core.graal.aarch64", "com.oracle.svm.core.graal.riscv64", @@ -1780,7 +1715,6 @@ "relpath" : True, "dependencies" : [ "com.oracle.svm.test", - "com.oracle.svm.test.jdk17", "com.oracle.svm.configure.test", "com.oracle.svm.graal.test", ], diff --git a/substratevm/src/com.oracle.svm.core.jdk17/src/com/oracle/svm/core/jdk17/RecordSupportJDK17OrLater.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/RecordSupportJDK17OrLater.java similarity index 100% rename from substratevm/src/com.oracle.svm.core.jdk17/src/com/oracle/svm/core/jdk17/RecordSupportJDK17OrLater.java rename to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/RecordSupportJDK17OrLater.java diff --git a/substratevm/src/com.oracle.svm.core.jdk17/src/com/oracle/svm/core/jdk17/SealedClassSupportJDK17OrLater.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/SealedClassSupportJDK17OrLater.java similarity index 100% rename from substratevm/src/com.oracle.svm.core.jdk17/src/com/oracle/svm/core/jdk17/SealedClassSupportJDK17OrLater.java rename to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/SealedClassSupportJDK17OrLater.java diff --git a/substratevm/src/com.oracle.svm.core.jdk17/src/com/oracle/svm/core/jdk17/Target_java_lang_ClassLoader_JDK17OrLater.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/Target_java_lang_ClassLoader_JDK17OrLater.java similarity index 100% rename from substratevm/src/com.oracle.svm.core.jdk17/src/com/oracle/svm/core/jdk17/Target_java_lang_ClassLoader_JDK17OrLater.java rename to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/Target_java_lang_ClassLoader_JDK17OrLater.java diff --git a/substratevm/src/com.oracle.svm.core.jdk17/src/com/oracle/svm/core/jdk17/Target_java_lang_Module_JDK17OrLater.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/Target_java_lang_Module_JDK17OrLater.java similarity index 100% rename from substratevm/src/com.oracle.svm.core.jdk17/src/com/oracle/svm/core/jdk17/Target_java_lang_Module_JDK17OrLater.java rename to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/Target_java_lang_Module_JDK17OrLater.java diff --git a/substratevm/src/com.oracle.svm.core.jdk17/src/com/oracle/svm/core/jdk17/Target_java_nio_DirectByteBuffer_JDK17.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/Target_java_nio_DirectByteBuffer_JDK17.java similarity index 100% rename from substratevm/src/com.oracle.svm.core.jdk17/src/com/oracle/svm/core/jdk17/Target_java_nio_DirectByteBuffer_JDK17.java rename to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/Target_java_nio_DirectByteBuffer_JDK17.java diff --git a/substratevm/src/com.oracle.svm.core.jdk17/src/com/oracle/svm/core/jdk17/Target_java_nio_DirectByteBuffer_JDK19OrLater.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/Target_java_nio_DirectByteBuffer_JDK19OrLater.java similarity index 100% rename from substratevm/src/com.oracle.svm.core.jdk17/src/com/oracle/svm/core/jdk17/Target_java_nio_DirectByteBuffer_JDK19OrLater.java rename to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/Target_java_nio_DirectByteBuffer_JDK19OrLater.java diff --git a/substratevm/src/com.oracle.svm.core.jdk17/src/com/oracle/svm/core/jdk17/Target_jdk_internal_loader_BootLoader_JDK17OrLater.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/Target_jdk_internal_loader_BootLoader_JDK17OrLater.java similarity index 100% rename from substratevm/src/com.oracle.svm.core.jdk17/src/com/oracle/svm/core/jdk17/Target_jdk_internal_loader_BootLoader_JDK17OrLater.java rename to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/Target_jdk_internal_loader_BootLoader_JDK17OrLater.java diff --git a/substratevm/src/com.oracle.svm.core.jdk17/src/com/oracle/svm/core/jdk17/Target_sun_nio_ch_UnixDomainSockets.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/Target_sun_nio_ch_UnixDomainSockets.java similarity index 100% rename from substratevm/src/com.oracle.svm.core.jdk17/src/com/oracle/svm/core/jdk17/Target_sun_nio_ch_UnixDomainSockets.java rename to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/Target_sun_nio_ch_UnixDomainSockets.java diff --git a/substratevm/src/com.oracle.svm.hosted.jdk17/src/com/oracle/svm/hosted/jdk17/JNIRegistrationSupport_JDK17OrLater.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk17/JNIRegistrationSupport_JDK17OrLater.java similarity index 100% rename from substratevm/src/com.oracle.svm.hosted.jdk17/src/com/oracle/svm/hosted/jdk17/JNIRegistrationSupport_JDK17OrLater.java rename to substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk17/JNIRegistrationSupport_JDK17OrLater.java diff --git a/substratevm/src/com.oracle.svm.test.jdk17/src/META-INF/native-image/com.oracle.svm.test.jdk17/reflect-config.json b/substratevm/src/com.oracle.svm.test/src/META-INF/native-image/com.oracle.svm.test.jdk17/reflect-config.json similarity index 100% rename from substratevm/src/com.oracle.svm.test.jdk17/src/META-INF/native-image/com.oracle.svm.test.jdk17/reflect-config.json rename to substratevm/src/com.oracle.svm.test/src/META-INF/native-image/com.oracle.svm.test.jdk17/reflect-config.json diff --git a/substratevm/src/com.oracle.svm.test.jdk17/src/com/oracle/svm/test/jdk17/recordannotations/F.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk17/recordannotations/F.java similarity index 100% rename from substratevm/src/com.oracle.svm.test.jdk17/src/com/oracle/svm/test/jdk17/recordannotations/F.java rename to substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk17/recordannotations/F.java diff --git a/substratevm/src/com.oracle.svm.test.jdk17/src/com/oracle/svm/test/jdk17/recordannotations/RCA.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk17/recordannotations/RCA.java similarity index 100% rename from substratevm/src/com.oracle.svm.test.jdk17/src/com/oracle/svm/test/jdk17/recordannotations/RCA.java rename to substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk17/recordannotations/RCA.java diff --git a/substratevm/src/com.oracle.svm.test.jdk17/src/com/oracle/svm/test/jdk17/recordannotations/RCA2.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk17/recordannotations/RCA2.java similarity index 100% rename from substratevm/src/com.oracle.svm.test.jdk17/src/com/oracle/svm/test/jdk17/recordannotations/RCA2.java rename to substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk17/recordannotations/RCA2.java diff --git a/substratevm/src/com.oracle.svm.test.jdk17/src/com/oracle/svm/test/jdk17/recordannotations/RecordAnnotationsTest.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk17/recordannotations/RecordAnnotationsTest.java similarity index 95% rename from substratevm/src/com.oracle.svm.test.jdk17/src/com/oracle/svm/test/jdk17/recordannotations/RecordAnnotationsTest.java rename to substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk17/recordannotations/RecordAnnotationsTest.java index 5666c8314d54..91c275a8be23 100644 --- a/substratevm/src/com.oracle.svm.test.jdk17/src/com/oracle/svm/test/jdk17/recordannotations/RecordAnnotationsTest.java +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk17/recordannotations/RecordAnnotationsTest.java @@ -61,8 +61,8 @@ public void verifyRecordAnnotations() { List stringCompAnnot = Arrays.asList(stringComp.getAnnotations()); // Checkstyle: resume Assert.assertEquals("expected 2 record annotations for string component", 2, stringCompAnnot.size()); - Assert.assertTrue("expected RCA component annotation", stringCompAnnot.stream().anyMatch(a -> a.annotationType().getName().equals("com.oracle.svm.test.jdk17.recordannotations.RCA"))); - Assert.assertTrue("expected RCA2 component annotation", stringCompAnnot.stream().anyMatch(a -> a.annotationType().getName().equals("com.oracle.svm.test.jdk17.recordannotations.RCA2"))); + Assert.assertTrue("expected RCA component annotation", stringCompAnnot.stream().anyMatch(a -> a.annotationType().getName().equals("com.oracle.svm.test.recordannotations.RCA"))); + Assert.assertTrue("expected RCA2 component annotation", stringCompAnnot.stream().anyMatch(a -> a.annotationType().getName().equals("com.oracle.svm.test.recordannotations.RCA2"))); Assert.assertEquals(String.class.getTypeName(), stringComp.getAnnotatedType().getType().getTypeName()); // Checkstyle: stop Annotation rcaAnnotation = stringComp.getAnnotation(RCA.class); @@ -76,7 +76,7 @@ public void verifyRecordAnnotations() { List intCompAnnot = Arrays.asList(intComp.getAnnotations()); // Checkstyle: resume Assert.assertEquals("expected 1 record annotation for int component", 1, intCompAnnot.size()); - Assert.assertTrue("expected RCA2 component annotation", intCompAnnot.stream().anyMatch(a -> a.annotationType().getName().equals("com.oracle.svm.test.jdk17.recordannotations.RCA2"))); + Assert.assertTrue("expected RCA2 component annotation", intCompAnnot.stream().anyMatch(a -> a.annotationType().getName().equals("com.oracle.svm.test.recordannotations.RCA2"))); Assert.assertEquals(int.class.getTypeName(), intComp.getAnnotatedType().getType().getTypeName()); // Checkstyle: stop Assert.assertNull(intComp.getAnnotation(RCA.class)); From f90c94ba062a1e915459d6b89bb829dd6e5a3282 Mon Sep 17 00:00:00 2001 From: Christian Wimmer Date: Fri, 31 Mar 2023 15:42:37 -0700 Subject: [PATCH 2/8] Remove RecordSupport --- .../oracle/svm/core/jdk/RecordSupport.java | 101 ------------------ .../src/com/oracle/svm/hosted/SVMHost.java | 3 +- .../svm/hosted/reflect/RecordUtils.java} | 25 +---- .../hosted/reflect/ReflectionDataBuilder.java | 8 +- .../serialize/SerializationFeature.java | 9 +- .../SubstrateGraphBuilderPlugins.java | 3 +- .../UnsafeAutomaticSubstitutionProcessor.java | 3 +- 7 files changed, 15 insertions(+), 137 deletions(-) delete mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/RecordSupport.java rename substratevm/src/{com.oracle.svm.core/src/com/oracle/svm/core/jdk17/RecordSupportJDK17OrLater.java => com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/RecordUtils.java} (72%) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/RecordSupport.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/RecordSupport.java deleted file mode 100644 index a2b990ab4448..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/RecordSupport.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2021, 2021, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.svm.core.jdk; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; - -import org.graalvm.nativeimage.ImageSingletons; -import org.graalvm.nativeimage.Platform; -import org.graalvm.nativeimage.Platforms; - -import com.oracle.svm.core.feature.AutomaticallyRegisteredImageSingleton; -import com.oracle.svm.core.util.VMError; - -/** - * Abstracts the information about Record classes, which are not available in Java 11 and Java 8. - * This class provides all information about Record classes without exposing any JDK types and - * methods that are not yet present in the old JDKs. - */ -@Platforms(Platform.HOSTED_ONLY.class) -public abstract class RecordSupport { - - public static RecordSupport singleton() { - return ImageSingletons.lookup(RecordSupport.class); - } - - /** Same as {@code Class.isRecord()}. */ - public abstract boolean isRecord(Class clazz); - - /** - * Same as {@code Class.getRecordComponents()}. - * - * Must only be called when {@link #isRecord} returns true. - */ - public abstract Object[] getRecordComponents(Class clazz); - - /** - * Returns the {@code RecordComponent.getAccessor} method for each of the - * {@code Class.getRecordComponents()}. - * - * Must only be called when {@link #isRecord} returns true. - */ - public abstract Method[] getRecordComponentAccessorMethods(Class clazz); - - /** - * Returns the canonical record constructor that is present in every record class and sets all - * record components. - * - * Must only be called when {@link #isRecord} returns true. - */ - public abstract Constructor getCanonicalRecordConstructor(Class clazz); -} - -/** - * Placeholder implementation for JDK versions that do not have Record classes. Since - * {@link #isRecord} always returns false, the other methods must never be invoked. - */ -@AutomaticallyRegisteredImageSingleton(value = RecordSupport.class, onlyWith = JDK11OrEarlier.class) -final class RecordSupportJDK11OrEarlier extends RecordSupport { - @Override - public boolean isRecord(Class clazz) { - return false; - } - - @Override - public Object[] getRecordComponents(Class clazz) { - throw VMError.shouldNotReachHere(); - } - - @Override - public Method[] getRecordComponentAccessorMethods(Class clazz) { - throw VMError.shouldNotReachHere(); - } - - @Override - public Constructor getCanonicalRecordConstructor(Class clazz) { - throw VMError.shouldNotReachHere(); - } -} diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java index db6bcc1090d5..9120894fcd18 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java @@ -109,7 +109,6 @@ import com.oracle.svm.core.jdk.ClassLoaderSupport; import com.oracle.svm.core.jdk.InternalVMMethod; import com.oracle.svm.core.jdk.LambdaFormHiddenMethod; -import com.oracle.svm.core.jdk.RecordSupport; import com.oracle.svm.core.jdk.SealedClassSupport; import com.oracle.svm.core.option.HostedOptionKey; import com.oracle.svm.core.option.SubstrateOptionsParser; @@ -412,7 +411,7 @@ private DynamicHub createHub(AnalysisType type) { Class nestHost = javaClass.getNestHost(); boolean isHidden = SubstrateUtil.isHiddenClass(javaClass); - boolean isRecord = RecordSupport.singleton().isRecord(javaClass); + boolean isRecord = javaClass.isRecord(); boolean assertionStatus = RuntimeAssertionsSupport.singleton().desiredAssertionStatus(javaClass); boolean isSealed = SealedClassSupport.singleton().isSealed(javaClass); boolean isVMInternal = type.isAnnotationPresent(InternalVMMethod.class); diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/RecordSupportJDK17OrLater.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/RecordUtils.java similarity index 72% rename from substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/RecordSupportJDK17OrLater.java rename to substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/RecordUtils.java index 9956715f8b1e..1cfc6093df44 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/RecordSupportJDK17OrLater.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/RecordUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2021, Oracle and/or its affiliates. All rights reserved. + * 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 @@ -22,7 +22,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package com.oracle.svm.core.jdk17; +package com.oracle.svm.hosted.reflect; import java.lang.reflect.Constructor; import java.lang.reflect.Method; @@ -30,33 +30,18 @@ import java.util.Arrays; import java.util.Objects; -import com.oracle.svm.core.jdk.JDK17OrLater; -import com.oracle.svm.core.jdk.RecordSupport; -import com.oracle.svm.core.feature.AutomaticallyRegisteredImageSingleton; import com.oracle.svm.core.util.VMError; -@AutomaticallyRegisteredImageSingleton(value = RecordSupport.class, onlyWith = JDK17OrLater.class) -final class RecordSupportJDK17OrLater extends RecordSupport { - @Override - public boolean isRecord(Class clazz) { - return clazz.isRecord(); - } - - @Override - public Object[] getRecordComponents(Class clazz) { - return clazz.getRecordComponents(); - } +public final class RecordUtils { - @Override - public Method[] getRecordComponentAccessorMethods(Class clazz) { + public static Method[] getRecordComponentAccessorMethods(Class clazz) { return Arrays.stream(clazz.getRecordComponents()) .map(RecordComponent::getAccessor) .filter(Objects::nonNull) .toArray(Method[]::new); } - @Override - public Constructor getCanonicalRecordConstructor(Class clazz) { + public static Constructor getCanonicalRecordConstructor(Class clazz) { Class[] paramTypes = Arrays.stream(clazz.getRecordComponents()) .map(RecordComponent::getType) .toArray(Class[]::new); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionDataBuilder.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionDataBuilder.java index aebdf77bede2..902e3cff9b64 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionDataBuilder.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionDataBuilder.java @@ -78,7 +78,6 @@ import com.oracle.graal.pointsto.meta.AnalysisUniverse; import com.oracle.svm.core.hub.ClassForNameSupport; import com.oracle.svm.core.hub.DynamicHub; -import com.oracle.svm.core.jdk.RecordSupport; import com.oracle.svm.core.reflect.SubstrateAccessor; import com.oracle.svm.core.util.UserError; import com.oracle.svm.core.util.VMError; @@ -349,7 +348,7 @@ private void registerMethod(boolean queriedOnly, Executable reflectExecutable) { processAnnotationMethod(queriedOnly, (Method) reflectExecutable); } - if (!throwMissingRegistrationErrors() && RecordSupport.singleton().isRecord(declaringClass)) { + if (!throwMissingRegistrationErrors() && declaringClass.isRecord()) { pendingRecordClasses.computeIfPresent(declaringClass, (clazz, unregisteredAccessors) -> { if (unregisteredAccessors.remove(reflectExecutable) && unregisteredAccessors.isEmpty()) { registerRecordComponents(declaringClass); @@ -858,8 +857,7 @@ private static T queryGenericInfo(Callable callable) { } private void maybeRegisterRecordComponents(Class clazz) { - RecordSupport support = RecordSupport.singleton(); - if (!support.isRecord(clazz)) { + if (!clazz.isRecord()) { return; } @@ -874,7 +872,7 @@ private void maybeRegisterRecordComponents(Class clazz) { * components in that case will throw an exception at image run time, see * DynamicHub.getRecordComponents0(). */ - Method[] accessors = support.getRecordComponentAccessorMethods(clazz); + Method[] accessors = RecordUtils.getRecordComponentAccessorMethods(clazz); Set unregisteredAccessors = ConcurrentHashMap.newKeySet(); for (Method accessor : accessors) { if (SubstitutionReflectivityFilter.shouldExclude(accessor, metaAccess, universe)) { diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/serialize/SerializationFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/serialize/SerializationFeature.java index bd27c6c5d242..5e156abbea25 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/serialize/SerializationFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/serialize/SerializationFeature.java @@ -78,7 +78,6 @@ import com.oracle.svm.core.configure.SerializationConfigurationParser; import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature; import com.oracle.svm.core.feature.InternalFeature; -import com.oracle.svm.core.jdk.RecordSupport; import com.oracle.svm.core.reflect.serialize.SerializationRegistry; import com.oracle.svm.core.reflect.serialize.SerializationSupport; import com.oracle.svm.core.util.UserError; @@ -90,6 +89,7 @@ import com.oracle.svm.hosted.FeatureImpl.BeforeAnalysisAccessImpl; import com.oracle.svm.hosted.ImageClassLoader; import com.oracle.svm.hosted.config.ConfigurationParserUtils; +import com.oracle.svm.hosted.reflect.RecordUtils; import com.oracle.svm.hosted.reflect.ReflectionFeature; import com.oracle.svm.hosted.reflect.proxy.DynamicProxyFeature; import com.oracle.svm.hosted.reflect.proxy.ProxyRegistry; @@ -558,17 +558,16 @@ public void afterAnalysis() { private static void registerForDeserialization(Class serializationTargetClass) { RuntimeReflection.register(serializationTargetClass); - RecordSupport recordSupport = RecordSupport.singleton(); - if (recordSupport.isRecord(serializationTargetClass)) { + if (serializationTargetClass.isRecord()) { /* Serialization for records uses the canonical record constructor directly. */ - RuntimeReflection.register(recordSupport.getCanonicalRecordConstructor(serializationTargetClass)); + RuntimeReflection.register(RecordUtils.getCanonicalRecordConstructor(serializationTargetClass)); /* * Serialization for records invokes Class.getRecordComponents(). Registering all record * component accessor methods for reflection ensures that the record components are * available at run time. */ RuntimeReflection.registerAllRecordComponents(serializationTargetClass); - RuntimeReflection.register(recordSupport.getRecordComponentAccessorMethods(serializationTargetClass)); + RuntimeReflection.register(RecordUtils.getRecordComponentAccessorMethods(serializationTargetClass)); } else if (Externalizable.class.isAssignableFrom(serializationTargetClass)) { Optional.ofNullable(ReflectionUtil.lookupConstructor(true, serializationTargetClass, (Class[]) null)) .ifPresent(RuntimeReflection::register); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/snippets/SubstrateGraphBuilderPlugins.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/snippets/SubstrateGraphBuilderPlugins.java index 43e385d3fa83..b0899fd2ec32 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/snippets/SubstrateGraphBuilderPlugins.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/snippets/SubstrateGraphBuilderPlugins.java @@ -144,7 +144,6 @@ import com.oracle.svm.core.heap.ReferenceAccessImpl; import com.oracle.svm.core.hub.DynamicHub; import com.oracle.svm.core.identityhashcode.SubstrateIdentityHashCodeNode; -import com.oracle.svm.core.jdk.RecordSupport; import com.oracle.svm.core.jdk.proxy.DynamicProxyRegistry; import com.oracle.svm.core.meta.SharedField; import com.oracle.svm.core.meta.SharedMethod; @@ -887,7 +886,7 @@ private static boolean isValidField(Field targetField, boolean isSunMiscUnsafe) return false; } if (isSunMiscUnsafe && JavaVersionUtil.JAVA_SPEC >= 17 && - (RecordSupport.singleton().isRecord(targetField.getDeclaringClass()) || SubstrateUtil.isHiddenClass(targetField.getDeclaringClass()))) { + (targetField.getDeclaringClass().isRecord() || SubstrateUtil.isHiddenClass(targetField.getDeclaringClass()))) { /* * After JDK 11, sun.misc.Unsafe performs a few more checks than * jdk.internal.misc.Unsafe to explicitly disallow hidden classes and records. diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/UnsafeAutomaticSubstitutionProcessor.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/UnsafeAutomaticSubstitutionProcessor.java index edc794ad80d9..72c8353147be 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/UnsafeAutomaticSubstitutionProcessor.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/UnsafeAutomaticSubstitutionProcessor.java @@ -85,7 +85,6 @@ import com.oracle.svm.core.annotate.RecomputeFieldValue.Kind; import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature; import com.oracle.svm.core.feature.InternalFeature; -import com.oracle.svm.core.jdk.RecordSupport; import com.oracle.svm.core.option.HostedOptionKey; import com.oracle.svm.core.util.VMError; import com.oracle.svm.hosted.FallbackFeature; @@ -485,7 +484,7 @@ private boolean isValidField(Invoke invoke, Field field, List> boolean valid = true; if (JavaVersionUtil.JAVA_SPEC >= 17 && isInvokeTo(invoke, sunMiscUnsafeObjectFieldOffsetMethod)) { Class declaringClass = field.getDeclaringClass(); - if (RecordSupport.singleton().isRecord(declaringClass)) { + if (declaringClass.isRecord()) { unsuccessfulReasons.add(() -> "The argument to " + methodFormat + " is a field of a record."); valid = false; } From 782c9b39a4beacf305b410fc9c1c75a2989f8b1e Mon Sep 17 00:00:00 2001 From: Christian Wimmer Date: Fri, 31 Mar 2023 15:47:23 -0700 Subject: [PATCH 3/8] Remove SealedClassSupport --- .../svm/core/jdk/SealedClassSupport.java | 67 ------------------- .../jdk17/SealedClassSupportJDK17OrLater.java | 43 ------------ .../src/com/oracle/svm/hosted/SVMHost.java | 3 +- 3 files changed, 1 insertion(+), 112 deletions(-) delete mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/SealedClassSupport.java delete mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/SealedClassSupportJDK17OrLater.java diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/SealedClassSupport.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/SealedClassSupport.java deleted file mode 100644 index bf358836aaf2..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/SealedClassSupport.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2021, 2021, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.svm.core.jdk; - -import org.graalvm.nativeimage.ImageSingletons; -import org.graalvm.nativeimage.Platform; -import org.graalvm.nativeimage.Platforms; - -import com.oracle.svm.core.feature.AutomaticallyRegisteredImageSingleton; - -/** - * Abstracts the information about sealed classes, which are not available in Java 11 and Java 8. - * This class provides all information about sealed classes without exposing any JDK types and - * methods that are not yet present in the old JDKs. - */ -@Platforms(Platform.HOSTED_ONLY.class) -public abstract class SealedClassSupport { - - public static SealedClassSupport singleton() { - return ImageSingletons.lookup(SealedClassSupport.class); - } - - /** Same as {@code Class.isSealed()}. */ - public abstract boolean isSealed(Class clazz); - - /** Same as {@code Class.getPermittedSubclasses()}. */ - public abstract Class[] getPermittedSubclasses(Class clazz); -} - -/** - * Placeholder implementation for JDK versions that do not have sealed classes. - */ -@AutomaticallyRegisteredImageSingleton(value = SealedClassSupport.class, onlyWith = JDK11OrEarlier.class) -final class SealedClassSupportJDK11OrEarlier extends SealedClassSupport { - - @Override - public boolean isSealed(Class clazz) { - return false; - } - - @Override - public Class[] getPermittedSubclasses(Class clazz) { - return null; - } -} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/SealedClassSupportJDK17OrLater.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/SealedClassSupportJDK17OrLater.java deleted file mode 100644 index b8d4dfef0c90..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/SealedClassSupportJDK17OrLater.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2021, 2021, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.svm.core.jdk17; - -import com.oracle.svm.core.jdk.JDK17OrLater; -import com.oracle.svm.core.jdk.SealedClassSupport; -import com.oracle.svm.core.feature.AutomaticallyRegisteredImageSingleton; - -@AutomaticallyRegisteredImageSingleton(value = SealedClassSupport.class, onlyWith = JDK17OrLater.class) -final class SealedClassSupportJDK17OrLater extends SealedClassSupport { - - @Override - public boolean isSealed(Class clazz) { - return clazz.isSealed(); - } - - @Override - public Class[] getPermittedSubclasses(Class clazz) { - return clazz.getPermittedSubclasses(); - } -} diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java index 9120894fcd18..c0f7194812e0 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java @@ -109,7 +109,6 @@ import com.oracle.svm.core.jdk.ClassLoaderSupport; import com.oracle.svm.core.jdk.InternalVMMethod; import com.oracle.svm.core.jdk.LambdaFormHiddenMethod; -import com.oracle.svm.core.jdk.SealedClassSupport; import com.oracle.svm.core.option.HostedOptionKey; import com.oracle.svm.core.option.SubstrateOptionsParser; import com.oracle.svm.core.thread.Continuation; @@ -413,7 +412,7 @@ private DynamicHub createHub(AnalysisType type) { boolean isHidden = SubstrateUtil.isHiddenClass(javaClass); boolean isRecord = javaClass.isRecord(); boolean assertionStatus = RuntimeAssertionsSupport.singleton().desiredAssertionStatus(javaClass); - boolean isSealed = SealedClassSupport.singleton().isSealed(javaClass); + boolean isSealed = javaClass.isSealed(); boolean isVMInternal = type.isAnnotationPresent(InternalVMMethod.class); boolean isLambdaFormHidden = type.isAnnotationPresent(LambdaFormHiddenMethod.class); From a8a55a4178bd118d1b6410a5708ec475c4c90020 Mon Sep 17 00:00:00 2001 From: Christian Wimmer Date: Fri, 31 Mar 2023 16:40:40 -0700 Subject: [PATCH 4/8] Move substitutions --- .../svm/core/jdk/JavaLangSubstitutions.java | 6 +++ .../jdk/Target_java_lang_ClassLoader.java | 24 +++++---- .../svm/core/jdk/Target_java_lang_Module.java | 14 ++++-- ..._jdk_internal_loader_NativeLibraries.java} | 48 +++--------------- ...et_jdk_internal_loader_NativeLibrary.java} | 17 +++---- .../Target_sun_nio_ch_UnixDomainSockets.java | 2 +- .../Target_sun_nio_ch_Util_JDK17.java} | 9 ++-- .../Target_sun_nio_ch_Util_JDK19OrLater.java} | 5 +- .../Target_java_lang_Module_JDK17OrLater.java | 49 ------------------- 9 files changed, 50 insertions(+), 124 deletions(-) rename substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/{jdk17/Target_java_lang_ClassLoader_JDK17OrLater.java => jdk/Target_jdk_internal_loader_NativeLibraries.java} (66%) rename substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/{jdk17/Target_jdk_internal_loader_BootLoader_JDK17OrLater.java => jdk/Target_jdk_internal_loader_NativeLibrary.java} (74%) rename substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/{jdk17 => jdk}/Target_sun_nio_ch_UnixDomainSockets.java (98%) rename substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/{jdk17/Target_java_nio_DirectByteBuffer_JDK17.java => jdk/Target_sun_nio_ch_Util_JDK17.java} (93%) rename substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/{jdk17/Target_java_nio_DirectByteBuffer_JDK19OrLater.java => jdk/Target_sun_nio_ch_Util_JDK19OrLater.java} (95%) delete mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/Target_java_lang_Module_JDK17OrLater.java 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 0ec974eef205..e8f57d92ee40 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 @@ -776,6 +776,12 @@ private static Class loadClass(Module module, String name) { return ClassForNameSupport.forNameOrNull(name, null); } + @SuppressWarnings("unused") + @Substitute + private static void loadLibrary(String name) { + System.loadLibrary(name); + } + @Substitute private static boolean hasClassPath() { return true; diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_ClassLoader.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_ClassLoader.java index 0a52dfaba20a..88337a29d33f 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_ClassLoader.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_ClassLoader.java @@ -36,7 +36,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Stream; -import jdk.internal.loader.ClassLoaderValue; import org.graalvm.nativeimage.hosted.FieldValueTransformer; import com.oracle.svm.core.SubstrateUtil; @@ -52,6 +51,9 @@ import com.oracle.svm.core.util.LazyFinalReference; import com.oracle.svm.core.util.VMError; +import jdk.internal.loader.ClassLoaderValue; +import jdk.internal.loader.NativeLibrary; + @TargetClass(className = "jdk.internal.loader.Resource") @SuppressWarnings("unused") final class Target_jdk_internal_loader_Resource { @@ -117,15 +119,17 @@ public static InputStream getSystemResourceAsStream(String name) { } @Substitute - @SuppressWarnings("unused") - @TargetElement(onlyWith = JDK11OrEarlier.class) // - /* Substitution for JDK 17 and later is in Target_java_lang_ClassLoader_JDK17OrLater. */ - static void loadLibrary(Class fromClass, String name, boolean isAbsolute) { - if (isAbsolute) { - NativeLibrarySupport.singleton().loadLibraryAbsolute(new File(name)); - } else { - NativeLibrarySupport.singleton().loadLibraryRelative(name); - } + static NativeLibrary loadLibrary(Class fromClass, String name) { + NativeLibrarySupport.singleton().loadLibraryRelative(name); + // We don't use the JDK's NativeLibraries or NativeLibrary implementations + return null; + } + + @Substitute + static NativeLibrary loadLibrary(Class fromClass, File file) { + NativeLibrarySupport.singleton().loadLibraryAbsolute(file); + // We don't use the JDK's NativeLibraries or NativeLibrary implementations + return null; } @Substitute diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_Module.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_Module.java index d059895c071e..2d28998c8506 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_Module.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_Module.java @@ -27,12 +27,13 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; import java.util.Arrays; +import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; import com.oracle.svm.core.SubstrateUtil; 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.resources.ResourceStorageEntry; @SuppressWarnings("unused") @@ -50,10 +51,13 @@ private InputStream getResourceAsStream(String resourceName) { return res == null ? null : new ByteArrayInputStream(res.getData().get(0)); } - @Substitute // - @TargetElement(onlyWith = JDK11OrEarlier.class) - private static void defineModule0(Module module, boolean isOpen, String version, String location, String[] pns) { - ModuleUtil.defineModule(module, isOpen, Arrays.asList(pns)); + @Substitute + private static void defineModule0(Module module, boolean isOpen, String version, String location, Object[] pns) { + if (Arrays.stream(pns).anyMatch(Objects::isNull)) { + throw new IllegalArgumentException("Bad package name"); + } + List packages = Arrays.stream(pns).map(Object::toString).collect(Collectors.toUnmodifiableList()); + ModuleUtil.defineModule(module, isOpen, packages); } @Substitute diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/Target_java_lang_ClassLoader_JDK17OrLater.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_loader_NativeLibraries.java similarity index 66% rename from substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/Target_java_lang_ClassLoader_JDK17OrLater.java rename to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_loader_NativeLibraries.java index 95eca2003d11..6a5649954737 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/Target_java_lang_ClassLoader_JDK17OrLater.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_loader_NativeLibraries.java @@ -22,9 +22,8 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package com.oracle.svm.core.jdk17; +package com.oracle.svm.core.jdk; -import java.io.File; import java.util.Deque; import java.util.Map; import java.util.Set; @@ -33,35 +32,11 @@ 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.JDK17OrLater; -import com.oracle.svm.core.jdk.JDK19OrLater; -import com.oracle.svm.core.jdk.NativeLibrarySupport; import jdk.internal.loader.NativeLibraries; -import jdk.internal.loader.NativeLibrary; -@TargetClass(value = ClassLoader.class, onlyWith = JDK17OrLater.class) -@SuppressWarnings({"static-method", "unused"}) -final class Target_java_lang_ClassLoader_JDK17OrLater { - - @Substitute - static NativeLibrary loadLibrary(Class fromClass, String name) { - NativeLibrarySupport.singleton().loadLibraryRelative(name); - // We don't use the JDK's NativeLibraries or NativeLibrary implementations - return null; - } - - @Substitute - static NativeLibrary loadLibrary(Class fromClass, File file) { - NativeLibrarySupport.singleton().loadLibraryAbsolute(file); - // We don't use the JDK's NativeLibraries or NativeLibrary implementations - return null; - } -} - -@TargetClass(value = jdk.internal.loader.NativeLibraries.class, onlyWith = JDK17OrLater.class) -final class Target_jdk_internal_loader_NativeLibraries_JDK17OrLater { +@TargetClass(value = jdk.internal.loader.NativeLibraries.class) +final class Target_jdk_internal_loader_NativeLibraries { /** * The NativeLibraries is only used by the `loadLibrary` methods that are substituted, so we do @@ -117,20 +92,9 @@ public static NativeLibraries newInstance(ClassLoader loader) { @Delete// @TargetElement(onlyWith = JDK17OrEarlier.class) - private static native long findEntry0(Target_jdk_internal_loader_NativeLibraries_NativeLibraryImpl_JDK17OrLater lib, String name); -} - -@TargetClass(value = jdk.internal.loader.NativeLibrary.class, onlyWith = JDK19OrLater.class) -final class Target_jdk_internal_loader_NativeLibrary_JDK19OrLater { - @Delete - private static native long findEntry0(long handle, String name); -} - -@TargetClass(value = jdk.internal.loader.NativeLibraries.class, innerClass = "NativeLibraryImpl", onlyWith = JDK17OrLater.class) -final class Target_jdk_internal_loader_NativeLibraries_NativeLibraryImpl_JDK17OrLater { + private static native long findEntry0(Target_jdk_internal_loader_NativeLibraries_NativeLibraryImpl lib, String name); } -@Delete// -@TargetClass(value = jdk.internal.loader.NativeLibraries.class, innerClass = "NativeLibraryContext", onlyWith = JDK19OrLater.class) -final class Target_jdk_internal_loader_NativeLibraries_NativeLibraryContext_JDK19OrLater { +@TargetClass(value = jdk.internal.loader.NativeLibraries.class, innerClass = "NativeLibraryImpl") +final class Target_jdk_internal_loader_NativeLibraries_NativeLibraryImpl { } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/Target_jdk_internal_loader_BootLoader_JDK17OrLater.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_loader_NativeLibrary.java similarity index 74% rename from substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/Target_jdk_internal_loader_BootLoader_JDK17OrLater.java rename to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_loader_NativeLibrary.java index b44b604085b7..d42d47e544c1 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/Target_jdk_internal_loader_BootLoader_JDK17OrLater.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_loader_NativeLibrary.java @@ -22,18 +22,13 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package com.oracle.svm.core.jdk17; +package com.oracle.svm.core.jdk; -import com.oracle.svm.core.annotate.Substitute; +import com.oracle.svm.core.annotate.Delete; import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.jdk.JDK17OrLater; -@TargetClass(className = "jdk.internal.loader.BootLoader", onlyWith = JDK17OrLater.class) -final class Target_jdk_internal_loader_BootLoader_JDK17OrLater { - - @SuppressWarnings("unused") - @Substitute - private static void loadLibrary(String name) { - System.loadLibrary(name); - } +@TargetClass(value = jdk.internal.loader.NativeLibrary.class, onlyWith = JDK19OrLater.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/jdk17/Target_sun_nio_ch_UnixDomainSockets.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_sun_nio_ch_UnixDomainSockets.java similarity index 98% rename from substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/Target_sun_nio_ch_UnixDomainSockets.java rename to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_sun_nio_ch_UnixDomainSockets.java index 73aaf5020901..4b498aa69b0f 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/Target_sun_nio_ch_UnixDomainSockets.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_sun_nio_ch_UnixDomainSockets.java @@ -22,7 +22,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package com.oracle.svm.core.jdk17; +package com.oracle.svm.core.jdk; import com.oracle.svm.core.annotate.Alias; import com.oracle.svm.core.annotate.RecomputeFieldValue; diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/Target_java_nio_DirectByteBuffer_JDK17.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_sun_nio_ch_Util_JDK17.java similarity index 93% rename from substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/Target_java_nio_DirectByteBuffer_JDK17.java rename to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_sun_nio_ch_Util_JDK17.java index 4440f01eea49..fddd493465c4 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/Target_java_nio_DirectByteBuffer_JDK17.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_sun_nio_ch_Util_JDK17.java @@ -22,15 +22,18 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package com.oracle.svm.core.jdk17; +package com.oracle.svm.core.jdk; import java.io.FileDescriptor; import com.oracle.svm.core.annotate.Alias; import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.jdk.JDK17OrEarlier; -import com.oracle.svm.core.jdk.JDK17OrLater; + +/* + * 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 = {JDK17OrLater.class, JDK17OrEarlier.class}) @SuppressWarnings("unused") diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/Target_java_nio_DirectByteBuffer_JDK19OrLater.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_sun_nio_ch_Util_JDK19OrLater.java similarity index 95% rename from substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/Target_java_nio_DirectByteBuffer_JDK19OrLater.java rename to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_sun_nio_ch_Util_JDK19OrLater.java index 1b5df9894b48..4ec35595d2d8 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/Target_java_nio_DirectByteBuffer_JDK19OrLater.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_sun_nio_ch_Util_JDK19OrLater.java @@ -22,14 +22,13 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package com.oracle.svm.core.jdk17; +package com.oracle.svm.core.jdk; import java.io.FileDescriptor; import com.oracle.svm.core.annotate.Alias; import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.jdk.JDK19OrLater; @TargetClass(className = "java.lang.foreign.MemorySegment", onlyWith = JDK19OrLater.class) @SuppressWarnings("unused") @@ -59,7 +58,7 @@ protected Target_java_nio_DirectByteBufferR_JDK19OrLater(int cap, long addr, Fil } @TargetClass(className = "sun.nio.ch.Util", onlyWith = JDK19OrLater.class) -final class Target_sun_nio_ch_Util_JDK17OrLater { +final class Target_sun_nio_ch_Util_JDK19OrLater { @Substitute private static Target_java_nio_DirectByteBuffer_JDK19OrLater newMappedByteBuffer(int size, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync) { diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/Target_java_lang_Module_JDK17OrLater.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/Target_java_lang_Module_JDK17OrLater.java deleted file mode 100644 index 7287502f7845..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk17/Target_java_lang_Module_JDK17OrLater.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2021, 2021, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.svm.core.jdk17; - -import java.util.Arrays; -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; - -import com.oracle.svm.core.annotate.Substitute; -import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.jdk.JDK17OrLater; -import com.oracle.svm.core.jdk.ModuleUtil; - -@SuppressWarnings("unused") -@TargetClass(value = java.lang.Module.class, onlyWith = JDK17OrLater.class) -public final class Target_java_lang_Module_JDK17OrLater { - - @Substitute - private static void defineModule0(Module module, boolean isOpen, String version, String location, Object[] pns) { - if (Arrays.stream(pns).anyMatch(Objects::isNull)) { - throw new IllegalArgumentException("Bad package name"); - } - List packages = Arrays.stream(pns).map(Object::toString).collect(Collectors.toUnmodifiableList()); - ModuleUtil.defineModule(module, isOpen, packages); - } -} From d34888a8f0999b7fcbd0bb7fd14d030a43a92841 Mon Sep 17 00:00:00 2001 From: Christian Wimmer Date: Fri, 31 Mar 2023 16:14:24 -0700 Subject: [PATCH 5/8] Hosted code --- .../hosted/jdk/JNIRegistrationSupport.java | 2 + .../JNIRegistrationSupport_JDK17OrLater.java | 56 ------------------- 2 files changed, 2 insertions(+), 56 deletions(-) delete mode 100644 substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk17/JNIRegistrationSupport_JDK17OrLater.java diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationSupport.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationSupport.java index e05a873a6b90..949da049dd2b 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationSupport.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationSupport.java @@ -73,6 +73,7 @@ import com.oracle.svm.hosted.c.codegen.CCompilerInvoker; import com.oracle.svm.hosted.c.util.FileUtils; +import jdk.internal.loader.BootLoader; import jdk.vm.ci.meta.ResolvedJavaMethod; /** Registration of native JDK libraries. */ @@ -108,6 +109,7 @@ public void afterAnalysis(AfterAnalysisAccess access) { @Override public void registerGraphBuilderPlugins(Providers providers, Plugins plugins, ParsingReason reason) { registerLoadLibraryPlugin(providers, plugins, System.class); + registerLoadLibraryPlugin(providers, plugins, BootLoader.class); } public void registerLoadLibraryPlugin(Providers providers, Plugins plugins, Class clazz) { diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk17/JNIRegistrationSupport_JDK17OrLater.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk17/JNIRegistrationSupport_JDK17OrLater.java deleted file mode 100644 index 95a2e9b72cc7..000000000000 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk17/JNIRegistrationSupport_JDK17OrLater.java +++ /dev/null @@ -1,56 +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.hosted.jdk17; - -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.Platforms; -import org.graalvm.nativeimage.impl.InternalPlatform; - -import com.oracle.svm.core.ParsingReason; -import com.oracle.svm.core.feature.InternalFeature; -import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature; -import com.oracle.svm.hosted.jdk.JNIRegistrationSupport; - -import jdk.internal.loader.BootLoader; - -/** - * Registration of native JDK libraries for JDK 17 and later that are loaded via - * jdk.internal.loader.BootLoader - */ -@Platforms(InternalPlatform.PLATFORM_JNI.class) -@AutomaticallyRegisteredFeature -final class JNIRegistrationSupport_JDK17OrLater implements InternalFeature { - @Override - public boolean isInConfiguration(IsInConfigurationAccess access) { - return JavaVersionUtil.JAVA_SPEC >= 17; - } - - @Override - public void registerGraphBuilderPlugins(Providers providers, Plugins plugins, ParsingReason reason) { - JNIRegistrationSupport.singleton().registerLoadLibraryPlugin(providers, plugins, BootLoader.class); - } -} From a26dbde978bc5882fc6b0d35f59be12e54e97235 Mon Sep 17 00:00:00 2001 From: Christian Wimmer Date: Fri, 31 Mar 2023 16:44:59 -0700 Subject: [PATCH 6/8] Package rename for tests --- .../{com.oracle.svm.test.jdk17 => }/reflect-config.json | 2 +- .../oracle/svm/test/{jdk17 => }/recordannotations/F.java | 2 +- .../oracle/svm/test/{jdk17 => }/recordannotations/RCA.java | 6 +++--- .../oracle/svm/test/{jdk17 => }/recordannotations/RCA2.java | 6 +++--- .../recordannotations/RecordAnnotationsTest.java | 3 ++- 5 files changed, 10 insertions(+), 9 deletions(-) rename substratevm/src/com.oracle.svm.test/src/META-INF/native-image/{com.oracle.svm.test.jdk17 => }/reflect-config.json (77%) rename substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/{jdk17 => }/recordannotations/F.java (96%) rename substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/{jdk17 => }/recordannotations/RCA.java (96%) rename substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/{jdk17 => }/recordannotations/RCA2.java (96%) rename substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/{jdk17 => }/recordannotations/RecordAnnotationsTest.java (98%) diff --git a/substratevm/src/com.oracle.svm.test/src/META-INF/native-image/com.oracle.svm.test.jdk17/reflect-config.json b/substratevm/src/com.oracle.svm.test/src/META-INF/native-image/reflect-config.json similarity index 77% rename from substratevm/src/com.oracle.svm.test/src/META-INF/native-image/com.oracle.svm.test.jdk17/reflect-config.json rename to substratevm/src/com.oracle.svm.test/src/META-INF/native-image/reflect-config.json index 4cff54a9803e..9d0a8eb93355 100644 --- a/substratevm/src/com.oracle.svm.test/src/META-INF/native-image/com.oracle.svm.test.jdk17/reflect-config.json +++ b/substratevm/src/com.oracle.svm.test/src/META-INF/native-image/reflect-config.json @@ -1,6 +1,6 @@ [ { - "name" : "com.oracle.svm.test.jdk17.recordannotations.F", + "name" : "com.oracle.svm.test.recordannotations.F", "allDeclaredConstructors" : true, "allPublicConstructors" : true, "allDeclaredMethods" : true, diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk17/recordannotations/F.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/recordannotations/F.java similarity index 96% rename from substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk17/recordannotations/F.java rename to substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/recordannotations/F.java index 07159409c9e6..408bf777fd96 100644 --- a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk17/recordannotations/F.java +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/recordannotations/F.java @@ -23,7 +23,7 @@ * questions. */ -package com.oracle.svm.test.jdk17.recordannotations; +package com.oracle.svm.test.recordannotations; // Main record under test. See Main. @RCA2 diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk17/recordannotations/RCA.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/recordannotations/RCA.java similarity index 96% rename from substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk17/recordannotations/RCA.java rename to substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/recordannotations/RCA.java index 536d62dee057..b21961b37193 100644 --- a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk17/recordannotations/RCA.java +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/recordannotations/RCA.java @@ -23,12 +23,12 @@ * questions. */ -package com.oracle.svm.test.jdk17.recordannotations; +package com.oracle.svm.test.recordannotations; -import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.ElementType; import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import java.lang.annotation.ElementType; @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.RECORD_COMPONENT, ElementType.FIELD}) diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk17/recordannotations/RCA2.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/recordannotations/RCA2.java similarity index 96% rename from substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk17/recordannotations/RCA2.java rename to substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/recordannotations/RCA2.java index 81d05f21cb8f..13bddc11fc31 100644 --- a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk17/recordannotations/RCA2.java +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/recordannotations/RCA2.java @@ -23,12 +23,12 @@ * questions. */ -package com.oracle.svm.test.jdk17.recordannotations; +package com.oracle.svm.test.recordannotations; -import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.ElementType; import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import java.lang.annotation.ElementType; @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.RECORD_COMPONENT, ElementType.FIELD, ElementType.TYPE}) diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk17/recordannotations/RecordAnnotationsTest.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/recordannotations/RecordAnnotationsTest.java similarity index 98% rename from substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk17/recordannotations/RecordAnnotationsTest.java rename to substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/recordannotations/RecordAnnotationsTest.java index 91c275a8be23..43023988cdea 100644 --- a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk17/recordannotations/RecordAnnotationsTest.java +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/recordannotations/RecordAnnotationsTest.java @@ -23,12 +23,13 @@ * questions. */ -package com.oracle.svm.test.jdk17.recordannotations; +package com.oracle.svm.test.recordannotations; import java.lang.annotation.Annotation; import java.lang.reflect.RecordComponent; import java.util.Arrays; import java.util.List; + import org.junit.Assert; import org.junit.Test; From bea56bf4028b57b28fb5c274aca79b85a390259f Mon Sep 17 00:00:00 2001 From: Christian Wimmer Date: Fri, 31 Mar 2023 16:49:56 -0700 Subject: [PATCH 7/8] Remove SubstateUtil.isHiddenClass --- .../com/oracle/svm/core/SubstrateUtil.java | 25 ------------------- .../svm/core/jfr/JfrTypeRepository.java | 3 +-- .../src/com/oracle/svm/hosted/SVMHost.java | 3 +-- .../SubstrateGraphBuilderPlugins.java | 9 +++---- .../UnsafeAutomaticSubstitutionProcessor.java | 3 +-- 5 files changed, 6 insertions(+), 37 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateUtil.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateUtil.java index b25e942309eb..1c606e57f13f 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateUtil.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateUtil.java @@ -27,9 +27,7 @@ import java.io.FileDescriptor; import java.io.FileOutputStream; import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Member; -import java.lang.reflect.Method; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -37,7 +35,6 @@ import org.graalvm.compiler.graph.Node.NodeIntrinsic; import org.graalvm.compiler.java.LambdaUtils; import org.graalvm.compiler.nodes.BreakpointNode; -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.c.type.CCharPointer; @@ -51,7 +48,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.hub.DynamicHub; import com.oracle.svm.core.util.VMError; import com.oracle.svm.util.ReflectionUtil; import com.oracle.svm.util.StringUtil; @@ -395,27 +391,6 @@ public static String mangleName(String methodName) { return mangled; } - private static final Method isHiddenMethod = JavaVersionUtil.JAVA_SPEC >= 17 ? ReflectionUtil.lookupMethod(Class.class, "isHidden") : null; - - public static boolean isHiddenClass(Class javaClass) { - if (JavaVersionUtil.JAVA_SPEC >= 17) { - try { - return (boolean) isHiddenMethod.invoke(javaClass); - } catch (IllegalAccessException | InvocationTargetException e) { - throw VMError.shouldNotReachHere(e); - } - } - return false; - } - - @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) - public static boolean isHiddenClass(DynamicHub hub) { - if (JavaVersionUtil.JAVA_SPEC >= 17) { - return hub.isHidden(); - } - return false; - } - public static int arrayTypeDimension(Class clazz) { int dimension = 0; Class componentType = clazz; diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrTypeRepository.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrTypeRepository.java index a4fef326bb93..00fcac8684e4 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrTypeRepository.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrTypeRepository.java @@ -33,7 +33,6 @@ import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; -import com.oracle.svm.core.SubstrateUtil; import com.oracle.svm.core.Uninterruptible; import com.oracle.svm.core.heap.Heap; import com.oracle.svm.core.jfr.traceid.JfrTraceId; @@ -150,7 +149,7 @@ private void writeClass(TypeInfo typeInfo, JfrChunkWriter writer, Class clazz writer.writeCompressedLong(getPackageId(typeInfo, clazz.getPackage())); writer.writeCompressedLong(clazz.getModifiers()); if (JavaVersionUtil.JAVA_SPEC >= 17) { - writer.writeBoolean(SubstrateUtil.isHiddenClass(clazz)); + writer.writeBoolean(clazz.isHidden()); } } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java index c0f7194812e0..4fcfbe9aedb9 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java @@ -92,7 +92,6 @@ import com.oracle.svm.core.RuntimeAssertionsSupport; import com.oracle.svm.core.SubstrateOptions; import com.oracle.svm.core.SubstrateOptions.OptimizationLevel; -import com.oracle.svm.core.SubstrateUtil; import com.oracle.svm.core.classinitialization.EnsureClassInitializedNode; import com.oracle.svm.core.graal.meta.SubstrateForeignCallLinkage; import com.oracle.svm.core.graal.meta.SubstrateForeignCallsProvider; @@ -409,7 +408,7 @@ private DynamicHub createHub(AnalysisType type) { String simpleBinaryName = stringTable.deduplicate(getSimpleBinaryName(javaClass), true); Class nestHost = javaClass.getNestHost(); - boolean isHidden = SubstrateUtil.isHiddenClass(javaClass); + boolean isHidden = javaClass.isHidden(); boolean isRecord = javaClass.isRecord(); boolean assertionStatus = RuntimeAssertionsSupport.singleton().desiredAssertionStatus(javaClass); boolean isSealed = javaClass.isSealed(); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/snippets/SubstrateGraphBuilderPlugins.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/snippets/SubstrateGraphBuilderPlugins.java index b0899fd2ec32..8f80b102f382 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/snippets/SubstrateGraphBuilderPlugins.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/snippets/SubstrateGraphBuilderPlugins.java @@ -93,7 +93,6 @@ import org.graalvm.compiler.replacements.nodes.CipherBlockChainingAESNode; import org.graalvm.compiler.replacements.nodes.CounterModeAESNode; import org.graalvm.compiler.replacements.nodes.MacroNode.MacroParams; -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.compiler.word.WordCastNode; import org.graalvm.nativeimage.AnnotationAccess; import org.graalvm.nativeimage.ImageInfo; @@ -123,7 +122,6 @@ import com.oracle.svm.core.RuntimeAssertionsSupport; import com.oracle.svm.core.StaticFieldsSupport; import com.oracle.svm.core.SubstrateOptions; -import com.oracle.svm.core.SubstrateUtil; import com.oracle.svm.core.classinitialization.EnsureClassInitializedNode; import com.oracle.svm.core.config.ConfigurationValues; import com.oracle.svm.core.graal.GraalEdgeUnsafePartition; @@ -885,11 +883,10 @@ private static boolean isValidField(Field targetField, boolean isSunMiscUnsafe) /* A NullPointerException will be thrown at run time for this call. */ return false; } - if (isSunMiscUnsafe && JavaVersionUtil.JAVA_SPEC >= 17 && - (targetField.getDeclaringClass().isRecord() || SubstrateUtil.isHiddenClass(targetField.getDeclaringClass()))) { + if (isSunMiscUnsafe && (targetField.getDeclaringClass().isRecord() || targetField.getDeclaringClass().isHidden())) { /* - * After JDK 11, sun.misc.Unsafe performs a few more checks than - * jdk.internal.misc.Unsafe to explicitly disallow hidden classes and records. + * sun.misc.Unsafe performs a few more checks than jdk.internal.misc.Unsafe to + * explicitly disallow hidden classes and records. */ return false; } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/UnsafeAutomaticSubstitutionProcessor.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/UnsafeAutomaticSubstitutionProcessor.java index 72c8353147be..039a7a052188 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/UnsafeAutomaticSubstitutionProcessor.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/UnsafeAutomaticSubstitutionProcessor.java @@ -80,7 +80,6 @@ import com.oracle.graal.pointsto.phases.NoClassInitializationPlugin; import com.oracle.graal.pointsto.util.GraalAccess; import com.oracle.svm.core.ParsingReason; -import com.oracle.svm.core.SubstrateUtil; import com.oracle.svm.core.annotate.RecomputeFieldValue; import com.oracle.svm.core.annotate.RecomputeFieldValue.Kind; import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature; @@ -488,7 +487,7 @@ private boolean isValidField(Invoke invoke, Field field, List> unsuccessfulReasons.add(() -> "The argument to " + methodFormat + " is a field of a record."); valid = false; } - if (SubstrateUtil.isHiddenClass(declaringClass)) { + if (declaringClass.isHidden()) { unsuccessfulReasons.add(() -> "The argument to " + methodFormat + " is a field of a hidden class."); valid = false; } From c8d7ce02ebd5176a9b7c5ad44982212c2487b9e8 Mon Sep 17 00:00:00 2001 From: Christian Wimmer Date: Fri, 31 Mar 2023 17:15:58 -0700 Subject: [PATCH 8/8] Remove JDK11OrEarlier substitutions --- .../heap/Target_jdk_internal_ref_Cleaner.java | 49 ------------ .../com/oracle/svm/core/hub/DynamicHub.java | 17 ---- .../oracle/svm/core/jdk/JDK11OrEarlier.java | 1 + .../svm/core/jdk/JavaLangSubstitutions.java | 6 -- .../oracle/svm/core/jdk/Load0With2Args.java | 49 ------------ .../oracle/svm/core/jdk/Load0With3Args.java | 49 ------------ .../oracle/svm/core/jdk/RecomputedFields.java | 28 ------- .../svm/core/jdk/SecuritySubstitutions.java | 58 -------------- .../svm/core/jdk/SunMiscSubstitutions.java | 24 ------ .../svm/core/jdk/SunNioSubstitutions.java | 28 +------ .../jdk/Target_java_lang_ClassLoader.java | 79 +------------------ ...k_internal_module_IllegalAccessLogger.java | 50 ------------ ...jdk_nashorn_api_scripting_ClassFilter.java | 32 -------- ..._scripting_NashornScriptEngineFactory.java | 56 ------------- .../core/jdk/ThreadLocalRandomAccessors.java | 14 +--- ...rviceProviderPool_OptimizedLocaleMode.java | 6 -- .../core/jfr/Target_jdk_jfr_internal_JVM.java | 29 ------- .../MethodHandleIntrinsicImpl.java | 2 +- .../Target_java_lang_invoke_MethodHandle.java | 2 +- ..._java_lang_invoke_MethodHandleNatives.java | 15 +--- .../target/ReflectionMetadataDecoderImpl.java | 12 +-- ...et_java_lang_reflect_AccessibleObject.java | 8 -- .../Target_java_lang_reflect_Field.java | 11 +-- .../oracle/svm/core/thread/JavaThreads.java | 15 +--- .../core/thread/Target_java_lang_Thread.java | 34 ++------ 25 files changed, 20 insertions(+), 654 deletions(-) delete mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Load0With2Args.java delete mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Load0With3Args.java delete mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_module_IllegalAccessLogger.java delete mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_nashorn_api_scripting_ClassFilter.java delete mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_nashorn_api_scripting_NashornScriptEngineFactory.java diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/Target_jdk_internal_ref_Cleaner.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/Target_jdk_internal_ref_Cleaner.java index 5cb07d80e10d..5cb82146a79b 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/Target_jdk_internal_ref_Cleaner.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/Target_jdk_internal_ref_Cleaner.java @@ -33,9 +33,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.JDK11OrEarlier; -import com.oracle.svm.core.jdk.JDK17OrLater; import com.oracle.svm.core.thread.VMThreads; import jdk.internal.misc.InnocuousThread; @@ -88,47 +85,15 @@ final class Target_jdk_internal_ref_CleanerImpl { @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.NewInstance, declClassName = "jdk.internal.ref.CleanerImpl$PhantomCleanableRef")// Target_jdk_internal_ref_PhantomCleanable phantomCleanableList; - @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.NewInstance, declClassName = "jdk.internal.ref.CleanerImpl$WeakCleanableRef")// - @TargetElement(onlyWith = JDK11OrEarlier.class) // - Target_jdk_internal_ref_WeakCleanable weakCleanableList; - - @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.NewInstance, declClassName = "jdk.internal.ref.CleanerImpl$SoftCleanableRef")// - @TargetElement(onlyWith = JDK11OrEarlier.class) // - Target_jdk_internal_ref_SoftCleanable softCleanableList; - @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.NewInstance, declClassName = "java.lang.ref.ReferenceQueue")// public ReferenceQueue queue; - /** @see #run() */ - @Substitute - @TargetElement(name = "run", onlyWith = JDK11OrEarlier.class) - public void runJDK11() { - Thread t = Thread.currentThread(); - InnocuousThread mlThread = (t instanceof InnocuousThread) ? (InnocuousThread) t : null; - while (!phantomCleanableList.isListEmpty() || !weakCleanableList.isListEmpty() || !softCleanableList.isListEmpty()) { - if (mlThread != null) { - mlThread.eraseThreadLocals(); - } - try { - Cleaner.Cleanable ref = (Cleaner.Cleanable) queue.remove(60 * 1000L); - if (ref != null) { - ref.clean(); - } - } catch (Throwable e) { - if (VMThreads.isTearingDown()) { - return; - } - } - } - } - /** * This loop executes in a daemon thread and waits until there are no more cleanables (including * the {@code Cleaner} itself), ignoring {@link InterruptedException}. This blocks VM tear-down, * so we add a check if the VM is tearing down here. */ @Substitute - @TargetElement(onlyWith = JDK17OrLater.class) public void run() { Thread t = Thread.currentThread(); InnocuousThread mlThread = (t instanceof InnocuousThread) ? (InnocuousThread) t : null; @@ -173,17 +138,3 @@ public Object transform(Object receiver, Object originalValue) { return receiver; } } - -// Removed by JDK-8251861 -@TargetClass(className = "jdk.internal.ref.WeakCleanable", onlyWith = JDK11OrEarlier.class) -final class Target_jdk_internal_ref_WeakCleanable { - @Alias - native boolean isListEmpty(); -} - -// Removed by JDK-8251861 -@TargetClass(className = "jdk.internal.ref.SoftCleanable", onlyWith = JDK11OrEarlier.class) -final class Target_jdk_internal_ref_SoftCleanable { - @Alias - native boolean isListEmpty(); -} 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 bd4ddb0dcfe1..68d245424f1d 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 @@ -95,7 +95,6 @@ import com.oracle.svm.core.config.ConfigurationValues; import com.oracle.svm.core.config.ObjectLayout; import com.oracle.svm.core.heap.UnknownObjectField; -import com.oracle.svm.core.jdk.JDK11OrEarlier; import com.oracle.svm.core.jdk.JDK17OrLater; import com.oracle.svm.core.jdk.JDK19OrLater; import com.oracle.svm.core.jdk.Resources; @@ -363,10 +362,6 @@ public void setModule(Module module) { @Substitute @InjectAccessors(CachedConstructorAccessors.class) // private Constructor cachedConstructor; - @Substitute @InjectAccessors(NewInstanceCallerCacheAccessors.class) // - @TargetElement(onlyWith = JDK11OrEarlier.class) // - private Class newInstanceCallerCache; - @UnknownObjectField(types = DynamicHubMetadata.class, canBeNull = true) private DynamicHubMetadata hubMetadata; @UnknownObjectField(types = ReflectionMetadata.class, canBeNull = true) private ReflectionMetadata reflectionMetadata; @@ -1821,18 +1816,6 @@ private static void setCachedConstructor(DynamicHub that, Constructor value) } } - private static class NewInstanceCallerCacheAccessors { - @SuppressWarnings("unused") - private static Class getNewInstanceCallerCache(DynamicHub that) { - return that.companion.getNewInstanceCallerCache(); - } - - @SuppressWarnings("unused") - private static void setNewInstanceCallerCache(DynamicHub that, Class value) { - that.companion.setNewInstanceCallerCache(value); - } - } - private static final class DynamicHubMetadata { final int enclosingMethodInfoIndex; diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK11OrEarlier.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK11OrEarlier.java index 011025f65c87..b9911b32de4c 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK11OrEarlier.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK11OrEarlier.java @@ -28,6 +28,7 @@ import org.graalvm.compiler.serviceprovider.JavaVersionUtil; +@Deprecated(since = "23.1.0", forRemoval = true) public class JDK11OrEarlier implements BooleanSupplier { @Override public boolean getAsBoolean() { 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 e8f57d92ee40..740e24fd1683 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 @@ -86,12 +86,6 @@ @SuppressWarnings("static-method") final class Target_java_lang_Object { - @Substitute - @TargetElement(name = "registerNatives", onlyWith = JDK11OrEarlier.class) - private static void registerNativesSubst() { - /* We reimplemented all native methods, so nothing to do. */ - } - @Substitute @TargetElement(name = "getClass") private Object getClassSubst() { diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Load0With2Args.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Load0With2Args.java deleted file mode 100644 index d8c6b6dbf1e8..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Load0With2Args.java +++ /dev/null @@ -1,49 +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.Arrays; -import java.util.function.BooleanSupplier; -import java.util.Optional; -import java.util.stream.Stream; - -/** - * A predicate that returns {@code true} iff - * {@code boolean java.lang.ClassLoader.NativeLibrary.load0(String name, boolean isBuiltin)} exists. - * It should only be used in conjunction with {@link JDK11OrEarlier} as {@code NativeLibrary} was - * moved to a top level class in later JDKs. - */ -// Checkstyle: allow Class.getSimpleName -public class Load0With2Args implements BooleanSupplier { - @Override - public boolean getAsBoolean() { - Optional> nativeLibrary = Stream.of(ClassLoader.class.getDeclaredClasses()).filter(c -> c.getSimpleName().equals("NativeLibrary")).findFirst(); - if (nativeLibrary.isPresent()) { - Class[] signature = {String.class, boolean.class}; - return Stream.of(nativeLibrary.get().getDeclaredMethods()).filter(m -> m.getName().equals("load0") && Arrays.equals(m.getParameters(), signature)).findFirst().isPresent(); - } - return false; - } -} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Load0With3Args.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Load0With3Args.java deleted file mode 100644 index 176e2beebb44..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Load0With3Args.java +++ /dev/null @@ -1,49 +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.Arrays; -import java.util.function.BooleanSupplier; -import java.util.Optional; -import java.util.stream.Stream; - -/** - * A predicate that returns {@code true} iff - * {@code boolean java.lang.ClassLoader.NativeLibrary.load0(String name, boolean isBuiltin, boolean throwExceptionIfFail)} - * exists. It should only be used in conjunction with {@link JDK11OrEarlier} as - * {@code NativeLibrary} was moved to a top level class in later JDKs. - */ -// Checkstyle: allow Class.getSimpleName -public class Load0With3Args implements BooleanSupplier { - @Override - public boolean getAsBoolean() { - Optional> nativeLibrary = Stream.of(ClassLoader.class.getDeclaredClasses()).filter(c -> c.getSimpleName().equals("NativeLibrary")).findFirst(); - if (nativeLibrary.isPresent()) { - Class[] signature = {String.class, boolean.class, boolean.class}; - return Stream.of(nativeLibrary.get().getDeclaredMethods()).filter(m -> m.getName().equals("load0") && Arrays.equals(m.getParameters(), signature)).findFirst().isPresent(); - } - return false; - } -} 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 d3d899be86e8..335f89f1f051 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 @@ -29,7 +29,6 @@ import static com.oracle.svm.core.annotate.RecomputeFieldValue.Kind.AtomicFieldUpdaterOffset; import static com.oracle.svm.core.annotate.RecomputeFieldValue.Kind.Reset; -import java.lang.ref.ReferenceQueue; import java.lang.ref.WeakReference; import java.lang.reflect.Field; import java.lang.reflect.Modifier; @@ -40,7 +39,6 @@ import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; import java.util.concurrent.atomic.AtomicLongFieldUpdater; import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; -import java.util.concurrent.locks.ReentrantLock; import java.util.function.Consumer; import org.graalvm.nativeimage.ImageSingletons; @@ -54,7 +52,6 @@ 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.RecomputeFieldValue.Kind; import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; import com.oracle.svm.core.annotate.TargetElement; @@ -389,31 +386,6 @@ private static synchronized ForkJoinPool initializeCommonPool() { } } -@TargetClass(value = java.util.concurrent.ForkJoinTask.class, onlyWith = JDK11OrEarlier.class) -@SuppressWarnings("static-method") -final class Target_java_util_concurrent_ForkJoinTask_JDK11OrEarlier { - @Alias @RecomputeFieldValue(kind = Kind.FromAlias) // - private static Target_java_util_concurrent_ForkJoinTask_ExceptionNode[] exceptionTable; - @Alias @RecomputeFieldValue(kind = Kind.FromAlias) // - private static ReentrantLock exceptionTableLock; - @Alias @RecomputeFieldValue(kind = Kind.FromAlias) // - private static ReferenceQueue exceptionTableRefQueue; - - static { - exceptionTableLock = new ReentrantLock(); - exceptionTableRefQueue = new ReferenceQueue<>(); - /* - * JDK 8 has a static final field EXCEPTION_MAP_CAPACITY with value 32, later versions just - * use 32 hardcoded. To be JDK version independent, we duplicate the hardcoded value. - */ - exceptionTable = new Target_java_util_concurrent_ForkJoinTask_ExceptionNode[32]; - } -} - -@TargetClass(value = java.util.concurrent.ForkJoinTask.class, innerClass = "ExceptionNode", onlyWith = JDK11OrEarlier.class) -final class Target_java_util_concurrent_ForkJoinTask_ExceptionNode { -} - /** Dummy class to have a class with the file's name. */ public final class RecomputedFields { } 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 f4fead83b3e7..5e9ab8e43df0 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 @@ -56,7 +56,6 @@ 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; @@ -66,7 +65,6 @@ import com.oracle.svm.core.util.VMError; import com.oracle.svm.util.ReflectionUtil; -import jdk.internal.reflect.Reflection; import sun.security.jca.ProviderList; import sun.security.util.SecurityConstants; @@ -79,35 +77,6 @@ @SuppressWarnings({"unused"}) final class Target_java_security_AccessController { - @Substitute - @TargetElement(onlyWith = JDK11OrEarlier.class) - public static T doPrivileged(PrivilegedAction action) throws Throwable { - return executePrivileged(action, null, Reflection.getCallerClass()); - } - - @Substitute - @TargetElement(onlyWith = JDK11OrEarlier.class) - public static T doPrivileged(PrivilegedAction action, AccessControlContext context) throws Throwable { - Class caller = Reflection.getCallerClass(); - AccessControlContext acc = checkContext(context, caller); - return executePrivileged(action, acc, caller); - } - - @Substitute - @TargetElement(onlyWith = JDK11OrEarlier.class) - public static T doPrivileged(PrivilegedExceptionAction action) throws Throwable { - Class caller = Reflection.getCallerClass(); - return executePrivileged(action, null, caller); - } - - @Substitute - @TargetElement(onlyWith = JDK11OrEarlier.class) - static T doPrivileged(PrivilegedExceptionAction action, AccessControlContext context) throws Throwable { - Class caller = Reflection.getCallerClass(); - AccessControlContext acc = checkContext(context, caller); - return executePrivileged(action, acc, caller); - } - @Substitute @SuppressWarnings("deprecation") static AccessControlContext getStackAccessControlContext() { @@ -321,17 +290,6 @@ static boolean isTrustedCryptoProvider(Provider provider) { @SuppressWarnings({"unused"}) final class Target_javax_crypto_JceSecurity { - /* - * Lazily recompute the RANDOM field at runtime. We cannot push the entire static initialization - * of JceSecurity to run time because we want the JceSecurity.verificationResults initialized at - * image build time. - * - * This is only used in {@link KeyAgreement}, it's safe to remove. - */ - @Alias @TargetElement(onlyWith = JDK11OrEarlier.class) // - @InjectAccessors(JceSecurityAccessor.class) // - static SecureRandom RANDOM; - /* * The JceSecurity.verificationResults cache is initialized by the SecurityServicesFeature at * build time, for all registered providers. The cache is used by JceSecurity.canUseProvider() @@ -634,22 +592,6 @@ final class Target_sun_security_jca_ProviderConfig_ProviderLoader { static Target_sun_security_jca_ProviderConfig_ProviderLoader INSTANCE; } -/** - * This only applies to JDK8 and JDK11. Experimental FIPS mode in the SunJSSE Provider was removed - * in JDK-8217835. Going forward it is recommended to configure FIPS 140 compliant cryptography - * providers by using the usual JCA providers configuration mechanism. - */ -@SuppressWarnings("unused") -@TargetClass(value = sun.security.ssl.SunJSSE.class, onlyWith = JDK11OrEarlier.class) -final class Target_sun_security_ssl_SunJSSE { - - @Substitute - private Target_sun_security_ssl_SunJSSE(java.security.Provider cryptoProvider, String providerName) { - throw VMError.unsupportedFeature("Experimental FIPS mode in the SunJSSE Provider is deprecated (JDK-8217835)." + - " To register a FIPS provider use the supported java.security.Security.addProvider() API."); - } -} - @TargetClass(className = "sun.security.jca.Providers") final class Target_sun_security_jca_Providers { @Alias// diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/SunMiscSubstitutions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/SunMiscSubstitutions.java index 534f6268a10e..b6e08595e3ae 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/SunMiscSubstitutions.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/SunMiscSubstitutions.java @@ -139,13 +139,6 @@ private Class defineClass(String name, byte[] b, int off, int len, ClassLoade return PredefinedClassesSupport.loadClass(loader, name, b, off, len, protectionDomain); } - // JDK-8243287 - @Substitute - @TargetElement(onlyWith = JDK11OrEarlier.class) - private Class defineAnonymousClass(Class hostClass, byte[] data, Object[] cpPatches) { - throw VMError.unsupportedFeature("Defining anonymous classes at runtime is not supported."); - } - @Substitute private int getLoadAverage0(double[] loadavg, int nelems) { /* Adapted from `Unsafe_GetLoadAverage0` in `src/hotspot/share/prims/unsafe.cpp`. */ @@ -188,28 +181,11 @@ private int getLoadAverage0(double[] loadavg, int nelems) { @Delete private native int arrayIndexScale0(Class arrayClass); - @Delete - @TargetElement(onlyWith = JDK11OrEarlier.class) - private native int addressSize0(); - @Substitute @SuppressWarnings("unused") private Class defineClass0(String name, byte[] b, int off, int len, ClassLoader loader, ProtectionDomain protectionDomain) { throw VMError.unsupportedFeature("Target_Unsafe_Core.defineClass0(String, byte[], int, int, ClassLoader, ProtectionDomain)"); } - - // JDK-8243287 - @Delete - @TargetElement(onlyWith = JDK11OrEarlier.class) - private native Class defineAnonymousClass0(Class hostClass, byte[] data, Object[] cpPatches); - - @Delete - @TargetElement(onlyWith = JDK11OrEarlier.class) - private native boolean unalignedAccess0(); - - @Delete - @TargetElement(onlyWith = JDK11OrEarlier.class) - private native boolean isBigEndian0(); } @TargetClass(classNameProvider = Package_jdk_internal_access.class, className = "SharedSecrets") diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/SunNioSubstitutions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/SunNioSubstitutions.java index 4106a14d6f90..3e5f7f9431a5 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/SunNioSubstitutions.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/SunNioSubstitutions.java @@ -31,33 +31,7 @@ import com.oracle.svm.core.annotate.TargetClass; import com.oracle.svm.core.util.VMError; -@TargetClass(className = "java.nio.channels.spi.SelectorProvider", onlyWith = JDK11OrEarlier.class) -final class Target_java_nio_channels_spi_SelectorProvider { - - @Alias// - static SelectorProvider provider; - - @Substitute - static SelectorProvider provider() { - VMError.guarantee(provider != null, "java.nio.channels.spi.SelectorProvider.provider must be initialized during image generation"); - return provider; - } - - static { - /* - * Calling the method during image generation triggers initialization. This ensures that we - * have a correctly initialized provider available at run time. It also means that the - * system property and service loader configuration that allow influencing the - * SelectorProvider implementation are accessed during image generation, i.e., it is not - * possible to overwrite the implementation class at run time anymore by changing the system - * property at run time. - */ - SelectorProvider result = java.nio.channels.spi.SelectorProvider.provider(); - assert result != null; - } -} - -@TargetClass(className = "java.nio.channels.spi.SelectorProvider", innerClass = "Holder", onlyWith = JDK17OrLater.class) +@TargetClass(className = "java.nio.channels.spi.SelectorProvider", innerClass = "Holder") final class Target_java_nio_channels_spi_SelectorProvider_Holder { @Alias// diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_ClassLoader.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_ClassLoader.java index 88337a29d33f..d4374707e1a1 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_ClassLoader.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_ClassLoader.java @@ -30,8 +30,6 @@ import java.security.ProtectionDomain; import java.util.Enumeration; import java.util.HashMap; -import java.util.Map; -import java.util.Set; import java.util.Vector; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Stream; @@ -119,6 +117,7 @@ public static InputStream getSystemResourceAsStream(String name) { } @Substitute + @SuppressWarnings("unused") static NativeLibrary loadLibrary(Class fromClass, String name) { NativeLibrarySupport.singleton().loadLibraryRelative(name); // We don't use the JDK's NativeLibraries or NativeLibrary implementations @@ -126,6 +125,7 @@ static NativeLibrary loadLibrary(Class fromClass, String name) { } @Substitute + @SuppressWarnings("unused") static NativeLibrary loadLibrary(Class fromClass, File file) { NativeLibrarySupport.singleton().loadLibraryAbsolute(file); // We don't use the JDK's NativeLibraries or NativeLibrary implementations @@ -166,14 +166,9 @@ Class loadClass(String name, boolean resolve) throws ClassNotFoundException { return findClass(name); } - @Delete - @TargetElement(onlyWith = JDK11OrEarlier.class) - native Class findBootstrapClassOrNull(String name); - // JDK-8265605 @Delete - @TargetElement(onlyWith = JDK17OrLater.class, name = "findBootstrapClassOrNull") - static native Class findBootstrapClassOrNullJDK17OrLater(String name); + static native Class findBootstrapClassOrNull(String name); @Substitute @SuppressWarnings("unused") @@ -213,7 +208,6 @@ private Class findLoadedClass0(String name) { ConcurrentHashMap createOrGetClassLoaderValueMap() { ConcurrentHashMap result = classLoaderValueMap; if (result == null) { - // Checkstyle: allow synchronization synchronized (this) { result = classLoaderValueMap; if (result == null) { @@ -342,80 +336,13 @@ private static Class defineClass0(ClassLoader loader, Class lookup, String throw VMError.unsupportedFeature("Defining hidden classes at runtime is not supported."); } - @Delete - @TargetElement(onlyWith = JDK11OrEarlier.class) - private native Class findBootstrapClass(String name); - // JDK-8265605 @Delete @TargetElement(onlyWith = JDK17OrLater.class, name = "findBootstrapClass") private static native Class findBootstrapClassJDK17OrLater(String name); - @Delete - @TargetElement(onlyWith = JDK11OrEarlier.class) - private static native String findBuiltinLib(String name); - @Delete private static native Target_java_lang_AssertionStatusDirectives retrieveDirectives(); - - /* - * Ensure that fields and methods that hold state of the image generator are not reachable when - * all fields or methods of the class are registered for reflection. - */ - - @Delete // - @TargetElement(onlyWith = JDK11OrEarlier.class) // - private static Set loadedLibraryNames; - @Delete // - @TargetElement(onlyWith = JDK11OrEarlier.class) // - private static Map systemNativeLibraries; - @Delete // - @TargetElement(onlyWith = JDK11OrEarlier.class) // - private Map nativeLibraries; - // Checkstyle: stop - @Delete // - @TargetElement(onlyWith = JDK11OrEarlier.class) // - private static String[] usr_paths; - @Delete // - @TargetElement(onlyWith = JDK11OrEarlier.class) // - private static String[] sys_paths; - // Checkstyle: resume - - @Delete - @TargetElement(onlyWith = JDK11OrEarlier.class) - private native Map nativeLibraries(); - - @Delete - @TargetElement(onlyWith = JDK11OrEarlier.class) - private static native Map systemNativeLibraries(); - - @Delete - @TargetElement(onlyWith = JDK11OrEarlier.class) - private static native boolean loadLibrary0(Class fromClass, File file); -} - -@TargetClass(value = ClassLoader.class, innerClass = "NativeLibrary", onlyWith = JDK11OrEarlier.class) -final class Target_java_lang_ClassLoader_NativeLibrary { - - /* - * We are defensive and also handle private native methods by marking them as deleted. If they - * are reachable, the user is certainly doing something wrong. But we do not want to fail with a - * linking error. - */ - - @Delete - @TargetElement(onlyWith = Load0With2Args.class) - private native boolean load0(String name, boolean isBuiltin); - - @Delete - @TargetElement(onlyWith = Load0With3Args.class) - private native boolean load0(String name, boolean isBuiltin, boolean throwExceptionIfFail); - - @Delete - private native long findEntry(String name); - - @Delete - private static native void unload(String name, boolean isBuiltin, long handle); } @TargetClass(className = "java.lang.AssertionStatusDirectives") // diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_module_IllegalAccessLogger.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_module_IllegalAccessLogger.java deleted file mode 100644 index 24f2c050088b..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_module_IllegalAccessLogger.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2021, 2021, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.svm.core.jdk; - -import com.oracle.svm.core.annotate.Alias; -import com.oracle.svm.core.annotate.RecomputeFieldValue; -import com.oracle.svm.core.annotate.RecomputeFieldValue.Kind; -import com.oracle.svm.core.annotate.Substitute; -import com.oracle.svm.core.annotate.TargetClass; - -/** - * Avoid making the code for logging reachable. We do not need it, and it only increases code size. - * If we ever want to enable logging, we also need to define a way to create the logger at run time, - * in the JDK the logger is created as part of the module system bootstrapping. - * - * The logging code is only present in JDK 11, all logging was removed for JDK 17. - */ -@TargetClass(className = "jdk.internal.module.IllegalAccessLogger", onlyWith = JDK11OrEarlier.class) -final class Target_jdk_internal_module_IllegalAccessLogger { - - @Alias @RecomputeFieldValue(kind = Kind.Reset) // - private static Target_jdk_internal_module_IllegalAccessLogger logger; - - @Substitute - private static Target_jdk_internal_module_IllegalAccessLogger illegalAccessLogger() { - return null; - } -} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_nashorn_api_scripting_ClassFilter.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_nashorn_api_scripting_ClassFilter.java deleted file mode 100644 index 72a3728caa24..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_nashorn_api_scripting_ClassFilter.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2018, 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 com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.jdk.NashornSupport.NashornAvailable; - -@TargetClass(className = "jdk.nashorn.api.scripting.ClassFilter", onlyWith = {JDK11OrEarlier.class, NashornAvailable.class}) -public final class Target_jdk_nashorn_api_scripting_ClassFilter { -} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_nashorn_api_scripting_NashornScriptEngineFactory.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_nashorn_api_scripting_NashornScriptEngineFactory.java deleted file mode 100644 index 31714e6a4649..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_nashorn_api_scripting_NashornScriptEngineFactory.java +++ /dev/null @@ -1,56 +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 javax.script.ScriptEngine; - -import com.oracle.svm.core.annotate.Substitute; -import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.jdk.NashornSupport.NashornAvailable; -import com.oracle.svm.core.util.VMError; - -@TargetClass(className = "jdk.nashorn.api.scripting.NashornScriptEngineFactory", onlyWith = {JDK11OrEarlier.class, NashornAvailable.class}) -public final class Target_jdk_nashorn_api_scripting_NashornScriptEngineFactory { - @Substitute - @SuppressWarnings({"unused", "static-method"}) - public ScriptEngine getScriptEngine() { - throw VMError.unsupportedFeature(Util.errorMessage); - } - - @Substitute - @SuppressWarnings({"unused", "static-method"}) - private ScriptEngine newEngine(String[] args, ClassLoader appLoader, Target_jdk_nashorn_api_scripting_ClassFilter classFilter) { - throw VMError.unsupportedFeature(Util.errorMessage); - } -} - -class Util { - static final String errorMessage = "The Nashorn scripting engine is not supported by native-image due to its use of invokedynamic. " + - "The native-image static analysis runs under a closed-world assumption " + - "which requires that all called methods and their call sites are known ahead-of-time, " + - "whereas invokedynamic can introduce calls at run time or change the method that is invoked." + - "Therefore, only specific use cases of invokedynamic are supported, " + - "namely when the invokedynamic can be reduced to a single virtual call or field access during native image generation."; -} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/ThreadLocalRandomAccessors.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/ThreadLocalRandomAccessors.java index 75671b8a1949..cb0d091d0769 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/ThreadLocalRandomAccessors.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/ThreadLocalRandomAccessors.java @@ -27,12 +27,9 @@ import java.util.concurrent.atomic.AtomicLong; -import org.graalvm.compiler.serviceprovider.JavaVersionUtil; - import com.oracle.svm.core.annotate.Alias; import com.oracle.svm.core.annotate.InjectAccessors; import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.annotate.TargetElement; @TargetClass(java.util.concurrent.ThreadLocalRandom.class) final class Target_java_util_concurrent_ThreadLocalRandom { @@ -43,11 +40,6 @@ final class Target_java_util_concurrent_ThreadLocalRandom { */ @Alias @InjectAccessors(ThreadLocalRandomAccessors.class)// private static AtomicLong seeder; - - @Alias - @TargetElement(onlyWith = JDK11OrEarlier.class) - static native long mix64(long z); - } @TargetClass(className = "jdk.internal.util.random.RandomSupport", onlyWith = JDK17OrLater.class) @@ -72,10 +64,6 @@ public static void setSeeder(AtomicLong value) { @Override long mix64(long l) { - if (JavaVersionUtil.JAVA_SPEC <= 11) { - return Target_java_util_concurrent_ThreadLocalRandom.mix64(l); - } else { - return Target_jdk_internal_util_random_RandomSupport.mixMurmur64(l); - } + return Target_jdk_internal_util_random_RandomSupport.mixMurmur64(l); } } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_locale_provider_LocaleServiceProviderPool_OptimizedLocaleMode.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_locale_provider_LocaleServiceProviderPool_OptimizedLocaleMode.java index 2829d35128d4..1bdd625d541f 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_locale_provider_LocaleServiceProviderPool_OptimizedLocaleMode.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_locale_provider_LocaleServiceProviderPool_OptimizedLocaleMode.java @@ -32,8 +32,6 @@ import com.oracle.svm.core.annotate.KeepOriginal; 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.JDK11OrEarlier; import com.oracle.svm.core.jdk.localization.LocalizationSupport; import com.oracle.svm.core.jdk.localization.substitutions.modes.OptimizedLocaleMode; import com.oracle.svm.core.util.VMError; @@ -83,10 +81,6 @@ public native

S getLocalizedObject(LocaleSe String key, Object... params); - @KeepOriginal // - @TargetElement(onlyWith = JDK11OrEarlier.class) // - static native void config(Class caller, String message); - @Substitute private static Locale[] getAllAvailableLocales() { return ImageSingletons.lookup(LocalizationSupport.class).allLocales; diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_JVM.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_JVM.java index c788d5cf93b8..592eb5aa32f1 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_JVM.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_JVM.java @@ -39,7 +39,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.JDK11OrEarlier; import com.oracle.svm.core.jdk.JDK17OrEarlier; import com.oracle.svm.core.jdk.JDK17OrLater; import com.oracle.svm.core.jdk.JDK19OrLater; @@ -48,7 +47,6 @@ import com.oracle.svm.core.util.VMError; import com.oracle.svm.util.ReflectionUtil; -import jdk.jfr.Event; import jdk.jfr.internal.JVM; import jdk.jfr.internal.LogTag; @@ -69,11 +67,6 @@ public final class Target_jdk_jfr_internal_JVM { @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset) // private volatile boolean nativeOK; - @Alias // - @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset) // - @TargetElement(onlyWith = JDK11OrEarlier.class) // - private volatile boolean recording; - /** See {@link JVM#registerNatives}. */ @Substitute private static void registerNatives() { @@ -124,13 +117,6 @@ public List> getAllEventClasses() { return JfrJavaEvents.getAllEventClasses(); } - /** See {@link JVM#getAllEventClasses}. */ - @Substitute - @TargetElement(name = "getAllEventClasses", onlyWith = JDK11OrEarlier.class) - public List> getAllEventClassesJDK11() { - return JfrJavaEvents.getJfrEventClasses(); - } - /** See {@link JVM#getUnloadedEventClassCount}. */ @Substitute public long getUnloadedEventClassCount() { @@ -148,13 +134,6 @@ public static long getClassId(Class clazz) { return SubstrateJVM.get().getClassId(clazz); } - /** See JVM.getClassIdNonIntrinsic(Class). */ - @Substitute - @TargetElement(onlyWith = JDK11OrEarlier.class) - public static long getClassIdNonIntrinsic(Class clazz) { - return getClassId(clazz); - } - /** See {@link JVM#getPid}. */ @Substitute public String getPid() { @@ -435,14 +414,6 @@ public boolean setThrottle(long eventTypeId, long eventSampleSize, long periodMs /** See {@link JVM#emitOldObjectSamples}. */ @Substitute - @TargetElement(onlyWith = JDK11OrEarlier.class) // - public void emitOldObjectSamples(long cutoff, boolean emitAll) { - // Not supported but this method is called during JFR shutdown, so we can't throw an error. - } - - /** See {@link JVM#emitOldObjectSamples}. */ - @Substitute - @TargetElement(onlyWith = JDK17OrLater.class) // public void emitOldObjectSamples(long cutoff, boolean emitAll, boolean skipBFS) { // Not supported but this method is called during JFR shutdown, so we can't throw an error. } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/methodhandles/MethodHandleIntrinsicImpl.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/methodhandles/MethodHandleIntrinsicImpl.java index 39646e4f4456..9f3e5cb18b38 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/methodhandles/MethodHandleIntrinsicImpl.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/methodhandles/MethodHandleIntrinsicImpl.java @@ -53,7 +53,7 @@ * * The intrinsics are created upon encountering a listed function during method handle resolution. * (see - * {@link Target_java_lang_invoke_MethodHandleNatives#resolve(Target_java_lang_invoke_MemberName, Class, boolean)}). + * {@link Util_java_lang_invoke_MethodHandleNatives#resolve(Target_java_lang_invoke_MemberName, Class, boolean)}). */ final class MethodHandleIntrinsicImpl implements MethodHandleIntrinsic { enum Variant { 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 7ca70571a95c..ad376ea9d251 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 @@ -134,7 +134,7 @@ static Object invokeInternal(Target_java_lang_invoke_MemberName memberName, Meth * we perform the resolution again. */ if (memberName.reflectAccess == null && memberName.intrinsic == null) { - Target_java_lang_invoke_MethodHandleNatives.resolve(memberName, null, false); + Util_java_lang_invoke_MethodHandleNatives.resolve(memberName, null, false); } if (memberName.intrinsic != null) { /* Intrinsic call */ 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 5b8a8c9f92e5..1dc33a2c49a9 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 @@ -38,7 +38,6 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import com.oracle.svm.core.jdk.JDK20OrEarlier; import org.graalvm.compiler.debug.GraalError; import org.graalvm.compiler.serviceprovider.JavaVersionUtil; @@ -52,8 +51,7 @@ 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.JDK11OrEarlier; -import com.oracle.svm.core.jdk.JDK17OrLater; +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; @@ -193,14 +191,6 @@ private static Object getMemberVMInfo(Target_java_lang_invoke_MemberName self) { @Delete private static native int getNamedCon(int which, Object[] name); - // JDK 11 - - @Substitute - @TargetElement(onlyWith = JDK11OrEarlier.class) - static Target_java_lang_invoke_MemberName resolve(Target_java_lang_invoke_MemberName self, Class caller, boolean speculativeResolve) throws LinkageError, ClassNotFoundException { - return Util_java_lang_invoke_MethodHandleNatives.resolve(self, caller, speculativeResolve); - } - @Delete private static native void copyOutBootstrapArguments(Class caller, int[] indexInfo, int start, int end, Object[] buf, int pos, boolean resolve, Object ifNotAvailable); @@ -215,10 +205,7 @@ private static void clearCallSiteContext(Target_java_lang_invoke_MethodHandleNat @AnnotateOriginal static native String refKindName(byte refKind); - // JDK 17 - @Substitute - @TargetElement(onlyWith = JDK17OrLater.class) static Target_java_lang_invoke_MemberName resolve(Target_java_lang_invoke_MemberName self, Class caller, int lookupMode, boolean speculativeResolve) throws LinkageError, ClassNotFoundException { Class declaringClass = self.getDeclaringClass(); diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/target/ReflectionMetadataDecoderImpl.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/target/ReflectionMetadataDecoderImpl.java index 1a0256207837..5d3e236b0358 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/target/ReflectionMetadataDecoderImpl.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/target/ReflectionMetadataDecoderImpl.java @@ -354,11 +354,7 @@ private static Object decodeField(UnsafeArrayTypeReader buf, Class declaringC return new FieldDescriptor(declaringClass, name); } Target_java_lang_reflect_Field field = new Target_java_lang_reflect_Field(); - if (JavaVersionUtil.JAVA_SPEC >= 17) { - field.constructorJDK17OrLater(declaringClass, name, negative ? Object.class : type, modifiers, false, -1, null, null); - } else { - field.constructorJDK11OrEarlier(declaringClass, name, negative ? Object.class : type, modifiers, -1, null, null); - } + field.constructor(declaringClass, name, negative ? Object.class : type, modifiers, false, -1, null, null); return SubstrateUtil.cast(field, Field.class); } boolean trustedFinal = (JavaVersionUtil.JAVA_SPEC >= 17) ? buf.getU1() == 1 : false; @@ -372,11 +368,7 @@ private static Object decodeField(UnsafeArrayTypeReader buf, Class declaringC } Target_java_lang_reflect_Field field = new Target_java_lang_reflect_Field(); - if (JavaVersionUtil.JAVA_SPEC >= 17) { - field.constructorJDK17OrLater(declaringClass, name, type, modifiers, trustedFinal, -1, signature, annotations); - } else { - field.constructorJDK11OrEarlier(declaringClass, name, type, modifiers, -1, signature, annotations); - } + field.constructor(declaringClass, name, type, modifiers, trustedFinal, -1, signature, annotations); field.offset = offset; field.deletedReason = deletedReason; SubstrateUtil.cast(field, Target_java_lang_reflect_AccessibleObject.class).typeAnnotations = typeAnnotations; diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/target/Target_java_lang_reflect_AccessibleObject.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/target/Target_java_lang_reflect_AccessibleObject.java index 27bf48e0e0a1..02830f86cd14 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/target/Target_java_lang_reflect_AccessibleObject.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/target/Target_java_lang_reflect_AccessibleObject.java @@ -32,9 +32,6 @@ import com.oracle.svm.core.annotate.Inject; 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.jdk.JDK11OrEarlier; -import com.oracle.svm.core.jdk.JDK17OrLater; @TargetClass(value = AccessibleObject.class) public final class Target_java_lang_reflect_AccessibleObject { @@ -42,11 +39,6 @@ public final class Target_java_lang_reflect_AccessibleObject { public boolean override; @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset) // - @TargetElement(onlyWith = JDK11OrEarlier.class) // - volatile Object securityCheckCache; - - @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset) // - @TargetElement(onlyWith = JDK17OrLater.class) // volatile Object accessCheckCache; @Inject @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Custom, declClass = TypeAnnotationsComputer.class) // 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 076b7de35d20..e639a3ad8fdb 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,9 +42,7 @@ 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.JDK11OrEarlier; import com.oracle.svm.core.jdk.JDK17OrEarlier; -import com.oracle.svm.core.jdk.JDK17OrLater; import com.oracle.svm.core.jdk.JDK19OrLater; import com.oracle.svm.core.util.VMError; @@ -98,14 +96,9 @@ public final class Target_java_lang_reflect_Field { native Target_jdk_internal_reflect_FieldAccessor acquireOverrideFieldAccessor(); @Alias - @TargetElement(name = CONSTRUCTOR_NAME, onlyWith = JDK17OrLater.class) + @TargetElement(name = CONSTRUCTOR_NAME) @SuppressWarnings("hiding") - native void constructorJDK17OrLater(Class declaringClass, String name, Class type, int modifiers, boolean trustedFinal, int slot, String signature, byte[] annotations); - - @Alias - @TargetElement(name = CONSTRUCTOR_NAME, onlyWith = JDK11OrEarlier.class) - @SuppressWarnings("hiding") - native void constructorJDK11OrEarlier(Class declaringClass, String name, Class type, int modifiers, int slot, String signature, byte[] annotations); + native void constructor(Class declaringClass, String name, Class type, int modifiers, boolean trustedFinal, int slot, String signature, byte[] annotations); @Substitute @TargetElement(onlyWith = JDK17OrEarlier.class) 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 e96ce08d9ee1..eef075349e4d 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 @@ -114,14 +114,7 @@ public static long getThreadId(Thread thread) { * in VM-internal contexts. */ public static boolean isInterrupted(Thread thread) { - return getInterruptedFlag(thread); - } - - private static boolean getInterruptedFlag(Thread thread) { - if (JavaVersionUtil.JAVA_SPEC >= 17) { - return toTarget(thread).interruptedJDK17OrLater; - } - return toTarget(thread).interruptedJDK11OrEarlier; + return toTarget(thread).interrupted; } static boolean getAndClearInterrupt(Thread thread) { @@ -147,11 +140,7 @@ static boolean getAndClearInterruptedFlag(Thread thread) { } static void writeInterruptedFlag(Thread thread, boolean value) { - if (JavaVersionUtil.JAVA_SPEC >= 17) { - toTarget(thread).interruptedJDK17OrLater = value; - } else { - toTarget(thread).interruptedJDK11OrEarlier = value; - } + toTarget(thread).interrupted = value; } @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) 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 8fd02487833b..ab0291cd103c 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 @@ -53,7 +53,6 @@ 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.JDK11OrEarlier; import com.oracle.svm.core.jdk.JDK17OrEarlier; import com.oracle.svm.core.jdk.JDK17OrLater; import com.oracle.svm.core.jdk.JDK19OrEarlier; @@ -90,22 +89,9 @@ public final class Target_java_lang_Thread { @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset) // IsolateThread isolateThread; - /** - * Every thread has a boolean for noting whether this thread is interrupted. - * - * After JDK 11, a field with same name has been introduced and the logic to set / reset it has - * moved into Java code. So this injected field and the substitutions that maintain it are no - * longer necessary. See {@link #interruptedJDK17OrLater}. - */ - @Inject // - @TargetElement(onlyWith = JDK11OrEarlier.class) // - @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset) // - volatile boolean interruptedJDK11OrEarlier; - @Alias // - @TargetElement(name = "interrupted", onlyWith = JDK17OrLater.class) // @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset) // - volatile boolean interruptedJDK17OrLater; + volatile boolean interrupted; @Inject @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset) // long parentThreadId; @@ -457,16 +443,10 @@ public boolean isInterrupted() { } @Substitute - @TargetElement(onlyWith = JDK17OrEarlier.class) public static boolean interrupted() { return JavaThreads.getAndClearInterrupt(Thread.currentThread()); } - @Delete - @TargetElement(onlyWith = JDK11OrEarlier.class) - @Platforms(InternalPlatform.NATIVE_ONLY.class) - private native boolean isInterrupted(boolean clearInterrupted); - /** * Marks the thread as interrupted and wakes it up. * @@ -476,14 +456,10 @@ public static boolean interrupted() { */ @Substitute void interrupt0() { - if (JavaVersionUtil.JAVA_SPEC <= 11) { - interruptedJDK11OrEarlier = true; - } else { - /* - * After JDK 11, the interrupted flag is maintained by the JDK in Java code, i.e., - * already set by the caller. So we do not need to set any flag. - */ - } + /* + * The interrupted flag is maintained by the JDK in Java code, i.e., already set by the + * caller. So we do not need to set any flag. + */ if (!SubstrateOptions.MultiThreaded.getValue()) { /* If the VM is single-threaded, this thread can not be blocked. */