예제 #1
0
  /**
   * In case the scrutinee:
   *
   * <ul>
   *   <li>is known to be null, an unconditional deopt is added.
   *   <li>is known to be non-null, the NullCheckNode is removed.
   *   <li>otherwise, the NullCheckNode is lowered to a FixedGuardNode which then allows using it as
   *       anchor for state-tracking.
   * </ul>
   *
   * <p>Precondition: the input (ie, object) hasn't been deverbosified yet.
   */
  private void visitNullCheckNode(NullCheckNode ncn) {
    ValueNode object = ncn.getObject();
    if (state.isNull(object)) {
      postponedDeopts.addDeoptBefore(ncn, NullCheckException);
      state.impossiblePath();
      return;
    }
    if (state.isNonNull(object)) {
      /*
       * Redundant NullCheckNode. Unlike GuardingPiNode or FixedGuardNode, NullCheckNode-s
       * aren't used as GuardingNode-s, thus in this case can be removed without further ado.
       */
      assert FlowUtil.lacksUsages(ncn);
      graph.removeFixed(ncn);
      return;
    }
    /*
     * Lower the NullCheckNode to a FixedGuardNode which then allows using it as anchor for
     * state-tracking. TODO the assumption here is that the code emitted for the resulting
     * FixedGuardNode is as efficient as for NullCheckNode.
     */
    IsNullNode isNN = graph.unique(IsNullNode.create(object));
    reasoner.added.add(isNN);
    FixedGuardNode nullCheck =
        graph.add(FixedGuardNode.create(isNN, UnreachedCode, InvalidateReprofile, true));
    graph.replaceFixedWithFixed(ncn, nullCheck);

    state.trackNN(object, nullCheck);
  }
예제 #2
0
 /**
  * Similar to {@link #deverbosifyInputsInPlace(com.oracle.graal.nodes.ValueNode)}, except that not
  * the parent but a fresh clone is updated upon any of its children changing.
  *
  * @return the original parent if no updated took place, a copy-on-write version of it otherwise.
  */
 private MethodCallTargetNode deverbosifyInputsCopyOnWrite(MethodCallTargetNode parent) {
   final CallTargetNode.InvokeKind ik = parent.invokeKind();
   final boolean shouldTryDevirt =
       (ik == CallTargetNode.InvokeKind.Interface || ik == CallTargetNode.InvokeKind.Virtual);
   boolean shouldDowncastReceiver = shouldTryDevirt;
   MethodCallTargetNode changed = null;
   for (ValueNode i : FlowUtil.distinctValueAndConditionInputs(parent)) {
     ValueNode j = (ValueNode) reasoner.deverbosify(i);
     if (shouldDowncastReceiver) {
       shouldDowncastReceiver = false;
       j = reasoner.downcast(j);
     }
     if (i != j) {
       assert j != parent;
       if (changed == null) {
         changed = (MethodCallTargetNode) parent.copyWithInputs();
         reasoner.added.add(changed);
         // copyWithInputs() implies graph.unique(changed)
         assert changed.isAlive();
         assert FlowUtil.lacksUsages(changed);
       }
       FlowUtil.replaceInPlace(changed, i, j);
     }
   }
   if (changed == null) {
     return parent;
   }
   FlowUtil.inferStampAndCheck(changed);
   /*
    * No need to rememberSubstitution() because not called from deverbosify(). In detail, it's
    * only deverbosify() that skips visited nodes (thus we'd better have recorded any
    * substitutions we want for them). Not this case.
    */
   return changed;
 }
예제 #3
0
 /**
  * This method performs two kinds of cleanup:
  *
  * <ol>
  *   <li>marking as unreachable certain code-paths, as described in {@link
  *       com.oracle.graal.phases.common.cfs.BaseReduction.PostponedDeopt}
  *   <li>Removing nodes not in use that were added during this phase, as described next.
  * </ol>
  *
  * <p>Methods like {@link
  * com.oracle.graal.phases.common.cfs.FlowUtil#replaceInPlace(com.oracle.graal.graph.Node,
  * com.oracle.graal.graph.Node, com.oracle.graal.graph.Node)} may result in old inputs becoming
  * disconnected from the graph. It's not advisable to {@link
  * com.oracle.graal.nodes.util.GraphUtil#tryKillUnused(com.oracle.graal.graph.Node)} at that
  * moment, because one of the inputs that might get killed is one of {@link #nullConstant}, {@link
  * #falseConstant}, or {@link #trueConstant}; which thus could get killed too early, before
  * another invocation of {@link
  * com.oracle.graal.phases.common.cfs.EquationalReasoner#deverbosify(com.oracle.graal.graph.Node)}
  * needs them. To recap, {@link
  * com.oracle.graal.nodes.util.GraphUtil#tryKillUnused(com.oracle.graal.graph.Node)} also
  * recursively visits the inputs of the its argument.
  *
  * <p>This method goes over all of the nodes that deverbosification might have added, which are
  * either:
  *
  * <ul>
  *   <li>{@link com.oracle.graal.nodes.calc.FloatingNode}, added by {@link
  *       com.oracle.graal.phases.common.cfs.EquationalReasoner#deverbosifyFloatingNode(com.oracle.graal.nodes.calc.FloatingNode)}
  *       ; or
  *   <li>{@link com.oracle.graal.nodes.java.MethodCallTargetNode}, added by {@link
  *       #deverbosifyInputsCopyOnWrite(com.oracle.graal.nodes.java.MethodCallTargetNode)}
  * </ul>
  *
  * Checking if they aren't in use, proceeding to remove them in that case.
  */
 @Override
 public void finished() {
   if (!postponedDeopts.isEmpty()) {
     for (PostponedDeopt postponed : postponedDeopts) {
       postponed.doRewrite(falseConstant);
     }
     new DeadCodeEliminationPhase(Optional).apply(graph);
   }
   for (MethodCallTargetNode mcn : graph.getNodes().filter(MethodCallTargetNode.class)) {
     if (mcn.isAlive() && FlowUtil.lacksUsages(mcn)) {
       mcn.safeDelete();
     }
   }
   for (Node n : graph.getNodes().filter(FloatingNode.class)) {
     GraphUtil.tryKillUnused(n);
   }
   assert !isAliveWithoutUsages(trueConstant);
   assert !isAliveWithoutUsages(falseConstant);
   assert !isAliveWithoutUsages(nullConstant);
   super.finished();
 }
예제 #4
0
 private static boolean isAliveWithoutUsages(FloatingNode node) {
   return node.isAlive() && FlowUtil.lacksUsages(node);
 }