From edf5831274150196d71f3ec5b72c8d5e2f92e7a4 Mon Sep 17 00:00:00 2001 From: Codrut Stancu Date: Tue, 2 Feb 2021 10:35:53 -0800 Subject: [PATCH 1/2] Add missing HOSTED_ONLY annotation. --- .../src/com/oracle/svm/core/c/NonmovableArrays.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/c/NonmovableArrays.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/c/NonmovableArrays.java index 2dc4d8950c64..71337c186861 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/c/NonmovableArrays.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/c/NonmovableArrays.java @@ -74,6 +74,8 @@ * via {@link #getHostedArray} and they must be cast back via {@link #fromImageHeap} at runtime. */ public final class NonmovableArrays { + + @Platforms(Platform.HOSTED_ONLY.class) // private static final HostedNonmovableArray HOSTED_NULL_VALUE = new HostedNonmovableObjectArray<>(null); private static final UninterruptibleUtils.AtomicLong runtimeArraysInExistence = new UninterruptibleUtils.AtomicLong(0); From 95624704e92cec4a6b6f3c9aee4794b036eb1f2b Mon Sep 17 00:00:00 2001 From: Codrut Stancu Date: Tue, 2 Feb 2021 10:36:05 -0800 Subject: [PATCH 2/2] Share manually allocated constant node between analysis and compilation. --- .../svm/hosted/code/CEntryPointCallStubSupport.java | 13 ++++++++++++- .../hosted/code/CEntryPointJavaCallStubMethod.java | 3 ++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/CEntryPointCallStubSupport.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/CEntryPointCallStubSupport.java index 9d4ae456f7be..18fa36ba2d84 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/CEntryPointCallStubSupport.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/CEntryPointCallStubSupport.java @@ -29,14 +29,15 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.function.Supplier; -import org.graalvm.nativeimage.hosted.Feature; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.c.function.CFunctionPointer; +import org.graalvm.nativeimage.hosted.Feature; import com.oracle.graal.pointsto.BigBang; import com.oracle.graal.pointsto.meta.AnalysisMethod; import com.oracle.svm.core.SubstrateUtil; import com.oracle.svm.core.annotate.AutomaticFeature; +import com.oracle.svm.core.c.BoxedRelocatedPointer; import com.oracle.svm.core.code.IsolateLeaveStub; import com.oracle.svm.hosted.FeatureImpl.BeforeAnalysisAccessImpl; import com.oracle.svm.hosted.FeatureImpl.DuringSetupAccessImpl; @@ -60,6 +61,12 @@ public static CEntryPointCallStubSupport singleton() { private final Map methodToJavaStub = new ConcurrentHashMap<>(); private NativeLibraries nativeLibraries; + /** + * Cache the BoxedRelocatedPointer objects to ensure that the same constant is seen during + * analysis and compilation. + */ + private final ConcurrentHashMap cFunctionPointerCache = new ConcurrentHashMap<>(); + private CEntryPointCallStubSupport(BigBang bigbang) { this.bigbang = bigbang; } @@ -121,6 +128,10 @@ public NativeLibraries getNativeLibraries() { assert nativeLibraries != null; return nativeLibraries; } + + public BoxedRelocatedPointer getBoxedRelocatedPointer(CFunctionPointer cFunctionPointer) { + return cFunctionPointerCache.computeIfAbsent(cFunctionPointer, t -> new BoxedRelocatedPointer(t)); + } } @AutomaticFeature diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/CEntryPointJavaCallStubMethod.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/CEntryPointJavaCallStubMethod.java index a4d9a7490e93..7f40c268204a 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/CEntryPointJavaCallStubMethod.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/CEntryPointJavaCallStubMethod.java @@ -46,6 +46,7 @@ * {@linkplain CEntryPointCallStubMethod native-to-Java stub}. */ public class CEntryPointJavaCallStubMethod extends CCallStubMethod { + private final String name; private final ResolvedJavaType declaringClass; private final CFunctionPointer target; @@ -79,7 +80,7 @@ protected ValueNode createTargetAddressNode(HostedGraphKit kit, HostedProviders * We currently cannot handle {@link MethodPointer} as a constant in the code, so we use an * indirection with a non-final field load from an object of BoxedRelocatedPointer. */ - BoxedRelocatedPointer box = new BoxedRelocatedPointer(target); + BoxedRelocatedPointer box = CEntryPointCallStubSupport.singleton().getBoxedRelocatedPointer(target); ConstantNode boxNode = kit.createObject(box); LoadFieldNode node = kit.createLoadFieldNode(boxNode, BoxedRelocatedPointer.class, "pointer"); return kit.append(node);