From 42f8a7e783917a0504ce9ed2375a265925a559c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksandar=20Pejovi=C4=87?= Date: Mon, 30 Jan 2023 14:21:58 +0100 Subject: [PATCH] Add option to explicitly make `jvm` shim DLL --- .../svm/hosted/jdk/JNIRegistrationSupport.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationSupport.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationSupport.java index 1d9f2b69900a..0a884f74aabf 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationSupport.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationSupport.java @@ -52,6 +52,7 @@ import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext; import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin; import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration; +import org.graalvm.compiler.options.Option; import org.graalvm.compiler.phases.util.Providers; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.Platforms; @@ -59,11 +60,12 @@ import com.oracle.svm.core.BuildArtifacts; import com.oracle.svm.core.ParsingReason; +import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature; import com.oracle.svm.core.feature.InternalFeature; import com.oracle.svm.core.jdk.JNIRegistrationUtil; import com.oracle.svm.core.jdk.NativeLibrarySupport; import com.oracle.svm.core.meta.SubstrateObjectConstant; -import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature; +import com.oracle.svm.core.option.HostedOptionKey; import com.oracle.svm.core.util.InterruptImageBuilding; import com.oracle.svm.core.util.VMError; import com.oracle.svm.hosted.FeatureImpl.AfterImageWriteAccessImpl; @@ -80,6 +82,11 @@ @AutomaticallyRegisteredFeature public final class JNIRegistrationSupport extends JNIRegistrationUtil implements InternalFeature { + public static class Options { + @Option(help = "Create a `jvm` shim for native libraries that link against that library.")// + public static final HostedOptionKey CreateJvmShim = new HostedOptionKey<>(false); + } + private final ConcurrentMap registeredLibraries = new ConcurrentHashMap<>(); private NativeLibraries nativeLibraries = null; private boolean isSunMSCAPIProviderReachable = false; @@ -159,6 +166,11 @@ private void addShimExports(String shimName, String... exports) { @Override public void beforeImageWrite(BeforeImageWriteAccess access) { + if (shimExports.containsKey("jvm") || Options.CreateJvmShim.getValue()) { + /* When making a `jvm` shim, also re-export the JNI functions that VM exports. */ + addJvmShimExports("JNI_CreateJavaVM", "JNI_GetCreatedJavaVMs", "JNI_GetDefaultJavaVMInitArgs"); + } + if (isWindows()) { ((BeforeImageWriteAccessImpl) access).registerLinkerInvocationTransformer(linkerInvocation -> { /* Make sure the native image exports all the symbols necessary for shim DLLs. */