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