Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
gluon-bot committed Oct 21, 2023
2 parents 59ce6df + 46f9be7 commit ea08331
Show file tree
Hide file tree
Showing 54 changed files with 894 additions and 1,428 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import jdk.compiler.graal.graph.NodeInputList;
import jdk.compiler.graal.nodeinfo.InputType;
import jdk.compiler.graal.nodeinfo.NodeInfo;
import jdk.compiler.graal.nodes.spi.LimitedValueProxy;
import jdk.compiler.graal.nodes.type.StampTool;
import jdk.compiler.graal.util.CollectionsUtil;

Expand Down Expand Up @@ -129,22 +130,22 @@ public boolean inferStamp() {
*/
private Stamp tryInferLoopPhiStamp(Stamp valuesStamp) {
if (isAlive() && isLoopPhi() && valuesStamp.isPointerStamp()) {
Stamp firstValueStamp = firstValue().stamp(NodeView.DEFAULT);
Stamp firstValueStamp = stripProxies(firstValue()).stamp(NodeView.DEFAULT);
if (firstValueStamp.meet(valuesStamp).equals(firstValueStamp)) {
/*
* Even the first value's stamp is not more precise than the current stamp, we won't
* be able to refine anything.
*/
return valuesStamp;
}
boolean hasDirectPhiOrProxyInput = false;
boolean hasDirectPhiInput = false;
for (ValueNode value : values()) {
if (value instanceof ValuePhiNode || value instanceof ValueProxyNode) {
hasDirectPhiOrProxyInput = true;
if (stripProxies(value) instanceof ValuePhiNode) {
hasDirectPhiInput = true;
break;
}
}
if (!hasDirectPhiOrProxyInput) {
if (!hasDirectPhiInput) {
// Nothing to recurse over.
return valuesStamp;
}
Expand All @@ -153,13 +154,12 @@ private Stamp tryInferLoopPhiStamp(Stamp valuesStamp) {
NodeFlood flood = new NodeFlood(graph());
flood.addAll(values());
for (Node node : flood) {
if (node == this) {
Node unproxifiedNode = stripProxies(node);
if (unproxifiedNode == this) {
// Don't use this value's stamp as that is what we are computing.
} else if (node instanceof ValuePhiNode phi) {
} else if (unproxifiedNode instanceof ValuePhiNode phi) {
flood.addAll(phi.values());
} else if (node instanceof ValueProxyNode proxy) {
flood.add(proxy.value());
} else if (node instanceof ValueNode value) {
} else if (unproxifiedNode instanceof ValueNode value) {
currentStamp = currentStamp.meet(value.stamp(NodeView.DEFAULT));
if (currentStamp.equals(valuesStamp)) {
// We won't become more precise.
Expand All @@ -175,6 +175,25 @@ private Stamp tryInferLoopPhiStamp(Stamp valuesStamp) {
return valuesStamp;
}

private static Node stripProxies(Node n) {
if (n instanceof ValueNode value) {
return stripProxies(value);
}
return n;
}

/**
* Proxies with the same stamp as the original node should be ignored when trying to infer a
* loop stamp.
*/
private static ValueNode stripProxies(ValueNode v) {
ValueNode result = v;
while (result instanceof LimitedValueProxy proxy && proxy.getOriginalNode().stamp(NodeView.DEFAULT).equals(result.stamp(NodeView.DEFAULT))) {
result = proxy.getOriginalNode();
}
return result;
}

@Override
public boolean verify() {
Stamp s = null;
Expand Down
1 change: 1 addition & 0 deletions substratevm/mx.substratevm/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,7 @@
"requiresConcealed": {
"jdk.internal.vm.ci": [
"jdk.vm.ci.meta",
"jdk.vm.ci.code",
"jdk.vm.ci.common",
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,42 @@
import java.util.Map;
import java.util.Optional;

import org.graalvm.nativeimage.AnnotationAccess;

import com.oracle.graal.pointsto.AbstractAnalysisEngine;
import com.oracle.graal.pointsto.ObjectScanner.EmbeddedRootScan;
import com.oracle.graal.pointsto.PointsToAnalysis;
import com.oracle.graal.pointsto.api.PointstoOptions;
import com.oracle.graal.pointsto.flow.LoadFieldTypeFlow.LoadInstanceFieldTypeFlow;
import com.oracle.graal.pointsto.flow.LoadFieldTypeFlow.LoadStaticFieldTypeFlow;
import com.oracle.graal.pointsto.flow.MethodFlowsGraph.GraphKind;
import com.oracle.graal.pointsto.flow.OffsetLoadTypeFlow.LoadIndexedTypeFlow;
import com.oracle.graal.pointsto.flow.OffsetLoadTypeFlow.UnsafeLoadTypeFlow;
import com.oracle.graal.pointsto.flow.OffsetLoadTypeFlow.UnsafePartitionLoadTypeFlow;
import com.oracle.graal.pointsto.flow.OffsetStoreTypeFlow.StoreIndexedTypeFlow;
import com.oracle.graal.pointsto.flow.OffsetStoreTypeFlow.UnsafePartitionStoreTypeFlow;
import com.oracle.graal.pointsto.flow.OffsetStoreTypeFlow.UnsafeStoreTypeFlow;
import com.oracle.graal.pointsto.flow.StoreFieldTypeFlow.StoreInstanceFieldTypeFlow;
import com.oracle.graal.pointsto.flow.StoreFieldTypeFlow.StoreStaticFieldTypeFlow;
import com.oracle.graal.pointsto.flow.builder.TypeFlowBuilder;
import com.oracle.graal.pointsto.flow.builder.TypeFlowGraphBuilder;
import com.oracle.graal.pointsto.meta.AnalysisField;
import com.oracle.graal.pointsto.meta.AnalysisMethod;
import com.oracle.graal.pointsto.meta.AnalysisType;
import com.oracle.graal.pointsto.meta.HostedProviders;
import com.oracle.graal.pointsto.meta.PointsToAnalysisMethod;
import com.oracle.graal.pointsto.nodes.UnsafePartitionLoadNode;
import com.oracle.graal.pointsto.nodes.UnsafePartitionStoreNode;
import com.oracle.graal.pointsto.phases.InlineBeforeAnalysis;
import com.oracle.graal.pointsto.results.StaticAnalysisResultsBuilder;
import com.oracle.graal.pointsto.results.StrengthenGraphs;
import com.oracle.graal.pointsto.typestate.TypeState;
import com.oracle.graal.pointsto.util.AnalysisError;
import com.oracle.svm.common.meta.MultiMethod;

import jdk.compiler.graal.core.common.spi.ForeignCallDescriptor;
import jdk.compiler.graal.core.common.spi.ForeignCallsProvider;
import jdk.compiler.graal.core.common.type.AbstractObjectStamp;
import jdk.compiler.graal.core.common.type.ObjectStamp;
import jdk.compiler.graal.core.common.type.TypeReference;
import jdk.compiler.graal.debug.DebugContext;
Expand Down Expand Up @@ -110,39 +144,6 @@
import jdk.compiler.graal.replacements.nodes.ObjectClone;
import jdk.compiler.graal.replacements.nodes.UnaryMathIntrinsicNode;
import jdk.compiler.graal.virtual.phases.ea.PartialEscapePhase;
import org.graalvm.nativeimage.AnnotationAccess;

import com.oracle.graal.pointsto.AbstractAnalysisEngine;
import com.oracle.graal.pointsto.ObjectScanner.EmbeddedRootScan;
import com.oracle.graal.pointsto.PointsToAnalysis;
import com.oracle.graal.pointsto.api.PointstoOptions;
import com.oracle.graal.pointsto.flow.LoadFieldTypeFlow.LoadInstanceFieldTypeFlow;
import com.oracle.graal.pointsto.flow.LoadFieldTypeFlow.LoadStaticFieldTypeFlow;
import com.oracle.graal.pointsto.flow.MethodFlowsGraph.GraphKind;
import com.oracle.graal.pointsto.flow.OffsetLoadTypeFlow.LoadIndexedTypeFlow;
import com.oracle.graal.pointsto.flow.OffsetLoadTypeFlow.UnsafeLoadTypeFlow;
import com.oracle.graal.pointsto.flow.OffsetLoadTypeFlow.UnsafePartitionLoadTypeFlow;
import com.oracle.graal.pointsto.flow.OffsetStoreTypeFlow.StoreIndexedTypeFlow;
import com.oracle.graal.pointsto.flow.OffsetStoreTypeFlow.UnsafePartitionStoreTypeFlow;
import com.oracle.graal.pointsto.flow.OffsetStoreTypeFlow.UnsafeStoreTypeFlow;
import com.oracle.graal.pointsto.flow.StoreFieldTypeFlow.StoreInstanceFieldTypeFlow;
import com.oracle.graal.pointsto.flow.StoreFieldTypeFlow.StoreStaticFieldTypeFlow;
import com.oracle.graal.pointsto.flow.builder.TypeFlowBuilder;
import com.oracle.graal.pointsto.flow.builder.TypeFlowGraphBuilder;
import com.oracle.graal.pointsto.meta.AnalysisField;
import com.oracle.graal.pointsto.meta.AnalysisMethod;
import com.oracle.graal.pointsto.meta.AnalysisType;
import com.oracle.graal.pointsto.meta.HostedProviders;
import com.oracle.graal.pointsto.meta.PointsToAnalysisMethod;
import com.oracle.graal.pointsto.nodes.UnsafePartitionLoadNode;
import com.oracle.graal.pointsto.nodes.UnsafePartitionStoreNode;
import com.oracle.graal.pointsto.phases.InlineBeforeAnalysis;
import com.oracle.graal.pointsto.results.StaticAnalysisResultsBuilder;
import com.oracle.graal.pointsto.results.StrengthenGraphs;
import com.oracle.graal.pointsto.typestate.TypeState;
import com.oracle.graal.pointsto.util.AnalysisError;
import com.oracle.svm.common.meta.MultiMethod;

import jdk.vm.ci.code.BytecodePosition;
import jdk.vm.ci.meta.Constant;
import jdk.vm.ci.meta.JavaConstant;
Expand Down Expand Up @@ -1041,8 +1042,7 @@ protected void node(FixedNode n) {

state.add(node, newArrayBuilder);

} else if (n instanceof LoadFieldNode) { // value = object.field
LoadFieldNode node = (LoadFieldNode) n;
} else if (n instanceof LoadFieldNode node) { // value = object.field
AnalysisField field = (AnalysisField) node.field();
assert field.isAccessed() : field;
if (node.getStackKind() == JavaKind.Object) {
Expand All @@ -1069,12 +1069,17 @@ protected void node(FixedNode n) {
}
state.add(node, loadFieldBuilder);
}
if (node.object() != null) {
processImplicitNonNull(node.object(), state);
}

} else if (n instanceof StoreFieldNode) { // object.field = value
processStoreField((StoreFieldNode) n, state);
} else if (n instanceof StoreFieldNode node) { // object.field = value
processStoreField(node, state);
if (node.object() != null) {
processImplicitNonNull(node.object(), state);
}

} else if (n instanceof LoadIndexedNode) {
LoadIndexedNode node = (LoadIndexedNode) n;
} else if (n instanceof LoadIndexedNode node) {
TypeFlowBuilder<?> arrayBuilder = state.lookup(node.array());
if (node.getStackKind() == JavaKind.Object) {
AnalysisType type = (AnalysisType) StampTool.typeOrNull(node.array(), bb.getMetaAccess());
Expand All @@ -1092,9 +1097,11 @@ protected void node(FixedNode n) {
loadIndexedBuilder.addObserverDependency(arrayBuilder);
state.add(node, loadIndexedBuilder);
}
processImplicitNonNull(node.array(), state);

} else if (n instanceof StoreIndexedNode) {
processStoreIndexed((StoreIndexedNode) n, state);
} else if (n instanceof StoreIndexedNode node) {
processStoreIndexed(node, state);
processImplicitNonNull(node.array(), state);

} else if (n instanceof UnsafePartitionLoadNode) {
UnsafePartitionLoadNode node = (UnsafePartitionLoadNode) n;
Expand Down Expand Up @@ -1309,13 +1316,17 @@ protected void node(FixedNode n) {

} else if (n instanceof InvokeNode || n instanceof InvokeWithExceptionNode) {
Invoke invoke = (Invoke) n;
if (invoke.callTarget() instanceof MethodCallTargetNode) {
if (invoke.callTarget() instanceof MethodCallTargetNode target) {
guarantee(bb.strengthenGraalGraphs() || invoke.stateAfter().outerFrameState() == null,
"Outer FrameState of %s must be null, but was %s. A non-null outer FrameState indicates that a method inlining has happened, but inlining should only happen after analysis.",
invoke.stateAfter(), invoke.stateAfter().outerFrameState());
MethodCallTargetNode target = (MethodCallTargetNode) invoke.callTarget();

processMethodInvocation(state, invoke, target.invokeKind(), (PointsToAnalysisMethod) target.targetMethod(), target.arguments());
var arguments = target.arguments();
processMethodInvocation(state, invoke, target.invokeKind(), (PointsToAnalysisMethod) target.targetMethod(), arguments);

if (target.invokeKind().hasReceiver()) {
processImplicitNonNull(arguments.get(0), invoke.asNode(), state);
}
}

} else if (n instanceof ObjectClone) {
Expand All @@ -1342,7 +1353,7 @@ protected void node(FixedNode n) {
monitorEntryBuilder.addUseDependency(objectBuilder);
/* Monitor enters must not be removed. */
typeFlowGraphBuilder.registerSinkBuilder(monitorEntryBuilder);
} else if (n instanceof MacroInvokable) {
} else if (n instanceof MacroInvokable node) {
/*
* Macro nodes can either be constant folded during compilation, or lowered back to
* invocations if constant folding is not possible. So the static analysis needs to
Expand All @@ -1351,8 +1362,10 @@ protected void node(FixedNode n) {
* Note that some macro nodes, like for object cloning, are handled separately
* above.
*/
MacroInvokable node = (MacroInvokable) n;
processMacroInvokable(state, node, true);
if (node.getInvokeKind().hasReceiver()) {
processImplicitNonNull(node.getArgument(0), node.asNode(), state);
}
}
}

Expand Down Expand Up @@ -1763,4 +1776,27 @@ private void processStoreIndexed(ValueNode node, ValueNode array, ValueNode valu
/** Hook for unsafe offset value checks. */
protected void checkUnsafeOffset(@SuppressWarnings("unused") ValueNode base, @SuppressWarnings("unused") ValueNode offset) {
}

private void processImplicitNonNull(ValueNode node, TypeFlowsOfNodes state) {
processImplicitNonNull(node, node, state);
}

protected void processImplicitNonNull(ValueNode node, ValueNode source, TypeFlowsOfNodes state) {
assert node.stamp(NodeView.DEFAULT) instanceof AbstractObjectStamp : node;
if (!StampTool.isPointerNonNull(node)) {
TypeFlowBuilder<?> inputBuilder = state.lookup(node);
TypeFlowBuilder<?> nullCheckBuilder = TypeFlowBuilder.create(bb, source, NullCheckTypeFlow.class, () -> {
var inputFlow = inputBuilder.get();
if (inputFlow instanceof NullCheckTypeFlow nullCheck && nullCheck.isBlockingNull()) {
// unnecessary to create redundant null type check
return nullCheck;
}
NullCheckTypeFlow nullCheckFlow = new NullCheckTypeFlow(AbstractAnalysisEngine.sourcePosition(source), inputFlow.getDeclaredType(), true);
flowsGraph.addMiscEntryFlow(nullCheckFlow);
return nullCheckFlow;
});
nullCheckBuilder.addUseDependency(inputBuilder);
state.update(node, nullCheckBuilder);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,21 @@ public void setGraphBuilderPlugins(GraphBuilderConfiguration.Plugins graphBuilde
}

@Override
public Providers copyWith(ConstantReflectionProvider substitution) {
public HostedProviders copyWith(ConstantReflectionProvider substitution) {
assert this.getClass() == HostedProviders.class : "must override in " + getClass();
return new HostedProviders(getMetaAccess(), getCodeCache(), substitution, getConstantFieldProvider(), getForeignCalls(), getLowerer(), getReplacements(), getStampProvider(),
getSnippetReflection(), getWordTypes(), getPlatformConfigurationProvider(), getMetaAccessExtensionProvider(), getLoopsDataProvider());
}

@Override
public Providers copyWith(ConstantFieldProvider substitution) {
public HostedProviders copyWith(ConstantFieldProvider substitution) {
assert this.getClass() == HostedProviders.class : "must override in " + getClass();
return new HostedProviders(getMetaAccess(), getCodeCache(), getConstantReflection(), substitution, getForeignCalls(), getLowerer(), getReplacements(), getStampProvider(),
getSnippetReflection(), getWordTypes(), getPlatformConfigurationProvider(), getMetaAccessExtensionProvider(), getLoopsDataProvider());
}

@Override
public Providers copyWith(Replacements substitution) {
public HostedProviders copyWith(Replacements substitution) {
assert this.getClass() == HostedProviders.class : "must override in " + getClass();
return new HostedProviders(getMetaAccess(), getCodeCache(), getConstantReflection(), getConstantFieldProvider(), getForeignCalls(), getLowerer(), substitution, getStampProvider(),
getSnippetReflection(), getWordTypes(), getPlatformConfigurationProvider(), getMetaAccessExtensionProvider(), getLoopsDataProvider());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
import com.oracle.svm.core.snippets.KnownIntrinsics;
import com.oracle.svm.core.snippets.SubstrateForeignCallTarget;
import com.oracle.svm.core.stack.StackOverflowCheck;
import com.oracle.svm.core.thread.Continuation;
import com.oracle.svm.core.thread.ContinuationSupport;
import com.oracle.svm.core.thread.VMOperation;
import com.oracle.svm.core.thread.VMThreads;
import com.oracle.svm.core.threadlocal.FastThreadLocal;
Expand Down Expand Up @@ -375,7 +375,7 @@ private static Object allocateLargeArrayLikeObjectInNewTlab(DynamicHub hub, int
@Uninterruptible(reason = "Holds uninitialized memory")
private static Object formatArrayLikeObject(Pointer memory, DynamicHub hub, int length, boolean unaligned, FillContent fillContent, byte[] podReferenceMap) {
Class<?> clazz = DynamicHub.toClass(hub);
if (Continuation.isSupported() && clazz == StoredContinuation.class) {
if (ContinuationSupport.isSupported() && clazz == StoredContinuation.class) {
return FormatStoredContinuationNode.formatStoredContinuation(memory, clazz, length, false, unaligned, true);
} else if (Pod.RuntimeSupport.isPresent() && podReferenceMap != null) {
return FormatPodNode.formatPod(memory, clazz, length, podReferenceMap, false, unaligned, fillContent, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
import com.oracle.svm.core.heap.Pod;
import com.oracle.svm.core.hub.DynamicHub;
import com.oracle.svm.core.hub.LayoutEncoding;
import com.oracle.svm.core.thread.Continuation;
import com.oracle.svm.core.thread.ContinuationSupport;

import jdk.vm.ci.meta.JavaKind;
Expand Down Expand Up @@ -130,7 +129,7 @@ public Templates(OptionValues options, Providers providers, SubstrateAllocationS
this.baseTemplates = baseTemplates;
formatObject = snippet(providers, GenScavengeAllocationSnippets.class, "formatObjectSnippet");
formatArray = snippet(providers, GenScavengeAllocationSnippets.class, "formatArraySnippet");
formatStoredContinuation = Continuation.isSupported() ? snippet(providers, GenScavengeAllocationSnippets.class, "formatStoredContinuation") : null;
formatStoredContinuation = ContinuationSupport.isSupported() ? snippet(providers, GenScavengeAllocationSnippets.class, "formatStoredContinuation") : null;
formatPod = Pod.RuntimeSupport.isPresent() ? snippet(providers,
GenScavengeAllocationSnippets.class,
"formatPodSnippet",
Expand All @@ -141,7 +140,7 @@ public Templates(OptionValues options, Providers providers, SubstrateAllocationS
public void registerLowering(Map<Class<? extends Node>, NodeLoweringProvider<?>> lowerings) {
lowerings.put(FormatObjectNode.class, new FormatObjectLowering());
lowerings.put(FormatArrayNode.class, new FormatArrayLowering());
if (Continuation.isSupported()) {
if (ContinuationSupport.isSupported()) {
lowerings.put(FormatStoredContinuationNode.class, new FormatStoredContinuationLowering());
}
if (Pod.RuntimeSupport.isPresent()) {
Expand Down
Loading

0 comments on commit ea08331

Please sign in to comment.