Skip to content

Commit f1da8dd

Browse files
committed
[GR-36191] Add option to explicitly make jvm shim DLL.
PullRequest: graal/13651
2 parents 74db449 + 42f8a7e commit f1da8dd

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationSupport.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,20 @@
5252
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
5353
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin;
5454
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration;
55+
import org.graalvm.compiler.options.Option;
5556
import org.graalvm.compiler.phases.util.Providers;
5657
import org.graalvm.nativeimage.ImageSingletons;
5758
import org.graalvm.nativeimage.Platforms;
5859
import org.graalvm.nativeimage.impl.InternalPlatform;
5960

6061
import com.oracle.svm.core.BuildArtifacts;
6162
import com.oracle.svm.core.ParsingReason;
63+
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
6264
import com.oracle.svm.core.feature.InternalFeature;
6365
import com.oracle.svm.core.jdk.JNIRegistrationUtil;
6466
import com.oracle.svm.core.jdk.NativeLibrarySupport;
6567
import com.oracle.svm.core.meta.SubstrateObjectConstant;
66-
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
68+
import com.oracle.svm.core.option.HostedOptionKey;
6769
import com.oracle.svm.core.util.InterruptImageBuilding;
6870
import com.oracle.svm.core.util.VMError;
6971
import com.oracle.svm.hosted.FeatureImpl.AfterImageWriteAccessImpl;
@@ -80,6 +82,11 @@
8082
@AutomaticallyRegisteredFeature
8183
public final class JNIRegistrationSupport extends JNIRegistrationUtil implements InternalFeature {
8284

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+
8390
private final ConcurrentMap<String, Boolean> registeredLibraries = new ConcurrentHashMap<>();
8491
private NativeLibraries nativeLibraries = null;
8592
private boolean isSunMSCAPIProviderReachable = false;
@@ -159,6 +166,11 @@ private void addShimExports(String shimName, String... exports) {
159166

160167
@Override
161168
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+
162174
if (isWindows()) {
163175
((BeforeImageWriteAccessImpl) access).registerLinkerInvocationTransformer(linkerInvocation -> {
164176
/* Make sure the native image exports all the symbols necessary for shim DLLs. */

0 commit comments

Comments
 (0)