Skip to content

Commit

Permalink
[GR-25050] Changes necessary for the heap scanning refactoring.
Browse files Browse the repository at this point in the history
PullRequest: graal/8102
  • Loading branch information
cstancu committed Feb 4, 2021
2 parents efc3db4 + 9562470 commit 50f5d55
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
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 50f5d55

Please sign in to comment.