diff --git a/docs/reference-manual/native-image/FFM-API.md b/docs/reference-manual/native-image/FFM-API.md index 481f122967b5..6f4914ad67b1 100644 --- a/docs/reference-manual/native-image/FFM-API.md +++ b/docs/reference-manual/native-image/FFM-API.md @@ -17,9 +17,7 @@ Modules that are permitted to perform _restricted_ native operations (including ## Foreign Memory -Native Image supports most foreign memory features. -Support for shared arenas (`Arena.ofShared()`) is still experimental and needs to be explicitly enabled with `-H:+SharedArenaSupport` (together with `-H:+UnlockExperimentalVMOptions`). -Note: Building a native image that includes calls to `Arena.ofShared()` will still succeed even if support for shared arenas is disabled. However, an exception will be thrown at run time when the application attempts to close the shared arena. +Native Image supports all foreign memory features. ## Foreign Functions 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 a9554f50224e..3b8958d27486 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 @@ -1528,16 +1528,13 @@ public static boolean isForeignAPIEnabled() { public static final HostedOptionKey VectorAPISupport = new HostedOptionKey<>(false); @Option(help = "Enable support for Arena.ofShared ", type = Expert)// - public static final HostedOptionKey SharedArenaSupport = new HostedOptionKey<>(false, key -> { - if (key.getValue()) { - UserError.guarantee(isForeignAPIEnabled(), "Support for Arena.ofShared is only available with foreign API support. " + - "Enable foreign API support with %s", - SubstrateOptionsParser.commandArgument(ForeignAPISupport, "+")); - + public static final HostedOptionKey SharedArenaSupport = new HostedOptionKey<>(true, key -> { + if (isSharedArenaSupportEnabled()) { // GR-65162: Shared arenas cannot be used together with Vector API support - UserError.guarantee(!VectorAPIEnabled.getValue(), "Support for Arena.ofShared is not available with Vector API support. " + - "Either disable Vector API support using %s or replace usages of Arena.ofShared with Arena.ofAuto and disable shared arena support.", - SubstrateOptionsParser.commandArgument(VectorAPISupport, "-")); + UserError.guarantee(!VectorAPIEnabled.getValue(), "Support for Arena.ofShared (which is part of the FFM API) is not available with Vector API support. " + + "Either disable Vector API support using %s or replace usages of Arena.ofShared with Arena.ofAuto and disable shared arena support using %s.", + SubstrateOptionsParser.commandArgument(VectorAPISupport, "-"), + SubstrateOptionsParser.commandArgument(key, "-")); } }); 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 256acca4a8e0..7d02eb8497fa 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 @@ -48,6 +48,7 @@ import java.util.function.Supplier; import java.util.function.UnaryOperator; +import com.oracle.svm.core.thread.JavaThreads; import org.graalvm.collections.EconomicSet; import org.graalvm.nativeimage.AnnotationAccess; import org.graalvm.nativeimage.ImageSingletons; @@ -764,6 +765,7 @@ protected void initSafeArenaAccessors(BeforeAnalysisAccessImpl access) throws No registerSafeArenaAccessorMethod(metaAccess, ReflectionUtil.lookupMethod(mappedMemoryUtils, "unload", long.class, boolean.class, long.class)); registerSafeArenaAccessorMethod(metaAccess, ReflectionUtil.lookupMethod(SubstrateMappedMemoryUtils.class, "load", long.class, boolean.class, long.class)); registerSafeArenaAccessorMethod(metaAccess, Thread.class.getMethod("currentThread")); + registerSafeArenaAccessorMethod(metaAccess, JavaThreads.class.getMethod("getCurrentThreadOrNull")); /* * The actual method checking a valid session state (if not inlined) is also safe as this