|
52 | 52 | import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext; |
53 | 53 | import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin; |
54 | 54 | import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration; |
| 55 | +import org.graalvm.compiler.options.Option; |
55 | 56 | import org.graalvm.compiler.phases.util.Providers; |
56 | 57 | import org.graalvm.nativeimage.ImageSingletons; |
57 | 58 | import org.graalvm.nativeimage.Platforms; |
58 | 59 | import org.graalvm.nativeimage.impl.InternalPlatform; |
59 | 60 |
|
60 | 61 | import com.oracle.svm.core.BuildArtifacts; |
61 | 62 | import com.oracle.svm.core.ParsingReason; |
| 63 | +import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature; |
62 | 64 | import com.oracle.svm.core.feature.InternalFeature; |
63 | 65 | import com.oracle.svm.core.jdk.JNIRegistrationUtil; |
64 | 66 | import com.oracle.svm.core.jdk.NativeLibrarySupport; |
65 | 67 | import com.oracle.svm.core.meta.SubstrateObjectConstant; |
66 | | -import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature; |
| 68 | +import com.oracle.svm.core.option.HostedOptionKey; |
67 | 69 | import com.oracle.svm.core.util.InterruptImageBuilding; |
68 | 70 | import com.oracle.svm.core.util.VMError; |
69 | 71 | import com.oracle.svm.hosted.FeatureImpl.AfterImageWriteAccessImpl; |
|
80 | 82 | @AutomaticallyRegisteredFeature |
81 | 83 | public final class JNIRegistrationSupport extends JNIRegistrationUtil implements InternalFeature { |
82 | 84 |
|
| 85 | + public static class Options { |
| 86 | + @Option(help = "Create a `jvm` shim for native libraries that link against that library.")// |
| 87 | + public static final HostedOptionKey<Boolean> CreateJvmShim = new HostedOptionKey<>(false); |
| 88 | + } |
| 89 | + |
83 | 90 | private final ConcurrentMap<String, Boolean> registeredLibraries = new ConcurrentHashMap<>(); |
84 | 91 | private NativeLibraries nativeLibraries = null; |
85 | 92 | private boolean isSunMSCAPIProviderReachable = false; |
@@ -159,6 +166,11 @@ private void addShimExports(String shimName, String... exports) { |
159 | 166 |
|
160 | 167 | @Override |
161 | 168 | public void beforeImageWrite(BeforeImageWriteAccess access) { |
| 169 | + if (shimExports.containsKey("jvm") || Options.CreateJvmShim.getValue()) { |
| 170 | + /* When making a `jvm` shim, also re-export the JNI functions that VM exports. */ |
| 171 | + addJvmShimExports("JNI_CreateJavaVM", "JNI_GetCreatedJavaVMs", "JNI_GetDefaultJavaVMInitArgs"); |
| 172 | + } |
| 173 | + |
162 | 174 | if (isWindows()) { |
163 | 175 | ((BeforeImageWriteAccessImpl) access).registerLinkerInvocationTransformer(linkerInvocation -> { |
164 | 176 | /* Make sure the native image exports all the symbols necessary for shim DLLs. */ |
|
0 commit comments