Skip to content

Commit

Permalink
[GR-49481] Backport to 20.3: Remove explicit null check exceptions fr…
Browse files Browse the repository at this point in the history
…om genCheckCast and genInstanceof.

PullRequest: graal/16433
  • Loading branch information
rmosaner committed Dec 21, 2023
2 parents a10ec61 + b0a3014 commit 0b9a3da
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,16 @@ default <T extends ValueNode> 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));
}
Expand Down

0 comments on commit 0b9a3da

Please sign in to comment.