Skip to content

Commit

Permalink
Share manually allocated constant node between analysis and compilation.
Browse files Browse the repository at this point in the history
  • Loading branch information
cstancu committed Feb 2, 2021
1 parent edf5831 commit 9562470
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -60,6 +61,12 @@ public static CEntryPointCallStubSupport singleton() {
private final Map<AnalysisMethod, AnalysisMethod> 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<CFunctionPointer, BoxedRelocatedPointer> cFunctionPointerCache = new ConcurrentHashMap<>();

private CEntryPointCallStubSupport(BigBang bigbang) {
this.bigbang = bigbang;
}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 9562470

Please sign in to comment.