diff --git a/sdk/src/org.graalvm.nativeimage/snapshot.sigtest b/sdk/src/org.graalvm.nativeimage/snapshot.sigtest index 0a23936dbf16..fd45783d107b 100644 --- a/sdk/src/org.graalvm.nativeimage/snapshot.sigtest +++ b/sdk/src/org.graalvm.nativeimage/snapshot.sigtest @@ -997,10 +997,28 @@ meth public !varargs static void registerAsQueried(java.lang.reflect.Executable[ meth public !varargs static void registerForReflectiveInstantiation(java.lang.Class[]) supr java.lang.Object +CLSS public final org.graalvm.nativeimage.hosted.RuntimeJNIAccess +meth public !varargs static void register(java.lang.Class[]) +meth public !varargs static void register(java.lang.reflect.Executable[]) +meth public !varargs static void register(java.lang.reflect.Field[]) +supr java.lang.Object + CLSS public final org.graalvm.nativeimage.hosted.RuntimeSerialization meth public !varargs static void register(java.lang.Class[]) meth public static void registerIncludingAssociatedClasses(java.lang.Class) meth public static void registerWithTargetConstructorClass(java.lang.Class,java.lang.Class) +meth public static void registerLambdaCapturingClass(java.lang.Class) +meth public !varargs static void registerProxyClass(java.lang.Class[]) +supr java.lang.Object + +CLSS public final org.graalvm.nativeimage.hosted.RuntimeProxyCreation +meth public !varargs static void register(java.lang.Class[]) +supr java.lang.Object + +CLSS public final org.graalvm.nativeimage.hosted.RuntimeResourceAccess +meth public static void addResource(java.lang.Module,java.lang.String) +meth public static void addResourceBundle(java.lang.Module,java.lang.String,java.util.Locale[]) +meth public static void addResourceBundle(java.lang.Module,java.lang.String) supr java.lang.Object CLSS public abstract interface org.graalvm.nativeimage.impl.InternalPlatform diff --git a/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/hosted/RuntimeJNIAccess.java b/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/hosted/RuntimeJNIAccess.java new file mode 100644 index 000000000000..e5c044517406 --- /dev/null +++ b/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/hosted/RuntimeJNIAccess.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * The Universal Permissive License (UPL), Version 1.0 + * + * Subject to the condition set forth below, permission is hereby granted to any + * person obtaining a copy of this software, associated documentation and/or + * data (collectively the "Software"), free of charge and under any and all + * copyright rights in the Software, and any and all patent rights owned or + * freely licensable by each licensor hereunder covering either (i) the + * unmodified Software as contributed to or provided by such licensor, or (ii) + * the Larger Works (as defined below), to deal in both + * + * (a) the Software, and + * + * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if + * one is included with the Software each a "Larger Work" to which the Software + * is contributed by such licensors), + * + * without restriction, including without limitation the rights to copy, create + * derivative works of, display, perform, and distribute the Software and make, + * use, sell, offer for sale, import, export, have made, and have sold the + * Software and the Larger Work(s), and to sublicense the foregoing rights on + * either these or other terms. + * + * This license is subject to the following condition: + * + * The above copyright notice and either this complete permission notice or at a + * minimum a reference to the UPL must be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.graalvm.nativeimage.hosted; + +import java.lang.reflect.Executable; +import java.lang.reflect.Field; + +import org.graalvm.nativeimage.ImageSingletons; +import org.graalvm.nativeimage.Platform; +import org.graalvm.nativeimage.Platforms; +import org.graalvm.nativeimage.impl.ConfigurationCondition; +import org.graalvm.nativeimage.impl.RuntimeJNIAccessSupport; + +/** + * This class provides methods that can be called during native image generation to register + * classes, methods, and fields for JNI access at run time. + * + * @since 22.3 + */ +@Platforms(Platform.HOSTED_ONLY.class) +public final class RuntimeJNIAccess { + + /** + * Makes the provided classes available for JNI access at run time. Needed when native code + * looks up Java classes via FindClass. + * + * @since 22.3 + */ + public static void register(Class... classes) { + ImageSingletons.lookup(RuntimeJNIAccessSupport.class).register(ConfigurationCondition.alwaysTrue(), classes); + } + + /** + * Makes the provided methods available for JNI access at run time. Needed when native code + * looks up Java methods via GetMethodID + * or GetStaticMethodID. + * + * @since 22.3 + */ + public static void register(Executable... methods) { + ImageSingletons.lookup(RuntimeJNIAccessSupport.class).register(ConfigurationCondition.alwaysTrue(), false, methods); + } + + /** + * Makes the provided fields available for JNI access at run time. Needed when native code looks + * up Java fields via GetFieldID + * or GetStaticFieldID. + * + * @since 22.3 + */ + public static void register(Field... fields) { + ImageSingletons.lookup(RuntimeJNIAccessSupport.class).register(ConfigurationCondition.alwaysTrue(), false, fields); + } + + private RuntimeJNIAccess() { + } +} diff --git a/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/hosted/RuntimeProxyCreation.java b/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/hosted/RuntimeProxyCreation.java new file mode 100644 index 000000000000..7018ed1b55f3 --- /dev/null +++ b/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/hosted/RuntimeProxyCreation.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * The Universal Permissive License (UPL), Version 1.0 + * + * Subject to the condition set forth below, permission is hereby granted to any + * person obtaining a copy of this software, associated documentation and/or + * data (collectively the "Software"), free of charge and under any and all + * copyright rights in the Software, and any and all patent rights owned or + * freely licensable by each licensor hereunder covering either (i) the + * unmodified Software as contributed to or provided by such licensor, or (ii) + * the Larger Works (as defined below), to deal in both + * + * (a) the Software, and + * + * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if + * one is included with the Software each a "Larger Work" to which the Software + * is contributed by such licensors), + * + * without restriction, including without limitation the rights to copy, create + * derivative works of, display, perform, and distribute the Software and make, + * use, sell, offer for sale, import, export, have made, and have sold the + * Software and the Larger Work(s), and to sublicense the foregoing rights on + * either these or other terms. + * + * This license is subject to the following condition: + * + * The above copyright notice and either this complete permission notice or at a + * minimum a reference to the UPL must be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.graalvm.nativeimage.hosted; + +import org.graalvm.nativeimage.ImageSingletons; +import org.graalvm.nativeimage.Platform; +import org.graalvm.nativeimage.Platforms; +import org.graalvm.nativeimage.impl.RuntimeProxyCreationSupport; + +/** + * This class can be used to make creating dynamic proxy classes at run time valid. + * + * @since 22.3 + */ +@Platforms(Platform.HOSTED_ONLY.class) +public final class RuntimeProxyCreation { + + /** + * Enables registering specifications of {@link java.lang.reflect.Proxy} classes during the + * image build so that matching proxy objects can be created at runtime. The proxy class is + * fully specified by the interfaces it implements. + * + * @since 22.3 + */ + public static void register(Class... interfaces) { + ImageSingletons.lookup(RuntimeProxyCreationSupport.class).addProxyClass(interfaces); + } + + private RuntimeProxyCreation() { + } +} diff --git a/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/hosted/RuntimeResourceAccess.java b/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/hosted/RuntimeResourceAccess.java new file mode 100644 index 000000000000..6f62b7a194b2 --- /dev/null +++ b/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/hosted/RuntimeResourceAccess.java @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * The Universal Permissive License (UPL), Version 1.0 + * + * Subject to the condition set forth below, permission is hereby granted to any + * person obtaining a copy of this software, associated documentation and/or + * data (collectively the "Software"), free of charge and under any and all + * copyright rights in the Software, and any and all patent rights owned or + * freely licensable by each licensor hereunder covering either (i) the + * unmodified Software as contributed to or provided by such licensor, or (ii) + * the Larger Works (as defined below), to deal in both + * + * (a) the Software, and + * + * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if + * one is included with the Software each a "Larger Work" to which the Software + * is contributed by such licensors), + * + * without restriction, including without limitation the rights to copy, create + * derivative works of, display, perform, and distribute the Software and make, + * use, sell, offer for sale, import, export, have made, and have sold the + * Software and the Larger Work(s), and to sublicense the foregoing rights on + * either these or other terms. + * + * This license is subject to the following condition: + * + * The above copyright notice and either this complete permission notice or at a + * minimum a reference to the UPL must be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.graalvm.nativeimage.hosted; + +import java.util.Arrays; +import java.util.Locale; +import java.util.Objects; +import java.util.regex.Pattern; + +import org.graalvm.nativeimage.ImageSingletons; +import org.graalvm.nativeimage.Platform; +import org.graalvm.nativeimage.Platforms; +import org.graalvm.nativeimage.impl.ConfigurationCondition; +import org.graalvm.nativeimage.impl.RuntimeResourceSupport; + +/** + * This class can be used to register Java resources and ResourceBundles that should be accessible + * at run time. + * + * @since 22.3 + */ +@Platforms(Platform.HOSTED_ONLY.class) +public final class RuntimeResourceAccess { + + /** + * Make Java resource {@code resourcePath} from {@code module} available at run time. If the + * given {@code module} is unnamed, the resource is looked up on the classpath instead. + * + * @since 22.3 + */ + public static void addResource(Module module, String resourcePath) { + ImageSingletons.lookup(RuntimeResourceSupport.class).addResources(ConfigurationCondition.alwaysTrue(), + withModuleName(module, Pattern.quote(resourcePath))); + } + + /** + * Make Java ResourceBundle that is specified by a {@code baseBundleName} and {@code locales} + * from module {@code module} available at run time. If the given {@code module} is unnamed, the + * ResourceBundle is looked up on the classpath instead. + * + * @since 22.3 + */ + public static void addResourceBundle(Module module, String baseBundleName, Locale[] locales) { + Objects.requireNonNull(locales); + ImageSingletons.lookup(RuntimeResourceSupport.class).addResourceBundles(ConfigurationCondition.alwaysTrue(), + withModuleName(module, baseBundleName), Arrays.asList(locales)); + } + + /** + * Make Java ResourceBundle that is specified by a {@code bundleName} from module {@code module} + * available at run time. If the given {@code module} is unnamed, the ResourceBundle is looked + * up on the classpath instead. + * + * @since 22.3 + */ + public static void addResourceBundle(Module module, String bundleName) { + ImageSingletons.lookup(RuntimeResourceSupport.class).addResourceBundles(ConfigurationCondition.alwaysTrue(), + withModuleName(module, bundleName)); + } + + private static String withModuleName(Module module, String str) { + Objects.requireNonNull(module); + Objects.requireNonNull(str); + return (module.isNamed() ? module.getName() : "ALL-UNNAMED") + ":" + str; + } + + private RuntimeResourceAccess() { + } +} diff --git a/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/hosted/RuntimeSerialization.java b/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/hosted/RuntimeSerialization.java index bd85f51a8ca9..64a12b19c7e9 100644 --- a/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/hosted/RuntimeSerialization.java +++ b/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/hosted/RuntimeSerialization.java @@ -100,6 +100,28 @@ public static void registerWithTargetConstructorClass(Class clazz, Class c ImageSingletons.lookup(RuntimeSerializationSupport.class).registerWithTargetConstructorClass(ConfigurationCondition.alwaysTrue(), clazz, customTargetConstructorClazz); } + /** + * Makes a class available for serialization at runtime that is created for the lambda + * expressions (a class that has a $deserializeLambda$ method) specified by the + * lambdaCapturingClass. + * + * @since 22.3 + */ + public static void registerLambdaCapturingClass(Class lambdaCapturingClass) { + ImageSingletons.lookup(RuntimeSerializationSupport.class).registerLambdaCapturingClass(ConfigurationCondition.alwaysTrue(), lambdaCapturingClass); + } + + /** + * Makes a dynamic proxy class (class that extends {@link java.lang.reflect.Proxy}) available + * for serialization at runtime that is specified by the given interfaces the proxy class + * implements. + * + * @since 22.3 + */ + public static void registerProxyClass(Class... implementedInterfaces) { + ImageSingletons.lookup(RuntimeSerializationSupport.class).registerProxyClass(ConfigurationCondition.alwaysTrue(), implementedInterfaces); + } + private RuntimeSerialization() { } } diff --git a/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/RuntimeJNIAccessSupport.java b/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/RuntimeJNIAccessSupport.java new file mode 100644 index 000000000000..9e014496ea55 --- /dev/null +++ b/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/RuntimeJNIAccessSupport.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * The Universal Permissive License (UPL), Version 1.0 + * + * Subject to the condition set forth below, permission is hereby granted to any + * person obtaining a copy of this software, associated documentation and/or + * data (collectively the "Software"), free of charge and under any and all + * copyright rights in the Software, and any and all patent rights owned or + * freely licensable by each licensor hereunder covering either (i) the + * unmodified Software as contributed to or provided by such licensor, or (ii) + * the Larger Works (as defined below), to deal in both + * + * (a) the Software, and + * + * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if + * one is included with the Software each a "Larger Work" to which the Software + * is contributed by such licensors), + * + * without restriction, including without limitation the rights to copy, create + * derivative works of, display, perform, and distribute the Software and make, + * use, sell, offer for sale, import, export, have made, and have sold the + * Software and the Larger Work(s), and to sublicense the foregoing rights on + * either these or other terms. + * + * This license is subject to the following condition: + * + * The above copyright notice and either this complete permission notice or at a + * minimum a reference to the UPL must be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.graalvm.nativeimage.impl; + +public interface RuntimeJNIAccessSupport extends ReflectionRegistry { + // needed as JNI-specific ImageSingletons key +} diff --git a/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/RuntimeProxyCreationSupport.java b/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/RuntimeProxyCreationSupport.java new file mode 100644 index 000000000000..1421e0513fca --- /dev/null +++ b/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/RuntimeProxyCreationSupport.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * The Universal Permissive License (UPL), Version 1.0 + * + * Subject to the condition set forth below, permission is hereby granted to any + * person obtaining a copy of this software, associated documentation and/or + * data (collectively the "Software"), free of charge and under any and all + * copyright rights in the Software, and any and all patent rights owned or + * freely licensable by each licensor hereunder covering either (i) the + * unmodified Software as contributed to or provided by such licensor, or (ii) + * the Larger Works (as defined below), to deal in both + * + * (a) the Software, and + * + * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if + * one is included with the Software each a "Larger Work" to which the Software + * is contributed by such licensors), + * + * without restriction, including without limitation the rights to copy, create + * derivative works of, display, perform, and distribute the Software and make, + * use, sell, offer for sale, import, export, have made, and have sold the + * Software and the Larger Work(s), and to sublicense the foregoing rights on + * either these or other terms. + * + * This license is subject to the following condition: + * + * The above copyright notice and either this complete permission notice or at a + * minimum a reference to the UPL must be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.graalvm.nativeimage.impl; + +public interface RuntimeProxyCreationSupport { + void addProxyClass(Class... interfaces); +} diff --git a/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/RuntimeResourceSupport.java b/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/RuntimeResourceSupport.java new file mode 100644 index 000000000000..b98cb47b6d1c --- /dev/null +++ b/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/RuntimeResourceSupport.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * The Universal Permissive License (UPL), Version 1.0 + * + * Subject to the condition set forth below, permission is hereby granted to any + * person obtaining a copy of this software, associated documentation and/or + * data (collectively the "Software"), free of charge and under any and all + * copyright rights in the Software, and any and all patent rights owned or + * freely licensable by each licensor hereunder covering either (i) the + * unmodified Software as contributed to or provided by such licensor, or (ii) + * the Larger Works (as defined below), to deal in both + * + * (a) the Software, and + * + * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if + * one is included with the Software each a "Larger Work" to which the Software + * is contributed by such licensors), + * + * without restriction, including without limitation the rights to copy, create + * derivative works of, display, perform, and distribute the Software and make, + * use, sell, offer for sale, import, export, have made, and have sold the + * Software and the Larger Work(s), and to sublicense the foregoing rights on + * either these or other terms. + * + * This license is subject to the following condition: + * + * The above copyright notice and either this complete permission notice or at a + * minimum a reference to the UPL must be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.graalvm.nativeimage.impl; + +import java.util.Collection; +import java.util.Locale; + +public interface RuntimeResourceSupport { + void addResources(ConfigurationCondition condition, String pattern); + + void ignoreResources(ConfigurationCondition condition, String pattern); + + void addResourceBundles(ConfigurationCondition condition, String name); + + void addResourceBundles(ConfigurationCondition condition, String basename, Collection locales); +} diff --git a/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/RuntimeSerializationSupport.java b/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/RuntimeSerializationSupport.java index 0b5c5e09a2d7..0d2d7352556c 100644 --- a/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/RuntimeSerializationSupport.java +++ b/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/RuntimeSerializationSupport.java @@ -40,7 +40,9 @@ */ package org.graalvm.nativeimage.impl; +import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; public interface RuntimeSerializationSupport { @@ -54,6 +56,13 @@ public interface RuntimeSerializationSupport { void registerLambdaCapturingClass(ConfigurationCondition condition, String lambdaCapturingClassName); + default void registerLambdaCapturingClass(ConfigurationCondition condition, Class lambdaCapturingClass) { + registerLambdaCapturingClass(condition, lambdaCapturingClass.getName()); + } + void registerProxyClass(ConfigurationCondition condition, List implementedInterfaces); + default void registerProxyClass(ConfigurationCondition condition, Class... implementedInterfaces) { + registerProxyClass(condition, Arrays.stream(implementedInterfaces).map(Class::getName).collect(Collectors.toList())); + } } diff --git a/substratevm/CHANGELOG.md b/substratevm/CHANGELOG.md index 6ad2918c1eb8..bff1b665bd55 100644 --- a/substratevm/CHANGELOG.md +++ b/substratevm/CHANGELOG.md @@ -10,6 +10,8 @@ This changelog summarizes major changes to GraalVM Native Image. * (GR-39475) Add initial support for jvmstat. * (GR-39563) Add support for JDK 19 and Project Loom Virtual Threads (JEP 425) for high-throughput lightweight concurrency. Enable on JDK 19 with `native-image --enable-preview`. * (GR-40264) Add `--enable-monitoring=` option to enable fine-grained control over monitoring features enabled in native executables. `-H:±AllowVMInspection` is now deprecated and will be removed in a future release. +* (GR-15630) Allow multiple classes with the same name from different class loaders. +* (GR-40198) Introduce public API for programmatic JNI / Resource / Proxy / Serialization registration from Feature classes during the image build. ## Version 22.2.0 * (GR-20653) Re-enable the usage of all CPU features for JIT compilation on AMD64. diff --git a/substratevm/src/com.oracle.svm.configure.test/src/META-INF/native-image/native-image.properties b/substratevm/src/com.oracle.svm.configure.test/src/META-INF/native-image/native-image.properties index d9c3e83c8ff0..58438cfd69af 100644 --- a/substratevm/src/com.oracle.svm.configure.test/src/META-INF/native-image/native-image.properties +++ b/substratevm/src/com.oracle.svm.configure.test/src/META-INF/native-image/native-image.properties @@ -1 +1 @@ -Args = -H:IncludeResources=com/oracle/svm/configure/test/config/.*json +Args = --add-exports=org.graalvm.sdk/org.graalvm.nativeimage.impl=ALL-UNNAMED -H:IncludeResources=com/oracle/svm/configure/test/config/.*json diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/configure/ResourcesRegistry.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/configure/ResourcesRegistry.java index 40532732fd5b..df941c65f45c 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/configure/ResourcesRegistry.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/configure/ResourcesRegistry.java @@ -24,16 +24,16 @@ */ package com.oracle.svm.core.configure; -import org.graalvm.nativeimage.impl.ConfigurationCondition; - import java.util.Collection; import java.util.Locale; -public interface ResourcesRegistry { +import org.graalvm.nativeimage.impl.ConfigurationCondition; +import org.graalvm.nativeimage.impl.RuntimeResourceSupport; + +public interface ResourcesRegistry extends RuntimeResourceSupport { /** - * @deprecated Use - * {@link ResourcesRegistry#addResources(org.graalvm.nativeimage.impl.ConfigurationCondition, String)} + * @deprecated Use {@link RuntimeResourceSupport#addResources(ConfigurationCondition, String)} * instead. */ @Deprecated @@ -43,7 +43,7 @@ default void addResources(String pattern) { /** * @deprecated Use - * {@link ResourcesRegistry#ignoreResources(org.graalvm.nativeimage.impl.ConfigurationCondition, String)} + * {@link RuntimeResourceSupport#ignoreResources(ConfigurationCondition, String)} * instead. */ @Deprecated @@ -53,7 +53,7 @@ default void ignoreResources(String pattern) { /** * @deprecated Use - * {@link ResourcesRegistry#addResourceBundles(org.graalvm.nativeimage.impl.ConfigurationCondition, String)} + * {@link RuntimeResourceSupport#addResourceBundles(ConfigurationCondition, String)} * instead. */ @Deprecated @@ -61,13 +61,22 @@ default void addResourceBundles(String name) { addResourceBundles(ConfigurationCondition.alwaysTrue(), name); } + void addClassBasedResourceBundle(ConfigurationCondition condition, String basename, String className); + + /** + * Although the interface-methods below are already defined in the super-interface + * {@link RuntimeResourceSupport} they are also needed here for legacy code that accesses them + * reflectively. + */ + @Override void addResources(ConfigurationCondition condition, String pattern); + @Override void ignoreResources(ConfigurationCondition condition, String pattern); + @Override void addResourceBundles(ConfigurationCondition condition, String name); + @Override void addResourceBundles(ConfigurationCondition condition, String basename, Collection locales); - - void addClassBasedResourceBundle(ConfigurationCondition condition, String basename, String className); } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JNIRegistrationUtil.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JNIRegistrationUtil.java index aa441c5eb35f..2248631793a7 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JNIRegistrationUtil.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JNIRegistrationUtil.java @@ -37,9 +37,9 @@ import org.graalvm.nativeimage.hosted.Feature.AfterAnalysisAccess; import org.graalvm.nativeimage.hosted.Feature.DuringAnalysisAccess; import org.graalvm.nativeimage.hosted.Feature.FeatureAccess; +import org.graalvm.nativeimage.hosted.RuntimeJNIAccess; import org.graalvm.nativeimage.impl.RuntimeClassInitializationSupport; -import com.oracle.svm.core.jni.JNIRuntimeAccess; import com.oracle.svm.core.util.ConcurrentIdentityHashMap; import com.oracle.svm.core.util.VMError; import com.oracle.svm.util.ReflectionUtil; @@ -106,8 +106,8 @@ protected static Field[] fields(FeatureAccess access, String className, String.. protected static void registerForThrowNew(FeatureAccess access, String... exceptionClassNames) { for (String exceptionClassName : exceptionClassNames) { - JNIRuntimeAccess.register(clazz(access, exceptionClassName)); - JNIRuntimeAccess.register(constructor(access, exceptionClassName, String.class)); + RuntimeJNIAccess.register(clazz(access, exceptionClassName)); + RuntimeJNIAccess.register(constructor(access, exceptionClassName, String.class)); } } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/LocalizationSupport.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/LocalizationSupport.java index d91bd2073c10..2dc0c0196210 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/LocalizationSupport.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/LocalizationSupport.java @@ -41,8 +41,8 @@ import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.hosted.RuntimeReflection; import org.graalvm.nativeimage.impl.ConfigurationCondition; +import org.graalvm.nativeimage.impl.RuntimeResourceSupport; -import com.oracle.svm.core.configure.ResourcesRegistry; import com.oracle.svm.core.util.VMError; /** @@ -97,7 +97,7 @@ public Map getBundleContentOf(Object bundle) { public void prepareBundle(String bundleName, ResourceBundle bundle, Locale locale) { if (bundle instanceof PropertyResourceBundle) { String withLocale = control.toBundleName(bundleName, locale); - ImageSingletons.lookup(ResourcesRegistry.class).addResources(ConfigurationCondition.alwaysTrue(), withLocale.replace('.', '/') + "\\.properties"); + ImageSingletons.lookup(RuntimeResourceSupport.class).addResources(ConfigurationCondition.alwaysTrue(), withLocale.replace('.', '/') + "\\.properties"); } else { RuntimeReflection.register(bundle.getClass()); RuntimeReflection.registerForReflectiveInstantiation(bundle.getClass()); diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/proxy/DynamicProxyRegistry.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/proxy/DynamicProxyRegistry.java index 892657ea09ae..d57bd01e0b52 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/proxy/DynamicProxyRegistry.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/proxy/DynamicProxyRegistry.java @@ -26,11 +26,9 @@ import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; +import org.graalvm.nativeimage.impl.RuntimeProxyCreationSupport; -public interface DynamicProxyRegistry { - - @Platforms(Platform.HOSTED_ONLY.class) - void addProxyClass(Class... interfaces); +public interface DynamicProxyRegistry extends RuntimeProxyCreationSupport { Class getProxyClass(ClassLoader loader, Class... interfaces); diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/JNIRuntimeAccess.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/JNIRuntimeAccess.java index f8d4ad346c2f..4e4080b7667e 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/JNIRuntimeAccess.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/JNIRuntimeAccess.java @@ -30,12 +30,9 @@ import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; +import org.graalvm.nativeimage.hosted.RuntimeJNIAccess; import org.graalvm.nativeimage.impl.ConfigurationCondition; -import org.graalvm.nativeimage.impl.ReflectionRegistry; - -import com.oracle.svm.core.SubstrateOptions; -import com.oracle.svm.core.option.SubstrateOptionsParser; -import com.oracle.svm.core.util.UserError; +import org.graalvm.nativeimage.impl.RuntimeJNIAccessSupport; /** * Support for registering classes, methods and fields before and during the analysis so they are @@ -47,28 +44,18 @@ private JNIRuntimeAccess() { } public static void register(Class... classes) { - getSupport().register(ConfigurationCondition.alwaysTrue(), classes); + RuntimeJNIAccess.register(classes); } public static void register(Executable... methods) { - getSupport().register(ConfigurationCondition.alwaysTrue(), false, methods); + RuntimeJNIAccess.register(methods); } public static void register(Field... fields) { - register(false, fields); + RuntimeJNIAccess.register(fields); } public static void register(boolean finalIsWritable, Field... fields) { - getSupport().register(ConfigurationCondition.alwaysTrue(), finalIsWritable, fields); - } - - private static JNIRuntimeAccessibilitySupport getSupport() { - if (!ImageSingletons.contains(JNIRuntimeAccessibilitySupport.class)) { - throw UserError.abort("Support for JNI is not enabled. The option %s must be set.", SubstrateOptionsParser.commandArgument(SubstrateOptions.JNI, "+")); - } - return ImageSingletons.lookup(JNIRuntimeAccessibilitySupport.class); - } - - public interface JNIRuntimeAccessibilitySupport extends ReflectionRegistry { + ImageSingletons.lookup(RuntimeJNIAccessSupport.class).register(ConfigurationCondition.alwaysTrue(), finalIsWritable, fields); } } diff --git a/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/LibGraalFeature.java b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/LibGraalFeature.java index e071dacdea3b..9f5f4f253451 100644 --- a/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/LibGraalFeature.java +++ b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/LibGraalFeature.java @@ -100,8 +100,8 @@ import org.graalvm.nativeimage.StackValue; import org.graalvm.nativeimage.VMRuntime; import org.graalvm.nativeimage.hosted.Feature; +import org.graalvm.nativeimage.hosted.RuntimeJNIAccess; import org.graalvm.nativeimage.hosted.RuntimeReflection; -import org.graalvm.nativeimage.impl.ConfigurationCondition; import org.graalvm.word.LocationIdentity; import org.graalvm.word.Pointer; import org.graalvm.word.WordFactory; @@ -124,7 +124,6 @@ import com.oracle.svm.core.graal.snippets.NodeLoweringProvider; import com.oracle.svm.core.heap.GCCause; import com.oracle.svm.core.heap.Heap; -import com.oracle.svm.core.jni.JNIRuntimeAccess; import com.oracle.svm.core.log.FunctionPointerLogHandler; import com.oracle.svm.core.option.HostedOptionKey; import com.oracle.svm.core.option.RuntimeOptionKey; @@ -212,10 +211,9 @@ public void afterRegistration(AfterRegistrationAccess access) { @Override public void duringSetup(DuringSetupAccess access) { - JNIRuntimeAccess.JNIRuntimeAccessibilitySupport registry = ImageSingletons.lookup(JNIRuntimeAccess.JNIRuntimeAccessibilitySupport.class); ImageClassLoader imageClassLoader = ((DuringSetupAccessImpl) access).getImageClassLoader(); - registerJNIConfiguration(registry, imageClassLoader); + registerJNIConfiguration(imageClassLoader); EconomicMap descriptors = EconomicMap.create(); for (Class optionsClass : imageClassLoader.findSubclasses(OptionDescriptors.class, false)) { if (!Modifier.isAbstract(optionsClass.getModifiers()) && !OptionDescriptorsMap.class.isAssignableFrom(optionsClass)) { @@ -345,10 +343,9 @@ UserException error(String format, Object... args) { } } - private static void registerJNIConfiguration(JNIRuntimeAccess.JNIRuntimeAccessibilitySupport registry, ImageClassLoader loader) { + private static void registerJNIConfiguration(ImageClassLoader loader) { try (JNIConfigSource source = new JNIConfigSource(loader)) { Map> classes = new HashMap<>(); - ConfigurationCondition condition = ConfigurationCondition.alwaysTrue(); for (String line : source.lines) { source.lineNo++; String[] tokens = line.split(" "); @@ -357,8 +354,8 @@ private static void registerJNIConfiguration(JNIRuntimeAccess.JNIRuntimeAccessib Class clazz = classes.get(className); if (clazz == null) { clazz = source.findClass(className); - registry.register(condition, clazz); - registry.register(condition, Array.newInstance(clazz, 0).getClass()); + RuntimeJNIAccess.register(clazz); + RuntimeJNIAccess.register(Array.newInstance(clazz, 0).getClass()); classes.put(className, clazz); } @@ -367,7 +364,7 @@ private static void registerJNIConfiguration(JNIRuntimeAccess.JNIRuntimeAccessib source.check(tokens.length == 4, "Expected 4 tokens for a field"); String fieldName = tokens[2]; try { - registry.register(condition, false, clazz.getDeclaredField(fieldName)); + RuntimeJNIAccess.register(clazz.getDeclaredField(fieldName)); } catch (NoSuchFieldException e) { throw source.error("Field %s.%s not found", clazz.getTypeName(), fieldName); } catch (NoClassDefFoundError e) { @@ -386,7 +383,7 @@ private static void registerJNIConfiguration(JNIRuntimeAccess.JNIRuntimeAccessib try { if ("".equals(methodName)) { Constructor cons = clazz.getDeclaredConstructor(parameters); - registry.register(condition, false, cons); + RuntimeJNIAccess.register(cons); if (Throwable.class.isAssignableFrom(clazz) && !Modifier.isAbstract(clazz.getModifiers())) { if (usedInTranslatedException(parameters)) { RuntimeReflection.register(clazz); @@ -394,7 +391,7 @@ private static void registerJNIConfiguration(JNIRuntimeAccess.JNIRuntimeAccessib } } } else { - registry.register(condition, false, clazz.getDeclaredMethod(methodName, parameters)); + RuntimeJNIAccess.register(clazz.getDeclaredMethod(methodName, parameters)); } } catch (NoSuchMethodException e) { throw source.error("Method %s.%s%s not found: %s", clazz.getTypeName(), methodName, descriptor, e); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ClassLoaderSupportImpl.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ClassLoaderSupportImpl.java index a1a119541fe5..dcd3023ea3da 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ClassLoaderSupportImpl.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ClassLoaderSupportImpl.java @@ -227,7 +227,9 @@ public List getResourceBundle(String bundleSpec, Locale locale) } String packageName = packageName(bundleName); Set modules; - if (moduleName != null) { + if (ResourcesFeature.MODULE_NAME_ALL_UNNAMED.equals(moduleName)) { + modules = Collections.emptySet(); + } else if (moduleName != null) { modules = classLoaderSupport.findModule(moduleName).stream().collect(Collectors.toSet()); } else { modules = packageToModules.getOrDefault(packageName, Collections.emptySet()); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ResourcesFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ResourcesFeature.java index b12d5e4cdda7..a86289998875 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ResourcesFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ResourcesFeature.java @@ -33,7 +33,6 @@ import java.util.Collections; import java.util.HashSet; import java.util.Locale; -import java.util.Optional; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.regex.Pattern; @@ -45,6 +44,7 @@ import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.hosted.Feature; import org.graalvm.nativeimage.impl.ConfigurationCondition; +import org.graalvm.nativeimage.impl.RuntimeResourceSupport; import com.oracle.svm.core.ClassLoaderSupport; import com.oracle.svm.core.ClassLoaderSupport.ResourceCollector; @@ -97,6 +97,8 @@ @AutomaticFeature public final class ResourcesFeature implements Feature { + static final String MODULE_NAME_ALL_UNNAMED = "ALL-UNNAMED"; + public static class Options { @Option(help = "Regexp to match names of resources to be included in the image.", type = OptionType.User)// public static final HostedOptionKey IncludeResources = new HostedOptionKey<>(new LocatableMultiOptionValue.Strings()); @@ -172,8 +174,9 @@ public void addResourceBundles(ConfigurationCondition condition, String basename public void afterRegistration(AfterRegistrationAccess a) { FeatureImpl.AfterRegistrationAccessImpl access = (FeatureImpl.AfterRegistrationAccessImpl) a; imageClassLoader = access.getImageClassLoader(); - ImageSingletons.add(ResourcesRegistry.class, - new ResourcesRegistryImpl(new ConfigurationTypeResolver("resource configuration", imageClassLoader))); + ResourcesRegistryImpl resourcesRegistry = new ResourcesRegistryImpl(new ConfigurationTypeResolver("resource configuration", imageClassLoader)); + ImageSingletons.add(ResourcesRegistry.class, resourcesRegistry); + ImageSingletons.add(RuntimeResourceSupport.class, resourcesRegistry); } private static ResourcesRegistryImpl resourceRegistryImpl() { @@ -210,7 +213,7 @@ public boolean isIncluded(String moduleName, String resourceName) { String relativePathWithTrailingSlash = resourceName + RESOURCES_INTERNAL_PATH_SEPARATOR; for (ResourcePattern rp : excludePatterns) { - if (rp.moduleName != null && !rp.moduleName.equals(moduleName)) { + if (!rp.moduleNameMatches(moduleName)) { continue; } if (rp.pattern.matcher(resourceName).matches() || rp.pattern.matcher(relativePathWithTrailingSlash).matches()) { @@ -219,7 +222,7 @@ public boolean isIncluded(String moduleName, String resourceName) { } for (ResourcePattern rp : includePatterns) { - if (rp.moduleName != null && !rp.moduleName.equals(moduleName)) { + if (!rp.moduleNameMatches(moduleName)) { continue; } if (rp.pattern.matcher(resourceName).matches() || rp.pattern.matcher(relativePathWithTrailingSlash).matches()) { @@ -281,11 +284,12 @@ private ResourcePattern makeResourcePattern(String rawPattern) { if (moduleNameWithPattern.length < 2) { return new ResourcePattern(null, Pattern.compile(moduleNameWithPattern[0])); } else { - Optional optModule = imageClassLoader.findModule(moduleNameWithPattern[0]); - if (optModule.isPresent()) { - return new ResourcePattern(moduleNameWithPattern[0], Pattern.compile(moduleNameWithPattern[1])); + String moduleName = moduleNameWithPattern[0]; + boolean acceptModuleName = MODULE_NAME_ALL_UNNAMED.equals(moduleName) ? true : imageClassLoader.findModule(moduleName).isPresent(); + if (acceptModuleName) { + return new ResourcePattern(moduleName, Pattern.compile(moduleNameWithPattern[1])); } else { - throw UserError.abort("Resource pattern \"" + rawPattern + "\"s specifies unknown module " + moduleNameWithPattern[0]); + throw UserError.abort("Resource pattern \"" + rawPattern + "\"s specifies unknown module " + moduleName); } } } @@ -298,6 +302,18 @@ private ResourcePattern(String moduleName, Pattern pattern) { this.moduleName = moduleName; this.pattern = pattern; } + + boolean moduleNameMatches(String resourceContainerModuleName) { + if (moduleName == null) { + // Accept everything + return true; + } + if (moduleName.equals(MODULE_NAME_ALL_UNNAMED)) { + // Only accept if resource is from classpath + return resourceContainerModuleName == null; + } + return moduleName.equals(resourceContainerModuleName); + } } @Override diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SecurityServicesFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SecurityServicesFeature.java index 17a68cbfd63a..aa832ba569ec 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SecurityServicesFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SecurityServicesFeature.java @@ -88,6 +88,7 @@ import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.hosted.Feature; +import org.graalvm.nativeimage.hosted.RuntimeJNIAccess; import org.graalvm.nativeimage.hosted.RuntimeReflection; import org.graalvm.nativeimage.impl.RuntimeClassInitializationSupport; @@ -100,7 +101,6 @@ import com.oracle.svm.core.jdk.NativeLibrarySupport; import com.oracle.svm.core.jdk.PlatformNativeLibrarySupport; import com.oracle.svm.core.jdk.SecurityProvidersFilter; -import com.oracle.svm.core.jni.JNIRuntimeAccess; import com.oracle.svm.core.option.HostedOptionKey; import com.oracle.svm.core.option.LocatableMultiOptionValue; import com.oracle.svm.core.util.UserError; @@ -474,26 +474,26 @@ private static void registerSunMSCAPIConfig(BeforeAnalysisAccess a) { } private static void registerLoadKeysOrCertificateChains(DuringAnalysisAccess a) { - JNIRuntimeAccess.register(constructor(a, "java.util.ArrayList")); - JNIRuntimeAccess.register(method(a, "sun.security.mscapi.CKeyStore", "generateCertificate", byte[].class, Collection.class)); - JNIRuntimeAccess.register(method(a, "sun.security.mscapi.CKeyStore", "generateCertificateChain", String.class, Collection.class)); - JNIRuntimeAccess.register(method(a, "sun.security.mscapi.CKeyStore", "generateKeyAndCertificateChain", boolean.class, String.class, long.class, long.class, int.class, Collection.class)); + RuntimeJNIAccess.register(constructor(a, "java.util.ArrayList")); + RuntimeJNIAccess.register(method(a, "sun.security.mscapi.CKeyStore", "generateCertificate", byte[].class, Collection.class)); + RuntimeJNIAccess.register(method(a, "sun.security.mscapi.CKeyStore", "generateCertificateChain", String.class, Collection.class)); + RuntimeJNIAccess.register(method(a, "sun.security.mscapi.CKeyStore", "generateKeyAndCertificateChain", boolean.class, String.class, long.class, long.class, int.class, Collection.class)); } private static void registerGenerateCKeyPair(DuringAnalysisAccess a) { - JNIRuntimeAccess.register(constructor(a, "sun.security.mscapi.CKeyPair", String.class, long.class, long.class, int.class)); + RuntimeJNIAccess.register(constructor(a, "sun.security.mscapi.CKeyPair", String.class, long.class, long.class, int.class)); } private static void registerCPrivateKeyOf(DuringAnalysisAccess a) { - JNIRuntimeAccess.register(method(a, "sun.security.mscapi.CPrivateKey", "of", String.class, long.class, long.class, int.class)); + RuntimeJNIAccess.register(method(a, "sun.security.mscapi.CPrivateKey", "of", String.class, long.class, long.class, int.class)); } private static void registerCPublicKeyOf(DuringAnalysisAccess a) { - JNIRuntimeAccess.register(method(a, "sun.security.mscapi.CPublicKey", "of", String.class, long.class, long.class, int.class)); + RuntimeJNIAccess.register(method(a, "sun.security.mscapi.CPublicKey", "of", String.class, long.class, long.class, int.class)); } private static void linkJaas(DuringAnalysisAccess a) { - JNIRuntimeAccess.register(fields(a, "com.sun.security.auth.module.UnixSystem", "username", "uid", "gid", "groups")); + RuntimeJNIAccess.register(fields(a, "com.sun.security.auth.module.UnixSystem", "username", "uid", "gid", "groups")); NativeLibraries nativeLibraries = ((DuringAnalysisAccessImpl) a).getNativeLibraries(); /* We can statically link jaas, thus we classify it as builtIn library */ diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationAwt.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationAwt.java index d2d753f2b36d..e8c8dba99a07 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationAwt.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationAwt.java @@ -30,16 +30,16 @@ import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.hosted.Feature; +import org.graalvm.nativeimage.hosted.RuntimeJNIAccess; import org.graalvm.nativeimage.impl.ConfigurationCondition; import org.graalvm.nativeimage.impl.InternalPlatform; +import org.graalvm.nativeimage.impl.RuntimeResourceSupport; import com.oracle.svm.core.SubstrateOptions; import com.oracle.svm.core.annotate.AutomaticFeature; -import com.oracle.svm.core.configure.ResourcesRegistry; import com.oracle.svm.core.jdk.JNIRegistrationUtil; import com.oracle.svm.core.jdk.NativeLibrarySupport; import com.oracle.svm.core.jdk.PlatformNativeLibrarySupport; -import com.oracle.svm.core.jni.JNIRuntimeAccess; import com.oracle.svm.hosted.FeatureImpl; import com.oracle.svm.hosted.c.NativeLibraries; @@ -99,11 +99,11 @@ public void beforeAnalysis(BeforeAnalysisAccess access) { private static void handlePreferencesClassReachable(DuringAnalysisAccess access) { - JNIRuntimeAccess.register(method(access, "java.lang.System", "setProperty", String.class, String.class)); - JNIRuntimeAccess.register(method(access, "java.lang.System", "loadLibrary", String.class)); + RuntimeJNIAccess.register(method(access, "java.lang.System", "setProperty", String.class, String.class)); + RuntimeJNIAccess.register(method(access, "java.lang.System", "loadLibrary", String.class)); - JNIRuntimeAccess.register(java.awt.GraphicsEnvironment.class); - JNIRuntimeAccess.register(method(access, "java.awt.GraphicsEnvironment", "isHeadless")); + RuntimeJNIAccess.register(GraphicsEnvironment.class); + RuntimeJNIAccess.register(method(access, "java.awt.GraphicsEnvironment", "isHeadless")); NativeLibraries nativeLibraries = getNativeLibraries(access); @@ -165,44 +165,38 @@ private static void registerFreeType(DuringAnalysisAccess access) { nativeLibraries.addStaticJniLibrary("fontmanager", isHeadless() ? "awt_headless" : "awt_xawt"); nativeLibraries.addDynamicNonJniLibrary("freetype"); - JNIRuntimeAccess.register(clazz(access, "sun.font.FontConfigManager$FontConfigInfo")); - JNIRuntimeAccess.register(fields(access, "sun.font.FontConfigManager$FontConfigInfo", "fcVersion", "cacheDirs")); - JNIRuntimeAccess.register(clazz(access, "sun.font.FontConfigManager$FcCompFont")); - JNIRuntimeAccess.register(fields(access, "sun.font.FontConfigManager$FcCompFont", "fcName", "firstFont", "allFonts")); - JNIRuntimeAccess.register(clazz(access, "sun.font.FontConfigManager$FontConfigFont")); - JNIRuntimeAccess.register(constructor(access, "sun.font.FontConfigManager$FontConfigFont")); - JNIRuntimeAccess.register(fields(access, "sun.font.FontConfigManager$FontConfigFont", "familyName", "styleStr", "fullName", "fontFile")); + RuntimeJNIAccess.register(clazz(access, "sun.font.FontConfigManager$FontConfigInfo")); + RuntimeJNIAccess.register(fields(access, "sun.font.FontConfigManager$FontConfigInfo", "fcVersion", "cacheDirs")); + RuntimeJNIAccess.register(clazz(access, "sun.font.FontConfigManager$FcCompFont")); + RuntimeJNIAccess.register(fields(access, "sun.font.FontConfigManager$FcCompFont", "fcName", "firstFont", "allFonts")); + RuntimeJNIAccess.register(clazz(access, "sun.font.FontConfigManager$FontConfigFont")); + RuntimeJNIAccess.register(constructor(access, "sun.font.FontConfigManager$FontConfigFont")); + RuntimeJNIAccess.register(fields(access, "sun.font.FontConfigManager$FontConfigFont", "familyName", "styleStr", "fullName", "fontFile")); } private static void registerColorProfiles(DuringAnalysisAccess duringAnalysisAccess) { - ResourcesRegistry resourcesRegistry = ImageSingletons.lookup(ResourcesRegistry.class); - resourcesRegistry.addResources(ConfigurationCondition.alwaysTrue(), "sun.java2d.cmm.profiles.*"); + ImageSingletons.lookup(RuntimeResourceSupport.class).addResources(ConfigurationCondition.alwaysTrue(), "sun.java2d.cmm.profiles.*"); } private static void registerFlavorMapProps(DuringAnalysisAccess duringAnalysisAccess) { - ResourcesRegistry resourcesRegistry = ImageSingletons.lookup(ResourcesRegistry.class); - resourcesRegistry.addResources(ConfigurationCondition.alwaysTrue(), "sun.datatransfer.resources.flavormap.properties"); + ImageSingletons.lookup(RuntimeResourceSupport.class).addResources(ConfigurationCondition.alwaysTrue(), "sun.datatransfer.resources.flavormap.properties"); } private static void registerRTFReaderCharsets(DuringAnalysisAccess duringAnalysisAccess) { - ResourcesRegistry resourcesRegistry = ImageSingletons.lookup(ResourcesRegistry.class); - resourcesRegistry.addResources(ConfigurationCondition.alwaysTrue(), "javax.swing.text.rtf.charsets.*"); + ImageSingletons.lookup(RuntimeResourceSupport.class).addResources(ConfigurationCondition.alwaysTrue(), "javax.swing.text.rtf.charsets.*"); } private static void registerOceanThemeIcons(DuringAnalysisAccess duringAnalysisAccess) { - ResourcesRegistry resourcesRegistry = ImageSingletons.lookup(ResourcesRegistry.class); - resourcesRegistry.addResources(ConfigurationCondition.alwaysTrue(), "javax.swing.plaf.metal.icons.*"); - resourcesRegistry.addResources(ConfigurationCondition.alwaysTrue(), "javax.swing.plaf.basic.icons.*"); + ImageSingletons.lookup(RuntimeResourceSupport.class).addResources(ConfigurationCondition.alwaysTrue(), "javax.swing.plaf.metal.icons.*"); + ImageSingletons.lookup(RuntimeResourceSupport.class).addResources(ConfigurationCondition.alwaysTrue(), "javax.swing.plaf.basic.icons.*"); } private static void registerHtml32bdtd(DuringAnalysisAccess duringAnalysisAccess) { - ResourcesRegistry resourcesRegistry = ImageSingletons.lookup(ResourcesRegistry.class); - resourcesRegistry.addResources(ConfigurationCondition.alwaysTrue(), "javax.swing.text.html.parser.html32.bdtd"); + ImageSingletons.lookup(RuntimeResourceSupport.class).addResources(ConfigurationCondition.alwaysTrue(), "javax.swing.text.html.parser.html32.bdtd"); } private static void registerDefaultCSS(DuringAnalysisAccess duringAnalysisAccess) { - ResourcesRegistry resourcesRegistry = ImageSingletons.lookup(ResourcesRegistry.class); - resourcesRegistry.addResources(ConfigurationCondition.alwaysTrue(), "javax.swing.text.html.default.css"); + ImageSingletons.lookup(RuntimeResourceSupport.class).addResources(ConfigurationCondition.alwaysTrue(), "javax.swing.text.html.default.css"); } private static NativeLibraries getNativeLibraries(DuringAnalysisAccess access) { diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJava.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJava.java index 7c0116526a85..4c97e236cb28 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJava.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJava.java @@ -32,12 +32,12 @@ import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.hosted.Feature; +import org.graalvm.nativeimage.hosted.RuntimeJNIAccess; import org.graalvm.nativeimage.impl.InternalPlatform; import com.oracle.svm.core.annotate.AutomaticFeature; import com.oracle.svm.core.jdk.JNIRegistrationUtil; import com.oracle.svm.core.jdk.PlatformNativeLibrarySupport; -import com.oracle.svm.core.jni.JNIRuntimeAccess; import com.oracle.svm.hosted.FeatureImpl; /** @@ -66,52 +66,53 @@ public void beforeAnalysis(BeforeAnalysisAccess a) { "java.lang.InstantiationException", "java.lang.UnsupportedOperationException", "java.io.IOException", "java.io.FileNotFoundException", "java.io.SyncFailedException", "java.io.InterruptedIOException", "java.util.zip.DataFormatException", "java.lang.IndexOutOfBoundsException"); - JNIRuntimeAccess.register(constructor(a, "java.io.FileNotFoundException", String.class, String.class)); + RuntimeJNIAccess.register(constructor(a, "java.io.FileNotFoundException", String.class, String.class)); /* Unconditional Integer and Boolean JNI registration (cheap) */ - JNIRuntimeAccess.register(clazz(a, "java.lang.Integer")); - JNIRuntimeAccess.register(constructor(a, "java.lang.Integer", int.class)); - JNIRuntimeAccess.register(fields(a, "java.lang.Integer", "value")); - JNIRuntimeAccess.register(clazz(a, "java.lang.Boolean")); - JNIRuntimeAccess.register(constructor(a, "java.lang.Boolean", boolean.class)); - JNIRuntimeAccess.register(fields(a, "java.lang.Boolean", "value")); - JNIRuntimeAccess.register(method(a, "java.lang.Boolean", "getBoolean", String.class)); + RuntimeJNIAccess.register(clazz(a, "java.lang.Integer")); + RuntimeJNIAccess.register(constructor(a, "java.lang.Integer", int.class)); + RuntimeJNIAccess.register(fields(a, "java.lang.Integer", "value")); + RuntimeJNIAccess.register(clazz(a, "java.lang.Boolean")); + RuntimeJNIAccess.register(constructor(a, "java.lang.Boolean", boolean.class)); + RuntimeJNIAccess.register(fields(a, "java.lang.Boolean", "value")); + RuntimeJNIAccess.register(method(a, "java.lang.Boolean", "getBoolean", String.class)); /* * Core JDK elements accessed from many places all around the JDK. They can be registered * unconditionally. */ - JNIRuntimeAccess.register(java.io.FileDescriptor.class); - JNIRuntimeAccess.register(fields(a, "java.io.FileDescriptor", "fd")); + RuntimeJNIAccess.register(java.io.FileDescriptor.class); + RuntimeJNIAccess.register(fields(a, "java.io.FileDescriptor", "fd")); if (isWindows()) { - JNIRuntimeAccess.register(fields(a, "java.io.FileDescriptor", "handle")); + RuntimeJNIAccess.register(fields(a, "java.io.FileDescriptor", "handle")); } - JNIRuntimeAccess.register(fields(a, "java.io.FileDescriptor", "append")); + RuntimeJNIAccess.register(fields(a, "java.io.FileDescriptor", "append")); /* Used by FileOutputStream.initIDs, which is called unconditionally during startup. */ - JNIRuntimeAccess.register(fields(a, "java.io.FileOutputStream", "fd")); + RuntimeJNIAccess.register(fields(a, "java.io.FileOutputStream", "fd")); /* Used by FileInputStream.initIDs, which is called unconditionally during startup. */ - JNIRuntimeAccess.register(fields(a, "java.io.FileInputStream", "fd")); + RuntimeJNIAccess.register(fields(a, "java.io.FileInputStream", "fd")); /* Used by UnixFileSystem/WinNTFileSystem.initIDs, called unconditionally during startup. */ - JNIRuntimeAccess.register(java.io.File.class); - JNIRuntimeAccess.register(fields(a, "java.io.File", "path")); + RuntimeJNIAccess.register(java.io.File.class); + RuntimeJNIAccess.register(fields(a, "java.io.File", "path")); // TODO classify the remaining registrations - JNIRuntimeAccess.register(byte[].class); /* used by ProcessEnvironment.environ() */ - - JNIRuntimeAccess.register(java.lang.String.class); - JNIRuntimeAccess.register(java.lang.System.class); - JNIRuntimeAccess.register(method(a, "java.lang.System", "getProperty", String.class)); - JNIRuntimeAccess.register(java.nio.charset.Charset.class); - JNIRuntimeAccess.register(method(a, "java.nio.charset.Charset", "isSupported", String.class)); - JNIRuntimeAccess.register(constructor(a, "java.lang.String", byte[].class)); - JNIRuntimeAccess.register(constructor(a, "java.lang.String", byte[].class, String.class)); - JNIRuntimeAccess.register(method(a, "java.lang.String", "getBytes", String.class)); - JNIRuntimeAccess.register(method(a, "java.lang.String", "getBytes")); - JNIRuntimeAccess.register(method(a, "java.lang.String", "concat", String.class)); - JNIRuntimeAccess.register(fields(a, "java.lang.String", "coder", "value")); + /* used by ProcessEnvironment.environ() */ + RuntimeJNIAccess.register(byte[].class); + + RuntimeJNIAccess.register(String.class); + RuntimeJNIAccess.register(System.class); + RuntimeJNIAccess.register(method(a, "java.lang.System", "getProperty", String.class)); + RuntimeJNIAccess.register(java.nio.charset.Charset.class); + RuntimeJNIAccess.register(method(a, "java.nio.charset.Charset", "isSupported", String.class)); + RuntimeJNIAccess.register(constructor(a, "java.lang.String", byte[].class)); + RuntimeJNIAccess.register(constructor(a, "java.lang.String", byte[].class, String.class)); + RuntimeJNIAccess.register(method(a, "java.lang.String", "getBytes", String.class)); + RuntimeJNIAccess.register(method(a, "java.lang.String", "getBytes")); + RuntimeJNIAccess.register(method(a, "java.lang.String", "concat", String.class)); + RuntimeJNIAccess.register(fields(a, "java.lang.String", "coder", "value")); a.registerReachabilityHandler(JNIRegistrationJava::registerRandomAccessFileInitIDs, method(a, "java.io.RandomAccessFile", "initIDs")); if (isWindows()) { @@ -142,10 +143,10 @@ public void beforeAnalysis(BeforeAnalysisAccess a) { } private static void registerProcessHandleImplInfoInitIDs(DuringAnalysisAccess a) { - JNIRuntimeAccess.register(fields(a, "java.lang.ProcessHandleImpl$Info", "command", "commandLine", "arguments", "startTime", "totalTime", "user")); + RuntimeJNIAccess.register(fields(a, "java.lang.ProcessHandleImpl$Info", "command", "commandLine", "arguments", "startTime", "totalTime", "user")); } private static void registerRandomAccessFileInitIDs(DuringAnalysisAccess a) { - JNIRuntimeAccess.register(fields(a, "java.io.RandomAccessFile", "fd")); + RuntimeJNIAccess.register(fields(a, "java.io.RandomAccessFile", "fd")); } } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNet.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNet.java index 1297637e0030..bd22bd78970a 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNet.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNet.java @@ -34,12 +34,12 @@ import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.hosted.Feature; +import org.graalvm.nativeimage.hosted.RuntimeJNIAccess; import org.graalvm.nativeimage.hosted.RuntimeReflection; import org.graalvm.nativeimage.impl.InternalPlatform; import com.oracle.svm.core.annotate.AutomaticFeature; import com.oracle.svm.core.jdk.JNIRegistrationUtil; -import com.oracle.svm.core.jni.JNIRuntimeAccess; import com.oracle.svm.core.util.VMError; import com.oracle.svm.hosted.FeatureImpl.DuringAnalysisAccessImpl; import com.oracle.svm.util.ReflectionUtil; @@ -205,27 +205,27 @@ static void registerInitInetAddressIDs(DuringAnalysisAccess a) { } /* Java_java_net_InetAddress_init */ - JNIRuntimeAccess.register(fields(a, "java.net.InetAddress", "holder")); + RuntimeJNIAccess.register(fields(a, "java.net.InetAddress", "holder")); if (JavaVersionUtil.JAVA_SPEC <= 17) { - JNIRuntimeAccess.register(fields(a, "java.net.InetAddress", "preferIPv6Address")); + RuntimeJNIAccess.register(fields(a, "java.net.InetAddress", "preferIPv6Address")); } - JNIRuntimeAccess.register(fields(a, "java.net.InetAddress$InetAddressHolder", "address", "family", "hostName", "originalHostName")); + RuntimeJNIAccess.register(fields(a, "java.net.InetAddress$InetAddressHolder", "address", "family", "hostName", "originalHostName")); /* Java_java_net_Inet4Address_init */ - JNIRuntimeAccess.register(constructor(a, "java.net.Inet4Address")); + RuntimeJNIAccess.register(constructor(a, "java.net.Inet4Address")); /* Java_java_net_Inet6Address_init */ - JNIRuntimeAccess.register(constructor(a, "java.net.Inet6Address")); - JNIRuntimeAccess.register(fields(a, "java.net.Inet6Address", "holder6")); + RuntimeJNIAccess.register(constructor(a, "java.net.Inet6Address")); + RuntimeJNIAccess.register(fields(a, "java.net.Inet6Address", "holder6")); if (JavaVersionUtil.JAVA_SPEC <= 11) { // JDK-8216417 Class c = clazz(a, "java.net.Inet6Address"); boolean optional = JavaVersionUtil.JAVA_SPEC == 11; // JDK-8269385 Field f = ReflectionUtil.lookupField(optional, c, "cached_scope_id"); if (f != null) { - JNIRuntimeAccess.register(f); + RuntimeJNIAccess.register(f); } } - JNIRuntimeAccess.register(fields(a, "java.net.Inet6Address$Inet6AddressHolder", "ipaddress", "scope_id", "scope_id_set", "scope_ifname")); + RuntimeJNIAccess.register(fields(a, "java.net.Inet6Address$Inet6AddressHolder", "ipaddress", "scope_id", "scope_id_set", "scope_ifname")); } private static void registerInetAddressLoadImpl(DuringAnalysisAccess a) { @@ -240,20 +240,20 @@ private static void registerNetworkInterfaceInit(DuringAnalysisAccess a) { return; /* Already registered. */ } - JNIRuntimeAccess.register(constructor(a, "java.net.NetworkInterface")); - JNIRuntimeAccess.register(fields(a, "java.net.NetworkInterface", "name", "displayName", "index", "addrs", "bindings", "childs")); + RuntimeJNIAccess.register(constructor(a, "java.net.NetworkInterface")); + RuntimeJNIAccess.register(fields(a, "java.net.NetworkInterface", "name", "displayName", "index", "addrs", "bindings", "childs")); if (isPosix()) { - JNIRuntimeAccess.register(fields(a, "java.net.NetworkInterface", "virtual", "parent", "defaultIndex")); + RuntimeJNIAccess.register(fields(a, "java.net.NetworkInterface", "virtual", "parent", "defaultIndex")); } - JNIRuntimeAccess.register(constructor(a, "java.net.InterfaceAddress")); - JNIRuntimeAccess.register(fields(a, "java.net.InterfaceAddress", "address", "broadcast", "maskLength")); + RuntimeJNIAccess.register(constructor(a, "java.net.InterfaceAddress")); + RuntimeJNIAccess.register(fields(a, "java.net.InterfaceAddress", "address", "broadcast", "maskLength")); registerInitInetAddressIDs(a); } private static void registerDatagramPacketInit(DuringAnalysisAccess a) { - JNIRuntimeAccess.register(fields(a, "java.net.DatagramPacket", "address", "port", "buf", "offset", "length", "bufLength")); + RuntimeJNIAccess.register(fields(a, "java.net.DatagramPacket", "address", "port", "buf", "offset", "length", "bufLength")); } private static void registerDatagramSocketCheckOldImpl(DuringAnalysisAccess a) { @@ -265,57 +265,57 @@ private static void registerDatagramSocketCheckOldImpl(DuringAnalysisAccess a) { } private static void registerPlainDatagramSocketImplInit(DuringAnalysisAccess a) { - JNIRuntimeAccess.register(fields(a, "java.net.DatagramSocketImpl", "fd", "localPort")); - JNIRuntimeAccess.register(fields(a, "java.net.AbstractPlainDatagramSocketImpl", "timeout", "trafficClass", "connected")); + RuntimeJNIAccess.register(fields(a, "java.net.DatagramSocketImpl", "fd", "localPort")); + RuntimeJNIAccess.register(fields(a, "java.net.AbstractPlainDatagramSocketImpl", "timeout", "trafficClass", "connected")); if (isWindows()) { - JNIRuntimeAccess.register(fields(a, "java.net.TwoStacksPlainDatagramSocketImpl", "fd1", "fduse", "lastfd")); + RuntimeJNIAccess.register(fields(a, "java.net.TwoStacksPlainDatagramSocketImpl", "fd1", "fduse", "lastfd")); registerInitInetAddressIDs(a); } else { - JNIRuntimeAccess.register(fields(a, "java.net.AbstractPlainDatagramSocketImpl", "connectedAddress", "connectedPort")); + RuntimeJNIAccess.register(fields(a, "java.net.AbstractPlainDatagramSocketImpl", "connectedAddress", "connectedPort")); registerNetworkInterfaceInit(a); } } private static void registerPlainDatagramSocketImplSocketGetOption(DuringAnalysisAccess a) { - JNIRuntimeAccess.register(method(a, "java.net.InetAddress", "anyLocalAddress")); + RuntimeJNIAccess.register(method(a, "java.net.InetAddress", "anyLocalAddress")); RuntimeReflection.register(clazz(a, "[Ljava.net.Inet4Address;")); /* Created via JNI. */ } private static void registerDualStackPlainDatagramSocketImplInitIDs(DuringAnalysisAccess a) { - JNIRuntimeAccess.register(fields(a, "java.net.DatagramSocketImpl", "fd")); + RuntimeJNIAccess.register(fields(a, "java.net.DatagramSocketImpl", "fd")); registerInitInetAddressIDs(a); } private static void registerPlainSocketImplInitProto(DuringAnalysisAccess a) { - JNIRuntimeAccess.register(fields(a, "java.net.SocketImpl", "fd", "address", "port", "localport", "serverSocket")); - JNIRuntimeAccess.register(fields(a, "java.net.AbstractPlainSocketImpl", "timeout", "trafficClass")); + RuntimeJNIAccess.register(fields(a, "java.net.SocketImpl", "fd", "address", "port", "localport", "serverSocket")); + RuntimeJNIAccess.register(fields(a, "java.net.AbstractPlainSocketImpl", "timeout", "trafficClass")); if (isWindows()) { - JNIRuntimeAccess.register(fields(a, "java.net.TwoStacksPlainSocketImpl", "fd1", "lastfd")); + RuntimeJNIAccess.register(fields(a, "java.net.TwoStacksPlainSocketImpl", "fd1", "lastfd")); } else { - JNIRuntimeAccess.register(fields(a, "java.net.AbstractPlainSocketImpl", "fdLock", "closePending")); + RuntimeJNIAccess.register(fields(a, "java.net.AbstractPlainSocketImpl", "fdLock", "closePending")); registerInitInetAddressIDs(a); } } private static void registerPlainSocketImplSocketGetOption(DuringAnalysisAccess a) { - JNIRuntimeAccess.register(fields(a, "java.net.InetAddressContainer", "addr")); + RuntimeJNIAccess.register(fields(a, "java.net.InetAddressContainer", "addr")); } private static void registerDualStackPlainSocketImplInitIDs(DuringAnalysisAccess a) { - JNIRuntimeAccess.register(constructor(a, "java.net.InetSocketAddress", InetAddress.class, int.class)); + RuntimeJNIAccess.register(constructor(a, "java.net.InetSocketAddress", InetAddress.class, int.class)); registerInitInetAddressIDs(a); } private static void registerDualStackPlainSocketImplLocalAddress(DuringAnalysisAccess a) { - JNIRuntimeAccess.register(fields(a, "java.net.InetAddressContainer", "addr")); + RuntimeJNIAccess.register(fields(a, "java.net.InetAddressContainer", "addr")); } private static void registerExtendedOptionsImplInit(DuringAnalysisAccess a) { - JNIRuntimeAccess.register(clazz(a, "jdk.net.SocketFlow")); - JNIRuntimeAccess.register(fields(a, "jdk.net.SocketFlow", "status", "priority", "bandwidth")); + RuntimeJNIAccess.register(clazz(a, "jdk.net.SocketFlow")); + RuntimeJNIAccess.register(fields(a, "jdk.net.SocketFlow", "status", "priority", "bandwidth")); - JNIRuntimeAccess.register(clazz(a, "jdk.net.SocketFlow$Status")); - JNIRuntimeAccess.register(fields(a, "jdk.net.SocketFlow$Status", "NO_STATUS", "OK", "NO_PERMISSION", "NOT_CONNECTED", "NOT_SUPPORTED", "ALREADY_CREATED", "IN_PROGRESS", "OTHER")); + RuntimeJNIAccess.register(clazz(a, "jdk.net.SocketFlow$Status")); + RuntimeJNIAccess.register(fields(a, "jdk.net.SocketFlow$Status", "NO_STATUS", "OK", "NO_PERMISSION", "NOT_CONNECTED", "NOT_SUPPORTED", "ALREADY_CREATED", "IN_PROGRESS", "OTHER")); } private static void registerPlatformSocketOptionsCreate(DuringAnalysisAccess a) { @@ -337,11 +337,11 @@ private static void registerDefaultProxySelectorInit(DuringAnalysisAccess a) { access.getNativeLibraries().addDynamicNonJniLibrary("winhttp"); } - JNIRuntimeAccess.register(constructor(a, "java.net.Proxy", Proxy.Type.class, SocketAddress.class)); - JNIRuntimeAccess.register(fields(a, "java.net.Proxy", "NO_PROXY")); + RuntimeJNIAccess.register(constructor(a, "java.net.Proxy", Proxy.Type.class, SocketAddress.class)); + RuntimeJNIAccess.register(fields(a, "java.net.Proxy", "NO_PROXY")); - JNIRuntimeAccess.register(fields(a, "java.net.Proxy$Type", "HTTP", "SOCKS")); + RuntimeJNIAccess.register(fields(a, "java.net.Proxy$Type", "HTTP", "SOCKS")); - JNIRuntimeAccess.register(method(a, "java.net.InetSocketAddress", "createUnresolved", String.class, int.class)); + RuntimeJNIAccess.register(method(a, "java.net.InetSocketAddress", "createUnresolved", String.class, int.class)); } } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNio.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNio.java index 05c055c4273a..5ab1d9679f32 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNio.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNio.java @@ -32,12 +32,12 @@ import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.hosted.Feature; +import org.graalvm.nativeimage.hosted.RuntimeJNIAccess; import org.graalvm.nativeimage.hosted.RuntimeReflection; import org.graalvm.nativeimage.impl.InternalPlatform; import com.oracle.svm.core.annotate.AutomaticFeature; import com.oracle.svm.core.jdk.JNIRegistrationUtil; -import com.oracle.svm.core.jni.JNIRuntimeAccess; /** * Registration of classes, methods, and fields accessed via JNI by C code of the JDK. @@ -73,10 +73,10 @@ public void duringSetup(DuringSetupAccess a) { public void beforeAnalysis(BeforeAnalysisAccess a) { if (isPosix()) { registerForThrowNew(a, "sun.nio.fs.UnixException"); - JNIRuntimeAccess.register(constructor(a, "sun.nio.fs.UnixException", int.class)); + RuntimeJNIAccess.register(constructor(a, "sun.nio.fs.UnixException", int.class)); } else if (isWindows()) { registerForThrowNew(a, "sun.nio.fs.WindowsException"); - JNIRuntimeAccess.register(constructor(a, "sun.nio.fs.WindowsException", int.class)); + RuntimeJNIAccess.register(constructor(a, "sun.nio.fs.WindowsException", int.class)); } /* Use the same lambda for registration to ensure it is called only once. */ @@ -122,93 +122,93 @@ public void beforeAnalysis(BeforeAnalysisAccess a) { } private static void registerServerSocketChannelImplInitIDs(DuringAnalysisAccess a) { - JNIRuntimeAccess.register(clazz(a, "java.net.InetSocketAddress")); - JNIRuntimeAccess.register(constructor(a, "java.net.InetSocketAddress", InetAddress.class, int.class)); + RuntimeJNIAccess.register(clazz(a, "java.net.InetSocketAddress")); + RuntimeJNIAccess.register(constructor(a, "java.net.InetSocketAddress", InetAddress.class, int.class)); } private static void registerDatagramChannelImplInitIDs(DuringAnalysisAccess a) { - JNIRuntimeAccess.register(clazz(a, "java.net.InetSocketAddress")); - JNIRuntimeAccess.register(constructor(a, "java.net.InetSocketAddress", InetAddress.class, int.class)); - JNIRuntimeAccess.register(clazz(a, "sun.nio.ch.DatagramChannelImpl")); - JNIRuntimeAccess.register(fields(a, "sun.nio.ch.DatagramChannelImpl", "sender", "cachedSenderInetAddress", "cachedSenderPort")); + RuntimeJNIAccess.register(clazz(a, "java.net.InetSocketAddress")); + RuntimeJNIAccess.register(constructor(a, "java.net.InetSocketAddress", InetAddress.class, int.class)); + RuntimeJNIAccess.register(clazz(a, "sun.nio.ch.DatagramChannelImpl")); + RuntimeJNIAccess.register(fields(a, "sun.nio.ch.DatagramChannelImpl", "sender", "cachedSenderInetAddress", "cachedSenderPort")); } private static void registerNetInitIDs(DuringAnalysisAccess a) { - JNIRuntimeAccess.register(clazz(a, "java.net.InetSocketAddress")); - JNIRuntimeAccess.register(constructor(a, "java.net.InetSocketAddress", InetAddress.class, int.class)); + RuntimeJNIAccess.register(clazz(a, "java.net.InetSocketAddress")); + RuntimeJNIAccess.register(constructor(a, "java.net.InetSocketAddress", InetAddress.class, int.class)); } private static void registerFileChannelImplInitIDs(DuringAnalysisAccess a) { - JNIRuntimeAccess.register(fields(a, "sun.nio.ch.FileChannelImpl", "fd")); + RuntimeJNIAccess.register(fields(a, "sun.nio.ch.FileChannelImpl", "fd")); } private static void registerFileKeyInitIDs(DuringAnalysisAccess a) { if (isPosix()) { - JNIRuntimeAccess.register(fields(a, "sun.nio.ch.FileKey", "st_dev", "st_ino")); + RuntimeJNIAccess.register(fields(a, "sun.nio.ch.FileKey", "st_dev", "st_ino")); } else if (isWindows()) { - JNIRuntimeAccess.register(fields(a, "sun.nio.ch.FileKey", "dwVolumeSerialNumber", "nFileIndexHigh", "nFileIndexLow")); + RuntimeJNIAccess.register(fields(a, "sun.nio.ch.FileKey", "dwVolumeSerialNumber", "nFileIndexHigh", "nFileIndexLow")); } } private static void registerUnixNativeDispatcherInit(DuringAnalysisAccess a) { - JNIRuntimeAccess.register(clazz(a, "sun.nio.fs.UnixFileAttributes")); - JNIRuntimeAccess.register(fields(a, "sun.nio.fs.UnixFileAttributes", + RuntimeJNIAccess.register(clazz(a, "sun.nio.fs.UnixFileAttributes")); + RuntimeJNIAccess.register(fields(a, "sun.nio.fs.UnixFileAttributes", "st_mode", "st_ino", "st_dev", "st_rdev", "st_nlink", "st_uid", "st_gid", "st_size", "st_atime_sec", "st_atime_nsec", "st_mtime_sec", "st_mtime_nsec", "st_ctime_sec", "st_ctime_nsec")); if (isDarwin()) { - JNIRuntimeAccess.register(fields(a, "sun.nio.fs.UnixFileAttributes", "st_birthtime_sec")); + RuntimeJNIAccess.register(fields(a, "sun.nio.fs.UnixFileAttributes", "st_birthtime_sec")); } - JNIRuntimeAccess.register(clazz(a, "sun.nio.fs.UnixFileStoreAttributes")); - JNIRuntimeAccess.register(fields(a, "sun.nio.fs.UnixFileStoreAttributes", "f_frsize", "f_blocks", "f_bfree", "f_bavail")); - JNIRuntimeAccess.register(clazz(a, "sun.nio.fs.UnixMountEntry")); - JNIRuntimeAccess.register(fields(a, "sun.nio.fs.UnixMountEntry", "name", "dir", "fstype", "opts", "dev")); + RuntimeJNIAccess.register(clazz(a, "sun.nio.fs.UnixFileStoreAttributes")); + RuntimeJNIAccess.register(fields(a, "sun.nio.fs.UnixFileStoreAttributes", "f_frsize", "f_blocks", "f_bfree", "f_bavail")); + RuntimeJNIAccess.register(clazz(a, "sun.nio.fs.UnixMountEntry")); + RuntimeJNIAccess.register(fields(a, "sun.nio.fs.UnixMountEntry", "name", "dir", "fstype", "opts", "dev")); /* * Registrations shared between all OS-specific subclasses of UnixNativeDispatcher, * therefore we factor it out here. */ - JNIRuntimeAccess.register(clazz(a, "sun.nio.fs.UnixMountEntry")); - JNIRuntimeAccess.register(fields(a, "sun.nio.fs.UnixMountEntry", "name", "dir", "fstype", "opts")); + RuntimeJNIAccess.register(clazz(a, "sun.nio.fs.UnixMountEntry")); + RuntimeJNIAccess.register(fields(a, "sun.nio.fs.UnixMountEntry", "name", "dir", "fstype", "opts")); } private static void registerSctpChannelImplInitIDs(DuringAnalysisAccess a) { - JNIRuntimeAccess.register(clazz(a, "sun.nio.ch.sctp.MessageInfoImpl")); - JNIRuntimeAccess.register(constructor(a, "sun.nio.ch.sctp.MessageInfoImpl", int.class, SocketAddress.class, int.class, int.class, boolean.class, boolean.class, int.class)); - JNIRuntimeAccess.register(clazz(a, "sun.nio.ch.sctp.ResultContainer")); - JNIRuntimeAccess.register(fields(a, "sun.nio.ch.sctp.ResultContainer", "value", "type")); - JNIRuntimeAccess.register(clazz(a, "sun.nio.ch.sctp.SendFailed")); - JNIRuntimeAccess.register(constructor(a, "sun.nio.ch.sctp.SendFailed", int.class, SocketAddress.class, ByteBuffer.class, int.class, int.class)); - JNIRuntimeAccess.register(clazz(a, "sun.nio.ch.sctp.AssociationChange")); - JNIRuntimeAccess.register(constructor(a, "sun.nio.ch.sctp.AssociationChange", int.class, int.class, int.class, int.class)); - JNIRuntimeAccess.register(clazz(a, "sun.nio.ch.sctp.PeerAddrChange")); - JNIRuntimeAccess.register(constructor(a, "sun.nio.ch.sctp.PeerAddrChange", int.class, SocketAddress.class, int.class)); - JNIRuntimeAccess.register(clazz(a, "sun.nio.ch.sctp.Shutdown")); - JNIRuntimeAccess.register(constructor(a, "sun.nio.ch.sctp.Shutdown", int.class)); + RuntimeJNIAccess.register(clazz(a, "sun.nio.ch.sctp.MessageInfoImpl")); + RuntimeJNIAccess.register(constructor(a, "sun.nio.ch.sctp.MessageInfoImpl", int.class, SocketAddress.class, int.class, int.class, boolean.class, boolean.class, int.class)); + RuntimeJNIAccess.register(clazz(a, "sun.nio.ch.sctp.ResultContainer")); + RuntimeJNIAccess.register(fields(a, "sun.nio.ch.sctp.ResultContainer", "value", "type")); + RuntimeJNIAccess.register(clazz(a, "sun.nio.ch.sctp.SendFailed")); + RuntimeJNIAccess.register(constructor(a, "sun.nio.ch.sctp.SendFailed", int.class, SocketAddress.class, ByteBuffer.class, int.class, int.class)); + RuntimeJNIAccess.register(clazz(a, "sun.nio.ch.sctp.AssociationChange")); + RuntimeJNIAccess.register(constructor(a, "sun.nio.ch.sctp.AssociationChange", int.class, int.class, int.class, int.class)); + RuntimeJNIAccess.register(clazz(a, "sun.nio.ch.sctp.PeerAddrChange")); + RuntimeJNIAccess.register(constructor(a, "sun.nio.ch.sctp.PeerAddrChange", int.class, SocketAddress.class, int.class)); + RuntimeJNIAccess.register(clazz(a, "sun.nio.ch.sctp.Shutdown")); + RuntimeJNIAccess.register(constructor(a, "sun.nio.ch.sctp.Shutdown", int.class)); } private static void registerWindowsNativeDispatcherInitIDs(DuringAnalysisAccess a) { - JNIRuntimeAccess.register(clazz(a, "sun.nio.fs.WindowsNativeDispatcher$FirstFile")); - JNIRuntimeAccess.register(fields(a, "sun.nio.fs.WindowsNativeDispatcher$FirstFile", "handle", "name", "attributes")); - JNIRuntimeAccess.register(clazz(a, "sun.nio.fs.WindowsNativeDispatcher$FirstStream")); - JNIRuntimeAccess.register(fields(a, "sun.nio.fs.WindowsNativeDispatcher$FirstStream", "handle", "name")); - JNIRuntimeAccess.register(clazz(a, "sun.nio.fs.WindowsNativeDispatcher$VolumeInformation")); - JNIRuntimeAccess.register(fields(a, "sun.nio.fs.WindowsNativeDispatcher$VolumeInformation", "fileSystemName", "volumeName", "volumeSerialNumber", "flags")); - JNIRuntimeAccess.register(clazz(a, "sun.nio.fs.WindowsNativeDispatcher$DiskFreeSpace")); - JNIRuntimeAccess.register(fields(a, "sun.nio.fs.WindowsNativeDispatcher$DiskFreeSpace", "freeBytesAvailable", "totalNumberOfBytes", "totalNumberOfFreeBytes")); - JNIRuntimeAccess.register(fields(a, "sun.nio.fs.WindowsNativeDispatcher$DiskFreeSpace", "bytesPerSector")); - JNIRuntimeAccess.register(clazz(a, "sun.nio.fs.WindowsNativeDispatcher$Account")); - JNIRuntimeAccess.register(fields(a, "sun.nio.fs.WindowsNativeDispatcher$Account", "domain", "name", "use")); - JNIRuntimeAccess.register(clazz(a, "sun.nio.fs.WindowsNativeDispatcher$AclInformation")); - JNIRuntimeAccess.register(fields(a, "sun.nio.fs.WindowsNativeDispatcher$AclInformation", "aceCount")); - JNIRuntimeAccess.register(clazz(a, "sun.nio.fs.WindowsNativeDispatcher$CompletionStatus")); - JNIRuntimeAccess.register(fields(a, "sun.nio.fs.WindowsNativeDispatcher$CompletionStatus", "error", "bytesTransferred", "completionKey")); + RuntimeJNIAccess.register(clazz(a, "sun.nio.fs.WindowsNativeDispatcher$FirstFile")); + RuntimeJNIAccess.register(fields(a, "sun.nio.fs.WindowsNativeDispatcher$FirstFile", "handle", "name", "attributes")); + RuntimeJNIAccess.register(clazz(a, "sun.nio.fs.WindowsNativeDispatcher$FirstStream")); + RuntimeJNIAccess.register(fields(a, "sun.nio.fs.WindowsNativeDispatcher$FirstStream", "handle", "name")); + RuntimeJNIAccess.register(clazz(a, "sun.nio.fs.WindowsNativeDispatcher$VolumeInformation")); + RuntimeJNIAccess.register(fields(a, "sun.nio.fs.WindowsNativeDispatcher$VolumeInformation", "fileSystemName", "volumeName", "volumeSerialNumber", "flags")); + RuntimeJNIAccess.register(clazz(a, "sun.nio.fs.WindowsNativeDispatcher$DiskFreeSpace")); + RuntimeJNIAccess.register(fields(a, "sun.nio.fs.WindowsNativeDispatcher$DiskFreeSpace", "freeBytesAvailable", "totalNumberOfBytes", "totalNumberOfFreeBytes")); + RuntimeJNIAccess.register(fields(a, "sun.nio.fs.WindowsNativeDispatcher$DiskFreeSpace", "bytesPerSector")); + RuntimeJNIAccess.register(clazz(a, "sun.nio.fs.WindowsNativeDispatcher$Account")); + RuntimeJNIAccess.register(fields(a, "sun.nio.fs.WindowsNativeDispatcher$Account", "domain", "name", "use")); + RuntimeJNIAccess.register(clazz(a, "sun.nio.fs.WindowsNativeDispatcher$AclInformation")); + RuntimeJNIAccess.register(fields(a, "sun.nio.fs.WindowsNativeDispatcher$AclInformation", "aceCount")); + RuntimeJNIAccess.register(clazz(a, "sun.nio.fs.WindowsNativeDispatcher$CompletionStatus")); + RuntimeJNIAccess.register(fields(a, "sun.nio.fs.WindowsNativeDispatcher$CompletionStatus", "error", "bytesTransferred", "completionKey")); } private static void registerIocpInitIDs(DuringAnalysisAccess a) { - JNIRuntimeAccess.register(clazz(a, "sun.nio.ch.Iocp$CompletionStatus")); - JNIRuntimeAccess.register(fields(a, "sun.nio.ch.Iocp$CompletionStatus", "error", "bytesTransferred", "completionKey", "overlapped")); + RuntimeJNIAccess.register(clazz(a, "sun.nio.ch.Iocp$CompletionStatus")); + RuntimeJNIAccess.register(fields(a, "sun.nio.ch.Iocp$CompletionStatus", "error", "bytesTransferred", "completionKey", "overlapped")); } private static void registerConnectionCreateInetSocketAddress(DuringAnalysisAccess a) { diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationPrefs.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationPrefs.java index 7e854609e7f8..9ada029016f3 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationPrefs.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationPrefs.java @@ -28,12 +28,12 @@ import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.hosted.Feature; +import org.graalvm.nativeimage.hosted.RuntimeJNIAccess; import org.graalvm.nativeimage.impl.InternalPlatform; import com.oracle.svm.core.annotate.AutomaticFeature; import com.oracle.svm.core.jdk.JNIRegistrationUtil; import com.oracle.svm.core.jdk.NativeLibrarySupport; -import com.oracle.svm.core.jni.JNIRuntimeAccess; import com.oracle.svm.core.util.VMError; import com.oracle.svm.hosted.FeatureImpl; import com.oracle.svm.hosted.c.NativeLibraries; @@ -81,7 +81,7 @@ private static void handlePreferencesClassReachable(@SuppressWarnings("unused") nativeLibraries.addStaticJniLibrary("prefs"); if (isDarwin()) { /* Darwin allocates a string array from native code */ - JNIRuntimeAccess.register(String[].class); + RuntimeJNIAccess.register(String[].class); } } } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationsJavaZip.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationsJavaZip.java index 6fbc5ab67de3..d8337a868b1a 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationsJavaZip.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationsJavaZip.java @@ -26,11 +26,11 @@ import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.hosted.Feature; +import org.graalvm.nativeimage.hosted.RuntimeJNIAccess; import org.graalvm.nativeimage.impl.InternalPlatform; import com.oracle.svm.core.annotate.AutomaticFeature; import com.oracle.svm.core.jdk.JNIRegistrationUtil; -import com.oracle.svm.core.jni.JNIRuntimeAccess; @Platforms(InternalPlatform.PLATFORM_JNI.class) @AutomaticFeature @@ -50,6 +50,6 @@ public void beforeAnalysis(BeforeAnalysisAccess a) { } private static void registerJDK11InflaterInitIDs(DuringAnalysisAccess a) { - JNIRuntimeAccess.register(fields(a, "java.util.zip.Inflater", "inputConsumed", "outputConsumed")); + RuntimeJNIAccess.register(fields(a, "java.util.zip.Inflater", "inputConsumed", "outputConsumed")); } } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jni/JNIAccessFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jni/JNIAccessFeature.java index f9cfd3213593..2e1a8a50ba95 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jni/JNIAccessFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jni/JNIAccessFeature.java @@ -48,7 +48,7 @@ import org.graalvm.nativeimage.c.function.CodePointer; import org.graalvm.nativeimage.hosted.Feature; import org.graalvm.nativeimage.impl.ConfigurationCondition; -import org.graalvm.nativeimage.impl.ReflectionRegistry; +import org.graalvm.nativeimage.impl.RuntimeJNIAccessSupport; import org.graalvm.word.PointerBase; import org.graalvm.word.WordFactory; @@ -66,7 +66,6 @@ import com.oracle.svm.core.graal.meta.KnownOffsets; import com.oracle.svm.core.jni.CallVariant; import com.oracle.svm.core.jni.JNIJavaCallTrampolineHolder; -import com.oracle.svm.core.jni.JNIRuntimeAccess; import com.oracle.svm.core.jni.access.JNIAccessibleClass; import com.oracle.svm.core.jni.access.JNIAccessibleField; import com.oracle.svm.core.jni.access.JNIAccessibleMethod; @@ -149,6 +148,8 @@ static final class JNICallableJavaMethod { } } + private JNIRuntimeAccessibilitySupportImpl runtimeSupport; + private boolean sealed = false; private final Map trampolineMethods = new ConcurrentHashMap<>(); private final Map javaCallWrapperMethods = new ConcurrentHashMap<>(); @@ -186,15 +187,16 @@ public void afterRegistration(AfterRegistrationAccess arg) { JNIReflectionDictionary.create(); - JNIRuntimeAccessibilitySupportImpl registry = new JNIRuntimeAccessibilitySupportImpl(); - ImageSingletons.add(JNIRuntimeAccess.JNIRuntimeAccessibilitySupport.class, registry); + runtimeSupport = new JNIRuntimeAccessibilitySupportImpl(); + ImageSingletons.add(RuntimeJNIAccessSupport.class, runtimeSupport); - ReflectionConfigurationParser>> parser = ConfigurationParserUtils.create(registry, access.getImageClassLoader()); + ReflectionConfigurationParser>> parser = ConfigurationParserUtils.create(runtimeSupport, access.getImageClassLoader()); loadedConfigurations = ConfigurationParserUtils.parseAndRegisterConfigurations(parser, access.getImageClassLoader(), "JNI", ConfigurationFiles.Options.JNIConfigurationFiles, ConfigurationFiles.Options.JNIConfigurationResources, ConfigurationFile.JNI.getFileName()); } - private class JNIRuntimeAccessibilitySupportImpl extends ConditionalConfigurationRegistry implements JNIRuntimeAccess.JNIRuntimeAccessibilitySupport, ReflectionRegistry { + private class JNIRuntimeAccessibilitySupportImpl extends ConditionalConfigurationRegistry + implements RuntimeJNIAccessSupport { @Override public void register(ConfigurationCondition condition, boolean unsafeAllocated, Class clazz) { @@ -245,7 +247,7 @@ public void beforeAnalysis(BeforeAnalysisAccess arg) { } private static ConditionalConfigurationRegistry getConditionalConfigurationRegistry() { - return (ConditionalConfigurationRegistry) ImageSingletons.lookup(JNIRuntimeAccess.JNIRuntimeAccessibilitySupport.class); + return singleton().runtimeSupport; } private static void registerJavaCallTrampoline(BeforeAnalysisAccessImpl access, CallVariant variant, boolean nonVirtual) { 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 3d51c2973643..5143282e0a3a 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 @@ -52,6 +52,7 @@ import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.hosted.Feature.DuringAnalysisAccess; +import org.graalvm.nativeimage.hosted.RuntimeProxyCreation; import org.graalvm.nativeimage.hosted.RuntimeReflection; import org.graalvm.nativeimage.impl.ConfigurationCondition; import org.graalvm.nativeimage.impl.RuntimeReflectionSupport; @@ -66,7 +67,6 @@ import com.oracle.svm.core.hub.ClassLoadingExceptionSupport; import com.oracle.svm.core.hub.DynamicHub; import com.oracle.svm.core.jdk.RecordSupport; -import com.oracle.svm.core.jdk.proxy.DynamicProxyRegistry; import com.oracle.svm.core.reflect.SubstrateAccessor; import com.oracle.svm.core.util.UserError; import com.oracle.svm.core.util.VMError; @@ -641,7 +641,7 @@ private static void registerTypes(DuringAnalysisAccessImpl access, Collection[] interfaces = extractClassArray(snippetReflection, annotationSubstitutions, interfacesNode); if (interfaces != null) { /* The interfaces array can be empty. The java.lang.reflect.Proxy API allows it. */ - ImageSingletons.lookup(DynamicProxyRegistry.class).addProxyClass(interfaces); + RuntimeProxyCreation.register(interfaces); if (ImageSingletons.contains(FallbackFeature.class)) { ImageSingletons.lookup(FallbackFeature.class).addAutoProxyInvoke(b.getMethod(), b.bci()); } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/xml/XMLParsersRegistration.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/xml/XMLParsersRegistration.java index d10bf13da6a7..ed1cb565df8f 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/xml/XMLParsersRegistration.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/xml/XMLParsersRegistration.java @@ -34,8 +34,8 @@ import org.graalvm.nativeimage.hosted.RuntimeReflection; import org.graalvm.nativeimage.impl.ConfigurationCondition; import org.graalvm.nativeimage.impl.RuntimeClassInitializationSupport; +import org.graalvm.nativeimage.impl.RuntimeResourceSupport; -import com.oracle.svm.core.configure.ResourcesRegistry; import com.oracle.svm.core.jdk.JNIRegistrationUtil; import com.oracle.svm.hosted.FeatureImpl; import com.oracle.svm.hosted.classinitialization.ClassInitializationSupport; @@ -133,10 +133,9 @@ void registerResources() { ClassInitializationSupport classInitializationSupport = (ClassInitializationSupport) ImageSingletons.lookup(RuntimeClassInitializationSupport.class); classInitializationSupport.setConfigurationSealed(false); - ResourcesRegistry resourcesRegistry = ImageSingletons.lookup(ResourcesRegistry.class); - resourcesRegistry.addResourceBundles(ConfigurationCondition.alwaysTrue(), "com.sun.org.apache.xml.internal.serializer.utils.SerializerMessages"); - resourcesRegistry.addResourceBundles(ConfigurationCondition.alwaysTrue(), "com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMessages"); - resourcesRegistry.addResources(ConfigurationCondition.alwaysTrue(), "com.sun.*.properties"); + ImageSingletons.lookup(RuntimeResourceSupport.class).addResourceBundles(ConfigurationCondition.alwaysTrue(), "com.sun.org.apache.xml.internal.serializer.utils.SerializerMessages"); + ImageSingletons.lookup(RuntimeResourceSupport.class).addResourceBundles(ConfigurationCondition.alwaysTrue(), "com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMessages"); + ImageSingletons.lookup(RuntimeResourceSupport.class).addResources(ConfigurationCondition.alwaysTrue(), "com.sun.*.properties"); classInitializationSupport.setConfigurationSealed(true); } diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/NativeImageResourceUtils.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/NativeImageResourceUtils.java index b5d5e58a090f..43dbc04531c8 100644 --- a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/NativeImageResourceUtils.java +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/NativeImageResourceUtils.java @@ -34,14 +34,10 @@ import java.nio.file.Path; import java.nio.file.Paths; -import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.hosted.Feature; -import org.graalvm.nativeimage.impl.ConfigurationCondition; +import org.graalvm.nativeimage.hosted.RuntimeResourceAccess; import org.junit.Assert; -import com.oracle.svm.core.configure.ResourcesRegistry; -import com.oracle.svm.util.ModuleSupport; - public class NativeImageResourceUtils { public static final String RESOURCE_DIR = "/resources"; @@ -50,23 +46,17 @@ public class NativeImageResourceUtils { // Register resources. public static final class TestFeature implements Feature { - @Override - public void afterRegistration(AfterRegistrationAccess access) { - ModuleSupport.accessPackagesToClass(ModuleSupport.Access.EXPORT, TestFeature.class, false, "org.graalvm.sdk", "org.graalvm.nativeimage.impl"); - ModuleSupport.accessPackagesToClass(ModuleSupport.Access.EXPORT, TestFeature.class, false, "org.graalvm.nativeimage.builder", "com.oracle.svm.core.configure"); - } - @Override public void beforeAnalysis(BeforeAnalysisAccess access) { - ResourcesRegistry registry = ImageSingletons.lookup(ResourcesRegistry.class); // Remove leading / for the resource patterns - registry.addResources(ConfigurationCondition.alwaysTrue(), RESOURCE_DIR.substring(1)); - registry.addResources(ConfigurationCondition.alwaysTrue(), RESOURCE_FILE_1.substring(1)); - registry.addResources(ConfigurationCondition.alwaysTrue(), RESOURCE_FILE_2.substring(1)); + Module resourceModule = TestFeature.class.getModule(); + RuntimeResourceAccess.addResource(resourceModule, RESOURCE_DIR.substring(1)); + RuntimeResourceAccess.addResource(resourceModule, RESOURCE_FILE_1.substring(1)); + RuntimeResourceAccess.addResource(resourceModule, RESOURCE_FILE_2.substring(1)); /** Needed for {@link #testURLExternalFormEquivalence()} */ for (Module module : ModuleLayer.boot().modules()) { - registry.addResources(ConfigurationCondition.alwaysTrue(), module.getName() + ":" + "module-info.class"); + RuntimeResourceAccess.addResource(module, "module-info.class"); } } } diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleBaseFeature.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleBaseFeature.java index 4e52e8e93150..11704e936763 100644 --- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleBaseFeature.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleBaseFeature.java @@ -64,6 +64,7 @@ import org.graalvm.nativeimage.hosted.RuntimeClassInitialization; import org.graalvm.nativeimage.hosted.RuntimeReflection; import org.graalvm.nativeimage.impl.ConfigurationCondition; +import org.graalvm.nativeimage.impl.RuntimeResourceSupport; import com.oracle.graal.pointsto.infrastructure.OriginalClassProvider; import com.oracle.graal.pointsto.meta.AnalysisMetaAccess; @@ -79,7 +80,6 @@ import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; import com.oracle.svm.core.config.ConfigurationValues; -import com.oracle.svm.core.configure.ResourcesRegistry; import com.oracle.svm.core.fieldvaluetransformer.FieldValueTransformerWithAvailability; import com.oracle.svm.core.heap.Pod; import com.oracle.svm.core.reflect.target.ReflectionSubstitutionSupport; @@ -344,7 +344,7 @@ public void beforeAnalysis(BeforeAnalysisAccess access) { LibraryExport.class); if (needsAllEncodings) { - ImageSingletons.lookup(ResourcesRegistry.class).addResources(ConfigurationCondition.alwaysTrue(), "org/graalvm/shadowed/org/jcodings/tables/.*bin$"); + ImageSingletons.lookup(RuntimeResourceSupport.class).addResources(ConfigurationCondition.alwaysTrue(), "org/graalvm/shadowed/org/jcodings/tables/.*bin$"); } access.registerFieldValueTransformer(ReflectionUtil.lookupField(ArrayBasedShapeGeneratorOffsetTransformer.SHAPE_GENERATOR, "byteArrayOffset"),