Skip to content

Commit

Permalink
[GR-25190] Use rootGraph's speculation log for type guard inlining.
Browse files Browse the repository at this point in the history
PullRequest: graal/7080
  • Loading branch information
mur47x111 committed Sep 11, 2020
2 parents 17acccd + 98c1eb3 commit 63cb636
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ public static EconomicSet<Node> inlineForCanonicalization(Invoke invoke, Structu
@SuppressWarnings("try")
public static EconomicSet<Node> inlineForCanonicalization(Invoke invoke, StructuredGraph inlineGraph, boolean receiverNullCheck, ResolvedJavaMethod inlineeMethod,
Consumer<UnmodifiableEconomicMap<Node, Node>> duplicatesConsumer, String reason, String phase) {
assert inlineGraph.isSubstitution() || invoke.asNode().graph().getSpeculationLog() == inlineGraph.getSpeculationLog();
EconomicSetNodeEventListener listener = new EconomicSetNodeEventListener();
/*
* This code relies on the fact that Graph.addDuplicates doesn't trigger the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@
import jdk.vm.ci.meta.JavaTypeProfile.ProfiledType;
import jdk.vm.ci.meta.ResolvedJavaMethod;
import jdk.vm.ci.meta.ResolvedJavaType;
import jdk.vm.ci.meta.SpeculationLog;
import jdk.vm.ci.meta.SpeculationLog.SpeculationReason;
import jdk.vm.ci.meta.SpeculationLog.Speculation;

/**
* Polymorphic inlining of m methods with n type checks (n &ge; m) in case that the profiling
Expand All @@ -84,10 +83,11 @@ public class MultiTypeGuardInlineInfo extends AbstractInlineInfo {
private final ArrayList<ProfiledType> ptypes;
private final double notRecordedTypeProbability;
private final Inlineable[] inlineableElements;
private final SpeculationReason speculation;
private final boolean speculationFailed;
private final Speculation speculation;

public MultiTypeGuardInlineInfo(Invoke invoke, ArrayList<ResolvedJavaMethod> concretes, ArrayList<ProfiledType> ptypes,
ArrayList<Integer> typesToConcretes, double notRecordedTypeProbability, SpeculationReason speculation) {
ArrayList<Integer> typesToConcretes, double notRecordedTypeProbability, boolean speculationFailed, Speculation speculation) {
super(invoke);
assert concretes.size() > 0 : "must have at least one method";
assert ptypes.size() == typesToConcretes.size() : "array lengths must match";
Expand All @@ -100,6 +100,7 @@ public MultiTypeGuardInlineInfo(Invoke invoke, ArrayList<ResolvedJavaMethod> con
this.methodProbabilities = computeMethodProbabilities();
this.maximumMethodProbability = maximumMethodProbability();
assert maximumMethodProbability > 0;
this.speculationFailed = speculationFailed;
this.speculation = speculation;
assert assertUniqueTypes(ptypes);
}
Expand Down Expand Up @@ -187,8 +188,7 @@ private boolean hasSingleMethod() {
}

private boolean shouldFallbackToInvoke() {
SpeculationLog speculationLog = invoke.asNode().graph().getSpeculationLog();
return notRecordedTypeProbability > 0 || (speculationLog != null && speculation != null && !speculationLog.maySpeculate(speculation));
return notRecordedTypeProbability > 0 || speculationFailed;
}

private EconomicSet<Node> inlineMultipleMethods(StructuredGraph graph, CoreProviders providers, String reason) {
Expand Down Expand Up @@ -232,9 +232,7 @@ private EconomicSet<Node> inlineMultipleMethods(StructuredGraph graph, CoreProvi
if (shouldFallbackToInvoke()) {
unknownTypeSux = createInvocationBlock(graph, invoke, returnMerge, returnValuePhi, exceptionMerge, exceptionObjectPhi, false);
} else {
SpeculationLog speculationLog = graph.getSpeculationLog();
unknownTypeSux = graph.add(new DeoptimizeNode(DeoptimizationAction.InvalidateReprofile, DeoptimizationReason.TypeCheckedInliningViolated,
speculationLog != null && speculation != null ? speculationLog.speculate(speculation) : SpeculationLog.NO_SPECULATION));
unknownTypeSux = graph.add(new DeoptimizeNode(DeoptimizationAction.InvalidateReprofile, DeoptimizationReason.TypeCheckedInliningViolated, speculation));
}
successors[successors.length - 1] = BeginNode.begin(unknownTypeSux);

Expand Down Expand Up @@ -444,7 +442,7 @@ public void tryToDevirtualizeInvoke(Providers providers) {

private void tryToDevirtualizeMultipleMethods(StructuredGraph graph, StampProvider stampProvider, ConstantReflectionProvider constantReflection) {
MethodCallTargetNode methodCallTarget = (MethodCallTargetNode) invoke.callTarget();
if (methodCallTarget.invokeKind() == InvokeKind.Interface) {
if (methodCallTarget.invokeKind() == InvokeKind.Interface && !speculationFailed) {
ResolvedJavaMethod targetMethod = methodCallTarget.targetMethod();
ResolvedJavaType leastCommonType = getLeastCommonType();
ResolvedJavaType contextType = invoke.getContextType();
Expand Down Expand Up @@ -474,9 +472,7 @@ private void devirtualizeWithTypeSwitch(StructuredGraph graph, InvokeKind kind,
}

private AbstractBeginNode createUnknownTypeSuccessor(StructuredGraph graph) {
SpeculationLog speculationLog = graph.getSpeculationLog();
return BeginNode.begin(graph.add(new DeoptimizeNode(DeoptimizationAction.InvalidateReprofile, DeoptimizationReason.TypeCheckedInliningViolated,
speculationLog == null || speculation == null ? SpeculationLog.NO_SPECULATION : speculationLog.speculate(speculation))));
return BeginNode.begin(graph.add(new DeoptimizeNode(DeoptimizationAction.InvalidateReprofile, DeoptimizationReason.TypeCheckedInliningViolated, speculation)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@
import jdk.vm.ci.meta.DeoptimizationReason;
import jdk.vm.ci.meta.ResolvedJavaMethod;
import jdk.vm.ci.meta.ResolvedJavaType;
import jdk.vm.ci.meta.SpeculationLog;
import jdk.vm.ci.meta.SpeculationLog.SpeculationReason;
import jdk.vm.ci.meta.SpeculationLog.Speculation;

/**
* Represents an inlining opportunity for which profiling information suggests a monomorphic
Expand All @@ -60,9 +59,9 @@ public class TypeGuardInlineInfo extends AbstractInlineInfo {
private final ResolvedJavaMethod concrete;
private final ResolvedJavaType type;
private Inlineable inlineableElement;
private final SpeculationReason speculation;
private final Speculation speculation;

public TypeGuardInlineInfo(Invoke invoke, ResolvedJavaMethod concrete, ResolvedJavaType type, SpeculationReason speculation) {
public TypeGuardInlineInfo(Invoke invoke, ResolvedJavaMethod concrete, ResolvedJavaType type, Speculation speculation) {
super(invoke);
this.concrete = concrete;
this.type = type;
Expand Down Expand Up @@ -125,9 +124,7 @@ private void createGuard(StructuredGraph graph, CoreProviders providers) {
ConstantNode typeHub = ConstantNode.forConstant(receiverHub.stamp(NodeView.DEFAULT), providers.getConstantReflection().asObjectHub(type), providers.getMetaAccess(), graph);

LogicNode typeCheck = CompareNode.createCompareNode(graph, CanonicalCondition.EQ, receiverHub, typeHub, providers.getConstantReflection(), NodeView.DEFAULT);
SpeculationLog speculationLog = graph.getSpeculationLog();
FixedGuardNode guard = graph.add(new FixedGuardNode(typeCheck, DeoptimizationReason.TypeCheckedInliningViolated, DeoptimizationAction.InvalidateReprofile,
speculationLog != null && speculation != null ? speculationLog.speculate(speculation) : SpeculationLog.NO_SPECULATION, false));
FixedGuardNode guard = graph.add(new FixedGuardNode(typeCheck, DeoptimizationReason.TypeCheckedInliningViolated, DeoptimizationAction.InvalidateReprofile, speculation, false));
assert invoke.predecessor() != null;

ValueNode anchoredReceiver = InliningUtil.createAnchoredReceiver(graph, guard, type, nonNullReceiver, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ private static ArrayList<Node> trackParameterUsages(ParameterNode param, ArrayLi
@SuppressWarnings("try")
private static StructuredGraph parseBytecodes(ResolvedJavaMethod method, HighTierContext context, CanonicalizerPhase canonicalizer, StructuredGraph caller, boolean trackNodeSourcePosition) {
DebugContext debug = caller.getDebug();
StructuredGraph newGraph = new StructuredGraph.Builder(caller.getOptions(), debug, caller.allowAssumptions()).method(method).trackNodeSourcePosition(
trackNodeSourcePosition).useProfilingInfo(caller.useProfilingInfo()).build();
StructuredGraph newGraph = new StructuredGraph.Builder(caller.getOptions(), debug, caller.allowAssumptions()).method(method).trackNodeSourcePosition(trackNodeSourcePosition).useProfilingInfo(
caller.useProfilingInfo()).speculationLog(caller.getSpeculationLog()).build();
try (DebugContext.Scope s = debug.scope("InlineGraph", newGraph)) {
if (!caller.isUnsafeAccessTrackingEnabled()) {
newGraph.disableUnsafeAccessTracking();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,20 @@ private InlineInfo getTypeCheckedInlineInfo(Invoke invoke, ResolvedJavaMethod ta
final OptimisticOptimizations optimisticOpts = context.getOptimisticOptimizations();
OptionValues options = invoke.asNode().getOptions();

boolean speculationFailed = false;
SpeculationLog speculationLog = graph.getSpeculationLog();
SpeculationLog.SpeculationReason speculation = notRecordedTypeProbability == 0 ? InliningUtil.createSpeculation(invoke, typeProfile) : null;
SpeculationLog.Speculation speculation = SpeculationLog.NO_SPECULATION;

if (ptypes.length == 1 && notRecordedTypeProbability == 0 && (speculationLog == null || speculationLog.maySpeculate(speculation))) {
if (speculationLog != null && notRecordedTypeProbability == 0) {
SpeculationLog.SpeculationReason speculationReason = InliningUtil.createSpeculation(invoke, typeProfile);
if (speculationLog.maySpeculate(speculationReason)) {
speculation = speculationLog.speculate(speculationReason);
} else {
speculationFailed = true;
}
}

if (ptypes.length == 1 && notRecordedTypeProbability == 0 && !speculationFailed) {
if (!optimisticOpts.inlineMonomorphicCalls(options)) {
InliningUtil.traceNotInlinedMethod(invoke, inliningDepth(), targetMethod, "inlining monomorphic calls is disabled");
inliningLog.addDecision(invoke, false, "InliningPhase", null, null, "inlining monomorphic calls is disabled");
Expand Down Expand Up @@ -394,7 +404,7 @@ private InlineInfo getTypeCheckedInlineInfo(Invoke invoke, ResolvedJavaMethod ta
return null;
}
}
return new MultiTypeGuardInlineInfo(invoke, concreteMethods, usedTypes, typesToConcretes, notRecordedTypeProbability, speculation);
return new MultiTypeGuardInlineInfo(invoke, concreteMethods, usedTypes, typesToConcretes, notRecordedTypeProbability, speculationFailed, speculation);
}
}

Expand Down

0 comments on commit 63cb636

Please sign in to comment.