From b0a3014ffaed8746e683a2f3d28851ac7d888cc3 Mon Sep 17 00:00:00 2001 From: Raphael Mosaner Date: Mon, 18 Dec 2023 18:46:38 +0100 Subject: [PATCH] [GR-49481] Remove explicit null check exceptions from genCheckCast and genInstanceof. (cherry picked from commit 020b17fe9492d371d89c97c58e4b861d3659cc97) --- .../src/org/graalvm/compiler/java/BytecodeParser.java | 4 ++-- .../nodes/graphbuilderconf/GraphBuilderContext.java | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/compiler/src/org.graalvm.compiler.java/src/org/graalvm/compiler/java/BytecodeParser.java b/compiler/src/org.graalvm.compiler.java/src/org/graalvm/compiler/java/BytecodeParser.java index 1347bcfbe782..c1c9add68368 100644 --- a/compiler/src/org.graalvm.compiler.java/src/org/graalvm/compiler/java/BytecodeParser.java +++ b/compiler/src/org.graalvm.compiler.java/src/org/graalvm/compiler/java/BytecodeParser.java @@ -4449,7 +4449,7 @@ protected void genCheckCast(ResolvedJavaType resolvedType, ValueNode objectIn) { if (profile.getNullSeen().isFalse()) { SpeculationLog.Speculation speculation = mayUseTypeProfile(); if (speculation != null) { - object = nullCheckedValue(object); + object = addNonNullCast(object, InvalidateReprofile); ResolvedJavaType singleType = profile.asSingleType(); if (singleType != null && checkedType.getType().isAssignableFrom(singleType)) { LogicNode typeCheck = append(createInstanceOf(TypeReference.createExactTrusted(singleType), object, profile)); @@ -4512,7 +4512,7 @@ protected void genInstanceOf(ResolvedJavaType resolvedType, ValueNode objectIn) LogicNode instanceOfNode = null; if (profile != null) { if (profile.getNullSeen().isFalse()) { - object = nullCheckedValue(object); + object = addNonNullCast(object, InvalidateReprofile); boolean createGuard = true; ResolvedJavaType singleType = profile.asSingleType(); if (singleType != null) { diff --git a/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/graphbuilderconf/GraphBuilderContext.java b/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/graphbuilderconf/GraphBuilderContext.java index e1fa81e8a174..49d508d386ae 100644 --- a/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/graphbuilderconf/GraphBuilderContext.java +++ b/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/graphbuilderconf/GraphBuilderContext.java @@ -113,12 +113,16 @@ default T add(T value) { } default ValueNode addNonNullCast(ValueNode value) { + return addNonNullCast(value, DeoptimizationAction.None); + } + + default ValueNode addNonNullCast(ValueNode value, DeoptimizationAction action) { AbstractPointerStamp valueStamp = (AbstractPointerStamp) value.stamp(NodeView.DEFAULT); if (valueStamp.nonNull()) { return value; } else { LogicNode isNull = add(IsNullNode.create(value)); - FixedGuardNode fixedGuard = add(new FixedGuardNode(isNull, DeoptimizationReason.NullCheckException, DeoptimizationAction.None, true)); + FixedGuardNode fixedGuard = add(new FixedGuardNode(isNull, DeoptimizationReason.NullCheckException, action, true)); Stamp newStamp = valueStamp.improveWith(StampFactory.objectNonNull()); return add(PiNode.create(value, newStamp, fixedGuard)); }