annotate graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/cfs/State.java @ 15404:1d3c23e675ed

fixed some minor javadoc formatting issues
author Doug Simon <doug.simon@oracle.com>
date Sun, 27 Apr 2014 17:29:19 +0200
parents 769fc3629f59
children 21204413a6de
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
1 /*
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
4 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
8 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
13 * accompanied this code).
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
14 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
18 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
21 * questions.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
22 */
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
23 package com.oracle.graal.phases.common.cfs;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
24
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
25 import com.oracle.graal.api.meta.Kind;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
26 import com.oracle.graal.api.meta.ResolvedJavaType;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
27 import com.oracle.graal.debug.Debug;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
28 import com.oracle.graal.debug.DebugMetric;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
29 import com.oracle.graal.nodes.*;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
30 import com.oracle.graal.nodes.calc.IsNullNode;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
31 import com.oracle.graal.nodes.calc.ObjectEqualsNode;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
32 import com.oracle.graal.nodes.extended.GuardedNode;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
33 import com.oracle.graal.nodes.extended.GuardingNode;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
34 import com.oracle.graal.nodes.java.InstanceOfNode;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
35 import com.oracle.graal.nodes.spi.ValueProxy;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
36 import com.oracle.graal.compiler.common.type.ObjectStamp;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
37 import com.oracle.graal.nodes.type.StampTool;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
38 import com.oracle.graal.nodes.util.GraphUtil;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
39 import com.oracle.graal.phases.graph.MergeableState;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
40
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
41 import java.lang.reflect.Modifier;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
42 import java.util.*;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
43
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
44 /**
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
45 * A State instance is mutated in place as each FixedNode is visited in a basic block of
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
46 * instructions. Basic block: starts with a {@link com.oracle.graal.nodes.BeginNode BeginNode}, ends
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
47 * at an {@link com.oracle.graal.nodes.EndNode EndNode} or
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
48 * {@link com.oracle.graal.nodes.ControlSinkNode ControlSinkNode} and lacks intervening control
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
49 * splits or merges.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
50 */
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
51 public final class State extends MergeableState<State> implements Cloneable {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
52
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
53 private static final DebugMetric metricTypeRegistered = Debug.metric("TypeRegistered");
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
54 private static final DebugMetric metricNullnessRegistered = Debug.metric("NullnessRegistered");
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
55 private static final DebugMetric metricObjectEqualsRegistered = Debug.metric("ObjectEqualsRegistered");
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
56 private static final DebugMetric metricImpossiblePathDetected = Debug.metric("ImpossiblePathDetected");
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
57
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
58 /**
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
59 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
60 * Each state update results in a higher {@link State#versionNr versionNr}. The
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
61 * {@link State#versionNr versionNr} of different State instances can't be meaningfully compared
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
62 * (ie, same {@link State#versionNr versionNr} just indicates they've gone through the same
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
63 * number of updates). In particular, the {@link State#versionNr versionNr} of a merged state
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
64 * doesn't guarantee any more than being different from those of the states being merged.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
65 * </p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
66 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
67 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
68 * Still, {@link State#versionNr versionNr} proves useful in two cases:
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
69 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
70 * <ul>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
71 * <li>recording the {@link State#versionNr versionNr} right after {@link State State} cloning,
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
72 * allows finding out afterwards whether (a) both states have diverged, (b) just one of them, or
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
73 * (c) none of them.</li>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
74 * <li>a {@link State State} may become {@link State#isUnreachable isUnreachable}. In such case,
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
75 * it may make a difference whether any updates were performed on the state from the time it was
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
76 * cloned. Those updates indicate information not available in the state is was cloned from. For
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
77 * the purposes of {@link FlowSensitiveReduction FlowSensitiveReduction} an unreachable state
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
78 * need not be merged with any other (because control-flow won't reach the merge point over the
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
79 * path of the unreachable state).</li>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
80 * </ul>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
81 * </p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
82 *
15404
1d3c23e675ed fixed some minor javadoc formatting issues
Doug Simon <doug.simon@oracle.com>
parents: 15388
diff changeset
83 */
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
84 int versionNr = 0;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
85
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
86 boolean isUnreachable = false;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
87
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
88 /**
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
89 * Getting here implies an opportunity was detected for dead-code-elimination. A counterpoint
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
90 * argument goes as follows: perhaps we don't get here that often, in which case the effort to
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
91 * detect an "impossible path" could be shaved off.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
92 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
93 * @see com.oracle.graal.phases.common.cfs.BaseReduction.PostponedDeopt
15404
1d3c23e675ed fixed some minor javadoc formatting issues
Doug Simon <doug.simon@oracle.com>
parents: 15388
diff changeset
94 */
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
95 void impossiblePath() {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
96 isUnreachable = true;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
97 metricImpossiblePathDetected.increment();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
98 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
99
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
100 /**
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
101 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
102 * This map semantically tracks "facts" (ie, properties valid for the program-point the state
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
103 * refers to) as opposed to floating-guard-dependent properties. The
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
104 * {@link com.oracle.graal.nodes.extended.GuardingNode} being tracked comes handy at
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
105 * {@link com.oracle.graal.phases.common.cfs.FlowSensitiveReduction#visitFixedGuardNode(com.oracle.graal.nodes.FixedGuardNode)}
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
106 * .
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
107 * </p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
108 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
109 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
110 * On a related note, {@link #typeRefinements} also captures information the way
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
111 * {@link #trueFacts} and {@link #falseFacts} do, including "witnessing" guards. Why not just
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
112 * standardize on one of them, and drop the other? Because the {@link #typeRefinements} eagerly
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
113 * aggregates information for easier querying afterwards, e.g. when producing a "downcasted"
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
114 * value (which involves building a {@link com.oracle.graal.nodes.PiNode}, see
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
115 * {@link EquationalReasoner#downcasted(com.oracle.graal.nodes.ValueNode) downcasted()}
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
116 * </p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
117 *
15404
1d3c23e675ed fixed some minor javadoc formatting issues
Doug Simon <doug.simon@oracle.com>
parents: 15388
diff changeset
118 */
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
119 private IdentityHashMap<ValueNode, Witness> typeRefinements;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
120
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
121 IdentityHashMap<ValueNode, GuardingNode> knownNull;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
122 IdentityHashMap<LogicNode, GuardingNode> trueFacts;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
123 IdentityHashMap<LogicNode, GuardingNode> falseFacts;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
124
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
125 public State() {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
126 this.typeRefinements = new IdentityHashMap<>();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
127 this.knownNull = new IdentityHashMap<>();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
128 this.trueFacts = new IdentityHashMap<>();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
129 this.falseFacts = new IdentityHashMap<>();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
130 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
131
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
132 public State(State other) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
133 this.isUnreachable = other.isUnreachable;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
134 this.versionNr = other.versionNr;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
135 this.typeRefinements = new IdentityHashMap<>();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
136 for (Map.Entry<ValueNode, Witness> entry : other.typeRefinements.entrySet()) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
137 this.typeRefinements.put(entry.getKey(), new Witness(entry.getValue()));
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
138 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
139 this.knownNull = new IdentityHashMap<>(other.knownNull);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
140 this.trueFacts = new IdentityHashMap<>(other.trueFacts);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
141 this.falseFacts = new IdentityHashMap<>(other.falseFacts);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
142 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
143
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
144 /**
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
145 * @return A new list containing only those states that are reachable.
15404
1d3c23e675ed fixed some minor javadoc formatting issues
Doug Simon <doug.simon@oracle.com>
parents: 15388
diff changeset
146 */
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
147 private static ArrayList<State> reachableStates(List<State> states) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
148 ArrayList<State> result = new ArrayList<>(states);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
149 Iterator<State> iter = result.iterator();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
150 while (iter.hasNext()) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
151 if (iter.next().isUnreachable) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
152 iter.remove();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
153 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
154 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
155 return result;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
156 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
157
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
158 private IdentityHashMap<ValueNode, Witness> mergeKnownTypes(MergeNode merge, ArrayList<State> withReachableStates) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
159 IdentityHashMap<ValueNode, Witness> newKnownTypes = new IdentityHashMap<>();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
160
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
161 for (Map.Entry<ValueNode, Witness> entry : typeRefinements.entrySet()) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
162 ValueNode node = entry.getKey();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
163 Witness type = new Witness(entry.getValue());
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
164
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
165 for (State other : withReachableStates) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
166 Witness otherType = other.typeInfo(node);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
167 if (otherType == null) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
168 type = null;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
169 break;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
170 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
171 type.merge(otherType, merge);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
172 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
173 if (type != null && type.knowsBetterThan(node)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
174 assert node == GraphUtil.unproxify(node);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
175 newKnownTypes.put(node, type);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
176 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
177 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
178
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
179 return newKnownTypes;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
180 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
181
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
182 private IdentityHashMap<ValueNode, GuardingNode> mergeKnownNull(MergeNode merge, ArrayList<State> withReachableStates) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
183 // newKnownNull starts empty
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
184 IdentityHashMap<ValueNode, GuardingNode> newKnownNull = new IdentityHashMap<>();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
185 for (Map.Entry<ValueNode, GuardingNode> entry : knownNull.entrySet()) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
186 ValueNode key = entry.getKey();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
187 GuardingNode newGN = entry.getValue();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
188 boolean missing = false;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
189
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
190 for (State other : withReachableStates) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
191 GuardingNode otherGuard = other.knownNull.get(key);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
192 if (otherGuard == null) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
193 missing = true;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
194 break;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
195 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
196 if (otherGuard != newGN) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
197 newGN = merge;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
198 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
199 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
200 if (!missing) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
201 newKnownNull.put(key, newGN);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
202 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
203 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
204 return newKnownNull;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
205 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
206
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
207 /**
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
208 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
209 * This method handles phis, by adding to the resulting state any information that can be gained
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
210 * (about type-refinement and nullness) based on the data available at each of the incoming
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
211 * branches.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
212 * </p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
213 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
214 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
215 * In more detail, <code>FlowSensitiveReduction#visitAbstractEndNode()</code> has already
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
216 * deverbosified the phi-values contributed by each reachable branch. The paths that
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
217 * {@link com.oracle.graal.phases.common.cfs.FlowSensitiveReduction} determined to be
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
218 * unreachable will be eliminated by canonicalization and dead code elimination. For now they
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
219 * still exist, thus polluting the result of
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
220 * {@link com.oracle.graal.nodes.ValuePhiNode#inferPhiStamp()} but we are careful to skip them
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
221 * when merging type-witnesses and known-null maps.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
222 * </p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
223 */
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
224 private void mergePhis(MergeNode merge, List<State> withStates, IdentityHashMap<ValueNode, Witness> newKnownPhiTypes, IdentityHashMap<ValueNode, GuardingNode> newKnownNullPhis) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
225
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
226 if (merge instanceof LoopBeginNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
227 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
228 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
229
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
230 for (PhiNode phi : merge.phis()) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
231 assert phi == GraphUtil.unproxify(phi);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
232 if (phi instanceof ValuePhiNode && phi.getKind() == Kind.Object) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
233 ArrayList<ValueNode> reachingValues = new ArrayList<>();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
234 if (!isUnreachable) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
235 reachingValues.add(phi.valueAt(0));
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
236 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
237 for (int i = 0; i < withStates.size(); i++) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
238 State otherState = withStates.get(i);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
239 if (!otherState.isUnreachable) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
240 reachingValues.add(phi.valueAt(i + 1));
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
241 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
242 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
243 assert !reachingValues.isEmpty();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
244 ObjectStamp phiStamp = (ObjectStamp) phi.stamp();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
245 ObjectStamp nonPollutedStamp = (ObjectStamp) StampTool.meet(reachingValues);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
246 Witness w = new Witness(nonPollutedStamp, merge);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
247 if (FlowUtil.isMorePrecise(w.type(), phiStamp.type())) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
248 // precision gain regarding type
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
249 newKnownPhiTypes.put(phi, w);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
250 // confirm no precision loss regarding nullness
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
251 assert implies(phiStamp.nonNull(), w.isNonNull());
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
252 } else if (w.isNonNull() && !phiStamp.nonNull()) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
253 // precision gain regarding nullness
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
254 newKnownPhiTypes.put(phi, w);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
255 // confirm no precision loss regarding type
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
256 assert !FlowUtil.isMorePrecise(phiStamp.type(), w.type());
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
257 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
258 if (nonPollutedStamp.alwaysNull()) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
259 newKnownNullPhis.put(phi, merge);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
260 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
261 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
262 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
263
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
264 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
265
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
266 private static boolean implies(boolean a, boolean b) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
267 return !a || b;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
268 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
269
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
270 @Override
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
271 public boolean merge(MergeNode merge, List<State> withStates) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
272
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
273 ArrayList<State> withReachableStates = reachableStates(withStates);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
274 if (withReachableStates.isEmpty()) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
275 return true;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
276 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
277
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
278 for (State state : withReachableStates) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
279 versionNr = Math.max(versionNr, state.versionNr) + 1;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
280 isUnreachable &= state.isUnreachable;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
281 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
282
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
283 if (isUnreachable) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
284 typeRefinements.clear();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
285 knownNull.clear();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
286 return true;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
287 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
288
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
289 // may also get updated in a moment, during processing of phi nodes.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
290 IdentityHashMap<ValueNode, Witness> newKnownTypes = mergeKnownTypes(merge, withReachableStates);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
291 // may also get updated in a moment, during processing of phi nodes.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
292 IdentityHashMap<ValueNode, GuardingNode> newKnownNull = mergeKnownNull(merge, withReachableStates);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
293 mergePhis(merge, withStates, newKnownTypes, newKnownNull);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
294 this.typeRefinements = newKnownTypes;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
295 this.knownNull = newKnownNull;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
296
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
297 this.trueFacts = mergeTrueFacts(withReachableStates, merge);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
298 this.falseFacts = mergeFalseFacts(withReachableStates, merge);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
299 return true;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
300 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
301
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
302 private IdentityHashMap<LogicNode, GuardingNode> mergeTrueFacts(ArrayList<State> withReachableStates, GuardingNode merge) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
303 IdentityHashMap<LogicNode, GuardingNode> newTrueConditions = new IdentityHashMap<>();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
304 for (Map.Entry<LogicNode, GuardingNode> entry : trueFacts.entrySet()) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
305 LogicNode check = entry.getKey();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
306 GuardingNode guard = entry.getValue();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
307
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
308 for (State other : withReachableStates) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
309 GuardingNode otherGuard = other.trueFacts.get(check);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
310 if (otherGuard == null) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
311 guard = null;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
312 break;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
313 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
314 if (otherGuard != guard) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
315 guard = merge;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
316 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
317 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
318 if (guard != null) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
319 newTrueConditions.put(check, guard);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
320 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
321 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
322 return newTrueConditions;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
323 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
324
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
325 private IdentityHashMap<LogicNode, GuardingNode> mergeFalseFacts(ArrayList<State> withReachableStates, GuardingNode merge) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
326 IdentityHashMap<LogicNode, GuardingNode> newFalseConditions = new IdentityHashMap<>();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
327 for (Map.Entry<LogicNode, GuardingNode> entry : falseFacts.entrySet()) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
328 LogicNode check = entry.getKey();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
329 GuardingNode guard = entry.getValue();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
330
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
331 for (State other : withReachableStates) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
332 GuardingNode otherGuard = other.falseFacts.get(check);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
333 if (otherGuard == null) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
334 guard = null;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
335 break;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
336 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
337 if (otherGuard != guard) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
338 guard = merge;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
339 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
340 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
341 if (guard != null) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
342 newFalseConditions.put(check, guard);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
343 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
344 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
345 return newFalseConditions;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
346 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
347
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
348 /**
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
349 * @retun null if no type-witness available for the argument, the witness otherwise.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
350 */
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
351 public Witness typeInfo(ValueNode object) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
352 assert FlowUtil.hasLegalObjectStamp(object);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
353 return typeRefinements.get(GraphUtil.unproxify(object));
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
354 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
355
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
356 /**
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
357 * @retun true iff the argument is known to stand for null.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
358 */
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
359 public boolean isNull(ValueNode object) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
360 assert FlowUtil.hasLegalObjectStamp(object);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
361 return StampTool.isObjectAlwaysNull(object) || knownNull.containsKey(GraphUtil.unproxify(object));
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
362 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
363
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
364 /**
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
365 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
366 * It makes a difference calling {@link Witness#isNonNull()} as opposed to
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
367 * {@link State#isNonNull(com.oracle.graal.nodes.ValueNode)}. The former guarantees the witness
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
368 * provides a guard certifying non-nullness. The latter just tells us there exists some guard
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
369 * that certifies the property we asked about.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
370 * </p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
371 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
372 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
373 * TODO improvement: isKnownNonNull could be made smarter by noticing some nodes always denote a
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
374 * non-null value (eg, ObjectGetClassNode). Similarly for isKnownNull. Code that looks at the
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
375 * stamp as well as code that looks for a non-null-witness would benefit from also checking such
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
376 * extended isKnownNonNull. Alternatively, the stamp of those nodes should always have
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
377 * is-non-null set.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
378 * </p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
379 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
380 * @retun true iff the argument is known to stand for non-null.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
381 */
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
382 public boolean isNonNull(ValueNode object) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
383 assert FlowUtil.hasLegalObjectStamp(object);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
384 if (StampTool.isObjectNonNull(object)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
385 return true;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
386 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
387 Witness w = typeInfo(object);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
388 return w == null ? false : w.isNonNull();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
389 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
390
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
391 /**
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
392 * @retun true iff the argument is known to stand for an object conforming to the given type.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
393 */
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
394 public boolean knownToConform(ValueNode object, ResolvedJavaType to) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
395 assert FlowUtil.hasLegalObjectStamp(object);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
396 assert !to.isPrimitive();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
397 ResolvedJavaType stampType = StampTool.typeOrNull(object);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
398 if (stampType != null && to.isAssignableFrom(stampType)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
399 return true;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
400 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
401 final ValueNode scrutinee = GraphUtil.unproxify(object);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
402 if (isNull(scrutinee)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
403 return true;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
404 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
405 Witness w = typeInfo(scrutinee);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
406 boolean witnessAnswer = w != null && w.type() != null && to.isAssignableFrom(w.type());
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
407 if (witnessAnswer) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
408 return true;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
409 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
410 return false;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
411 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
412
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
413 /**
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
414 * @retun true iff the argument is known to stand for an object that definitely does not conform
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
415 * to the given type.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
416 */
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
417 public boolean knownNotToConform(ValueNode object, ResolvedJavaType to) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
418 assert FlowUtil.hasLegalObjectStamp(object);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
419 assert !to.isPrimitive();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
420 final ValueNode scrutinee = GraphUtil.unproxify(object);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
421 if (isNull(scrutinee)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
422 return false;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
423 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
424 ResolvedJavaType stampType = StampTool.typeOrNull(object);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
425 if (stampType != null && knownNotToConform(stampType, to)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
426 return true;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
427 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
428 Witness w = typeInfo(scrutinee);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
429 boolean witnessAnswer = w != null && !w.cluelessAboutType() && knownNotToConform(w.type(), to);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
430 if (witnessAnswer) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
431 return true;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
432 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
433 return false;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
434 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
435
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
436 // @formatter:off
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
437 /**
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
438 * \ | | | |
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
439 * \ b| | | |
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
440 * a \ | | | |
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
441 * \|iface|final|non-f|
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
442 * -----+-----------------|
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
443 * iface| F | F | F |
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
444 * -----+-----------------|
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
445 * final| C | C | C |
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
446 * -----+-----------------|
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
447 * non-f| F | C | C |
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
448 * -----------------------+
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
449 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
450 * where:
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
451 * F: false
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
452 * C: check
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
453 * iface: interface
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
454 * final: exact non-interface reference-type
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
455 * non-f: non-exact non-interface reference-type
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
456 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
457 * @retun true iff the first argument is known not to conform to the second argument.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
458 */
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
459 // @formatter:on
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
460 public static boolean knownNotToConform(ResolvedJavaType a, ResolvedJavaType b) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
461 assert !a.isPrimitive();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
462 assert !b.isPrimitive();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
463 if (b.isAssignableFrom(a)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
464 return false;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
465 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
466 if (a.isInterface()) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
467 return false;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
468 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
469 boolean aFinal = Modifier.isFinal(a.getModifiers());
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
470 if (b.isInterface() && !aFinal) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
471 return false;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
472 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
473 if (a.isAssignableFrom(b)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
474 return false;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
475 } else {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
476 return true;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
477 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
478 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
479
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
480 @Override
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
481 public State clone() {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
482 return new State(this);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
483 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
484
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
485 /**
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
486 * Porcelain method.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
487 */
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
488 private Witness getOrElseAddTypeInfo(ValueNode object) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
489 ValueNode scrutinee = GraphUtil.unproxify(object);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
490 Witness w = typeRefinements.get(scrutinee);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
491 if (w == null) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
492 w = new Witness();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
493 typeRefinements.put(scrutinee, w);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
494 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
495 return w;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
496 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
497
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
498 /**
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
499 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
500 * Updates this {@link State State} to account for an observation about the scrutinee being
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
501 * non-null. In case instanceof was observed,
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
502 * {@link #trackIO(com.oracle.graal.nodes.ValueNode, com.oracle.graal.api.meta.ResolvedJavaType, com.oracle.graal.nodes.extended.GuardingNode)
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
503 * <code>trackIO(ResolvedJavaType, GuardingNode)</code>} should be invoked instead.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
504 * </p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
505 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
506 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
507 * No check is made on whether a contradiction would be introduced into the factbase (in which
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
508 * case the state should be marked unreachable), the caller takes care of that.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
509 * </p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
510 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
511 * @return whether state was updated (iff the observation added any new information)
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
512 */
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
513 public boolean trackNN(ValueNode object, GuardingNode anchor) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
514 if (isDependencyTainted(object, anchor)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
515 return false;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
516 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
517 ResolvedJavaType stampType = StampTool.typeOrNull(object);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
518 if (stampType != null && !stampType.isInterface()) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
519 return trackIO(object, stampType, anchor);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
520 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
521 Witness w = getOrElseAddTypeInfo(object);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
522 if (w.trackNN(anchor)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
523 versionNr++;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
524 return true;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
525 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
526 return false;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
527 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
528
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
529 /**
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
530 * Updates this {@link State State} to account for an observation about the scrutinee conforming
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
531 * to a type. In case instanceof was observed,
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
532 * {@link #trackIO(com.oracle.graal.nodes.ValueNode, com.oracle.graal.api.meta.ResolvedJavaType, com.oracle.graal.nodes.extended.GuardingNode)
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
533 * <code>trackIO(ResolvedJavaType, GuardingNode)</code>} should be invoked instead.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
534 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
535 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
536 * No check is made on whether a contradiction would be introduced into the factbase (in which
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
537 * case the state should be marked unreachable), the caller must take care of that.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
538 * </p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
539 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
540 * @return false iff the observed type is an interface, or doesn't provide any new information
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
541 * not already known. Ie, this method returns true iff the observation resulted in
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
542 * information gain.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
543 */
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
544 public boolean trackCC(ValueNode object, ResolvedJavaType observed, GuardingNode anchor) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
545 if (observed.isInterface()) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
546 return false;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
547 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
548 if (isDependencyTainted(object, anchor)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
549 return false;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
550 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
551 Witness w = getOrElseAddTypeInfo(object);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
552 if (w.trackCC(observed, anchor)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
553 versionNr++;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
554 metricTypeRegistered.increment();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
555 return true;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
556 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
557 return false;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
558 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
559
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
560 /**
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
561 * Updates this {@link State State} to account for an observation about the non-null scrutinee
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
562 * conforming to a type.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
563 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
564 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
565 * No check is made on whether a contradiction would be introduced into the factbase (in which
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
566 * case the state should be marked unreachable), the caller must take care of that.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
567 * </p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
568 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
569 * @return whether state was updated (iff the observation added any new information)
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
570 */
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
571 public boolean trackIO(ValueNode object, ResolvedJavaType observed, GuardingNode anchor) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
572 assert !observed.isInterface() : "no infrastructure yet in State.Witness to support interfaces in general";
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
573 if (isDependencyTainted(object, anchor)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
574 return false;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
575 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
576 Witness w = getOrElseAddTypeInfo(object);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
577 if (w.trackIO(observed, anchor)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
578 versionNr++;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
579 metricTypeRegistered.increment();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
580 return true;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
581 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
582 return false;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
583 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
584
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
585 /**
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
586 * This method increases {@link #versionNr} (thus potentially invalidating
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
587 * {@link EquationalReasoner EquationalReasoner}'s caches) only if the fact wasn't known
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
588 * already.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
589 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
590 * <p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
591 * No check is made on whether a contradiction would be introduced into the factbase (in which
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
592 * case the state should be marked unreachable), the caller must take care of that.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
593 * </p>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
594 *
15404
1d3c23e675ed fixed some minor javadoc formatting issues
Doug Simon <doug.simon@oracle.com>
parents: 15388
diff changeset
595 */
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
596 private void addFactPrimordial(LogicNode condition, IdentityHashMap<LogicNode, GuardingNode> to, GuardingNode anchor) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
597 assert condition != null;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
598 if (!to.containsKey(condition)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
599 versionNr++;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
600 to.put(condition, anchor);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
601 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
602 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
603
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
604 /**
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
605 * Ideas for the future:
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
606 * <ul>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
607 * <li>track inferred less-than edges from (accumulated) CompareNode-s</li>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
608 * <li>track set-representative for equality classes determined by (chained) IntegerTestNode</li>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
609 * </ul>
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
610 *
15404
1d3c23e675ed fixed some minor javadoc formatting issues
Doug Simon <doug.simon@oracle.com>
parents: 15388
diff changeset
611 */
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
612 public void addFact(boolean isTrue, LogicNode condition, GuardingNode anchor) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
613 assert anchor != null;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
614 assert !isUnreachable;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
615
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
616 if (condition instanceof LogicConstantNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
617 if (((LogicConstantNode) condition).getValue() != isTrue) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
618 impossiblePath();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
619 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
620 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
621 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
622
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
623 if (condition instanceof LogicNegationNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
624 addFact(!isTrue, ((LogicNegationNode) condition).getInput(), anchor);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
625 } else if (condition instanceof ShortCircuitOrNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
626 /*
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
627 * We can register the conditions being or-ed as long as the anchor is a fixed node,
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
628 * because floating guards will be registered at a BeginNode but might be "valid" only
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
629 * later due to data flow dependencies. Therefore, registering both conditions of a
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
630 * ShortCircuitOrNode for a floating guard could lead to cycles in data flow, because
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
631 * the guard will be used as anchor for both conditions, and one condition could be
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
632 * depending on the other.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
633 */
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
634 if (isTrue) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
635 CastCheckExtractor cce = CastCheckExtractor.extract(condition);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
636 if (cce == null || isDependencyTainted(cce.subject, anchor)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
637 addFactPrimordial(condition, isTrue ? trueFacts : falseFacts, anchor);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
638 } else {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
639 trackCC(cce.subject, cce.type, anchor);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
640 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
641 } else {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
642 ShortCircuitOrNode disjunction = (ShortCircuitOrNode) condition;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
643 addFact(disjunction.isXNegated(), disjunction.getX(), anchor);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
644 // previous addFact might have resulted in impossiblePath()
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
645 if (isUnreachable) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
646 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
647 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
648 addFact(disjunction.isYNegated(), disjunction.getY(), anchor);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
649 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
650 } else if (condition instanceof InstanceOfNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
651 addFactInstanceOf(isTrue, (InstanceOfNode) condition, anchor);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
652 } else if (condition instanceof IsNullNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
653 IsNullNode nullCheck = (IsNullNode) condition;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
654 addNullness(isTrue, nullCheck.object(), anchor);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
655 } else if (condition instanceof ObjectEqualsNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
656 addFactObjectEqualsNode(isTrue, (ObjectEqualsNode) condition, anchor);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
657 } else {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
658 addFactPrimordial(condition, isTrue ? trueFacts : falseFacts, anchor);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
659 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
660 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
661
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
662 /**
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
663 * An instanceof hint is tracked differently depending on whether it's an interface-test or not
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
664 * (because type-refinements currently lacks the ability to track interface types).
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
665 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
666 */
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
667 private void addFactInstanceOf(boolean isTrue, InstanceOfNode instanceOf, GuardingNode anchor) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
668 ValueNode object = instanceOf.object();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
669 if (isTrue) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
670 if (knownNotToConform(object, instanceOf.type())) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
671 impossiblePath();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
672 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
673 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
674 addNullness(false, object, anchor);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
675 if (instanceOf.type().isInterface()) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
676 if (!knownToConform(object, instanceOf.type())) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
677 addFactPrimordial(instanceOf, trueFacts, anchor);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
678 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
679 } else {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
680 trackIO(object, instanceOf.type(), anchor);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
681 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
682 } else {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
683 if (knownToConform(object, instanceOf.type())) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
684 impossiblePath(); // TODO this used to be a bug
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
685 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
686 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
687 if (instanceOf.type().isInterface()) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
688 if (!knownNotToConform(object, instanceOf.type())) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
689 addFactPrimordial(instanceOf, falseFacts, anchor);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
690 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
691 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
692 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
693 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
694
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
695 private void addFactObjectEqualsNode(boolean isTrue, ObjectEqualsNode equals, GuardingNode anchor) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
696 if (isDependencyTainted(equals.x(), anchor)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
697 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
698 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
699 if (isDependencyTainted(equals.y(), anchor)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
700 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
701 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
702 ValueNode x = GraphUtil.unproxify(equals.x());
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
703 ValueNode y = GraphUtil.unproxify(equals.y());
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
704 if (isTrue) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
705 if (isNull(x) && isNonNull(y)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
706 impossiblePath();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
707 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
708 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
709 if (isNonNull(x) && isNull(y)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
710 impossiblePath();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
711 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
712 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
713 if (isNull(x) || isNull(y)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
714 metricObjectEqualsRegistered.increment();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
715 addNullness(true, equals.x(), anchor);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
716 addNullness(true, equals.y(), anchor);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
717 } else if (isNonNull(x) || isNonNull(y)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
718 metricObjectEqualsRegistered.increment();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
719 addNullness(false, equals.x(), anchor);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
720 addNullness(false, equals.y(), anchor);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
721 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
722 Witness wx = typeInfo(x);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
723 Witness wy = typeInfo(y);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
724 if (wx == null && wy == null) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
725 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
726 } else if (wx != null && wy != null) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
727 // tighten their type-hints, provided at least one available
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
728 // both witnesses may have seen == null, ie they may be NN witnesses
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
729 ResolvedJavaType best = FlowUtil.tighten(wx.type(), wy.type());
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
730 if (best != null) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
731 assert !best.isInterface();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
732 // type tightening is enough, nullness already taken care of
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
733 trackCC(equals.x(), best, anchor);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
734 trackCC(equals.y(), best, anchor);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
735 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
736 } else if (wx == null) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
737 typeRefinements.put(x, new Witness(wy));
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
738 } else if (wy == null) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
739 typeRefinements.put(y, new Witness(wx));
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
740 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
741 } else {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
742 if (isNull(x) && !isNonNull(y)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
743 metricObjectEqualsRegistered.increment();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
744 addNullness(false, equals.y(), anchor);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
745 } else if (!isNonNull(x) && isNull(y)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
746 metricObjectEqualsRegistered.increment();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
747 addNullness(false, equals.x(), anchor);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
748 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
749 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
750 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
751
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
752 /**
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
753 * Adds information about the nullness of a value. If isNull is true then the value is known to
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
754 * be null, otherwise the value is known to be non-null.
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
755 */
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
756 public void addNullness(boolean isNull, ValueNode value, GuardingNode anchor) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
757 if (isDependencyTainted(value, anchor)) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
758 return;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
759 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
760 ValueNode original = GraphUtil.unproxify(value);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
761 boolean wasNull = isNull(original);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
762 boolean wasNonNull = isNonNull(original);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
763 if (isNull) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
764 if (wasNonNull) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
765 impossiblePath();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
766 } else {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
767 metricNullnessRegistered.increment();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
768 versionNr++;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
769 knownNull.put(original, anchor);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
770 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
771 } else {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
772 if (wasNull) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
773 impossiblePath();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
774 } else {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
775 metricNullnessRegistered.increment();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
776 trackNN(original, anchor);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
777 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
778 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
779 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
780
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
781 /**
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
782 *
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
783 * @return true iff `value` may lose dependency not covered by `anchor`.
15404
1d3c23e675ed fixed some minor javadoc formatting issues
Doug Simon <doug.simon@oracle.com>
parents: 15388
diff changeset
784 */
15388
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
785 public static boolean isDependencyTainted(ValueNode value, GuardingNode anchor) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
786 if (value instanceof ValueProxy) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
787 if (value instanceof GuardedNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
788 GuardedNode gn = (GuardedNode) value;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
789 GuardingNode guardian = gn.getGuard();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
790 if (guardian != null) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
791 boolean isGuardedByFixed = guardian instanceof FixedNode;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
792 if (!isGuardedByFixed) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
793 return true;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
794 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
795 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
796 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
797 // if (value instanceof GuardingNode) {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
798 // return true;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
799 // }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
800 ValueProxy proxy = (ValueProxy) value;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
801 return isDependencyTainted(proxy.getOriginalNode(), anchor);
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
802 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
803 return false;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
804 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
805
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
806 public void clear() {
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
807 versionNr = 0;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
808 isUnreachable = false;
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
809 typeRefinements.clear();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
810 knownNull.clear();
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
811 }
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
812
769fc3629f59 Add phase FlowSensitiveReductionPhase.
Miguel Garcia <miguel.m.garcia@oracle.com>
parents:
diff changeset
813 }