annotate src/share/vm/opto/escape.cpp @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children b789bcaf2dd9
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 }
a61af66fc99e Initial load
duke
parents:
diff changeset
398
a61af66fc99e Initial load
duke
parents:
diff changeset
399 orig_phi_worklist.append_if_missing(orig_phi);
a61af66fc99e Initial load
duke
parents:
diff changeset
400 result = PhiNode::make(orig_phi->in(0), NULL, Type::MEMORY, atype);
a61af66fc99e Initial load
duke
parents:
diff changeset
401 set_map_phi(orig_phi->_idx, result);
a61af66fc99e Initial load
duke
parents:
diff changeset
402 igvn->set_type(result, result->bottom_type());
a61af66fc99e Initial load
duke
parents:
diff changeset
403 record_for_optimizer(result);
a61af66fc99e Initial load
duke
parents:
diff changeset
404 new_created = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
405 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
406 }
a61af66fc99e Initial load
duke
parents:
diff changeset
407
a61af66fc99e Initial load
duke
parents:
diff changeset
408 //
a61af66fc99e Initial load
duke
parents:
diff changeset
409 // Return a new version of Memory Phi "orig_phi" with the inputs having the
a61af66fc99e Initial load
duke
parents:
diff changeset
410 // specified alias index.
a61af66fc99e Initial load
duke
parents:
diff changeset
411 //
a61af66fc99e Initial load
duke
parents:
diff changeset
412 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
413
a61af66fc99e Initial load
duke
parents:
diff changeset
414 assert(alias_idx != Compile::AliasIdxBot, "can't split out bottom memory");
a61af66fc99e Initial load
duke
parents:
diff changeset
415 Compile *C = _compile;
a61af66fc99e Initial load
duke
parents:
diff changeset
416 bool new_phi_created;
a61af66fc99e Initial load
duke
parents:
diff changeset
417 PhiNode *result = create_split_phi(orig_phi, alias_idx, orig_phi_worklist, igvn, new_phi_created);
a61af66fc99e Initial load
duke
parents:
diff changeset
418 if (!new_phi_created) {
a61af66fc99e Initial load
duke
parents:
diff changeset
419 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
420 }
a61af66fc99e Initial load
duke
parents:
diff changeset
421
a61af66fc99e Initial load
duke
parents:
diff changeset
422 GrowableArray<PhiNode *> phi_list;
a61af66fc99e Initial load
duke
parents:
diff changeset
423 GrowableArray<uint> cur_input;
a61af66fc99e Initial load
duke
parents:
diff changeset
424
a61af66fc99e Initial load
duke
parents:
diff changeset
425 PhiNode *phi = orig_phi;
a61af66fc99e Initial load
duke
parents:
diff changeset
426 uint idx = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
427 bool finished = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
428 while(!finished) {
a61af66fc99e Initial load
duke
parents:
diff changeset
429 while (idx < phi->req()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
430 Node *mem = find_mem(phi->in(idx), alias_idx, igvn);
a61af66fc99e Initial load
duke
parents:
diff changeset
431 if (mem != NULL && mem->is_Phi()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
432 PhiNode *nphi = create_split_phi(mem->as_Phi(), alias_idx, orig_phi_worklist, igvn, new_phi_created);
a61af66fc99e Initial load
duke
parents:
diff changeset
433 if (new_phi_created) {
a61af66fc99e Initial load
duke
parents:
diff changeset
434 // found an phi for which we created a new split, push current one on worklist and begin
a61af66fc99e Initial load
duke
parents:
diff changeset
435 // processing new one
a61af66fc99e Initial load
duke
parents:
diff changeset
436 phi_list.push(phi);
a61af66fc99e Initial load
duke
parents:
diff changeset
437 cur_input.push(idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
438 phi = mem->as_Phi();
a61af66fc99e Initial load
duke
parents:
diff changeset
439 result = nphi;
a61af66fc99e Initial load
duke
parents:
diff changeset
440 idx = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
441 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
442 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
443 mem = nphi;
a61af66fc99e Initial load
duke
parents:
diff changeset
444 }
a61af66fc99e Initial load
duke
parents:
diff changeset
445 }
a61af66fc99e Initial load
duke
parents:
diff changeset
446 result->set_req(idx++, mem);
a61af66fc99e Initial load
duke
parents:
diff changeset
447 }
a61af66fc99e Initial load
duke
parents:
diff changeset
448 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
449 // verify that the new Phi has an input for each input of the original
a61af66fc99e Initial load
duke
parents:
diff changeset
450 assert( phi->req() == result->req(), "must have same number of inputs.");
a61af66fc99e Initial load
duke
parents:
diff changeset
451 assert( result->in(0) != NULL && result->in(0) == phi->in(0), "regions must match");
a61af66fc99e Initial load
duke
parents:
diff changeset
452 for (uint i = 1; i < phi->req(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
453 assert((phi->in(i) == NULL) == (result->in(i) == NULL), "inputs must correspond.");
a61af66fc99e Initial load
duke
parents:
diff changeset
454 }
a61af66fc99e Initial load
duke
parents:
diff changeset
455 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
456 // we have finished processing a Phi, see if there are any more to do
a61af66fc99e Initial load
duke
parents:
diff changeset
457 finished = (phi_list.length() == 0 );
a61af66fc99e Initial load
duke
parents:
diff changeset
458 if (!finished) {
a61af66fc99e Initial load
duke
parents:
diff changeset
459 phi = phi_list.pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
460 idx = cur_input.pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
461 PhiNode *prev_phi = get_map_phi(phi->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
462 prev_phi->set_req(idx++, result);
a61af66fc99e Initial load
duke
parents:
diff changeset
463 result = prev_phi;
a61af66fc99e Initial load
duke
parents:
diff changeset
464 }
a61af66fc99e Initial load
duke
parents:
diff changeset
465 }
a61af66fc99e Initial load
duke
parents:
diff changeset
466 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
467 }
a61af66fc99e Initial load
duke
parents:
diff changeset
468
a61af66fc99e Initial load
duke
parents:
diff changeset
469 //
a61af66fc99e Initial load
duke
parents:
diff changeset
470 // Convert the types of unescaped object to instance types where possible,
a61af66fc99e Initial load
duke
parents:
diff changeset
471 // propagate the new type information through the graph, and update memory
a61af66fc99e Initial load
duke
parents:
diff changeset
472 // edges and MergeMem inputs to reflect the new type.
a61af66fc99e Initial load
duke
parents:
diff changeset
473 //
a61af66fc99e Initial load
duke
parents:
diff changeset
474 // We start with allocations (and calls which may be allocations) on alloc_worklist.
a61af66fc99e Initial load
duke
parents:
diff changeset
475 // The processing is done in 4 phases:
a61af66fc99e Initial load
duke
parents:
diff changeset
476 //
a61af66fc99e Initial load
duke
parents:
diff changeset
477 // Phase 1: Process possible allocations from alloc_worklist. Create instance
a61af66fc99e Initial load
duke
parents:
diff changeset
478 // types for the CheckCastPP for allocations where possible.
a61af66fc99e Initial load
duke
parents:
diff changeset
479 // Propagate the the new types through users as follows:
a61af66fc99e Initial load
duke
parents:
diff changeset
480 // casts and Phi: push users on alloc_worklist
a61af66fc99e Initial load
duke
parents:
diff changeset
481 // AddP: cast Base and Address inputs to the instance type
a61af66fc99e Initial load
duke
parents:
diff changeset
482 // push any AddP users on alloc_worklist and push any memnode
a61af66fc99e Initial load
duke
parents:
diff changeset
483 // users onto memnode_worklist.
a61af66fc99e Initial load
duke
parents:
diff changeset
484 // Phase 2: Process MemNode's from memnode_worklist. compute new address type and
a61af66fc99e Initial load
duke
parents:
diff changeset
485 // search the Memory chain for a store with the appropriate type
a61af66fc99e Initial load
duke
parents:
diff changeset
486 // address type. If a Phi is found, create a new version with
a61af66fc99e Initial load
duke
parents:
diff changeset
487 // the approriate memory slices from each of the Phi inputs.
a61af66fc99e Initial load
duke
parents:
diff changeset
488 // For stores, process the users as follows:
a61af66fc99e Initial load
duke
parents:
diff changeset
489 // MemNode: push on memnode_worklist
a61af66fc99e Initial load
duke
parents:
diff changeset
490 // MergeMem: push on mergemem_worklist
a61af66fc99e Initial load
duke
parents:
diff changeset
491 // Phase 3: Process MergeMem nodes from mergemem_worklist. Walk each memory slice
a61af66fc99e Initial load
duke
parents:
diff changeset
492 // moving the first node encountered of each instance type to the
a61af66fc99e Initial load
duke
parents:
diff changeset
493 // the input corresponding to its alias index.
a61af66fc99e Initial load
duke
parents:
diff changeset
494 // appropriate memory slice.
a61af66fc99e Initial load
duke
parents:
diff changeset
495 // Phase 4: Update the inputs of non-instance memory Phis and the Memory input of memnodes.
a61af66fc99e Initial load
duke
parents:
diff changeset
496 //
a61af66fc99e Initial load
duke
parents:
diff changeset
497 // In the following example, the CheckCastPP nodes are the cast of allocation
a61af66fc99e Initial load
duke
parents:
diff changeset
498 // results and the allocation of node 29 is unescaped and eligible to be an
a61af66fc99e Initial load
duke
parents:
diff changeset
499 // instance type.
a61af66fc99e Initial load
duke
parents:
diff changeset
500 //
a61af66fc99e Initial load
duke
parents:
diff changeset
501 // We start with:
a61af66fc99e Initial load
duke
parents:
diff changeset
502 //
a61af66fc99e Initial load
duke
parents:
diff changeset
503 // 7 Parm #memory
a61af66fc99e Initial load
duke
parents:
diff changeset
504 // 10 ConI "12"
a61af66fc99e Initial load
duke
parents:
diff changeset
505 // 19 CheckCastPP "Foo"
a61af66fc99e Initial load
duke
parents:
diff changeset
506 // 20 AddP _ 19 19 10 Foo+12 alias_index=4
a61af66fc99e Initial load
duke
parents:
diff changeset
507 // 29 CheckCastPP "Foo"
a61af66fc99e Initial load
duke
parents:
diff changeset
508 // 30 AddP _ 29 29 10 Foo+12 alias_index=4
a61af66fc99e Initial load
duke
parents:
diff changeset
509 //
a61af66fc99e Initial load
duke
parents:
diff changeset
510 // 40 StoreP 25 7 20 ... alias_index=4
a61af66fc99e Initial load
duke
parents:
diff changeset
511 // 50 StoreP 35 40 30 ... alias_index=4
a61af66fc99e Initial load
duke
parents:
diff changeset
512 // 60 StoreP 45 50 20 ... alias_index=4
a61af66fc99e Initial load
duke
parents:
diff changeset
513 // 70 LoadP _ 60 30 ... alias_index=4
a61af66fc99e Initial load
duke
parents:
diff changeset
514 // 80 Phi 75 50 60 Memory alias_index=4
a61af66fc99e Initial load
duke
parents:
diff changeset
515 // 90 LoadP _ 80 30 ... alias_index=4
a61af66fc99e Initial load
duke
parents:
diff changeset
516 // 100 LoadP _ 80 20 ... alias_index=4
a61af66fc99e Initial load
duke
parents:
diff changeset
517 //
a61af66fc99e Initial load
duke
parents:
diff changeset
518 //
a61af66fc99e Initial load
duke
parents:
diff changeset
519 // Phase 1 creates an instance type for node 29 assigning it an instance id of 24
a61af66fc99e Initial load
duke
parents:
diff changeset
520 // and creating a new alias index for node 30. This gives:
a61af66fc99e Initial load
duke
parents:
diff changeset
521 //
a61af66fc99e Initial load
duke
parents:
diff changeset
522 // 7 Parm #memory
a61af66fc99e Initial load
duke
parents:
diff changeset
523 // 10 ConI "12"
a61af66fc99e Initial load
duke
parents:
diff changeset
524 // 19 CheckCastPP "Foo"
a61af66fc99e Initial load
duke
parents:
diff changeset
525 // 20 AddP _ 19 19 10 Foo+12 alias_index=4
a61af66fc99e Initial load
duke
parents:
diff changeset
526 // 29 CheckCastPP "Foo" iid=24
a61af66fc99e Initial load
duke
parents:
diff changeset
527 // 30 AddP _ 29 29 10 Foo+12 alias_index=6 iid=24
a61af66fc99e Initial load
duke
parents:
diff changeset
528 //
a61af66fc99e Initial load
duke
parents:
diff changeset
529 // 40 StoreP 25 7 20 ... alias_index=4
a61af66fc99e Initial load
duke
parents:
diff changeset
530 // 50 StoreP 35 40 30 ... alias_index=6
a61af66fc99e Initial load
duke
parents:
diff changeset
531 // 60 StoreP 45 50 20 ... alias_index=4
a61af66fc99e Initial load
duke
parents:
diff changeset
532 // 70 LoadP _ 60 30 ... alias_index=6
a61af66fc99e Initial load
duke
parents:
diff changeset
533 // 80 Phi 75 50 60 Memory alias_index=4
a61af66fc99e Initial load
duke
parents:
diff changeset
534 // 90 LoadP _ 80 30 ... alias_index=6
a61af66fc99e Initial load
duke
parents:
diff changeset
535 // 100 LoadP _ 80 20 ... alias_index=4
a61af66fc99e Initial load
duke
parents:
diff changeset
536 //
a61af66fc99e Initial load
duke
parents:
diff changeset
537 // In phase 2, new memory inputs are computed for the loads and stores,
a61af66fc99e Initial load
duke
parents:
diff changeset
538 // And a new version of the phi is created. In phase 4, the inputs to
a61af66fc99e Initial load
duke
parents:
diff changeset
539 // node 80 are updated and then the memory nodes are updated with the
a61af66fc99e Initial load
duke
parents:
diff changeset
540 // values computed in phase 2. This results in:
a61af66fc99e Initial load
duke
parents:
diff changeset
541 //
a61af66fc99e Initial load
duke
parents:
diff changeset
542 // 7 Parm #memory
a61af66fc99e Initial load
duke
parents:
diff changeset
543 // 10 ConI "12"
a61af66fc99e Initial load
duke
parents:
diff changeset
544 // 19 CheckCastPP "Foo"
a61af66fc99e Initial load
duke
parents:
diff changeset
545 // 20 AddP _ 19 19 10 Foo+12 alias_index=4
a61af66fc99e Initial load
duke
parents:
diff changeset
546 // 29 CheckCastPP "Foo" iid=24
a61af66fc99e Initial load
duke
parents:
diff changeset
547 // 30 AddP _ 29 29 10 Foo+12 alias_index=6 iid=24
a61af66fc99e Initial load
duke
parents:
diff changeset
548 //
a61af66fc99e Initial load
duke
parents:
diff changeset
549 // 40 StoreP 25 7 20 ... alias_index=4
a61af66fc99e Initial load
duke
parents:
diff changeset
550 // 50 StoreP 35 7 30 ... alias_index=6
a61af66fc99e Initial load
duke
parents:
diff changeset
551 // 60 StoreP 45 40 20 ... alias_index=4
a61af66fc99e Initial load
duke
parents:
diff changeset
552 // 70 LoadP _ 50 30 ... alias_index=6
a61af66fc99e Initial load
duke
parents:
diff changeset
553 // 80 Phi 75 40 60 Memory alias_index=4
a61af66fc99e Initial load
duke
parents:
diff changeset
554 // 120 Phi 75 50 50 Memory alias_index=6
a61af66fc99e Initial load
duke
parents:
diff changeset
555 // 90 LoadP _ 120 30 ... alias_index=6
a61af66fc99e Initial load
duke
parents:
diff changeset
556 // 100 LoadP _ 80 20 ... alias_index=4
a61af66fc99e Initial load
duke
parents:
diff changeset
557 //
a61af66fc99e Initial load
duke
parents:
diff changeset
558 void ConnectionGraph::split_unique_types(GrowableArray<Node *> &alloc_worklist) {
a61af66fc99e Initial load
duke
parents:
diff changeset
559 GrowableArray<Node *> memnode_worklist;
a61af66fc99e Initial load
duke
parents:
diff changeset
560 GrowableArray<Node *> mergemem_worklist;
a61af66fc99e Initial load
duke
parents:
diff changeset
561 GrowableArray<PhiNode *> orig_phis;
a61af66fc99e Initial load
duke
parents:
diff changeset
562 PhaseGVN *igvn = _compile->initial_gvn();
a61af66fc99e Initial load
duke
parents:
diff changeset
563 uint new_index_start = (uint) _compile->num_alias_types();
a61af66fc99e Initial load
duke
parents:
diff changeset
564 VectorSet visited(Thread::current()->resource_area());
a61af66fc99e Initial load
duke
parents:
diff changeset
565 VectorSet ptset(Thread::current()->resource_area());
a61af66fc99e Initial load
duke
parents:
diff changeset
566
a61af66fc99e Initial load
duke
parents:
diff changeset
567 // Phase 1: Process possible allocations from alloc_worklist. Create instance
a61af66fc99e Initial load
duke
parents:
diff changeset
568 // types for the CheckCastPP for allocations where possible.
a61af66fc99e Initial load
duke
parents:
diff changeset
569 while (alloc_worklist.length() != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
570 Node *n = alloc_worklist.pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
571 uint ni = n->_idx;
a61af66fc99e Initial load
duke
parents:
diff changeset
572 if (n->is_Call()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
573 CallNode *alloc = n->as_Call();
a61af66fc99e Initial load
duke
parents:
diff changeset
574 // copy escape information to call node
a61af66fc99e Initial load
duke
parents:
diff changeset
575 PointsToNode ptn = _nodes->at(alloc->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
576 PointsToNode::EscapeState es = escape_state(alloc, igvn);
a61af66fc99e Initial load
duke
parents:
diff changeset
577 alloc->_escape_state = es;
a61af66fc99e Initial load
duke
parents:
diff changeset
578 // find CheckCastPP of call return value
a61af66fc99e Initial load
duke
parents:
diff changeset
579 n = alloc->proj_out(TypeFunc::Parms);
a61af66fc99e Initial load
duke
parents:
diff changeset
580 if (n != NULL && n->outcnt() == 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
581 n = n->unique_out();
a61af66fc99e Initial load
duke
parents:
diff changeset
582 if (n->Opcode() != Op_CheckCastPP) {
a61af66fc99e Initial load
duke
parents:
diff changeset
583 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
584 }
a61af66fc99e Initial load
duke
parents:
diff changeset
585 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
586 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
587 }
a61af66fc99e Initial load
duke
parents:
diff changeset
588 // we have an allocation or call which returns a Java object, see if it is unescaped
a61af66fc99e Initial load
duke
parents:
diff changeset
589 if (es != PointsToNode::NoEscape || !ptn._unique_type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
590 continue; // can't make a unique type
a61af66fc99e Initial load
duke
parents:
diff changeset
591 }
a61af66fc99e Initial load
duke
parents:
diff changeset
592 set_map(alloc->_idx, n);
a61af66fc99e Initial load
duke
parents:
diff changeset
593 set_map(n->_idx, alloc);
a61af66fc99e Initial load
duke
parents:
diff changeset
594 const TypeInstPtr *t = igvn->type(n)->isa_instptr();
a61af66fc99e Initial load
duke
parents:
diff changeset
595 // Unique types which are arrays are not currently supported.
a61af66fc99e Initial load
duke
parents:
diff changeset
596 // The check for AllocateArray is needed in case an array
a61af66fc99e Initial load
duke
parents:
diff changeset
597 // allocation is immediately cast to Object
a61af66fc99e Initial load
duke
parents:
diff changeset
598 if (t == NULL || alloc->is_AllocateArray())
a61af66fc99e Initial load
duke
parents:
diff changeset
599 continue; // not a TypeInstPtr
a61af66fc99e Initial load
duke
parents:
diff changeset
600 const TypeOopPtr *tinst = t->cast_to_instance(ni);
a61af66fc99e Initial load
duke
parents:
diff changeset
601 igvn->hash_delete(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
602 igvn->set_type(n, tinst);
a61af66fc99e Initial load
duke
parents:
diff changeset
603 n->raise_bottom_type(tinst);
a61af66fc99e Initial load
duke
parents:
diff changeset
604 igvn->hash_insert(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
605 } else if (n->is_AddP()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
606 ptset.Clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
607 PointsTo(ptset, n->in(AddPNode::Address), igvn);
a61af66fc99e Initial load
duke
parents:
diff changeset
608 assert(ptset.Size() == 1, "AddP address is unique");
a61af66fc99e Initial load
duke
parents:
diff changeset
609 Node *base = get_map(ptset.getelem());
a61af66fc99e Initial load
duke
parents:
diff changeset
610 split_AddP(n, base, igvn);
a61af66fc99e Initial load
duke
parents:
diff changeset
611 } else if (n->is_Phi() || n->Opcode() == Op_CastPP || n->Opcode() == Op_CheckCastPP) {
a61af66fc99e Initial load
duke
parents:
diff changeset
612 if (visited.test_set(n->_idx)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
613 assert(n->is_Phi(), "loops only through Phi's");
a61af66fc99e Initial load
duke
parents:
diff changeset
614 continue; // already processed
a61af66fc99e Initial load
duke
parents:
diff changeset
615 }
a61af66fc99e Initial load
duke
parents:
diff changeset
616 ptset.Clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
617 PointsTo(ptset, n, igvn);
a61af66fc99e Initial load
duke
parents:
diff changeset
618 if (ptset.Size() == 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
619 TypeNode *tn = n->as_Type();
a61af66fc99e Initial load
duke
parents:
diff changeset
620 Node *val = get_map(ptset.getelem());
a61af66fc99e Initial load
duke
parents:
diff changeset
621 const TypeInstPtr *val_t = igvn->type(val)->isa_instptr();;
a61af66fc99e Initial load
duke
parents:
diff changeset
622 assert(val_t != NULL && val_t->is_instance(), "instance type expected.");
a61af66fc99e Initial load
duke
parents:
diff changeset
623 const TypeInstPtr *tn_t = igvn->type(tn)->isa_instptr();;
a61af66fc99e Initial load
duke
parents:
diff changeset
624
a61af66fc99e Initial load
duke
parents:
diff changeset
625 if (tn_t != NULL && val_t->cast_to_instance(TypeOopPtr::UNKNOWN_INSTANCE)->higher_equal(tn_t)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
626 igvn->hash_delete(tn);
a61af66fc99e Initial load
duke
parents:
diff changeset
627 igvn->set_type(tn, val_t);
a61af66fc99e Initial load
duke
parents:
diff changeset
628 tn->set_type(val_t);
a61af66fc99e Initial load
duke
parents:
diff changeset
629 igvn->hash_insert(tn);
a61af66fc99e Initial load
duke
parents:
diff changeset
630 }
a61af66fc99e Initial load
duke
parents:
diff changeset
631 }
a61af66fc99e Initial load
duke
parents:
diff changeset
632 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
633 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
634 }
a61af66fc99e Initial load
duke
parents:
diff changeset
635 // push users on appropriate worklist
a61af66fc99e Initial load
duke
parents:
diff changeset
636 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
637 Node *use = n->fast_out(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
638 if(use->is_Mem() && use->in(MemNode::Address) == n) {
a61af66fc99e Initial load
duke
parents:
diff changeset
639 memnode_worklist.push(use);
a61af66fc99e Initial load
duke
parents:
diff changeset
640 } else if (use->is_AddP() || use->is_Phi() || use->Opcode() == Op_CastPP || use->Opcode() == Op_CheckCastPP) {
a61af66fc99e Initial load
duke
parents:
diff changeset
641 alloc_worklist.push(use);
a61af66fc99e Initial load
duke
parents:
diff changeset
642 }
a61af66fc99e Initial load
duke
parents:
diff changeset
643 }
a61af66fc99e Initial load
duke
parents:
diff changeset
644
a61af66fc99e Initial load
duke
parents:
diff changeset
645 }
a61af66fc99e Initial load
duke
parents:
diff changeset
646 uint new_index_end = (uint) _compile->num_alias_types();
a61af66fc99e Initial load
duke
parents:
diff changeset
647
a61af66fc99e Initial load
duke
parents:
diff changeset
648 // Phase 2: Process MemNode's from memnode_worklist. compute new address type and
a61af66fc99e Initial load
duke
parents:
diff changeset
649 // compute new values for Memory inputs (the Memory inputs are not
a61af66fc99e Initial load
duke
parents:
diff changeset
650 // actually updated until phase 4.)
a61af66fc99e Initial load
duke
parents:
diff changeset
651 if (memnode_worklist.length() == 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
652 return; // nothing to do
a61af66fc99e Initial load
duke
parents:
diff changeset
653
a61af66fc99e Initial load
duke
parents:
diff changeset
654
a61af66fc99e Initial load
duke
parents:
diff changeset
655 while (memnode_worklist.length() != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
656 Node *n = memnode_worklist.pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
657 if (n->is_Phi()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
658 assert(n->as_Phi()->adr_type() != TypePtr::BOTTOM, "narrow memory slice required");
a61af66fc99e Initial load
duke
parents:
diff changeset
659 // 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
660 // this Phi before
a61af66fc99e Initial load
duke
parents:
diff changeset
661 if (visited.test_set(n->_idx))
a61af66fc99e Initial load
duke
parents:
diff changeset
662 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
663 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
664 assert(n->is_Mem(), "memory node required.");
a61af66fc99e Initial load
duke
parents:
diff changeset
665 Node *addr = n->in(MemNode::Address);
a61af66fc99e Initial load
duke
parents:
diff changeset
666 const Type *addr_t = igvn->type(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
667 if (addr_t == Type::TOP)
a61af66fc99e Initial load
duke
parents:
diff changeset
668 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
669 assert (addr_t->isa_ptr() != NULL, "pointer type required.");
a61af66fc99e Initial load
duke
parents:
diff changeset
670 int alias_idx = _compile->get_alias_index(addr_t->is_ptr());
a61af66fc99e Initial load
duke
parents:
diff changeset
671 Node *mem = find_mem(n->in(MemNode::Memory), alias_idx, igvn);
a61af66fc99e Initial load
duke
parents:
diff changeset
672 if (mem->is_Phi()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
673 mem = split_memory_phi(mem->as_Phi(), alias_idx, orig_phis, igvn);
a61af66fc99e Initial load
duke
parents:
diff changeset
674 }
a61af66fc99e Initial load
duke
parents:
diff changeset
675 if (mem != n->in(MemNode::Memory))
a61af66fc99e Initial load
duke
parents:
diff changeset
676 set_map(n->_idx, mem);
a61af66fc99e Initial load
duke
parents:
diff changeset
677 if (n->is_Load()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
678 continue; // don't push users
a61af66fc99e Initial load
duke
parents:
diff changeset
679 } else if (n->is_LoadStore()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
680 // get the memory projection
a61af66fc99e Initial load
duke
parents:
diff changeset
681 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
682 Node *use = n->fast_out(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
683 if (use->Opcode() == Op_SCMemProj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
684 n = use;
a61af66fc99e Initial load
duke
parents:
diff changeset
685 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
686 }
a61af66fc99e Initial load
duke
parents:
diff changeset
687 }
a61af66fc99e Initial load
duke
parents:
diff changeset
688 assert(n->Opcode() == Op_SCMemProj, "memory projection required");
a61af66fc99e Initial load
duke
parents:
diff changeset
689 }
a61af66fc99e Initial load
duke
parents:
diff changeset
690 }
a61af66fc99e Initial load
duke
parents:
diff changeset
691 // push user on appropriate worklist
a61af66fc99e Initial load
duke
parents:
diff changeset
692 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
693 Node *use = n->fast_out(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
694 if (use->is_Phi()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
695 memnode_worklist.push(use);
a61af66fc99e Initial load
duke
parents:
diff changeset
696 } else if(use->is_Mem() && use->in(MemNode::Memory) == n) {
a61af66fc99e Initial load
duke
parents:
diff changeset
697 memnode_worklist.push(use);
a61af66fc99e Initial load
duke
parents:
diff changeset
698 } else if (use->is_MergeMem()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
699 mergemem_worklist.push(use);
a61af66fc99e Initial load
duke
parents:
diff changeset
700 }
a61af66fc99e Initial load
duke
parents:
diff changeset
701 }
a61af66fc99e Initial load
duke
parents:
diff changeset
702 }
a61af66fc99e Initial load
duke
parents:
diff changeset
703
a61af66fc99e Initial load
duke
parents:
diff changeset
704 // Phase 3: Process MergeMem nodes from mergemem_worklist. Walk each memory slice
a61af66fc99e Initial load
duke
parents:
diff changeset
705 // moving the first node encountered of each instance type to the
a61af66fc99e Initial load
duke
parents:
diff changeset
706 // the input corresponding to its alias index.
a61af66fc99e Initial load
duke
parents:
diff changeset
707 while (mergemem_worklist.length() != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
708 Node *n = mergemem_worklist.pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
709 assert(n->is_MergeMem(), "MergeMem node required.");
a61af66fc99e Initial load
duke
parents:
diff changeset
710 MergeMemNode *nmm = n->as_MergeMem();
a61af66fc99e Initial load
duke
parents:
diff changeset
711 // Note: we don't want to use MergeMemStream here because we only want to
a61af66fc99e Initial load
duke
parents:
diff changeset
712 // scan inputs which exist at the start, not ones we add during processing
a61af66fc99e Initial load
duke
parents:
diff changeset
713 uint nslices = nmm->req();
a61af66fc99e Initial load
duke
parents:
diff changeset
714 igvn->hash_delete(nmm);
a61af66fc99e Initial load
duke
parents:
diff changeset
715 for (uint i = Compile::AliasIdxRaw+1; i < nslices; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
716 Node * mem = nmm->in(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
717 Node * cur = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
718 if (mem == NULL || mem->is_top())
a61af66fc99e Initial load
duke
parents:
diff changeset
719 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
720 while (mem->is_Mem()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
721 const Type *at = igvn->type(mem->in(MemNode::Address));
a61af66fc99e Initial load
duke
parents:
diff changeset
722 if (at != Type::TOP) {
a61af66fc99e Initial load
duke
parents:
diff changeset
723 assert (at->isa_ptr() != NULL, "pointer type required.");
a61af66fc99e Initial load
duke
parents:
diff changeset
724 uint idx = (uint)_compile->get_alias_index(at->is_ptr());
a61af66fc99e Initial load
duke
parents:
diff changeset
725 if (idx == i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
726 if (cur == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
727 cur = mem;
a61af66fc99e Initial load
duke
parents:
diff changeset
728 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
729 if (idx >= nmm->req() || nmm->is_empty_memory(nmm->in(idx))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
730 nmm->set_memory_at(idx, mem);
a61af66fc99e Initial load
duke
parents:
diff changeset
731 }
a61af66fc99e Initial load
duke
parents:
diff changeset
732 }
a61af66fc99e Initial load
duke
parents:
diff changeset
733 }
a61af66fc99e Initial load
duke
parents:
diff changeset
734 mem = mem->in(MemNode::Memory);
a61af66fc99e Initial load
duke
parents:
diff changeset
735 }
a61af66fc99e Initial load
duke
parents:
diff changeset
736 nmm->set_memory_at(i, (cur != NULL) ? cur : mem);
a61af66fc99e Initial load
duke
parents:
diff changeset
737 if (mem->is_Phi()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
738 // We have encountered a Phi, we need to split the Phi for
a61af66fc99e Initial load
duke
parents:
diff changeset
739 // any instance of the current type if we haven't encountered
a61af66fc99e Initial load
duke
parents:
diff changeset
740 // a value of the instance along the chain.
a61af66fc99e Initial load
duke
parents:
diff changeset
741 for (uint ni = new_index_start; ni < new_index_end; ni++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
742 if((uint)_compile->get_general_index(ni) == i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
743 Node *m = (ni >= nmm->req()) ? nmm->empty_memory() : nmm->in(ni);
a61af66fc99e Initial load
duke
parents:
diff changeset
744 if (nmm->is_empty_memory(m)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
745 nmm->set_memory_at(ni, split_memory_phi(mem->as_Phi(), ni, orig_phis, igvn));
a61af66fc99e Initial load
duke
parents:
diff changeset
746 }
a61af66fc99e Initial load
duke
parents:
diff changeset
747 }
a61af66fc99e Initial load
duke
parents:
diff changeset
748 }
a61af66fc99e Initial load
duke
parents:
diff changeset
749 }
a61af66fc99e Initial load
duke
parents:
diff changeset
750 }
a61af66fc99e Initial load
duke
parents:
diff changeset
751 igvn->hash_insert(nmm);
a61af66fc99e Initial load
duke
parents:
diff changeset
752 record_for_optimizer(nmm);
a61af66fc99e Initial load
duke
parents:
diff changeset
753 }
a61af66fc99e Initial load
duke
parents:
diff changeset
754
a61af66fc99e Initial load
duke
parents:
diff changeset
755 // Phase 4: Update the inputs of non-instance memory Phis and the Memory input of memnodes
a61af66fc99e Initial load
duke
parents:
diff changeset
756 //
a61af66fc99e Initial load
duke
parents:
diff changeset
757 // First update the inputs of any non-instance Phi's from
a61af66fc99e Initial load
duke
parents:
diff changeset
758 // which we split out an instance Phi. Note we don't have
a61af66fc99e Initial load
duke
parents:
diff changeset
759 // to recursively process Phi's encounted on the input memory
a61af66fc99e Initial load
duke
parents:
diff changeset
760 // chains as is done in split_memory_phi() since they will
a61af66fc99e Initial load
duke
parents:
diff changeset
761 // also be processed here.
a61af66fc99e Initial load
duke
parents:
diff changeset
762 while (orig_phis.length() != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
763 PhiNode *phi = orig_phis.pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
764 int alias_idx = _compile->get_alias_index(phi->adr_type());
a61af66fc99e Initial load
duke
parents:
diff changeset
765 igvn->hash_delete(phi);
a61af66fc99e Initial load
duke
parents:
diff changeset
766 for (uint i = 1; i < phi->req(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
767 Node *mem = phi->in(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
768 Node *new_mem = find_mem(mem, alias_idx, igvn);
a61af66fc99e Initial load
duke
parents:
diff changeset
769 if (mem != new_mem) {
a61af66fc99e Initial load
duke
parents:
diff changeset
770 phi->set_req(i, new_mem);
a61af66fc99e Initial load
duke
parents:
diff changeset
771 }
a61af66fc99e Initial load
duke
parents:
diff changeset
772 }
a61af66fc99e Initial load
duke
parents:
diff changeset
773 igvn->hash_insert(phi);
a61af66fc99e Initial load
duke
parents:
diff changeset
774 record_for_optimizer(phi);
a61af66fc99e Initial load
duke
parents:
diff changeset
775 }
a61af66fc99e Initial load
duke
parents:
diff changeset
776
a61af66fc99e Initial load
duke
parents:
diff changeset
777 // Update the memory inputs of MemNodes with the value we computed
a61af66fc99e Initial load
duke
parents:
diff changeset
778 // in Phase 2.
a61af66fc99e Initial load
duke
parents:
diff changeset
779 for (int i = 0; i < _nodes->length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
780 Node *nmem = get_map(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
781 if (nmem != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
782 Node *n = _nodes->at(i)._node;
a61af66fc99e Initial load
duke
parents:
diff changeset
783 if (n != NULL && n->is_Mem()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
784 igvn->hash_delete(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
785 n->set_req(MemNode::Memory, nmem);
a61af66fc99e Initial load
duke
parents:
diff changeset
786 igvn->hash_insert(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
787 record_for_optimizer(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
788 }
a61af66fc99e Initial load
duke
parents:
diff changeset
789 }
a61af66fc99e Initial load
duke
parents:
diff changeset
790 }
a61af66fc99e Initial load
duke
parents:
diff changeset
791 }
a61af66fc99e Initial load
duke
parents:
diff changeset
792
a61af66fc99e Initial load
duke
parents:
diff changeset
793 void ConnectionGraph::compute_escape() {
a61af66fc99e Initial load
duke
parents:
diff changeset
794 GrowableArray<int> worklist;
a61af66fc99e Initial load
duke
parents:
diff changeset
795 GrowableArray<Node *> alloc_worklist;
a61af66fc99e Initial load
duke
parents:
diff changeset
796 VectorSet visited(Thread::current()->resource_area());
a61af66fc99e Initial load
duke
parents:
diff changeset
797 PhaseGVN *igvn = _compile->initial_gvn();
a61af66fc99e Initial load
duke
parents:
diff changeset
798
a61af66fc99e Initial load
duke
parents:
diff changeset
799 // process Phi nodes from the deferred list, they may not have
a61af66fc99e Initial load
duke
parents:
diff changeset
800 while(_deferred.size() > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
801 Node * n = _deferred.pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
802 PhiNode * phi = n->as_Phi();
a61af66fc99e Initial load
duke
parents:
diff changeset
803
a61af66fc99e Initial load
duke
parents:
diff changeset
804 process_phi_escape(phi, igvn);
a61af66fc99e Initial load
duke
parents:
diff changeset
805 }
a61af66fc99e Initial load
duke
parents:
diff changeset
806
a61af66fc99e Initial load
duke
parents:
diff changeset
807 VectorSet ptset(Thread::current()->resource_area());
a61af66fc99e Initial load
duke
parents:
diff changeset
808
a61af66fc99e Initial load
duke
parents:
diff changeset
809 // remove deferred edges from the graph and collect
a61af66fc99e Initial load
duke
parents:
diff changeset
810 // information we will need for type splitting
a61af66fc99e Initial load
duke
parents:
diff changeset
811 for (uint ni = 0; ni < (uint)_nodes->length(); ni++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
812 PointsToNode * ptn = _nodes->adr_at(ni);
a61af66fc99e Initial load
duke
parents:
diff changeset
813 PointsToNode::NodeType nt = ptn->node_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
814
a61af66fc99e Initial load
duke
parents:
diff changeset
815 if (nt == PointsToNode::UnknownType) {
a61af66fc99e Initial load
duke
parents:
diff changeset
816 continue; // not a node we are interested in
a61af66fc99e Initial load
duke
parents:
diff changeset
817 }
a61af66fc99e Initial load
duke
parents:
diff changeset
818 Node *n = ptn->_node;
a61af66fc99e Initial load
duke
parents:
diff changeset
819 if (nt == PointsToNode::LocalVar || nt == PointsToNode::Field) {
a61af66fc99e Initial load
duke
parents:
diff changeset
820 remove_deferred(ni);
a61af66fc99e Initial load
duke
parents:
diff changeset
821 if (n->is_AddP()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
822 // if this AddP computes an address which may point to more that one
a61af66fc99e Initial load
duke
parents:
diff changeset
823 // object, nothing the address points to can be a unique type.
a61af66fc99e Initial load
duke
parents:
diff changeset
824 Node *base = n->in(AddPNode::Base);
a61af66fc99e Initial load
duke
parents:
diff changeset
825 ptset.Clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
826 PointsTo(ptset, base, igvn);
a61af66fc99e Initial load
duke
parents:
diff changeset
827 if (ptset.Size() > 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
828 for( VectorSetI j(&ptset); j.test(); ++j ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
829 PointsToNode *ptaddr = _nodes->adr_at(j.elem);
a61af66fc99e Initial load
duke
parents:
diff changeset
830 ptaddr->_unique_type = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
831 }
a61af66fc99e Initial load
duke
parents:
diff changeset
832 }
a61af66fc99e Initial load
duke
parents:
diff changeset
833 }
a61af66fc99e Initial load
duke
parents:
diff changeset
834 } else if (n->is_Call()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
835 // initialize _escape_state of calls to GlobalEscape
a61af66fc99e Initial load
duke
parents:
diff changeset
836 n->as_Call()->_escape_state = PointsToNode::GlobalEscape;
a61af66fc99e Initial load
duke
parents:
diff changeset
837 // push call on alloc_worlist (alocations are calls)
a61af66fc99e Initial load
duke
parents:
diff changeset
838 // for processing by split_unique_types()
a61af66fc99e Initial load
duke
parents:
diff changeset
839 alloc_worklist.push(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
840 }
a61af66fc99e Initial load
duke
parents:
diff changeset
841 }
a61af66fc99e Initial load
duke
parents:
diff changeset
842 // push all GlobalEscape nodes on the worklist
a61af66fc99e Initial load
duke
parents:
diff changeset
843 for (uint nj = 0; nj < (uint)_nodes->length(); nj++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
844 if (_nodes->at(nj).escape_state() == PointsToNode::GlobalEscape) {
a61af66fc99e Initial load
duke
parents:
diff changeset
845 worklist.append(nj);
a61af66fc99e Initial load
duke
parents:
diff changeset
846 }
a61af66fc99e Initial load
duke
parents:
diff changeset
847 }
a61af66fc99e Initial load
duke
parents:
diff changeset
848 // mark all node reachable from GlobalEscape nodes
a61af66fc99e Initial load
duke
parents:
diff changeset
849 while(worklist.length() > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
850 PointsToNode n = _nodes->at(worklist.pop());
a61af66fc99e Initial load
duke
parents:
diff changeset
851 for (uint ei = 0; ei < n.edge_count(); ei++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
852 uint npi = n.edge_target(ei);
a61af66fc99e Initial load
duke
parents:
diff changeset
853 PointsToNode *np = ptnode_adr(npi);
a61af66fc99e Initial load
duke
parents:
diff changeset
854 if (np->escape_state() != PointsToNode::GlobalEscape) {
a61af66fc99e Initial load
duke
parents:
diff changeset
855 np->set_escape_state(PointsToNode::GlobalEscape);
a61af66fc99e Initial load
duke
parents:
diff changeset
856 worklist.append_if_missing(npi);
a61af66fc99e Initial load
duke
parents:
diff changeset
857 }
a61af66fc99e Initial load
duke
parents:
diff changeset
858 }
a61af66fc99e Initial load
duke
parents:
diff changeset
859 }
a61af66fc99e Initial load
duke
parents:
diff changeset
860
a61af66fc99e Initial load
duke
parents:
diff changeset
861 // push all ArgEscape nodes on the worklist
a61af66fc99e Initial load
duke
parents:
diff changeset
862 for (uint nk = 0; nk < (uint)_nodes->length(); nk++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
863 if (_nodes->at(nk).escape_state() == PointsToNode::ArgEscape)
a61af66fc99e Initial load
duke
parents:
diff changeset
864 worklist.push(nk);
a61af66fc99e Initial load
duke
parents:
diff changeset
865 }
a61af66fc99e Initial load
duke
parents:
diff changeset
866 // mark all node reachable from ArgEscape nodes
a61af66fc99e Initial load
duke
parents:
diff changeset
867 while(worklist.length() > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
868 PointsToNode n = _nodes->at(worklist.pop());
a61af66fc99e Initial load
duke
parents:
diff changeset
869
a61af66fc99e Initial load
duke
parents:
diff changeset
870 for (uint ei = 0; ei < n.edge_count(); ei++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
871 uint npi = n.edge_target(ei);
a61af66fc99e Initial load
duke
parents:
diff changeset
872 PointsToNode *np = ptnode_adr(npi);
a61af66fc99e Initial load
duke
parents:
diff changeset
873 if (np->escape_state() != PointsToNode::ArgEscape) {
a61af66fc99e Initial load
duke
parents:
diff changeset
874 np->set_escape_state(PointsToNode::ArgEscape);
a61af66fc99e Initial load
duke
parents:
diff changeset
875 worklist.append_if_missing(npi);
a61af66fc99e Initial load
duke
parents:
diff changeset
876 }
a61af66fc99e Initial load
duke
parents:
diff changeset
877 }
a61af66fc99e Initial load
duke
parents:
diff changeset
878 }
a61af66fc99e Initial load
duke
parents:
diff changeset
879 _collecting = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
880
a61af66fc99e Initial load
duke
parents:
diff changeset
881 // Now use the escape information to create unique types for
a61af66fc99e Initial load
duke
parents:
diff changeset
882 // unescaped objects
a61af66fc99e Initial load
duke
parents:
diff changeset
883 split_unique_types(alloc_worklist);
a61af66fc99e Initial load
duke
parents:
diff changeset
884 }
a61af66fc99e Initial load
duke
parents:
diff changeset
885
a61af66fc99e Initial load
duke
parents:
diff changeset
886 Node * ConnectionGraph::skip_casts(Node *n) {
a61af66fc99e Initial load
duke
parents:
diff changeset
887 while(n->Opcode() == Op_CastPP || n->Opcode() == Op_CheckCastPP) {
a61af66fc99e Initial load
duke
parents:
diff changeset
888 n = n->in(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
889 }
a61af66fc99e Initial load
duke
parents:
diff changeset
890 return n;
a61af66fc99e Initial load
duke
parents:
diff changeset
891 }
a61af66fc99e Initial load
duke
parents:
diff changeset
892
a61af66fc99e Initial load
duke
parents:
diff changeset
893 void ConnectionGraph::process_phi_escape(PhiNode *phi, PhaseTransform *phase) {
a61af66fc99e Initial load
duke
parents:
diff changeset
894
a61af66fc99e Initial load
duke
parents:
diff changeset
895 if (phi->type()->isa_oopptr() == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
896 return; // nothing to do if not an oop
a61af66fc99e Initial load
duke
parents:
diff changeset
897
a61af66fc99e Initial load
duke
parents:
diff changeset
898 PointsToNode *ptadr = ptnode_adr(phi->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
899 int incount = phi->req();
a61af66fc99e Initial load
duke
parents:
diff changeset
900 int non_null_inputs = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
901
a61af66fc99e Initial load
duke
parents:
diff changeset
902 for (int i = 1; i < incount ; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
903 if (phi->in(i) != NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
904 non_null_inputs++;
a61af66fc99e Initial load
duke
parents:
diff changeset
905 }
a61af66fc99e Initial load
duke
parents:
diff changeset
906 if (non_null_inputs == ptadr->_inputs_processed)
a61af66fc99e Initial load
duke
parents:
diff changeset
907 return; // no new inputs since the last time this node was processed,
a61af66fc99e Initial load
duke
parents:
diff changeset
908 // the current information is valid
a61af66fc99e Initial load
duke
parents:
diff changeset
909
a61af66fc99e Initial load
duke
parents:
diff changeset
910 ptadr->_inputs_processed = non_null_inputs; // prevent recursive processing of this node
a61af66fc99e Initial load
duke
parents:
diff changeset
911 for (int j = 1; j < incount ; j++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
912 Node * n = phi->in(j);
a61af66fc99e Initial load
duke
parents:
diff changeset
913 if (n == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
914 continue; // ignore NULL
a61af66fc99e Initial load
duke
parents:
diff changeset
915 n = skip_casts(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
916 if (n->is_top() || n == phi)
a61af66fc99e Initial load
duke
parents:
diff changeset
917 continue; // ignore top or inputs which go back this node
a61af66fc99e Initial load
duke
parents:
diff changeset
918 int nopc = n->Opcode();
a61af66fc99e Initial load
duke
parents:
diff changeset
919 PointsToNode npt = _nodes->at(n->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
920 if (_nodes->at(n->_idx).node_type() == PointsToNode::JavaObject) {
a61af66fc99e Initial load
duke
parents:
diff changeset
921 add_pointsto_edge(phi->_idx, n->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
922 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
923 add_deferred_edge(phi->_idx, n->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
924 }
a61af66fc99e Initial load
duke
parents:
diff changeset
925 }
a61af66fc99e Initial load
duke
parents:
diff changeset
926 }
a61af66fc99e Initial load
duke
parents:
diff changeset
927
a61af66fc99e Initial load
duke
parents:
diff changeset
928 void ConnectionGraph::process_call_arguments(CallNode *call, PhaseTransform *phase) {
a61af66fc99e Initial load
duke
parents:
diff changeset
929
a61af66fc99e Initial load
duke
parents:
diff changeset
930 _processed.set(call->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
931 switch (call->Opcode()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
932
a61af66fc99e Initial load
duke
parents:
diff changeset
933 // arguments to allocation and locking don't escape
a61af66fc99e Initial load
duke
parents:
diff changeset
934 case Op_Allocate:
a61af66fc99e Initial load
duke
parents:
diff changeset
935 case Op_AllocateArray:
a61af66fc99e Initial load
duke
parents:
diff changeset
936 case Op_Lock:
a61af66fc99e Initial load
duke
parents:
diff changeset
937 case Op_Unlock:
a61af66fc99e Initial load
duke
parents:
diff changeset
938 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
939
a61af66fc99e Initial load
duke
parents:
diff changeset
940 case Op_CallStaticJava:
a61af66fc99e Initial load
duke
parents:
diff changeset
941 // For a static call, we know exactly what method is being called.
a61af66fc99e Initial load
duke
parents:
diff changeset
942 // Use bytecode estimator to record the call's escape affects
a61af66fc99e Initial load
duke
parents:
diff changeset
943 {
a61af66fc99e Initial load
duke
parents:
diff changeset
944 ciMethod *meth = call->as_CallJava()->method();
a61af66fc99e Initial load
duke
parents:
diff changeset
945 if (meth != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
946 const TypeTuple * d = call->tf()->domain();
a61af66fc99e Initial load
duke
parents:
diff changeset
947 BCEscapeAnalyzer call_analyzer(meth);
a61af66fc99e Initial load
duke
parents:
diff changeset
948 VectorSet ptset(Thread::current()->resource_area());
a61af66fc99e Initial load
duke
parents:
diff changeset
949 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
950 const Type* at = d->field_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
951 int k = i - TypeFunc::Parms;
a61af66fc99e Initial load
duke
parents:
diff changeset
952
a61af66fc99e Initial load
duke
parents:
diff changeset
953 if (at->isa_oopptr() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
954 Node *arg = skip_casts(call->in(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
955
a61af66fc99e Initial load
duke
parents:
diff changeset
956 if (!call_analyzer.is_arg_stack(k)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
957 // The argument global escapes, mark everything it could point to
a61af66fc99e Initial load
duke
parents:
diff changeset
958 ptset.Clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
959 PointsTo(ptset, arg, phase);
a61af66fc99e Initial load
duke
parents:
diff changeset
960 for( VectorSetI j(&ptset); j.test(); ++j ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
961 uint pt = j.elem;
a61af66fc99e Initial load
duke
parents:
diff changeset
962
a61af66fc99e Initial load
duke
parents:
diff changeset
963 set_escape_state(pt, PointsToNode::GlobalEscape);
a61af66fc99e Initial load
duke
parents:
diff changeset
964 }
a61af66fc99e Initial load
duke
parents:
diff changeset
965 } else if (!call_analyzer.is_arg_local(k)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
966 // The argument itself doesn't escape, but any fields might
a61af66fc99e Initial load
duke
parents:
diff changeset
967 ptset.Clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
968 PointsTo(ptset, arg, phase);
a61af66fc99e Initial load
duke
parents:
diff changeset
969 for( VectorSetI j(&ptset); j.test(); ++j ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
970 uint pt = j.elem;
a61af66fc99e Initial load
duke
parents:
diff changeset
971 add_edge_from_fields(pt, _phantom_object, Type::OffsetBot);
a61af66fc99e Initial load
duke
parents:
diff changeset
972 }
a61af66fc99e Initial load
duke
parents:
diff changeset
973 }
a61af66fc99e Initial load
duke
parents:
diff changeset
974 }
a61af66fc99e Initial load
duke
parents:
diff changeset
975 }
a61af66fc99e Initial load
duke
parents:
diff changeset
976 call_analyzer.copy_dependencies(C()->dependencies());
a61af66fc99e Initial load
duke
parents:
diff changeset
977 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
978 }
a61af66fc99e Initial load
duke
parents:
diff changeset
979 // fall-through if not a Java method
a61af66fc99e Initial load
duke
parents:
diff changeset
980 }
a61af66fc99e Initial load
duke
parents:
diff changeset
981
a61af66fc99e Initial load
duke
parents:
diff changeset
982 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
983 // Some other type of call, assume the worst case: all arguments
a61af66fc99e Initial load
duke
parents:
diff changeset
984 // globally escape.
a61af66fc99e Initial load
duke
parents:
diff changeset
985 {
a61af66fc99e Initial load
duke
parents:
diff changeset
986 // adjust escape state for outgoing arguments
a61af66fc99e Initial load
duke
parents:
diff changeset
987 const TypeTuple * d = call->tf()->domain();
a61af66fc99e Initial load
duke
parents:
diff changeset
988 VectorSet ptset(Thread::current()->resource_area());
a61af66fc99e Initial load
duke
parents:
diff changeset
989 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
990 const Type* at = d->field_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
991
a61af66fc99e Initial load
duke
parents:
diff changeset
992 if (at->isa_oopptr() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
993 Node *arg = skip_casts(call->in(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
994 ptset.Clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
995 PointsTo(ptset, arg, phase);
a61af66fc99e Initial load
duke
parents:
diff changeset
996 for( VectorSetI j(&ptset); j.test(); ++j ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
997 uint pt = j.elem;
a61af66fc99e Initial load
duke
parents:
diff changeset
998
a61af66fc99e Initial load
duke
parents:
diff changeset
999 set_escape_state(pt, PointsToNode::GlobalEscape);
a61af66fc99e Initial load
duke
parents:
diff changeset
1000 }
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 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1006 void ConnectionGraph::process_call_result(ProjNode *resproj, PhaseTransform *phase) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1007 CallNode *call = resproj->in(0)->as_Call();
a61af66fc99e Initial load
duke
parents:
diff changeset
1008
a61af66fc99e Initial load
duke
parents:
diff changeset
1009 PointsToNode *ptadr = ptnode_adr(resproj->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1010
a61af66fc99e Initial load
duke
parents:
diff changeset
1011 ptadr->_node = resproj;
a61af66fc99e Initial load
duke
parents:
diff changeset
1012 ptadr->set_node_type(PointsToNode::LocalVar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1013 set_escape_state(resproj->_idx, PointsToNode::UnknownEscape);
a61af66fc99e Initial load
duke
parents:
diff changeset
1014 _processed.set(resproj->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1015
a61af66fc99e Initial load
duke
parents:
diff changeset
1016 switch (call->Opcode()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1017 case Op_Allocate:
a61af66fc99e Initial load
duke
parents:
diff changeset
1018 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1019 Node *k = call->in(AllocateNode::KlassNode);
a61af66fc99e Initial load
duke
parents:
diff changeset
1020 const TypeKlassPtr *kt;
a61af66fc99e Initial load
duke
parents:
diff changeset
1021 if (k->Opcode() == Op_LoadKlass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1022 kt = k->as_Load()->type()->isa_klassptr();
a61af66fc99e Initial load
duke
parents:
diff changeset
1023 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1024 kt = k->as_Type()->type()->isa_klassptr();
a61af66fc99e Initial load
duke
parents:
diff changeset
1025 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1026 assert(kt != NULL, "TypeKlassPtr required.");
a61af66fc99e Initial load
duke
parents:
diff changeset
1027 ciKlass* cik = kt->klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
1028 ciInstanceKlass* ciik = cik->as_instance_klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
1029
a61af66fc99e Initial load
duke
parents:
diff changeset
1030 PointsToNode *ptadr = ptnode_adr(call->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1031 ptadr->set_node_type(PointsToNode::JavaObject);
a61af66fc99e Initial load
duke
parents:
diff changeset
1032 if (cik->is_subclass_of(_compile->env()->Thread_klass()) || ciik->has_finalizer()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1033 set_escape_state(call->_idx, PointsToNode::GlobalEscape);
a61af66fc99e Initial load
duke
parents:
diff changeset
1034 add_pointsto_edge(resproj->_idx, _phantom_object);
a61af66fc99e Initial load
duke
parents:
diff changeset
1035 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1036 set_escape_state(call->_idx, PointsToNode::NoEscape);
a61af66fc99e Initial load
duke
parents:
diff changeset
1037 add_pointsto_edge(resproj->_idx, call->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1038 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1039 _processed.set(call->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1040 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1041 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1042
a61af66fc99e Initial load
duke
parents:
diff changeset
1043 case Op_AllocateArray:
a61af66fc99e Initial load
duke
parents:
diff changeset
1044 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1045 PointsToNode *ptadr = ptnode_adr(call->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1046 ptadr->set_node_type(PointsToNode::JavaObject);
a61af66fc99e Initial load
duke
parents:
diff changeset
1047 set_escape_state(call->_idx, PointsToNode::NoEscape);
a61af66fc99e Initial load
duke
parents:
diff changeset
1048 _processed.set(call->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1049 add_pointsto_edge(resproj->_idx, call->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1050 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1051 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1052
a61af66fc99e Initial load
duke
parents:
diff changeset
1053 case Op_Lock:
a61af66fc99e Initial load
duke
parents:
diff changeset
1054 case Op_Unlock:
a61af66fc99e Initial load
duke
parents:
diff changeset
1055 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1056
a61af66fc99e Initial load
duke
parents:
diff changeset
1057 case Op_CallStaticJava:
a61af66fc99e Initial load
duke
parents:
diff changeset
1058 // For a static call, we know exactly what method is being called.
a61af66fc99e Initial load
duke
parents:
diff changeset
1059 // Use bytecode estimator to record whether the call's return value escapes
a61af66fc99e Initial load
duke
parents:
diff changeset
1060 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1061 const TypeTuple *r = call->tf()->range();
a61af66fc99e Initial load
duke
parents:
diff changeset
1062 const Type* ret_type = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1063
a61af66fc99e Initial load
duke
parents:
diff changeset
1064 if (r->cnt() > TypeFunc::Parms)
a61af66fc99e Initial load
duke
parents:
diff changeset
1065 ret_type = r->field_at(TypeFunc::Parms);
a61af66fc99e Initial load
duke
parents:
diff changeset
1066
a61af66fc99e Initial load
duke
parents:
diff changeset
1067 // Note: we use isa_ptr() instead of isa_oopptr() here because the
a61af66fc99e Initial load
duke
parents:
diff changeset
1068 // _multianewarray functions return a TypeRawPtr.
a61af66fc99e Initial load
duke
parents:
diff changeset
1069 if (ret_type == NULL || ret_type->isa_ptr() == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
1070 break; // doesn't return a pointer type
a61af66fc99e Initial load
duke
parents:
diff changeset
1071
a61af66fc99e Initial load
duke
parents:
diff changeset
1072 ciMethod *meth = call->as_CallJava()->method();
a61af66fc99e Initial load
duke
parents:
diff changeset
1073 if (meth == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1074 // not a Java method, assume global escape
a61af66fc99e Initial load
duke
parents:
diff changeset
1075 set_escape_state(call->_idx, PointsToNode::GlobalEscape);
a61af66fc99e Initial load
duke
parents:
diff changeset
1076 if (resproj != NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
1077 add_pointsto_edge(resproj->_idx, _phantom_object);
a61af66fc99e Initial load
duke
parents:
diff changeset
1078 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1079 BCEscapeAnalyzer call_analyzer(meth);
a61af66fc99e Initial load
duke
parents:
diff changeset
1080 VectorSet ptset(Thread::current()->resource_area());
a61af66fc99e Initial load
duke
parents:
diff changeset
1081
a61af66fc99e Initial load
duke
parents:
diff changeset
1082 if (call_analyzer.is_return_local() && resproj != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1083 // determine whether any arguments are returned
a61af66fc99e Initial load
duke
parents:
diff changeset
1084 const TypeTuple * d = call->tf()->domain();
a61af66fc99e Initial load
duke
parents:
diff changeset
1085 set_escape_state(call->_idx, PointsToNode::NoEscape);
a61af66fc99e Initial load
duke
parents:
diff changeset
1086 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1087 const Type* at = d->field_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1088
a61af66fc99e Initial load
duke
parents:
diff changeset
1089 if (at->isa_oopptr() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1090 Node *arg = skip_casts(call->in(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
1091
a61af66fc99e Initial load
duke
parents:
diff changeset
1092 if (call_analyzer.is_arg_returned(i - TypeFunc::Parms)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1093 PointsToNode *arg_esp = _nodes->adr_at(arg->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1094 if (arg_esp->node_type() == PointsToNode::JavaObject)
a61af66fc99e Initial load
duke
parents:
diff changeset
1095 add_pointsto_edge(resproj->_idx, arg->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1096 else
a61af66fc99e Initial load
duke
parents:
diff changeset
1097 add_deferred_edge(resproj->_idx, arg->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1098 arg_esp->_hidden_alias = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1099 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1100 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1101 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1102 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1103 set_escape_state(call->_idx, PointsToNode::GlobalEscape);
a61af66fc99e Initial load
duke
parents:
diff changeset
1104 if (resproj != NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
1105 add_pointsto_edge(resproj->_idx, _phantom_object);
a61af66fc99e Initial load
duke
parents:
diff changeset
1106 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1107 call_analyzer.copy_dependencies(C()->dependencies());
a61af66fc99e Initial load
duke
parents:
diff changeset
1108 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1109 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1110 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1111
a61af66fc99e Initial load
duke
parents:
diff changeset
1112 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
1113 // Some other type of call, assume the worst case that the
a61af66fc99e Initial load
duke
parents:
diff changeset
1114 // returned value, if any, globally escapes.
a61af66fc99e Initial load
duke
parents:
diff changeset
1115 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1116 const TypeTuple *r = call->tf()->range();
a61af66fc99e Initial load
duke
parents:
diff changeset
1117
a61af66fc99e Initial load
duke
parents:
diff changeset
1118 if (r->cnt() > TypeFunc::Parms) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1119 const Type* ret_type = r->field_at(TypeFunc::Parms);
a61af66fc99e Initial load
duke
parents:
diff changeset
1120
a61af66fc99e Initial load
duke
parents:
diff changeset
1121 // Note: we use isa_ptr() instead of isa_oopptr() here because the
a61af66fc99e Initial load
duke
parents:
diff changeset
1122 // _multianewarray functions return a TypeRawPtr.
a61af66fc99e Initial load
duke
parents:
diff changeset
1123 if (ret_type->isa_ptr() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1124 PointsToNode *ptadr = ptnode_adr(call->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1125 ptadr->set_node_type(PointsToNode::JavaObject);
a61af66fc99e Initial load
duke
parents:
diff changeset
1126 set_escape_state(call->_idx, PointsToNode::GlobalEscape);
a61af66fc99e Initial load
duke
parents:
diff changeset
1127 if (resproj != NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
1128 add_pointsto_edge(resproj->_idx, _phantom_object);
a61af66fc99e Initial load
duke
parents:
diff changeset
1129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1131 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1132 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1133 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1134
a61af66fc99e Initial load
duke
parents:
diff changeset
1135 void ConnectionGraph::record_for_escape_analysis(Node *n) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1136 if (_collecting) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1137 if (n->is_Phi()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1138 PhiNode *phi = n->as_Phi();
a61af66fc99e Initial load
duke
parents:
diff changeset
1139 const Type *pt = phi->type();
a61af66fc99e Initial load
duke
parents:
diff changeset
1140 if ((pt->isa_oopptr() != NULL) || pt == TypePtr::NULL_PTR) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1141 PointsToNode *ptn = ptnode_adr(phi->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1142 ptn->set_node_type(PointsToNode::LocalVar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1143 ptn->_node = n;
a61af66fc99e Initial load
duke
parents:
diff changeset
1144 _deferred.push(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
1145 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1146 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1147 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1148 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1149
a61af66fc99e Initial load
duke
parents:
diff changeset
1150 void ConnectionGraph::record_escape_work(Node *n, PhaseTransform *phase) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1151
a61af66fc99e Initial load
duke
parents:
diff changeset
1152 int opc = n->Opcode();
a61af66fc99e Initial load
duke
parents:
diff changeset
1153 PointsToNode *ptadr = ptnode_adr(n->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1154
a61af66fc99e Initial load
duke
parents:
diff changeset
1155 if (_processed.test(n->_idx))
a61af66fc99e Initial load
duke
parents:
diff changeset
1156 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1157
a61af66fc99e Initial load
duke
parents:
diff changeset
1158 ptadr->_node = n;
a61af66fc99e Initial load
duke
parents:
diff changeset
1159 if (n->is_Call()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1160 CallNode *call = n->as_Call();
a61af66fc99e Initial load
duke
parents:
diff changeset
1161 process_call_arguments(call, phase);
a61af66fc99e Initial load
duke
parents:
diff changeset
1162 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1163 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1164
a61af66fc99e Initial load
duke
parents:
diff changeset
1165 switch (opc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1166 case Op_AddP:
a61af66fc99e Initial load
duke
parents:
diff changeset
1167 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1168 Node *base = skip_casts(n->in(AddPNode::Base));
a61af66fc99e Initial load
duke
parents:
diff changeset
1169 ptadr->set_node_type(PointsToNode::Field);
a61af66fc99e Initial load
duke
parents:
diff changeset
1170
a61af66fc99e Initial load
duke
parents:
diff changeset
1171 // create a field edge to this node from everything adr could point to
a61af66fc99e Initial load
duke
parents:
diff changeset
1172 VectorSet ptset(Thread::current()->resource_area());
a61af66fc99e Initial load
duke
parents:
diff changeset
1173 PointsTo(ptset, base, phase);
a61af66fc99e Initial load
duke
parents:
diff changeset
1174 for( VectorSetI i(&ptset); i.test(); ++i ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1175 uint pt = i.elem;
a61af66fc99e Initial load
duke
parents:
diff changeset
1176 add_field_edge(pt, n->_idx, type_to_offset(phase->type(n)));
a61af66fc99e Initial load
duke
parents:
diff changeset
1177 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1178 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1179 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1180 case Op_Parm:
a61af66fc99e Initial load
duke
parents:
diff changeset
1181 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1182 ProjNode *nproj = n->as_Proj();
a61af66fc99e Initial load
duke
parents:
diff changeset
1183 uint con = nproj->_con;
a61af66fc99e Initial load
duke
parents:
diff changeset
1184 if (con < TypeFunc::Parms)
a61af66fc99e Initial load
duke
parents:
diff changeset
1185 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1186 const Type *t = nproj->in(0)->as_Start()->_domain->field_at(con);
a61af66fc99e Initial load
duke
parents:
diff changeset
1187 if (t->isa_ptr() == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
1188 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1189 ptadr->set_node_type(PointsToNode::JavaObject);
a61af66fc99e Initial load
duke
parents:
diff changeset
1190 if (t->isa_oopptr() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1191 set_escape_state(n->_idx, PointsToNode::ArgEscape);
a61af66fc99e Initial load
duke
parents:
diff changeset
1192 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1193 // this must be the incoming state of an OSR compile, we have to assume anything
a61af66fc99e Initial load
duke
parents:
diff changeset
1194 // passed in globally escapes
a61af66fc99e Initial load
duke
parents:
diff changeset
1195 assert(_compile->is_osr_compilation(), "bad argument type for non-osr compilation");
a61af66fc99e Initial load
duke
parents:
diff changeset
1196 set_escape_state(n->_idx, PointsToNode::GlobalEscape);
a61af66fc99e Initial load
duke
parents:
diff changeset
1197 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1198 _processed.set(n->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1199 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1200 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1201 case Op_Phi:
a61af66fc99e Initial load
duke
parents:
diff changeset
1202 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1203 PhiNode *phi = n->as_Phi();
a61af66fc99e Initial load
duke
parents:
diff changeset
1204 if (phi->type()->isa_oopptr() == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
1205 return; // nothing to do if not an oop
a61af66fc99e Initial load
duke
parents:
diff changeset
1206 ptadr->set_node_type(PointsToNode::LocalVar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1207 process_phi_escape(phi, phase);
a61af66fc99e Initial load
duke
parents:
diff changeset
1208 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1209 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1210 case Op_CreateEx:
a61af66fc99e Initial load
duke
parents:
diff changeset
1211 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1212 // assume that all exception objects globally escape
a61af66fc99e Initial load
duke
parents:
diff changeset
1213 ptadr->set_node_type(PointsToNode::JavaObject);
a61af66fc99e Initial load
duke
parents:
diff changeset
1214 set_escape_state(n->_idx, PointsToNode::GlobalEscape);
a61af66fc99e Initial load
duke
parents:
diff changeset
1215 _processed.set(n->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1216 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1217 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1218 case Op_ConP:
a61af66fc99e Initial load
duke
parents:
diff changeset
1219 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1220 const Type *t = phase->type(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
1221 ptadr->set_node_type(PointsToNode::JavaObject);
a61af66fc99e Initial load
duke
parents:
diff changeset
1222 // assume all pointer constants globally escape except for null
a61af66fc99e Initial load
duke
parents:
diff changeset
1223 if (t == TypePtr::NULL_PTR)
a61af66fc99e Initial load
duke
parents:
diff changeset
1224 set_escape_state(n->_idx, PointsToNode::NoEscape);
a61af66fc99e Initial load
duke
parents:
diff changeset
1225 else
a61af66fc99e Initial load
duke
parents:
diff changeset
1226 set_escape_state(n->_idx, PointsToNode::GlobalEscape);
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_LoadKlass:
a61af66fc99e Initial load
duke
parents:
diff changeset
1231 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1232 ptadr->set_node_type(PointsToNode::JavaObject);
a61af66fc99e Initial load
duke
parents:
diff changeset
1233 set_escape_state(n->_idx, PointsToNode::GlobalEscape);
a61af66fc99e Initial load
duke
parents:
diff changeset
1234 _processed.set(n->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1235 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1236 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1237 case Op_LoadP:
a61af66fc99e Initial load
duke
parents:
diff changeset
1238 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1239 const Type *t = phase->type(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
1240 if (!t->isa_oopptr())
a61af66fc99e Initial load
duke
parents:
diff changeset
1241 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1242 ptadr->set_node_type(PointsToNode::LocalVar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1243 set_escape_state(n->_idx, PointsToNode::UnknownEscape);
a61af66fc99e Initial load
duke
parents:
diff changeset
1244
a61af66fc99e Initial load
duke
parents:
diff changeset
1245 Node *adr = skip_casts(n->in(MemNode::Address));
a61af66fc99e Initial load
duke
parents:
diff changeset
1246 const Type *adr_type = phase->type(adr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1247 Node *adr_base = skip_casts((adr->Opcode() == Op_AddP) ? adr->in(AddPNode::Base) : adr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1248
a61af66fc99e Initial load
duke
parents:
diff changeset
1249 // For everything "adr" could point to, create a deferred edge from
a61af66fc99e Initial load
duke
parents:
diff changeset
1250 // this node to each field with the same offset as "adr_type"
a61af66fc99e Initial load
duke
parents:
diff changeset
1251 VectorSet ptset(Thread::current()->resource_area());
a61af66fc99e Initial load
duke
parents:
diff changeset
1252 PointsTo(ptset, adr_base, phase);
a61af66fc99e Initial load
duke
parents:
diff changeset
1253 // If ptset is empty, then this value must have been set outside
a61af66fc99e Initial load
duke
parents:
diff changeset
1254 // this method, so we add the phantom node
a61af66fc99e Initial load
duke
parents:
diff changeset
1255 if (ptset.Size() == 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
1256 ptset.set(_phantom_object);
a61af66fc99e Initial load
duke
parents:
diff changeset
1257 for( VectorSetI i(&ptset); i.test(); ++i ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1258 uint pt = i.elem;
a61af66fc99e Initial load
duke
parents:
diff changeset
1259 add_deferred_edge_to_fields(n->_idx, pt, type_to_offset(adr_type));
a61af66fc99e Initial load
duke
parents:
diff changeset
1260 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1261 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1262 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1263 case Op_StoreP:
a61af66fc99e Initial load
duke
parents:
diff changeset
1264 case Op_StorePConditional:
a61af66fc99e Initial load
duke
parents:
diff changeset
1265 case Op_CompareAndSwapP:
a61af66fc99e Initial load
duke
parents:
diff changeset
1266 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1267 Node *adr = n->in(MemNode::Address);
a61af66fc99e Initial load
duke
parents:
diff changeset
1268 Node *val = skip_casts(n->in(MemNode::ValueIn));
a61af66fc99e Initial load
duke
parents:
diff changeset
1269 const Type *adr_type = phase->type(adr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1270 if (!adr_type->isa_oopptr())
a61af66fc99e Initial load
duke
parents:
diff changeset
1271 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1272
a61af66fc99e Initial load
duke
parents:
diff changeset
1273 assert(adr->Opcode() == Op_AddP, "expecting an AddP");
a61af66fc99e Initial load
duke
parents:
diff changeset
1274 Node *adr_base = adr->in(AddPNode::Base);
a61af66fc99e Initial load
duke
parents:
diff changeset
1275
a61af66fc99e Initial load
duke
parents:
diff changeset
1276 // For everything "adr_base" could point to, create a deferred edge to "val" from each field
a61af66fc99e Initial load
duke
parents:
diff changeset
1277 // with the same offset as "adr_type"
a61af66fc99e Initial load
duke
parents:
diff changeset
1278 VectorSet ptset(Thread::current()->resource_area());
a61af66fc99e Initial load
duke
parents:
diff changeset
1279 PointsTo(ptset, adr_base, phase);
a61af66fc99e Initial load
duke
parents:
diff changeset
1280 for( VectorSetI i(&ptset); i.test(); ++i ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1281 uint pt = i.elem;
a61af66fc99e Initial load
duke
parents:
diff changeset
1282 add_edge_from_fields(pt, val->_idx, type_to_offset(adr_type));
a61af66fc99e Initial load
duke
parents:
diff changeset
1283 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1284 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1285 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1286 case Op_Proj:
a61af66fc99e Initial load
duke
parents:
diff changeset
1287 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1288 ProjNode *nproj = n->as_Proj();
a61af66fc99e Initial load
duke
parents:
diff changeset
1289 Node *n0 = nproj->in(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
1290 // we are only interested in the result projection from a call
a61af66fc99e Initial load
duke
parents:
diff changeset
1291 if (nproj->_con == TypeFunc::Parms && n0->is_Call() ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1292 process_call_result(nproj, phase);
a61af66fc99e Initial load
duke
parents:
diff changeset
1293 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1294
a61af66fc99e Initial load
duke
parents:
diff changeset
1295 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1296 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1297 case Op_CastPP:
a61af66fc99e Initial load
duke
parents:
diff changeset
1298 case Op_CheckCastPP:
a61af66fc99e Initial load
duke
parents:
diff changeset
1299 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1300 ptadr->set_node_type(PointsToNode::LocalVar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1301 int ti = n->in(1)->_idx;
a61af66fc99e Initial load
duke
parents:
diff changeset
1302 if (_nodes->at(ti).node_type() == PointsToNode::JavaObject) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1303 add_pointsto_edge(n->_idx, ti);
a61af66fc99e Initial load
duke
parents:
diff changeset
1304 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1305 add_deferred_edge(n->_idx, ti);
a61af66fc99e Initial load
duke
parents:
diff changeset
1306 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1307 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1308 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1309 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
1310 ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1311 // nothing to do
a61af66fc99e Initial load
duke
parents:
diff changeset
1312 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1313 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1314
a61af66fc99e Initial load
duke
parents:
diff changeset
1315 void ConnectionGraph::record_escape(Node *n, PhaseTransform *phase) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1316 if (_collecting)
a61af66fc99e Initial load
duke
parents:
diff changeset
1317 record_escape_work(n, phase);
a61af66fc99e Initial load
duke
parents:
diff changeset
1318 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1319
a61af66fc99e Initial load
duke
parents:
diff changeset
1320 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
1321 void ConnectionGraph::dump() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1322 PhaseGVN *igvn = _compile->initial_gvn();
a61af66fc99e Initial load
duke
parents:
diff changeset
1323 bool first = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1324
a61af66fc99e Initial load
duke
parents:
diff changeset
1325 for (uint ni = 0; ni < (uint)_nodes->length(); ni++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1326 PointsToNode *esp = _nodes->adr_at(ni);
a61af66fc99e Initial load
duke
parents:
diff changeset
1327 if (esp->node_type() == PointsToNode::UnknownType || esp->_node == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
1328 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1329 PointsToNode::EscapeState es = escape_state(esp->_node, igvn);
a61af66fc99e Initial load
duke
parents:
diff changeset
1330 if (es == PointsToNode::NoEscape || (Verbose &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1331 (es != PointsToNode::UnknownEscape || esp->edge_count() != 0))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1332 // don't print null pointer node which almost every method has
a61af66fc99e Initial load
duke
parents:
diff changeset
1333 if (esp->_node->Opcode() != Op_ConP || igvn->type(esp->_node) != TypePtr::NULL_PTR) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1334 if (first) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1335 tty->print("======== Connection graph for ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1336 C()->method()->print_short_name();
a61af66fc99e Initial load
duke
parents:
diff changeset
1337 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
1338 first = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1339 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1340 tty->print("%4d ", ni);
a61af66fc99e Initial load
duke
parents:
diff changeset
1341 esp->dump();
a61af66fc99e Initial load
duke
parents:
diff changeset
1342 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1343 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1344 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1345 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1346 #endif