Skip to content

Commit 1ff744c

Browse files
committed
[JDK-8337983] Always insert null check before is array check.
PullRequest: graal/18560
2 parents 5a6081a + c3536d7 commit 1ff744c

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/hotspot/test/GraalOSRTest.java

+24
Original file line numberDiff line numberDiff line change
@@ -290,4 +290,28 @@ static ReturnValue testArrayBottom(byte[] aB, int[] aI, int i) {
290290
public void testOSR07() {
291291
testOSR(getInitialOptions(), "testArrayBottom", null, new byte[100], new int[100], 10);
292292
}
293+
294+
static ReturnValue testNonNullArrayBottom(int i) {
295+
Object a;
296+
long base;
297+
if (i % 2 == 0) {
298+
a = new byte[100];
299+
base = Unsafe.ARRAY_BYTE_BASE_OFFSET;
300+
} else {
301+
a = new int[100];
302+
base = Unsafe.ARRAY_INT_BASE_OFFSET;
303+
}
304+
int res = 0;
305+
for (int j = 0; j < 10000; j++) {
306+
res += UNSAFE.getByte(a, base + j);
307+
}
308+
GraalDirectives.sideEffect(res);
309+
310+
return ReturnValue.SUCCESS;
311+
}
312+
313+
@Test
314+
public void testOSR08() {
315+
testOSR(getInitialOptions(), "testNonNullArrayBottom", null, 10);
316+
}
293317
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/phases/OnStackReplacementPhase.java

+11-16
Original file line numberDiff line numberDiff line change
@@ -311,22 +311,17 @@ private static ValueNode narrowOsrLocal(StructuredGraph graph, Stamp narrowedSta
311311
* test against a type, it is not an instance of operation but a null check and an
312312
* isArray check
313313
*/
314-
if (checkedStamp.isObjectStamp() && ((ObjectStamp) checkedStamp).nonNull()) {
315-
// without a null check
316-
check = graph.addOrUniqueWithInputs(ObjectIsArrayNode.create(effectiveOsrLocal));
317-
} else {
318-
// add a preceding null check with the same speculation reason
319-
check = graph.addOrUniqueWithInputs(LogicNegationNode.create(IsNullNode.create(effectiveOsrLocal)));
320-
SpeculationLog.Speculation constant = graph.getSpeculationLog().speculate(reason);
321-
FixedGuardNode guard = graph.add(new FixedGuardNode(check, DeoptimizationReason.OptimizedTypeCheckViolated, DeoptimizationAction.InvalidateRecompile, constant, false));
322-
graph.addAfterFixed(osrStart, guard);
323-
PiNode nonNullPi = graph.addOrUnique(new PiNode(effectiveOsrLocal, ((ObjectStamp) checkedStamp).asNonNull(), guard));
324-
325-
insertionPoint = guard;
326-
327-
// with a null check
328-
check = graph.addOrUnique(ObjectIsArrayNode.create(nonNullPi));
329-
}
314+
// add a preceding null check with the same speculation reason
315+
check = graph.addOrUniqueWithInputs(LogicNegationNode.create(IsNullNode.create(effectiveOsrLocal)));
316+
SpeculationLog.Speculation constant = graph.getSpeculationLog().speculate(reason);
317+
FixedGuardNode guard = graph.add(new FixedGuardNode(check, DeoptimizationReason.OptimizedTypeCheckViolated, DeoptimizationAction.InvalidateRecompile, constant, false));
318+
graph.addAfterFixed(osrStart, guard);
319+
PiNode nonNullPi = graph.addOrUnique(new PiNode(effectiveOsrLocal, ((ObjectStamp) checkedStamp).asNonNull(), guard));
320+
321+
insertionPoint = guard;
322+
323+
// with a null check
324+
check = graph.addOrUnique(ObjectIsArrayNode.create(nonNullPi));
330325
checkedStamp = new ObjectStamp(null, false, true, false, true);
331326
} else {
332327
check = graph.addOrUniqueWithInputs(InstanceOfNode.createHelper((ObjectStamp) checkedStamp, effectiveOsrLocal, null, null));

0 commit comments

Comments
 (0)