Mercurial > hg > graal-compiler
annotate graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/UseTrappingNullChecksPhase.java @ 22054:0e095e2c24e2
Rename com.oracle.jvmci to jdk.internal.jvmci
author | twisti |
---|---|
date | Mon, 22 Jun 2015 12:12:53 -0700 |
parents | 48c1ebd24120 |
children | 7b4a47fcc4c0 |
rev | line source |
---|---|
13635
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
1 /* |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
2 * Copyright (c) 2014, 2014, Oracle and/or its affiliates. All rights reserved. |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
4 * |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
8 * |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
13 * accompanied this code). |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
14 * |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
18 * |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
21 * questions. |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
22 */ |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
23 package com.oracle.graal.phases.common; |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
24 |
15698
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
25 import java.util.*; |
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
26 |
22054 | 27 import jdk.internal.jvmci.debug.*; |
28 import jdk.internal.jvmci.meta.*; | |
29 | |
13635
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
30 import com.oracle.graal.graph.*; |
16841
cbd42807a31f
moved NodeInfo and friends into separate com.oracle.graal.nodeinfo project so that annotation processor can be applied to the base Node class
Doug Simon <doug.simon@oracle.com>
parents:
16423
diff
changeset
|
31 import com.oracle.graal.nodeinfo.*; |
13635
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
32 import com.oracle.graal.nodes.*; |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
33 import com.oracle.graal.nodes.calc.*; |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
34 import com.oracle.graal.nodes.extended.*; |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
35 import com.oracle.graal.nodes.util.*; |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
36 import com.oracle.graal.phases.*; |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
37 import com.oracle.graal.phases.tiers.*; |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
38 |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
39 public class UseTrappingNullChecksPhase extends BasePhase<LowTierContext> { |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
40 |
15698
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
41 private static final DebugMetric metricTrappingNullCheck = Debug.metric("TrappingNullCheck"); |
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
42 private static final DebugMetric metricTrappingNullCheckUnreached = Debug.metric("TrappingNullCheckUnreached"); |
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
43 private static final DebugMetric metricTrappingNullCheckDynamicDeoptimize = Debug.metric("TrappingNullCheckDynamicDeoptimize"); |
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
44 |
13635
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
45 @Override |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
46 protected void run(StructuredGraph graph, LowTierContext context) { |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
47 if (context.getTarget().implicitNullCheckLimit <= 0) { |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
48 return; |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
49 } |
18970
edf3a7fdd067
Add utility methods to GuardsStage.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18937
diff
changeset
|
50 assert graph.getGuardsStage().areFrameStatesAtDeopts(); |
13635
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
51 |
19410
61d3cb8e1280
Add generic parameter to NodeClass. Change Graph#getNodes(Class) to Graph#getNodes(NodeClass).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18997
diff
changeset
|
52 for (DeoptimizeNode deopt : graph.getNodes(DeoptimizeNode.TYPE)) { |
15698
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
53 tryUseTrappingNullCheck(deopt, deopt.predecessor(), deopt.reason(), deopt.getSpeculation()); |
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
54 } |
19410
61d3cb8e1280
Add generic parameter to NodeClass. Change Graph#getNodes(Class) to Graph#getNodes(NodeClass).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18997
diff
changeset
|
55 for (DynamicDeoptimizeNode deopt : graph.getNodes(DynamicDeoptimizeNode.TYPE)) { |
15698
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
56 tryUseTrappingNullCheck(context.getMetaAccess(), deopt); |
13635
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
57 } |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
58 } |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
59 |
15698
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
60 private static void tryUseTrappingNullCheck(MetaAccessProvider metaAccessProvider, DynamicDeoptimizeNode deopt) { |
13635
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
61 Node predecessor = deopt.predecessor(); |
18995
a2cb19764970
Rename MergeNode to AbstractMergeNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18993
diff
changeset
|
62 if (predecessor instanceof AbstractMergeNode) { |
a2cb19764970
Rename MergeNode to AbstractMergeNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18993
diff
changeset
|
63 AbstractMergeNode merge = (AbstractMergeNode) predecessor; |
15698
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
64 |
15807
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
65 // Process each predecessor at the merge, unpacking the reasons and speculations as |
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
66 // needed. |
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
67 ValueNode reason = deopt.getActionAndReason(); |
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
68 ValuePhiNode reasonPhi = null; |
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
69 List<ValueNode> reasons = null; |
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
70 int expectedPhis = 0; |
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
71 |
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
72 if (reason instanceof ValuePhiNode) { |
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
73 reasonPhi = (ValuePhiNode) reason; |
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
74 if (reasonPhi.merge() != merge) { |
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
75 return; |
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
76 } |
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
77 reasons = reasonPhi.values().snapshot(); |
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
78 expectedPhis++; |
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
79 } else if (!reason.isConstant()) { |
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
80 return; |
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
81 } |
15698
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
82 |
15807
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
83 ValueNode speculation = deopt.getSpeculation(); |
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
84 ValuePhiNode speculationPhi = null; |
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
85 List<ValueNode> speculations = null; |
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
86 if (speculation instanceof ValuePhiNode) { |
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
87 speculationPhi = (ValuePhiNode) speculation; |
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
88 if (speculationPhi.merge() != merge) { |
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
89 return; |
15778
9ae1d2f3bda6
convert asserts into if tests and check for phis at merge
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15741
diff
changeset
|
90 } |
15807
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
91 speculations = speculationPhi.values().snapshot(); |
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
92 expectedPhis++; |
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
93 } |
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
94 |
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
95 if (merge.phis().count() != expectedPhis) { |
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
96 return; |
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
97 } |
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
98 |
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
99 int index = 0; |
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
100 for (AbstractEndNode end : merge.cfgPredecessors().snapshot()) { |
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
101 ValueNode thisReason = reasons != null ? reasons.get(index) : reason; |
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
102 ValueNode thisSpeculation = speculations != null ? speculations.get(index++) : speculation; |
18490
ca81508f2a19
Generalize NULL handling to work on arbitrary pointers.
Roland Schatz <roland.schatz@oracle.com>
parents:
18487
diff
changeset
|
103 if (!thisReason.isConstant() || !thisSpeculation.isConstant() || !thisSpeculation.asConstant().equals(JavaConstant.NULL_POINTER)) { |
15807
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
104 continue; |
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
105 } |
18187
9619ba4daf4c
Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents:
17450
diff
changeset
|
106 DeoptimizationReason deoptimizationReason = metaAccessProvider.decodeDeoptReason(thisReason.asJavaConstant()); |
15807
c9f913e5a93b
handle expected phis when converting to trapping null checks
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15778
diff
changeset
|
107 tryUseTrappingNullCheck(deopt, end.predecessor(), deoptimizationReason, null); |
15698
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
108 } |
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
109 } |
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
110 } |
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
111 |
18187
9619ba4daf4c
Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents:
17450
diff
changeset
|
112 private static void tryUseTrappingNullCheck(AbstractDeoptimizeNode deopt, Node predecessor, DeoptimizationReason deoptimizationReason, JavaConstant speculation) { |
15698
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
113 if (deoptimizationReason != DeoptimizationReason.NullCheckException && deoptimizationReason != DeoptimizationReason.UnreachedCode) { |
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
114 return; |
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
115 } |
18490
ca81508f2a19
Generalize NULL handling to work on arbitrary pointers.
Roland Schatz <roland.schatz@oracle.com>
parents:
18487
diff
changeset
|
116 if (speculation != null && !speculation.equals(JavaConstant.NULL_POINTER)) { |
15698
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
117 return; |
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
118 } |
18995
a2cb19764970
Rename MergeNode to AbstractMergeNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18993
diff
changeset
|
119 if (predecessor instanceof AbstractMergeNode) { |
a2cb19764970
Rename MergeNode to AbstractMergeNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18993
diff
changeset
|
120 AbstractMergeNode merge = (AbstractMergeNode) predecessor; |
15778
9ae1d2f3bda6
convert asserts into if tests and check for phis at merge
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15741
diff
changeset
|
121 if (merge.phis().isEmpty()) { |
9ae1d2f3bda6
convert asserts into if tests and check for phis at merge
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15741
diff
changeset
|
122 for (AbstractEndNode end : merge.cfgPredecessors().snapshot()) { |
9ae1d2f3bda6
convert asserts into if tests and check for phis at merge
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15741
diff
changeset
|
123 checkPredecessor(deopt, end.predecessor(), deoptimizationReason); |
9ae1d2f3bda6
convert asserts into if tests and check for phis at merge
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15741
diff
changeset
|
124 } |
15698
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
125 } |
18993
480bd3b1adcd
Rename BeginNode => AbstractBeginNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18970
diff
changeset
|
126 } else if (predecessor instanceof AbstractBeginNode) { |
15698
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
127 checkPredecessor(deopt, predecessor, deoptimizationReason); |
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
128 } |
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
129 } |
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
130 |
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
131 private static void checkPredecessor(AbstractDeoptimizeNode deopt, Node predecessor, DeoptimizationReason deoptimizationReason) { |
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
132 Node current = predecessor; |
18993
480bd3b1adcd
Rename BeginNode => AbstractBeginNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18970
diff
changeset
|
133 AbstractBeginNode branch = null; |
480bd3b1adcd
Rename BeginNode => AbstractBeginNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18970
diff
changeset
|
134 while (current instanceof AbstractBeginNode) { |
480bd3b1adcd
Rename BeginNode => AbstractBeginNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18970
diff
changeset
|
135 branch = (AbstractBeginNode) current; |
16423
a9b85fe36dbc
Don't rewrite to trapping null checks if the FrameState has an input that's anchored to the deopting branch.
Roland Schatz <roland.schatz@oracle.com>
parents:
16207
diff
changeset
|
136 if (branch.anchored().isNotEmpty()) { |
a9b85fe36dbc
Don't rewrite to trapping null checks if the FrameState has an input that's anchored to the deopting branch.
Roland Schatz <roland.schatz@oracle.com>
parents:
16207
diff
changeset
|
137 // some input of the deopt framestate is anchored to this branch |
a9b85fe36dbc
Don't rewrite to trapping null checks if the FrameState has an input that's anchored to the deopting branch.
Roland Schatz <roland.schatz@oracle.com>
parents:
16207
diff
changeset
|
138 return; |
a9b85fe36dbc
Don't rewrite to trapping null checks if the FrameState has an input that's anchored to the deopting branch.
Roland Schatz <roland.schatz@oracle.com>
parents:
16207
diff
changeset
|
139 } |
15698
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
140 current = current.predecessor(); |
13635
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
141 } |
15698
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
142 if (current instanceof IfNode) { |
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
143 IfNode ifNode = (IfNode) current; |
13635
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
144 if (branch != ifNode.trueSuccessor()) { |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
145 return; |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
146 } |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
147 LogicNode condition = ifNode.condition(); |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
148 if (condition instanceof IsNullNode) { |
15698
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
149 replaceWithTrappingNullCheck(deopt, ifNode, condition, deoptimizationReason); |
13635
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
150 } |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
151 } |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
152 } |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
153 |
15698
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
154 private static void replaceWithTrappingNullCheck(AbstractDeoptimizeNode deopt, IfNode ifNode, LogicNode condition, DeoptimizationReason deoptimizationReason) { |
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
155 metricTrappingNullCheck.increment(); |
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
156 if (deopt instanceof DynamicDeoptimizeNode) { |
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
157 metricTrappingNullCheckDynamicDeoptimize.increment(); |
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
158 } |
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
159 if (deoptimizationReason == DeoptimizationReason.UnreachedCode) { |
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
160 metricTrappingNullCheckUnreached.increment(); |
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
161 } |
13635
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
162 IsNullNode isNullNode = (IsNullNode) condition; |
18993
480bd3b1adcd
Rename BeginNode => AbstractBeginNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18970
diff
changeset
|
163 AbstractBeginNode nonTrappingContinuation = ifNode.falseSuccessor(); |
480bd3b1adcd
Rename BeginNode => AbstractBeginNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18970
diff
changeset
|
164 AbstractBeginNode trappingContinuation = ifNode.trueSuccessor(); |
18845
f57d86eb036f
removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents:
18490
diff
changeset
|
165 NullCheckNode trappingNullCheck = deopt.graph().add(new NullCheckNode(isNullNode.getValue())); |
14734
6ae9af961b7c
Introduce separate interfaces for deoptimizing nodes that deopt to a state before, during or after their execution.
Roland Schatz <roland.schatz@oracle.com>
parents:
13684
diff
changeset
|
166 trappingNullCheck.setStateBefore(deopt.stateBefore()); |
13635
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
167 deopt.graph().replaceSplit(ifNode, trappingNullCheck, nonTrappingContinuation); |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
168 |
15698
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
169 /* |
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
170 * We now have the pattern NullCheck/BeginNode/... It's possible some node is using the |
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
171 * BeginNode as a guard input, so replace guard users of the Begin with the NullCheck and |
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
172 * then remove the Begin from the graph. |
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
173 */ |
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
174 nonTrappingContinuation.replaceAtUsages(InputType.Guard, trappingNullCheck); |
18997
2ccaaf5a6be4
Fix class comparison statements for BeginNode and MergeNode to reflect new class hierarchy.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18995
diff
changeset
|
175 if (nonTrappingContinuation instanceof BeginNode) { |
17054
fb8fe09c00a3
Don't remove LoopExitNodes in UseTrappingNullChecksPhase.
Roland Schatz <roland.schatz@oracle.com>
parents:
16895
diff
changeset
|
176 FixedNode next = nonTrappingContinuation.next(); |
fb8fe09c00a3
Don't remove LoopExitNodes in UseTrappingNullChecksPhase.
Roland Schatz <roland.schatz@oracle.com>
parents:
16895
diff
changeset
|
177 nonTrappingContinuation.clearSuccessors(); |
fb8fe09c00a3
Don't remove LoopExitNodes in UseTrappingNullChecksPhase.
Roland Schatz <roland.schatz@oracle.com>
parents:
16895
diff
changeset
|
178 trappingNullCheck.setNext(next); |
fb8fe09c00a3
Don't remove LoopExitNodes in UseTrappingNullChecksPhase.
Roland Schatz <roland.schatz@oracle.com>
parents:
16895
diff
changeset
|
179 nonTrappingContinuation.safeDelete(); |
fb8fe09c00a3
Don't remove LoopExitNodes in UseTrappingNullChecksPhase.
Roland Schatz <roland.schatz@oracle.com>
parents:
16895
diff
changeset
|
180 } else { |
fb8fe09c00a3
Don't remove LoopExitNodes in UseTrappingNullChecksPhase.
Roland Schatz <roland.schatz@oracle.com>
parents:
16895
diff
changeset
|
181 trappingNullCheck.setNext(nonTrappingContinuation); |
fb8fe09c00a3
Don't remove LoopExitNodes in UseTrappingNullChecksPhase.
Roland Schatz <roland.schatz@oracle.com>
parents:
16895
diff
changeset
|
182 } |
15698
eaeba148bb15
more aggressively fold implicit nulls into memory operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15145
diff
changeset
|
183 |
13635
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
184 GraphUtil.killCFG(trappingContinuation); |
18937
ff232ff8d028
Add utility Node#hasNoUsages.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18845
diff
changeset
|
185 if (isNullNode.hasNoUsages()) { |
13635
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
186 GraphUtil.killWithUnusedFloatingInputs(isNullNode); |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
187 } |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
188 } |
e57115c41164
Make a separate phase to use trapping null checks instead of branches when implicitNullCheckLimit > 0
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
189 } |