# HG changeset patch # User Gilles Duboscq # Date 1381761651 -7200 # Node ID 28d80a9260cdc955a9d3361fd73c4fc2377ff7b6 # Parent 1d2d7924033ac2e5d5e806f26bcf9bf066335738 During CheckCast lowering, if null was never seen and a guard is created for the null case, the instanceof should be done on a non-null value. diff -r 1d2d7924033a -r 28d80a9260cd graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/CheckCastNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/CheckCastNode.java Mon Oct 14 15:52:24 2013 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/CheckCastNode.java Mon Oct 14 16:40:51 2013 +0200 @@ -91,13 +91,12 @@ * 2: B b = guardingPi(a instanceof B, a, stamp(B, non-null)) * * - * Note: we use {@link Graph#add} as opposed to {@link Graph#unique} for the new + * Note: we use {@link Graph#addWithoutUnique} as opposed to {@link Graph#unique} for the new * {@link InstanceOfNode} to maintain the invariant checked by * {@code LoweringPhase.checkUsagesAreScheduled()}. */ @Override public void lower(LoweringTool tool) { - InstanceOfNode typeTest = graph().addWithoutUnique(new InstanceOfNode(type, object, profile)); Stamp stamp = StampFactory.declared(type); if (stamp() instanceof ObjectStamp && object().stamp() instanceof ObjectStamp) { stamp = ((ObjectStamp) object().stamp()).castTo((ObjectStamp) stamp); @@ -108,17 +107,20 @@ condition = LogicConstantNode.contradiction(graph()); stamp = StampFactory.declared(type); } else if (ObjectStamp.isObjectNonNull(object)) { - condition = typeTest; + condition = graph().addWithoutUnique(new InstanceOfNode(type, object, profile)); } else { if (profile != null && profile.getNullSeen() == TriState.FALSE) { - FixedGuardNode nullGuard = graph().add(new FixedGuardNode(graph().unique(new IsNullNode(object)), UnreachedCode, DeoptimizationAction.InvalidateReprofile, true)); - graph().addBeforeFixed(this, nullGuard); + FixedGuardNode nullCheck = graph().add(new FixedGuardNode(graph().unique(new IsNullNode(object)), UnreachedCode, InvalidateReprofile, true)); + PiNode nullGuarded = graph().unique(new PiNode(object, object().stamp().join(StampFactory.objectNonNull()), nullCheck)); + InstanceOfNode typeTest = graph().addWithoutUnique(new InstanceOfNode(type, nullGuarded, profile)); + graph().addBeforeFixed(this, nullCheck); condition = typeTest; stamp = stamp.join(StampFactory.objectNonNull()); - nullGuard.lower(tool); + nullCheck.lower(tool); } else { // TODO (ds) replace with probability of null-seen when available double shortCircuitProbability = NOT_FREQUENT_PROBABILITY; + InstanceOfNode typeTest = graph().addWithoutUnique(new InstanceOfNode(type, object, profile)); condition = LogicNode.or(graph().unique(new IsNullNode(object)), typeTest, shortCircuitProbability); } }