Mercurial > hg > graal-compiler
annotate src/share/vm/opto/escape.cpp @ 235:9c2ecc2ffb12 jdk7-b31
Merge
author | trims |
---|---|
date | Fri, 11 Jul 2008 01:14:44 -0700 |
parents | d1605aabd0a1 1dd146f17531 |
children | 4a4c365f777d |
rev | line source |
---|---|
0 | 1 /* |
196 | 2 * Copyright 2005-2008 Sun Microsystems, Inc. All Rights Reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 #include "incls/_precompiled.incl" | |
26 #include "incls/_escape.cpp.incl" | |
27 | |
28 uint PointsToNode::edge_target(uint e) const { | |
29 assert(_edges != NULL && e < (uint)_edges->length(), "valid edge index"); | |
30 return (_edges->at(e) >> EdgeShift); | |
31 } | |
32 | |
33 PointsToNode::EdgeType PointsToNode::edge_type(uint e) const { | |
34 assert(_edges != NULL && e < (uint)_edges->length(), "valid edge index"); | |
35 return (EdgeType) (_edges->at(e) & EdgeMask); | |
36 } | |
37 | |
38 void PointsToNode::add_edge(uint targIdx, PointsToNode::EdgeType et) { | |
39 uint v = (targIdx << EdgeShift) + ((uint) et); | |
40 if (_edges == NULL) { | |
41 Arena *a = Compile::current()->comp_arena(); | |
42 _edges = new(a) GrowableArray<uint>(a, INITIAL_EDGE_COUNT, 0, 0); | |
43 } | |
44 _edges->append_if_missing(v); | |
45 } | |
46 | |
47 void PointsToNode::remove_edge(uint targIdx, PointsToNode::EdgeType et) { | |
48 uint v = (targIdx << EdgeShift) + ((uint) et); | |
49 | |
50 _edges->remove(v); | |
51 } | |
52 | |
53 #ifndef PRODUCT | |
77 | 54 static const char *node_type_names[] = { |
0 | 55 "UnknownType", |
56 "JavaObject", | |
57 "LocalVar", | |
58 "Field" | |
59 }; | |
60 | |
77 | 61 static const char *esc_names[] = { |
0 | 62 "UnknownEscape", |
65 | 63 "NoEscape", |
64 "ArgEscape", | |
65 "GlobalEscape" | |
0 | 66 }; |
67 | |
77 | 68 static const char *edge_type_suffix[] = { |
0 | 69 "?", // UnknownEdge |
70 "P", // PointsToEdge | |
71 "D", // DeferredEdge | |
72 "F" // FieldEdge | |
73 }; | |
74 | |
75 void PointsToNode::dump() const { | |
76 NodeType nt = node_type(); | |
77 EscapeState es = escape_state(); | |
65 | 78 tty->print("%s %s %s [[", node_type_names[(int) nt], esc_names[(int) es], _scalar_replaceable ? "" : "NSR"); |
0 | 79 for (uint i = 0; i < edge_count(); i++) { |
80 tty->print(" %d%s", edge_target(i), edge_type_suffix[(int) edge_type(i)]); | |
81 } | |
82 tty->print("]] "); | |
83 if (_node == NULL) | |
84 tty->print_cr("<null>"); | |
85 else | |
86 _node->dump(); | |
87 } | |
88 #endif | |
89 | |
90 ConnectionGraph::ConnectionGraph(Compile * C) : _processed(C->comp_arena()), _node_map(C->comp_arena()) { | |
91 _collecting = true; | |
92 this->_compile = C; | |
93 const PointsToNode &dummy = PointsToNode(); | |
65 | 94 int sz = C->unique(); |
95 _nodes = new(C->comp_arena()) GrowableArray<PointsToNode>(C->comp_arena(), sz, sz, dummy); | |
0 | 96 _phantom_object = C->top()->_idx; |
97 PointsToNode *phn = ptnode_adr(_phantom_object); | |
65 | 98 phn->_node = C->top(); |
0 | 99 phn->set_node_type(PointsToNode::JavaObject); |
100 phn->set_escape_state(PointsToNode::GlobalEscape); | |
101 } | |
102 | |
103 void ConnectionGraph::add_pointsto_edge(uint from_i, uint to_i) { | |
104 PointsToNode *f = ptnode_adr(from_i); | |
105 PointsToNode *t = ptnode_adr(to_i); | |
106 | |
107 assert(f->node_type() != PointsToNode::UnknownType && t->node_type() != PointsToNode::UnknownType, "node types must be set"); | |
108 assert(f->node_type() == PointsToNode::LocalVar || f->node_type() == PointsToNode::Field, "invalid source of PointsTo edge"); | |
109 assert(t->node_type() == PointsToNode::JavaObject, "invalid destination of PointsTo edge"); | |
110 f->add_edge(to_i, PointsToNode::PointsToEdge); | |
111 } | |
112 | |
113 void ConnectionGraph::add_deferred_edge(uint from_i, uint to_i) { | |
114 PointsToNode *f = ptnode_adr(from_i); | |
115 PointsToNode *t = ptnode_adr(to_i); | |
116 | |
117 assert(f->node_type() != PointsToNode::UnknownType && t->node_type() != PointsToNode::UnknownType, "node types must be set"); | |
118 assert(f->node_type() == PointsToNode::LocalVar || f->node_type() == PointsToNode::Field, "invalid source of Deferred edge"); | |
119 assert(t->node_type() == PointsToNode::LocalVar || t->node_type() == PointsToNode::Field, "invalid destination of Deferred edge"); | |
120 // don't add a self-referential edge, this can occur during removal of | |
121 // deferred edges | |
122 if (from_i != to_i) | |
123 f->add_edge(to_i, PointsToNode::DeferredEdge); | |
124 } | |
125 | |
65 | 126 int ConnectionGraph::address_offset(Node* adr, PhaseTransform *phase) { |
127 const Type *adr_type = phase->type(adr); | |
128 if (adr->is_AddP() && adr_type->isa_oopptr() == NULL && | |
129 adr->in(AddPNode::Address)->is_Proj() && | |
130 adr->in(AddPNode::Address)->in(0)->is_Allocate()) { | |
131 // We are computing a raw address for a store captured by an Initialize | |
132 // compute an appropriate address type. AddP cases #3 and #5 (see below). | |
133 int offs = (int)phase->find_intptr_t_con(adr->in(AddPNode::Offset), Type::OffsetBot); | |
134 assert(offs != Type::OffsetBot || | |
135 adr->in(AddPNode::Address)->in(0)->is_AllocateArray(), | |
136 "offset must be a constant or it is initialization of array"); | |
137 return offs; | |
138 } | |
139 const TypePtr *t_ptr = adr_type->isa_ptr(); | |
0 | 140 assert(t_ptr != NULL, "must be a pointer type"); |
141 return t_ptr->offset(); | |
142 } | |
143 | |
144 void ConnectionGraph::add_field_edge(uint from_i, uint to_i, int offset) { | |
145 PointsToNode *f = ptnode_adr(from_i); | |
146 PointsToNode *t = ptnode_adr(to_i); | |
147 | |
148 assert(f->node_type() != PointsToNode::UnknownType && t->node_type() != PointsToNode::UnknownType, "node types must be set"); | |
149 assert(f->node_type() == PointsToNode::JavaObject, "invalid destination of Field edge"); | |
150 assert(t->node_type() == PointsToNode::Field, "invalid destination of Field edge"); | |
151 assert (t->offset() == -1 || t->offset() == offset, "conflicting field offsets"); | |
152 t->set_offset(offset); | |
153 | |
154 f->add_edge(to_i, PointsToNode::FieldEdge); | |
155 } | |
156 | |
157 void ConnectionGraph::set_escape_state(uint ni, PointsToNode::EscapeState es) { | |
158 PointsToNode *npt = ptnode_adr(ni); | |
159 PointsToNode::EscapeState old_es = npt->escape_state(); | |
160 if (es > old_es) | |
161 npt->set_escape_state(es); | |
162 } | |
163 | |
65 | 164 void ConnectionGraph::add_node(Node *n, PointsToNode::NodeType nt, |
165 PointsToNode::EscapeState es, bool done) { | |
166 PointsToNode* ptadr = ptnode_adr(n->_idx); | |
167 ptadr->_node = n; | |
168 ptadr->set_node_type(nt); | |
169 | |
170 // inline set_escape_state(idx, es); | |
171 PointsToNode::EscapeState old_es = ptadr->escape_state(); | |
172 if (es > old_es) | |
173 ptadr->set_escape_state(es); | |
174 | |
175 if (done) | |
176 _processed.set(n->_idx); | |
177 } | |
178 | |
0 | 179 PointsToNode::EscapeState ConnectionGraph::escape_state(Node *n, PhaseTransform *phase) { |
180 uint idx = n->_idx; | |
181 PointsToNode::EscapeState es; | |
182 | |
65 | 183 // If we are still collecting or there were no non-escaping allocations |
184 // we don't know the answer yet | |
185 if (_collecting || !_has_allocations) | |
0 | 186 return PointsToNode::UnknownEscape; |
187 | |
188 // if the node was created after the escape computation, return | |
189 // UnknownEscape | |
190 if (idx >= (uint)_nodes->length()) | |
191 return PointsToNode::UnknownEscape; | |
192 | |
193 es = _nodes->at_grow(idx).escape_state(); | |
194 | |
195 // if we have already computed a value, return it | |
196 if (es != PointsToNode::UnknownEscape) | |
197 return es; | |
198 | |
199 // compute max escape state of anything this node could point to | |
200 VectorSet ptset(Thread::current()->resource_area()); | |
201 PointsTo(ptset, n, phase); | |
65 | 202 for(VectorSetI i(&ptset); i.test() && es != PointsToNode::GlobalEscape; ++i) { |
0 | 203 uint pt = i.elem; |
65 | 204 PointsToNode::EscapeState pes = _nodes->adr_at(pt)->escape_state(); |
0 | 205 if (pes > es) |
206 es = pes; | |
207 } | |
208 // cache the computed escape state | |
209 assert(es != PointsToNode::UnknownEscape, "should have computed an escape state"); | |
210 _nodes->adr_at(idx)->set_escape_state(es); | |
211 return es; | |
212 } | |
213 | |
214 void ConnectionGraph::PointsTo(VectorSet &ptset, Node * n, PhaseTransform *phase) { | |
215 VectorSet visited(Thread::current()->resource_area()); | |
216 GrowableArray<uint> worklist; | |
217 | |
124
b130b98db9cf
6689060: Escape Analysis does not work with Compressed Oops
kvn
parents:
113
diff
changeset
|
218 #ifdef ASSERT |
b130b98db9cf
6689060: Escape Analysis does not work with Compressed Oops
kvn
parents:
113
diff
changeset
|
219 Node *orig_n = n; |
b130b98db9cf
6689060: Escape Analysis does not work with Compressed Oops
kvn
parents:
113
diff
changeset
|
220 #endif |
b130b98db9cf
6689060: Escape Analysis does not work with Compressed Oops
kvn
parents:
113
diff
changeset
|
221 |
65 | 222 n = n->uncast(); |
0 | 223 PointsToNode npt = _nodes->at_grow(n->_idx); |
224 | |
225 // If we have a JavaObject, return just that object | |
226 if (npt.node_type() == PointsToNode::JavaObject) { | |
227 ptset.set(n->_idx); | |
228 return; | |
229 } | |
124
b130b98db9cf
6689060: Escape Analysis does not work with Compressed Oops
kvn
parents:
113
diff
changeset
|
230 #ifdef ASSERT |
b130b98db9cf
6689060: Escape Analysis does not work with Compressed Oops
kvn
parents:
113
diff
changeset
|
231 if (npt._node == NULL) { |
b130b98db9cf
6689060: Escape Analysis does not work with Compressed Oops
kvn
parents:
113
diff
changeset
|
232 if (orig_n != n) |
b130b98db9cf
6689060: Escape Analysis does not work with Compressed Oops
kvn
parents:
113
diff
changeset
|
233 orig_n->dump(); |
b130b98db9cf
6689060: Escape Analysis does not work with Compressed Oops
kvn
parents:
113
diff
changeset
|
234 n->dump(); |
b130b98db9cf
6689060: Escape Analysis does not work with Compressed Oops
kvn
parents:
113
diff
changeset
|
235 assert(npt._node != NULL, "unregistered node"); |
b130b98db9cf
6689060: Escape Analysis does not work with Compressed Oops
kvn
parents:
113
diff
changeset
|
236 } |
b130b98db9cf
6689060: Escape Analysis does not work with Compressed Oops
kvn
parents:
113
diff
changeset
|
237 #endif |
0 | 238 worklist.push(n->_idx); |
239 while(worklist.length() > 0) { | |
240 int ni = worklist.pop(); | |
241 PointsToNode pn = _nodes->at_grow(ni); | |
65 | 242 if (!visited.test_set(ni)) { |
0 | 243 // ensure that all inputs of a Phi have been processed |
65 | 244 assert(!_collecting || !pn._node->is_Phi() || _processed.test(ni),""); |
0 | 245 |
246 int edges_processed = 0; | |
247 for (uint e = 0; e < pn.edge_count(); e++) { | |
65 | 248 uint etgt = pn.edge_target(e); |
0 | 249 PointsToNode::EdgeType et = pn.edge_type(e); |
250 if (et == PointsToNode::PointsToEdge) { | |
65 | 251 ptset.set(etgt); |
0 | 252 edges_processed++; |
253 } else if (et == PointsToNode::DeferredEdge) { | |
65 | 254 worklist.push(etgt); |
0 | 255 edges_processed++; |
65 | 256 } else { |
257 assert(false,"neither PointsToEdge or DeferredEdge"); | |
0 | 258 } |
259 } | |
260 if (edges_processed == 0) { | |
65 | 261 // no deferred or pointsto edges found. Assume the value was set |
262 // outside this method. Add the phantom object to the pointsto set. | |
0 | 263 ptset.set(_phantom_object); |
264 } | |
265 } | |
266 } | |
267 } | |
268 | |
101
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
269 void ConnectionGraph::remove_deferred(uint ni, GrowableArray<uint>* deferred_edges, VectorSet* visited) { |
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
270 // This method is most expensive during ConnectionGraph construction. |
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
271 // Reuse vectorSet and an additional growable array for deferred edges. |
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
272 deferred_edges->clear(); |
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
273 visited->Clear(); |
0 | 274 |
275 uint i = 0; | |
276 PointsToNode *ptn = ptnode_adr(ni); | |
277 | |
101
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
278 // Mark current edges as visited and move deferred edges to separate array. |
124
b130b98db9cf
6689060: Escape Analysis does not work with Compressed Oops
kvn
parents:
113
diff
changeset
|
279 while (i < ptn->edge_count()) { |
65 | 280 uint t = ptn->edge_target(i); |
101
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
281 #ifdef ASSERT |
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
282 assert(!visited->test_set(t), "expecting no duplications"); |
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
283 #else |
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
284 visited->set(t); |
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
285 #endif |
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
286 if (ptn->edge_type(i) == PointsToNode::DeferredEdge) { |
0 | 287 ptn->remove_edge(t, PointsToNode::DeferredEdge); |
101
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
288 deferred_edges->append(t); |
124
b130b98db9cf
6689060: Escape Analysis does not work with Compressed Oops
kvn
parents:
113
diff
changeset
|
289 } else { |
b130b98db9cf
6689060: Escape Analysis does not work with Compressed Oops
kvn
parents:
113
diff
changeset
|
290 i++; |
101
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
291 } |
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
292 } |
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
293 for (int next = 0; next < deferred_edges->length(); ++next) { |
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
294 uint t = deferred_edges->at(next); |
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
295 PointsToNode *ptt = ptnode_adr(t); |
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
296 for (uint j = 0; j < ptt->edge_count(); j++) { |
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
297 uint n1 = ptt->edge_target(j); |
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
298 if (visited->test_set(n1)) |
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
299 continue; |
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
300 switch(ptt->edge_type(j)) { |
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
301 case PointsToNode::PointsToEdge: |
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
302 add_pointsto_edge(ni, n1); |
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
303 if(n1 == _phantom_object) { |
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
304 // Special case - field set outside (globally escaping). |
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
305 ptn->set_escape_state(PointsToNode::GlobalEscape); |
0 | 306 } |
101
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
307 break; |
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
308 case PointsToNode::DeferredEdge: |
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
309 deferred_edges->append(n1); |
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
310 break; |
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
311 case PointsToNode::FieldEdge: |
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
312 assert(false, "invalid connection graph"); |
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
313 break; |
0 | 314 } |
315 } | |
316 } | |
317 } | |
318 | |
319 | |
320 // Add an edge to node given by "to_i" from any field of adr_i whose offset | |
321 // matches "offset" A deferred edge is added if to_i is a LocalVar, and | |
322 // a pointsto edge is added if it is a JavaObject | |
323 | |
324 void ConnectionGraph::add_edge_from_fields(uint adr_i, uint to_i, int offs) { | |
325 PointsToNode an = _nodes->at_grow(adr_i); | |
326 PointsToNode to = _nodes->at_grow(to_i); | |
327 bool deferred = (to.node_type() == PointsToNode::LocalVar); | |
328 | |
329 for (uint fe = 0; fe < an.edge_count(); fe++) { | |
330 assert(an.edge_type(fe) == PointsToNode::FieldEdge, "expecting a field edge"); | |
331 int fi = an.edge_target(fe); | |
332 PointsToNode pf = _nodes->at_grow(fi); | |
333 int po = pf.offset(); | |
334 if (po == offs || po == Type::OffsetBot || offs == Type::OffsetBot) { | |
335 if (deferred) | |
336 add_deferred_edge(fi, to_i); | |
337 else | |
338 add_pointsto_edge(fi, to_i); | |
339 } | |
340 } | |
341 } | |
342 | |
65 | 343 // Add a deferred edge from node given by "from_i" to any field of adr_i |
344 // whose offset matches "offset". | |
0 | 345 void ConnectionGraph::add_deferred_edge_to_fields(uint from_i, uint adr_i, int offs) { |
346 PointsToNode an = _nodes->at_grow(adr_i); | |
347 for (uint fe = 0; fe < an.edge_count(); fe++) { | |
348 assert(an.edge_type(fe) == PointsToNode::FieldEdge, "expecting a field edge"); | |
349 int fi = an.edge_target(fe); | |
350 PointsToNode pf = _nodes->at_grow(fi); | |
351 int po = pf.offset(); | |
352 if (pf.edge_count() == 0) { | |
353 // we have not seen any stores to this field, assume it was set outside this method | |
354 add_pointsto_edge(fi, _phantom_object); | |
355 } | |
356 if (po == offs || po == Type::OffsetBot || offs == Type::OffsetBot) { | |
357 add_deferred_edge(from_i, fi); | |
358 } | |
359 } | |
360 } | |
361 | |
65 | 362 // Helper functions |
363 | |
364 static Node* get_addp_base(Node *addp) { | |
365 assert(addp->is_AddP(), "must be AddP"); | |
366 // | |
367 // AddP cases for Base and Address inputs: | |
368 // case #1. Direct object's field reference: | |
369 // Allocate | |
370 // | | |
371 // Proj #5 ( oop result ) | |
372 // | | |
373 // CheckCastPP (cast to instance type) | |
374 // | | | |
375 // AddP ( base == address ) | |
376 // | |
377 // case #2. Indirect object's field reference: | |
378 // Phi | |
379 // | | |
380 // CastPP (cast to instance type) | |
381 // | | | |
382 // AddP ( base == address ) | |
383 // | |
384 // case #3. Raw object's field reference for Initialize node: | |
385 // Allocate | |
386 // | | |
387 // Proj #5 ( oop result ) | |
388 // top | | |
389 // \ | | |
390 // AddP ( base == top ) | |
391 // | |
392 // case #4. Array's element reference: | |
393 // {CheckCastPP | CastPP} | |
394 // | | | | |
395 // | AddP ( array's element offset ) | |
396 // | | | |
397 // AddP ( array's offset ) | |
398 // | |
399 // case #5. Raw object's field reference for arraycopy stub call: | |
400 // The inline_native_clone() case when the arraycopy stub is called | |
401 // after the allocation before Initialize and CheckCastPP nodes. | |
402 // Allocate | |
403 // | | |
404 // Proj #5 ( oop result ) | |
405 // | | | |
406 // AddP ( base == address ) | |
407 // | |
77 | 408 // case #6. Constant Pool, ThreadLocal, CastX2P or |
409 // Raw object's field reference: | |
410 // {ConP, ThreadLocal, CastX2P, raw Load} | |
65 | 411 // top | |
412 // \ | | |
413 // AddP ( base == top ) | |
414 // | |
77 | 415 // case #7. Klass's field reference. |
416 // LoadKlass | |
417 // | | | |
418 // AddP ( base == address ) | |
419 // | |
164
c436414a719e
6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents:
163
diff
changeset
|
420 // case #8. narrow Klass's field reference. |
c436414a719e
6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents:
163
diff
changeset
|
421 // LoadNKlass |
c436414a719e
6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents:
163
diff
changeset
|
422 // | |
c436414a719e
6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents:
163
diff
changeset
|
423 // DecodeN |
c436414a719e
6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents:
163
diff
changeset
|
424 // | | |
c436414a719e
6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents:
163
diff
changeset
|
425 // AddP ( base == address ) |
c436414a719e
6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents:
163
diff
changeset
|
426 // |
65 | 427 Node *base = addp->in(AddPNode::Base)->uncast(); |
428 if (base->is_top()) { // The AddP case #3 and #6. | |
429 base = addp->in(AddPNode::Address)->uncast(); | |
430 assert(base->Opcode() == Op_ConP || base->Opcode() == Op_ThreadLocal || | |
168
7793bd37a336
6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents:
164
diff
changeset
|
431 base->Opcode() == Op_CastX2P || base->is_DecodeN() || |
77 | 432 (base->is_Mem() && base->bottom_type() == TypeRawPtr::NOTNULL) || |
433 (base->is_Proj() && base->in(0)->is_Allocate()), "sanity"); | |
0 | 434 } |
65 | 435 return base; |
436 } | |
437 | |
438 static Node* find_second_addp(Node* addp, Node* n) { | |
439 assert(addp->is_AddP() && addp->outcnt() > 0, "Don't process dead nodes"); | |
440 | |
441 Node* addp2 = addp->raw_out(0); | |
442 if (addp->outcnt() == 1 && addp2->is_AddP() && | |
443 addp2->in(AddPNode::Base) == n && | |
444 addp2->in(AddPNode::Address) == addp) { | |
445 | |
446 assert(addp->in(AddPNode::Base) == n, "expecting the same base"); | |
447 // | |
448 // Find array's offset to push it on worklist first and | |
449 // as result process an array's element offset first (pushed second) | |
450 // to avoid CastPP for the array's offset. | |
451 // Otherwise the inserted CastPP (LocalVar) will point to what | |
452 // the AddP (Field) points to. Which would be wrong since | |
453 // the algorithm expects the CastPP has the same point as | |
454 // as AddP's base CheckCastPP (LocalVar). | |
455 // | |
456 // ArrayAllocation | |
457 // | | |
458 // CheckCastPP | |
459 // | | |
460 // memProj (from ArrayAllocation CheckCastPP) | |
461 // | || | |
462 // | || Int (element index) | |
463 // | || | ConI (log(element size)) | |
464 // | || | / | |
465 // | || LShift | |
466 // | || / | |
467 // | AddP (array's element offset) | |
468 // | | | |
469 // | | ConI (array's offset: #12(32-bits) or #24(64-bits)) | |
470 // | / / | |
471 // AddP (array's offset) | |
472 // | | |
473 // Load/Store (memory operation on array's element) | |
474 // | |
475 return addp2; | |
476 } | |
477 return NULL; | |
0 | 478 } |
479 | |
480 // | |
481 // Adjust the type and inputs of an AddP which computes the | |
482 // address of a field of an instance | |
483 // | |
484 void ConnectionGraph::split_AddP(Node *addp, Node *base, PhaseGVN *igvn) { | |
65 | 485 const TypeOopPtr *base_t = igvn->type(base)->isa_oopptr(); |
223 | 486 assert(base_t != NULL && base_t->is_known_instance(), "expecting instance oopptr"); |
0 | 487 const TypeOopPtr *t = igvn->type(addp)->isa_oopptr(); |
65 | 488 if (t == NULL) { |
489 // We are computing a raw address for a store captured by an Initialize | |
490 // compute an appropriate address type. | |
491 assert(igvn->type(addp) == TypeRawPtr::NOTNULL, "must be raw pointer"); | |
492 assert(addp->in(AddPNode::Address)->is_Proj(), "base of raw address must be result projection from allocation"); | |
493 int offs = (int)igvn->find_intptr_t_con(addp->in(AddPNode::Offset), Type::OffsetBot); | |
494 assert(offs != Type::OffsetBot, "offset must be a constant"); | |
495 t = base_t->add_offset(offs)->is_oopptr(); | |
496 } | |
223 | 497 int inst_id = base_t->instance_id(); |
498 assert(!t->is_known_instance() || t->instance_id() == inst_id, | |
0 | 499 "old type must be non-instance or match new type"); |
500 const TypeOopPtr *tinst = base_t->add_offset(t->offset())->is_oopptr(); | |
65 | 501 // Do NOT remove the next call: ensure an new alias index is allocated |
502 // for the instance type | |
0 | 503 int alias_idx = _compile->get_alias_index(tinst); |
504 igvn->set_type(addp, tinst); | |
505 // record the allocation in the node map | |
506 set_map(addp->_idx, get_map(base->_idx)); | |
65 | 507 // if the Address input is not the appropriate instance type |
508 // (due to intervening casts,) insert a cast | |
0 | 509 Node *adr = addp->in(AddPNode::Address); |
510 const TypeOopPtr *atype = igvn->type(adr)->isa_oopptr(); | |
65 | 511 if (atype != NULL && atype->instance_id() != inst_id) { |
223 | 512 assert(!atype->is_known_instance(), "no conflicting instances"); |
0 | 513 const TypeOopPtr *new_atype = base_t->add_offset(atype->offset())->isa_oopptr(); |
514 Node *acast = new (_compile, 2) CastPPNode(adr, new_atype); | |
515 acast->set_req(0, adr->in(0)); | |
516 igvn->set_type(acast, new_atype); | |
517 record_for_optimizer(acast); | |
518 Node *bcast = acast; | |
519 Node *abase = addp->in(AddPNode::Base); | |
520 if (abase != adr) { | |
521 bcast = new (_compile, 2) CastPPNode(abase, base_t); | |
522 bcast->set_req(0, abase->in(0)); | |
523 igvn->set_type(bcast, base_t); | |
524 record_for_optimizer(bcast); | |
525 } | |
526 igvn->hash_delete(addp); | |
527 addp->set_req(AddPNode::Base, bcast); | |
528 addp->set_req(AddPNode::Address, acast); | |
529 igvn->hash_insert(addp); | |
530 } | |
65 | 531 // Put on IGVN worklist since at least addp's type was changed above. |
532 record_for_optimizer(addp); | |
0 | 533 } |
534 | |
535 // | |
536 // Create a new version of orig_phi if necessary. Returns either the newly | |
537 // created phi or an existing phi. Sets create_new to indicate wheter a new | |
538 // phi was created. Cache the last newly created phi in the node map. | |
539 // | |
540 PhiNode *ConnectionGraph::create_split_phi(PhiNode *orig_phi, int alias_idx, GrowableArray<PhiNode *> &orig_phi_worklist, PhaseGVN *igvn, bool &new_created) { | |
541 Compile *C = _compile; | |
542 new_created = false; | |
543 int phi_alias_idx = C->get_alias_index(orig_phi->adr_type()); | |
544 // nothing to do if orig_phi is bottom memory or matches alias_idx | |
65 | 545 if (phi_alias_idx == alias_idx) { |
0 | 546 return orig_phi; |
547 } | |
548 // have we already created a Phi for this alias index? | |
549 PhiNode *result = get_map_phi(orig_phi->_idx); | |
550 if (result != NULL && C->get_alias_index(result->adr_type()) == alias_idx) { | |
551 return result; | |
552 } | |
38
b789bcaf2dd9
6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents:
0
diff
changeset
|
553 if ((int)C->unique() + 2*NodeLimitFudgeFactor > MaxNodeLimit) { |
b789bcaf2dd9
6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents:
0
diff
changeset
|
554 if (C->do_escape_analysis() == true && !C->failing()) { |
b789bcaf2dd9
6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents:
0
diff
changeset
|
555 // Retry compilation without escape analysis. |
b789bcaf2dd9
6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents:
0
diff
changeset
|
556 // If this is the first failure, the sentinel string will "stick" |
b789bcaf2dd9
6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents:
0
diff
changeset
|
557 // to the Compile object, and the C2Compiler will see it and retry. |
b789bcaf2dd9
6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents:
0
diff
changeset
|
558 C->record_failure(C2Compiler::retry_no_escape_analysis()); |
b789bcaf2dd9
6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents:
0
diff
changeset
|
559 } |
b789bcaf2dd9
6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents:
0
diff
changeset
|
560 return NULL; |
b789bcaf2dd9
6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents:
0
diff
changeset
|
561 } |
0 | 562 orig_phi_worklist.append_if_missing(orig_phi); |
65 | 563 const TypePtr *atype = C->get_adr_type(alias_idx); |
0 | 564 result = PhiNode::make(orig_phi->in(0), NULL, Type::MEMORY, atype); |
565 set_map_phi(orig_phi->_idx, result); | |
566 igvn->set_type(result, result->bottom_type()); | |
567 record_for_optimizer(result); | |
568 new_created = true; | |
569 return result; | |
570 } | |
571 | |
572 // | |
573 // Return a new version of Memory Phi "orig_phi" with the inputs having the | |
574 // specified alias index. | |
575 // | |
576 PhiNode *ConnectionGraph::split_memory_phi(PhiNode *orig_phi, int alias_idx, GrowableArray<PhiNode *> &orig_phi_worklist, PhaseGVN *igvn) { | |
577 | |
578 assert(alias_idx != Compile::AliasIdxBot, "can't split out bottom memory"); | |
579 Compile *C = _compile; | |
580 bool new_phi_created; | |
65 | 581 PhiNode *result = create_split_phi(orig_phi, alias_idx, orig_phi_worklist, igvn, new_phi_created); |
0 | 582 if (!new_phi_created) { |
583 return result; | |
584 } | |
585 | |
586 GrowableArray<PhiNode *> phi_list; | |
587 GrowableArray<uint> cur_input; | |
588 | |
589 PhiNode *phi = orig_phi; | |
590 uint idx = 1; | |
591 bool finished = false; | |
592 while(!finished) { | |
593 while (idx < phi->req()) { | |
65 | 594 Node *mem = find_inst_mem(phi->in(idx), alias_idx, orig_phi_worklist, igvn); |
0 | 595 if (mem != NULL && mem->is_Phi()) { |
65 | 596 PhiNode *newphi = create_split_phi(mem->as_Phi(), alias_idx, orig_phi_worklist, igvn, new_phi_created); |
0 | 597 if (new_phi_created) { |
598 // found an phi for which we created a new split, push current one on worklist and begin | |
599 // processing new one | |
600 phi_list.push(phi); | |
601 cur_input.push(idx); | |
602 phi = mem->as_Phi(); | |
65 | 603 result = newphi; |
0 | 604 idx = 1; |
605 continue; | |
606 } else { | |
65 | 607 mem = newphi; |
0 | 608 } |
609 } | |
38
b789bcaf2dd9
6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents:
0
diff
changeset
|
610 if (C->failing()) { |
b789bcaf2dd9
6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents:
0
diff
changeset
|
611 return NULL; |
b789bcaf2dd9
6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents:
0
diff
changeset
|
612 } |
0 | 613 result->set_req(idx++, mem); |
614 } | |
615 #ifdef ASSERT | |
616 // verify that the new Phi has an input for each input of the original | |
617 assert( phi->req() == result->req(), "must have same number of inputs."); | |
618 assert( result->in(0) != NULL && result->in(0) == phi->in(0), "regions must match"); | |
65 | 619 #endif |
620 // Check if all new phi's inputs have specified alias index. | |
621 // Otherwise use old phi. | |
0 | 622 for (uint i = 1; i < phi->req(); i++) { |
65 | 623 Node* in = result->in(i); |
624 assert((phi->in(i) == NULL) == (in == NULL), "inputs must correspond."); | |
0 | 625 } |
626 // we have finished processing a Phi, see if there are any more to do | |
627 finished = (phi_list.length() == 0 ); | |
628 if (!finished) { | |
629 phi = phi_list.pop(); | |
630 idx = cur_input.pop(); | |
65 | 631 PhiNode *prev_result = get_map_phi(phi->_idx); |
632 prev_result->set_req(idx++, result); | |
633 result = prev_result; | |
0 | 634 } |
635 } | |
636 return result; | |
637 } | |
638 | |
65 | 639 |
640 // | |
641 // The next methods are derived from methods in MemNode. | |
642 // | |
643 static Node *step_through_mergemem(MergeMemNode *mmem, int alias_idx, const TypeOopPtr *tinst) { | |
644 Node *mem = mmem; | |
645 // TypeInstPtr::NOTNULL+any is an OOP with unknown offset - generally | |
646 // means an array I have not precisely typed yet. Do not do any | |
647 // alias stuff with it any time soon. | |
648 if( tinst->base() != Type::AnyPtr && | |
649 !(tinst->klass()->is_java_lang_Object() && | |
650 tinst->offset() == Type::OffsetBot) ) { | |
651 mem = mmem->memory_at(alias_idx); | |
652 // Update input if it is progress over what we have now | |
653 } | |
654 return mem; | |
655 } | |
656 | |
657 // | |
658 // Search memory chain of "mem" to find a MemNode whose address | |
659 // is the specified alias index. | |
660 // | |
661 Node* ConnectionGraph::find_inst_mem(Node *orig_mem, int alias_idx, GrowableArray<PhiNode *> &orig_phis, PhaseGVN *phase) { | |
662 if (orig_mem == NULL) | |
663 return orig_mem; | |
664 Compile* C = phase->C; | |
665 const TypeOopPtr *tinst = C->get_adr_type(alias_idx)->isa_oopptr(); | |
223 | 666 bool is_instance = (tinst != NULL) && tinst->is_known_instance(); |
65 | 667 Node *prev = NULL; |
668 Node *result = orig_mem; | |
669 while (prev != result) { | |
670 prev = result; | |
671 if (result->is_Mem()) { | |
672 MemNode *mem = result->as_Mem(); | |
673 const Type *at = phase->type(mem->in(MemNode::Address)); | |
674 if (at != Type::TOP) { | |
675 assert (at->isa_ptr() != NULL, "pointer type required."); | |
676 int idx = C->get_alias_index(at->is_ptr()); | |
677 if (idx == alias_idx) | |
678 break; | |
679 } | |
680 result = mem->in(MemNode::Memory); | |
681 } | |
682 if (!is_instance) | |
683 continue; // don't search further for non-instance types | |
684 // skip over a call which does not affect this memory slice | |
685 if (result->is_Proj() && result->as_Proj()->_con == TypeFunc::Memory) { | |
686 Node *proj_in = result->in(0); | |
687 if (proj_in->is_Call()) { | |
688 CallNode *call = proj_in->as_Call(); | |
689 if (!call->may_modify(tinst, phase)) { | |
690 result = call->in(TypeFunc::Memory); | |
691 } | |
692 } else if (proj_in->is_Initialize()) { | |
693 AllocateNode* alloc = proj_in->as_Initialize()->allocation(); | |
694 // Stop if this is the initialization for the object instance which | |
695 // which contains this memory slice, otherwise skip over it. | |
223 | 696 if (alloc == NULL || alloc->_idx != (uint)tinst->instance_id()) { |
65 | 697 result = proj_in->in(TypeFunc::Memory); |
698 } | |
699 } else if (proj_in->is_MemBar()) { | |
700 result = proj_in->in(TypeFunc::Memory); | |
701 } | |
702 } else if (result->is_MergeMem()) { | |
703 MergeMemNode *mmem = result->as_MergeMem(); | |
704 result = step_through_mergemem(mmem, alias_idx, tinst); | |
705 if (result == mmem->base_memory()) { | |
706 // Didn't find instance memory, search through general slice recursively. | |
707 result = mmem->memory_at(C->get_general_index(alias_idx)); | |
708 result = find_inst_mem(result, alias_idx, orig_phis, phase); | |
709 if (C->failing()) { | |
710 return NULL; | |
711 } | |
712 mmem->set_memory_at(alias_idx, result); | |
713 } | |
714 } else if (result->is_Phi() && | |
715 C->get_alias_index(result->as_Phi()->adr_type()) != alias_idx) { | |
716 Node *un = result->as_Phi()->unique_input(phase); | |
717 if (un != NULL) { | |
718 result = un; | |
719 } else { | |
720 break; | |
721 } | |
722 } | |
723 } | |
724 if (is_instance && result->is_Phi()) { | |
725 PhiNode *mphi = result->as_Phi(); | |
726 assert(mphi->bottom_type() == Type::MEMORY, "memory phi required"); | |
727 const TypePtr *t = mphi->adr_type(); | |
728 if (C->get_alias_index(t) != alias_idx) { | |
729 result = split_memory_phi(mphi, alias_idx, orig_phis, phase); | |
730 } | |
731 } | |
732 // the result is either MemNode, PhiNode, InitializeNode. | |
733 return result; | |
734 } | |
735 | |
736 | |
0 | 737 // |
738 // Convert the types of unescaped object to instance types where possible, | |
739 // propagate the new type information through the graph, and update memory | |
740 // edges and MergeMem inputs to reflect the new type. | |
741 // | |
742 // We start with allocations (and calls which may be allocations) on alloc_worklist. | |
743 // The processing is done in 4 phases: | |
744 // | |
745 // Phase 1: Process possible allocations from alloc_worklist. Create instance | |
746 // types for the CheckCastPP for allocations where possible. | |
747 // Propagate the the new types through users as follows: | |
748 // casts and Phi: push users on alloc_worklist | |
749 // AddP: cast Base and Address inputs to the instance type | |
750 // push any AddP users on alloc_worklist and push any memnode | |
751 // users onto memnode_worklist. | |
752 // Phase 2: Process MemNode's from memnode_worklist. compute new address type and | |
753 // search the Memory chain for a store with the appropriate type | |
754 // address type. If a Phi is found, create a new version with | |
755 // the approriate memory slices from each of the Phi inputs. | |
756 // For stores, process the users as follows: | |
757 // MemNode: push on memnode_worklist | |
758 // MergeMem: push on mergemem_worklist | |
759 // Phase 3: Process MergeMem nodes from mergemem_worklist. Walk each memory slice | |
760 // moving the first node encountered of each instance type to the | |
761 // the input corresponding to its alias index. | |
762 // appropriate memory slice. | |
763 // Phase 4: Update the inputs of non-instance memory Phis and the Memory input of memnodes. | |
764 // | |
765 // In the following example, the CheckCastPP nodes are the cast of allocation | |
766 // results and the allocation of node 29 is unescaped and eligible to be an | |
767 // instance type. | |
768 // | |
769 // We start with: | |
770 // | |
771 // 7 Parm #memory | |
772 // 10 ConI "12" | |
773 // 19 CheckCastPP "Foo" | |
774 // 20 AddP _ 19 19 10 Foo+12 alias_index=4 | |
775 // 29 CheckCastPP "Foo" | |
776 // 30 AddP _ 29 29 10 Foo+12 alias_index=4 | |
777 // | |
778 // 40 StoreP 25 7 20 ... alias_index=4 | |
779 // 50 StoreP 35 40 30 ... alias_index=4 | |
780 // 60 StoreP 45 50 20 ... alias_index=4 | |
781 // 70 LoadP _ 60 30 ... alias_index=4 | |
782 // 80 Phi 75 50 60 Memory alias_index=4 | |
783 // 90 LoadP _ 80 30 ... alias_index=4 | |
784 // 100 LoadP _ 80 20 ... alias_index=4 | |
785 // | |
786 // | |
787 // Phase 1 creates an instance type for node 29 assigning it an instance id of 24 | |
788 // and creating a new alias index for node 30. This gives: | |
789 // | |
790 // 7 Parm #memory | |
791 // 10 ConI "12" | |
792 // 19 CheckCastPP "Foo" | |
793 // 20 AddP _ 19 19 10 Foo+12 alias_index=4 | |
794 // 29 CheckCastPP "Foo" iid=24 | |
795 // 30 AddP _ 29 29 10 Foo+12 alias_index=6 iid=24 | |
796 // | |
797 // 40 StoreP 25 7 20 ... alias_index=4 | |
798 // 50 StoreP 35 40 30 ... alias_index=6 | |
799 // 60 StoreP 45 50 20 ... alias_index=4 | |
800 // 70 LoadP _ 60 30 ... alias_index=6 | |
801 // 80 Phi 75 50 60 Memory alias_index=4 | |
802 // 90 LoadP _ 80 30 ... alias_index=6 | |
803 // 100 LoadP _ 80 20 ... alias_index=4 | |
804 // | |
805 // In phase 2, new memory inputs are computed for the loads and stores, | |
806 // And a new version of the phi is created. In phase 4, the inputs to | |
807 // node 80 are updated and then the memory nodes are updated with the | |
808 // values computed in phase 2. This results in: | |
809 // | |
810 // 7 Parm #memory | |
811 // 10 ConI "12" | |
812 // 19 CheckCastPP "Foo" | |
813 // 20 AddP _ 19 19 10 Foo+12 alias_index=4 | |
814 // 29 CheckCastPP "Foo" iid=24 | |
815 // 30 AddP _ 29 29 10 Foo+12 alias_index=6 iid=24 | |
816 // | |
817 // 40 StoreP 25 7 20 ... alias_index=4 | |
818 // 50 StoreP 35 7 30 ... alias_index=6 | |
819 // 60 StoreP 45 40 20 ... alias_index=4 | |
820 // 70 LoadP _ 50 30 ... alias_index=6 | |
821 // 80 Phi 75 40 60 Memory alias_index=4 | |
822 // 120 Phi 75 50 50 Memory alias_index=6 | |
823 // 90 LoadP _ 120 30 ... alias_index=6 | |
824 // 100 LoadP _ 80 20 ... alias_index=4 | |
825 // | |
826 void ConnectionGraph::split_unique_types(GrowableArray<Node *> &alloc_worklist) { | |
827 GrowableArray<Node *> memnode_worklist; | |
828 GrowableArray<Node *> mergemem_worklist; | |
829 GrowableArray<PhiNode *> orig_phis; | |
830 PhaseGVN *igvn = _compile->initial_gvn(); | |
831 uint new_index_start = (uint) _compile->num_alias_types(); | |
832 VectorSet visited(Thread::current()->resource_area()); | |
833 VectorSet ptset(Thread::current()->resource_area()); | |
834 | |
65 | 835 |
836 // Phase 1: Process possible allocations from alloc_worklist. | |
837 // Create instance types for the CheckCastPP for allocations where possible. | |
0 | 838 while (alloc_worklist.length() != 0) { |
839 Node *n = alloc_worklist.pop(); | |
840 uint ni = n->_idx; | |
65 | 841 const TypeOopPtr* tinst = NULL; |
0 | 842 if (n->is_Call()) { |
843 CallNode *alloc = n->as_Call(); | |
844 // copy escape information to call node | |
65 | 845 PointsToNode* ptn = _nodes->adr_at(alloc->_idx); |
0 | 846 PointsToNode::EscapeState es = escape_state(alloc, igvn); |
65 | 847 // We have an allocation or call which returns a Java object, |
848 // see if it is unescaped. | |
849 if (es != PointsToNode::NoEscape || !ptn->_scalar_replaceable) | |
0 | 850 continue; |
39
76256d272075
6667612: (Escape Analysis) disable loop cloning if it has a scalar replaceable allocation
kvn
parents:
38
diff
changeset
|
851 if (alloc->is_Allocate()) { |
76256d272075
6667612: (Escape Analysis) disable loop cloning if it has a scalar replaceable allocation
kvn
parents:
38
diff
changeset
|
852 // Set the scalar_replaceable flag before the next check. |
76256d272075
6667612: (Escape Analysis) disable loop cloning if it has a scalar replaceable allocation
kvn
parents:
38
diff
changeset
|
853 alloc->as_Allocate()->_is_scalar_replaceable = true; |
76256d272075
6667612: (Escape Analysis) disable loop cloning if it has a scalar replaceable allocation
kvn
parents:
38
diff
changeset
|
854 } |
65 | 855 // find CheckCastPP of call return value |
856 n = alloc->result_cast(); | |
857 if (n == NULL || // No uses accept Initialize or | |
858 !n->is_CheckCastPP()) // not unique CheckCastPP. | |
859 continue; | |
860 // The inline code for Object.clone() casts the allocation result to | |
861 // java.lang.Object and then to the the actual type of the allocated | |
862 // object. Detect this case and use the second cast. | |
863 if (alloc->is_Allocate() && n->as_Type()->type() == TypeInstPtr::NOTNULL | |
864 && igvn->type(alloc->in(AllocateNode::KlassNode)) != TypeKlassPtr::OBJECT) { | |
865 Node *cast2 = NULL; | |
866 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) { | |
867 Node *use = n->fast_out(i); | |
868 if (use->is_CheckCastPP()) { | |
869 cast2 = use; | |
870 break; | |
871 } | |
872 } | |
873 if (cast2 != NULL) { | |
874 n = cast2; | |
875 } else { | |
876 continue; | |
877 } | |
878 } | |
879 set_escape_state(n->_idx, es); | |
880 // in order for an object to be stackallocatable, it must be: | |
881 // - a direct allocation (not a call returning an object) | |
882 // - non-escaping | |
883 // - eligible to be a unique type | |
884 // - not determined to be ineligible by escape analysis | |
0 | 885 set_map(alloc->_idx, n); |
886 set_map(n->_idx, alloc); | |
65 | 887 const TypeOopPtr *t = igvn->type(n)->isa_oopptr(); |
888 if (t == NULL) | |
0 | 889 continue; // not a TypeInstPtr |
223 | 890 tinst = t->cast_to_instance_id(ni); |
0 | 891 igvn->hash_delete(n); |
892 igvn->set_type(n, tinst); | |
893 n->raise_bottom_type(tinst); | |
894 igvn->hash_insert(n); | |
65 | 895 record_for_optimizer(n); |
896 if (alloc->is_Allocate() && ptn->_scalar_replaceable && | |
897 (t->isa_instptr() || t->isa_aryptr())) { | |
163 | 898 |
899 // First, put on the worklist all Field edges from Connection Graph | |
900 // which is more accurate then putting immediate users from Ideal Graph. | |
901 for (uint e = 0; e < ptn->edge_count(); e++) { | |
902 Node *use = _nodes->adr_at(ptn->edge_target(e))->_node; | |
903 assert(ptn->edge_type(e) == PointsToNode::FieldEdge && use->is_AddP(), | |
904 "only AddP nodes are Field edges in CG"); | |
905 if (use->outcnt() > 0) { // Don't process dead nodes | |
906 Node* addp2 = find_second_addp(use, use->in(AddPNode::Base)); | |
907 if (addp2 != NULL) { | |
908 assert(alloc->is_AllocateArray(),"array allocation was expected"); | |
909 alloc_worklist.append_if_missing(addp2); | |
910 } | |
911 alloc_worklist.append_if_missing(use); | |
912 } | |
913 } | |
914 | |
65 | 915 // An allocation may have an Initialize which has raw stores. Scan |
916 // the users of the raw allocation result and push AddP users | |
917 // on alloc_worklist. | |
918 Node *raw_result = alloc->proj_out(TypeFunc::Parms); | |
919 assert (raw_result != NULL, "must have an allocation result"); | |
920 for (DUIterator_Fast imax, i = raw_result->fast_outs(imax); i < imax; i++) { | |
921 Node *use = raw_result->fast_out(i); | |
922 if (use->is_AddP() && use->outcnt() > 0) { // Don't process dead nodes | |
923 Node* addp2 = find_second_addp(use, raw_result); | |
924 if (addp2 != NULL) { | |
925 assert(alloc->is_AllocateArray(),"array allocation was expected"); | |
926 alloc_worklist.append_if_missing(addp2); | |
927 } | |
928 alloc_worklist.append_if_missing(use); | |
929 } else if (use->is_Initialize()) { | |
930 memnode_worklist.append_if_missing(use); | |
931 } | |
932 } | |
933 } | |
0 | 934 } else if (n->is_AddP()) { |
935 ptset.Clear(); | |
65 | 936 PointsTo(ptset, get_addp_base(n), igvn); |
0 | 937 assert(ptset.Size() == 1, "AddP address is unique"); |
65 | 938 uint elem = ptset.getelem(); // Allocation node's index |
939 if (elem == _phantom_object) | |
940 continue; // Assume the value was set outside this method. | |
941 Node *base = get_map(elem); // CheckCastPP node | |
0 | 942 split_AddP(n, base, igvn); |
65 | 943 tinst = igvn->type(base)->isa_oopptr(); |
944 } else if (n->is_Phi() || | |
945 n->is_CheckCastPP() || | |
168
7793bd37a336
6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents:
164
diff
changeset
|
946 n->is_EncodeP() || |
7793bd37a336
6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents:
164
diff
changeset
|
947 n->is_DecodeN() || |
65 | 948 (n->is_ConstraintCast() && n->Opcode() == Op_CastPP)) { |
0 | 949 if (visited.test_set(n->_idx)) { |
950 assert(n->is_Phi(), "loops only through Phi's"); | |
951 continue; // already processed | |
952 } | |
953 ptset.Clear(); | |
954 PointsTo(ptset, n, igvn); | |
955 if (ptset.Size() == 1) { | |
65 | 956 uint elem = ptset.getelem(); // Allocation node's index |
957 if (elem == _phantom_object) | |
958 continue; // Assume the value was set outside this method. | |
959 Node *val = get_map(elem); // CheckCastPP node | |
0 | 960 TypeNode *tn = n->as_Type(); |
65 | 961 tinst = igvn->type(val)->isa_oopptr(); |
223 | 962 assert(tinst != NULL && tinst->is_known_instance() && |
963 (uint)tinst->instance_id() == elem , "instance type expected."); | |
163 | 964 |
965 const Type *tn_type = igvn->type(tn); | |
223 | 966 const TypeOopPtr *tn_t; |
967 if (tn_type->isa_narrowoop()) { | |
968 tn_t = tn_type->make_ptr()->isa_oopptr(); | |
969 } else { | |
970 tn_t = tn_type->isa_oopptr(); | |
971 } | |
0 | 972 |
65 | 973 if (tn_t != NULL && |
223 | 974 tinst->cast_to_instance_id(TypeOopPtr::InstanceBot)->higher_equal(tn_t)) { |
163 | 975 if (tn_type->isa_narrowoop()) { |
976 tn_type = tinst->make_narrowoop(); | |
977 } else { | |
978 tn_type = tinst; | |
979 } | |
0 | 980 igvn->hash_delete(tn); |
163 | 981 igvn->set_type(tn, tn_type); |
982 tn->set_type(tn_type); | |
0 | 983 igvn->hash_insert(tn); |
65 | 984 record_for_optimizer(n); |
0 | 985 } |
986 } | |
987 } else { | |
988 continue; | |
989 } | |
990 // push users on appropriate worklist | |
991 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) { | |
992 Node *use = n->fast_out(i); | |
993 if(use->is_Mem() && use->in(MemNode::Address) == n) { | |
65 | 994 memnode_worklist.append_if_missing(use); |
995 } else if (use->is_Initialize()) { | |
996 memnode_worklist.append_if_missing(use); | |
997 } else if (use->is_MergeMem()) { | |
998 mergemem_worklist.append_if_missing(use); | |
999 } else if (use->is_Call() && tinst != NULL) { | |
1000 // Look for MergeMem nodes for calls which reference unique allocation | |
1001 // (through CheckCastPP nodes) even for debug info. | |
1002 Node* m = use->in(TypeFunc::Memory); | |
1003 uint iid = tinst->instance_id(); | |
1004 while (m->is_Proj() && m->in(0)->is_Call() && | |
1005 m->in(0) != use && !m->in(0)->_idx != iid) { | |
1006 m = m->in(0)->in(TypeFunc::Memory); | |
1007 } | |
1008 if (m->is_MergeMem()) { | |
1009 mergemem_worklist.append_if_missing(m); | |
1010 } | |
1011 } else if (use->is_AddP() && use->outcnt() > 0) { // No dead nodes | |
1012 Node* addp2 = find_second_addp(use, n); | |
1013 if (addp2 != NULL) { | |
1014 alloc_worklist.append_if_missing(addp2); | |
1015 } | |
1016 alloc_worklist.append_if_missing(use); | |
1017 } else if (use->is_Phi() || | |
1018 use->is_CheckCastPP() || | |
168
7793bd37a336
6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents:
164
diff
changeset
|
1019 use->is_EncodeP() || |
7793bd37a336
6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents:
164
diff
changeset
|
1020 use->is_DecodeN() || |
65 | 1021 (use->is_ConstraintCast() && use->Opcode() == Op_CastPP)) { |
1022 alloc_worklist.append_if_missing(use); | |
0 | 1023 } |
1024 } | |
1025 | |
1026 } | |
65 | 1027 // New alias types were created in split_AddP(). |
0 | 1028 uint new_index_end = (uint) _compile->num_alias_types(); |
1029 | |
1030 // Phase 2: Process MemNode's from memnode_worklist. compute new address type and | |
1031 // compute new values for Memory inputs (the Memory inputs are not | |
1032 // actually updated until phase 4.) | |
1033 if (memnode_worklist.length() == 0) | |
1034 return; // nothing to do | |
1035 | |
1036 while (memnode_worklist.length() != 0) { | |
1037 Node *n = memnode_worklist.pop(); | |
65 | 1038 if (visited.test_set(n->_idx)) |
1039 continue; | |
0 | 1040 if (n->is_Phi()) { |
1041 assert(n->as_Phi()->adr_type() != TypePtr::BOTTOM, "narrow memory slice required"); | |
1042 // we don't need to do anything, but the users must be pushed if we haven't processed | |
1043 // this Phi before | |
65 | 1044 } else if (n->is_Initialize()) { |
1045 // we don't need to do anything, but the users of the memory projection must be pushed | |
1046 n = n->as_Initialize()->proj_out(TypeFunc::Memory); | |
1047 if (n == NULL) | |
0 | 1048 continue; |
1049 } else { | |
1050 assert(n->is_Mem(), "memory node required."); | |
1051 Node *addr = n->in(MemNode::Address); | |
65 | 1052 assert(addr->is_AddP(), "AddP required"); |
0 | 1053 const Type *addr_t = igvn->type(addr); |
1054 if (addr_t == Type::TOP) | |
1055 continue; | |
1056 assert (addr_t->isa_ptr() != NULL, "pointer type required."); | |
1057 int alias_idx = _compile->get_alias_index(addr_t->is_ptr()); | |
65 | 1058 assert ((uint)alias_idx < new_index_end, "wrong alias index"); |
1059 Node *mem = find_inst_mem(n->in(MemNode::Memory), alias_idx, orig_phis, igvn); | |
38
b789bcaf2dd9
6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents:
0
diff
changeset
|
1060 if (_compile->failing()) { |
b789bcaf2dd9
6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents:
0
diff
changeset
|
1061 return; |
b789bcaf2dd9
6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents:
0
diff
changeset
|
1062 } |
65 | 1063 if (mem != n->in(MemNode::Memory)) { |
0 | 1064 set_map(n->_idx, mem); |
65 | 1065 _nodes->adr_at(n->_idx)->_node = n; |
1066 } | |
0 | 1067 if (n->is_Load()) { |
1068 continue; // don't push users | |
1069 } else if (n->is_LoadStore()) { | |
1070 // get the memory projection | |
1071 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) { | |
1072 Node *use = n->fast_out(i); | |
1073 if (use->Opcode() == Op_SCMemProj) { | |
1074 n = use; | |
1075 break; | |
1076 } | |
1077 } | |
1078 assert(n->Opcode() == Op_SCMemProj, "memory projection required"); | |
1079 } | |
1080 } | |
1081 // push user on appropriate worklist | |
1082 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) { | |
1083 Node *use = n->fast_out(i); | |
1084 if (use->is_Phi()) { | |
65 | 1085 memnode_worklist.append_if_missing(use); |
0 | 1086 } else if(use->is_Mem() && use->in(MemNode::Memory) == n) { |
65 | 1087 memnode_worklist.append_if_missing(use); |
1088 } else if (use->is_Initialize()) { | |
1089 memnode_worklist.append_if_missing(use); | |
0 | 1090 } else if (use->is_MergeMem()) { |
65 | 1091 mergemem_worklist.append_if_missing(use); |
0 | 1092 } |
1093 } | |
1094 } | |
1095 | |
65 | 1096 // Phase 3: Process MergeMem nodes from mergemem_worklist. |
1097 // Walk each memory moving the first node encountered of each | |
1098 // instance type to the the input corresponding to its alias index. | |
0 | 1099 while (mergemem_worklist.length() != 0) { |
1100 Node *n = mergemem_worklist.pop(); | |
1101 assert(n->is_MergeMem(), "MergeMem node required."); | |
65 | 1102 if (visited.test_set(n->_idx)) |
1103 continue; | |
0 | 1104 MergeMemNode *nmm = n->as_MergeMem(); |
1105 // Note: we don't want to use MergeMemStream here because we only want to | |
65 | 1106 // scan inputs which exist at the start, not ones we add during processing. |
0 | 1107 uint nslices = nmm->req(); |
1108 igvn->hash_delete(nmm); | |
1109 for (uint i = Compile::AliasIdxRaw+1; i < nslices; i++) { | |
65 | 1110 Node* mem = nmm->in(i); |
1111 Node* cur = NULL; | |
0 | 1112 if (mem == NULL || mem->is_top()) |
1113 continue; | |
1114 while (mem->is_Mem()) { | |
1115 const Type *at = igvn->type(mem->in(MemNode::Address)); | |
1116 if (at != Type::TOP) { | |
1117 assert (at->isa_ptr() != NULL, "pointer type required."); | |
1118 uint idx = (uint)_compile->get_alias_index(at->is_ptr()); | |
1119 if (idx == i) { | |
1120 if (cur == NULL) | |
1121 cur = mem; | |
1122 } else { | |
1123 if (idx >= nmm->req() || nmm->is_empty_memory(nmm->in(idx))) { | |
1124 nmm->set_memory_at(idx, mem); | |
1125 } | |
1126 } | |
1127 } | |
1128 mem = mem->in(MemNode::Memory); | |
1129 } | |
1130 nmm->set_memory_at(i, (cur != NULL) ? cur : mem); | |
65 | 1131 // Find any instance of the current type if we haven't encountered |
1132 // a value of the instance along the chain. | |
1133 for (uint ni = new_index_start; ni < new_index_end; ni++) { | |
1134 if((uint)_compile->get_general_index(ni) == i) { | |
1135 Node *m = (ni >= nmm->req()) ? nmm->empty_memory() : nmm->in(ni); | |
1136 if (nmm->is_empty_memory(m)) { | |
1137 Node* result = find_inst_mem(mem, ni, orig_phis, igvn); | |
1138 if (_compile->failing()) { | |
1139 return; | |
1140 } | |
1141 nmm->set_memory_at(ni, result); | |
1142 } | |
1143 } | |
1144 } | |
1145 } | |
1146 // Find the rest of instances values | |
1147 for (uint ni = new_index_start; ni < new_index_end; ni++) { | |
1148 const TypeOopPtr *tinst = igvn->C->get_adr_type(ni)->isa_oopptr(); | |
1149 Node* result = step_through_mergemem(nmm, ni, tinst); | |
1150 if (result == nmm->base_memory()) { | |
1151 // Didn't find instance memory, search through general slice recursively. | |
1152 result = nmm->memory_at(igvn->C->get_general_index(ni)); | |
1153 result = find_inst_mem(result, ni, orig_phis, igvn); | |
1154 if (_compile->failing()) { | |
1155 return; | |
1156 } | |
1157 nmm->set_memory_at(ni, result); | |
1158 } | |
1159 } | |
1160 igvn->hash_insert(nmm); | |
1161 record_for_optimizer(nmm); | |
1162 | |
1163 // Propagate new memory slices to following MergeMem nodes. | |
1164 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) { | |
1165 Node *use = n->fast_out(i); | |
1166 if (use->is_Call()) { | |
1167 CallNode* in = use->as_Call(); | |
1168 if (in->proj_out(TypeFunc::Memory) != NULL) { | |
1169 Node* m = in->proj_out(TypeFunc::Memory); | |
1170 for (DUIterator_Fast jmax, j = m->fast_outs(jmax); j < jmax; j++) { | |
1171 Node* mm = m->fast_out(j); | |
1172 if (mm->is_MergeMem()) { | |
1173 mergemem_worklist.append_if_missing(mm); | |
1174 } | |
1175 } | |
1176 } | |
1177 if (use->is_Allocate()) { | |
1178 use = use->as_Allocate()->initialization(); | |
1179 if (use == NULL) { | |
1180 continue; | |
1181 } | |
1182 } | |
1183 } | |
1184 if (use->is_Initialize()) { | |
1185 InitializeNode* in = use->as_Initialize(); | |
1186 if (in->proj_out(TypeFunc::Memory) != NULL) { | |
1187 Node* m = in->proj_out(TypeFunc::Memory); | |
1188 for (DUIterator_Fast jmax, j = m->fast_outs(jmax); j < jmax; j++) { | |
1189 Node* mm = m->fast_out(j); | |
1190 if (mm->is_MergeMem()) { | |
1191 mergemem_worklist.append_if_missing(mm); | |
0 | 1192 } |
1193 } | |
1194 } | |
1195 } | |
1196 } | |
1197 } | |
1198 | |
65 | 1199 // Phase 4: Update the inputs of non-instance memory Phis and |
1200 // the Memory input of memnodes | |
0 | 1201 // First update the inputs of any non-instance Phi's from |
1202 // which we split out an instance Phi. Note we don't have | |
1203 // to recursively process Phi's encounted on the input memory | |
1204 // chains as is done in split_memory_phi() since they will | |
1205 // also be processed here. | |
1206 while (orig_phis.length() != 0) { | |
1207 PhiNode *phi = orig_phis.pop(); | |
1208 int alias_idx = _compile->get_alias_index(phi->adr_type()); | |
1209 igvn->hash_delete(phi); | |
1210 for (uint i = 1; i < phi->req(); i++) { | |
1211 Node *mem = phi->in(i); | |
65 | 1212 Node *new_mem = find_inst_mem(mem, alias_idx, orig_phis, igvn); |
1213 if (_compile->failing()) { | |
1214 return; | |
1215 } | |
0 | 1216 if (mem != new_mem) { |
1217 phi->set_req(i, new_mem); | |
1218 } | |
1219 } | |
1220 igvn->hash_insert(phi); | |
1221 record_for_optimizer(phi); | |
1222 } | |
1223 | |
1224 // Update the memory inputs of MemNodes with the value we computed | |
1225 // in Phase 2. | |
1226 for (int i = 0; i < _nodes->length(); i++) { | |
1227 Node *nmem = get_map(i); | |
1228 if (nmem != NULL) { | |
65 | 1229 Node *n = _nodes->adr_at(i)->_node; |
0 | 1230 if (n != NULL && n->is_Mem()) { |
1231 igvn->hash_delete(n); | |
1232 n->set_req(MemNode::Memory, nmem); | |
1233 igvn->hash_insert(n); | |
1234 record_for_optimizer(n); | |
1235 } | |
1236 } | |
1237 } | |
1238 } | |
1239 | |
1240 void ConnectionGraph::compute_escape() { | |
65 | 1241 |
163 | 1242 // 1. Populate Connection Graph (CG) with Ideal nodes. |
65 | 1243 |
1244 Unique_Node_List worklist_init; | |
1245 worklist_init.map(_compile->unique(), NULL); // preallocate space | |
1246 | |
1247 // Initialize worklist | |
1248 if (_compile->root() != NULL) { | |
1249 worklist_init.push(_compile->root()); | |
1250 } | |
1251 | |
1252 GrowableArray<int> cg_worklist; | |
1253 PhaseGVN* igvn = _compile->initial_gvn(); | |
1254 bool has_allocations = false; | |
1255 | |
1256 // Push all useful nodes onto CG list and set their type. | |
1257 for( uint next = 0; next < worklist_init.size(); ++next ) { | |
1258 Node* n = worklist_init.at(next); | |
1259 record_for_escape_analysis(n, igvn); | |
1260 if (n->is_Call() && | |
1261 _nodes->adr_at(n->_idx)->node_type() == PointsToNode::JavaObject) { | |
1262 has_allocations = true; | |
1263 } | |
1264 if(n->is_AddP()) | |
1265 cg_worklist.append(n->_idx); | |
1266 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) { | |
1267 Node* m = n->fast_out(i); // Get user | |
1268 worklist_init.push(m); | |
1269 } | |
1270 } | |
0 | 1271 |
65 | 1272 if (has_allocations) { |
1273 _has_allocations = true; | |
1274 } else { | |
1275 _has_allocations = false; | |
1276 _collecting = false; | |
1277 return; // Nothing to do. | |
1278 } | |
1279 | |
1280 // 2. First pass to create simple CG edges (doesn't require to walk CG). | |
1281 for( uint next = 0; next < _delayed_worklist.size(); ++next ) { | |
1282 Node* n = _delayed_worklist.at(next); | |
1283 build_connection_graph(n, igvn); | |
1284 } | |
0 | 1285 |
65 | 1286 // 3. Pass to create fields edges (Allocate -F-> AddP). |
1287 for( int next = 0; next < cg_worklist.length(); ++next ) { | |
1288 int ni = cg_worklist.at(next); | |
1289 build_connection_graph(_nodes->adr_at(ni)->_node, igvn); | |
1290 } | |
1291 | |
1292 cg_worklist.clear(); | |
1293 cg_worklist.append(_phantom_object); | |
1294 | |
1295 // 4. Build Connection Graph which need | |
1296 // to walk the connection graph. | |
1297 for (uint ni = 0; ni < (uint)_nodes->length(); ni++) { | |
1298 PointsToNode* ptn = _nodes->adr_at(ni); | |
1299 Node *n = ptn->_node; | |
1300 if (n != NULL) { // Call, AddP, LoadP, StoreP | |
1301 build_connection_graph(n, igvn); | |
1302 if (ptn->node_type() != PointsToNode::UnknownType) | |
1303 cg_worklist.append(n->_idx); // Collect CG nodes | |
1304 } | |
0 | 1305 } |
1306 | |
1307 VectorSet ptset(Thread::current()->resource_area()); | |
101
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
1308 GrowableArray<Node*> alloc_worklist; |
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
1309 GrowableArray<int> worklist; |
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
1310 GrowableArray<uint> deferred_edges; |
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
1311 VectorSet visited(Thread::current()->resource_area()); |
0 | 1312 |
1313 // remove deferred edges from the graph and collect | |
1314 // information we will need for type splitting | |
65 | 1315 for( int next = 0; next < cg_worklist.length(); ++next ) { |
1316 int ni = cg_worklist.at(next); | |
1317 PointsToNode* ptn = _nodes->adr_at(ni); | |
0 | 1318 PointsToNode::NodeType nt = ptn->node_type(); |
1319 Node *n = ptn->_node; | |
1320 if (nt == PointsToNode::LocalVar || nt == PointsToNode::Field) { | |
101
a6cb86dd209b
6681577: PIT: some VM tests fails with -XX:+AggressiveOpts in 6u5p b01
kvn
parents:
65
diff
changeset
|
1321 remove_deferred(ni, &deferred_edges, &visited); |
0 | 1322 if (n->is_AddP()) { |
65 | 1323 // If this AddP computes an address which may point to more that one |
163 | 1324 // object or more then one field (array's element), nothing the address |
1325 // points to can be scalar replaceable. | |
65 | 1326 Node *base = get_addp_base(n); |
0 | 1327 ptset.Clear(); |
1328 PointsTo(ptset, base, igvn); | |
163 | 1329 if (ptset.Size() > 1 || |
1330 (ptset.Size() != 0 && ptn->offset() == Type::OffsetBot)) { | |
0 | 1331 for( VectorSetI j(&ptset); j.test(); ++j ) { |
65 | 1332 uint pt = j.elem; |
1333 ptnode_adr(pt)->_scalar_replaceable = false; | |
0 | 1334 } |
1335 } | |
1336 } | |
65 | 1337 } else if (nt == PointsToNode::JavaObject && n->is_Call()) { |
1338 // Push call on alloc_worlist (alocations are calls) | |
1339 // for processing by split_unique_types(). | |
1340 alloc_worklist.append(n); | |
0 | 1341 } |
1342 } | |
65 | 1343 |
0 | 1344 // push all GlobalEscape nodes on the worklist |
65 | 1345 for( int next = 0; next < cg_worklist.length(); ++next ) { |
1346 int nk = cg_worklist.at(next); | |
1347 if (_nodes->adr_at(nk)->escape_state() == PointsToNode::GlobalEscape) | |
1348 worklist.append(nk); | |
0 | 1349 } |
1350 // mark all node reachable from GlobalEscape nodes | |
1351 while(worklist.length() > 0) { | |
1352 PointsToNode n = _nodes->at(worklist.pop()); | |
1353 for (uint ei = 0; ei < n.edge_count(); ei++) { | |
1354 uint npi = n.edge_target(ei); | |
1355 PointsToNode *np = ptnode_adr(npi); | |
65 | 1356 if (np->escape_state() < PointsToNode::GlobalEscape) { |
0 | 1357 np->set_escape_state(PointsToNode::GlobalEscape); |
1358 worklist.append_if_missing(npi); | |
1359 } | |
1360 } | |
1361 } | |
1362 | |
1363 // push all ArgEscape nodes on the worklist | |
65 | 1364 for( int next = 0; next < cg_worklist.length(); ++next ) { |
1365 int nk = cg_worklist.at(next); | |
1366 if (_nodes->adr_at(nk)->escape_state() == PointsToNode::ArgEscape) | |
0 | 1367 worklist.push(nk); |
1368 } | |
1369 // mark all node reachable from ArgEscape nodes | |
1370 while(worklist.length() > 0) { | |
1371 PointsToNode n = _nodes->at(worklist.pop()); | |
1372 for (uint ei = 0; ei < n.edge_count(); ei++) { | |
1373 uint npi = n.edge_target(ei); | |
1374 PointsToNode *np = ptnode_adr(npi); | |
65 | 1375 if (np->escape_state() < PointsToNode::ArgEscape) { |
0 | 1376 np->set_escape_state(PointsToNode::ArgEscape); |
1377 worklist.append_if_missing(npi); | |
1378 } | |
1379 } | |
1380 } | |
65 | 1381 |
1382 // push all NoEscape nodes on the worklist | |
1383 for( int next = 0; next < cg_worklist.length(); ++next ) { | |
1384 int nk = cg_worklist.at(next); | |
1385 if (_nodes->adr_at(nk)->escape_state() == PointsToNode::NoEscape) | |
1386 worklist.push(nk); | |
1387 } | |
1388 // mark all node reachable from NoEscape nodes | |
1389 while(worklist.length() > 0) { | |
1390 PointsToNode n = _nodes->at(worklist.pop()); | |
1391 for (uint ei = 0; ei < n.edge_count(); ei++) { | |
1392 uint npi = n.edge_target(ei); | |
1393 PointsToNode *np = ptnode_adr(npi); | |
1394 if (np->escape_state() < PointsToNode::NoEscape) { | |
1395 np->set_escape_state(PointsToNode::NoEscape); | |
1396 worklist.append_if_missing(npi); | |
1397 } | |
1398 } | |
1399 } | |
1400 | |
0 | 1401 _collecting = false; |
1402 | |
65 | 1403 has_allocations = false; // Are there scalar replaceable allocations? |
0 | 1404 |
65 | 1405 for( int next = 0; next < alloc_worklist.length(); ++next ) { |
1406 Node* n = alloc_worklist.at(next); | |
1407 uint ni = n->_idx; | |
1408 PointsToNode* ptn = _nodes->adr_at(ni); | |
1409 PointsToNode::EscapeState es = ptn->escape_state(); | |
1410 if (ptn->escape_state() == PointsToNode::NoEscape && | |
1411 ptn->_scalar_replaceable) { | |
1412 has_allocations = true; | |
1413 break; | |
1414 } | |
0 | 1415 } |
65 | 1416 if (!has_allocations) { |
1417 return; // Nothing to do. | |
1418 } | |
0 | 1419 |
65 | 1420 if(_compile->AliasLevel() >= 3 && EliminateAllocations) { |
1421 // Now use the escape information to create unique types for | |
1422 // unescaped objects | |
1423 split_unique_types(alloc_worklist); | |
1424 if (_compile->failing()) return; | |
0 | 1425 |
65 | 1426 // Clean up after split unique types. |
1427 ResourceMark rm; | |
1428 PhaseRemoveUseless pru(_compile->initial_gvn(), _compile->for_igvn()); | |
0 | 1429 |
65 | 1430 #ifdef ASSERT |
1431 } else if (PrintEscapeAnalysis || PrintEliminateAllocations) { | |
1432 tty->print("=== No allocations eliminated for "); | |
1433 C()->method()->print_short_name(); | |
1434 if(!EliminateAllocations) { | |
1435 tty->print(" since EliminateAllocations is off ==="); | |
1436 } else if(_compile->AliasLevel() < 3) { | |
1437 tty->print(" since AliasLevel < 3 ==="); | |
0 | 1438 } |
65 | 1439 tty->cr(); |
1440 #endif | |
0 | 1441 } |
1442 } | |
1443 | |
1444 void ConnectionGraph::process_call_arguments(CallNode *call, PhaseTransform *phase) { | |
1445 | |
1446 switch (call->Opcode()) { | |
65 | 1447 #ifdef ASSERT |
0 | 1448 case Op_Allocate: |
1449 case Op_AllocateArray: | |
1450 case Op_Lock: | |
1451 case Op_Unlock: | |
65 | 1452 assert(false, "should be done already"); |
0 | 1453 break; |
65 | 1454 #endif |
1455 case Op_CallLeafNoFP: | |
1456 { | |
1457 // Stub calls, objects do not escape but they are not scale replaceable. | |
1458 // Adjust escape state for outgoing arguments. | |
1459 const TypeTuple * d = call->tf()->domain(); | |
1460 VectorSet ptset(Thread::current()->resource_area()); | |
1461 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) { | |
1462 const Type* at = d->field_at(i); | |
1463 Node *arg = call->in(i)->uncast(); | |
1464 const Type *aat = phase->type(arg); | |
1465 if (!arg->is_top() && at->isa_ptr() && aat->isa_ptr()) { | |
1466 assert(aat == Type::TOP || aat == TypePtr::NULL_PTR || | |
1467 aat->isa_ptr() != NULL, "expecting an Ptr"); | |
1468 set_escape_state(arg->_idx, PointsToNode::ArgEscape); | |
1469 if (arg->is_AddP()) { | |
1470 // | |
1471 // The inline_native_clone() case when the arraycopy stub is called | |
1472 // after the allocation before Initialize and CheckCastPP nodes. | |
1473 // | |
1474 // Set AddP's base (Allocate) as not scalar replaceable since | |
1475 // pointer to the base (with offset) is passed as argument. | |
1476 // | |
1477 arg = get_addp_base(arg); | |
1478 } | |
1479 ptset.Clear(); | |
1480 PointsTo(ptset, arg, phase); | |
1481 for( VectorSetI j(&ptset); j.test(); ++j ) { | |
1482 uint pt = j.elem; | |
1483 set_escape_state(pt, PointsToNode::ArgEscape); | |
1484 } | |
1485 } | |
1486 } | |
1487 break; | |
1488 } | |
0 | 1489 |
1490 case Op_CallStaticJava: | |
1491 // For a static call, we know exactly what method is being called. | |
1492 // Use bytecode estimator to record the call's escape affects | |
1493 { | |
1494 ciMethod *meth = call->as_CallJava()->method(); | |
65 | 1495 BCEscapeAnalyzer *call_analyzer = (meth !=NULL) ? meth->get_bcea() : NULL; |
1496 // fall-through if not a Java method or no analyzer information | |
1497 if (call_analyzer != NULL) { | |
0 | 1498 const TypeTuple * d = call->tf()->domain(); |
1499 VectorSet ptset(Thread::current()->resource_area()); | |
65 | 1500 bool copy_dependencies = false; |
0 | 1501 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) { |
1502 const Type* at = d->field_at(i); | |
1503 int k = i - TypeFunc::Parms; | |
1504 | |
1505 if (at->isa_oopptr() != NULL) { | |
65 | 1506 Node *arg = call->in(i)->uncast(); |
0 | 1507 |
65 | 1508 bool global_escapes = false; |
1509 bool fields_escapes = false; | |
1510 if (!call_analyzer->is_arg_stack(k)) { | |
1511 // The argument global escapes, mark everything it could point to | |
1512 set_escape_state(arg->_idx, PointsToNode::GlobalEscape); | |
1513 global_escapes = true; | |
1514 } else { | |
1515 if (!call_analyzer->is_arg_local(k)) { | |
1516 // The argument itself doesn't escape, but any fields might | |
1517 fields_escapes = true; | |
0 | 1518 } |
65 | 1519 set_escape_state(arg->_idx, PointsToNode::ArgEscape); |
1520 copy_dependencies = true; | |
1521 } | |
1522 | |
1523 ptset.Clear(); | |
1524 PointsTo(ptset, arg, phase); | |
1525 for( VectorSetI j(&ptset); j.test(); ++j ) { | |
1526 uint pt = j.elem; | |
1527 if (global_escapes) { | |
1528 //The argument global escapes, mark everything it could point to | |
1529 set_escape_state(pt, PointsToNode::GlobalEscape); | |
1530 } else { | |
1531 if (fields_escapes) { | |
1532 // The argument itself doesn't escape, but any fields might | |
1533 add_edge_from_fields(pt, _phantom_object, Type::OffsetBot); | |
1534 } | |
1535 set_escape_state(pt, PointsToNode::ArgEscape); | |
0 | 1536 } |
1537 } | |
1538 } | |
1539 } | |
65 | 1540 if (copy_dependencies) |
1541 call_analyzer->copy_dependencies(C()->dependencies()); | |
0 | 1542 break; |
1543 } | |
1544 } | |
1545 | |
1546 default: | |
65 | 1547 // Fall-through here if not a Java method or no analyzer information |
1548 // or some other type of call, assume the worst case: all arguments | |
0 | 1549 // globally escape. |
1550 { | |
1551 // adjust escape state for outgoing arguments | |
1552 const TypeTuple * d = call->tf()->domain(); | |
1553 VectorSet ptset(Thread::current()->resource_area()); | |
1554 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) { | |
1555 const Type* at = d->field_at(i); | |
1556 if (at->isa_oopptr() != NULL) { | |
65 | 1557 Node *arg = call->in(i)->uncast(); |
1558 set_escape_state(arg->_idx, PointsToNode::GlobalEscape); | |
0 | 1559 ptset.Clear(); |
1560 PointsTo(ptset, arg, phase); | |
1561 for( VectorSetI j(&ptset); j.test(); ++j ) { | |
1562 uint pt = j.elem; | |
1563 set_escape_state(pt, PointsToNode::GlobalEscape); | |
65 | 1564 PointsToNode *ptadr = ptnode_adr(pt); |
0 | 1565 } |
1566 } | |
1567 } | |
1568 } | |
1569 } | |
1570 } | |
1571 void ConnectionGraph::process_call_result(ProjNode *resproj, PhaseTransform *phase) { | |
1572 PointsToNode *ptadr = ptnode_adr(resproj->_idx); | |
1573 | |
65 | 1574 CallNode *call = resproj->in(0)->as_Call(); |
0 | 1575 switch (call->Opcode()) { |
1576 case Op_Allocate: | |
1577 { | |
1578 Node *k = call->in(AllocateNode::KlassNode); | |
1579 const TypeKlassPtr *kt; | |
1580 if (k->Opcode() == Op_LoadKlass) { | |
1581 kt = k->as_Load()->type()->isa_klassptr(); | |
1582 } else { | |
164
c436414a719e
6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents:
163
diff
changeset
|
1583 // Also works for DecodeN(LoadNKlass). |
0 | 1584 kt = k->as_Type()->type()->isa_klassptr(); |
1585 } | |
1586 assert(kt != NULL, "TypeKlassPtr required."); | |
1587 ciKlass* cik = kt->klass(); | |
1588 ciInstanceKlass* ciik = cik->as_instance_klass(); | |
1589 | |
1590 PointsToNode *ptadr = ptnode_adr(call->_idx); | |
65 | 1591 PointsToNode::EscapeState es; |
1592 uint edge_to; | |
0 | 1593 if (cik->is_subclass_of(_compile->env()->Thread_klass()) || ciik->has_finalizer()) { |
65 | 1594 es = PointsToNode::GlobalEscape; |
1595 edge_to = _phantom_object; // Could not be worse | |
0 | 1596 } else { |
65 | 1597 es = PointsToNode::NoEscape; |
1598 edge_to = call->_idx; | |
0 | 1599 } |
65 | 1600 set_escape_state(call->_idx, es); |
1601 add_pointsto_edge(resproj->_idx, edge_to); | |
1602 _processed.set(resproj->_idx); | |
0 | 1603 break; |
1604 } | |
1605 | |
1606 case Op_AllocateArray: | |
1607 { | |
1608 PointsToNode *ptadr = ptnode_adr(call->_idx); | |
65 | 1609 int length = call->in(AllocateNode::ALength)->find_int_con(-1); |
1610 if (length < 0 || length > EliminateAllocationArraySizeLimit) { | |
1611 // Not scalar replaceable if the length is not constant or too big. | |
1612 ptadr->_scalar_replaceable = false; | |
1613 } | |
0 | 1614 set_escape_state(call->_idx, PointsToNode::NoEscape); |
1615 add_pointsto_edge(resproj->_idx, call->_idx); | |
65 | 1616 _processed.set(resproj->_idx); |
0 | 1617 break; |
1618 } | |
1619 | |
1620 case Op_CallStaticJava: | |
1621 // For a static call, we know exactly what method is being called. | |
1622 // Use bytecode estimator to record whether the call's return value escapes | |
1623 { | |
65 | 1624 bool done = true; |
0 | 1625 const TypeTuple *r = call->tf()->range(); |
1626 const Type* ret_type = NULL; | |
1627 | |
1628 if (r->cnt() > TypeFunc::Parms) | |
1629 ret_type = r->field_at(TypeFunc::Parms); | |
1630 | |
1631 // Note: we use isa_ptr() instead of isa_oopptr() here because the | |
1632 // _multianewarray functions return a TypeRawPtr. | |
65 | 1633 if (ret_type == NULL || ret_type->isa_ptr() == NULL) { |
1634 _processed.set(resproj->_idx); | |
0 | 1635 break; // doesn't return a pointer type |
65 | 1636 } |
0 | 1637 ciMethod *meth = call->as_CallJava()->method(); |
65 | 1638 const TypeTuple * d = call->tf()->domain(); |
0 | 1639 if (meth == NULL) { |
1640 // not a Java method, assume global escape | |
1641 set_escape_state(call->_idx, PointsToNode::GlobalEscape); | |
1642 if (resproj != NULL) | |
1643 add_pointsto_edge(resproj->_idx, _phantom_object); | |
1644 } else { | |
65 | 1645 BCEscapeAnalyzer *call_analyzer = meth->get_bcea(); |
0 | 1646 VectorSet ptset(Thread::current()->resource_area()); |
65 | 1647 bool copy_dependencies = false; |
0 | 1648 |
65 | 1649 if (call_analyzer->is_return_allocated()) { |
1650 // Returns a newly allocated unescaped object, simply | |
1651 // update dependency information. | |
1652 // Mark it as NoEscape so that objects referenced by | |
1653 // it's fields will be marked as NoEscape at least. | |
1654 set_escape_state(call->_idx, PointsToNode::NoEscape); | |
1655 if (resproj != NULL) | |
1656 add_pointsto_edge(resproj->_idx, call->_idx); | |
1657 copy_dependencies = true; | |
1658 } else if (call_analyzer->is_return_local() && resproj != NULL) { | |
0 | 1659 // determine whether any arguments are returned |
1660 set_escape_state(call->_idx, PointsToNode::NoEscape); | |
1661 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) { | |
1662 const Type* at = d->field_at(i); | |
1663 | |
1664 if (at->isa_oopptr() != NULL) { | |
65 | 1665 Node *arg = call->in(i)->uncast(); |
0 | 1666 |
65 | 1667 if (call_analyzer->is_arg_returned(i - TypeFunc::Parms)) { |
0 | 1668 PointsToNode *arg_esp = _nodes->adr_at(arg->_idx); |
65 | 1669 if (arg_esp->node_type() == PointsToNode::UnknownType) |
1670 done = false; | |
1671 else if (arg_esp->node_type() == PointsToNode::JavaObject) | |
0 | 1672 add_pointsto_edge(resproj->_idx, arg->_idx); |
1673 else | |
1674 add_deferred_edge(resproj->_idx, arg->_idx); | |
1675 arg_esp->_hidden_alias = true; | |
1676 } | |
1677 } | |
1678 } | |
65 | 1679 copy_dependencies = true; |
0 | 1680 } else { |
1681 set_escape_state(call->_idx, PointsToNode::GlobalEscape); | |
1682 if (resproj != NULL) | |
1683 add_pointsto_edge(resproj->_idx, _phantom_object); | |
65 | 1684 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) { |
1685 const Type* at = d->field_at(i); | |
1686 if (at->isa_oopptr() != NULL) { | |
1687 Node *arg = call->in(i)->uncast(); | |
1688 PointsToNode *arg_esp = _nodes->adr_at(arg->_idx); | |
1689 arg_esp->_hidden_alias = true; | |
1690 } | |
1691 } | |
0 | 1692 } |
65 | 1693 if (copy_dependencies) |
1694 call_analyzer->copy_dependencies(C()->dependencies()); | |
0 | 1695 } |
65 | 1696 if (done) |
1697 _processed.set(resproj->_idx); | |
0 | 1698 break; |
1699 } | |
1700 | |
1701 default: | |
1702 // Some other type of call, assume the worst case that the | |
1703 // returned value, if any, globally escapes. | |
1704 { | |
1705 const TypeTuple *r = call->tf()->range(); | |
1706 if (r->cnt() > TypeFunc::Parms) { | |
1707 const Type* ret_type = r->field_at(TypeFunc::Parms); | |
1708 | |
1709 // Note: we use isa_ptr() instead of isa_oopptr() here because the | |
1710 // _multianewarray functions return a TypeRawPtr. | |
1711 if (ret_type->isa_ptr() != NULL) { | |
1712 PointsToNode *ptadr = ptnode_adr(call->_idx); | |
1713 set_escape_state(call->_idx, PointsToNode::GlobalEscape); | |
1714 if (resproj != NULL) | |
1715 add_pointsto_edge(resproj->_idx, _phantom_object); | |
1716 } | |
1717 } | |
65 | 1718 _processed.set(resproj->_idx); |
0 | 1719 } |
1720 } | |
1721 } | |
1722 | |
65 | 1723 // Populate Connection Graph with Ideal nodes and create simple |
1724 // connection graph edges (do not need to check the node_type of inputs | |
1725 // or to call PointsTo() to walk the connection graph). | |
1726 void ConnectionGraph::record_for_escape_analysis(Node *n, PhaseTransform *phase) { | |
1727 if (_processed.test(n->_idx)) | |
1728 return; // No need to redefine node's state. | |
1729 | |
1730 if (n->is_Call()) { | |
1731 // Arguments to allocation and locking don't escape. | |
1732 if (n->is_Allocate()) { | |
1733 add_node(n, PointsToNode::JavaObject, PointsToNode::UnknownEscape, true); | |
1734 record_for_optimizer(n); | |
1735 } else if (n->is_Lock() || n->is_Unlock()) { | |
1736 // Put Lock and Unlock nodes on IGVN worklist to process them during | |
1737 // the first IGVN optimization when escape information is still available. | |
1738 record_for_optimizer(n); | |
1739 _processed.set(n->_idx); | |
1740 } else { | |
1741 // Have to process call's arguments first. | |
1742 PointsToNode::NodeType nt = PointsToNode::UnknownType; | |
1743 | |
1744 // Check if a call returns an object. | |
1745 const TypeTuple *r = n->as_Call()->tf()->range(); | |
1746 if (r->cnt() > TypeFunc::Parms && | |
1747 n->as_Call()->proj_out(TypeFunc::Parms) != NULL) { | |
1748 // Note: use isa_ptr() instead of isa_oopptr() here because | |
1749 // the _multianewarray functions return a TypeRawPtr. | |
1750 if (r->field_at(TypeFunc::Parms)->isa_ptr() != NULL) { | |
1751 nt = PointsToNode::JavaObject; | |
1752 } | |
1753 } | |
1754 add_node(n, nt, PointsToNode::UnknownEscape, false); | |
1755 } | |
1756 return; | |
1757 } | |
1758 | |
1759 // Using isa_ptr() instead of isa_oopptr() for LoadP and Phi because | |
1760 // ThreadLocal has RawPrt type. | |
1761 switch (n->Opcode()) { | |
1762 case Op_AddP: | |
1763 { | |
1764 add_node(n, PointsToNode::Field, PointsToNode::UnknownEscape, false); | |
1765 break; | |
1766 } | |
1767 case Op_CastX2P: | |
1768 { // "Unsafe" memory access. | |
1769 add_node(n, PointsToNode::JavaObject, PointsToNode::GlobalEscape, true); | |
1770 break; | |
1771 } | |
1772 case Op_CastPP: | |
1773 case Op_CheckCastPP: | |
124
b130b98db9cf
6689060: Escape Analysis does not work with Compressed Oops
kvn
parents:
113
diff
changeset
|
1774 case Op_EncodeP: |
b130b98db9cf
6689060: Escape Analysis does not work with Compressed Oops
kvn
parents:
113
diff
changeset
|
1775 case Op_DecodeN: |
65 | 1776 { |
1777 add_node(n, PointsToNode::LocalVar, PointsToNode::UnknownEscape, false); | |
1778 int ti = n->in(1)->_idx; | |
1779 PointsToNode::NodeType nt = _nodes->adr_at(ti)->node_type(); | |
1780 if (nt == PointsToNode::UnknownType) { | |
1781 _delayed_worklist.push(n); // Process it later. | |
1782 break; | |
1783 } else if (nt == PointsToNode::JavaObject) { | |
1784 add_pointsto_edge(n->_idx, ti); | |
1785 } else { | |
1786 add_deferred_edge(n->_idx, ti); | |
1787 } | |
1788 _processed.set(n->_idx); | |
1789 break; | |
1790 } | |
1791 case Op_ConP: | |
1792 { | |
1793 // assume all pointer constants globally escape except for null | |
1794 PointsToNode::EscapeState es; | |
1795 if (phase->type(n) == TypePtr::NULL_PTR) | |
1796 es = PointsToNode::NoEscape; | |
1797 else | |
1798 es = PointsToNode::GlobalEscape; | |
0 | 1799 |
65 | 1800 add_node(n, PointsToNode::JavaObject, es, true); |
1801 break; | |
1802 } | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
102
diff
changeset
|
1803 case Op_ConN: |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
102
diff
changeset
|
1804 { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
102
diff
changeset
|
1805 // assume all narrow oop constants globally escape except for null |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
102
diff
changeset
|
1806 PointsToNode::EscapeState es; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
102
diff
changeset
|
1807 if (phase->type(n) == TypeNarrowOop::NULL_PTR) |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
102
diff
changeset
|
1808 es = PointsToNode::NoEscape; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
102
diff
changeset
|
1809 else |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
102
diff
changeset
|
1810 es = PointsToNode::GlobalEscape; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
102
diff
changeset
|
1811 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
102
diff
changeset
|
1812 add_node(n, PointsToNode::JavaObject, es, true); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
102
diff
changeset
|
1813 break; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
102
diff
changeset
|
1814 } |
124
b130b98db9cf
6689060: Escape Analysis does not work with Compressed Oops
kvn
parents:
113
diff
changeset
|
1815 case Op_CreateEx: |
b130b98db9cf
6689060: Escape Analysis does not work with Compressed Oops
kvn
parents:
113
diff
changeset
|
1816 { |
b130b98db9cf
6689060: Escape Analysis does not work with Compressed Oops
kvn
parents:
113
diff
changeset
|
1817 // assume that all exception objects globally escape |
b130b98db9cf
6689060: Escape Analysis does not work with Compressed Oops
kvn
parents:
113
diff
changeset
|
1818 add_node(n, PointsToNode::JavaObject, PointsToNode::GlobalEscape, true); |
b130b98db9cf
6689060: Escape Analysis does not work with Compressed Oops
kvn
parents:
113
diff
changeset
|
1819 break; |
b130b98db9cf
6689060: Escape Analysis does not work with Compressed Oops
kvn
parents:
113
diff
changeset
|
1820 } |
65 | 1821 case Op_LoadKlass: |
164
c436414a719e
6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents:
163
diff
changeset
|
1822 case Op_LoadNKlass: |
65 | 1823 { |
1824 add_node(n, PointsToNode::JavaObject, PointsToNode::GlobalEscape, true); | |
1825 break; | |
1826 } | |
1827 case Op_LoadP: | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
102
diff
changeset
|
1828 case Op_LoadN: |
65 | 1829 { |
1830 const Type *t = phase->type(n); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
102
diff
changeset
|
1831 if (!t->isa_narrowoop() && t->isa_ptr() == NULL) { |
65 | 1832 _processed.set(n->_idx); |
1833 return; | |
1834 } | |
1835 add_node(n, PointsToNode::LocalVar, PointsToNode::UnknownEscape, false); | |
1836 break; | |
1837 } | |
1838 case Op_Parm: | |
1839 { | |
1840 _processed.set(n->_idx); // No need to redefine it state. | |
1841 uint con = n->as_Proj()->_con; | |
1842 if (con < TypeFunc::Parms) | |
1843 return; | |
1844 const Type *t = n->in(0)->as_Start()->_domain->field_at(con); | |
1845 if (t->isa_ptr() == NULL) | |
1846 return; | |
1847 // We have to assume all input parameters globally escape | |
1848 // (Note: passing 'false' since _processed is already set). | |
1849 add_node(n, PointsToNode::JavaObject, PointsToNode::GlobalEscape, false); | |
1850 break; | |
1851 } | |
1852 case Op_Phi: | |
1853 { | |
1854 if (n->as_Phi()->type()->isa_ptr() == NULL) { | |
1855 // nothing to do if not an oop | |
1856 _processed.set(n->_idx); | |
1857 return; | |
1858 } | |
1859 add_node(n, PointsToNode::LocalVar, PointsToNode::UnknownEscape, false); | |
1860 uint i; | |
1861 for (i = 1; i < n->req() ; i++) { | |
1862 Node* in = n->in(i); | |
1863 if (in == NULL) | |
1864 continue; // ignore NULL | |
1865 in = in->uncast(); | |
1866 if (in->is_top() || in == n) | |
1867 continue; // ignore top or inputs which go back this node | |
1868 int ti = in->_idx; | |
1869 PointsToNode::NodeType nt = _nodes->adr_at(ti)->node_type(); | |
1870 if (nt == PointsToNode::UnknownType) { | |
1871 break; | |
1872 } else if (nt == PointsToNode::JavaObject) { | |
1873 add_pointsto_edge(n->_idx, ti); | |
1874 } else { | |
1875 add_deferred_edge(n->_idx, ti); | |
1876 } | |
1877 } | |
1878 if (i >= n->req()) | |
1879 _processed.set(n->_idx); | |
1880 else | |
1881 _delayed_worklist.push(n); | |
1882 break; | |
1883 } | |
1884 case Op_Proj: | |
1885 { | |
1886 // we are only interested in the result projection from a call | |
1887 if (n->as_Proj()->_con == TypeFunc::Parms && n->in(0)->is_Call() ) { | |
1888 add_node(n, PointsToNode::LocalVar, PointsToNode::UnknownEscape, false); | |
1889 process_call_result(n->as_Proj(), phase); | |
1890 if (!_processed.test(n->_idx)) { | |
1891 // The call's result may need to be processed later if the call | |
1892 // returns it's argument and the argument is not processed yet. | |
1893 _delayed_worklist.push(n); | |
1894 } | |
1895 } else { | |
1896 _processed.set(n->_idx); | |
1897 } | |
1898 break; | |
1899 } | |
1900 case Op_Return: | |
1901 { | |
1902 if( n->req() > TypeFunc::Parms && | |
1903 phase->type(n->in(TypeFunc::Parms))->isa_oopptr() ) { | |
1904 // Treat Return value as LocalVar with GlobalEscape escape state. | |
1905 add_node(n, PointsToNode::LocalVar, PointsToNode::GlobalEscape, false); | |
1906 int ti = n->in(TypeFunc::Parms)->_idx; | |
1907 PointsToNode::NodeType nt = _nodes->adr_at(ti)->node_type(); | |
1908 if (nt == PointsToNode::UnknownType) { | |
1909 _delayed_worklist.push(n); // Process it later. | |
1910 break; | |
1911 } else if (nt == PointsToNode::JavaObject) { | |
1912 add_pointsto_edge(n->_idx, ti); | |
1913 } else { | |
1914 add_deferred_edge(n->_idx, ti); | |
1915 } | |
1916 } | |
1917 _processed.set(n->_idx); | |
1918 break; | |
1919 } | |
1920 case Op_StoreP: | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
102
diff
changeset
|
1921 case Op_StoreN: |
65 | 1922 { |
1923 const Type *adr_type = phase->type(n->in(MemNode::Address)); | |
221
1e026f8da827
6710487: More than half of JDI Regression tests hang with COOPs in -Xcomp mode
kvn
parents:
168
diff
changeset
|
1924 adr_type = adr_type->make_ptr(); |
65 | 1925 if (adr_type->isa_oopptr()) { |
1926 add_node(n, PointsToNode::UnknownType, PointsToNode::UnknownEscape, false); | |
1927 } else { | |
1928 Node* adr = n->in(MemNode::Address); | |
1929 if (adr->is_AddP() && phase->type(adr) == TypeRawPtr::NOTNULL && | |
1930 adr->in(AddPNode::Address)->is_Proj() && | |
1931 adr->in(AddPNode::Address)->in(0)->is_Allocate()) { | |
1932 add_node(n, PointsToNode::UnknownType, PointsToNode::UnknownEscape, false); | |
1933 // We are computing a raw address for a store captured | |
1934 // by an Initialize compute an appropriate address type. | |
1935 int offs = (int)phase->find_intptr_t_con(adr->in(AddPNode::Offset), Type::OffsetBot); | |
1936 assert(offs != Type::OffsetBot, "offset must be a constant"); | |
1937 } else { | |
1938 _processed.set(n->_idx); | |
1939 return; | |
1940 } | |
1941 } | |
1942 break; | |
1943 } | |
1944 case Op_StorePConditional: | |
1945 case Op_CompareAndSwapP: | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
102
diff
changeset
|
1946 case Op_CompareAndSwapN: |
65 | 1947 { |
1948 const Type *adr_type = phase->type(n->in(MemNode::Address)); | |
221
1e026f8da827
6710487: More than half of JDI Regression tests hang with COOPs in -Xcomp mode
kvn
parents:
168
diff
changeset
|
1949 adr_type = adr_type->make_ptr(); |
65 | 1950 if (adr_type->isa_oopptr()) { |
1951 add_node(n, PointsToNode::UnknownType, PointsToNode::UnknownEscape, false); | |
1952 } else { | |
1953 _processed.set(n->_idx); | |
1954 return; | |
1955 } | |
1956 break; | |
1957 } | |
1958 case Op_ThreadLocal: | |
1959 { | |
1960 add_node(n, PointsToNode::JavaObject, PointsToNode::ArgEscape, true); | |
1961 break; | |
1962 } | |
1963 default: | |
1964 ; | |
1965 // nothing to do | |
1966 } | |
1967 return; | |
1968 } | |
1969 | |
1970 void ConnectionGraph::build_connection_graph(Node *n, PhaseTransform *phase) { | |
1971 // Don't set processed bit for AddP, LoadP, StoreP since | |
1972 // they may need more then one pass to process. | |
1973 if (_processed.test(n->_idx)) | |
1974 return; // No need to redefine node's state. | |
1975 | |
0 | 1976 PointsToNode *ptadr = ptnode_adr(n->_idx); |
1977 | |
1978 if (n->is_Call()) { | |
1979 CallNode *call = n->as_Call(); | |
1980 process_call_arguments(call, phase); | |
65 | 1981 _processed.set(n->_idx); |
0 | 1982 return; |
1983 } | |
1984 | |
65 | 1985 switch (n->Opcode()) { |
0 | 1986 case Op_AddP: |
1987 { | |
65 | 1988 Node *base = get_addp_base(n); |
1989 // Create a field edge to this node from everything base could point to. | |
0 | 1990 VectorSet ptset(Thread::current()->resource_area()); |
1991 PointsTo(ptset, base, phase); | |
1992 for( VectorSetI i(&ptset); i.test(); ++i ) { | |
1993 uint pt = i.elem; | |
65 | 1994 add_field_edge(pt, n->_idx, address_offset(n, phase)); |
1995 } | |
1996 break; | |
1997 } | |
1998 case Op_CastX2P: | |
1999 { | |
2000 assert(false, "Op_CastX2P"); | |
2001 break; | |
2002 } | |
2003 case Op_CastPP: | |
2004 case Op_CheckCastPP: | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
102
diff
changeset
|
2005 case Op_EncodeP: |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
102
diff
changeset
|
2006 case Op_DecodeN: |
65 | 2007 { |
2008 int ti = n->in(1)->_idx; | |
2009 if (_nodes->adr_at(ti)->node_type() == PointsToNode::JavaObject) { | |
2010 add_pointsto_edge(n->_idx, ti); | |
2011 } else { | |
2012 add_deferred_edge(n->_idx, ti); | |
2013 } | |
2014 _processed.set(n->_idx); | |
2015 break; | |
2016 } | |
2017 case Op_ConP: | |
2018 { | |
2019 assert(false, "Op_ConP"); | |
2020 break; | |
2021 } | |
163 | 2022 case Op_ConN: |
2023 { | |
2024 assert(false, "Op_ConN"); | |
2025 break; | |
2026 } | |
65 | 2027 case Op_CreateEx: |
2028 { | |
2029 assert(false, "Op_CreateEx"); | |
2030 break; | |
2031 } | |
2032 case Op_LoadKlass: | |
164
c436414a719e
6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents:
163
diff
changeset
|
2033 case Op_LoadNKlass: |
65 | 2034 { |
2035 assert(false, "Op_LoadKlass"); | |
2036 break; | |
2037 } | |
2038 case Op_LoadP: | |
124
b130b98db9cf
6689060: Escape Analysis does not work with Compressed Oops
kvn
parents:
113
diff
changeset
|
2039 case Op_LoadN: |
65 | 2040 { |
2041 const Type *t = phase->type(n); | |
2042 #ifdef ASSERT | |
124
b130b98db9cf
6689060: Escape Analysis does not work with Compressed Oops
kvn
parents:
113
diff
changeset
|
2043 if (!t->isa_narrowoop() && t->isa_ptr() == NULL) |
65 | 2044 assert(false, "Op_LoadP"); |
2045 #endif | |
2046 | |
2047 Node* adr = n->in(MemNode::Address)->uncast(); | |
2048 const Type *adr_type = phase->type(adr); | |
2049 Node* adr_base; | |
2050 if (adr->is_AddP()) { | |
2051 adr_base = get_addp_base(adr); | |
2052 } else { | |
2053 adr_base = adr; | |
2054 } | |
2055 | |
2056 // For everything "adr_base" could point to, create a deferred edge from | |
2057 // this node to each field with the same offset. | |
2058 VectorSet ptset(Thread::current()->resource_area()); | |
2059 PointsTo(ptset, adr_base, phase); | |
2060 int offset = address_offset(adr, phase); | |
2061 for( VectorSetI i(&ptset); i.test(); ++i ) { | |
2062 uint pt = i.elem; | |
2063 add_deferred_edge_to_fields(n->_idx, pt, offset); | |
0 | 2064 } |
2065 break; | |
2066 } | |
2067 case Op_Parm: | |
2068 { | |
65 | 2069 assert(false, "Op_Parm"); |
0 | 2070 break; |
2071 } | |
2072 case Op_Phi: | |
2073 { | |
65 | 2074 #ifdef ASSERT |
2075 if (n->as_Phi()->type()->isa_ptr() == NULL) | |
2076 assert(false, "Op_Phi"); | |
2077 #endif | |
2078 for (uint i = 1; i < n->req() ; i++) { | |
2079 Node* in = n->in(i); | |
2080 if (in == NULL) | |
2081 continue; // ignore NULL | |
2082 in = in->uncast(); | |
2083 if (in->is_top() || in == n) | |
2084 continue; // ignore top or inputs which go back this node | |
2085 int ti = in->_idx; | |
2086 if (_nodes->adr_at(in->_idx)->node_type() == PointsToNode::JavaObject) { | |
2087 add_pointsto_edge(n->_idx, ti); | |
2088 } else { | |
2089 add_deferred_edge(n->_idx, ti); | |
2090 } | |
2091 } | |
0 | 2092 _processed.set(n->_idx); |
2093 break; | |
2094 } | |
65 | 2095 case Op_Proj: |
0 | 2096 { |
65 | 2097 // we are only interested in the result projection from a call |
2098 if (n->as_Proj()->_con == TypeFunc::Parms && n->in(0)->is_Call() ) { | |
2099 process_call_result(n->as_Proj(), phase); | |
2100 assert(_processed.test(n->_idx), "all call results should be processed"); | |
2101 } else { | |
2102 assert(false, "Op_Proj"); | |
2103 } | |
0 | 2104 break; |
2105 } | |
65 | 2106 case Op_Return: |
0 | 2107 { |
65 | 2108 #ifdef ASSERT |
2109 if( n->req() <= TypeFunc::Parms || | |
2110 !phase->type(n->in(TypeFunc::Parms))->isa_oopptr() ) { | |
2111 assert(false, "Op_Return"); | |
0 | 2112 } |
65 | 2113 #endif |
2114 int ti = n->in(TypeFunc::Parms)->_idx; | |
2115 if (_nodes->adr_at(ti)->node_type() == PointsToNode::JavaObject) { | |
2116 add_pointsto_edge(n->_idx, ti); | |
2117 } else { | |
2118 add_deferred_edge(n->_idx, ti); | |
2119 } | |
2120 _processed.set(n->_idx); | |
0 | 2121 break; |
2122 } | |
2123 case Op_StoreP: | |
124
b130b98db9cf
6689060: Escape Analysis does not work with Compressed Oops
kvn
parents:
113
diff
changeset
|
2124 case Op_StoreN: |
0 | 2125 case Op_StorePConditional: |
2126 case Op_CompareAndSwapP: | |
124
b130b98db9cf
6689060: Escape Analysis does not work with Compressed Oops
kvn
parents:
113
diff
changeset
|
2127 case Op_CompareAndSwapN: |
0 | 2128 { |
2129 Node *adr = n->in(MemNode::Address); | |
221
1e026f8da827
6710487: More than half of JDI Regression tests hang with COOPs in -Xcomp mode
kvn
parents:
168
diff
changeset
|
2130 const Type *adr_type = phase->type(adr)->make_ptr(); |
65 | 2131 #ifdef ASSERT |
0 | 2132 if (!adr_type->isa_oopptr()) |
65 | 2133 assert(phase->type(adr) == TypeRawPtr::NOTNULL, "Op_StoreP"); |
2134 #endif | |
0 | 2135 |
65 | 2136 assert(adr->is_AddP(), "expecting an AddP"); |
2137 Node *adr_base = get_addp_base(adr); | |
2138 Node *val = n->in(MemNode::ValueIn)->uncast(); | |
2139 // For everything "adr_base" could point to, create a deferred edge | |
2140 // to "val" from each field with the same offset. | |
0 | 2141 VectorSet ptset(Thread::current()->resource_area()); |
2142 PointsTo(ptset, adr_base, phase); | |
2143 for( VectorSetI i(&ptset); i.test(); ++i ) { | |
2144 uint pt = i.elem; | |
65 | 2145 add_edge_from_fields(pt, val->_idx, address_offset(adr, phase)); |
0 | 2146 } |
2147 break; | |
2148 } | |
65 | 2149 case Op_ThreadLocal: |
0 | 2150 { |
65 | 2151 assert(false, "Op_ThreadLocal"); |
0 | 2152 break; |
2153 } | |
2154 default: | |
2155 ; | |
2156 // nothing to do | |
2157 } | |
2158 } | |
2159 | |
2160 #ifndef PRODUCT | |
2161 void ConnectionGraph::dump() { | |
2162 PhaseGVN *igvn = _compile->initial_gvn(); | |
2163 bool first = true; | |
2164 | |
65 | 2165 uint size = (uint)_nodes->length(); |
2166 for (uint ni = 0; ni < size; ni++) { | |
2167 PointsToNode *ptn = _nodes->adr_at(ni); | |
2168 PointsToNode::NodeType ptn_type = ptn->node_type(); | |
2169 | |
2170 if (ptn_type != PointsToNode::JavaObject || ptn->_node == NULL) | |
0 | 2171 continue; |
65 | 2172 PointsToNode::EscapeState es = escape_state(ptn->_node, igvn); |
2173 if (ptn->_node->is_Allocate() && (es == PointsToNode::NoEscape || Verbose)) { | |
2174 if (first) { | |
2175 tty->cr(); | |
2176 tty->print("======== Connection graph for "); | |
2177 C()->method()->print_short_name(); | |
2178 tty->cr(); | |
2179 first = false; | |
2180 } | |
2181 tty->print("%6d ", ni); | |
2182 ptn->dump(); | |
2183 // Print all locals which reference this allocation | |
2184 for (uint li = ni; li < size; li++) { | |
2185 PointsToNode *ptn_loc = _nodes->adr_at(li); | |
2186 PointsToNode::NodeType ptn_loc_type = ptn_loc->node_type(); | |
2187 if ( ptn_loc_type == PointsToNode::LocalVar && ptn_loc->_node != NULL && | |
2188 ptn_loc->edge_count() == 1 && ptn_loc->edge_target(0) == ni ) { | |
2189 tty->print("%6d LocalVar [[%d]]", li, ni); | |
2190 _nodes->adr_at(li)->_node->dump(); | |
0 | 2191 } |
2192 } | |
65 | 2193 if (Verbose) { |
2194 // Print all fields which reference this allocation | |
2195 for (uint i = 0; i < ptn->edge_count(); i++) { | |
2196 uint ei = ptn->edge_target(i); | |
2197 tty->print("%6d Field [[%d]]", ei, ni); | |
2198 _nodes->adr_at(ei)->_node->dump(); | |
2199 } | |
2200 } | |
2201 tty->cr(); | |
0 | 2202 } |
2203 } | |
2204 } | |
2205 #endif |