Skip to content

Commit 49a0dd6

Browse files
committed
verify we are finding a read node to an array at the bounds check if
1 parent 96fc07b commit 49a0dd6

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/BoxingSnippets.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
package jdk.graal.compiler.replacements;
2626

2727
import java.util.EnumMap;
28+
import java.util.List;
2829

2930
import org.graalvm.collections.UnmodifiableEconomicMap;
3031
import org.graalvm.word.LocationIdentity;
@@ -48,6 +49,7 @@
4849
import jdk.graal.compiler.nodes.extended.BoxNode;
4950
import jdk.graal.compiler.nodes.extended.BranchProbabilityNode;
5051
import jdk.graal.compiler.nodes.extended.UnboxNode;
52+
import jdk.graal.compiler.nodes.memory.MemoryAccess;
5153
import jdk.graal.compiler.nodes.spi.CoreProviders;
5254
import jdk.graal.compiler.nodes.spi.LoweringTool;
5355
import jdk.graal.compiler.options.OptionValues;
@@ -308,6 +310,9 @@ private static void assignPrimitiveCacheProfiles(JavaKind kind, UnmodifiableEcon
308310
}
309311
GraalError.guarantee(controlFlow.count() == 1, "Must only have a single control flow element - the branch into the cache but found more %s", controlFlow);
310312

313+
IfNode cacheIf = (IfNode) controlFlow.first();
314+
IfNode inlinedNode = (IfNode) duplicates.get(cacheIf);
315+
311316
ProfileData.BranchProbabilityData b = null;
312317
switch (kind) {
313318
case Byte:
@@ -322,13 +327,19 @@ private static void assignPrimitiveCacheProfiles(JavaKind kind, UnmodifiableEcon
322327
case Short:
323328
case Int:
324329
case Long:
330+
AbstractBeginNode trueSucc = cacheIf.trueSuccessor();
331+
GraalError.guarantee(trueSucc.next() instanceof IfNode, "Must have the bounds check next but found %s", trueSucc.next());
332+
IfNode boundsIf = (IfNode) trueSucc.next();
333+
GraalError.guarantee(isBoundsCheck(boundsIf), "Must have the bounds check next but found %s", boundsIf);
334+
List<Node> anchored = boundsIf.trueSuccessor().anchored().snapshot();
335+
GraalError.guarantee(anchored.stream().filter(x -> x instanceof MemoryAccess m && NamedLocationIdentity.isArrayLocation(m.getLocationIdentity())).count() == 1,
336+
"Remaining control flow should read from the cache but is %s", boundsIf.trueSuccessor());
337+
325338
b = ProfileData.BranchProbabilityData.injected(BranchProbabilityNode.FREQUENT_PROBABILITY);
326339
break;
327340
default:
328341
throw GraalError.shouldNotReachHere("Unknown control flow in boxing code, did a JDK change trigger this error? Consider adding new logic to set the profile of " + controlFlow);
329342
}
330-
IfNode cacheIf = (IfNode) controlFlow.first();
331-
IfNode inlinedNode = (IfNode) duplicates.get(cacheIf);
332343
inlinedNode.setTrueSuccessorProbability(b);
333344
inlinedNode.graph().getDebug().dump(DebugContext.VERY_DETAILED_LEVEL, inlinedNode.graph(), "After updating profile of %s", inlinedNode);
334345
}

0 commit comments

Comments
 (0)