From b65967899879ec0a3eee5a1980ce3610f3a7541b Mon Sep 17 00:00:00 2001 From: Peter Hofer Date: Mon, 4 Dec 2023 18:31:30 +0100 Subject: [PATCH 1/2] Option for experimental Foreign Function and Memory API support. --- ci/common.jsonnet | 3 + compiler/mx.compiler/suite.py | 1 - .../native-image/ForeignInterface.md | 5 +- sdk/mx.sdk/suite.py | 3 +- substratevm/CHANGELOG.md | 1 + substratevm/mx.substratevm/mx_substratevm.py | 16 -- substratevm/mx.substratevm/suite.py | 51 +------ .../com/oracle/svm/core/foreign/AbiUtils.java | 12 +- .../core/foreign/ForeignFunctionsEnabled.java | 36 +++++ .../core/foreign/ForeignFunctionsRuntime.java | 4 +- ...Target_java_lang_foreign_SymbolLookup.java | 2 +- ...get_jdk_internal_foreign_SystemLookup.java | 4 +- ...internal_foreign_abi_NativeEntryPoint.java | 2 +- ..._jdk_internal_misc_ScopedMemoryAccess.java | 4 +- .../com/oracle/svm/core/SubstrateOptions.java | 3 + .../jdk/ForeignDisabledSubstitutions.java | 144 ++++++++++++++++++ .../svm/core/jdk/Target_java_lang_Module.java | 6 + ...arget_jdk_internal_reflect_Reflection.java | 9 ++ .../svm/core/jdk/Target_sun_nio_ch_Util.java | 7 + .../svm/driver/DefaultOptionHandler.java | 5 +- .../com/oracle/svm/driver/NativeImage.java | 41 ----- .../foreign/ForeignFunctionsFeature.java | 35 ++--- vm/mx.vm/mx_vm.py | 18 +-- 23 files changed, 255 insertions(+), 157 deletions(-) create mode 100644 substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/ForeignFunctionsEnabled.java create mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/ForeignDisabledSubstitutions.java diff --git a/ci/common.jsonnet b/ci/common.jsonnet index 43f78c8a4812..a9e64dc11602 100644 --- a/ci/common.jsonnet +++ b/ci/common.jsonnet @@ -229,6 +229,9 @@ local common_json = import "../common.json"; }, svm:: { + packages+: { + cmake: "==3.22.2", + }, environment+: { DEFAULT_VM: "server", LANG: "en_US.UTF-8", diff --git a/compiler/mx.compiler/suite.py b/compiler/mx.compiler/suite.py index 96870bee17e2..c81103331dae 100644 --- a/compiler/mx.compiler/suite.py +++ b/compiler/mx.compiler/suite.py @@ -498,7 +498,6 @@ """* to com.oracle.graal.graal_enterprise, org.graalvm.nativeimage.pointsto, org.graalvm.nativeimage.builder, - org.graalvm.nativeimage.foreign, org.graalvm.nativeimage.llvm, com.oracle.svm.svm_enterprise, com.oracle.svm_enterprise.ml_dataset, diff --git a/docs/reference-manual/native-image/ForeignInterface.md b/docs/reference-manual/native-image/ForeignInterface.md index 68cebe8a2e9d..1254b59b4ae9 100644 --- a/docs/reference-manual/native-image/ForeignInterface.md +++ b/docs/reference-manual/native-image/ForeignInterface.md @@ -7,8 +7,9 @@ permalink: /reference-manual/native-image/dynamic-features/foreign-interface/ # Foreign Function & Memory API in Native Image -The Foreign Function & Memory (FFM) API is a native interface that enables Java code to interact with native code and vice versa. -As of [JEP 442](https://openjdk.org/jeps/442){:target="_blank"}, it is a preview API of the Java platform and must be enabled with `--enable-preview`. +The Foreign Function & Memory (FFM) API is an interface that enables Java code to interact with native code and vice versa. +It has been finalized in JDK 22 with [JEP 454](https://openjdk.org/jeps/454){:target="_blank"}. +Support in Native Image is currently experimental and needs to be explicitly enabled with `-H:+ForeignAPISupport` (requiring `-H:+UnlockExperimentalVMOptions`). Modules that are permitted to perform "restricted" native operations (including creating handles for calls to or from native code) must be specified using `--enable-native-access=`. This page gives an overview of support for the FFM API in Native Image. diff --git a/sdk/mx.sdk/suite.py b/sdk/mx.sdk/suite.py index a7ceded8071e..d9fbc2637fc3 100644 --- a/sdk/mx.sdk/suite.py +++ b/sdk/mx.sdk/suite.py @@ -668,8 +668,7 @@ class UniversalDetector { com.oracle.svm.svm_enterprise, org.graalvm.extraimage.builder, org.graalvm.truffle.runtime.svm, - com.oracle.svm.enterprise.truffle, - org.graalvm.nativeimage.foreign""", + com.oracle.svm.enterprise.truffle""", "org.graalvm.nativeimage.impl.clinit to org.graalvm.nativeimage.builder", ], "uses" : [], diff --git a/substratevm/CHANGELOG.md b/substratevm/CHANGELOG.md index 638971acc057..6eda86468f0e 100644 --- a/substratevm/CHANGELOG.md +++ b/substratevm/CHANGELOG.md @@ -16,6 +16,7 @@ This changelog summarizes major changes to GraalVM Native Image. * (GR-45651) The Native Image agent now tracks calls to `ClassLoader.findSystemClass`, `ObjectInputStream.resolveClass` and `Bundles.of`, and registers resource bundles as bundle name-locale pairs. * (GR-49807) Before this change the function `System#setSecurityManager` was always halting program execution with a VM error. This was inconvenient as the VM error prints an uncomprehensible error message and prevents further continuation of the program. For cases where the program is expected to throw an exception when `System#setSecurityManager` is called, execution on Native Image was not possible. Now, `System#setSecurityManager` throws an `java.lang.UnsupportedOperationException` by default. If the property `java.security.manager` is set to anything but `disallow` at program startup this function will throw a `java.lang.SecurityException` according to the Java spec. * (GR-30433) Disallow the deprecated environment variable USE_NATIVE_IMAGE_JAVA_PLATFORM_MODULE_SYSTEM=false. +* (GR-49655) Experimental support for parts of the [Foreign Function & Memory API](https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/ForeignInterface.md) (part of "Project Panama", [JEP 454](https://openjdk.org/jeps/454)) on AMD64. Must be enabled with `-H:+ForeignAPISupport` (requiring `-H:+UnlockExperimentalVMOptions`). ## GraalVM for JDK 21 (Internal Version 23.1.0) * (GR-35746) Lower the default aligned chunk size from 1 MB to 512 KB for the serial and epsilon GCs, reducing memory usage and image size in many cases. diff --git a/substratevm/mx.substratevm/mx_substratevm.py b/substratevm/mx.substratevm/mx_substratevm.py index 0c874a4f5df3..d026fa65b01e 100644 --- a/substratevm/mx.substratevm/mx_substratevm.py +++ b/substratevm/mx.substratevm/mx_substratevm.py @@ -1074,22 +1074,6 @@ def _native_image_launcher_extra_jvm_args(): additional_ni_dependencies = [] -if mx.get_jdk(tag='default').javaCompliance >= '21': - mx_sdk_vm.register_graalvm_component(mx_sdk_vm.GraalVmJreComponent( - suite=suite, - name='SubstrateVM Foreign API Preview Feature', - short_name='svmforeign', - dir_name='svm-preview', - installable_id='native-image', - license_files=[], - third_party_license_files=[], - dependencies=['SubstrateVM'], - builder_jar_distributions=['substratevm:SVM_FOREIGN'], - installable=False, - jlink=False, - )) - additional_ni_dependencies += ['svmforeign'] - native_image = mx_sdk_vm.GraalVmJreComponent( suite=suite, name='Native Image', diff --git a/substratevm/mx.substratevm/suite.py b/substratevm/mx.substratevm/suite.py index 464dd14c3368..fa7f517de354 100644 --- a/substratevm/mx.substratevm/suite.py +++ b/substratevm/mx.substratevm/suite.py @@ -689,13 +689,11 @@ "jdk.internal.vm.ci" : [ ], }, - "javaCompliance" : "21+", - "javaPreviewNeeded": "21+", + "javaCompliance" : "22+", "annotationProcessors": [ "compiler:GRAAL_PROCESSOR", "SVM_PROCESSOR", ], - "javac.lint.overrides": "-preview", "checkstyle": "com.oracle.svm.hosted", "workingSets": "SVM", "jacoco" : "include", @@ -719,13 +717,11 @@ "jdk.vm.ci.code" ], }, - "javaCompliance" : "21+", - "javaPreviewNeeded": "21+", + "javaCompliance" : "22+", "annotationProcessors": [ "compiler:GRAAL_PROCESSOR", "SVM_PROCESSOR", ], - "javac.lint.overrides": "-preview", "checkstyle": "com.oracle.svm.hosted", "workingSets": "SVM", "jacoco" : "include", @@ -1424,6 +1420,7 @@ "dependencies": [ "com.oracle.svm.graal", "com.oracle.svm.hosted", + "com.oracle.svm.hosted.foreign", "com.oracle.svm.core", "com.oracle.svm.core.graal.amd64", "com.oracle.svm.core.graal.aarch64", @@ -1889,9 +1886,9 @@ "name" : "org.graalvm.nativeimage.base", "requires" : ["java.sql", "java.xml"],# workaround for GR-47773 on the module-path which requires java.sql (like truffle) or java.xml "exports" : [ - "com.oracle.svm.util to org.graalvm.nativeimage.pointsto,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.librarysupport,org.graalvm.nativeimage.driver,org.graalvm.nativeimage.llvm,org.graalvm.nativeimage.agent.jvmtibase,org.graalvm.nativeimage.agent.tracing,org.graalvm.nativeimage.agent.diagnostics,org.graalvm.nativeimage.junitsupport,com.oracle.svm.svm_enterprise,com.oracle.svm_enterprise.ml_dataset,org.graalvm.extraimage.builder,com.oracle.svm.extraimage_enterprise,org.graalvm.extraimage.librarysupport,org.graalvm.nativeimage.foreign,org.graalvm.truffle.runtime.svm,com.oracle.truffle.enterprise.svm", - "com.oracle.svm.common.meta to org.graalvm.nativeimage.pointsto,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.llvm,org.graalvm.extraimage.builder,org.graalvm.nativeimage.foreign,org.graalvm.truffle.runtime.svm,com.oracle.truffle.enterprise.svm", - "com.oracle.svm.common.option to org.graalvm.nativeimage.pointsto,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.driver,org.graalvm.nativeimage.foreign,org.graalvm.truffle.runtime.svm,com.oracle.truffle.enterprise.svm", + "com.oracle.svm.util to org.graalvm.nativeimage.pointsto,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.librarysupport,org.graalvm.nativeimage.driver,org.graalvm.nativeimage.llvm,org.graalvm.nativeimage.agent.jvmtibase,org.graalvm.nativeimage.agent.tracing,org.graalvm.nativeimage.agent.diagnostics,org.graalvm.nativeimage.junitsupport,com.oracle.svm.svm_enterprise,com.oracle.svm_enterprise.ml_dataset,org.graalvm.extraimage.builder,com.oracle.svm.extraimage_enterprise,org.graalvm.extraimage.librarysupport,org.graalvm.truffle.runtime.svm,com.oracle.truffle.enterprise.svm", + "com.oracle.svm.common.meta to org.graalvm.nativeimage.pointsto,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.llvm,org.graalvm.extraimage.builder,org.graalvm.truffle.runtime.svm,com.oracle.truffle.enterprise.svm", + "com.oracle.svm.common.option to org.graalvm.nativeimage.pointsto,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.driver,org.graalvm.truffle.runtime.svm,com.oracle.truffle.enterprise.svm", ], }, "noMavenJavadoc": True, @@ -2164,42 +2161,6 @@ }, }, - "SVM_FOREIGN": { - "subDir": "src", - "description" : "SubstrateVM support for the Foreign API", - "dependencies": [ - "com.oracle.svm.hosted.foreign", - ], - "distDependencies": [ - "compiler:GRAAL", - "SVM" - ], - "moduleInfo" : { - "name" : "org.graalvm.nativeimage.foreign", - "requires" : [ - "org.graalvm.nativeimage.builder" - ], - "exports" : [ - "* to org.graalvm.nativeimage.builder", - ], - "requiresConcealed": { - "jdk.internal.vm.ci" : [ - "jdk.vm.ci.meta", - "jdk.vm.ci.code", - "jdk.vm.ci.amd64", - ], - "java.base": [ - "jdk.internal.foreign", - "jdk.internal.foreign.abi", - "jdk.internal.foreign.abi.x64", - "jdk.internal.foreign.abi.x64.sysv", - "jdk.internal.foreign.abi.x64.windows", - ], - }, - }, - "maven" : False, - }, - "SVM_LLVM" : { "subDir" : "src", "description" : "LLVM backend for Native Image", diff --git a/substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/AbiUtils.java b/substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/AbiUtils.java index a0a3fd8565e1..883436dc93b8 100644 --- a/substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/AbiUtils.java +++ b/substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/AbiUtils.java @@ -40,9 +40,6 @@ import java.util.Objects; import java.util.stream.Stream; -import jdk.graal.compiler.api.replacements.Fold; -import jdk.graal.compiler.nodes.ValueNode; -import jdk.graal.compiler.nodes.calc.ReinterpretNode; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; @@ -53,6 +50,9 @@ import com.oracle.svm.core.headers.WindowsAPIs; import com.oracle.svm.core.util.VMError; +import jdk.graal.compiler.api.replacements.Fold; +import jdk.graal.compiler.nodes.ValueNode; +import jdk.graal.compiler.nodes.calc.ReinterpretNode; import jdk.internal.foreign.CABI; import jdk.internal.foreign.abi.Binding; import jdk.internal.foreign.abi.CallingSequence; @@ -534,7 +534,7 @@ protected List generateAdaptations(NativeEntryPointInfo nep) @Platforms(Platform.HOSTED_ONLY.class) public void checkLibrarySupport() { String name = "SystemV (Linux AMD64)"; - VMError.guarantee(LibC.isSupported(), "Foreign functions feature requires LibC support on " + name); + VMError.guarantee(LibC.isSupported(), "Foreign functions feature requires LibC support on %s", name); } @Override @@ -587,8 +587,8 @@ protected List generateAdaptations(NativeEntryPointInfo nep) @Platforms(Platform.HOSTED_ONLY.class) public void checkLibrarySupport() { String name = "Win64 (Windows AMD64)"; - VMError.guarantee(LibC.isSupported(), "Foreign functions feature requires LibC support on" + name); - VMError.guarantee(WindowsAPIs.isSupported(), "Foreign functions feature requires Windows APIs support on" + name); + VMError.guarantee(LibC.isSupported(), "Foreign functions feature requires LibC support on %s", name); + VMError.guarantee(WindowsAPIs.isSupported(), "Foreign functions feature requires Windows APIs support on %s", name); } @Override diff --git a/substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/ForeignFunctionsEnabled.java b/substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/ForeignFunctionsEnabled.java new file mode 100644 index 000000000000..1b937c22a20d --- /dev/null +++ b/substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/ForeignFunctionsEnabled.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023, 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.svm.core.foreign; + +import java.util.function.BooleanSupplier; + +import com.oracle.svm.core.SubstrateOptions; + +final class ForeignFunctionsEnabled implements BooleanSupplier { + @Override + public boolean getAsBoolean() { + return SubstrateOptions.ForeignAPISupport.getValue(); + } +} diff --git a/substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/ForeignFunctionsRuntime.java b/substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/ForeignFunctionsRuntime.java index d44a0ff3e29a..1eda5453d6ef 100644 --- a/substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/ForeignFunctionsRuntime.java +++ b/substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/ForeignFunctionsRuntime.java @@ -27,7 +27,6 @@ import static jdk.graal.compiler.core.common.spi.ForeignCallDescriptor.CallSideEffect.HAS_SIDE_EFFECT; import org.graalvm.collections.EconomicMap; -import jdk.graal.compiler.api.replacements.Fold; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; @@ -44,6 +43,7 @@ import com.oracle.svm.core.snippets.SubstrateForeignCallTarget; import com.oracle.svm.core.util.VMError; +import jdk.graal.compiler.api.replacements.Fold; import jdk.internal.foreign.abi.CapturableState; public class ForeignFunctionsRuntime { @@ -59,7 +59,7 @@ public ForeignFunctionsRuntime() { @Platforms(Platform.HOSTED_ONLY.class) public void addDowncallStubPointer(NativeEntryPointInfo nep, CFunctionPointer ptr) { - VMError.guarantee(!downcallStubs.containsKey(nep), "Seems like multiple stubs were generated for " + nep); + VMError.guarantee(!downcallStubs.containsKey(nep), "Seems like multiple stubs were generated for %s", nep); VMError.guarantee(downcallStubs.put(nep, new FunctionPointerHolder(ptr)) == null); } diff --git a/substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/Target_java_lang_foreign_SymbolLookup.java b/substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/Target_java_lang_foreign_SymbolLookup.java index ffda625c7dd8..508c7490a15f 100644 --- a/substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/Target_java_lang_foreign_SymbolLookup.java +++ b/substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/Target_java_lang_foreign_SymbolLookup.java @@ -66,7 +66,7 @@ * succeed. See * {@link com.oracle.svm.core.jdk.Target_java_lang_ClassLoader#loadLibrary(java.lang.Class, java.lang.String)} */ -@TargetClass(className = "java.lang.foreign.SymbolLookup") +@TargetClass(className = "java.lang.foreign.SymbolLookup", onlyWith = ForeignFunctionsEnabled.class) public final class Target_java_lang_foreign_SymbolLookup { @Substitute diff --git a/substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/Target_jdk_internal_foreign_SystemLookup.java b/substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/Target_jdk_internal_foreign_SystemLookup.java index abd100d719d7..3469c9fdaac3 100644 --- a/substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/Target_jdk_internal_foreign_SystemLookup.java +++ b/substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/Target_jdk_internal_foreign_SystemLookup.java @@ -36,7 +36,7 @@ * libraries. The provided libraries are not really defined in the documentation, so the best we can * do is load the exact same libraries as HotSpot. */ -@TargetClass(className = "jdk.internal.foreign.SystemLookup") +@TargetClass(className = "jdk.internal.foreign.SystemLookup", onlyWith = ForeignFunctionsEnabled.class) public final class Target_jdk_internal_foreign_SystemLookup { @Substitute public Optional find(String name) { @@ -44,7 +44,7 @@ public Optional find(String name) { } } -@TargetClass(className = "jdk.internal.foreign.SystemLookup", innerClass = "WindowsFallbackSymbols") +@TargetClass(className = "jdk.internal.foreign.SystemLookup", innerClass = "WindowsFallbackSymbols", onlyWith = ForeignFunctionsEnabled.class) @Delete final class Target_jdk_internal_foreign_SystemLookup_WindowsFallbackSymbols { } diff --git a/substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/Target_jdk_internal_foreign_abi_NativeEntryPoint.java b/substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/Target_jdk_internal_foreign_abi_NativeEntryPoint.java index 75e848d8e771..17537e990a37 100644 --- a/substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/Target_jdk_internal_foreign_abi_NativeEntryPoint.java +++ b/substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/Target_jdk_internal_foreign_abi_NativeEntryPoint.java @@ -36,7 +36,7 @@ * Packs the address of a {@link com.oracle.svm.hosted.foreign.DowncallStub} with some extra * information. */ -@TargetClass(className = "jdk.internal.foreign.abi.NativeEntryPoint") +@TargetClass(className = "jdk.internal.foreign.abi.NativeEntryPoint", onlyWith = ForeignFunctionsEnabled.class) @Substitute public final class Target_jdk_internal_foreign_abi_NativeEntryPoint { diff --git a/substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/Target_jdk_internal_misc_ScopedMemoryAccess.java b/substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/Target_jdk_internal_misc_ScopedMemoryAccess.java index ef77d680204b..811931893aa7 100644 --- a/substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/Target_jdk_internal_misc_ScopedMemoryAccess.java +++ b/substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/Target_jdk_internal_misc_ScopedMemoryAccess.java @@ -39,7 +39,7 @@ *

* It seems like this could be easily supported once thread-local handshakes are supported. */ -@TargetClass(className = "jdk.internal.misc.ScopedMemoryAccess") +@TargetClass(className = "jdk.internal.misc.ScopedMemoryAccess", onlyWith = ForeignFunctionsEnabled.class) public final class Target_jdk_internal_misc_ScopedMemoryAccess { @Substitute static void registerNatives() { @@ -80,6 +80,6 @@ boolean closeScope0(MemorySessionImpl session) { } } -@TargetClass(className = "jdk.internal.misc.ScopedMemoryAccess$ScopedAccessError", onlyWith = JDK22OrLater.class) +@TargetClass(className = "jdk.internal.misc.ScopedMemoryAccess$ScopedAccessError", onlyWith = {JDK22OrLater.class, ForeignFunctionsEnabled.class}) final class Target_jdk_internal_misc_ScopedMemoryAccess_ScopedAccessError { } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java index d827d45a9445..3394043aeebc 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java @@ -1040,6 +1040,9 @@ public enum ReportingMode { @Option(help = "Include all classes, methods, fields, and resources from given paths", type = OptionType.Debug) // public static final HostedOptionKey IncludeAllFromPath = new HostedOptionKey<>(LocatableMultiOptionValue.Strings.build()); + @Option(help = "Support for calls via the Java Foreign Function and Memory API", type = Expert) // + public static final HostedOptionKey ForeignAPISupport = new HostedOptionKey<>(false); + public static class TruffleStableOptions { @Option(help = "Automatically copy the necessary language resources to the resources/languages directory next to the produced image." + diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/ForeignDisabledSubstitutions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/ForeignDisabledSubstitutions.java new file mode 100644 index 000000000000..f0eb0b704ff4 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/ForeignDisabledSubstitutions.java @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2023, 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.svm.core.jdk; + +import java.io.IOException; +import java.lang.invoke.VarHandle; +import java.nio.channels.FileChannel; +import java.util.List; +import java.util.Set; +import java.util.function.BooleanSupplier; +import java.util.function.Function; + +import com.oracle.svm.core.AlwaysInline; +import com.oracle.svm.core.SubstrateOptions; +import com.oracle.svm.core.annotate.Substitute; +import com.oracle.svm.core.annotate.TargetClass; +import com.oracle.svm.core.option.SubstrateOptionsParser; +import com.oracle.svm.core.util.VMError; + +/* Substitutions for when Foreign Function and Memory (FFM) API support is disabled. */ + +final class ForeignDisabled implements BooleanSupplier { + @Override + public boolean getAsBoolean() { + return !SubstrateOptions.ForeignAPISupport.getValue(); + } +} + +@TargetClass(className = "jdk.internal.foreign.MemorySessionImpl", onlyWith = ForeignDisabled.class) +final class Target_jdk_internal_foreign_MemorySessionImpl { + @Substitute + Target_java_lang_foreign_Arena asArena() { + throw ForeignDisabledSubstitutions.fail(); + } +} + +@TargetClass(className = "java.lang.foreign.Arena", onlyWith = ForeignDisabled.class) +final class Target_java_lang_foreign_Arena { +} + +@TargetClass(className = "java.lang.foreign.Linker", onlyWith = ForeignDisabled.class) +final class Target_java_lang_foreign_Linker { +} + +@TargetClass(className = "jdk.internal.foreign.abi.SharedUtils", onlyWith = ForeignDisabled.class) +final class Target_jdk_internal_foreign_abi_SharedUtils { + @Substitute + static Target_java_lang_foreign_Arena newBoundedArena(long size) { + throw ForeignDisabledSubstitutions.fail(); + } + + @Substitute + static Target_java_lang_foreign_Arena newEmptyArena() { + throw ForeignDisabledSubstitutions.fail(); + } + + @Substitute + static Target_java_lang_foreign_Linker getSystemLinker() { + throw ForeignDisabledSubstitutions.fail(); + } +} + +@TargetClass(className = "java.lang.foreign.MemoryLayout", onlyWith = ForeignDisabled.class) +final class Target_java_lang_foreign_MemoryLayout { +} + +@TargetClass(className = "jdk.internal.foreign.FunctionDescriptorImpl", onlyWith = ForeignDisabled.class) +final class Target_jdk_internal_foreign_FunctionDescriptorImpl { + @Substitute + Target_jdk_internal_foreign_FunctionDescriptorImpl(Target_java_lang_foreign_MemoryLayout resLayout, List argLayouts) { + throw ForeignDisabledSubstitutions.fail(); + } +} + +@TargetClass(className = "jdk.internal.foreign.SegmentFactories", onlyWith = {ForeignDisabled.class, JDK22OrLater.class}) +final class Target_jdk_internal_foreign_SegmentFactories { + @Substitute + @AlwaysInline("Make remaining code in callers unreachable.") + static void ensureInitialized() { + throw ForeignDisabledSubstitutions.fail(); + } +} + +@TargetClass(className = "sun.nio.ch.FileChannelImpl", onlyWith = ForeignDisabled.class) +final class Target_sun_nio_ch_FileChannelImpl { + @Substitute + Target_java_lang_foreign_MemorySegment map(FileChannel.MapMode mode, long offset, long size, Target_java_lang_foreign_Arena arena) throws IOException { + throw ForeignDisabledSubstitutions.fail(); + } +} + +@TargetClass(className = "jdk.internal.foreign.LayoutPath", onlyWith = ForeignDisabled.class) +final class Target_jdk_internal_foreign_LayoutPath { +} + +@TargetClass(className = "java.lang.foreign.MemoryLayout", innerClass = "PathElement", onlyWith = ForeignDisabled.class) +final class Target_java_lang_foreign_MemoryLayout_PathElement { +} + +@TargetClass(className = "jdk.internal.foreign.layout.AbstractLayout", onlyWith = {ForeignDisabled.class, JDK22OrLater.class}) +final class Target_jdk_internal_foreign_layout_AbstractLayout { + @Substitute + @AlwaysInline("Make remaining code in callers unreachable.") + VarHandle varHandle(Target_java_lang_foreign_MemoryLayout_PathElement... elements) { + throw ForeignDisabledSubstitutions.fail(); + } + + @Substitute + static Z computePathOp(Target_jdk_internal_foreign_LayoutPath path, Function finalizer, + Set badKinds, Target_java_lang_foreign_MemoryLayout_PathElement... elements) { + throw ForeignDisabledSubstitutions.fail(); + } +} + +final class ForeignDisabledSubstitutions { + private static final String OPTION_NAME = SubstrateOptionsParser.commandArgument(SubstrateOptions.ForeignAPISupport, "+"); + + static RuntimeException fail() { + assert !SubstrateOptions.ForeignAPISupport.getValue(); + throw VMError.unsupportedFeature("Support for the Java Foreign Function and Memory API is not active: enable with " + OPTION_NAME); + } +} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_Module.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_Module.java index 10996ed2d0e6..0238aac44e55 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_Module.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_Module.java @@ -37,6 +37,12 @@ @SuppressWarnings("unused") @TargetClass(value = java.lang.Module.class) public final class Target_java_lang_Module { + @Substitute + @TargetElement(onlyWith = ForeignDisabled.class) + public boolean isNativeAccessEnabled() { + throw ForeignDisabledSubstitutions.fail(); + } + @Alias @TargetElement(onlyWith = JDK21OrEarlier.class) public native void ensureNativeAccess(Class owner, String methodName); diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_reflect_Reflection.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_reflect_Reflection.java index 07473bee98dd..d63d006adb4e 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_reflect_Reflection.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_reflect_Reflection.java @@ -27,15 +27,24 @@ import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.impl.InternalPlatform; +import com.oracle.svm.core.AlwaysInline; import com.oracle.svm.core.NeverInline; import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; +import com.oracle.svm.core.annotate.TargetElement; import com.oracle.svm.core.hub.DynamicHub; import com.oracle.svm.core.snippets.KnownIntrinsics; @TargetClass(value = jdk.internal.reflect.Reflection.class) final class Target_jdk_internal_reflect_Reflection { + @TargetElement(onlyWith = ForeignDisabled.class) + @Substitute + @AlwaysInline("Make remaining code in callers unreachable.") + static void ensureNativeAccess(Class currentClass, Class owner, String methodName) { + throw ForeignDisabledSubstitutions.fail(); + } + @Substitute @NeverInline("Starting a stack walk in the caller frame") @Platforms(InternalPlatform.NATIVE_ONLY.class) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_sun_nio_ch_Util.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_sun_nio_ch_Util.java index 641b11507d09..8e0ff99ce6a7 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_sun_nio_ch_Util.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_sun_nio_ch_Util.java @@ -25,16 +25,23 @@ package com.oracle.svm.core.jdk; import java.io.FileDescriptor; +import java.nio.Buffer; import java.nio.MappedByteBuffer; import com.oracle.svm.core.SubstrateUtil; import com.oracle.svm.core.annotate.Alias; import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; +import com.oracle.svm.core.annotate.TargetElement; @TargetClass(className = "java.lang.foreign.MemorySegment") @SuppressWarnings("unused") final class Target_java_lang_foreign_MemorySegment { + @TargetElement(onlyWith = ForeignDisabled.class) + @Substitute + static Target_java_lang_foreign_MemorySegment ofBuffer(Buffer buffer) { + throw ForeignDisabledSubstitutions.fail(); + } } @TargetClass(className = "java.nio.DirectByteBufferR") diff --git a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/DefaultOptionHandler.java b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/DefaultOptionHandler.java index df0cbe0bad92..5f277a36a631 100644 --- a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/DefaultOptionHandler.java +++ b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/DefaultOptionHandler.java @@ -129,7 +129,6 @@ public boolean consume(ArgumentQueue args) { case "--enable-preview": args.poll(); nativeImage.addCustomJavaArgs("--enable-preview"); - nativeImage.enablePreview(); return true; case nativeAccessOption: args.poll(); @@ -137,7 +136,7 @@ public boolean consume(ArgumentQueue args) { if (modules == null) { NativeImage.showError(nativeAccessOption + moduleSetModifierOptionErrorMessage); } - nativeImage.addCustomJavaArgs(nativeAccessOption + "=" + modules + ",org.graalvm.nativeimage.foreign"); + nativeImage.addCustomJavaArgs(nativeAccessOption + "=" + modules + ",org.graalvm.nativeimage.builder"); return true; } @@ -218,7 +217,7 @@ public boolean consume(ArgumentQueue args) { if (nativeAccessModules.isEmpty()) { NativeImage.showError(headArg + moduleSetModifierOptionErrorMessage); } - nativeImage.addCustomJavaArgs(headArg + ",org.graalvm.nativeimage.foreign"); + nativeImage.addCustomJavaArgs(headArg + ",org.graalvm.nativeimage.builder"); return true; } return false; diff --git a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java index 1bffeeccd3ae..633937f8ff03 100644 --- a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java +++ b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java @@ -319,7 +319,6 @@ protected static class BuildConfiguration { protected final Path workDir; protected final Path rootDir; protected final Path libJvmciDir; - protected final Path libPreviewDir; protected final List args; BuildConfiguration(BuildConfiguration original) { @@ -328,7 +327,6 @@ protected static class BuildConfiguration { workDir = original.workDir; rootDir = original.rootDir; libJvmciDir = original.libJvmciDir; - libPreviewDir = original.libPreviewDir; args = original.args; } @@ -371,8 +369,6 @@ protected BuildConfiguration(List args) { } Path ljDir = this.rootDir.resolve(Paths.get("lib", "jvmci")); libJvmciDir = Files.exists(ljDir) ? ljDir : null; - Path lpDir = this.rootDir.resolve(Paths.get("lib", "svm-preview", "builder")); - libPreviewDir = Files.exists(lpDir) ? lpDir : null; } /** @@ -1895,43 +1891,6 @@ Path canonicalize(Path path, boolean strict) { } } - public enum PreviewFeatures { - FOREIGN(JavaVersionUtil.JAVA_SPEC >= 21, "svm-foreign"); - - private final boolean requirementsMet; - private final String libName; - - PreviewFeatures(boolean requirementsMet, String libName) { - this.requirementsMet = requirementsMet; - this.libName = libName; - } - - public boolean requirementsMet() { - return requirementsMet; - } - - public String getLibName() { - return libName; - } - } - - public void enablePreview() { - if (config.libPreviewDir == null && PreviewFeatures.values().length > 0) { - throw showError("The directory containing the preview modules was not found."); - } - - for (var preview : PreviewFeatures.values()) { - if (preview.requirementsMet()) { - Path libPath = config.libPreviewDir == null ? null : config.libPreviewDir.resolve(preview.getLibName() + ".jar"); - if (libPath != null && Files.exists(libPath)) { - addImageBuilderModulePath(libPath); - } else { - throw showError("Preview library " + preview.getLibName() + " should be enabled, but was not found."); - } - } - } - } - public void addImageBuilderModulePath(Path modulePathEntry) { imageBuilderModulePath.add(canonicalize(modulePathEntry)); } diff --git a/substratevm/src/com.oracle.svm.hosted.foreign/src/com/oracle/svm/hosted/foreign/ForeignFunctionsFeature.java b/substratevm/src/com.oracle.svm.hosted.foreign/src/com/oracle/svm/hosted/foreign/ForeignFunctionsFeature.java index aea603fa5035..24cced11e590 100644 --- a/substratevm/src/com.oracle.svm.hosted.foreign/src/com/oracle/svm/hosted/foreign/ForeignFunctionsFeature.java +++ b/substratevm/src/com.oracle.svm.hosted.foreign/src/com/oracle/svm/hosted/foreign/ForeignFunctionsFeature.java @@ -35,8 +35,6 @@ import java.util.function.Function; import org.graalvm.collections.Pair; -import jdk.graal.compiler.api.replacements.Fold; -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; @@ -62,7 +60,6 @@ import com.oracle.svm.core.graal.meta.SubstrateForeignCallsProvider; import com.oracle.svm.core.meta.MethodPointer; import com.oracle.svm.core.util.UserError; -import com.oracle.svm.core.util.VMError; import com.oracle.svm.hosted.ConditionalConfigurationRegistry; import com.oracle.svm.hosted.FeatureImpl; import com.oracle.svm.hosted.ProgressReporter; @@ -70,24 +67,13 @@ import com.oracle.svm.util.ModuleSupport; import com.oracle.svm.util.ReflectionUtil; +import jdk.graal.compiler.api.replacements.Fold; +import jdk.graal.compiler.serviceprovider.JavaVersionUtil; import jdk.vm.ci.meta.ResolvedJavaMethod; @AutomaticallyRegisteredFeature @Platforms(Platform.HOSTED_ONLY.class) public class ForeignFunctionsFeature implements InternalFeature { - private static boolean isPreviewEnabled() { - try { - return (boolean) ReflectionUtil.lookupMethod( - ReflectionUtil.lookupClass(false, "jdk.internal.misc.PreviewFeatures"), - "isEnabled").invoke(null); - } catch (ReflectiveOperationException e) { - throw VMError.shouldNotReachHere(e); - } - } - - private static final int FIRST_SUPPORTED_PREVIEW = 21; - private static final int FIRST_SUPPORTED_NON_PREVIEW = Integer.MAX_VALUE - 1; // TBD - private static final Map REQUIRES_CONCEALED = Map.of( "jdk.internal.vm.ci", new String[]{"jdk.vm.ci.code", "jdk.vm.ci.meta", "jdk.vm.ci.amd64"}, "java.base", new String[]{ @@ -122,8 +108,8 @@ public void registerForDowncall(ConfigurationCondition condition, FunctionDescri ForeignFunctionsFeature() { /* - * We add these exports systematically in the constructor, as to avoid access errors from - * plugins when the feature is disabled in the config. + * We intentionally add these exports in the constructor to avoid access errors from plugins + * when the feature is disabled in the config. */ for (var modulePackages : REQUIRES_CONCEALED.entrySet()) { ModuleSupport.accessPackagesToClass(ModuleSupport.Access.EXPORT, ForeignFunctionsFeature.class, false, modulePackages.getKey(), modulePackages.getValue()); @@ -132,16 +118,17 @@ public void registerForDowncall(ConfigurationCondition condition, FunctionDescri @Override public boolean isInConfiguration(IsInConfigurationAccess access) { - return SubstrateUtil.getArchitectureName().contains("amd64") && !SubstrateOptions.useLLVMBackend(); + if (!SubstrateOptions.ForeignAPISupport.getValue()) { + return false; + } + UserError.guarantee(JavaVersionUtil.JAVA_SPEC >= 22, "Support for the Foreign Function and Memory API is available only with JDK 22 and later."); + UserError.guarantee(SubstrateUtil.getArchitectureName().contains("amd64"), "Support for the Foreign Function and Memory API is currently available only on the AMD64 architecture."); + UserError.guarantee(!SubstrateOptions.useLLVMBackend(), "Support for the Foreign Function and Memory API is not available with the LLVM backend."); + return true; } @Override public void duringSetup(DuringSetupAccess a) { - assert (JavaVersionUtil.JAVA_SPEC >= FIRST_SUPPORTED_PREVIEW && isPreviewEnabled()) || - JavaVersionUtil.JAVA_SPEC >= FIRST_SUPPORTED_NON_PREVIEW; - - UserError.guarantee(!SubstrateOptions.useLLVMBackend(), "Foreign functions interface is in use, but is not supported together with the LLVM backend."); - ImageSingletons.add(AbiUtils.class, AbiUtils.create()); ImageSingletons.add(ForeignFunctionsRuntime.class, new ForeignFunctionsRuntime()); ImageSingletons.add(RuntimeForeignAccessSupport.class, accessSupport); diff --git a/vm/mx.vm/mx_vm.py b/vm/mx.vm/mx_vm.py index db4b0894d1a1..ed2bb07b0875 100644 --- a/vm/mx.vm/mx_vm.py +++ b/vm/mx.vm/mx_vm.py @@ -189,10 +189,10 @@ def local_path_to_url(args): llvm_components = ['bgraalvm-native-binutil', 'bgraalvm-native-clang', 'bgraalvm-native-clang-cl', 'bgraalvm-native-clang++', 'bgraalvm-native-flang', 'bgraalvm-native-ld'] # pylint: disable=line-too-long -ce_unchained_components = ['bnative-image-configure', 'cmp', 'lg', 'ni', 'nic', 'nil', 'nr_lib_jvmcicompiler', 'sdkc', 'sdkni', 'svm', 'svmforeign', 'svmsl', 'svmt', 'tflc', 'tflsm'] +ce_unchained_components = ['bnative-image-configure', 'cmp', 'lg', 'ni', 'nic', 'nil', 'nr_lib_jvmcicompiler', 'sdkc', 'sdkni', 'svm', 'svmsl', 'svmt', 'tflc', 'tflsm'] ce_components_minimal = ['bpolyglot', 'cmp', 'cov', 'dap', 'gu', 'gvm', 'ins', 'insight', 'insightheap', 'lg', 'libpoly', 'lsp', 'nfi-libffi', 'nfi', 'poly', 'polynative', 'pro', 'sdk', 'sdkni', 'sdkc', 'sdkl', 'spolyglot', 'tfl', 'tfla', 'tflc', 'tflm', 'truffle-json'] -ce_components = ce_components_minimal + ['nr_lib_jvmcicompiler', 'bnative-image-configure', 'ni', 'nic', 'nil', 'svm', 'svmt', 'svmnfi', 'svmsl', 'svmforeign'] -ce_win_complete_components = ['antlr4', 'bnative-image-configure', 'bpolyglot', 'cmp', 'cov', 'dap', 'ejvm', 'gu', 'gvm', 'gwa', 'gwal', 'icu4j', 'xz', 'ins', 'insight', 'insightheap', 'java', 'js', 'jsl', 'jss', 'lg', 'libpoly', 'llp', 'llrc', 'llrl', 'llrlf', 'llrn', 'lsp', 'nfi-libffi', 'nfi', 'ni', 'nic', 'nil', 'njs', 'njsl', 'poly', 'polynative', 'pro', 'pyn', 'pynl', 'rgx', 'sdk', 'sdkni', 'sdkc', 'sdkl', 'spolyglot', 'svm', 'svmt', 'svmnfi', 'svmsl', 'svmforeign', 'tfl', 'tfla', 'tflc', 'tflm', 'truffle-json', 'vvm'] +ce_components = ce_components_minimal + ['nr_lib_jvmcicompiler', 'bnative-image-configure', 'ni', 'nic', 'nil', 'svm', 'svmt', 'svmnfi', 'svmsl'] +ce_win_complete_components = ['antlr4', 'bnative-image-configure', 'bpolyglot', 'cmp', 'cov', 'dap', 'ejvm', 'gu', 'gvm', 'gwa', 'gwal', 'icu4j', 'xz', 'ins', 'insight', 'insightheap', 'java', 'js', 'jsl', 'jss', 'lg', 'libpoly', 'llp', 'llrc', 'llrl', 'llrlf', 'llrn', 'lsp', 'nfi-libffi', 'nfi', 'ni', 'nic', 'nil', 'njs', 'njsl', 'poly', 'polynative', 'pro', 'pyn', 'pynl', 'rgx', 'sdk', 'sdkni', 'sdkc', 'sdkl', 'spolyglot', 'svm', 'svmt', 'svmnfi', 'svmsl', 'tfl', 'tfla', 'tflc', 'tflm', 'truffle-json', 'vvm'] ce_aarch64_complete_components = ce_win_complete_components + ['rby', 'rbyl', 'svml'] ce_complete_components = ce_aarch64_complete_components + ['ellvm', 'R', 'bRMain', 'xz'] ce_darwin_aarch64_complete_components = list(ce_aarch64_complete_components) @@ -227,15 +227,15 @@ def local_path_to_url(args): mx_sdk_vm.register_vm_config('toolchain-only', ['antlr4', 'sdk', 'sdkni', 'sdkc', 'sdkl', 'tfl', 'tfla', 'tflc', 'tflm', 'nfi-libffi', 'nfi', 'cmp', 'llp', 'llrc', 'llrlf', 'llrn'], _suite) mx_sdk_vm.register_vm_config('libgraal-bash', llvm_components + ['cmp', 'gu', 'gvm', 'lg', 'nfi-libffi', 'nfi', 'poly', 'polynative', 'sdk', 'sdkni', 'sdkc', 'sdkl', 'tfl', 'tfla', 'tflc', 'tflm', 'bpolyglot'], _suite, env_file=False) mx_sdk_vm.register_vm_config('toolchain-only-bash', llvm_components + ['antlr4', 'tfl', 'tfla', 'tflc', 'tflm', 'gu', 'gvm', 'polynative', 'llp', 'nfi-libffi', 'nfi', 'svml', 'sdk', 'sdkni', 'sdkc', 'sdkl', 'llrc', 'llrlf', 'llrn', 'cmp'], _suite, env_file=False) -mx_sdk_vm.register_vm_config('ce', llvm_components + ['antlr4', 'java', 'libpoly', 'sjavavm', 'spolyglot', 'ejvm', 'sjsvm', 'sllvmvm', 'bnative-image', 'srubyvm', 'pynl', 'spythonvm', 'pyn', 'cmp', 'gwa', 'gwal', 'icu4j', 'xz', 'js', 'jsl', 'jss', 'lg', 'llp', 'nfi-libffi', 'nfi', 'ni', 'nil', 'pbm', 'pmh', 'pbi', 'rby', 'rbyl', 'rgx', 'sdk', 'sdkni', 'sdkc', 'sdkl', 'llrc', 'llrn', 'llrl', 'llrlf', 'snative-image-agent', 'snative-image-diagnostics-agent', 'svm', 'svmt', 'svmnfi', 'svmsl', 'svmforeign', 'swasmvm', 'tfl', 'tfla', 'tflc', 'tflm'], _suite, env_file='polybench-ce') -mx_sdk_vm.register_vm_config('ce', ['bnative-image', 'bpolybench', 'cmp', 'icu4j', 'xz', 'lg', 'nfi', 'ni', 'nil', 'pbi', 'pbm', 'pmh', 'sdk', 'sdkni', 'sdkc', 'sdkl', 'snative-image-agent', 'snative-image-diagnostics-agent', 'svm', 'svmt', 'svmnfi', 'svmsl', 'svmforeign', 'tfl', 'tfla', 'tflc', 'tflm'], _suite, dist_name='ce', env_file='polybench-ctw-ce') -mx_sdk_vm.register_vm_config('ce', ['pbm', 'pmh', 'pbi', 'ni', 'icu4j', 'xz', 'js', 'jsl', 'jss', 'lg', 'nfi-libffi', 'nfi', 'tfl', 'tfla', 'tflc', 'svm', 'svmt', 'nil', 'rgx', 'sdk', 'sdkni', 'sdkc', 'sdkl', 'cmp', 'tflm', 'svmnfi', 'svmsl', 'svmforeign', 'bnative-image', 'sjsvm', 'snative-image-agent', 'snative-image-diagnostics-agent'], _suite, env_file='polybench-nfi-ce') -mx_sdk_vm.register_vm_config('ce', llvm_components + ['antlr4', 'sllvmvm', 'bnative-image', 'cmp', 'lg', 'llrc', 'llrl', 'llrlf', 'llrn', 'nfi-libffi', 'nfi', 'ni', 'nil', 'pbm', 'pbi', 'sdk', 'sdkni', 'sdkc', 'sdkl', 'snative-image-agent', 'snative-image-diagnostics-agent', 'svm', 'svmt', 'svmnfi', 'svmsl', 'svmforeign', 'tfl', 'tfla', 'tflc', 'tflm'], _suite, env_file='polybench-sulong-ce') +mx_sdk_vm.register_vm_config('ce', llvm_components + ['antlr4', 'java', 'libpoly', 'sjavavm', 'spolyglot', 'ejvm', 'sjsvm', 'sllvmvm', 'bnative-image', 'srubyvm', 'pynl', 'spythonvm', 'pyn', 'cmp', 'gwa', 'gwal', 'icu4j', 'xz', 'js', 'jsl', 'jss', 'lg', 'llp', 'nfi-libffi', 'nfi', 'ni', 'nil', 'pbm', 'pmh', 'pbi', 'rby', 'rbyl', 'rgx', 'sdk', 'sdkni', 'sdkc', 'sdkl', 'llrc', 'llrn', 'llrl', 'llrlf', 'snative-image-agent', 'snative-image-diagnostics-agent', 'svm', 'svmt', 'svmnfi', 'svmsl', 'swasmvm', 'tfl', 'tfla', 'tflc', 'tflm'], _suite, env_file='polybench-ce') +mx_sdk_vm.register_vm_config('ce', ['bnative-image', 'bpolybench', 'cmp', 'icu4j', 'xz', 'lg', 'nfi', 'ni', 'nil', 'pbi', 'pbm', 'pmh', 'sdk', 'sdkni', 'sdkc', 'sdkl', 'snative-image-agent', 'snative-image-diagnostics-agent', 'svm', 'svmt', 'svmnfi', 'svmsl', 'tfl', 'tfla', 'tflc', 'tflm'], _suite, dist_name='ce', env_file='polybench-ctw-ce') +mx_sdk_vm.register_vm_config('ce', ['pbm', 'pmh', 'pbi', 'ni', 'icu4j', 'xz', 'js', 'jsl', 'jss', 'lg', 'nfi-libffi', 'nfi', 'tfl', 'tfla', 'tflc', 'svm', 'svmt', 'nil', 'rgx', 'sdk', 'sdkni', 'sdkc', 'sdkl', 'cmp', 'tflm', 'svmnfi', 'svmsl', 'bnative-image', 'sjsvm', 'snative-image-agent', 'snative-image-diagnostics-agent'], _suite, env_file='polybench-nfi-ce') +mx_sdk_vm.register_vm_config('ce', llvm_components + ['antlr4', 'sllvmvm', 'bnative-image', 'cmp', 'lg', 'llrc', 'llrl', 'llrlf', 'llrn', 'nfi-libffi', 'nfi', 'ni', 'nil', 'pbm', 'pbi', 'sdk', 'sdkni', 'sdkc', 'sdkl', 'snative-image-agent', 'snative-image-diagnostics-agent', 'svm', 'svmt', 'svmnfi', 'svmsl', 'tfl', 'tfla', 'tflc', 'tflm'], _suite, env_file='polybench-sulong-ce') if mx.get_os() == 'windows': - mx_sdk_vm.register_vm_config('svm', ['bnative-image', 'bnative-image-configure', 'bpolyglot', 'cmp', 'gvm', 'nfi-libffi', 'nfi', 'ni', 'nil', 'nju', 'njucp', 'nic', 'poly', 'polynative', 'rgx', 'sdk', 'sdkni', 'sdkc', 'sdkl', 'snative-image-agent', 'snative-image-diagnostics-agent', 'svm', 'svmt', 'svmnfi', 'svmsl', 'svmforeign', 'tfl', 'tfla', 'tflc', 'tflm'], _suite, env_file=False) + mx_sdk_vm.register_vm_config('svm', ['bnative-image', 'bnative-image-configure', 'bpolyglot', 'cmp', 'gvm', 'nfi-libffi', 'nfi', 'ni', 'nil', 'nju', 'njucp', 'nic', 'poly', 'polynative', 'rgx', 'sdk', 'sdkni', 'sdkc', 'sdkl', 'snative-image-agent', 'snative-image-diagnostics-agent', 'svm', 'svmt', 'svmnfi', 'svmsl', 'tfl', 'tfla', 'tflc', 'tflm'], _suite, env_file=False) else: - mx_sdk_vm.register_vm_config('svm', ['bnative-image', 'bnative-image-configure', 'bpolyglot', 'cmp', 'gu', 'gvm', 'nfi-libffi', 'nfi', 'ni', 'nil', 'nju', 'njucp', 'nic', 'poly', 'polynative', 'rgx', 'sdk', 'sdkni', 'sdkc', 'sdkl', 'snative-image-agent', 'snative-image-diagnostics-agent', 'svm', 'svmt', 'svmnfi', 'svmsl', 'svml', 'svmforeign', 'tfl', 'tfla', 'tflc', 'tflm'], _suite, env_file=False) + mx_sdk_vm.register_vm_config('svm', ['bnative-image', 'bnative-image-configure', 'bpolyglot', 'cmp', 'gu', 'gvm', 'nfi-libffi', 'nfi', 'ni', 'nil', 'nju', 'njucp', 'nic', 'poly', 'polynative', 'rgx', 'sdk', 'sdkni', 'sdkc', 'sdkl', 'snative-image-agent', 'snative-image-diagnostics-agent', 'svm', 'svmt', 'svmnfi', 'svmsl', 'svml', 'tfl', 'tfla', 'tflc', 'tflm'], _suite, env_file=False) # pylint: enable=line-too-long From 4f147efeafc6687e3690a9100d6b38b762e83185 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Wed, 6 Dec 2023 13:40:30 +0100 Subject: [PATCH 2/2] svm: reintroduce SVM_FOREIGN distribution --- compiler/mx.compiler/suite.py | 1 + sdk/mx.sdk/suite.py | 3 +- substratevm/mx.substratevm/mx_substratevm.py | 2 +- substratevm/mx.substratevm/suite.py | 43 ++++++++++++++++++-- 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/compiler/mx.compiler/suite.py b/compiler/mx.compiler/suite.py index c81103331dae..96870bee17e2 100644 --- a/compiler/mx.compiler/suite.py +++ b/compiler/mx.compiler/suite.py @@ -498,6 +498,7 @@ """* to com.oracle.graal.graal_enterprise, org.graalvm.nativeimage.pointsto, org.graalvm.nativeimage.builder, + org.graalvm.nativeimage.foreign, org.graalvm.nativeimage.llvm, com.oracle.svm.svm_enterprise, com.oracle.svm_enterprise.ml_dataset, diff --git a/sdk/mx.sdk/suite.py b/sdk/mx.sdk/suite.py index d9fbc2637fc3..a7ceded8071e 100644 --- a/sdk/mx.sdk/suite.py +++ b/sdk/mx.sdk/suite.py @@ -668,7 +668,8 @@ class UniversalDetector { com.oracle.svm.svm_enterprise, org.graalvm.extraimage.builder, org.graalvm.truffle.runtime.svm, - com.oracle.svm.enterprise.truffle""", + com.oracle.svm.enterprise.truffle, + org.graalvm.nativeimage.foreign""", "org.graalvm.nativeimage.impl.clinit to org.graalvm.nativeimage.builder", ], "uses" : [], diff --git a/substratevm/mx.substratevm/mx_substratevm.py b/substratevm/mx.substratevm/mx_substratevm.py index d026fa65b01e..0f81e6c83e62 100644 --- a/substratevm/mx.substratevm/mx_substratevm.py +++ b/substratevm/mx.substratevm/mx_substratevm.py @@ -1005,7 +1005,7 @@ def native_image_context_run(func, func_args=None, config=None, build_if_missing 'substratevm:OBJECTFILE', 'substratevm:POINTSTO', 'substratevm:NATIVE_IMAGE_BASE', - ], + ] + (['substratevm:SVM_FOREIGN'] if mx_sdk_vm.base_jdk().javaCompliance >= '22' else []), support_distributions=['substratevm:SVM_GRAALVM_SUPPORT'], stability="earlyadopter", jlink=False, diff --git a/substratevm/mx.substratevm/suite.py b/substratevm/mx.substratevm/suite.py index fa7f517de354..ff63e6e642c9 100644 --- a/substratevm/mx.substratevm/suite.py +++ b/substratevm/mx.substratevm/suite.py @@ -1420,7 +1420,6 @@ "dependencies": [ "com.oracle.svm.graal", "com.oracle.svm.hosted", - "com.oracle.svm.hosted.foreign", "com.oracle.svm.core", "com.oracle.svm.core.graal.amd64", "com.oracle.svm.core.graal.aarch64", @@ -1886,9 +1885,9 @@ "name" : "org.graalvm.nativeimage.base", "requires" : ["java.sql", "java.xml"],# workaround for GR-47773 on the module-path which requires java.sql (like truffle) or java.xml "exports" : [ - "com.oracle.svm.util to org.graalvm.nativeimage.pointsto,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.librarysupport,org.graalvm.nativeimage.driver,org.graalvm.nativeimage.llvm,org.graalvm.nativeimage.agent.jvmtibase,org.graalvm.nativeimage.agent.tracing,org.graalvm.nativeimage.agent.diagnostics,org.graalvm.nativeimage.junitsupport,com.oracle.svm.svm_enterprise,com.oracle.svm_enterprise.ml_dataset,org.graalvm.extraimage.builder,com.oracle.svm.extraimage_enterprise,org.graalvm.extraimage.librarysupport,org.graalvm.truffle.runtime.svm,com.oracle.truffle.enterprise.svm", - "com.oracle.svm.common.meta to org.graalvm.nativeimage.pointsto,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.llvm,org.graalvm.extraimage.builder,org.graalvm.truffle.runtime.svm,com.oracle.truffle.enterprise.svm", - "com.oracle.svm.common.option to org.graalvm.nativeimage.pointsto,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.driver,org.graalvm.truffle.runtime.svm,com.oracle.truffle.enterprise.svm", + "com.oracle.svm.util to org.graalvm.nativeimage.pointsto,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.librarysupport,org.graalvm.nativeimage.driver,org.graalvm.nativeimage.llvm,org.graalvm.nativeimage.agent.jvmtibase,org.graalvm.nativeimage.agent.tracing,org.graalvm.nativeimage.agent.diagnostics,org.graalvm.nativeimage.junitsupport,com.oracle.svm.svm_enterprise,com.oracle.svm_enterprise.ml_dataset,org.graalvm.extraimage.builder,com.oracle.svm.extraimage_enterprise,org.graalvm.extraimage.librarysupport,org.graalvm.nativeimage.foreign,org.graalvm.truffle.runtime.svm,com.oracle.truffle.enterprise.svm", + "com.oracle.svm.common.meta to org.graalvm.nativeimage.pointsto,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.llvm,org.graalvm.extraimage.builder,org.graalvm.nativeimage.foreign,org.graalvm.truffle.runtime.svm,com.oracle.truffle.enterprise.svm", + "com.oracle.svm.common.option to org.graalvm.nativeimage.pointsto,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.driver,org.graalvm.nativeimage.foreign,org.graalvm.truffle.runtime.svm,com.oracle.truffle.enterprise.svm", ], }, "noMavenJavadoc": True, @@ -2161,6 +2160,42 @@ }, }, + "SVM_FOREIGN": { + "subDir": "src", + "description" : "SubstrateVM support for the Foreign API", + "dependencies": [ + "com.oracle.svm.hosted.foreign", + ], + "distDependencies": [ + "compiler:GRAAL", + "SVM" + ], + "moduleInfo" : { + "name" : "org.graalvm.nativeimage.foreign", + "requires" : [ + "org.graalvm.nativeimage.builder" + ], + "exports" : [ + "* to org.graalvm.nativeimage.builder" + ], + "requiresConcealed": { + "jdk.internal.vm.ci" : [ + "jdk.vm.ci.meta", + "jdk.vm.ci.code", + "jdk.vm.ci.amd64", + ], + "java.base": [ + "jdk.internal.foreign", + "jdk.internal.foreign.abi", + "jdk.internal.foreign.abi.x64", + "jdk.internal.foreign.abi.x64.sysv", + "jdk.internal.foreign.abi.x64.windows", + ], + }, + }, + "maven" : False, + }, + "SVM_LLVM" : { "subDir" : "src", "description" : "LLVM backend for Native Image",