annotate src/share/vm/opto/escape.cpp @ 39:76256d272075

6667612: (Escape Analysis) disable loop cloning if it has a scalar replaceable allocation Summary: Cloning an allocation will not allow scalar replacement since memory operations could not be associated with one allocation. Reviewed-by: rasbold
author kvn
date Thu, 06 Mar 2008 10:53:33 -0800
parents b789bcaf2dd9
children 99269dbf4ba8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 #include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 #include "incls/_escape.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 uint PointsToNode::edge_target(uint e) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
29 assert(_edges != NULL && e < (uint)_edges->length(), "valid edge index");
a61af66fc99e Initial load
duke
parents:
diff changeset
30 return (_edges->at(e) >> EdgeShift);
a61af66fc99e Initial load
duke
parents:
diff changeset
31 }
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 PointsToNode::EdgeType PointsToNode::edge_type(uint e) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
34 assert(_edges != NULL && e < (uint)_edges->length(), "valid edge index");
a61af66fc99e Initial load
duke
parents:
diff changeset
35 return (EdgeType) (_edges->at(e) & EdgeMask);
a61af66fc99e Initial load
duke
parents:
diff changeset
36 }
a61af66fc99e Initial load
duke
parents:
diff changeset
37
a61af66fc99e Initial load
duke
parents:
diff changeset
38 void PointsToNode::add_edge(uint targIdx, PointsToNode::EdgeType et) {
a61af66fc99e Initial load
duke
parents:
diff changeset
39 uint v = (targIdx << EdgeShift) + ((uint) et);
a61af66fc99e Initial load
duke
parents:
diff changeset
40 if (_edges == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
41 Arena *a = Compile::current()->comp_arena();
a61af66fc99e Initial load
duke
parents:
diff changeset
42 _edges = new(a) GrowableArray<uint>(a, INITIAL_EDGE_COUNT, 0, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
43 }
a61af66fc99e Initial load
duke
parents:
diff changeset
44 _edges->append_if_missing(v);
a61af66fc99e Initial load
duke
parents:
diff changeset
45 }
a61af66fc99e Initial load
duke
parents:
diff changeset
46
a61af66fc99e Initial load
duke
parents:
diff changeset
47 void PointsToNode::remove_edge(uint targIdx, PointsToNode::EdgeType et) {
a61af66fc99e Initial load
duke
parents:
diff changeset
48 uint v = (targIdx << EdgeShift) + ((uint) et);
a61af66fc99e Initial load
duke
parents:
diff changeset
49
a61af66fc99e Initial load
duke
parents:
diff changeset
50 _edges->remove(v);
a61af66fc99e Initial load
duke
parents:
diff changeset
51 }
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
54 static char *node_type_names[] = {
a61af66fc99e Initial load
duke
parents:
diff changeset
55 "UnknownType",
a61af66fc99e Initial load
duke
parents:
diff changeset
56 "JavaObject",
a61af66fc99e Initial load
duke
parents:
diff changeset
57 "LocalVar",
a61af66fc99e Initial load
duke
parents:
diff changeset
58 "Field"
a61af66fc99e Initial load
duke
parents:
diff changeset
59 };
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61 static char *esc_names[] = {
a61af66fc99e Initial load
duke
parents:
diff changeset
62 "UnknownEscape",
a61af66fc99e Initial load
duke
parents:
diff changeset
63 "NoEscape ",
a61af66fc99e Initial load
duke
parents:
diff changeset
64 "ArgEscape ",
a61af66fc99e Initial load
duke
parents:
diff changeset
65 "GlobalEscape "
a61af66fc99e Initial load
duke
parents:
diff changeset
66 };
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 static char *edge_type_suffix[] = {
a61af66fc99e Initial load
duke
parents:
diff changeset
69 "?", // UnknownEdge
a61af66fc99e Initial load
duke
parents:
diff changeset
70 "P", // PointsToEdge
a61af66fc99e Initial load
duke
parents:
diff changeset
71 "D", // DeferredEdge
a61af66fc99e Initial load
duke
parents:
diff changeset
72 "F" // FieldEdge
a61af66fc99e Initial load
duke
parents:
diff changeset
73 };
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75 void PointsToNode::dump() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
76 NodeType nt = node_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
77 EscapeState es = escape_state();
a61af66fc99e Initial load
duke
parents:
diff changeset
78 tty->print("%s %s [[", node_type_names[(int) nt], esc_names[(int) es]);
a61af66fc99e Initial load
duke
parents:
diff changeset
79 for (uint i = 0; i < edge_count(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
80 tty->print(" %d%s", edge_target(i), edge_type_suffix[(int) edge_type(i)]);
a61af66fc99e Initial load
duke
parents:
diff changeset
81 }
a61af66fc99e Initial load
duke
parents:
diff changeset
82 tty->print("]] ");
a61af66fc99e Initial load
duke
parents:
diff changeset
83 if (_node == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
84 tty->print_cr("<null>");
a61af66fc99e Initial load
duke
parents:
diff changeset
85 else
a61af66fc99e Initial load
duke
parents:
diff changeset
86 _node->dump();
a61af66fc99e Initial load
duke
parents:
diff changeset
87 }
a61af66fc99e Initial load
duke
parents:
diff changeset
88 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 ConnectionGraph::ConnectionGraph(Compile * C) : _processed(C->comp_arena()), _node_map(C->comp_arena()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 _collecting = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
92 this->_compile = C;
a61af66fc99e Initial load
duke
parents:
diff changeset
93 const PointsToNode &dummy = PointsToNode();
a61af66fc99e Initial load
duke
parents:
diff changeset
94 _nodes = new(C->comp_arena()) GrowableArray<PointsToNode>(C->comp_arena(), (int) INITIAL_NODE_COUNT, 0, dummy);
a61af66fc99e Initial load
duke
parents:
diff changeset
95 _phantom_object = C->top()->_idx;
a61af66fc99e Initial load
duke
parents:
diff changeset
96 PointsToNode *phn = ptnode_adr(_phantom_object);
a61af66fc99e Initial load
duke
parents:
diff changeset
97 phn->set_node_type(PointsToNode::JavaObject);
a61af66fc99e Initial load
duke
parents:
diff changeset
98 phn->set_escape_state(PointsToNode::GlobalEscape);
a61af66fc99e Initial load
duke
parents:
diff changeset
99 }
a61af66fc99e Initial load
duke
parents:
diff changeset
100
a61af66fc99e Initial load
duke
parents:
diff changeset
101 void ConnectionGraph::add_pointsto_edge(uint from_i, uint to_i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 PointsToNode *f = ptnode_adr(from_i);
a61af66fc99e Initial load
duke
parents:
diff changeset
103 PointsToNode *t = ptnode_adr(to_i);
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 assert(f->node_type() != PointsToNode::UnknownType && t->node_type() != PointsToNode::UnknownType, "node types must be set");
a61af66fc99e Initial load
duke
parents:
diff changeset
106 assert(f->node_type() == PointsToNode::LocalVar || f->node_type() == PointsToNode::Field, "invalid source of PointsTo edge");
a61af66fc99e Initial load
duke
parents:
diff changeset
107 assert(t->node_type() == PointsToNode::JavaObject, "invalid destination of PointsTo edge");
a61af66fc99e Initial load
duke
parents:
diff changeset
108 f->add_edge(to_i, PointsToNode::PointsToEdge);
a61af66fc99e Initial load
duke
parents:
diff changeset
109 }
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 void ConnectionGraph::add_deferred_edge(uint from_i, uint to_i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 PointsToNode *f = ptnode_adr(from_i);
a61af66fc99e Initial load
duke
parents:
diff changeset
113 PointsToNode *t = ptnode_adr(to_i);
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 assert(f->node_type() != PointsToNode::UnknownType && t->node_type() != PointsToNode::UnknownType, "node types must be set");
a61af66fc99e Initial load
duke
parents:
diff changeset
116 assert(f->node_type() == PointsToNode::LocalVar || f->node_type() == PointsToNode::Field, "invalid source of Deferred edge");
a61af66fc99e Initial load
duke
parents:
diff changeset
117 assert(t->node_type() == PointsToNode::LocalVar || t->node_type() == PointsToNode::Field, "invalid destination of Deferred edge");
a61af66fc99e Initial load
duke
parents:
diff changeset
118 // don't add a self-referential edge, this can occur during removal of
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // deferred edges
a61af66fc99e Initial load
duke
parents:
diff changeset
120 if (from_i != to_i)
a61af66fc99e Initial load
duke
parents:
diff changeset
121 f->add_edge(to_i, PointsToNode::DeferredEdge);
a61af66fc99e Initial load
duke
parents:
diff changeset
122 }
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 int ConnectionGraph::type_to_offset(const Type *t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 const TypePtr *t_ptr = t->isa_ptr();
a61af66fc99e Initial load
duke
parents:
diff changeset
126 assert(t_ptr != NULL, "must be a pointer type");
a61af66fc99e Initial load
duke
parents:
diff changeset
127 return t_ptr->offset();
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129
a61af66fc99e Initial load
duke
parents:
diff changeset
130 void ConnectionGraph::add_field_edge(uint from_i, uint to_i, int offset) {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 PointsToNode *f = ptnode_adr(from_i);
a61af66fc99e Initial load
duke
parents:
diff changeset
132 PointsToNode *t = ptnode_adr(to_i);
a61af66fc99e Initial load
duke
parents:
diff changeset
133
a61af66fc99e Initial load
duke
parents:
diff changeset
134 assert(f->node_type() != PointsToNode::UnknownType && t->node_type() != PointsToNode::UnknownType, "node types must be set");
a61af66fc99e Initial load
duke
parents:
diff changeset
135 assert(f->node_type() == PointsToNode::JavaObject, "invalid destination of Field edge");
a61af66fc99e Initial load
duke
parents:
diff changeset
136 assert(t->node_type() == PointsToNode::Field, "invalid destination of Field edge");
a61af66fc99e Initial load
duke
parents:
diff changeset
137 assert (t->offset() == -1 || t->offset() == offset, "conflicting field offsets");
a61af66fc99e Initial load
duke
parents:
diff changeset
138 t->set_offset(offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
139
a61af66fc99e Initial load
duke
parents:
diff changeset
140 f->add_edge(to_i, PointsToNode::FieldEdge);
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 void ConnectionGraph::set_escape_state(uint ni, PointsToNode::EscapeState es) {
a61af66fc99e Initial load
duke
parents:
diff changeset
144 PointsToNode *npt = ptnode_adr(ni);
a61af66fc99e Initial load
duke
parents:
diff changeset
145 PointsToNode::EscapeState old_es = npt->escape_state();
a61af66fc99e Initial load
duke
parents:
diff changeset
146 if (es > old_es)
a61af66fc99e Initial load
duke
parents:
diff changeset
147 npt->set_escape_state(es);
a61af66fc99e Initial load
duke
parents:
diff changeset
148 }
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 PointsToNode::EscapeState ConnectionGraph::escape_state(Node *n, PhaseTransform *phase) {
a61af66fc99e Initial load
duke
parents:
diff changeset
151 uint idx = n->_idx;
a61af66fc99e Initial load
duke
parents:
diff changeset
152 PointsToNode::EscapeState es;
a61af66fc99e Initial load
duke
parents:
diff changeset
153
a61af66fc99e Initial load
duke
parents:
diff changeset
154 // If we are still collecting we don't know the answer yet
a61af66fc99e Initial load
duke
parents:
diff changeset
155 if (_collecting)
a61af66fc99e Initial load
duke
parents:
diff changeset
156 return PointsToNode::UnknownEscape;
a61af66fc99e Initial load
duke
parents:
diff changeset
157
a61af66fc99e Initial load
duke
parents:
diff changeset
158 // if the node was created after the escape computation, return
a61af66fc99e Initial load
duke
parents:
diff changeset
159 // UnknownEscape
a61af66fc99e Initial load
duke
parents:
diff changeset
160 if (idx >= (uint)_nodes->length())
a61af66fc99e Initial load
duke
parents:
diff changeset
161 return PointsToNode::UnknownEscape;
a61af66fc99e Initial load
duke
parents:
diff changeset
162
a61af66fc99e Initial load
duke
parents:
diff changeset
163 es = _nodes->at_grow(idx).escape_state();
a61af66fc99e Initial load
duke
parents:
diff changeset
164
a61af66fc99e Initial load
duke
parents:
diff changeset
165 // if we have already computed a value, return it
a61af66fc99e Initial load
duke
parents:
diff changeset
166 if (es != PointsToNode::UnknownEscape)
a61af66fc99e Initial load
duke
parents:
diff changeset
167 return es;
a61af66fc99e Initial load
duke
parents:
diff changeset
168
a61af66fc99e Initial load
duke
parents:
diff changeset
169 // compute max escape state of anything this node could point to
a61af66fc99e Initial load
duke
parents:
diff changeset
170 VectorSet ptset(Thread::current()->resource_area());
a61af66fc99e Initial load
duke
parents:
diff changeset
171 PointsTo(ptset, n, phase);
a61af66fc99e Initial load
duke
parents:
diff changeset
172 for( VectorSetI i(&ptset); i.test() && es != PointsToNode::GlobalEscape; ++i ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
173 uint pt = i.elem;
a61af66fc99e Initial load
duke
parents:
diff changeset
174 PointsToNode::EscapeState pes = _nodes->at(pt).escape_state();
a61af66fc99e Initial load
duke
parents:
diff changeset
175 if (pes > es)
a61af66fc99e Initial load
duke
parents:
diff changeset
176 es = pes;
a61af66fc99e Initial load
duke
parents:
diff changeset
177 }
a61af66fc99e Initial load
duke
parents:
diff changeset
178 // cache the computed escape state
a61af66fc99e Initial load
duke
parents:
diff changeset
179 assert(es != PointsToNode::UnknownEscape, "should have computed an escape state");
a61af66fc99e Initial load
duke
parents:
diff changeset
180 _nodes->adr_at(idx)->set_escape_state(es);
a61af66fc99e Initial load
duke
parents:
diff changeset
181 return es;
a61af66fc99e Initial load
duke
parents:
diff changeset
182 }
a61af66fc99e Initial load
duke
parents:
diff changeset
183
a61af66fc99e Initial load
duke
parents:
diff changeset
184 void ConnectionGraph::PointsTo(VectorSet &ptset, Node * n, PhaseTransform *phase) {
a61af66fc99e Initial load
duke
parents:
diff changeset
185 VectorSet visited(Thread::current()->resource_area());
a61af66fc99e Initial load
duke
parents:
diff changeset
186 GrowableArray<uint> worklist;
a61af66fc99e Initial load
duke
parents:
diff changeset
187
a61af66fc99e Initial load
duke
parents:
diff changeset
188 n = skip_casts(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
189 PointsToNode npt = _nodes->at_grow(n->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
190
a61af66fc99e Initial load
duke
parents:
diff changeset
191 // If we have a JavaObject, return just that object
a61af66fc99e Initial load
duke
parents:
diff changeset
192 if (npt.node_type() == PointsToNode::JavaObject) {
a61af66fc99e Initial load
duke
parents:
diff changeset
193 ptset.set(n->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
194 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
195 }
a61af66fc99e Initial load
duke
parents:
diff changeset
196 // we may have a Phi which has not been processed
a61af66fc99e Initial load
duke
parents:
diff changeset
197 if (npt._node == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
198 assert(n->is_Phi(), "unprocessed node must be a Phi");
a61af66fc99e Initial load
duke
parents:
diff changeset
199 record_for_escape_analysis(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
200 npt = _nodes->at(n->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
201 }
a61af66fc99e Initial load
duke
parents:
diff changeset
202 worklist.push(n->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
203 while(worklist.length() > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
204 int ni = worklist.pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
205 PointsToNode pn = _nodes->at_grow(ni);
a61af66fc99e Initial load
duke
parents:
diff changeset
206 if (!visited.test(ni)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
207 visited.set(ni);
a61af66fc99e Initial load
duke
parents:
diff changeset
208
a61af66fc99e Initial load
duke
parents:
diff changeset
209 // ensure that all inputs of a Phi have been processed
a61af66fc99e Initial load
duke
parents:
diff changeset
210 if (_collecting && pn._node->is_Phi()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
211 PhiNode *phi = pn._node->as_Phi();
a61af66fc99e Initial load
duke
parents:
diff changeset
212 process_phi_escape(phi, phase);
a61af66fc99e Initial load
duke
parents:
diff changeset
213 }
a61af66fc99e Initial load
duke
parents:
diff changeset
214
a61af66fc99e Initial load
duke
parents:
diff changeset
215 int edges_processed = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
216 for (uint e = 0; e < pn.edge_count(); e++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
217 PointsToNode::EdgeType et = pn.edge_type(e);
a61af66fc99e Initial load
duke
parents:
diff changeset
218 if (et == PointsToNode::PointsToEdge) {
a61af66fc99e Initial load
duke
parents:
diff changeset
219 ptset.set(pn.edge_target(e));
a61af66fc99e Initial load
duke
parents:
diff changeset
220 edges_processed++;
a61af66fc99e Initial load
duke
parents:
diff changeset
221 } else if (et == PointsToNode::DeferredEdge) {
a61af66fc99e Initial load
duke
parents:
diff changeset
222 worklist.push(pn.edge_target(e));
a61af66fc99e Initial load
duke
parents:
diff changeset
223 edges_processed++;
a61af66fc99e Initial load
duke
parents:
diff changeset
224 }
a61af66fc99e Initial load
duke
parents:
diff changeset
225 }
a61af66fc99e Initial load
duke
parents:
diff changeset
226 if (edges_processed == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
227 // no deferred or pointsto edges found. Assume the value was set outside
a61af66fc99e Initial load
duke
parents:
diff changeset
228 // this method. Add the phantom object to the pointsto set.
a61af66fc99e Initial load
duke
parents:
diff changeset
229 ptset.set(_phantom_object);
a61af66fc99e Initial load
duke
parents:
diff changeset
230 }
a61af66fc99e Initial load
duke
parents:
diff changeset
231 }
a61af66fc99e Initial load
duke
parents:
diff changeset
232 }
a61af66fc99e Initial load
duke
parents:
diff changeset
233 }
a61af66fc99e Initial load
duke
parents:
diff changeset
234
a61af66fc99e Initial load
duke
parents:
diff changeset
235 void ConnectionGraph::remove_deferred(uint ni) {
a61af66fc99e Initial load
duke
parents:
diff changeset
236 VectorSet visited(Thread::current()->resource_area());
a61af66fc99e Initial load
duke
parents:
diff changeset
237
a61af66fc99e Initial load
duke
parents:
diff changeset
238 uint i = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
239 PointsToNode *ptn = ptnode_adr(ni);
a61af66fc99e Initial load
duke
parents:
diff changeset
240
a61af66fc99e Initial load
duke
parents:
diff changeset
241 while(i < ptn->edge_count()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
242 if (ptn->edge_type(i) != PointsToNode::DeferredEdge) {
a61af66fc99e Initial load
duke
parents:
diff changeset
243 i++;
a61af66fc99e Initial load
duke
parents:
diff changeset
244 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
245 uint t = ptn->edge_target(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
246 PointsToNode *ptt = ptnode_adr(t);
a61af66fc99e Initial load
duke
parents:
diff changeset
247 ptn->remove_edge(t, PointsToNode::DeferredEdge);
a61af66fc99e Initial load
duke
parents:
diff changeset
248 if(!visited.test(t)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
249 visited.set(t);
a61af66fc99e Initial load
duke
parents:
diff changeset
250 for (uint j = 0; j < ptt->edge_count(); j++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
251 uint n1 = ptt->edge_target(j);
a61af66fc99e Initial load
duke
parents:
diff changeset
252 PointsToNode *pt1 = ptnode_adr(n1);
a61af66fc99e Initial load
duke
parents:
diff changeset
253 switch(ptt->edge_type(j)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
254 case PointsToNode::PointsToEdge:
a61af66fc99e Initial load
duke
parents:
diff changeset
255 add_pointsto_edge(ni, n1);
a61af66fc99e Initial load
duke
parents:
diff changeset
256 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
257 case PointsToNode::DeferredEdge:
a61af66fc99e Initial load
duke
parents:
diff changeset
258 add_deferred_edge(ni, n1);
a61af66fc99e Initial load
duke
parents:
diff changeset
259 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
260 case PointsToNode::FieldEdge:
a61af66fc99e Initial load
duke
parents:
diff changeset
261 assert(false, "invalid connection graph");
a61af66fc99e Initial load
duke
parents:
diff changeset
262 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
263 }
a61af66fc99e Initial load
duke
parents:
diff changeset
264 }
a61af66fc99e Initial load
duke
parents:
diff changeset
265 }
a61af66fc99e Initial load
duke
parents:
diff changeset
266 }
a61af66fc99e Initial load
duke
parents:
diff changeset
267 }
a61af66fc99e Initial load
duke
parents:
diff changeset
268 }
a61af66fc99e Initial load
duke
parents:
diff changeset
269
a61af66fc99e Initial load
duke
parents:
diff changeset
270
a61af66fc99e Initial load
duke
parents:
diff changeset
271 // Add an edge to node given by "to_i" from any field of adr_i whose offset
a61af66fc99e Initial load
duke
parents:
diff changeset
272 // matches "offset" A deferred edge is added if to_i is a LocalVar, and
a61af66fc99e Initial load
duke
parents:
diff changeset
273 // a pointsto edge is added if it is a JavaObject
a61af66fc99e Initial load
duke
parents:
diff changeset
274
a61af66fc99e Initial load
duke
parents:
diff changeset
275 void ConnectionGraph::add_edge_from_fields(uint adr_i, uint to_i, int offs) {
a61af66fc99e Initial load
duke
parents:
diff changeset
276 PointsToNode an = _nodes->at_grow(adr_i);
a61af66fc99e Initial load
duke
parents:
diff changeset
277 PointsToNode to = _nodes->at_grow(to_i);
a61af66fc99e Initial load
duke
parents:
diff changeset
278 bool deferred = (to.node_type() == PointsToNode::LocalVar);
a61af66fc99e Initial load
duke
parents:
diff changeset
279
a61af66fc99e Initial load
duke
parents:
diff changeset
280 for (uint fe = 0; fe < an.edge_count(); fe++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
281 assert(an.edge_type(fe) == PointsToNode::FieldEdge, "expecting a field edge");
a61af66fc99e Initial load
duke
parents:
diff changeset
282 int fi = an.edge_target(fe);
a61af66fc99e Initial load
duke
parents:
diff changeset
283 PointsToNode pf = _nodes->at_grow(fi);
a61af66fc99e Initial load
duke
parents:
diff changeset
284 int po = pf.offset();
a61af66fc99e Initial load
duke
parents:
diff changeset
285 if (po == offs || po == Type::OffsetBot || offs == Type::OffsetBot) {
a61af66fc99e Initial load
duke
parents:
diff changeset
286 if (deferred)
a61af66fc99e Initial load
duke
parents:
diff changeset
287 add_deferred_edge(fi, to_i);
a61af66fc99e Initial load
duke
parents:
diff changeset
288 else
a61af66fc99e Initial load
duke
parents:
diff changeset
289 add_pointsto_edge(fi, to_i);
a61af66fc99e Initial load
duke
parents:
diff changeset
290 }
a61af66fc99e Initial load
duke
parents:
diff changeset
291 }
a61af66fc99e Initial load
duke
parents:
diff changeset
292 }
a61af66fc99e Initial load
duke
parents:
diff changeset
293
a61af66fc99e Initial load
duke
parents:
diff changeset
294 // Add a deferred edge from node given by "from_i" to any field of adr_i whose offset
a61af66fc99e Initial load
duke
parents:
diff changeset
295 // matches "offset"
a61af66fc99e Initial load
duke
parents:
diff changeset
296 void ConnectionGraph::add_deferred_edge_to_fields(uint from_i, uint adr_i, int offs) {
a61af66fc99e Initial load
duke
parents:
diff changeset
297 PointsToNode an = _nodes->at_grow(adr_i);
a61af66fc99e Initial load
duke
parents:
diff changeset
298 for (uint fe = 0; fe < an.edge_count(); fe++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
299 assert(an.edge_type(fe) == PointsToNode::FieldEdge, "expecting a field edge");
a61af66fc99e Initial load
duke
parents:
diff changeset
300 int fi = an.edge_target(fe);
a61af66fc99e Initial load
duke
parents:
diff changeset
301 PointsToNode pf = _nodes->at_grow(fi);
a61af66fc99e Initial load
duke
parents:
diff changeset
302 int po = pf.offset();
a61af66fc99e Initial load
duke
parents:
diff changeset
303 if (pf.edge_count() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
304 // we have not seen any stores to this field, assume it was set outside this method
a61af66fc99e Initial load
duke
parents:
diff changeset
305 add_pointsto_edge(fi, _phantom_object);
a61af66fc99e Initial load
duke
parents:
diff changeset
306 }
a61af66fc99e Initial load
duke
parents:
diff changeset
307 if (po == offs || po == Type::OffsetBot || offs == Type::OffsetBot) {
a61af66fc99e Initial load
duke
parents:
diff changeset
308 add_deferred_edge(from_i, fi);
a61af66fc99e Initial load
duke
parents:
diff changeset
309 }
a61af66fc99e Initial load
duke
parents:
diff changeset
310 }
a61af66fc99e Initial load
duke
parents:
diff changeset
311 }
a61af66fc99e Initial load
duke
parents:
diff changeset
312
a61af66fc99e Initial load
duke
parents:
diff changeset
313 //
a61af66fc99e Initial load
duke
parents:
diff changeset
314 // Search memory chain of "mem" to find a MemNode whose address
a61af66fc99e Initial load
duke
parents:
diff changeset
315 // is the specified alias index. Returns the MemNode found or the
a61af66fc99e Initial load
duke
parents:
diff changeset
316 // first non-MemNode encountered.
a61af66fc99e Initial load
duke
parents:
diff changeset
317 //
a61af66fc99e Initial load
duke
parents:
diff changeset
318 Node *ConnectionGraph::find_mem(Node *mem, int alias_idx, PhaseGVN *igvn) {
a61af66fc99e Initial load
duke
parents:
diff changeset
319 if (mem == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
320 return mem;
a61af66fc99e Initial load
duke
parents:
diff changeset
321 while (mem->is_Mem()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
322 const Type *at = igvn->type(mem->in(MemNode::Address));
a61af66fc99e Initial load
duke
parents:
diff changeset
323 if (at != Type::TOP) {
a61af66fc99e Initial load
duke
parents:
diff changeset
324 assert (at->isa_ptr() != NULL, "pointer type required.");
a61af66fc99e Initial load
duke
parents:
diff changeset
325 int idx = _compile->get_alias_index(at->is_ptr());
a61af66fc99e Initial load
duke
parents:
diff changeset
326 if (idx == alias_idx)
a61af66fc99e Initial load
duke
parents:
diff changeset
327 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
328 }
a61af66fc99e Initial load
duke
parents:
diff changeset
329 mem = mem->in(MemNode::Memory);
a61af66fc99e Initial load
duke
parents:
diff changeset
330 }
a61af66fc99e Initial load
duke
parents:
diff changeset
331 return mem;
a61af66fc99e Initial load
duke
parents:
diff changeset
332 }
a61af66fc99e Initial load
duke
parents:
diff changeset
333
a61af66fc99e Initial load
duke
parents:
diff changeset
334 //
a61af66fc99e Initial load
duke
parents:
diff changeset
335 // Adjust the type and inputs of an AddP which computes the
a61af66fc99e Initial load
duke
parents:
diff changeset
336 // address of a field of an instance
a61af66fc99e Initial load
duke
parents:
diff changeset
337 //
a61af66fc99e Initial load
duke
parents:
diff changeset
338 void ConnectionGraph::split_AddP(Node *addp, Node *base, PhaseGVN *igvn) {
a61af66fc99e Initial load
duke
parents:
diff changeset
339 const TypeOopPtr *t = igvn->type(addp)->isa_oopptr();
a61af66fc99e Initial load
duke
parents:
diff changeset
340 const TypeOopPtr *base_t = igvn->type(base)->isa_oopptr();
a61af66fc99e Initial load
duke
parents:
diff changeset
341 assert(t != NULL, "expecting oopptr");
a61af66fc99e Initial load
duke
parents:
diff changeset
342 assert(base_t != NULL && base_t->is_instance(), "expecting instance oopptr");
a61af66fc99e Initial load
duke
parents:
diff changeset
343 uint inst_id = base_t->instance_id();
a61af66fc99e Initial load
duke
parents:
diff changeset
344 assert(!t->is_instance() || t->instance_id() == inst_id,
a61af66fc99e Initial load
duke
parents:
diff changeset
345 "old type must be non-instance or match new type");
a61af66fc99e Initial load
duke
parents:
diff changeset
346 const TypeOopPtr *tinst = base_t->add_offset(t->offset())->is_oopptr();
a61af66fc99e Initial load
duke
parents:
diff changeset
347 // ensure an alias index is allocated for the instance type
a61af66fc99e Initial load
duke
parents:
diff changeset
348 int alias_idx = _compile->get_alias_index(tinst);
a61af66fc99e Initial load
duke
parents:
diff changeset
349 igvn->set_type(addp, tinst);
a61af66fc99e Initial load
duke
parents:
diff changeset
350 // record the allocation in the node map
a61af66fc99e Initial load
duke
parents:
diff changeset
351 set_map(addp->_idx, get_map(base->_idx));
a61af66fc99e Initial load
duke
parents:
diff changeset
352 // if the Address input is not the appropriate instance type (due to intervening
a61af66fc99e Initial load
duke
parents:
diff changeset
353 // casts,) insert a cast
a61af66fc99e Initial load
duke
parents:
diff changeset
354 Node *adr = addp->in(AddPNode::Address);
a61af66fc99e Initial load
duke
parents:
diff changeset
355 const TypeOopPtr *atype = igvn->type(adr)->isa_oopptr();
a61af66fc99e Initial load
duke
parents:
diff changeset
356 if (atype->instance_id() != inst_id) {
a61af66fc99e Initial load
duke
parents:
diff changeset
357 assert(!atype->is_instance(), "no conflicting instances");
a61af66fc99e Initial load
duke
parents:
diff changeset
358 const TypeOopPtr *new_atype = base_t->add_offset(atype->offset())->isa_oopptr();
a61af66fc99e Initial load
duke
parents:
diff changeset
359 Node *acast = new (_compile, 2) CastPPNode(adr, new_atype);
a61af66fc99e Initial load
duke
parents:
diff changeset
360 acast->set_req(0, adr->in(0));
a61af66fc99e Initial load
duke
parents:
diff changeset
361 igvn->set_type(acast, new_atype);
a61af66fc99e Initial load
duke
parents:
diff changeset
362 record_for_optimizer(acast);
a61af66fc99e Initial load
duke
parents:
diff changeset
363 Node *bcast = acast;
a61af66fc99e Initial load
duke
parents:
diff changeset
364 Node *abase = addp->in(AddPNode::Base);
a61af66fc99e Initial load
duke
parents:
diff changeset
365 if (abase != adr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
366 bcast = new (_compile, 2) CastPPNode(abase, base_t);
a61af66fc99e Initial load
duke
parents:
diff changeset
367 bcast->set_req(0, abase->in(0));
a61af66fc99e Initial load
duke
parents:
diff changeset
368 igvn->set_type(bcast, base_t);
a61af66fc99e Initial load
duke
parents:
diff changeset
369 record_for_optimizer(bcast);
a61af66fc99e Initial load
duke
parents:
diff changeset
370 }
a61af66fc99e Initial load
duke
parents:
diff changeset
371 igvn->hash_delete(addp);
a61af66fc99e Initial load
duke
parents:
diff changeset
372 addp->set_req(AddPNode::Base, bcast);
a61af66fc99e Initial load
duke
parents:
diff changeset
373 addp->set_req(AddPNode::Address, acast);
a61af66fc99e Initial load
duke
parents:
diff changeset
374 igvn->hash_insert(addp);
a61af66fc99e Initial load
duke
parents:
diff changeset
375 record_for_optimizer(addp);
a61af66fc99e Initial load
duke
parents:
diff changeset
376 }
a61af66fc99e Initial load
duke
parents:
diff changeset
377 }
a61af66fc99e Initial load
duke
parents:
diff changeset
378
a61af66fc99e Initial load
duke
parents:
diff changeset
379 //
a61af66fc99e Initial load
duke
parents:
diff changeset
380 // Create a new version of orig_phi if necessary. Returns either the newly
a61af66fc99e Initial load
duke
parents:
diff changeset
381 // created phi or an existing phi. Sets create_new to indicate wheter a new
a61af66fc99e Initial load
duke
parents:
diff changeset
382 // phi was created. Cache the last newly created phi in the node map.
a61af66fc99e Initial load
duke
parents:
diff changeset
383 //
a61af66fc99e Initial load
duke
parents:
diff changeset
384 PhiNode *ConnectionGraph::create_split_phi(PhiNode *orig_phi, int alias_idx, GrowableArray<PhiNode *> &orig_phi_worklist, PhaseGVN *igvn, bool &new_created) {
a61af66fc99e Initial load
duke
parents:
diff changeset
385 Compile *C = _compile;
a61af66fc99e Initial load
duke
parents:
diff changeset
386 new_created = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
387 int phi_alias_idx = C->get_alias_index(orig_phi->adr_type());
a61af66fc99e Initial load
duke
parents:
diff changeset
388 // nothing to do if orig_phi is bottom memory or matches alias_idx
a61af66fc99e Initial load
duke
parents:
diff changeset
389 if (phi_alias_idx == Compile::AliasIdxBot || phi_alias_idx == alias_idx) {
a61af66fc99e Initial load
duke
parents:
diff changeset
390 return orig_phi;
a61af66fc99e Initial load
duke
parents:
diff changeset
391 }
a61af66fc99e Initial load
duke
parents:
diff changeset
392 // have we already created a Phi for this alias index?
a61af66fc99e Initial load
duke
parents:
diff changeset
393 PhiNode *result = get_map_phi(orig_phi->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
394 const TypePtr *atype = C->get_adr_type(alias_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
395 if (result != NULL && C->get_alias_index(result->adr_type()) == alias_idx) {
a61af66fc99e Initial load
duke
parents:
diff changeset
396 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
397 }
38
b789bcaf2dd9 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 0
diff changeset
398 if ((int)C->unique() + 2*NodeLimitFudgeFactor > MaxNodeLimit) {
b789bcaf2dd9 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 0
diff changeset
399 if (C->do_escape_analysis() == true && !C->failing()) {
b789bcaf2dd9 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 0
diff changeset
400 // Retry compilation without escape analysis.
b789bcaf2dd9 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 0
diff changeset
401 // If this is the first failure, the sentinel string will "stick"
b789bcaf2dd9 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 0
diff changeset
402 // to the Compile object, and the C2Compiler will see it and retry.
b789bcaf2dd9 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 0
diff changeset
403 C->record_failure(C2Compiler::retry_no_escape_analysis());
b789bcaf2dd9 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 0
diff changeset
404 }
b789bcaf2dd9 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 0
diff changeset
405 return NULL;
b789bcaf2dd9 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 0
diff changeset
406 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
407
a61af66fc99e Initial load
duke
parents:
diff changeset
408 orig_phi_worklist.append_if_missing(orig_phi);
a61af66fc99e Initial load
duke
parents:
diff changeset
409 result = PhiNode::make(orig_phi->in(0), NULL, Type::MEMORY, atype);
a61af66fc99e Initial load
duke
parents:
diff changeset
410 set_map_phi(orig_phi->_idx, result);
a61af66fc99e Initial load
duke
parents:
diff changeset
411 igvn->set_type(result, result->bottom_type());
a61af66fc99e Initial load
duke
parents:
diff changeset
412 record_for_optimizer(result);
a61af66fc99e Initial load
duke
parents:
diff changeset
413 new_created = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
414 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
415 }
a61af66fc99e Initial load
duke
parents:
diff changeset
416
a61af66fc99e Initial load
duke
parents:
diff changeset
417 //
a61af66fc99e Initial load
duke
parents:
diff changeset
418 // Return a new version of Memory Phi "orig_phi" with the inputs having the
a61af66fc99e Initial load
duke
parents:
diff changeset
419 // specified alias index.
a61af66fc99e Initial load
duke
parents:
diff changeset
420 //
a61af66fc99e Initial load
duke
parents:
diff changeset
421 PhiNode *ConnectionGraph::split_memory_phi(PhiNode *orig_phi, int alias_idx, GrowableArray<PhiNode *> &orig_phi_worklist, PhaseGVN *igvn) {
a61af66fc99e Initial load
duke
parents:
diff changeset
422
a61af66fc99e Initial load
duke
parents:
diff changeset
423 assert(alias_idx != Compile::AliasIdxBot, "can't split out bottom memory");
a61af66fc99e Initial load
duke
parents:
diff changeset
424 Compile *C = _compile;
a61af66fc99e Initial load
duke
parents:
diff changeset
425 bool new_phi_created;
a61af66fc99e Initial load
duke
parents:
diff changeset
426 PhiNode *result = create_split_phi(orig_phi, alias_idx, orig_phi_worklist, igvn, new_phi_created);
a61af66fc99e Initial load
duke
parents:
diff changeset
427 if (!new_phi_created) {
a61af66fc99e Initial load
duke
parents:
diff changeset
428 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
429 }
a61af66fc99e Initial load
duke
parents:
diff changeset
430
a61af66fc99e Initial load
duke
parents:
diff changeset
431 GrowableArray<PhiNode *> phi_list;
a61af66fc99e Initial load
duke
parents:
diff changeset
432 GrowableArray<uint> cur_input;
a61af66fc99e Initial load
duke
parents:
diff changeset
433
a61af66fc99e Initial load
duke
parents:
diff changeset
434 PhiNode *phi = orig_phi;
a61af66fc99e Initial load
duke
parents:
diff changeset
435 uint idx = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
436 bool finished = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
437 while(!finished) {
a61af66fc99e Initial load
duke
parents:
diff changeset
438 while (idx < phi->req()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
439 Node *mem = find_mem(phi->in(idx), alias_idx, igvn);
a61af66fc99e Initial load
duke
parents:
diff changeset
440 if (mem != NULL && mem->is_Phi()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
441 PhiNode *nphi = create_split_phi(mem->as_Phi(), alias_idx, orig_phi_worklist, igvn, new_phi_created);
a61af66fc99e Initial load
duke
parents:
diff changeset
442 if (new_phi_created) {
a61af66fc99e Initial load
duke
parents:
diff changeset
443 // found an phi for which we created a new split, push current one on worklist and begin
a61af66fc99e Initial load
duke
parents:
diff changeset
444 // processing new one
a61af66fc99e Initial load
duke
parents:
diff changeset
445 phi_list.push(phi);
a61af66fc99e Initial load
duke
parents:
diff changeset
446 cur_input.push(idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
447 phi = mem->as_Phi();
a61af66fc99e Initial load
duke
parents:
diff changeset
448 result = nphi;
a61af66fc99e Initial load
duke
parents:
diff changeset
449 idx = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
450 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
451 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
452 mem = nphi;
a61af66fc99e Initial load
duke
parents:
diff changeset
453 }
a61af66fc99e Initial load
duke
parents:
diff changeset
454 }
38
b789bcaf2dd9 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 0
diff changeset
455 if (C->failing()) {
b789bcaf2dd9 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 0
diff changeset
456 return NULL;
b789bcaf2dd9 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 0
diff changeset
457 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
458 result->set_req(idx++, mem);
a61af66fc99e Initial load
duke
parents:
diff changeset
459 }
a61af66fc99e Initial load
duke
parents:
diff changeset
460 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
461 // verify that the new Phi has an input for each input of the original
a61af66fc99e Initial load
duke
parents:
diff changeset
462 assert( phi->req() == result->req(), "must have same number of inputs.");
a61af66fc99e Initial load
duke
parents:
diff changeset
463 assert( result->in(0) != NULL && result->in(0) == phi->in(0), "regions must match");
a61af66fc99e Initial load
duke
parents:
diff changeset
464 for (uint i = 1; i < phi->req(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
465 assert((phi->in(i) == NULL) == (result->in(i) == NULL), "inputs must correspond.");
a61af66fc99e Initial load
duke
parents:
diff changeset
466 }
a61af66fc99e Initial load
duke
parents:
diff changeset
467 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
468 // we have finished processing a Phi, see if there are any more to do
a61af66fc99e Initial load
duke
parents:
diff changeset
469 finished = (phi_list.length() == 0 );
a61af66fc99e Initial load
duke
parents:
diff changeset
470 if (!finished) {
a61af66fc99e Initial load
duke
parents:
diff changeset
471 phi = phi_list.pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
472 idx = cur_input.pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
473 PhiNode *prev_phi = get_map_phi(phi->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
474 prev_phi->set_req(idx++, result);
a61af66fc99e Initial load
duke
parents:
diff changeset
475 result = prev_phi;
a61af66fc99e Initial load
duke
parents:
diff changeset
476 }
a61af66fc99e Initial load
duke
parents:
diff changeset
477 }
a61af66fc99e Initial load
duke
parents:
diff changeset
478 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
479 }
a61af66fc99e Initial load
duke
parents:
diff changeset
480
a61af66fc99e Initial load
duke
parents:
diff changeset
481 //
a61af66fc99e Initial load
duke
parents:
diff changeset
482 // Convert the types of unescaped object to instance types where possible,
a61af66fc99e Initial load
duke
parents:
diff changeset
483 // propagate the new type information through the graph, and update memory
a61af66fc99e Initial load
duke
parents:
diff changeset
484 // edges and MergeMem inputs to reflect the new type.
a61af66fc99e Initial load
duke
parents:
diff changeset
485 //
a61af66fc99e Initial load
duke
parents:
diff changeset
486 // We start with allocations (and calls which may be allocations) on alloc_worklist.
a61af66fc99e Initial load
duke
parents:
diff changeset
487 // The processing is done in 4 phases:
a61af66fc99e Initial load
duke
parents:
diff changeset
488 //
a61af66fc99e Initial load
duke
parents:
diff changeset
489 // Phase 1: Process possible allocations from alloc_worklist. Create instance
a61af66fc99e Initial load
duke
parents:
diff changeset
490 // types for the CheckCastPP for allocations where possible.
a61af66fc99e Initial load
duke
parents:
diff changeset
491 // Propagate the the new types through users as follows:
a61af66fc99e Initial load
duke
parents:
diff changeset
492 // casts and Phi: push users on alloc_worklist
a61af66fc99e Initial load
duke
parents:
diff changeset
493 // AddP: cast Base and Address inputs to the instance type
a61af66fc99e Initial load
duke
parents:
diff changeset
494 // push any AddP users on alloc_worklist and push any memnode
a61af66fc99e Initial load
duke
parents:
diff changeset
495 // users onto memnode_worklist.
a61af66fc99e Initial load
duke
parents:
diff changeset
496 // Phase 2: Process MemNode's from memnode_worklist. compute new address type and
a61af66fc99e Initial load
duke
parents:
diff changeset
497 // search the Memory chain for a store with the appropriate type
a61af66fc99e Initial load
duke
parents:
diff changeset
498 // address type. If a Phi is found, create a new version with
a61af66fc99e Initial load
duke
parents:
diff changeset
499 // the approriate memory slices from each of the Phi inputs.
a61af66fc99e Initial load
duke
parents:
diff changeset
500 // For stores, process the users as follows:
a61af66fc99e Initial load
duke
parents:
diff changeset
501 // MemNode: push on memnode_worklist
a61af66fc99e Initial load
duke
parents:
diff changeset
502 // MergeMem: push on mergemem_worklist
a61af66fc99e Initial load
duke
parents:
diff changeset
503 // Phase 3: Process MergeMem nodes from mergemem_worklist. Walk each memory slice
a61af66fc99e Initial load
duke
parents:
diff changeset
504 // moving the first node encountered of each instance type to the
a61af66fc99e Initial load
duke
parents:
diff changeset
505 // the input corresponding to its alias index.
a61af66fc99e Initial load
duke
parents:
diff changeset
506 // appropriate memory slice.
a61af66fc99e Initial load
duke
parents:
diff changeset
507 // Phase 4: Update the inputs of non-instance memory Phis and the Memory input of memnodes.
a61af66fc99e Initial load
duke
parents:
diff changeset
508 //
a61af66fc99e Initial load
duke
parents:
diff changeset
509 // In the following example, the CheckCastPP nodes are the cast of allocation
a61af66fc99e Initial load
duke
parents:
diff changeset
510 // results and the allocation of node 29 is unescaped and eligible to be an
a61af66fc99e Initial load
duke
parents:
diff changeset
511 // instance type.
a61af66fc99e Initial load
duke
parents:
diff changeset
512 //
a61af66fc99e Initial load
duke
parents:
diff changeset
513 // We start with:
a61af66fc99e Initial load
duke
parents:
diff changeset
514 //
a61af66fc99e Initial load
duke
parents:
diff changeset
515 // 7 Parm #memory
a61af66fc99e Initial load
duke
parents:
diff changeset
516 // 10 ConI "12"
a61af66fc99e Initial load
duke
parents:
diff changeset
517 // 19 CheckCastPP "Foo"
a61af66fc99e Initial load
duke
parents:
diff changeset
518 // 20 AddP _ 19 19 10 Foo+12 alias_index=4
a61af66fc99e Initial load
duke
parents:
diff changeset
519 // 29 CheckCastPP "Foo"
a61af66fc99e Initial load
duke
parents:
diff changeset
520 // 30 AddP _ 29 29 10 Foo+12 alias_index=4
a61af66fc99e Initial load
duke
parents:
diff changeset
521 //
a61af66fc99e Initial load
duke
parents:
diff changeset
522 // 40 StoreP 25 7 20 ... alias_index=4
a61af66fc99e Initial load
duke
parents:
diff changeset
523 // 50 StoreP 35 40 30 ... alias_index=4
a61af66fc99e Initial load
duke
parents:
diff changeset
524 // 60 StoreP 45 50 20 ... alias_index=4
a61af66fc99e Initial load
duke
parents:
diff changeset
525 // 70 LoadP _ 60 30 ... alias_index=4
a61af66fc99e Initial load
duke
parents:
diff changeset
526 // 80 Phi 75 50 60 Memory alias_index=4
a61af66fc99e Initial load
duke
parents:
diff changeset
527 // 90 LoadP _ 80 30 ... alias_index=4
a61af66fc99e Initial load
duke
parents:
diff changeset
528 // 100 LoadP _ 80 20 ... alias_index=4
a61af66fc99e Initial load
duke
parents:
diff changeset
529 //
a61af66fc99e Initial load
duke
parents:
diff changeset
530 //
a61af66fc99e Initial load
duke
parents:
diff changeset
531 // Phase 1 creates an instance type for node 29 assigning it an instance id of 24
a61af66fc99e Initial load
duke
parents:
diff changeset
532 // and creating a new alias index for node 30. This gives:
a61af66fc99e Initial load
duke
parents:
diff changeset
533 //
a61af66fc99e Initial load
duke
parents:
diff changeset
534 // 7 Parm #memory
a61af66fc99e Initial load
duke
parents:
diff changeset
535 // 10 ConI "12"
a61af66fc99e Initial load
duke
parents:
diff changeset
536 // 19 CheckCastPP "Foo"
a61af66fc99e Initial load
duke
parents:
diff changeset
537 // 20 AddP _ 19 19 10 Foo+12 alias_index=4
a61af66fc99e Initial load
duke
parents:
diff changeset
538 // 29 CheckCastPP "Foo" iid=24
a61af66fc99e Initial load
duke
parents:
diff changeset
539 // 30 AddP _ 29 29 10 Foo+12 alias_index=6 iid=24
a61af66fc99e Initial load
duke
parents:
diff changeset
540 //
a61af66fc99e Initial load
duke
parents:
diff changeset
541 // 40 StoreP 25 7 20 ... alias_index=4
a61af66fc99e Initial load
duke
parents:
diff changeset
542 // 50 StoreP 35 40 30 ... alias_index=6
a61af66fc99e Initial load
duke
parents:
diff changeset
543 // 60 StoreP 45 50 20 ... alias_index=4
a61af66fc99e Initial load
duke
parents:
diff changeset
544 // 70 LoadP _ 60 30 ... alias_index=6
a61af66fc99e Initial load
duke
parents:
diff changeset
545 // 80 Phi 75 50 60 Memory alias_index=4
a61af66fc99e Initial load
duke
parents:
diff changeset
546 // 90 LoadP _ 80 30 ... alias_index=6
a61af66fc99e Initial load
duke
parents:
diff changeset
547 // 100 LoadP _ 80 20 ... alias_index=4
a61af66fc99e Initial load
duke
parents:
diff changeset
548 //
a61af66fc99e Initial load
duke
parents:
diff changeset
549 // In phase 2, new memory inputs are computed for the loads and stores,
a61af66fc99e Initial load
duke
parents:
diff changeset
550 // And a new version of the phi is created. In phase 4, the inputs to
a61af66fc99e Initial load
duke
parents:
diff changeset
551 // node 80 are updated and then the memory nodes are updated with the
a61af66fc99e Initial load
duke
parents:
diff changeset
552 // values computed in phase 2. This results in:
a61af66fc99e Initial load
duke
parents:
diff changeset
553 //
a61af66fc99e Initial load
duke
parents:
diff changeset
554 // 7 Parm #memory
a61af66fc99e Initial load
duke
parents:
diff changeset
555 // 10 ConI "12"
a61af66fc99e Initial load
duke
parents:
diff changeset
556 // 19 CheckCastPP "Foo"
a61af66fc99e Initial load
duke
parents:
diff changeset
557 // 20 AddP _ 19 19 10 Foo+12 alias_index=4
a61af66fc99e Initial load
duke
parents:
diff changeset
558 // 29 CheckCastPP "Foo" iid=24
a61af66fc99e Initial load
duke
parents:
diff changeset
559 // 30 AddP _ 29 29 10 Foo+12 alias_index=6 iid=24
a61af66fc99e Initial load
duke
parents:
diff changeset
560 //
a61af66fc99e Initial load
duke
parents:
diff changeset
561 // 40 StoreP 25 7 20 ... alias_index=4
a61af66fc99e Initial load
duke
parents:
diff changeset
562 // 50 StoreP 35 7 30 ... alias_index=6
a61af66fc99e Initial load
duke
parents:
diff changeset
563 // 60 StoreP 45 40 20 ... alias_index=4
a61af66fc99e Initial load
duke
parents:
diff changeset
564 // 70 LoadP _ 50 30 ... alias_index=6
a61af66fc99e Initial load
duke
parents:
diff changeset
565 // 80 Phi 75 40 60 Memory alias_index=4
a61af66fc99e Initial load
duke
parents:
diff changeset
566 // 120 Phi 75 50 50 Memory alias_index=6
a61af66fc99e Initial load
duke
parents:
diff changeset
567 // 90 LoadP _ 120 30 ... alias_index=6
a61af66fc99e Initial load
duke
parents:
diff changeset
568 // 100 LoadP _ 80 20 ... alias_index=4
a61af66fc99e Initial load
duke
parents:
diff changeset
569 //
a61af66fc99e Initial load
duke
parents:
diff changeset
570 void ConnectionGraph::split_unique_types(GrowableArray<Node *> &alloc_worklist) {
a61af66fc99e Initial load
duke
parents:
diff changeset
571 GrowableArray<Node *> memnode_worklist;
a61af66fc99e Initial load
duke
parents:
diff changeset
572 GrowableArray<Node *> mergemem_worklist;
a61af66fc99e Initial load
duke
parents:
diff changeset
573 GrowableArray<PhiNode *> orig_phis;
a61af66fc99e Initial load
duke
parents:
diff changeset
574 PhaseGVN *igvn = _compile->initial_gvn();
a61af66fc99e Initial load
duke
parents:
diff changeset
575 uint new_index_start = (uint) _compile->num_alias_types();
a61af66fc99e Initial load
duke
parents:
diff changeset
576 VectorSet visited(Thread::current()->resource_area());
a61af66fc99e Initial load
duke
parents:
diff changeset
577 VectorSet ptset(Thread::current()->resource_area());
a61af66fc99e Initial load
duke
parents:
diff changeset
578
a61af66fc99e Initial load
duke
parents:
diff changeset
579 // Phase 1: Process possible allocations from alloc_worklist. Create instance
a61af66fc99e Initial load
duke
parents:
diff changeset
580 // types for the CheckCastPP for allocations where possible.
a61af66fc99e Initial load
duke
parents:
diff changeset
581 while (alloc_worklist.length() != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
582 Node *n = alloc_worklist.pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
583 uint ni = n->_idx;
a61af66fc99e Initial load
duke
parents:
diff changeset
584 if (n->is_Call()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
585 CallNode *alloc = n->as_Call();
a61af66fc99e Initial load
duke
parents:
diff changeset
586 // copy escape information to call node
a61af66fc99e Initial load
duke
parents:
diff changeset
587 PointsToNode ptn = _nodes->at(alloc->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
588 PointsToNode::EscapeState es = escape_state(alloc, igvn);
a61af66fc99e Initial load
duke
parents:
diff changeset
589 alloc->_escape_state = es;
a61af66fc99e Initial load
duke
parents:
diff changeset
590 // find CheckCastPP of call return value
a61af66fc99e Initial load
duke
parents:
diff changeset
591 n = alloc->proj_out(TypeFunc::Parms);
a61af66fc99e Initial load
duke
parents:
diff changeset
592 if (n != NULL && n->outcnt() == 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
593 n = n->unique_out();
a61af66fc99e Initial load
duke
parents:
diff changeset
594 if (n->Opcode() != Op_CheckCastPP) {
a61af66fc99e Initial load
duke
parents:
diff changeset
595 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
596 }
a61af66fc99e Initial load
duke
parents:
diff changeset
597 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
598 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
599 }
a61af66fc99e Initial load
duke
parents:
diff changeset
600 // we have an allocation or call which returns a Java object, see if it is unescaped
a61af66fc99e Initial load
duke
parents:
diff changeset
601 if (es != PointsToNode::NoEscape || !ptn._unique_type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
602 continue; // can't make a unique type
a61af66fc99e Initial load
duke
parents:
diff changeset
603 }
39
76256d272075 6667612: (Escape Analysis) disable loop cloning if it has a scalar replaceable allocation
kvn
parents: 38
diff changeset
604 if (alloc->is_Allocate()) {
76256d272075 6667612: (Escape Analysis) disable loop cloning if it has a scalar replaceable allocation
kvn
parents: 38
diff changeset
605 // Set the scalar_replaceable flag before the next check.
76256d272075 6667612: (Escape Analysis) disable loop cloning if it has a scalar replaceable allocation
kvn
parents: 38
diff changeset
606 alloc->as_Allocate()->_is_scalar_replaceable = true;
76256d272075 6667612: (Escape Analysis) disable loop cloning if it has a scalar replaceable allocation
kvn
parents: 38
diff changeset
607 }
76256d272075 6667612: (Escape Analysis) disable loop cloning if it has a scalar replaceable allocation
kvn
parents: 38
diff changeset
608
0
a61af66fc99e Initial load
duke
parents:
diff changeset
609 set_map(alloc->_idx, n);
a61af66fc99e Initial load
duke
parents:
diff changeset
610 set_map(n->_idx, alloc);
a61af66fc99e Initial load
duke
parents:
diff changeset
611 const TypeInstPtr *t = igvn->type(n)->isa_instptr();
a61af66fc99e Initial load
duke
parents:
diff changeset
612 // Unique types which are arrays are not currently supported.
a61af66fc99e Initial load
duke
parents:
diff changeset
613 // The check for AllocateArray is needed in case an array
a61af66fc99e Initial load
duke
parents:
diff changeset
614 // allocation is immediately cast to Object
a61af66fc99e Initial load
duke
parents:
diff changeset
615 if (t == NULL || alloc->is_AllocateArray())
a61af66fc99e Initial load
duke
parents:
diff changeset
616 continue; // not a TypeInstPtr
a61af66fc99e Initial load
duke
parents:
diff changeset
617 const TypeOopPtr *tinst = t->cast_to_instance(ni);
a61af66fc99e Initial load
duke
parents:
diff changeset
618 igvn->hash_delete(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
619 igvn->set_type(n, tinst);
a61af66fc99e Initial load
duke
parents:
diff changeset
620 n->raise_bottom_type(tinst);
a61af66fc99e Initial load
duke
parents:
diff changeset
621 igvn->hash_insert(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
622 } else if (n->is_AddP()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
623 ptset.Clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
624 PointsTo(ptset, n->in(AddPNode::Address), igvn);
a61af66fc99e Initial load
duke
parents:
diff changeset
625 assert(ptset.Size() == 1, "AddP address is unique");
a61af66fc99e Initial load
duke
parents:
diff changeset
626 Node *base = get_map(ptset.getelem());
a61af66fc99e Initial load
duke
parents:
diff changeset
627 split_AddP(n, base, igvn);
a61af66fc99e Initial load
duke
parents:
diff changeset
628 } else if (n->is_Phi() || n->Opcode() == Op_CastPP || n->Opcode() == Op_CheckCastPP) {
a61af66fc99e Initial load
duke
parents:
diff changeset
629 if (visited.test_set(n->_idx)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
630 assert(n->is_Phi(), "loops only through Phi's");
a61af66fc99e Initial load
duke
parents:
diff changeset
631 continue; // already processed
a61af66fc99e Initial load
duke
parents:
diff changeset
632 }
a61af66fc99e Initial load
duke
parents:
diff changeset
633 ptset.Clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
634 PointsTo(ptset, n, igvn);
a61af66fc99e Initial load
duke
parents:
diff changeset
635 if (ptset.Size() == 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
636 TypeNode *tn = n->as_Type();
a61af66fc99e Initial load
duke
parents:
diff changeset
637 Node *val = get_map(ptset.getelem());
a61af66fc99e Initial load
duke
parents:
diff changeset
638 const TypeInstPtr *val_t = igvn->type(val)->isa_instptr();;
a61af66fc99e Initial load
duke
parents:
diff changeset
639 assert(val_t != NULL && val_t->is_instance(), "instance type expected.");
a61af66fc99e Initial load
duke
parents:
diff changeset
640 const TypeInstPtr *tn_t = igvn->type(tn)->isa_instptr();;
a61af66fc99e Initial load
duke
parents:
diff changeset
641
a61af66fc99e Initial load
duke
parents:
diff changeset
642 if (tn_t != NULL && val_t->cast_to_instance(TypeOopPtr::UNKNOWN_INSTANCE)->higher_equal(tn_t)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
643 igvn->hash_delete(tn);
a61af66fc99e Initial load
duke
parents:
diff changeset
644 igvn->set_type(tn, val_t);
a61af66fc99e Initial load
duke
parents:
diff changeset
645 tn->set_type(val_t);
a61af66fc99e Initial load
duke
parents:
diff changeset
646 igvn->hash_insert(tn);
a61af66fc99e Initial load
duke
parents:
diff changeset
647 }
a61af66fc99e Initial load
duke
parents:
diff changeset
648 }
a61af66fc99e Initial load
duke
parents:
diff changeset
649 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
650 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
651 }
a61af66fc99e Initial load
duke
parents:
diff changeset
652 // push users on appropriate worklist
a61af66fc99e Initial load
duke
parents:
diff changeset
653 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
654 Node *use = n->fast_out(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
655 if(use->is_Mem() && use->in(MemNode::Address) == n) {
a61af66fc99e Initial load
duke
parents:
diff changeset
656 memnode_worklist.push(use);
a61af66fc99e Initial load
duke
parents:
diff changeset
657 } else if (use->is_AddP() || use->is_Phi() || use->Opcode() == Op_CastPP || use->Opcode() == Op_CheckCastPP) {
a61af66fc99e Initial load
duke
parents:
diff changeset
658 alloc_worklist.push(use);
a61af66fc99e Initial load
duke
parents:
diff changeset
659 }
a61af66fc99e Initial load
duke
parents:
diff changeset
660 }
a61af66fc99e Initial load
duke
parents:
diff changeset
661
a61af66fc99e Initial load
duke
parents:
diff changeset
662 }
a61af66fc99e Initial load
duke
parents:
diff changeset
663 uint new_index_end = (uint) _compile->num_alias_types();
a61af66fc99e Initial load
duke
parents:
diff changeset
664
a61af66fc99e Initial load
duke
parents:
diff changeset
665 // Phase 2: Process MemNode's from memnode_worklist. compute new address type and
a61af66fc99e Initial load
duke
parents:
diff changeset
666 // compute new values for Memory inputs (the Memory inputs are not
a61af66fc99e Initial load
duke
parents:
diff changeset
667 // actually updated until phase 4.)
a61af66fc99e Initial load
duke
parents:
diff changeset
668 if (memnode_worklist.length() == 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
669 return; // nothing to do
a61af66fc99e Initial load
duke
parents:
diff changeset
670
a61af66fc99e Initial load
duke
parents:
diff changeset
671
a61af66fc99e Initial load
duke
parents:
diff changeset
672 while (memnode_worklist.length() != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
673 Node *n = memnode_worklist.pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
674 if (n->is_Phi()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
675 assert(n->as_Phi()->adr_type() != TypePtr::BOTTOM, "narrow memory slice required");
a61af66fc99e Initial load
duke
parents:
diff changeset
676 // we don't need to do anything, but the users must be pushed if we haven't processed
a61af66fc99e Initial load
duke
parents:
diff changeset
677 // this Phi before
a61af66fc99e Initial load
duke
parents:
diff changeset
678 if (visited.test_set(n->_idx))
a61af66fc99e Initial load
duke
parents:
diff changeset
679 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
680 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
681 assert(n->is_Mem(), "memory node required.");
a61af66fc99e Initial load
duke
parents:
diff changeset
682 Node *addr = n->in(MemNode::Address);
a61af66fc99e Initial load
duke
parents:
diff changeset
683 const Type *addr_t = igvn->type(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
684 if (addr_t == Type::TOP)
a61af66fc99e Initial load
duke
parents:
diff changeset
685 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
686 assert (addr_t->isa_ptr() != NULL, "pointer type required.");
a61af66fc99e Initial load
duke
parents:
diff changeset
687 int alias_idx = _compile->get_alias_index(addr_t->is_ptr());
a61af66fc99e Initial load
duke
parents:
diff changeset
688 Node *mem = find_mem(n->in(MemNode::Memory), alias_idx, igvn);
a61af66fc99e Initial load
duke
parents:
diff changeset
689 if (mem->is_Phi()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
690 mem = split_memory_phi(mem->as_Phi(), alias_idx, orig_phis, igvn);
a61af66fc99e Initial load
duke
parents:
diff changeset
691 }
38
b789bcaf2dd9 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 0
diff changeset
692 if (_compile->failing()) {
b789bcaf2dd9 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 0
diff changeset
693 return;
b789bcaf2dd9 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 0
diff changeset
694 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
695 if (mem != n->in(MemNode::Memory))
a61af66fc99e Initial load
duke
parents:
diff changeset
696 set_map(n->_idx, mem);
a61af66fc99e Initial load
duke
parents:
diff changeset
697 if (n->is_Load()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
698 continue; // don't push users
a61af66fc99e Initial load
duke
parents:
diff changeset
699 } else if (n->is_LoadStore()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
700 // get the memory projection
a61af66fc99e Initial load
duke
parents:
diff changeset
701 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
702 Node *use = n->fast_out(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
703 if (use->Opcode() == Op_SCMemProj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
704 n = use;
a61af66fc99e Initial load
duke
parents:
diff changeset
705 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
706 }
a61af66fc99e Initial load
duke
parents:
diff changeset
707 }
a61af66fc99e Initial load
duke
parents:
diff changeset
708 assert(n->Opcode() == Op_SCMemProj, "memory projection required");
a61af66fc99e Initial load
duke
parents:
diff changeset
709 }
a61af66fc99e Initial load
duke
parents:
diff changeset
710 }
a61af66fc99e Initial load
duke
parents:
diff changeset
711 // push user on appropriate worklist
a61af66fc99e Initial load
duke
parents:
diff changeset
712 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
713 Node *use = n->fast_out(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
714 if (use->is_Phi()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
715 memnode_worklist.push(use);
a61af66fc99e Initial load
duke
parents:
diff changeset
716 } else if(use->is_Mem() && use->in(MemNode::Memory) == n) {
a61af66fc99e Initial load
duke
parents:
diff changeset
717 memnode_worklist.push(use);
a61af66fc99e Initial load
duke
parents:
diff changeset
718 } else if (use->is_MergeMem()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
719 mergemem_worklist.push(use);
a61af66fc99e Initial load
duke
parents:
diff changeset
720 }
a61af66fc99e Initial load
duke
parents:
diff changeset
721 }
a61af66fc99e Initial load
duke
parents:
diff changeset
722 }
a61af66fc99e Initial load
duke
parents:
diff changeset
723
a61af66fc99e Initial load
duke
parents:
diff changeset
724 // Phase 3: Process MergeMem nodes from mergemem_worklist. Walk each memory slice
a61af66fc99e Initial load
duke
parents:
diff changeset
725 // moving the first node encountered of each instance type to the
a61af66fc99e Initial load
duke
parents:
diff changeset
726 // the input corresponding to its alias index.
a61af66fc99e Initial load
duke
parents:
diff changeset
727 while (mergemem_worklist.length() != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
728 Node *n = mergemem_worklist.pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
729 assert(n->is_MergeMem(), "MergeMem node required.");
a61af66fc99e Initial load
duke
parents:
diff changeset
730 MergeMemNode *nmm = n->as_MergeMem();
a61af66fc99e Initial load
duke
parents:
diff changeset
731 // Note: we don't want to use MergeMemStream here because we only want to
a61af66fc99e Initial load
duke
parents:
diff changeset
732 // scan inputs which exist at the start, not ones we add during processing
a61af66fc99e Initial load
duke
parents:
diff changeset
733 uint nslices = nmm->req();
a61af66fc99e Initial load
duke
parents:
diff changeset
734 igvn->hash_delete(nmm);
a61af66fc99e Initial load
duke
parents:
diff changeset
735 for (uint i = Compile::AliasIdxRaw+1; i < nslices; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
736 Node * mem = nmm->in(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
737 Node * cur = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
738 if (mem == NULL || mem->is_top())
a61af66fc99e Initial load
duke
parents:
diff changeset
739 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
740 while (mem->is_Mem()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
741 const Type *at = igvn->type(mem->in(MemNode::Address));
a61af66fc99e Initial load
duke
parents:
diff changeset
742 if (at != Type::TOP) {
a61af66fc99e Initial load
duke
parents:
diff changeset
743 assert (at->isa_ptr() != NULL, "pointer type required.");
a61af66fc99e Initial load
duke
parents:
diff changeset
744 uint idx = (uint)_compile->get_alias_index(at->is_ptr());
a61af66fc99e Initial load
duke
parents:
diff changeset
745 if (idx == i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
746 if (cur == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
747 cur = mem;
a61af66fc99e Initial load
duke
parents:
diff changeset
748 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
749 if (idx >= nmm->req() || nmm->is_empty_memory(nmm->in(idx))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
750 nmm->set_memory_at(idx, mem);
a61af66fc99e Initial load
duke
parents:
diff changeset
751 }
a61af66fc99e Initial load
duke
parents:
diff changeset
752 }
a61af66fc99e Initial load
duke
parents:
diff changeset
753 }
a61af66fc99e Initial load
duke
parents:
diff changeset
754 mem = mem->in(MemNode::Memory);
a61af66fc99e Initial load
duke
parents:
diff changeset
755 }
a61af66fc99e Initial load
duke
parents:
diff changeset
756 nmm->set_memory_at(i, (cur != NULL) ? cur : mem);
a61af66fc99e Initial load
duke
parents:
diff changeset
757 if (mem->is_Phi()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
758 // We have encountered a Phi, we need to split the Phi for
a61af66fc99e Initial load
duke
parents:
diff changeset
759 // any instance of the current type if we haven't encountered
a61af66fc99e Initial load
duke
parents:
diff changeset
760 // a value of the instance along the chain.
a61af66fc99e Initial load
duke
parents:
diff changeset
761 for (uint ni = new_index_start; ni < new_index_end; ni++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
762 if((uint)_compile->get_general_index(ni) == i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
763 Node *m = (ni >= nmm->req()) ? nmm->empty_memory() : nmm->in(ni);
a61af66fc99e Initial load
duke
parents:
diff changeset
764 if (nmm->is_empty_memory(m)) {
38
b789bcaf2dd9 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 0
diff changeset
765 m = split_memory_phi(mem->as_Phi(), ni, orig_phis, igvn);
b789bcaf2dd9 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 0
diff changeset
766 if (_compile->failing()) {
b789bcaf2dd9 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 0
diff changeset
767 return;
b789bcaf2dd9 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 0
diff changeset
768 }
b789bcaf2dd9 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 0
diff changeset
769 nmm->set_memory_at(ni, m);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
770 }
a61af66fc99e Initial load
duke
parents:
diff changeset
771 }
a61af66fc99e Initial load
duke
parents:
diff changeset
772 }
a61af66fc99e Initial load
duke
parents:
diff changeset
773 }
a61af66fc99e Initial load
duke
parents:
diff changeset
774 }
a61af66fc99e Initial load
duke
parents:
diff changeset
775 igvn->hash_insert(nmm);
a61af66fc99e Initial load
duke
parents:
diff changeset
776 record_for_optimizer(nmm);
a61af66fc99e Initial load
duke
parents:
diff changeset
777 }
a61af66fc99e Initial load
duke
parents:
diff changeset
778
a61af66fc99e Initial load
duke
parents:
diff changeset
779 // Phase 4: Update the inputs of non-instance memory Phis and the Memory input of memnodes
a61af66fc99e Initial load
duke
parents:
diff changeset
780 //
a61af66fc99e Initial load
duke
parents:
diff changeset
781 // First update the inputs of any non-instance Phi's from
a61af66fc99e Initial load
duke
parents:
diff changeset
782 // which we split out an instance Phi. Note we don't have
a61af66fc99e Initial load
duke
parents:
diff changeset
783 // to recursively process Phi's encounted on the input memory
a61af66fc99e Initial load
duke
parents:
diff changeset
784 // chains as is done in split_memory_phi() since they will
a61af66fc99e Initial load
duke
parents:
diff changeset
785 // also be processed here.
a61af66fc99e Initial load
duke
parents:
diff changeset
786 while (orig_phis.length() != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
787 PhiNode *phi = orig_phis.pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
788 int alias_idx = _compile->get_alias_index(phi->adr_type());
a61af66fc99e Initial load
duke
parents:
diff changeset
789 igvn->hash_delete(phi);
a61af66fc99e Initial load
duke
parents:
diff changeset
790 for (uint i = 1; i < phi->req(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
791 Node *mem = phi->in(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
792 Node *new_mem = find_mem(mem, alias_idx, igvn);
a61af66fc99e Initial load
duke
parents:
diff changeset
793 if (mem != new_mem) {
a61af66fc99e Initial load
duke
parents:
diff changeset
794 phi->set_req(i, new_mem);
a61af66fc99e Initial load
duke
parents:
diff changeset
795 }
a61af66fc99e Initial load
duke
parents:
diff changeset
796 }
a61af66fc99e Initial load
duke
parents:
diff changeset
797 igvn->hash_insert(phi);
a61af66fc99e Initial load
duke
parents:
diff changeset
798 record_for_optimizer(phi);
a61af66fc99e Initial load
duke
parents:
diff changeset
799 }
a61af66fc99e Initial load
duke
parents:
diff changeset
800
a61af66fc99e Initial load
duke
parents:
diff changeset
801 // Update the memory inputs of MemNodes with the value we computed
a61af66fc99e Initial load
duke
parents:
diff changeset
802 // in Phase 2.
a61af66fc99e Initial load
duke
parents:
diff changeset
803 for (int i = 0; i < _nodes->length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
804 Node *nmem = get_map(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
805 if (nmem != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
806 Node *n = _nodes->at(i)._node;
a61af66fc99e Initial load
duke
parents:
diff changeset
807 if (n != NULL && n->is_Mem()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
808 igvn->hash_delete(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
809 n->set_req(MemNode::Memory, nmem);
a61af66fc99e Initial load
duke
parents:
diff changeset
810 igvn->hash_insert(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
811 record_for_optimizer(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
812 }
a61af66fc99e Initial load
duke
parents:
diff changeset
813 }
a61af66fc99e Initial load
duke
parents:
diff changeset
814 }
a61af66fc99e Initial load
duke
parents:
diff changeset
815 }
a61af66fc99e Initial load
duke
parents:
diff changeset
816
a61af66fc99e Initial load
duke
parents:
diff changeset
817 void ConnectionGraph::compute_escape() {
a61af66fc99e Initial load
duke
parents:
diff changeset
818 GrowableArray<int> worklist;
a61af66fc99e Initial load
duke
parents:
diff changeset
819 GrowableArray<Node *> alloc_worklist;
a61af66fc99e Initial load
duke
parents:
diff changeset
820 VectorSet visited(Thread::current()->resource_area());
a61af66fc99e Initial load
duke
parents:
diff changeset
821 PhaseGVN *igvn = _compile->initial_gvn();
a61af66fc99e Initial load
duke
parents:
diff changeset
822
a61af66fc99e Initial load
duke
parents:
diff changeset
823 // process Phi nodes from the deferred list, they may not have
a61af66fc99e Initial load
duke
parents:
diff changeset
824 while(_deferred.size() > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
825 Node * n = _deferred.pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
826 PhiNode * phi = n->as_Phi();
a61af66fc99e Initial load
duke
parents:
diff changeset
827
a61af66fc99e Initial load
duke
parents:
diff changeset
828 process_phi_escape(phi, igvn);
a61af66fc99e Initial load
duke
parents:
diff changeset
829 }
a61af66fc99e Initial load
duke
parents:
diff changeset
830
a61af66fc99e Initial load
duke
parents:
diff changeset
831 VectorSet ptset(Thread::current()->resource_area());
a61af66fc99e Initial load
duke
parents:
diff changeset
832
a61af66fc99e Initial load
duke
parents:
diff changeset
833 // remove deferred edges from the graph and collect
a61af66fc99e Initial load
duke
parents:
diff changeset
834 // information we will need for type splitting
a61af66fc99e Initial load
duke
parents:
diff changeset
835 for (uint ni = 0; ni < (uint)_nodes->length(); ni++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
836 PointsToNode * ptn = _nodes->adr_at(ni);
a61af66fc99e Initial load
duke
parents:
diff changeset
837 PointsToNode::NodeType nt = ptn->node_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
838
a61af66fc99e Initial load
duke
parents:
diff changeset
839 if (nt == PointsToNode::UnknownType) {
a61af66fc99e Initial load
duke
parents:
diff changeset
840 continue; // not a node we are interested in
a61af66fc99e Initial load
duke
parents:
diff changeset
841 }
a61af66fc99e Initial load
duke
parents:
diff changeset
842 Node *n = ptn->_node;
a61af66fc99e Initial load
duke
parents:
diff changeset
843 if (nt == PointsToNode::LocalVar || nt == PointsToNode::Field) {
a61af66fc99e Initial load
duke
parents:
diff changeset
844 remove_deferred(ni);
a61af66fc99e Initial load
duke
parents:
diff changeset
845 if (n->is_AddP()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
846 // if this AddP computes an address which may point to more that one
a61af66fc99e Initial load
duke
parents:
diff changeset
847 // object, nothing the address points to can be a unique type.
a61af66fc99e Initial load
duke
parents:
diff changeset
848 Node *base = n->in(AddPNode::Base);
a61af66fc99e Initial load
duke
parents:
diff changeset
849 ptset.Clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
850 PointsTo(ptset, base, igvn);
a61af66fc99e Initial load
duke
parents:
diff changeset
851 if (ptset.Size() > 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
852 for( VectorSetI j(&ptset); j.test(); ++j ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
853 PointsToNode *ptaddr = _nodes->adr_at(j.elem);
a61af66fc99e Initial load
duke
parents:
diff changeset
854 ptaddr->_unique_type = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
855 }
a61af66fc99e Initial load
duke
parents:
diff changeset
856 }
a61af66fc99e Initial load
duke
parents:
diff changeset
857 }
a61af66fc99e Initial load
duke
parents:
diff changeset
858 } else if (n->is_Call()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
859 // initialize _escape_state of calls to GlobalEscape
a61af66fc99e Initial load
duke
parents:
diff changeset
860 n->as_Call()->_escape_state = PointsToNode::GlobalEscape;
a61af66fc99e Initial load
duke
parents:
diff changeset
861 // push call on alloc_worlist (alocations are calls)
a61af66fc99e Initial load
duke
parents:
diff changeset
862 // for processing by split_unique_types()
a61af66fc99e Initial load
duke
parents:
diff changeset
863 alloc_worklist.push(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
864 }
a61af66fc99e Initial load
duke
parents:
diff changeset
865 }
a61af66fc99e Initial load
duke
parents:
diff changeset
866 // push all GlobalEscape nodes on the worklist
a61af66fc99e Initial load
duke
parents:
diff changeset
867 for (uint nj = 0; nj < (uint)_nodes->length(); nj++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
868 if (_nodes->at(nj).escape_state() == PointsToNode::GlobalEscape) {
a61af66fc99e Initial load
duke
parents:
diff changeset
869 worklist.append(nj);
a61af66fc99e Initial load
duke
parents:
diff changeset
870 }
a61af66fc99e Initial load
duke
parents:
diff changeset
871 }
a61af66fc99e Initial load
duke
parents:
diff changeset
872 // mark all node reachable from GlobalEscape nodes
a61af66fc99e Initial load
duke
parents:
diff changeset
873 while(worklist.length() > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
874 PointsToNode n = _nodes->at(worklist.pop());
a61af66fc99e Initial load
duke
parents:
diff changeset
875 for (uint ei = 0; ei < n.edge_count(); ei++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
876 uint npi = n.edge_target(ei);
a61af66fc99e Initial load
duke
parents:
diff changeset
877 PointsToNode *np = ptnode_adr(npi);
a61af66fc99e Initial load
duke
parents:
diff changeset
878 if (np->escape_state() != PointsToNode::GlobalEscape) {
a61af66fc99e Initial load
duke
parents:
diff changeset
879 np->set_escape_state(PointsToNode::GlobalEscape);
a61af66fc99e Initial load
duke
parents:
diff changeset
880 worklist.append_if_missing(npi);
a61af66fc99e Initial load
duke
parents:
diff changeset
881 }
a61af66fc99e Initial load
duke
parents:
diff changeset
882 }
a61af66fc99e Initial load
duke
parents:
diff changeset
883 }
a61af66fc99e Initial load
duke
parents:
diff changeset
884
a61af66fc99e Initial load
duke
parents:
diff changeset
885 // push all ArgEscape nodes on the worklist
a61af66fc99e Initial load
duke
parents:
diff changeset
886 for (uint nk = 0; nk < (uint)_nodes->length(); nk++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
887 if (_nodes->at(nk).escape_state() == PointsToNode::ArgEscape)
a61af66fc99e Initial load
duke
parents:
diff changeset
888 worklist.push(nk);
a61af66fc99e Initial load
duke
parents:
diff changeset
889 }
a61af66fc99e Initial load
duke
parents:
diff changeset
890 // mark all node reachable from ArgEscape nodes
a61af66fc99e Initial load
duke
parents:
diff changeset
891 while(worklist.length() > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
892 PointsToNode n = _nodes->at(worklist.pop());
a61af66fc99e Initial load
duke
parents:
diff changeset
893
a61af66fc99e Initial load
duke
parents:
diff changeset
894 for (uint ei = 0; ei < n.edge_count(); ei++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
895 uint npi = n.edge_target(ei);
a61af66fc99e Initial load
duke
parents:
diff changeset
896 PointsToNode *np = ptnode_adr(npi);
a61af66fc99e Initial load
duke
parents:
diff changeset
897 if (np->escape_state() != PointsToNode::ArgEscape) {
a61af66fc99e Initial load
duke
parents:
diff changeset
898 np->set_escape_state(PointsToNode::ArgEscape);
a61af66fc99e Initial load
duke
parents:
diff changeset
899 worklist.append_if_missing(npi);
a61af66fc99e Initial load
duke
parents:
diff changeset
900 }
a61af66fc99e Initial load
duke
parents:
diff changeset
901 }
a61af66fc99e Initial load
duke
parents:
diff changeset
902 }
a61af66fc99e Initial load
duke
parents:
diff changeset
903 _collecting = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
904
a61af66fc99e Initial load
duke
parents:
diff changeset
905 // Now use the escape information to create unique types for
a61af66fc99e Initial load
duke
parents:
diff changeset
906 // unescaped objects
a61af66fc99e Initial load
duke
parents:
diff changeset
907 split_unique_types(alloc_worklist);
38
b789bcaf2dd9 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 0
diff changeset
908 if (_compile->failing()) return;
b789bcaf2dd9 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 0
diff changeset
909
b789bcaf2dd9 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 0
diff changeset
910 // Clean up after split unique types.
b789bcaf2dd9 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 0
diff changeset
911 ResourceMark rm;
b789bcaf2dd9 6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents: 0
diff changeset
912 PhaseRemoveUseless pru(_compile->initial_gvn(), _compile->for_igvn());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
913 }
a61af66fc99e Initial load
duke
parents:
diff changeset
914
a61af66fc99e Initial load
duke
parents:
diff changeset
915 Node * ConnectionGraph::skip_casts(Node *n) {
a61af66fc99e Initial load
duke
parents:
diff changeset
916 while(n->Opcode() == Op_CastPP || n->Opcode() == Op_CheckCastPP) {
a61af66fc99e Initial load
duke
parents:
diff changeset
917 n = n->in(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
918 }
a61af66fc99e Initial load
duke
parents:
diff changeset
919 return n;
a61af66fc99e Initial load
duke
parents:
diff changeset
920 }
a61af66fc99e Initial load
duke
parents:
diff changeset
921
a61af66fc99e Initial load
duke
parents:
diff changeset
922 void ConnectionGraph::process_phi_escape(PhiNode *phi, PhaseTransform *phase) {
a61af66fc99e Initial load
duke
parents:
diff changeset
923
a61af66fc99e Initial load
duke
parents:
diff changeset
924 if (phi->type()->isa_oopptr() == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
925 return; // nothing to do if not an oop
a61af66fc99e Initial load
duke
parents:
diff changeset
926
a61af66fc99e Initial load
duke
parents:
diff changeset
927 PointsToNode *ptadr = ptnode_adr(phi->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
928 int incount = phi->req();
a61af66fc99e Initial load
duke
parents:
diff changeset
929 int non_null_inputs = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
930
a61af66fc99e Initial load
duke
parents:
diff changeset
931 for (int i = 1; i < incount ; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
932 if (phi->in(i) != NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
933 non_null_inputs++;
a61af66fc99e Initial load
duke
parents:
diff changeset
934 }
a61af66fc99e Initial load
duke
parents:
diff changeset
935 if (non_null_inputs == ptadr->_inputs_processed)
a61af66fc99e Initial load
duke
parents:
diff changeset
936 return; // no new inputs since the last time this node was processed,
a61af66fc99e Initial load
duke
parents:
diff changeset
937 // the current information is valid
a61af66fc99e Initial load
duke
parents:
diff changeset
938
a61af66fc99e Initial load
duke
parents:
diff changeset
939 ptadr->_inputs_processed = non_null_inputs; // prevent recursive processing of this node
a61af66fc99e Initial load
duke
parents:
diff changeset
940 for (int j = 1; j < incount ; j++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
941 Node * n = phi->in(j);
a61af66fc99e Initial load
duke
parents:
diff changeset
942 if (n == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
943 continue; // ignore NULL
a61af66fc99e Initial load
duke
parents:
diff changeset
944 n = skip_casts(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
945 if (n->is_top() || n == phi)
a61af66fc99e Initial load
duke
parents:
diff changeset
946 continue; // ignore top or inputs which go back this node
a61af66fc99e Initial load
duke
parents:
diff changeset
947 int nopc = n->Opcode();
a61af66fc99e Initial load
duke
parents:
diff changeset
948 PointsToNode npt = _nodes->at(n->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
949 if (_nodes->at(n->_idx).node_type() == PointsToNode::JavaObject) {
a61af66fc99e Initial load
duke
parents:
diff changeset
950 add_pointsto_edge(phi->_idx, n->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
951 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
952 add_deferred_edge(phi->_idx, n->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
953 }
a61af66fc99e Initial load
duke
parents:
diff changeset
954 }
a61af66fc99e Initial load
duke
parents:
diff changeset
955 }
a61af66fc99e Initial load
duke
parents:
diff changeset
956
a61af66fc99e Initial load
duke
parents:
diff changeset
957 void ConnectionGraph::process_call_arguments(CallNode *call, PhaseTransform *phase) {
a61af66fc99e Initial load
duke
parents:
diff changeset
958
a61af66fc99e Initial load
duke
parents:
diff changeset
959 _processed.set(call->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
960 switch (call->Opcode()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
961
a61af66fc99e Initial load
duke
parents:
diff changeset
962 // arguments to allocation and locking don't escape
a61af66fc99e Initial load
duke
parents:
diff changeset
963 case Op_Allocate:
a61af66fc99e Initial load
duke
parents:
diff changeset
964 case Op_AllocateArray:
a61af66fc99e Initial load
duke
parents:
diff changeset
965 case Op_Lock:
a61af66fc99e Initial load
duke
parents:
diff changeset
966 case Op_Unlock:
a61af66fc99e Initial load
duke
parents:
diff changeset
967 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
968
a61af66fc99e Initial load
duke
parents:
diff changeset
969 case Op_CallStaticJava:
a61af66fc99e Initial load
duke
parents:
diff changeset
970 // For a static call, we know exactly what method is being called.
a61af66fc99e Initial load
duke
parents:
diff changeset
971 // Use bytecode estimator to record the call's escape affects
a61af66fc99e Initial load
duke
parents:
diff changeset
972 {
a61af66fc99e Initial load
duke
parents:
diff changeset
973 ciMethod *meth = call->as_CallJava()->method();
a61af66fc99e Initial load
duke
parents:
diff changeset
974 if (meth != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
975 const TypeTuple * d = call->tf()->domain();
a61af66fc99e Initial load
duke
parents:
diff changeset
976 BCEscapeAnalyzer call_analyzer(meth);
a61af66fc99e Initial load
duke
parents:
diff changeset
977 VectorSet ptset(Thread::current()->resource_area());
a61af66fc99e Initial load
duke
parents:
diff changeset
978 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
979 const Type* at = d->field_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
980 int k = i - TypeFunc::Parms;
a61af66fc99e Initial load
duke
parents:
diff changeset
981
a61af66fc99e Initial load
duke
parents:
diff changeset
982 if (at->isa_oopptr() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
983 Node *arg = skip_casts(call->in(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
984
a61af66fc99e Initial load
duke
parents:
diff changeset
985 if (!call_analyzer.is_arg_stack(k)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
986 // The argument global escapes, mark everything it could point to
a61af66fc99e Initial load
duke
parents:
diff changeset
987 ptset.Clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
988 PointsTo(ptset, arg, phase);
a61af66fc99e Initial load
duke
parents:
diff changeset
989 for( VectorSetI j(&ptset); j.test(); ++j ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
990 uint pt = j.elem;
a61af66fc99e Initial load
duke
parents:
diff changeset
991
a61af66fc99e Initial load
duke
parents:
diff changeset
992 set_escape_state(pt, PointsToNode::GlobalEscape);
a61af66fc99e Initial load
duke
parents:
diff changeset
993 }
a61af66fc99e Initial load
duke
parents:
diff changeset
994 } else if (!call_analyzer.is_arg_local(k)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
995 // The argument itself doesn't escape, but any fields might
a61af66fc99e Initial load
duke
parents:
diff changeset
996 ptset.Clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
997 PointsTo(ptset, arg, phase);
a61af66fc99e Initial load
duke
parents:
diff changeset
998 for( VectorSetI j(&ptset); j.test(); ++j ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
999 uint pt = j.elem;
a61af66fc99e Initial load
duke
parents:
diff changeset
1000 add_edge_from_fields(pt, _phantom_object, Type::OffsetBot);
a61af66fc99e Initial load
duke
parents:
diff changeset
1001 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1002 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1003 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1004 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1005 call_analyzer.copy_dependencies(C()->dependencies());
a61af66fc99e Initial load
duke
parents:
diff changeset
1006 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1007 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1008 // fall-through if not a Java method
a61af66fc99e Initial load
duke
parents:
diff changeset
1009 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1010
a61af66fc99e Initial load
duke
parents:
diff changeset
1011 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
1012 // Some other type of call, assume the worst case: all arguments
a61af66fc99e Initial load
duke
parents:
diff changeset
1013 // globally escape.
a61af66fc99e Initial load
duke
parents:
diff changeset
1014 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1015 // adjust escape state for outgoing arguments
a61af66fc99e Initial load
duke
parents:
diff changeset
1016 const TypeTuple * d = call->tf()->domain();
a61af66fc99e Initial load
duke
parents:
diff changeset
1017 VectorSet ptset(Thread::current()->resource_area());
a61af66fc99e Initial load
duke
parents:
diff changeset
1018 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1019 const Type* at = d->field_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1020
a61af66fc99e Initial load
duke
parents:
diff changeset
1021 if (at->isa_oopptr() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1022 Node *arg = skip_casts(call->in(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
1023 ptset.Clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
1024 PointsTo(ptset, arg, phase);
a61af66fc99e Initial load
duke
parents:
diff changeset
1025 for( VectorSetI j(&ptset); j.test(); ++j ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1026 uint pt = j.elem;
a61af66fc99e Initial load
duke
parents:
diff changeset
1027
a61af66fc99e Initial load
duke
parents:
diff changeset
1028 set_escape_state(pt, PointsToNode::GlobalEscape);
a61af66fc99e Initial load
duke
parents:
diff changeset
1029 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1030 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1031 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1032 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1033 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1034 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1035 void ConnectionGraph::process_call_result(ProjNode *resproj, PhaseTransform *phase) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1036 CallNode *call = resproj->in(0)->as_Call();
a61af66fc99e Initial load
duke
parents:
diff changeset
1037
a61af66fc99e Initial load
duke
parents:
diff changeset
1038 PointsToNode *ptadr = ptnode_adr(resproj->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1039
a61af66fc99e Initial load
duke
parents:
diff changeset
1040 ptadr->_node = resproj;
a61af66fc99e Initial load
duke
parents:
diff changeset
1041 ptadr->set_node_type(PointsToNode::LocalVar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1042 set_escape_state(resproj->_idx, PointsToNode::UnknownEscape);
a61af66fc99e Initial load
duke
parents:
diff changeset
1043 _processed.set(resproj->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1044
a61af66fc99e Initial load
duke
parents:
diff changeset
1045 switch (call->Opcode()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1046 case Op_Allocate:
a61af66fc99e Initial load
duke
parents:
diff changeset
1047 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1048 Node *k = call->in(AllocateNode::KlassNode);
a61af66fc99e Initial load
duke
parents:
diff changeset
1049 const TypeKlassPtr *kt;
a61af66fc99e Initial load
duke
parents:
diff changeset
1050 if (k->Opcode() == Op_LoadKlass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1051 kt = k->as_Load()->type()->isa_klassptr();
a61af66fc99e Initial load
duke
parents:
diff changeset
1052 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1053 kt = k->as_Type()->type()->isa_klassptr();
a61af66fc99e Initial load
duke
parents:
diff changeset
1054 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1055 assert(kt != NULL, "TypeKlassPtr required.");
a61af66fc99e Initial load
duke
parents:
diff changeset
1056 ciKlass* cik = kt->klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
1057 ciInstanceKlass* ciik = cik->as_instance_klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
1058
a61af66fc99e Initial load
duke
parents:
diff changeset
1059 PointsToNode *ptadr = ptnode_adr(call->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1060 ptadr->set_node_type(PointsToNode::JavaObject);
a61af66fc99e Initial load
duke
parents:
diff changeset
1061 if (cik->is_subclass_of(_compile->env()->Thread_klass()) || ciik->has_finalizer()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1062 set_escape_state(call->_idx, PointsToNode::GlobalEscape);
a61af66fc99e Initial load
duke
parents:
diff changeset
1063 add_pointsto_edge(resproj->_idx, _phantom_object);
a61af66fc99e Initial load
duke
parents:
diff changeset
1064 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1065 set_escape_state(call->_idx, PointsToNode::NoEscape);
a61af66fc99e Initial load
duke
parents:
diff changeset
1066 add_pointsto_edge(resproj->_idx, call->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1067 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1068 _processed.set(call->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1069 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1070 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1071
a61af66fc99e Initial load
duke
parents:
diff changeset
1072 case Op_AllocateArray:
a61af66fc99e Initial load
duke
parents:
diff changeset
1073 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1074 PointsToNode *ptadr = ptnode_adr(call->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1075 ptadr->set_node_type(PointsToNode::JavaObject);
a61af66fc99e Initial load
duke
parents:
diff changeset
1076 set_escape_state(call->_idx, PointsToNode::NoEscape);
a61af66fc99e Initial load
duke
parents:
diff changeset
1077 _processed.set(call->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1078 add_pointsto_edge(resproj->_idx, call->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1079 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1080 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1081
a61af66fc99e Initial load
duke
parents:
diff changeset
1082 case Op_Lock:
a61af66fc99e Initial load
duke
parents:
diff changeset
1083 case Op_Unlock:
a61af66fc99e Initial load
duke
parents:
diff changeset
1084 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1085
a61af66fc99e Initial load
duke
parents:
diff changeset
1086 case Op_CallStaticJava:
a61af66fc99e Initial load
duke
parents:
diff changeset
1087 // For a static call, we know exactly what method is being called.
a61af66fc99e Initial load
duke
parents:
diff changeset
1088 // Use bytecode estimator to record whether the call's return value escapes
a61af66fc99e Initial load
duke
parents:
diff changeset
1089 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1090 const TypeTuple *r = call->tf()->range();
a61af66fc99e Initial load
duke
parents:
diff changeset
1091 const Type* ret_type = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1092
a61af66fc99e Initial load
duke
parents:
diff changeset
1093 if (r->cnt() > TypeFunc::Parms)
a61af66fc99e Initial load
duke
parents:
diff changeset
1094 ret_type = r->field_at(TypeFunc::Parms);
a61af66fc99e Initial load
duke
parents:
diff changeset
1095
a61af66fc99e Initial load
duke
parents:
diff changeset
1096 // Note: we use isa_ptr() instead of isa_oopptr() here because the
a61af66fc99e Initial load
duke
parents:
diff changeset
1097 // _multianewarray functions return a TypeRawPtr.
a61af66fc99e Initial load
duke
parents:
diff changeset
1098 if (ret_type == NULL || ret_type->isa_ptr() == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
1099 break; // doesn't return a pointer type
a61af66fc99e Initial load
duke
parents:
diff changeset
1100
a61af66fc99e Initial load
duke
parents:
diff changeset
1101 ciMethod *meth = call->as_CallJava()->method();
a61af66fc99e Initial load
duke
parents:
diff changeset
1102 if (meth == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1103 // not a Java method, assume global escape
a61af66fc99e Initial load
duke
parents:
diff changeset
1104 set_escape_state(call->_idx, PointsToNode::GlobalEscape);
a61af66fc99e Initial load
duke
parents:
diff changeset
1105 if (resproj != NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
1106 add_pointsto_edge(resproj->_idx, _phantom_object);
a61af66fc99e Initial load
duke
parents:
diff changeset
1107 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1108 BCEscapeAnalyzer call_analyzer(meth);
a61af66fc99e Initial load
duke
parents:
diff changeset
1109 VectorSet ptset(Thread::current()->resource_area());
a61af66fc99e Initial load
duke
parents:
diff changeset
1110
a61af66fc99e Initial load
duke
parents:
diff changeset
1111 if (call_analyzer.is_return_local() && resproj != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1112 // determine whether any arguments are returned
a61af66fc99e Initial load
duke
parents:
diff changeset
1113 const TypeTuple * d = call->tf()->domain();
a61af66fc99e Initial load
duke
parents:
diff changeset
1114 set_escape_state(call->_idx, PointsToNode::NoEscape);
a61af66fc99e Initial load
duke
parents:
diff changeset
1115 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1116 const Type* at = d->field_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1117
a61af66fc99e Initial load
duke
parents:
diff changeset
1118 if (at->isa_oopptr() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1119 Node *arg = skip_casts(call->in(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
1120
a61af66fc99e Initial load
duke
parents:
diff changeset
1121 if (call_analyzer.is_arg_returned(i - TypeFunc::Parms)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1122 PointsToNode *arg_esp = _nodes->adr_at(arg->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1123 if (arg_esp->node_type() == PointsToNode::JavaObject)
a61af66fc99e Initial load
duke
parents:
diff changeset
1124 add_pointsto_edge(resproj->_idx, arg->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1125 else
a61af66fc99e Initial load
duke
parents:
diff changeset
1126 add_deferred_edge(resproj->_idx, arg->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1127 arg_esp->_hidden_alias = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1131 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1132 set_escape_state(call->_idx, PointsToNode::GlobalEscape);
a61af66fc99e Initial load
duke
parents:
diff changeset
1133 if (resproj != NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
1134 add_pointsto_edge(resproj->_idx, _phantom_object);
a61af66fc99e Initial load
duke
parents:
diff changeset
1135 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1136 call_analyzer.copy_dependencies(C()->dependencies());
a61af66fc99e Initial load
duke
parents:
diff changeset
1137 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1138 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1140
a61af66fc99e Initial load
duke
parents:
diff changeset
1141 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
1142 // Some other type of call, assume the worst case that the
a61af66fc99e Initial load
duke
parents:
diff changeset
1143 // returned value, if any, globally escapes.
a61af66fc99e Initial load
duke
parents:
diff changeset
1144 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1145 const TypeTuple *r = call->tf()->range();
a61af66fc99e Initial load
duke
parents:
diff changeset
1146
a61af66fc99e Initial load
duke
parents:
diff changeset
1147 if (r->cnt() > TypeFunc::Parms) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1148 const Type* ret_type = r->field_at(TypeFunc::Parms);
a61af66fc99e Initial load
duke
parents:
diff changeset
1149
a61af66fc99e Initial load
duke
parents:
diff changeset
1150 // Note: we use isa_ptr() instead of isa_oopptr() here because the
a61af66fc99e Initial load
duke
parents:
diff changeset
1151 // _multianewarray functions return a TypeRawPtr.
a61af66fc99e Initial load
duke
parents:
diff changeset
1152 if (ret_type->isa_ptr() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1153 PointsToNode *ptadr = ptnode_adr(call->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1154 ptadr->set_node_type(PointsToNode::JavaObject);
a61af66fc99e Initial load
duke
parents:
diff changeset
1155 set_escape_state(call->_idx, PointsToNode::GlobalEscape);
a61af66fc99e Initial load
duke
parents:
diff changeset
1156 if (resproj != NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
1157 add_pointsto_edge(resproj->_idx, _phantom_object);
a61af66fc99e Initial load
duke
parents:
diff changeset
1158 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1159 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1160 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1161 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1162 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1163
a61af66fc99e Initial load
duke
parents:
diff changeset
1164 void ConnectionGraph::record_for_escape_analysis(Node *n) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1165 if (_collecting) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1166 if (n->is_Phi()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1167 PhiNode *phi = n->as_Phi();
a61af66fc99e Initial load
duke
parents:
diff changeset
1168 const Type *pt = phi->type();
a61af66fc99e Initial load
duke
parents:
diff changeset
1169 if ((pt->isa_oopptr() != NULL) || pt == TypePtr::NULL_PTR) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1170 PointsToNode *ptn = ptnode_adr(phi->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1171 ptn->set_node_type(PointsToNode::LocalVar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1172 ptn->_node = n;
a61af66fc99e Initial load
duke
parents:
diff changeset
1173 _deferred.push(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
1174 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1175 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1176 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1177 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1178
a61af66fc99e Initial load
duke
parents:
diff changeset
1179 void ConnectionGraph::record_escape_work(Node *n, PhaseTransform *phase) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1180
a61af66fc99e Initial load
duke
parents:
diff changeset
1181 int opc = n->Opcode();
a61af66fc99e Initial load
duke
parents:
diff changeset
1182 PointsToNode *ptadr = ptnode_adr(n->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1183
a61af66fc99e Initial load
duke
parents:
diff changeset
1184 if (_processed.test(n->_idx))
a61af66fc99e Initial load
duke
parents:
diff changeset
1185 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1186
a61af66fc99e Initial load
duke
parents:
diff changeset
1187 ptadr->_node = n;
a61af66fc99e Initial load
duke
parents:
diff changeset
1188 if (n->is_Call()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1189 CallNode *call = n->as_Call();
a61af66fc99e Initial load
duke
parents:
diff changeset
1190 process_call_arguments(call, phase);
a61af66fc99e Initial load
duke
parents:
diff changeset
1191 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1192 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1193
a61af66fc99e Initial load
duke
parents:
diff changeset
1194 switch (opc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1195 case Op_AddP:
a61af66fc99e Initial load
duke
parents:
diff changeset
1196 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1197 Node *base = skip_casts(n->in(AddPNode::Base));
a61af66fc99e Initial load
duke
parents:
diff changeset
1198 ptadr->set_node_type(PointsToNode::Field);
a61af66fc99e Initial load
duke
parents:
diff changeset
1199
a61af66fc99e Initial load
duke
parents:
diff changeset
1200 // create a field edge to this node from everything adr could point to
a61af66fc99e Initial load
duke
parents:
diff changeset
1201 VectorSet ptset(Thread::current()->resource_area());
a61af66fc99e Initial load
duke
parents:
diff changeset
1202 PointsTo(ptset, base, phase);
a61af66fc99e Initial load
duke
parents:
diff changeset
1203 for( VectorSetI i(&ptset); i.test(); ++i ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1204 uint pt = i.elem;
a61af66fc99e Initial load
duke
parents:
diff changeset
1205 add_field_edge(pt, n->_idx, type_to_offset(phase->type(n)));
a61af66fc99e Initial load
duke
parents:
diff changeset
1206 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1207 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1208 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1209 case Op_Parm:
a61af66fc99e Initial load
duke
parents:
diff changeset
1210 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1211 ProjNode *nproj = n->as_Proj();
a61af66fc99e Initial load
duke
parents:
diff changeset
1212 uint con = nproj->_con;
a61af66fc99e Initial load
duke
parents:
diff changeset
1213 if (con < TypeFunc::Parms)
a61af66fc99e Initial load
duke
parents:
diff changeset
1214 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1215 const Type *t = nproj->in(0)->as_Start()->_domain->field_at(con);
a61af66fc99e Initial load
duke
parents:
diff changeset
1216 if (t->isa_ptr() == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
1217 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1218 ptadr->set_node_type(PointsToNode::JavaObject);
a61af66fc99e Initial load
duke
parents:
diff changeset
1219 if (t->isa_oopptr() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1220 set_escape_state(n->_idx, PointsToNode::ArgEscape);
a61af66fc99e Initial load
duke
parents:
diff changeset
1221 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1222 // this must be the incoming state of an OSR compile, we have to assume anything
a61af66fc99e Initial load
duke
parents:
diff changeset
1223 // passed in globally escapes
a61af66fc99e Initial load
duke
parents:
diff changeset
1224 assert(_compile->is_osr_compilation(), "bad argument type for non-osr compilation");
a61af66fc99e Initial load
duke
parents:
diff changeset
1225 set_escape_state(n->_idx, PointsToNode::GlobalEscape);
a61af66fc99e Initial load
duke
parents:
diff changeset
1226 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1227 _processed.set(n->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1228 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1229 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1230 case Op_Phi:
a61af66fc99e Initial load
duke
parents:
diff changeset
1231 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1232 PhiNode *phi = n->as_Phi();
a61af66fc99e Initial load
duke
parents:
diff changeset
1233 if (phi->type()->isa_oopptr() == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
1234 return; // nothing to do if not an oop
a61af66fc99e Initial load
duke
parents:
diff changeset
1235 ptadr->set_node_type(PointsToNode::LocalVar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1236 process_phi_escape(phi, phase);
a61af66fc99e Initial load
duke
parents:
diff changeset
1237 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1238 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1239 case Op_CreateEx:
a61af66fc99e Initial load
duke
parents:
diff changeset
1240 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1241 // assume that all exception objects globally escape
a61af66fc99e Initial load
duke
parents:
diff changeset
1242 ptadr->set_node_type(PointsToNode::JavaObject);
a61af66fc99e Initial load
duke
parents:
diff changeset
1243 set_escape_state(n->_idx, PointsToNode::GlobalEscape);
a61af66fc99e Initial load
duke
parents:
diff changeset
1244 _processed.set(n->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1245 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1246 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1247 case Op_ConP:
a61af66fc99e Initial load
duke
parents:
diff changeset
1248 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1249 const Type *t = phase->type(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
1250 ptadr->set_node_type(PointsToNode::JavaObject);
a61af66fc99e Initial load
duke
parents:
diff changeset
1251 // assume all pointer constants globally escape except for null
a61af66fc99e Initial load
duke
parents:
diff changeset
1252 if (t == TypePtr::NULL_PTR)
a61af66fc99e Initial load
duke
parents:
diff changeset
1253 set_escape_state(n->_idx, PointsToNode::NoEscape);
a61af66fc99e Initial load
duke
parents:
diff changeset
1254 else
a61af66fc99e Initial load
duke
parents:
diff changeset
1255 set_escape_state(n->_idx, PointsToNode::GlobalEscape);
a61af66fc99e Initial load
duke
parents:
diff changeset
1256 _processed.set(n->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1257 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1258 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1259 case Op_LoadKlass:
a61af66fc99e Initial load
duke
parents:
diff changeset
1260 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1261 ptadr->set_node_type(PointsToNode::JavaObject);
a61af66fc99e Initial load
duke
parents:
diff changeset
1262 set_escape_state(n->_idx, PointsToNode::GlobalEscape);
a61af66fc99e Initial load
duke
parents:
diff changeset
1263 _processed.set(n->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1264 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1265 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1266 case Op_LoadP:
a61af66fc99e Initial load
duke
parents:
diff changeset
1267 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1268 const Type *t = phase->type(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
1269 if (!t->isa_oopptr())
a61af66fc99e Initial load
duke
parents:
diff changeset
1270 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1271 ptadr->set_node_type(PointsToNode::LocalVar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1272 set_escape_state(n->_idx, PointsToNode::UnknownEscape);
a61af66fc99e Initial load
duke
parents:
diff changeset
1273
a61af66fc99e Initial load
duke
parents:
diff changeset
1274 Node *adr = skip_casts(n->in(MemNode::Address));
a61af66fc99e Initial load
duke
parents:
diff changeset
1275 const Type *adr_type = phase->type(adr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1276 Node *adr_base = skip_casts((adr->Opcode() == Op_AddP) ? adr->in(AddPNode::Base) : adr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1277
a61af66fc99e Initial load
duke
parents:
diff changeset
1278 // For everything "adr" could point to, create a deferred edge from
a61af66fc99e Initial load
duke
parents:
diff changeset
1279 // this node to each field with the same offset as "adr_type"
a61af66fc99e Initial load
duke
parents:
diff changeset
1280 VectorSet ptset(Thread::current()->resource_area());
a61af66fc99e Initial load
duke
parents:
diff changeset
1281 PointsTo(ptset, adr_base, phase);
a61af66fc99e Initial load
duke
parents:
diff changeset
1282 // If ptset is empty, then this value must have been set outside
a61af66fc99e Initial load
duke
parents:
diff changeset
1283 // this method, so we add the phantom node
a61af66fc99e Initial load
duke
parents:
diff changeset
1284 if (ptset.Size() == 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
1285 ptset.set(_phantom_object);
a61af66fc99e Initial load
duke
parents:
diff changeset
1286 for( VectorSetI i(&ptset); i.test(); ++i ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1287 uint pt = i.elem;
a61af66fc99e Initial load
duke
parents:
diff changeset
1288 add_deferred_edge_to_fields(n->_idx, pt, type_to_offset(adr_type));
a61af66fc99e Initial load
duke
parents:
diff changeset
1289 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1290 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1291 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1292 case Op_StoreP:
a61af66fc99e Initial load
duke
parents:
diff changeset
1293 case Op_StorePConditional:
a61af66fc99e Initial load
duke
parents:
diff changeset
1294 case Op_CompareAndSwapP:
a61af66fc99e Initial load
duke
parents:
diff changeset
1295 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1296 Node *adr = n->in(MemNode::Address);
a61af66fc99e Initial load
duke
parents:
diff changeset
1297 Node *val = skip_casts(n->in(MemNode::ValueIn));
a61af66fc99e Initial load
duke
parents:
diff changeset
1298 const Type *adr_type = phase->type(adr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1299 if (!adr_type->isa_oopptr())
a61af66fc99e Initial load
duke
parents:
diff changeset
1300 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1301
a61af66fc99e Initial load
duke
parents:
diff changeset
1302 assert(adr->Opcode() == Op_AddP, "expecting an AddP");
a61af66fc99e Initial load
duke
parents:
diff changeset
1303 Node *adr_base = adr->in(AddPNode::Base);
a61af66fc99e Initial load
duke
parents:
diff changeset
1304
a61af66fc99e Initial load
duke
parents:
diff changeset
1305 // For everything "adr_base" could point to, create a deferred edge to "val" from each field
a61af66fc99e Initial load
duke
parents:
diff changeset
1306 // with the same offset as "adr_type"
a61af66fc99e Initial load
duke
parents:
diff changeset
1307 VectorSet ptset(Thread::current()->resource_area());
a61af66fc99e Initial load
duke
parents:
diff changeset
1308 PointsTo(ptset, adr_base, phase);
a61af66fc99e Initial load
duke
parents:
diff changeset
1309 for( VectorSetI i(&ptset); i.test(); ++i ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1310 uint pt = i.elem;
a61af66fc99e Initial load
duke
parents:
diff changeset
1311 add_edge_from_fields(pt, val->_idx, type_to_offset(adr_type));
a61af66fc99e Initial load
duke
parents:
diff changeset
1312 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1313 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1314 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1315 case Op_Proj:
a61af66fc99e Initial load
duke
parents:
diff changeset
1316 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1317 ProjNode *nproj = n->as_Proj();
a61af66fc99e Initial load
duke
parents:
diff changeset
1318 Node *n0 = nproj->in(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
1319 // we are only interested in the result projection from a call
a61af66fc99e Initial load
duke
parents:
diff changeset
1320 if (nproj->_con == TypeFunc::Parms && n0->is_Call() ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1321 process_call_result(nproj, phase);
a61af66fc99e Initial load
duke
parents:
diff changeset
1322 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1323
a61af66fc99e Initial load
duke
parents:
diff changeset
1324 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1325 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1326 case Op_CastPP:
a61af66fc99e Initial load
duke
parents:
diff changeset
1327 case Op_CheckCastPP:
a61af66fc99e Initial load
duke
parents:
diff changeset
1328 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1329 ptadr->set_node_type(PointsToNode::LocalVar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1330 int ti = n->in(1)->_idx;
a61af66fc99e Initial load
duke
parents:
diff changeset
1331 if (_nodes->at(ti).node_type() == PointsToNode::JavaObject) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1332 add_pointsto_edge(n->_idx, ti);
a61af66fc99e Initial load
duke
parents:
diff changeset
1333 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1334 add_deferred_edge(n->_idx, ti);
a61af66fc99e Initial load
duke
parents:
diff changeset
1335 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1336 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1337 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1338 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
1339 ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1340 // nothing to do
a61af66fc99e Initial load
duke
parents:
diff changeset
1341 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1342 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1343
a61af66fc99e Initial load
duke
parents:
diff changeset
1344 void ConnectionGraph::record_escape(Node *n, PhaseTransform *phase) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1345 if (_collecting)
a61af66fc99e Initial load
duke
parents:
diff changeset
1346 record_escape_work(n, phase);
a61af66fc99e Initial load
duke
parents:
diff changeset
1347 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1348
a61af66fc99e Initial load
duke
parents:
diff changeset
1349 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
1350 void ConnectionGraph::dump() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1351 PhaseGVN *igvn = _compile->initial_gvn();
a61af66fc99e Initial load
duke
parents:
diff changeset
1352 bool first = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1353
a61af66fc99e Initial load
duke
parents:
diff changeset
1354 for (uint ni = 0; ni < (uint)_nodes->length(); ni++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1355 PointsToNode *esp = _nodes->adr_at(ni);
a61af66fc99e Initial load
duke
parents:
diff changeset
1356 if (esp->node_type() == PointsToNode::UnknownType || esp->_node == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
1357 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1358 PointsToNode::EscapeState es = escape_state(esp->_node, igvn);
a61af66fc99e Initial load
duke
parents:
diff changeset
1359 if (es == PointsToNode::NoEscape || (Verbose &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1360 (es != PointsToNode::UnknownEscape || esp->edge_count() != 0))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1361 // don't print null pointer node which almost every method has
a61af66fc99e Initial load
duke
parents:
diff changeset
1362 if (esp->_node->Opcode() != Op_ConP || igvn->type(esp->_node) != TypePtr::NULL_PTR) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1363 if (first) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1364 tty->print("======== Connection graph for ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1365 C()->method()->print_short_name();
a61af66fc99e Initial load
duke
parents:
diff changeset
1366 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
1367 first = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1368 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1369 tty->print("%4d ", ni);
a61af66fc99e Initial load
duke
parents:
diff changeset
1370 esp->dump();
a61af66fc99e Initial load
duke
parents:
diff changeset
1371 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1372 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1373 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1374 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1375 #endif