Skip to content

Commit a548f1b

Browse files
committed
[GR-68116] Enable shared arena support by default.
PullRequest: graal/21658
2 parents 87b0750 + 7d1c835 commit a548f1b

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

docs/reference-manual/native-image/FFM-API.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ Modules that are permitted to perform _restricted_ native operations (including
1717

1818
## Foreign Memory
1919

20-
Native Image supports most foreign memory features.
21-
Support for shared arenas (`Arena.ofShared()`) is still experimental and needs to be explicitly enabled with `-H:+SharedArenaSupport` (together with `-H:+UnlockExperimentalVMOptions`).
22-
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.
20+
Native Image supports all foreign memory features.
2321

2422
## Foreign Functions
2523

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,16 +1528,13 @@ public static boolean isForeignAPIEnabled() {
15281528
public static final HostedOptionKey<Boolean> VectorAPISupport = new HostedOptionKey<>(false);
15291529

15301530
@Option(help = "Enable support for Arena.ofShared ", type = Expert)//
1531-
public static final HostedOptionKey<Boolean> SharedArenaSupport = new HostedOptionKey<>(false, key -> {
1532-
if (key.getValue()) {
1533-
UserError.guarantee(isForeignAPIEnabled(), "Support for Arena.ofShared is only available with foreign API support. " +
1534-
"Enable foreign API support with %s",
1535-
SubstrateOptionsParser.commandArgument(ForeignAPISupport, "+"));
1536-
1531+
public static final HostedOptionKey<Boolean> SharedArenaSupport = new HostedOptionKey<>(true, key -> {
1532+
if (isSharedArenaSupportEnabled()) {
15371533
// GR-65162: Shared arenas cannot be used together with Vector API support
1538-
UserError.guarantee(!VectorAPIEnabled.getValue(), "Support for Arena.ofShared is not available with Vector API support. " +
1539-
"Either disable Vector API support using %s or replace usages of Arena.ofShared with Arena.ofAuto and disable shared arena support.",
1540-
SubstrateOptionsParser.commandArgument(VectorAPISupport, "-"));
1534+
UserError.guarantee(!VectorAPIEnabled.getValue(), "Support for Arena.ofShared (which is part of the FFM API) is not available with Vector API support. " +
1535+
"Either disable Vector API support using %s or replace usages of Arena.ofShared with Arena.ofAuto and disable shared arena support using %s.",
1536+
SubstrateOptionsParser.commandArgument(VectorAPISupport, "-"),
1537+
SubstrateOptionsParser.commandArgument(key, "-"));
15411538
}
15421539
});
15431540

substratevm/src/com.oracle.svm.hosted.foreign/src/com/oracle/svm/hosted/foreign/ForeignFunctionsFeature.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import java.util.function.Supplier;
4949
import java.util.function.UnaryOperator;
5050

51+
import com.oracle.svm.core.thread.JavaThreads;
5152
import org.graalvm.collections.EconomicSet;
5253
import org.graalvm.nativeimage.AnnotationAccess;
5354
import org.graalvm.nativeimage.ImageSingletons;
@@ -772,6 +773,7 @@ protected void initSafeArenaAccessors(BeforeAnalysisAccessImpl access) throws No
772773
registerSafeArenaAccessorMethod(metaAccess, ReflectionUtil.lookupMethod(mappedMemoryUtils, "unload", long.class, boolean.class, long.class));
773774
registerSafeArenaAccessorMethod(metaAccess, ReflectionUtil.lookupMethod(SubstrateMappedMemoryUtils.class, "load", long.class, boolean.class, long.class));
774775
registerSafeArenaAccessorMethod(metaAccess, Thread.class.getMethod("currentThread"));
776+
registerSafeArenaAccessorMethod(metaAccess, JavaThreads.class.getMethod("getCurrentThreadOrNull"));
775777

776778
/*
777779
* The actual method checking a valid session state (if not inlined) is also safe as this

0 commit comments

Comments
 (0)