diff --git a/substratevm/src/com.oracle.svm.configure/src/com/oracle/svm/configure/ConfigurationTool.java b/substratevm/src/com.oracle.svm.configure/src/com/oracle/svm/configure/ConfigurationTool.java index 9c2e272f1e1e..7557f5c430db 100644 --- a/substratevm/src/com.oracle.svm.configure/src/com/oracle/svm/configure/ConfigurationTool.java +++ b/substratevm/src/com.oracle.svm.configure/src/com/oracle/svm/configure/ConfigurationTool.java @@ -30,7 +30,6 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; -import java.lang.reflect.Method; import java.net.URI; import java.nio.charset.StandardCharsets; import java.nio.file.Files; @@ -48,13 +47,13 @@ import com.oracle.svm.configure.config.ConfigurationSet; import com.oracle.svm.configure.filters.FilterConfigurationParser; +import com.oracle.svm.configure.filters.ModuleFilterTools; import com.oracle.svm.configure.filters.RuleNode; import com.oracle.svm.configure.json.JsonWriter; import com.oracle.svm.configure.trace.AccessAdvisor; import com.oracle.svm.configure.trace.TraceProcessor; import com.oracle.svm.core.configure.ConfigurationFile; import com.oracle.svm.core.util.VMError; -import com.oracle.svm.util.ReflectionUtil; public class ConfigurationTool { @@ -368,17 +367,7 @@ private static void generateFilterRules(Iterator argsIter) throws IOExce exportedInclusion = RuleNode.Inclusion.Include; unexportedInclusion = RuleNode.Inclusion.Exclude; } - - try { - Class moduleFilterToolsClass = Class.forName("com.oracle.svm.configure.jdk11.filters.ModuleFilterTools"); - Method generateFromModulesMethod = ReflectionUtil.lookupMethod(moduleFilterToolsClass, "generateFromModules", - String[].class, RuleNode.Inclusion.class, RuleNode.Inclusion.class, RuleNode.Inclusion.class, boolean.class); - rootNode = (RuleNode) generateFromModulesMethod.invoke(null, moduleNames, rootInclusion, exportedInclusion, unexportedInclusion, reduce); - } catch (ClassNotFoundException e) { - throw new RuntimeException("Module-based filter generation is not available in JDK 8 and below."); - } catch (ReflectiveOperationException e) { - throw new RuntimeException(e); - } + rootNode = ModuleFilterTools.generateFromModules(moduleNames, rootInclusion, exportedInclusion, unexportedInclusion, reduce); } else { throw new UsageException(current + " is currently not supported in the native-image build of this tool."); } diff --git a/substratevm/src/com.oracle.svm.configure/src/com/oracle/svm/configure/jdk11/filters/ModuleFilterTools.java b/substratevm/src/com.oracle.svm.configure/src/com/oracle/svm/configure/filters/ModuleFilterTools.java similarity index 96% rename from substratevm/src/com.oracle.svm.configure/src/com/oracle/svm/configure/jdk11/filters/ModuleFilterTools.java rename to substratevm/src/com.oracle.svm.configure/src/com/oracle/svm/configure/filters/ModuleFilterTools.java index 219283d54a9e..0375f216adbc 100644 --- a/substratevm/src/com.oracle.svm.configure/src/com/oracle/svm/configure/jdk11/filters/ModuleFilterTools.java +++ b/substratevm/src/com.oracle.svm.configure/src/com/oracle/svm/configure/filters/ModuleFilterTools.java @@ -22,17 +22,15 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package com.oracle.svm.configure.jdk11.filters; +package com.oracle.svm.configure.filters; import java.lang.module.ModuleDescriptor; import java.util.Collections; import java.util.HashSet; import java.util.Set; -import com.oracle.svm.configure.filters.RuleNode; import com.oracle.svm.configure.filters.RuleNode.Inclusion; -@SuppressWarnings("unused") public class ModuleFilterTools { public static RuleNode generateFromModules(String[] moduleNames, Inclusion rootInclusion, Inclusion exportedInclusion, Inclusion unexportedInclusion, boolean reduce) { 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.jdk17/src/com/oracle/svm/core/jdk17/Target_java_lang_Module_JDK17OrLater.java index 787a9785d78a..f8a5088d0a00 100644 --- 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.jdk17/src/com/oracle/svm/core/jdk17/Target_java_lang_Module_JDK17OrLater.java @@ -32,10 +32,10 @@ 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.jdk11.ModuleUtil; +import com.oracle.svm.core.jdk.ModuleUtil; @SuppressWarnings("unused") -@TargetClass(value = Module.class, onlyWith = JDK17OrLater.class) +@TargetClass(value = java.lang.Module.class, onlyWith = JDK17OrLater.class) public final class Target_java_lang_Module_JDK17OrLater { // Checkstyle: allow synchronization 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 3fa41b127589..bd9c4642392e 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 @@ -70,14 +70,14 @@ import com.oracle.svm.core.classinitialization.EnsureClassInitializedNode; import com.oracle.svm.core.jdk.JDK17OrLater; import com.oracle.svm.core.jdk.Resources; -import com.oracle.svm.core.jdk.Target_java_lang_Module; -import com.oracle.svm.core.jdk.Target_jdk_internal_reflect_Reflection; import com.oracle.svm.core.meta.SharedType; import com.oracle.svm.core.util.LazyFinalReference; import com.oracle.svm.core.util.VMError; import com.oracle.svm.util.ReflectionUtil; import com.oracle.svm.util.ReflectionUtil.ReflectionUtilError; +import jdk.internal.reflect.ConstantPool; +import jdk.internal.reflect.Reflection; import jdk.vm.ci.meta.JavaKind; @Hybrid(canHybridFieldsBeDuplicated = false) @@ -290,11 +290,9 @@ public final class DynamicHub implements JavaKind.FormatWithToString, AnnotatedE private AnnotatedSuperInfo annotatedSuperInfo; /** - * Field used for module information access at run-time The run time type of this field is - * java.lang.Module but can be casted to {@link Target_java_lang_Module} The module is of type - * Object to avoid ClassCastExceptions at image build time due to base module miss-match. + * Field used for module information access at run-time. */ - private Object module; + private Module module; /** * JDK 11 and later: the class that serves as the host for the nest. All nestmates have the same @@ -303,7 +301,7 @@ public final class DynamicHub implements JavaKind.FormatWithToString, AnnotatedE private final Class nestHost; @Platforms(Platform.HOSTED_ONLY.class) - public void setModule(Object module) { + public void setModule(Module module) { this.module = module; } @@ -682,7 +680,7 @@ public Enum[] getEnumConstantsShared() { @Substitute public InputStream getResourceAsStream(String resourceName) { - String moduleName = module == null ? null : SubstrateUtil.cast(module, Target_java_lang_Module.class).name; + String moduleName = module == null ? null : module.getName(); String resolvedName = resolveName(resourceName); return Resources.createInputStream(moduleName, resolvedName); } @@ -1253,17 +1251,17 @@ private Constructor getEnclosingConstructor() { @Substitute public static Class forName(String className) throws ClassNotFoundException { - Class caller = Target_jdk_internal_reflect_Reflection.getCallerClass(); + Class caller = Reflection.getCallerClass(); return forName(className, true, caller.getClassLoader()); } @Substitute // - public static Class forName(@SuppressWarnings("unused") Target_java_lang_Module module, String className) { + public static Class forName(@SuppressWarnings("unused") Module module, String className) { /* * The module system is not supported for now, therefore the module parameter is ignored and * we use the class loader of the caller class instead of the module's loader. */ - Class caller = Target_jdk_internal_reflect_Reflection.getCallerClass(); + Class caller = Reflection.getCallerClass(); try { return forName(className, false, caller.getClassLoader()); } catch (ClassNotFoundException e) { @@ -1351,8 +1349,8 @@ public boolean desiredAssertionStatus() { } @Substitute // - public Target_java_lang_Module getModule() { - return (Target_java_lang_Module) module; + public Module getModule() { + return module; } @Substitute // @@ -1504,7 +1502,7 @@ private void setSigners(@SuppressWarnings("unused") Object[] signers) { native byte[] getRawTypeAnnotations(); @Delete - native Target_jdk_internal_reflect_ConstantPool getConstantPool(); + native ConstantPool getConstantPool(); @Delete private native Field[] getDeclaredFields0(boolean publicOnly); @@ -1582,22 +1580,22 @@ final class Target_java_lang_Class_ReflectionData { // Checkstyle: resume } -@TargetClass(className = "jdk.internal.reflect.ReflectionFactory") +@TargetClass(value = jdk.internal.reflect.ReflectionFactory.class) final class Target_jdk_internal_reflect_ReflectionFactory { @Alias // private static Target_jdk_internal_reflect_ReflectionFactory soleInstance; + /** + * This substitution eliminates the SecurityManager check in the original method, which would + * make some build-time verifications fail. + */ @Substitute public static Target_jdk_internal_reflect_ReflectionFactory getReflectionFactory() { return soleInstance; } } -@TargetClass(className = "jdk.internal.reflect.ConstantPool") -final class Target_jdk_internal_reflect_ConstantPool { -} - @TargetClass(className = "java.lang.reflect.RecordComponent", onlyWith = JDK17OrLater.class) final class Target_java_lang_reflect_RecordComponent { } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/BootModuleLayerSupport.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/BootModuleLayerSupport.java similarity index 98% rename from substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/BootModuleLayerSupport.java rename to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/BootModuleLayerSupport.java index 502265882b6e..08776be5d837 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/BootModuleLayerSupport.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/BootModuleLayerSupport.java @@ -22,7 +22,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package com.oracle.svm.core.jdk11; +package com.oracle.svm.core.jdk; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.Platform; diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/JDKVersionSpecificResourceBuilderJDK11OrLater.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDKVersionSpecificResourceBuilderJDK11OrLater.java similarity index 96% rename from substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/JDKVersionSpecificResourceBuilderJDK11OrLater.java rename to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDKVersionSpecificResourceBuilderJDK11OrLater.java index 8a1b7a527a9d..3f1332ea9d02 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/JDKVersionSpecificResourceBuilderJDK11OrLater.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDKVersionSpecificResourceBuilderJDK11OrLater.java @@ -23,7 +23,7 @@ * questions. */ -package com.oracle.svm.core.jdk11; +package com.oracle.svm.core.jdk; import java.io.IOException; import java.io.InputStream; @@ -34,7 +34,6 @@ import org.graalvm.nativeimage.hosted.Feature; import com.oracle.svm.core.annotate.AutomaticFeature; -import com.oracle.svm.core.jdk.JDKVersionSpecificResourceBuilder; public class JDKVersionSpecificResourceBuilderJDK11OrLater implements JDKVersionSpecificResourceBuilder { 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 e222fc87b72a..7e53ec2e7a24 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 @@ -36,6 +36,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.function.BooleanSupplier; +import java.util.stream.Stream; import org.graalvm.compiler.replacements.nodes.BinaryMathIntrinsicNode; import org.graalvm.compiler.replacements.nodes.BinaryMathIntrinsicNode.BinaryOperation; @@ -64,6 +65,7 @@ import com.oracle.svm.core.annotate.TargetClass; import com.oracle.svm.core.annotate.TargetElement; import com.oracle.svm.core.annotate.Uninterruptible; +import com.oracle.svm.core.hub.ClassForNameSupport; import com.oracle.svm.core.hub.DynamicHub; import com.oracle.svm.core.jdk.JavaLangSubstitutions.ClassValueSupport; import com.oracle.svm.core.monitor.MonitorSupport; @@ -640,12 +642,67 @@ private String getExtendedNPEMessage() { } } -@TargetClass(className = "jdk.internal.loader.ClassLoaders") +@TargetClass(value = jdk.internal.loader.ClassLoaders.class) final class Target_jdk_internal_loader_ClassLoaders { + @Alias + static native Target_jdk_internal_loader_BuiltinClassLoader bootLoader(); + @Alias public static native ClassLoader platformClassLoader(); } +@TargetClass(value = jdk.internal.loader.BootLoader.class) +final class Target_jdk_internal_loader_BootLoader { + + @Substitute + static Package getDefinedPackage(String name) { + if (name != null) { + Target_java_lang_Package pkg = new Target_java_lang_Package(name, null, null, null, + null, null, null, null, null); + return SubstrateUtil.cast(pkg, Package.class); + } else { + return null; + } + } + + @Substitute + public static Stream packages() { + Target_jdk_internal_loader_BuiltinClassLoader bootClassLoader = Target_jdk_internal_loader_ClassLoaders.bootLoader(); + Target_java_lang_ClassLoader systemClassLoader = SubstrateUtil.cast(bootClassLoader, Target_java_lang_ClassLoader.class); + return systemClassLoader.packages(); + } + + @Delete("only used by #packages()") + private static native String[] getSystemPackageNames(); + + @Substitute + private static Class loadClassOrNull(String name) { + return ClassForNameSupport.forNameOrNull(name, null); + } + + @SuppressWarnings("unused") + @Substitute + private static Class loadClass(Module module, String name) { + /* The module system is not supported for now, therefore the module parameter is ignored. */ + return ClassForNameSupport.forNameOrNull(name, null); + } + + @Substitute + private static boolean hasClassPath() { + return true; + } + + /** + * All ClassLoaderValue are reset at run time for now. See also + * {@link Target_java_lang_ClassLoader#classLoaderValueMap} for resetting of individual class + * loaders. + */ + // Checkstyle: stop + @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.NewInstance, declClass = ConcurrentHashMap.class)// + static ConcurrentHashMap CLASS_LOADER_VALUE_MAP; + // Checkstyle: resume +} + /** Dummy class to have a class with the file's name. */ public final class JavaLangSubstitutions { diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/JavaNetHttpFeature.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JavaNetHttpFeature.java similarity index 96% rename from substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/JavaNetHttpFeature.java rename to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JavaNetHttpFeature.java index 0c228dc16d5e..0d9e789ee287 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/JavaNetHttpFeature.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JavaNetHttpFeature.java @@ -22,13 +22,12 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package com.oracle.svm.core.jdk11; +package com.oracle.svm.core.jdk; import org.graalvm.nativeimage.hosted.Feature; import org.graalvm.nativeimage.hosted.RuntimeReflection; import com.oracle.svm.core.annotate.AutomaticFeature; -import com.oracle.svm.core.jdk.JNIRegistrationUtil; @AutomaticFeature public class JavaNetHttpFeature extends JNIRegistrationUtil implements Feature { diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/ModuleUtil.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/ModuleUtil.java similarity index 99% rename from substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/ModuleUtil.java rename to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/ModuleUtil.java index 91926780de73..50473981899a 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/ModuleUtil.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/ModuleUtil.java @@ -22,11 +22,8 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package com.oracle.svm.core.jdk11; +package com.oracle.svm.core.jdk; -import com.oracle.svm.core.SubstrateUtil; - -import javax.lang.model.SourceVersion; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -35,6 +32,10 @@ import java.util.Set; import java.util.stream.Collectors; +import javax.lang.model.SourceVersion; + +import com.oracle.svm.core.SubstrateUtil; + public final class ModuleUtil { private ModuleUtil() { } 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 94388e850856..5357cfc4e729 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 @@ -34,6 +34,7 @@ import java.util.Set; import java.util.Vector; import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Stream; import com.oracle.svm.core.SubstrateUtil; import com.oracle.svm.core.annotate.Alias; @@ -45,6 +46,7 @@ import com.oracle.svm.core.annotate.TargetElement; import com.oracle.svm.core.hub.ClassForNameSupport; import com.oracle.svm.core.hub.PredefinedClassesSupport; +import com.oracle.svm.core.util.LazyFinalReference; import com.oracle.svm.core.util.VMError; import jdk.vm.ci.meta.MetaAccessProvider; @@ -176,7 +178,7 @@ static void checkClassLoaderPermission(ClassLoader cl, Class caller) { @Substitute // @SuppressWarnings("unused") - Class loadClass(Target_java_lang_Module module, String name) { + Class loadClass(Module module, String name) { /* The module system is not supported for now, therefore the module parameter is ignored. */ try { return loadClass(name, false); @@ -200,6 +202,22 @@ private Class findLoadedClass0(String name) { return ClassForNameSupport.forNameOrNull(name, SubstrateUtil.cast(this, ClassLoader.class)); } + /** + * All ClassLoaderValue are reset at run time for now. See also + * {@link Target_jdk_internal_loader_BootLoader#CLASS_LOADER_VALUE_MAP} for resetting of the + * boot class loader. + */ + @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.NewInstance, declClass = ConcurrentHashMap.class)// + ConcurrentHashMap classLoaderValueMap; + + @Alias + native Stream packages(); + + @SuppressWarnings("static-method") + @Substitute + public Target_java_lang_Module getUnnamedModule() { + return ClassLoaderUtil.unnamedModuleReference.get(); + } /* * The assertion status of classes is fixed at image build time because it is baked into the AOT * compiled code. All methods that modify the assertion status are substituted to throw an @@ -379,10 +397,6 @@ final class Target_java_lang_ClassLoader_NativeLibrary { final class Target_java_lang_AssertionStatusDirectives { } -@TargetClass(className = "java.lang.NamedPackage") // -final class Target_java_lang_NamedPackage { -} - class PackageFieldTransformer implements RecomputeFieldValue.CustomFieldValueTransformer { @Override public RecomputeFieldValue.ValueAvailability valueAvailability() { @@ -406,3 +420,8 @@ public Object transform(MetaAccessProvider metaAccess, ResolvedJavaField origina } } } + +final class ClassLoaderUtil { + + public static final LazyFinalReference unnamedModuleReference = new LazyFinalReference<>(Target_java_lang_Module::new); +} 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 62bd3f450bab..d20f7dc38e83 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 @@ -24,12 +24,65 @@ */ package com.oracle.svm.core.jdk; +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.util.Arrays; +import java.util.Objects; + 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.annotate.TargetElement; +import com.oracle.svm.core.jdk.resources.ResourceStorageEntry; @SuppressWarnings("unused") -@TargetClass(className = "java.lang.Module") -public final class Target_java_lang_Module { +@TargetClass(value = java.lang.Module.class) +final class Target_java_lang_Module { + @Alias // - public String name; + private String name; + + @SuppressWarnings("static-method") + @Substitute + private InputStream getResourceAsStream(String resourceName) { + ResourceStorageEntry res = Resources.get(name, 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 addReads0(Module from, Module to) { + if (Objects.isNull(from)) { + throw new NullPointerException("from_module is null"); + } + } + + @Substitute + private static void addExports0(Module from, String pn, Module to) { + if (Objects.isNull(to)) { + throw new NullPointerException("to_module is null"); + } + + ModuleUtil.checkFromModuleAndPackageNullability(from, pn); + ModuleUtil.checkIsPackageContainedInModule(pn, from); + } + + @Substitute + private static void addExportsToAll0(Module from, String pn) { + ModuleUtil.checkFromModuleAndPackageNullability(from, pn); + ModuleUtil.checkIsPackageContainedInModule(pn, from); + } + + @Substitute + private static void addExportsToAllUnnamed0(Module from, String pn) { + ModuleUtil.checkFromModuleAndPackageNullability(from, pn); + if (from.isNamed()) { + ModuleUtil.checkIsPackageContainedInModule(pn, from); + } + } } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/Target_java_lang_ModuleLayer.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_ModuleLayer.java similarity index 97% rename from substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/Target_java_lang_ModuleLayer.java rename to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_ModuleLayer.java index 7a00170378cc..9f091def7d90 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/Target_java_lang_ModuleLayer.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_ModuleLayer.java @@ -22,7 +22,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package com.oracle.svm.core.jdk11; +package com.oracle.svm.core.jdk; import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/Target_java_lang_ClassLoader.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_Module_ReflectionData.java similarity index 56% rename from substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/Target_java_lang_ClassLoader.java rename to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_Module_ReflectionData.java index e3a6979fea5b..89ce46f5f310 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/Target_java_lang_ClassLoader.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_Module_ReflectionData.java @@ -22,44 +22,23 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package com.oracle.svm.core.jdk11; +package com.oracle.svm.core.jdk; -import java.util.concurrent.ConcurrentHashMap; -import java.util.stream.Stream; +import java.util.Map; import com.oracle.svm.core.annotate.Alias; 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.util.LazyFinalReference; -@SuppressWarnings({"unused"}) -@TargetClass(value = ClassLoader.class) -public final class Target_java_lang_ClassLoader { +@TargetClass(value = Module.class, innerClass = "ReflectionData") // +final class Target_java_lang_Module_ReflectionData { - /** - * All ClassLoaderValue are reset at run time for now. See also - * {@link Target_jdk_internal_loader_BootLoader#CLASS_LOADER_VALUE_MAP} for resetting of the - * boot class loader. - */ - @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.NewInstance, declClass = ConcurrentHashMap.class)// - ConcurrentHashMap classLoaderValueMap; + @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.NewInstance, declClassName = "java.lang.WeakPairMap") // + private static Target_java_lang_WeakPairMap reads; - @Alias - native Stream packages(); + @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.NewInstance, declClassName = "java.lang.WeakPairMap") // + private static Target_java_lang_WeakPairMap> exports; - @SuppressWarnings("static-method") - @Substitute - public Target_java_lang_Module getUnnamedModule() { - return ClassLoaderUtil.unnamedModuleReference.get(); - } - - @Alias - protected native Class findLoadedClass(String name); - -} - -final class ClassLoaderUtil { - - public static final LazyFinalReference unnamedModuleReference = new LazyFinalReference<>(Target_java_lang_Module::new); + @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.NewInstance, declClassName = "java.lang.WeakPairMap") // + private static Target_java_lang_WeakPairMap, Boolean> uses; } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/Target_java_lang_NamedPackage.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_NamedPackage.java similarity index 97% rename from substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/Target_java_lang_NamedPackage.java rename to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_NamedPackage.java index 2d4dff5da0f4..b265503b8071 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/Target_java_lang_NamedPackage.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_NamedPackage.java @@ -22,7 +22,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package com.oracle.svm.core.jdk11; +package com.oracle.svm.core.jdk; import com.oracle.svm.core.annotate.Alias; import com.oracle.svm.core.annotate.TargetClass; diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_Package.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_Package.java index f05d65cab903..3e9f48586d12 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_Package.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_Package.java @@ -31,10 +31,10 @@ @SuppressWarnings({"unused"}) @TargetClass(Package.class) -public final class Target_java_lang_Package { +final class Target_java_lang_Package { @Alias - public Target_java_lang_Package(String name, + Target_java_lang_Package(String name, String spectitle, String specversion, String specvendor, String impltitle, String implversion, String implvendor, URL sealbase, ClassLoader loader) { diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/Target_java_lang_StackWalker.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_StackWalker.java similarity index 99% rename from substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/Target_java_lang_StackWalker.java rename to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_StackWalker.java index 4ee06a7a8685..1b881e39788f 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/Target_java_lang_StackWalker.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_StackWalker.java @@ -23,7 +23,7 @@ * questions. */ -package com.oracle.svm.core.jdk11; +package com.oracle.svm.core.jdk; import java.lang.StackWalker.Option; import java.lang.StackWalker.StackFrame; @@ -57,8 +57,6 @@ import com.oracle.svm.core.deopt.Deoptimizer; import com.oracle.svm.core.heap.StoredContinuation; import com.oracle.svm.core.heap.StoredContinuationImpl; -import com.oracle.svm.core.jdk.LoomJDK; -import com.oracle.svm.core.jdk.StackTraceUtils; import com.oracle.svm.core.snippets.KnownIntrinsics; import com.oracle.svm.core.stack.JavaStackFrameVisitor; import com.oracle.svm.core.stack.JavaStackWalk; diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/Target_java_lang_WeakPairMap.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_WeakPairMap.java similarity index 97% rename from substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/Target_java_lang_WeakPairMap.java rename to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_WeakPairMap.java index 2229872a5851..c1310a772678 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/Target_java_lang_WeakPairMap.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_WeakPairMap.java @@ -22,7 +22,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package com.oracle.svm.core.jdk11; +package com.oracle.svm.core.jdk; import com.oracle.svm.core.annotate.TargetClass; diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/Target_java_util_ServiceLoader.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_util_ServiceLoader.java similarity index 99% rename from substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/Target_java_util_ServiceLoader.java rename to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_util_ServiceLoader.java index 47399db6e6df..f21d43eac2bd 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/Target_java_util_ServiceLoader.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_util_ServiceLoader.java @@ -23,7 +23,7 @@ * questions. */ -package com.oracle.svm.core.jdk11; +package com.oracle.svm.core.jdk; // Checkstyle: allow reflection diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/Target_java_util_logging_SimpleFormatter.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_util_logging_SimpleFormatter.java similarity index 98% rename from substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/Target_java_util_logging_SimpleFormatter.java rename to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_util_logging_SimpleFormatter.java index 00bdf97c4efc..53f684fcdb7e 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/Target_java_util_logging_SimpleFormatter.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_util_logging_SimpleFormatter.java @@ -22,7 +22,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package com.oracle.svm.core.jdk11; +package com.oracle.svm.core.jdk; //Checkstyle: allow reflection diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/Target_java_util_zip_ZipFile.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_util_zip_ZipFile.java similarity index 98% rename from substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/Target_java_util_zip_ZipFile.java rename to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_util_zip_ZipFile.java index e6fe67f2f740..bfaa4908f346 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/Target_java_util_zip_ZipFile.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_util_zip_ZipFile.java @@ -22,7 +22,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package com.oracle.svm.core.jdk11; +package com.oracle.svm.core.jdk; import java.util.HashMap; import java.util.zip.ZipFile; diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/Target_jdk_internal_loader_BuiltinClassLoader.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_loader_BuiltinClassLoader.java similarity index 97% rename from substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/Target_jdk_internal_loader_BuiltinClassLoader.java rename to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_loader_BuiltinClassLoader.java index 458befd5d457..3d084aa18f9a 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/Target_jdk_internal_loader_BuiltinClassLoader.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_loader_BuiltinClassLoader.java @@ -22,7 +22,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package com.oracle.svm.core.jdk11; +package com.oracle.svm.core.jdk; import java.io.IOException; import java.io.InputStream; @@ -34,7 +34,6 @@ 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.jdk.ResourcesHelper; @TargetClass(value = jdk.internal.loader.BuiltinClassLoader.class) @SuppressWarnings({"unused", "static-method"}) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_reflect_Reflection.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_reflect_Reflection.java index 0f0b2f4f82d7..e5c7850edbee 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_reflect_Reflection.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_reflect_Reflection.java @@ -30,12 +30,12 @@ import com.oracle.svm.core.hub.DynamicHub; import com.oracle.svm.core.snippets.KnownIntrinsics; -@TargetClass(className = "jdk.internal.reflect.Reflection") -public final class Target_jdk_internal_reflect_Reflection { +@TargetClass(value = jdk.internal.reflect.Reflection.class) +final class Target_jdk_internal_reflect_Reflection { @Substitute @NeverInline("Starting a stack walk in the caller frame") - public static Class getCallerClass() { + private static Class getCallerClass() { return StackTraceUtils.getCallerClass(KnownIntrinsics.readCallerStackPointer(), true); } @@ -44,7 +44,7 @@ private static int getClassAccessFlags(Class cls) { return cls.getModifiers(); } - @Substitute // + @Substitute private static boolean areNestMates(Class currentClass, Class memberClass) { return DynamicHub.fromClass(currentClass).isNestmateOf(memberClass); } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/Target_sun_misc_Unsafe.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_sun_misc_Unsafe.java similarity index 93% rename from substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/Target_sun_misc_Unsafe.java rename to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_sun_misc_Unsafe.java index 605abd609961..4e566fff6d52 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/Target_sun_misc_Unsafe.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_sun_misc_Unsafe.java @@ -22,7 +22,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package com.oracle.svm.core.jdk11; +package com.oracle.svm.core.jdk; import com.oracle.svm.core.annotate.Alias; import com.oracle.svm.core.annotate.RecomputeFieldValue; @@ -30,9 +30,9 @@ import com.oracle.svm.core.annotate.TargetClass; /** - * These substitutions are necessary because in JDK 11 the static initializations of these fields - * are copies of the corresponding (recomputed) fields of {@link jdk.internal.misc.Unsafe}. But - * copying a recomputed value during image building does not recompute the value. See GR-12640. + * These substitutions are necessary because the static initializations of these fields are copies + * of the corresponding (recomputed) fields of {@link jdk.internal.misc.Unsafe}. But copying a + * recomputed value during image building does not recompute the value. See GR-12640. */ @TargetClass(value = sun.misc.Unsafe.class) final class Target_sun_misc_Unsafe { diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_util_ResourceBundle.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_util_ResourceBundle.java index 4cf500543839..9d406330db8b 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_util_ResourceBundle.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_util_ResourceBundle.java @@ -24,6 +24,13 @@ */ package com.oracle.svm.core.jdk.localization.substitutions; +import java.util.Locale; +import java.util.ResourceBundle; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + +import org.graalvm.nativeimage.ImageSingletons; + import com.oracle.svm.core.annotate.Alias; import com.oracle.svm.core.annotate.RecomputeFieldValue; import com.oracle.svm.core.annotate.Substitute; @@ -31,12 +38,6 @@ import com.oracle.svm.core.annotate.TargetElement; import com.oracle.svm.core.jdk.localization.LocalizationSupport; import com.oracle.svm.core.jdk.localization.substitutions.modes.OptimizedLocaleMode; -import org.graalvm.nativeimage.ImageSingletons; - -import java.util.Locale; -import java.util.ResourceBundle; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; @TargetClass(java.util.ResourceBundle.class) @SuppressWarnings({"unused"}) @@ -80,4 +81,21 @@ private static ResourceBundle getBundle(String baseName, Locale locale, ClassLoa private static ResourceBundle getBundle(String baseName, Locale targetLocale, ClassLoader loader, ResourceBundle.Control control) { return ImageSingletons.lookup(LocalizationSupport.class).asOptimizedSupport().getCached(baseName, targetLocale); } + + /** + * Currently there is no support for the module system at run time. Module arguments are + * therefore ignored. + */ + + @Substitute + @TargetElement(onlyWith = OptimizedLocaleMode.class) + private static ResourceBundle getBundle(String baseName, @SuppressWarnings("unused") Module module) { + return ImageSingletons.lookup(LocalizationSupport.class).asOptimizedSupport().getCached(baseName, Locale.getDefault()); + } + + @Substitute + @TargetElement(onlyWith = OptimizedLocaleMode.class) + private static ResourceBundle getBundle(String baseName, Locale targetLocale, @SuppressWarnings("unused") Module module) { + return ImageSingletons.lookup(LocalizationSupport.class).asOptimizedSupport().getCached(baseName, targetLocale); + } } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/localization/substitutions/Target_sun_util_resources_Bundles.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_resources_Bundles.java similarity index 97% rename from substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/localization/substitutions/Target_sun_util_resources_Bundles.java rename to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_resources_Bundles.java index 7ce67de65995..9712a0b06884 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/localization/substitutions/Target_sun_util_resources_Bundles.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_resources_Bundles.java @@ -22,7 +22,9 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package com.oracle.svm.core.jdk11.localization.substitutions; +package com.oracle.svm.core.jdk.localization.substitutions; + +// Checkstyle: stop import java.util.Locale; import java.util.ResourceBundle; @@ -39,8 +41,8 @@ import com.oracle.svm.core.jdk.localization.LocalizationSupport; import com.oracle.svm.core.jdk.localization.substitutions.modes.OptimizedLocaleMode; -// Checkstyle: stop import sun.util.resources.Bundles.Strategy; + // Checkstyle: resume @TargetClass(value = sun.util.resources.Bundles.class) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/JavaLangSubstitutions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/JavaLangSubstitutions.java deleted file mode 100644 index 063cb8fdad04..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/JavaLangSubstitutions.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2021, 2021, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2021, 2021, Red Hat Inc. 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.jdk11; - -import java.util.concurrent.ConcurrentHashMap; -import java.util.stream.Stream; - -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.RecomputeFieldValue; -import com.oracle.svm.core.annotate.Substitute; -import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.hub.ClassForNameSupport; -import com.oracle.svm.core.jdk.Target_java_lang_Package; - -@TargetClass(value = jdk.internal.loader.ClassLoaders.class) -final class Target_jdk_internal_loader_ClassLoaders { - @Alias - static native Target_jdk_internal_loader_BuiltinClassLoader bootLoader(); - - @Alias - public static native ClassLoader platformClassLoader(); -} - -@TargetClass(value = jdk.internal.loader.BootLoader.class) -final class Target_jdk_internal_loader_BootLoader { - - @Substitute - static Package getDefinedPackage(String name) { - if (name != null) { - Target_java_lang_Package pkg = new Target_java_lang_Package(name, null, null, null, - null, null, null, null, null); - return SubstrateUtil.cast(pkg, Package.class); - } else { - return null; - } - } - - @Substitute - public static Stream packages() { - Target_jdk_internal_loader_BuiltinClassLoader bootClassLoader = Target_jdk_internal_loader_ClassLoaders.bootLoader(); - Target_java_lang_ClassLoader systemClassLoader = SubstrateUtil.cast(bootClassLoader, Target_java_lang_ClassLoader.class); - return systemClassLoader.packages(); - } - - @Delete("only used by #packages()") - private static native String[] getSystemPackageNames(); - - @Substitute - private static Class loadClassOrNull(String name) { - return ClassForNameSupport.forNameOrNull(name, null); - } - - @SuppressWarnings("unused") - @Substitute - private static Class loadClass(Target_java_lang_Module module, String name) { - /* The module system is not supported for now, therefore the module parameter is ignored. */ - return ClassForNameSupport.forNameOrNull(name, null); - } - - @Substitute - private static boolean hasClassPath() { - return true; - } - - /** - * All ClassLoaderValue are reset at run time for now. See also - * {@link Target_java_lang_ClassLoader#classLoaderValueMap} for resetting of individual class - * loaders. - */ - // Checkstyle: stop - @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.NewInstance, declClass = ConcurrentHashMap.class)// - static ConcurrentHashMap CLASS_LOADER_VALUE_MAP; - // Checkstyle: resume -} - -/** Dummy class to have a class with the file's name. */ -public final class JavaLangSubstitutions { - -} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/Target_java_lang_Module.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/Target_java_lang_Module.java deleted file mode 100644 index 95c0d594ac88..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/Target_java_lang_Module.java +++ /dev/null @@ -1,104 +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.jdk11; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.util.Arrays; -import java.util.Map; -import java.util.Objects; - -import com.oracle.svm.core.annotate.Alias; -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.Resources; -import com.oracle.svm.core.jdk.resources.ResourceStorageEntry; - -@SuppressWarnings("unused") -@TargetClass(value = java.lang.Module.class) -public final class Target_java_lang_Module { - - @Alias private String name; - - @SuppressWarnings("static-method") - @Substitute - public InputStream getResourceAsStream(String resourceName) { - ResourceStorageEntry res = Resources.get(name, 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 addReads0(Module from, Module to) { - if (Objects.isNull(from)) { - throw new NullPointerException("from_module is null"); - } - } - - @Substitute - private static void addExports0(Module from, String pn, Module to) { - if (Objects.isNull(to)) { - throw new NullPointerException("to_module is null"); - } - - ModuleUtil.checkFromModuleAndPackageNullability(from, pn); - ModuleUtil.checkIsPackageContainedInModule(pn, from); - } - - @Substitute - private static void addExportsToAll0(Module from, String pn) { - ModuleUtil.checkFromModuleAndPackageNullability(from, pn); - ModuleUtil.checkIsPackageContainedInModule(pn, from); - } - - @Substitute - private static void addExportsToAllUnnamed0(Module from, String pn) { - ModuleUtil.checkFromModuleAndPackageNullability(from, pn); - if (from.isNamed()) { - ModuleUtil.checkIsPackageContainedInModule(pn, from); - } - } - - @TargetClass(className = "java.lang.Module", innerClass = "ReflectionData") // - private static final class Target_java_lang_Module_ReflectionData { - - @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.NewInstance, declClassName = "java.lang.WeakPairMap") // - static Target_java_lang_WeakPairMap reads; - - @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.NewInstance, declClassName = "java.lang.WeakPairMap") // - static Target_java_lang_WeakPairMap> exports; - - @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.NewInstance, declClassName = "java.lang.WeakPairMap") // - static Target_java_lang_WeakPairMap, Boolean> uses; - } -} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/localization/substitutions/Target_java_util_ResourceBundle.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/localization/substitutions/Target_java_util_ResourceBundle.java deleted file mode 100644 index 6cbfef5badb9..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk11/localization/substitutions/Target_java_util_ResourceBundle.java +++ /dev/null @@ -1,55 +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.jdk11.localization.substitutions; - -import java.util.Locale; -import java.util.ResourceBundle; - -import org.graalvm.nativeimage.ImageSingletons; - -import com.oracle.svm.core.annotate.Substitute; -import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.jdk.localization.LocalizationSupport; -import com.oracle.svm.core.jdk.localization.substitutions.modes.OptimizedLocaleMode; -import com.oracle.svm.core.jdk11.Target_java_lang_Module; - -@TargetClass(value = java.util.ResourceBundle.class, onlyWith = OptimizedLocaleMode.class) -public final class Target_java_util_ResourceBundle { - - /** - * Currently there is no support for the module system at run time. Module arguments are - * therefore ignored. - */ - - @Substitute - private static ResourceBundle getBundle(String baseName, @SuppressWarnings("unused") Target_java_lang_Module module) { - return ImageSingletons.lookup(LocalizationSupport.class).asOptimizedSupport().getCached(baseName, Locale.getDefault()); - } - - @Substitute - private static ResourceBundle getBundle(String baseName, Locale targetLocale, @SuppressWarnings("unused") Target_java_lang_Module module) { - return ImageSingletons.lookup(LocalizationSupport.class).asOptimizedSupport().getCached(baseName, targetLocale); - } -} diff --git a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java index b071f70e5c70..bc2c934c5ec8 100644 --- a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java +++ b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java @@ -93,7 +93,7 @@ public class NativeImage { private static final String DEFAULT_GENERATOR_CLASS_NAME = NativeImageGeneratorRunner.class.getName(); - private static final String DEFAULT_GENERATOR_MODULE_NAME = ModuleSupport.getModuleName(NativeImageGeneratorRunner.class); + private static final String DEFAULT_GENERATOR_MODULE_NAME = NativeImageGeneratorRunner.class.getModule().getName(); private static final String DEFAULT_GENERATOR_9PLUS_SUFFIX = "$JDK9Plus"; private static final String CUSTOM_SYSTEM_CLASS_LOADER = NativeImageSystemClassLoader.class.getCanonicalName(); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/FallbackFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/FallbackFeature.java index ee44ae1b9969..8e8375fa8c0f 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/FallbackFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/FallbackFeature.java @@ -26,6 +26,9 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import java.lang.module.ModuleDescriptor; +import java.lang.module.ModuleFinder; +import java.lang.module.ModuleReference; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; @@ -34,6 +37,7 @@ import java.util.List; import java.util.Objects; import java.util.Set; +import java.util.stream.Collectors; import org.graalvm.nativeimage.hosted.Feature; @@ -46,7 +50,6 @@ import com.oracle.svm.core.util.VMError; import com.oracle.svm.hosted.FeatureImpl.AfterAnalysisAccessImpl; import com.oracle.svm.hosted.FeatureImpl.BeforeAnalysisAccessImpl; -import com.oracle.svm.util.ModuleSupport; import jdk.vm.ci.code.BytecodePosition; import jdk.vm.ci.meta.ResolvedJavaMethod; @@ -63,7 +66,9 @@ public class FallbackFeature implements Feature { private final List proxyCalls = new ArrayList<>(); private final List serializationCalls = new ArrayList<>(); - private final Set systemModuleDescriptors = ModuleSupport.getSystemModuleDescriptors(); + private final Set systemModuleDescriptors = ModuleFinder.ofSystem().findAll().stream() + .map(ModuleReference::descriptor) + .collect(Collectors.toSet()); private static class AutoProxyInvoke { private final ResolvedJavaMethod method; @@ -124,7 +129,7 @@ void trackMethod(AnalysisMetaAccess metaAccess) { void apply(BytecodePosition invokeLocation) { Class javaClass = ((AnalysisMethod) invokeLocation.getMethod()).getDeclaringClass().getJavaClass(); - if (systemModuleDescriptors.contains(ModuleSupport.getModuleDescriptor(javaClass))) { + if (systemModuleDescriptors.contains(javaClass.getModule().getDescriptor())) { /* Ensure all JDK system modules are excluded from reporting reflection use. */ return; } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ModuleLayerFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ModuleLayerFeature.java index 198f632c216d..26ab03dc48aa 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ModuleLayerFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ModuleLayerFeature.java @@ -59,7 +59,7 @@ import com.oracle.svm.core.SubstrateUtil; import com.oracle.svm.core.annotate.AutomaticFeature; import com.oracle.svm.core.hub.DynamicHub; -import com.oracle.svm.core.jdk11.BootModuleLayerSupport; +import com.oracle.svm.core.jdk.BootModuleLayerSupport; import com.oracle.svm.core.util.VMError; import com.oracle.svm.hosted.jdk.NativeImageClassLoaderSupportJDK11OrLater; import com.oracle.svm.util.ModuleSupport; diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/sources/SourceCache.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/sources/SourceCache.java index a186bd401955..51611d90ae17 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/sources/SourceCache.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/sources/SourceCache.java @@ -47,7 +47,6 @@ import com.oracle.svm.core.option.OptionUtils; import com.oracle.svm.hosted.FeatureImpl; import com.oracle.svm.hosted.ImageClassLoader; -import com.oracle.svm.util.ModuleSupport; /** * An abstract cache manager for some subspace of the JDK, GraalVM or application source file space. @@ -297,7 +296,7 @@ protected Path tryCacheFile(Path filePath, Class clazz) { String moduleName = null; if (clazz != null) { /* Paths require the module name as prefix */ - moduleName = ModuleSupport.getModuleName(clazz); + moduleName = clazz.getModule().getName(); } if (moduleName != null) { @@ -361,7 +360,7 @@ protected Path checkCacheFile(Path filePath, Class clazz) { String moduleName = null; if (clazz != null) { /* Paths require the module name as prefix */ - moduleName = ModuleSupport.getModuleName(clazz); + moduleName = clazz.getModule().getName(); } if (moduleName != null) { diff --git a/substratevm/src/com.oracle.svm.test/src/META-INF/native-image/com.oracle.svm.test/native-image.properties b/substratevm/src/com.oracle.svm.test/src/META-INF/native-image/com.oracle.svm.test/native-image.properties index 0257c250d150..a7ab262819b5 100644 --- a/substratevm/src/com.oracle.svm.test/src/META-INF/native-image/com.oracle.svm.test/native-image.properties +++ b/substratevm/src/com.oracle.svm.test/src/META-INF/native-image/com.oracle.svm.test/native-image.properties @@ -1 +1 @@ -Args = --initialize-at-run-time=com.oracle.svm.test --initialize-at-build-time=com.oracle.svm.test.AbstractClassSerializationTest,com.oracle.svm.test.SerializationRegistrationTest --features=com.oracle.svm.test.SerializationRegistrationTestFeature -H:+AllowVMInspection +Args=--initialize-at-run-time=com.oracle.svm.test --initialize-at-build-time=com.oracle.svm.test.AbstractClassSerializationTest,com.oracle.svm.test.SerializationRegistrationTest --features=com.oracle.svm.test.SerializationRegistrationTestFeature -H:+AllowVMInspection --features=com.oracle.svm.test.AbstractServiceLoaderTest$TestFeature,com.oracle.svm.test.NoProviderConstructorServiceLoaderTest$TestFeature diff --git a/substratevm/src/com.oracle.svm.test/src/META-INF/native-image/com/oracle/svm/test/jdk11/native-image.properties b/substratevm/src/com.oracle.svm.test/src/META-INF/native-image/com/oracle/svm/test/jdk11/native-image.properties deleted file mode 100644 index 0f603009f8ac..000000000000 --- a/substratevm/src/com.oracle.svm.test/src/META-INF/native-image/com/oracle/svm/test/jdk11/native-image.properties +++ /dev/null @@ -1 +0,0 @@ -Args = --features=com.oracle.svm.test.jdk11.AbstractServiceLoaderTest$TestFeature,com.oracle.svm.test.jdk11.NoProviderConstructorServiceLoaderTest$TestFeature diff --git a/substratevm/src/com.oracle.svm.test/src/META-INF/services/com.oracle.svm.test.AbstractServiceLoaderTest$ServiceInterface b/substratevm/src/com.oracle.svm.test/src/META-INF/services/com.oracle.svm.test.AbstractServiceLoaderTest$ServiceInterface new file mode 100644 index 000000000000..2a453fda35a1 --- /dev/null +++ b/substratevm/src/com.oracle.svm.test/src/META-INF/services/com.oracle.svm.test.AbstractServiceLoaderTest$ServiceInterface @@ -0,0 +1,2 @@ +com.oracle.svm.test.AbstractServiceLoaderTest$ConcreteService +com.oracle.svm.test.AbstractServiceLoaderTest$AbstractService diff --git a/substratevm/src/com.oracle.svm.test/src/META-INF/services/com.oracle.svm.test.NoProviderConstructorServiceLoaderTest$ServiceInterface b/substratevm/src/com.oracle.svm.test/src/META-INF/services/com.oracle.svm.test.NoProviderConstructorServiceLoaderTest$ServiceInterface new file mode 100644 index 000000000000..b1a8b1378090 --- /dev/null +++ b/substratevm/src/com.oracle.svm.test/src/META-INF/services/com.oracle.svm.test.NoProviderConstructorServiceLoaderTest$ServiceInterface @@ -0,0 +1,2 @@ +com.oracle.svm.test.NoProviderConstructorServiceLoaderTest$ProperService +com.oracle.svm.test.NoProviderConstructorServiceLoaderTest$NoProviderConstructorService diff --git a/substratevm/src/com.oracle.svm.test/src/META-INF/services/com.oracle.svm.test.jdk11.AbstractServiceLoaderTest$ServiceInterface b/substratevm/src/com.oracle.svm.test/src/META-INF/services/com.oracle.svm.test.jdk11.AbstractServiceLoaderTest$ServiceInterface deleted file mode 100644 index 306218667c62..000000000000 --- a/substratevm/src/com.oracle.svm.test/src/META-INF/services/com.oracle.svm.test.jdk11.AbstractServiceLoaderTest$ServiceInterface +++ /dev/null @@ -1,2 +0,0 @@ -com.oracle.svm.test.jdk11.AbstractServiceLoaderTest$ConcreteService -com.oracle.svm.test.jdk11.AbstractServiceLoaderTest$AbstractService diff --git a/substratevm/src/com.oracle.svm.test/src/META-INF/services/com.oracle.svm.test.jdk11.NoProviderConstructorServiceLoaderTest$ServiceInterface b/substratevm/src/com.oracle.svm.test/src/META-INF/services/com.oracle.svm.test.jdk11.NoProviderConstructorServiceLoaderTest$ServiceInterface deleted file mode 100644 index 1fc7964f1376..000000000000 --- a/substratevm/src/com.oracle.svm.test/src/META-INF/services/com.oracle.svm.test.jdk11.NoProviderConstructorServiceLoaderTest$ServiceInterface +++ /dev/null @@ -1,2 +0,0 @@ -com.oracle.svm.test.jdk11.NoProviderConstructorServiceLoaderTest$ProperService -com.oracle.svm.test.jdk11.NoProviderConstructorServiceLoaderTest$NoProviderConstructorService diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/AbstractServiceLoaderTest.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/AbstractServiceLoaderTest.java similarity index 99% rename from substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/AbstractServiceLoaderTest.java rename to substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/AbstractServiceLoaderTest.java index ec31c327a764..19868f01c643 100644 --- a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/AbstractServiceLoaderTest.java +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/AbstractServiceLoaderTest.java @@ -22,7 +22,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package com.oracle.svm.test.jdk11; +package com.oracle.svm.test; import java.util.HashSet; import java.util.ServiceConfigurationError; diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/NoProviderConstructorServiceLoaderTest.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/NoProviderConstructorServiceLoaderTest.java similarity index 99% rename from substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/NoProviderConstructorServiceLoaderTest.java rename to substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/NoProviderConstructorServiceLoaderTest.java index aa50b328cb90..aa2f328a817d 100644 --- a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/NoProviderConstructorServiceLoaderTest.java +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/NoProviderConstructorServiceLoaderTest.java @@ -22,7 +22,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package com.oracle.svm.test.jdk11; +package com.oracle.svm.test; import java.util.HashSet; import java.util.ServiceConfigurationError; diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/ReusePortAvailableTest.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/ReusePortAvailableTest.java similarity index 97% rename from substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/ReusePortAvailableTest.java rename to substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/ReusePortAvailableTest.java index 70ca9363b113..d1cf141c529d 100644 --- a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/ReusePortAvailableTest.java +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/ReusePortAvailableTest.java @@ -22,7 +22,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package com.oracle.svm.test.jdk11; +package com.oracle.svm.test; import java.net.Socket; diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/ServiceLoaderTest.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/ServiceLoaderTest.java index c4d272b29b23..b74b429700b9 100644 --- a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/ServiceLoaderTest.java +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/ServiceLoaderTest.java @@ -24,8 +24,12 @@ */ package com.oracle.svm.test; +import java.util.ArrayList; +import java.util.List; import java.util.ServiceLoader; +import javax.tools.JavaCompiler; + import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.hosted.Feature; @@ -155,4 +159,24 @@ public void test02JDKService() { Assert.assertTrue(foundZip); } + + @Test + public void test03JavaCompiler() { + ServiceLoader loader = ServiceLoader.load(JavaCompiler.class, ClassLoader.getSystemClassLoader()); + boolean foundJavacTool = false; + List unexpected = new ArrayList<>(); + + for (JavaCompiler javaCompiler : loader) { + if (javaCompiler.getClass().getName().equals("com.sun.tools.javac.api.JavacTool")) { + foundJavacTool = true; + } else { + unexpected.add(javaCompiler); + } + } + + if (!unexpected.isEmpty()) { + Assert.fail("Found unexpected JavaCompiler providers: " + unexpected); + } + Assert.assertTrue("Did not find JavacTool", foundJavacTool); + } } diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/ServiceLoaderTest.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/ServiceLoaderTest.java deleted file mode 100644 index 80d4f5f12f23..000000000000 --- a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/ServiceLoaderTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2018, 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.test.jdk11; - -import java.util.ArrayList; -import java.util.List; -import java.util.ServiceLoader; - -import javax.tools.JavaCompiler; - -import org.junit.Assert; -import org.junit.Test; - -public class ServiceLoaderTest { - - @Test - public void test03JavaCompiler() { - ServiceLoader loader = ServiceLoader.load(JavaCompiler.class, ClassLoader.getSystemClassLoader()); - boolean foundJavacTool = false; - List unexpected = new ArrayList<>(); - - for (JavaCompiler javaCompiler : loader) { - if (javaCompiler.getClass().getName().equals("com.sun.tools.javac.api.JavacTool")) { - foundJavacTool = true; - } else { - unexpected.add(javaCompiler); - } - } - - if (!unexpected.isEmpty()) { - Assert.fail("Found unexpected JavaCompiler providers: " + unexpected); - } - Assert.assertTrue("Did not find JavacTool", foundJavacTool); - } -} diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/jfr/ClassEvent.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/ClassEvent.java similarity index 97% rename from substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/jfr/ClassEvent.java rename to substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/ClassEvent.java index 78acc0bd3fee..854eadf8123b 100644 --- a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/jfr/ClassEvent.java +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/ClassEvent.java @@ -24,7 +24,7 @@ * questions. */ -package com.oracle.svm.test.jdk11.jfr; +package com.oracle.svm.test.jfr; import jdk.jfr.Description; import jdk.jfr.Event; diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/jfr/JFR.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/JFR.java similarity index 97% rename from substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/jfr/JFR.java rename to substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/JFR.java index 443d1a375c62..b987fe397b3b 100644 --- a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/jfr/JFR.java +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/JFR.java @@ -24,7 +24,7 @@ * questions. */ -package com.oracle.svm.test.jdk11.jfr; +package com.oracle.svm.test.jfr; import java.io.IOException; diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/jfr/JFRTest.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/JFRTest.java similarity index 97% rename from substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/jfr/JFRTest.java rename to substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/JFRTest.java index d41a0ac01a2c..921ae32677b0 100644 --- a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/jfr/JFRTest.java +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/JFRTest.java @@ -22,7 +22,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package com.oracle.svm.test.jdk11.jfr; +package com.oracle.svm.test.jfr; import static org.junit.Assume.assumeTrue; diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/jfr/LocalJFR.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/LocalJFR.java similarity index 98% rename from substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/jfr/LocalJFR.java rename to substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/LocalJFR.java index 7d8d19ae85ed..0b34188d7f43 100644 --- a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/jfr/LocalJFR.java +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/LocalJFR.java @@ -24,7 +24,7 @@ * questions. */ -package com.oracle.svm.test.jdk11.jfr; +package com.oracle.svm.test.jfr; import java.io.File; import java.io.IOException; diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/jfr/MetadataDescriptor.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/MetadataDescriptor.java similarity index 99% rename from substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/jfr/MetadataDescriptor.java rename to substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/MetadataDescriptor.java index a13c98451970..cc849d02f702 100644 --- a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/jfr/MetadataDescriptor.java +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/MetadataDescriptor.java @@ -23,7 +23,7 @@ * questions. */ -package com.oracle.svm.test.jdk11.jfr; +package com.oracle.svm.test.jfr; import java.io.DataInput; import java.io.IOException; diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/jfr/MetadataReader.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/MetadataReader.java similarity index 96% rename from substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/jfr/MetadataReader.java rename to substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/MetadataReader.java index de6d5aeaf662..dc74796cbf4c 100644 --- a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/jfr/MetadataReader.java +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/MetadataReader.java @@ -23,14 +23,14 @@ * questions. */ -package com.oracle.svm.test.jdk11.jfr; +package com.oracle.svm.test.jfr; import java.io.DataInput; import java.io.IOException; import java.util.ArrayList; import java.util.List; -import com.oracle.svm.test.jdk11.jfr.MetadataDescriptor.Element; +import com.oracle.svm.test.jfr.MetadataDescriptor.Element; /** * Parses metadata. diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/jfr/RecordingInput.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/RecordingInput.java similarity index 99% rename from substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/jfr/RecordingInput.java rename to substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/RecordingInput.java index 429f81d83d4e..21f0b2269dba 100644 --- a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/jfr/RecordingInput.java +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/RecordingInput.java @@ -23,7 +23,7 @@ * questions. */ -package com.oracle.svm.test.jdk11.jfr; +package com.oracle.svm.test.jfr; import java.io.DataInput; import java.io.EOFException; diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/jfr/StringEvent.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/StringEvent.java similarity index 97% rename from substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/jfr/StringEvent.java rename to substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/StringEvent.java index 2ba777638eae..0521c5ab0b73 100644 --- a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/jfr/StringEvent.java +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/StringEvent.java @@ -24,7 +24,7 @@ * questions. */ -package com.oracle.svm.test.jdk11.jfr; +package com.oracle.svm.test.jfr; import jdk.jfr.Description; import jdk.jfr.Event; diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/jfr/TestClassEvent.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestClassEvent.java similarity index 98% rename from substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/jfr/TestClassEvent.java rename to substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestClassEvent.java index c3909750bd22..c284397d173f 100644 --- a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/jfr/TestClassEvent.java +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestClassEvent.java @@ -24,7 +24,7 @@ * questions. */ -package com.oracle.svm.test.jdk11.jfr; +package com.oracle.svm.test.jfr; import static org.junit.Assert.assertNotNull; diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/jfr/TestJFRCompiles.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestJFRCompiles.java similarity index 97% rename from substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/jfr/TestJFRCompiles.java rename to substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestJFRCompiles.java index 12dd67c3f1f6..5f2d181382cc 100644 --- a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/jfr/TestJFRCompiles.java +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestJFRCompiles.java @@ -24,12 +24,12 @@ * questions. */ -package com.oracle.svm.test.jdk11.jfr; - -import jdk.jfr.Recording; +package com.oracle.svm.test.jfr; import org.junit.Test; +import jdk.jfr.Recording; + public class TestJFRCompiles extends JFRTest { @Test diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/jfr/TestRecordingParsable.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestRecordingParsable.java similarity index 98% rename from substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/jfr/TestRecordingParsable.java rename to substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestRecordingParsable.java index fd7dcf142287..f79dc739f570 100644 --- a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/jfr/TestRecordingParsable.java +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestRecordingParsable.java @@ -24,14 +24,15 @@ * questions. */ -package com.oracle.svm.test.jdk11.jfr; - -import jdk.jfr.Recording; -import jdk.jfr.consumer.RecordingFile; +package com.oracle.svm.test.jfr; import static org.junit.Assert.assertNotNull; + import org.junit.Test; +import jdk.jfr.Recording; +import jdk.jfr.consumer.RecordingFile; + public class TestRecordingParsable extends JFRTest { @Test diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/jfr/TestSingleEvent.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestSingleEvent.java similarity index 98% rename from substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/jfr/TestSingleEvent.java rename to substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestSingleEvent.java index 01a4d773604d..d9fb1dbcf14f 100644 --- a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jdk11/jfr/TestSingleEvent.java +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestSingleEvent.java @@ -24,15 +24,16 @@ * questions. */ -package com.oracle.svm.test.jdk11.jfr; - -import jdk.jfr.Recording; +package com.oracle.svm.test.jfr; import static org.junit.Assert.assertEquals; -import org.junit.Test; import java.io.IOException; +import org.junit.Test; + +import jdk.jfr.Recording; + public class TestSingleEvent extends JFRTest { private static final long METADATA_TYPE_ID = 0; private static final long CONSTANT_POOL_TYPE_ID = 1; diff --git a/substratevm/src/com.oracle.svm.util/src/com/oracle/svm/util/ModuleSupport.java b/substratevm/src/com.oracle.svm.util/src/com/oracle/svm/util/ModuleSupport.java index 2f289c6b135c..a9eeb19511dc 100644 --- a/substratevm/src/com.oracle.svm.util/src/com/oracle/svm/util/ModuleSupport.java +++ b/substratevm/src/com.oracle.svm.util/src/com/oracle/svm/util/ModuleSupport.java @@ -24,12 +24,9 @@ */ package com.oracle.svm.util; -import java.lang.module.ModuleFinder; -import java.lang.module.ModuleReference; import java.util.NoSuchElementException; import java.util.Optional; import java.util.Set; -import java.util.stream.Collectors; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; @@ -123,18 +120,4 @@ public static void exportAndOpenPackageToUnnamed(String name, String pkg, boolea Modules.addExportsToAllUnnamed(module, pkg); Modules.addOpensToAllUnnamed(module, pkg); } - - public static String getModuleName(Class clazz) { - return clazz.getModule().getName(); - } - - public static Object getModuleDescriptor(Class clazz) { - return clazz.getModule().getDescriptor(); - } - - public static Set getSystemModuleDescriptors() { - return ModuleFinder.ofSystem().findAll().stream() - .map(ModuleReference::descriptor) - .collect(Collectors.toSet()); - } }