author | anoll |
Mon, 14 Apr 2014 09:04:36 +0000 | |
changeset 24016 | 2927072ed5fb |
parent 24015 | e54063b2eb53 |
parent 24009 | ec494183af7e |
child 24424 | 2658d7834c6e |
permissions | -rw-r--r-- |
1 | 1 |
/* |
22234
da823d78ad65
8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
mikael
parents:
21099
diff
changeset
|
2 |
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4020
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4020
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4020
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "memory/allocation.inline.hpp" |
|
27 |
#include "opto/block.hpp" |
|
28 |
#include "opto/callnode.hpp" |
|
29 |
#include "opto/cfgnode.hpp" |
|
30 |
#include "opto/idealGraphPrinter.hpp" |
|
31 |
#include "opto/loopnode.hpp" |
|
32 |
#include "opto/machnode.hpp" |
|
33 |
#include "opto/opcodes.hpp" |
|
34 |
#include "opto/phaseX.hpp" |
|
35 |
#include "opto/regalloc.hpp" |
|
36 |
#include "opto/rootnode.hpp" |
|
1 | 37 |
|
38 |
//============================================================================= |
|
39 |
#define NODE_HASH_MINIMUM_SIZE 255 |
|
40 |
//------------------------------NodeHash--------------------------------------- |
|
41 |
NodeHash::NodeHash(uint est_max_size) : |
|
42 |
_max( round_up(est_max_size < NODE_HASH_MINIMUM_SIZE ? NODE_HASH_MINIMUM_SIZE : est_max_size) ), |
|
43 |
_a(Thread::current()->resource_area()), |
|
44 |
_table( NEW_ARENA_ARRAY( _a , Node* , _max ) ), // (Node**)_a->Amalloc(_max * sizeof(Node*)) ), |
|
45 |
_inserts(0), _insert_limit( insert_limit() ), |
|
46 |
_look_probes(0), _lookup_hits(0), _lookup_misses(0), |
|
47 |
_total_insert_probes(0), _total_inserts(0), |
|
48 |
_insert_probes(0), _grows(0) { |
|
49 |
// _sentinel must be in the current node space |
|
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
13312
diff
changeset
|
50 |
_sentinel = new (Compile::current()) ProjNode(NULL, TypeFunc::Control); |
1 | 51 |
memset(_table,0,sizeof(Node*)*_max); |
52 |
} |
|
53 |
||
54 |
//------------------------------NodeHash--------------------------------------- |
|
55 |
NodeHash::NodeHash(Arena *arena, uint est_max_size) : |
|
56 |
_max( round_up(est_max_size < NODE_HASH_MINIMUM_SIZE ? NODE_HASH_MINIMUM_SIZE : est_max_size) ), |
|
57 |
_a(arena), |
|
58 |
_table( NEW_ARENA_ARRAY( _a , Node* , _max ) ), |
|
59 |
_inserts(0), _insert_limit( insert_limit() ), |
|
60 |
_look_probes(0), _lookup_hits(0), _lookup_misses(0), |
|
61 |
_delete_probes(0), _delete_hits(0), _delete_misses(0), |
|
62 |
_total_insert_probes(0), _total_inserts(0), |
|
63 |
_insert_probes(0), _grows(0) { |
|
64 |
// _sentinel must be in the current node space |
|
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
13312
diff
changeset
|
65 |
_sentinel = new (Compile::current()) ProjNode(NULL, TypeFunc::Control); |
1 | 66 |
memset(_table,0,sizeof(Node*)*_max); |
67 |
} |
|
68 |
||
69 |
//------------------------------NodeHash--------------------------------------- |
|
70 |
NodeHash::NodeHash(NodeHash *nh) { |
|
71 |
debug_only(_table = (Node**)badAddress); // interact correctly w/ operator= |
|
72 |
// just copy in all the fields |
|
73 |
*this = *nh; |
|
74 |
// nh->_sentinel must be in the current node space |
|
75 |
} |
|
76 |
||
15113 | 77 |
void NodeHash::replace_with(NodeHash *nh) { |
78 |
debug_only(_table = (Node**)badAddress); // interact correctly w/ operator= |
|
79 |
// just copy in all the fields |
|
80 |
*this = *nh; |
|
81 |
// nh->_sentinel must be in the current node space |
|
82 |
} |
|
83 |
||
1 | 84 |
//------------------------------hash_find-------------------------------------- |
85 |
// Find in hash table |
|
86 |
Node *NodeHash::hash_find( const Node *n ) { |
|
87 |
// ((Node*)n)->set_hash( n->hash() ); |
|
88 |
uint hash = n->hash(); |
|
89 |
if (hash == Node::NO_HASH) { |
|
90 |
debug_only( _lookup_misses++ ); |
|
91 |
return NULL; |
|
92 |
} |
|
93 |
uint key = hash & (_max-1); |
|
94 |
uint stride = key | 0x01; |
|
95 |
debug_only( _look_probes++ ); |
|
96 |
Node *k = _table[key]; // Get hashed value |
|
97 |
if( !k ) { // ?Miss? |
|
98 |
debug_only( _lookup_misses++ ); |
|
99 |
return NULL; // Miss! |
|
100 |
} |
|
101 |
||
102 |
int op = n->Opcode(); |
|
103 |
uint req = n->req(); |
|
104 |
while( 1 ) { // While probing hash table |
|
105 |
if( k->req() == req && // Same count of inputs |
|
106 |
k->Opcode() == op ) { // Same Opcode |
|
107 |
for( uint i=0; i<req; i++ ) |
|
108 |
if( n->in(i)!=k->in(i)) // Different inputs? |
|
109 |
goto collision; // "goto" is a speed hack... |
|
110 |
if( n->cmp(*k) ) { // Check for any special bits |
|
111 |
debug_only( _lookup_hits++ ); |
|
112 |
return k; // Hit! |
|
113 |
} |
|
114 |
} |
|
115 |
collision: |
|
116 |
debug_only( _look_probes++ ); |
|
117 |
key = (key + stride/*7*/) & (_max-1); // Stride through table with relative prime |
|
118 |
k = _table[key]; // Get hashed value |
|
119 |
if( !k ) { // ?Miss? |
|
120 |
debug_only( _lookup_misses++ ); |
|
121 |
return NULL; // Miss! |
|
122 |
} |
|
123 |
} |
|
124 |
ShouldNotReachHere(); |
|
125 |
return NULL; |
|
126 |
} |
|
127 |
||
128 |
//------------------------------hash_find_insert------------------------------- |
|
129 |
// Find in hash table, insert if not already present |
|
130 |
// Used to preserve unique entries in hash table |
|
131 |
Node *NodeHash::hash_find_insert( Node *n ) { |
|
132 |
// n->set_hash( ); |
|
133 |
uint hash = n->hash(); |
|
134 |
if (hash == Node::NO_HASH) { |
|
135 |
debug_only( _lookup_misses++ ); |
|
136 |
return NULL; |
|
137 |
} |
|
138 |
uint key = hash & (_max-1); |
|
139 |
uint stride = key | 0x01; // stride must be relatively prime to table siz |
|
140 |
uint first_sentinel = 0; // replace a sentinel if seen. |
|
141 |
debug_only( _look_probes++ ); |
|
142 |
Node *k = _table[key]; // Get hashed value |
|
143 |
if( !k ) { // ?Miss? |
|
144 |
debug_only( _lookup_misses++ ); |
|
145 |
_table[key] = n; // Insert into table! |
|
146 |
debug_only(n->enter_hash_lock()); // Lock down the node while in the table. |
|
147 |
check_grow(); // Grow table if insert hit limit |
|
148 |
return NULL; // Miss! |
|
149 |
} |
|
150 |
else if( k == _sentinel ) { |
|
151 |
first_sentinel = key; // Can insert here |
|
152 |
} |
|
153 |
||
154 |
int op = n->Opcode(); |
|
155 |
uint req = n->req(); |
|
156 |
while( 1 ) { // While probing hash table |
|
157 |
if( k->req() == req && // Same count of inputs |
|
158 |
k->Opcode() == op ) { // Same Opcode |
|
159 |
for( uint i=0; i<req; i++ ) |
|
160 |
if( n->in(i)!=k->in(i)) // Different inputs? |
|
161 |
goto collision; // "goto" is a speed hack... |
|
162 |
if( n->cmp(*k) ) { // Check for any special bits |
|
163 |
debug_only( _lookup_hits++ ); |
|
164 |
return k; // Hit! |
|
165 |
} |
|
166 |
} |
|
167 |
collision: |
|
168 |
debug_only( _look_probes++ ); |
|
169 |
key = (key + stride) & (_max-1); // Stride through table w/ relative prime |
|
170 |
k = _table[key]; // Get hashed value |
|
171 |
if( !k ) { // ?Miss? |
|
172 |
debug_only( _lookup_misses++ ); |
|
173 |
key = (first_sentinel == 0) ? key : first_sentinel; // ?saw sentinel? |
|
174 |
_table[key] = n; // Insert into table! |
|
175 |
debug_only(n->enter_hash_lock()); // Lock down the node while in the table. |
|
176 |
check_grow(); // Grow table if insert hit limit |
|
177 |
return NULL; // Miss! |
|
178 |
} |
|
179 |
else if( first_sentinel == 0 && k == _sentinel ) { |
|
180 |
first_sentinel = key; // Can insert here |
|
181 |
} |
|
182 |
||
183 |
} |
|
184 |
ShouldNotReachHere(); |
|
185 |
return NULL; |
|
186 |
} |
|
187 |
||
188 |
//------------------------------hash_insert------------------------------------ |
|
189 |
// Insert into hash table |
|
190 |
void NodeHash::hash_insert( Node *n ) { |
|
191 |
// // "conflict" comments -- print nodes that conflict |
|
192 |
// bool conflict = false; |
|
193 |
// n->set_hash(); |
|
194 |
uint hash = n->hash(); |
|
195 |
if (hash == Node::NO_HASH) { |
|
196 |
return; |
|
197 |
} |
|
198 |
check_grow(); |
|
199 |
uint key = hash & (_max-1); |
|
200 |
uint stride = key | 0x01; |
|
201 |
||
202 |
while( 1 ) { // While probing hash table |
|
203 |
debug_only( _insert_probes++ ); |
|
204 |
Node *k = _table[key]; // Get hashed value |
|
205 |
if( !k || (k == _sentinel) ) break; // Found a slot |
|
206 |
assert( k != n, "already inserted" ); |
|
207 |
// if( PrintCompilation && PrintOptoStatistics && Verbose ) { tty->print(" conflict: "); k->dump(); conflict = true; } |
|
208 |
key = (key + stride) & (_max-1); // Stride through table w/ relative prime |
|
209 |
} |
|
210 |
_table[key] = n; // Insert into table! |
|
211 |
debug_only(n->enter_hash_lock()); // Lock down the node while in the table. |
|
212 |
// if( conflict ) { n->dump(); } |
|
213 |
} |
|
214 |
||
215 |
//------------------------------hash_delete------------------------------------ |
|
2131 | 216 |
// Replace in hash table with sentinel |
1 | 217 |
bool NodeHash::hash_delete( const Node *n ) { |
218 |
Node *k; |
|
219 |
uint hash = n->hash(); |
|
220 |
if (hash == Node::NO_HASH) { |
|
221 |
debug_only( _delete_misses++ ); |
|
222 |
return false; |
|
223 |
} |
|
224 |
uint key = hash & (_max-1); |
|
225 |
uint stride = key | 0x01; |
|
226 |
debug_only( uint counter = 0; ); |
|
2131 | 227 |
for( ; /* (k != NULL) && (k != _sentinel) */; ) { |
1 | 228 |
debug_only( counter++ ); |
229 |
debug_only( _delete_probes++ ); |
|
230 |
k = _table[key]; // Get hashed value |
|
231 |
if( !k ) { // Miss? |
|
232 |
debug_only( _delete_misses++ ); |
|
233 |
#ifdef ASSERT |
|
234 |
if( VerifyOpto ) { |
|
235 |
for( uint i=0; i < _max; i++ ) |
|
236 |
assert( _table[i] != n, "changed edges with rehashing" ); |
|
237 |
} |
|
238 |
#endif |
|
239 |
return false; // Miss! Not in chain |
|
240 |
} |
|
241 |
else if( n == k ) { |
|
242 |
debug_only( _delete_hits++ ); |
|
243 |
_table[key] = _sentinel; // Hit! Label as deleted entry |
|
244 |
debug_only(((Node*)n)->exit_hash_lock()); // Unlock the node upon removal from table. |
|
245 |
return true; |
|
246 |
} |
|
247 |
else { |
|
248 |
// collision: move through table with prime offset |
|
249 |
key = (key + stride/*7*/) & (_max-1); |
|
250 |
assert( counter <= _insert_limit, "Cycle in hash-table"); |
|
251 |
} |
|
252 |
} |
|
253 |
ShouldNotReachHere(); |
|
254 |
return false; |
|
255 |
} |
|
256 |
||
257 |
//------------------------------round_up--------------------------------------- |
|
258 |
// Round up to nearest power of 2 |
|
259 |
uint NodeHash::round_up( uint x ) { |
|
260 |
x += (x>>2); // Add 25% slop |
|
261 |
if( x <16 ) return 16; // Small stuff |
|
262 |
uint i=16; |
|
263 |
while( i < x ) i <<= 1; // Double to fit |
|
264 |
return i; // Return hash table size |
|
265 |
} |
|
266 |
||
267 |
//------------------------------grow------------------------------------------- |
|
268 |
// Grow _table to next power of 2 and insert old entries |
|
269 |
void NodeHash::grow() { |
|
270 |
// Record old state |
|
271 |
uint old_max = _max; |
|
272 |
Node **old_table = _table; |
|
273 |
// Construct new table with twice the space |
|
274 |
_grows++; |
|
275 |
_total_inserts += _inserts; |
|
276 |
_total_insert_probes += _insert_probes; |
|
277 |
_inserts = 0; |
|
278 |
_insert_probes = 0; |
|
279 |
_max = _max << 1; |
|
280 |
_table = NEW_ARENA_ARRAY( _a , Node* , _max ); // (Node**)_a->Amalloc( _max * sizeof(Node*) ); |
|
281 |
memset(_table,0,sizeof(Node*)*_max); |
|
282 |
_insert_limit = insert_limit(); |
|
283 |
// Insert old entries into the new table |
|
284 |
for( uint i = 0; i < old_max; i++ ) { |
|
285 |
Node *m = *old_table++; |
|
286 |
if( !m || m == _sentinel ) continue; |
|
287 |
debug_only(m->exit_hash_lock()); // Unlock the node upon removal from old table. |
|
288 |
hash_insert(m); |
|
289 |
} |
|
290 |
} |
|
291 |
||
292 |
//------------------------------clear------------------------------------------ |
|
293 |
// Clear all entries in _table to NULL but keep storage |
|
294 |
void NodeHash::clear() { |
|
295 |
#ifdef ASSERT |
|
296 |
// Unlock all nodes upon removal from table. |
|
297 |
for (uint i = 0; i < _max; i++) { |
|
298 |
Node* n = _table[i]; |
|
299 |
if (!n || n == _sentinel) continue; |
|
300 |
n->exit_hash_lock(); |
|
301 |
} |
|
302 |
#endif |
|
303 |
||
304 |
memset( _table, 0, _max * sizeof(Node*) ); |
|
305 |
} |
|
306 |
||
307 |
//-----------------------remove_useless_nodes---------------------------------- |
|
308 |
// Remove useless nodes from value table, |
|
309 |
// implementation does not depend on hash function |
|
310 |
void NodeHash::remove_useless_nodes(VectorSet &useful) { |
|
311 |
||
312 |
// Dead nodes in the hash table inherited from GVN should not replace |
|
313 |
// existing nodes, remove dead nodes. |
|
314 |
uint max = size(); |
|
315 |
Node *sentinel_node = sentinel(); |
|
316 |
for( uint i = 0; i < max; ++i ) { |
|
317 |
Node *n = at(i); |
|
318 |
if(n != NULL && n != sentinel_node && !useful.test(n->_idx)) { |
|
319 |
debug_only(n->exit_hash_lock()); // Unlock the node when removed |
|
320 |
_table[i] = sentinel_node; // Replace with placeholder |
|
321 |
} |
|
322 |
} |
|
323 |
} |
|
324 |
||
22799
83e58bac7980
8027422: assert(_gvn.type(obj)->higher_equal(tjp)) failed: cast_up is no longer needed
roland
parents:
22234
diff
changeset
|
325 |
|
83e58bac7980
8027422: assert(_gvn.type(obj)->higher_equal(tjp)) failed: cast_up is no longer needed
roland
parents:
22234
diff
changeset
|
326 |
void NodeHash::check_no_speculative_types() { |
83e58bac7980
8027422: assert(_gvn.type(obj)->higher_equal(tjp)) failed: cast_up is no longer needed
roland
parents:
22234
diff
changeset
|
327 |
#ifdef ASSERT |
83e58bac7980
8027422: assert(_gvn.type(obj)->higher_equal(tjp)) failed: cast_up is no longer needed
roland
parents:
22234
diff
changeset
|
328 |
uint max = size(); |
83e58bac7980
8027422: assert(_gvn.type(obj)->higher_equal(tjp)) failed: cast_up is no longer needed
roland
parents:
22234
diff
changeset
|
329 |
Node *sentinel_node = sentinel(); |
83e58bac7980
8027422: assert(_gvn.type(obj)->higher_equal(tjp)) failed: cast_up is no longer needed
roland
parents:
22234
diff
changeset
|
330 |
for (uint i = 0; i < max; ++i) { |
83e58bac7980
8027422: assert(_gvn.type(obj)->higher_equal(tjp)) failed: cast_up is no longer needed
roland
parents:
22234
diff
changeset
|
331 |
Node *n = at(i); |
23525
e3eb08ead679
8031755: Type speculation should be used to optimize explicit null checks
roland
parents:
22799
diff
changeset
|
332 |
if(n != NULL && n != sentinel_node && n->is_Type() && n->outcnt() > 0) { |
22799
83e58bac7980
8027422: assert(_gvn.type(obj)->higher_equal(tjp)) failed: cast_up is no longer needed
roland
parents:
22234
diff
changeset
|
333 |
TypeNode* tn = n->as_Type(); |
83e58bac7980
8027422: assert(_gvn.type(obj)->higher_equal(tjp)) failed: cast_up is no longer needed
roland
parents:
22234
diff
changeset
|
334 |
const Type* t = tn->type(); |
83e58bac7980
8027422: assert(_gvn.type(obj)->higher_equal(tjp)) failed: cast_up is no longer needed
roland
parents:
22234
diff
changeset
|
335 |
const Type* t_no_spec = t->remove_speculative(); |
83e58bac7980
8027422: assert(_gvn.type(obj)->higher_equal(tjp)) failed: cast_up is no longer needed
roland
parents:
22234
diff
changeset
|
336 |
assert(t == t_no_spec, "dead node in hash table or missed node during speculative cleanup"); |
83e58bac7980
8027422: assert(_gvn.type(obj)->higher_equal(tjp)) failed: cast_up is no longer needed
roland
parents:
22234
diff
changeset
|
337 |
} |
83e58bac7980
8027422: assert(_gvn.type(obj)->higher_equal(tjp)) failed: cast_up is no longer needed
roland
parents:
22234
diff
changeset
|
338 |
} |
83e58bac7980
8027422: assert(_gvn.type(obj)->higher_equal(tjp)) failed: cast_up is no longer needed
roland
parents:
22234
diff
changeset
|
339 |
#endif |
83e58bac7980
8027422: assert(_gvn.type(obj)->higher_equal(tjp)) failed: cast_up is no longer needed
roland
parents:
22234
diff
changeset
|
340 |
} |
83e58bac7980
8027422: assert(_gvn.type(obj)->higher_equal(tjp)) failed: cast_up is no longer needed
roland
parents:
22234
diff
changeset
|
341 |
|
1 | 342 |
#ifndef PRODUCT |
343 |
//------------------------------dump------------------------------------------- |
|
344 |
// Dump statistics for the hash table |
|
345 |
void NodeHash::dump() { |
|
346 |
_total_inserts += _inserts; |
|
347 |
_total_insert_probes += _insert_probes; |
|
10988
a3b2bd43ef4f
7107042: assert(no_dead_loop) failed: dead loop detected
kvn
parents:
10563
diff
changeset
|
348 |
if (PrintCompilation && PrintOptoStatistics && Verbose && (_inserts > 0)) { |
a3b2bd43ef4f
7107042: assert(no_dead_loop) failed: dead loop detected
kvn
parents:
10563
diff
changeset
|
349 |
if (WizardMode) { |
a3b2bd43ef4f
7107042: assert(no_dead_loop) failed: dead loop detected
kvn
parents:
10563
diff
changeset
|
350 |
for (uint i=0; i<_max; i++) { |
a3b2bd43ef4f
7107042: assert(no_dead_loop) failed: dead loop detected
kvn
parents:
10563
diff
changeset
|
351 |
if (_table[i]) |
a3b2bd43ef4f
7107042: assert(no_dead_loop) failed: dead loop detected
kvn
parents:
10563
diff
changeset
|
352 |
tty->print("%d/%d/%d ",i,_table[i]->hash()&(_max-1),_table[i]->_idx); |
a3b2bd43ef4f
7107042: assert(no_dead_loop) failed: dead loop detected
kvn
parents:
10563
diff
changeset
|
353 |
} |
1 | 354 |
} |
355 |
tty->print("\nGVN Hash stats: %d grows to %d max_size\n", _grows, _max); |
|
356 |
tty->print(" %d/%d (%8.1f%% full)\n", _inserts, _max, (double)_inserts/_max*100.0); |
|
357 |
tty->print(" %dp/(%dh+%dm) (%8.2f probes/lookup)\n", _look_probes, _lookup_hits, _lookup_misses, (double)_look_probes/(_lookup_hits+_lookup_misses)); |
|
358 |
tty->print(" %dp/%di (%8.2f probes/insert)\n", _total_insert_probes, _total_inserts, (double)_total_insert_probes/_total_inserts); |
|
359 |
// sentinels increase lookup cost, but not insert cost |
|
360 |
assert((_lookup_misses+_lookup_hits)*4+100 >= _look_probes, "bad hash function"); |
|
361 |
assert( _inserts+(_inserts>>3) < _max, "table too full" ); |
|
362 |
assert( _inserts*3+100 >= _insert_probes, "bad hash function" ); |
|
363 |
} |
|
364 |
} |
|
365 |
||
366 |
Node *NodeHash::find_index(uint idx) { // For debugging |
|
367 |
// Find an entry by its index value |
|
368 |
for( uint i = 0; i < _max; i++ ) { |
|
369 |
Node *m = _table[i]; |
|
370 |
if( !m || m == _sentinel ) continue; |
|
371 |
if( m->_idx == (uint)idx ) return m; |
|
372 |
} |
|
373 |
return NULL; |
|
374 |
} |
|
375 |
#endif |
|
376 |
||
377 |
#ifdef ASSERT |
|
378 |
NodeHash::~NodeHash() { |
|
379 |
// Unlock all nodes upon destruction of table. |
|
380 |
if (_table != (Node**)badAddress) clear(); |
|
381 |
} |
|
382 |
||
383 |
void NodeHash::operator=(const NodeHash& nh) { |
|
384 |
// Unlock all nodes upon replacement of table. |
|
385 |
if (&nh == this) return; |
|
386 |
if (_table != (Node**)badAddress) clear(); |
|
387 |
memcpy(this, &nh, sizeof(*this)); |
|
388 |
// Do not increment hash_lock counts again. |
|
389 |
// Instead, be sure we never again use the source table. |
|
390 |
((NodeHash*)&nh)->_table = (Node**)badAddress; |
|
391 |
} |
|
392 |
||
393 |
||
394 |
#endif |
|
395 |
||
396 |
||
397 |
//============================================================================= |
|
398 |
//------------------------------PhaseRemoveUseless----------------------------- |
|
399 |
// 1) Use a breadthfirst walk to collect useful nodes reachable from root. |
|
400 |
PhaseRemoveUseless::PhaseRemoveUseless( PhaseGVN *gvn, Unique_Node_List *worklist ) : Phase(Remove_Useless), |
|
401 |
_useful(Thread::current()->resource_area()) { |
|
402 |
||
403 |
// Implementation requires 'UseLoopSafepoints == true' and an edge from root |
|
404 |
// to each SafePointNode at a backward branch. Inserted in add_safepoint(). |
|
405 |
if( !UseLoopSafepoints || !OptoRemoveUseless ) return; |
|
406 |
||
407 |
// Identify nodes that are reachable from below, useful. |
|
408 |
C->identify_useful_nodes(_useful); |
|
14623
70c4c1be0a14
7092905: C2: Keep track of the number of dead nodes
bharadwaj
parents:
13963
diff
changeset
|
409 |
// Update dead node list |
70c4c1be0a14
7092905: C2: Keep track of the number of dead nodes
bharadwaj
parents:
13963
diff
changeset
|
410 |
C->update_dead_node_list(_useful); |
1 | 411 |
|
412 |
// Remove all useless nodes from PhaseValues' recorded types |
|
413 |
// Must be done before disconnecting nodes to preserve hash-table-invariant |
|
414 |
gvn->remove_useless_nodes(_useful.member_set()); |
|
415 |
||
416 |
// Remove all useless nodes from future worklist |
|
417 |
worklist->remove_useless_nodes(_useful.member_set()); |
|
418 |
||
419 |
// Disconnect 'useless' nodes that are adjacent to useful nodes |
|
420 |
C->remove_useless_nodes(_useful); |
|
421 |
||
422 |
// Remove edges from "root" to each SafePoint at a backward branch. |
|
423 |
// They were inserted during parsing (see add_safepoint()) to make infinite |
|
424 |
// loops without calls or exceptions visible to root, i.e., useful. |
|
425 |
Node *root = C->root(); |
|
426 |
if( root != NULL ) { |
|
427 |
for( uint i = root->req(); i < root->len(); ++i ) { |
|
428 |
Node *n = root->in(i); |
|
429 |
if( n != NULL && n->is_SafePoint() ) { |
|
430 |
root->rm_prec(i); |
|
431 |
--i; |
|
432 |
} |
|
433 |
} |
|
434 |
} |
|
435 |
} |
|
436 |
||
437 |
||
438 |
//============================================================================= |
|
439 |
//------------------------------PhaseTransform--------------------------------- |
|
440 |
PhaseTransform::PhaseTransform( PhaseNumber pnum ) : Phase(pnum), |
|
441 |
_arena(Thread::current()->resource_area()), |
|
442 |
_nodes(_arena), |
|
443 |
_types(_arena) |
|
444 |
{ |
|
445 |
init_con_caches(); |
|
446 |
#ifndef PRODUCT |
|
447 |
clear_progress(); |
|
448 |
clear_transforms(); |
|
449 |
set_allow_progress(true); |
|
450 |
#endif |
|
451 |
// Force allocation for currently existing nodes |
|
452 |
_types.map(C->unique(), NULL); |
|
453 |
} |
|
454 |
||
455 |
//------------------------------PhaseTransform--------------------------------- |
|
456 |
PhaseTransform::PhaseTransform( Arena *arena, PhaseNumber pnum ) : Phase(pnum), |
|
457 |
_arena(arena), |
|
458 |
_nodes(arena), |
|
459 |
_types(arena) |
|
460 |
{ |
|
461 |
init_con_caches(); |
|
462 |
#ifndef PRODUCT |
|
463 |
clear_progress(); |
|
464 |
clear_transforms(); |
|
465 |
set_allow_progress(true); |
|
466 |
#endif |
|
467 |
// Force allocation for currently existing nodes |
|
468 |
_types.map(C->unique(), NULL); |
|
469 |
} |
|
470 |
||
471 |
//------------------------------PhaseTransform--------------------------------- |
|
472 |
// Initialize with previously generated type information |
|
473 |
PhaseTransform::PhaseTransform( PhaseTransform *pt, PhaseNumber pnum ) : Phase(pnum), |
|
474 |
_arena(pt->_arena), |
|
475 |
_nodes(pt->_nodes), |
|
476 |
_types(pt->_types) |
|
477 |
{ |
|
478 |
init_con_caches(); |
|
479 |
#ifndef PRODUCT |
|
480 |
clear_progress(); |
|
481 |
clear_transforms(); |
|
482 |
set_allow_progress(true); |
|
483 |
#endif |
|
484 |
} |
|
485 |
||
486 |
void PhaseTransform::init_con_caches() { |
|
487 |
memset(_icons,0,sizeof(_icons)); |
|
488 |
memset(_lcons,0,sizeof(_lcons)); |
|
489 |
memset(_zcons,0,sizeof(_zcons)); |
|
490 |
} |
|
491 |
||
492 |
||
493 |
//--------------------------------find_int_type-------------------------------- |
|
494 |
const TypeInt* PhaseTransform::find_int_type(Node* n) { |
|
495 |
if (n == NULL) return NULL; |
|
496 |
// Call type_or_null(n) to determine node's type since we might be in |
|
497 |
// parse phase and call n->Value() may return wrong type. |
|
498 |
// (For example, a phi node at the beginning of loop parsing is not ready.) |
|
499 |
const Type* t = type_or_null(n); |
|
500 |
if (t == NULL) return NULL; |
|
501 |
return t->isa_int(); |
|
502 |
} |
|
503 |
||
504 |
||
505 |
//-------------------------------find_long_type-------------------------------- |
|
506 |
const TypeLong* PhaseTransform::find_long_type(Node* n) { |
|
507 |
if (n == NULL) return NULL; |
|
508 |
// (See comment above on type_or_null.) |
|
509 |
const Type* t = type_or_null(n); |
|
510 |
if (t == NULL) return NULL; |
|
511 |
return t->isa_long(); |
|
512 |
} |
|
513 |
||
514 |
||
515 |
#ifndef PRODUCT |
|
516 |
void PhaseTransform::dump_old2new_map() const { |
|
517 |
_nodes.dump(); |
|
518 |
} |
|
519 |
||
520 |
void PhaseTransform::dump_new( uint nidx ) const { |
|
521 |
for( uint i=0; i<_nodes.Size(); i++ ) |
|
522 |
if( _nodes[i] && _nodes[i]->_idx == nidx ) { |
|
523 |
_nodes[i]->dump(); |
|
524 |
tty->cr(); |
|
525 |
tty->print_cr("Old index= %d",i); |
|
526 |
return; |
|
527 |
} |
|
528 |
tty->print_cr("Node %d not found in the new indices", nidx); |
|
529 |
} |
|
530 |
||
531 |
//------------------------------dump_types------------------------------------- |
|
532 |
void PhaseTransform::dump_types( ) const { |
|
533 |
_types.dump(); |
|
534 |
} |
|
535 |
||
536 |
//------------------------------dump_nodes_and_types--------------------------- |
|
537 |
void PhaseTransform::dump_nodes_and_types(const Node *root, uint depth, bool only_ctrl) { |
|
538 |
VectorSet visited(Thread::current()->resource_area()); |
|
539 |
dump_nodes_and_types_recur( root, depth, only_ctrl, visited ); |
|
540 |
} |
|
541 |
||
542 |
//------------------------------dump_nodes_and_types_recur--------------------- |
|
543 |
void PhaseTransform::dump_nodes_and_types_recur( const Node *n, uint depth, bool only_ctrl, VectorSet &visited) { |
|
544 |
if( !n ) return; |
|
545 |
if( depth == 0 ) return; |
|
546 |
if( visited.test_set(n->_idx) ) return; |
|
547 |
for( uint i=0; i<n->len(); i++ ) { |
|
548 |
if( only_ctrl && !(n->is_Region()) && i != TypeFunc::Control ) continue; |
|
549 |
dump_nodes_and_types_recur( n->in(i), depth-1, only_ctrl, visited ); |
|
550 |
} |
|
551 |
n->dump(); |
|
552 |
if (type_or_null(n) != NULL) { |
|
553 |
tty->print(" "); type(n)->dump(); tty->cr(); |
|
554 |
} |
|
555 |
} |
|
556 |
||
557 |
#endif |
|
558 |
||
559 |
||
560 |
//============================================================================= |
|
561 |
//------------------------------PhaseValues------------------------------------ |
|
562 |
// Set minimum table size to "255" |
|
563 |
PhaseValues::PhaseValues( Arena *arena, uint est_max_size ) : PhaseTransform(arena, GVN), _table(arena, est_max_size) { |
|
564 |
NOT_PRODUCT( clear_new_values(); ) |
|
565 |
} |
|
566 |
||
567 |
//------------------------------PhaseValues------------------------------------ |
|
568 |
// Set minimum table size to "255" |
|
569 |
PhaseValues::PhaseValues( PhaseValues *ptv ) : PhaseTransform( ptv, GVN ), |
|
570 |
_table(&ptv->_table) { |
|
571 |
NOT_PRODUCT( clear_new_values(); ) |
|
572 |
} |
|
573 |
||
574 |
//------------------------------PhaseValues------------------------------------ |
|
575 |
// Used by +VerifyOpto. Clear out hash table but copy _types array. |
|
576 |
PhaseValues::PhaseValues( PhaseValues *ptv, const char *dummy ) : PhaseTransform( ptv, GVN ), |
|
577 |
_table(ptv->arena(),ptv->_table.size()) { |
|
578 |
NOT_PRODUCT( clear_new_values(); ) |
|
579 |
} |
|
580 |
||
581 |
//------------------------------~PhaseValues----------------------------------- |
|
582 |
#ifndef PRODUCT |
|
583 |
PhaseValues::~PhaseValues() { |
|
584 |
_table.dump(); |
|
585 |
||
586 |
// Statistics for value progress and efficiency |
|
587 |
if( PrintCompilation && Verbose && WizardMode ) { |
|
588 |
tty->print("\n%sValues: %d nodes ---> %d/%d (%d)", |
|
589 |
is_IterGVN() ? "Iter" : " ", C->unique(), made_progress(), made_transforms(), made_new_values()); |
|
590 |
if( made_transforms() != 0 ) { |
|
591 |
tty->print_cr(" ratio %f", made_progress()/(float)made_transforms() ); |
|
592 |
} else { |
|
593 |
tty->cr(); |
|
594 |
} |
|
595 |
} |
|
596 |
} |
|
597 |
#endif |
|
598 |
||
599 |
//------------------------------makecon---------------------------------------- |
|
600 |
ConNode* PhaseTransform::makecon(const Type *t) { |
|
601 |
assert(t->singleton(), "must be a constant"); |
|
602 |
assert(!t->empty() || t == Type::TOP, "must not be vacuous range"); |
|
603 |
switch (t->base()) { // fast paths |
|
604 |
case Type::Half: |
|
605 |
case Type::Top: return (ConNode*) C->top(); |
|
606 |
case Type::Int: return intcon( t->is_int()->get_con() ); |
|
607 |
case Type::Long: return longcon( t->is_long()->get_con() ); |
|
608 |
} |
|
609 |
if (t->is_zero_type()) |
|
610 |
return zerocon(t->basic_type()); |
|
611 |
return uncached_makecon(t); |
|
612 |
} |
|
613 |
||
614 |
//--------------------------uncached_makecon----------------------------------- |
|
615 |
// Make an idealized constant - one of ConINode, ConPNode, etc. |
|
616 |
ConNode* PhaseValues::uncached_makecon(const Type *t) { |
|
617 |
assert(t->singleton(), "must be a constant"); |
|
618 |
ConNode* x = ConNode::make(C, t); |
|
619 |
ConNode* k = (ConNode*)hash_find_insert(x); // Value numbering |
|
620 |
if (k == NULL) { |
|
621 |
set_type(x, t); // Missed, provide type mapping |
|
622 |
GrowableArray<Node_Notes*>* nna = C->node_note_array(); |
|
623 |
if (nna != NULL) { |
|
624 |
Node_Notes* loc = C->locate_node_notes(nna, x->_idx, true); |
|
625 |
loc->clear(); // do not put debug info on constants |
|
626 |
} |
|
627 |
} else { |
|
628 |
x->destruct(); // Hit, destroy duplicate constant |
|
629 |
x = k; // use existing constant |
|
630 |
} |
|
631 |
return x; |
|
632 |
} |
|
633 |
||
634 |
//------------------------------intcon----------------------------------------- |
|
635 |
// Fast integer constant. Same as "transform(new ConINode(TypeInt::make(i)))" |
|
636 |
ConINode* PhaseTransform::intcon(int i) { |
|
637 |
// Small integer? Check cache! Check that cached node is not dead |
|
638 |
if (i >= _icon_min && i <= _icon_max) { |
|
639 |
ConINode* icon = _icons[i-_icon_min]; |
|
640 |
if (icon != NULL && icon->in(TypeFunc::Control) != NULL) |
|
641 |
return icon; |
|
642 |
} |
|
643 |
ConINode* icon = (ConINode*) uncached_makecon(TypeInt::make(i)); |
|
644 |
assert(icon->is_Con(), ""); |
|
645 |
if (i >= _icon_min && i <= _icon_max) |
|
646 |
_icons[i-_icon_min] = icon; // Cache small integers |
|
647 |
return icon; |
|
648 |
} |
|
649 |
||
650 |
//------------------------------longcon---------------------------------------- |
|
651 |
// Fast long constant. |
|
652 |
ConLNode* PhaseTransform::longcon(jlong l) { |
|
653 |
// Small integer? Check cache! Check that cached node is not dead |
|
654 |
if (l >= _lcon_min && l <= _lcon_max) { |
|
655 |
ConLNode* lcon = _lcons[l-_lcon_min]; |
|
656 |
if (lcon != NULL && lcon->in(TypeFunc::Control) != NULL) |
|
657 |
return lcon; |
|
658 |
} |
|
659 |
ConLNode* lcon = (ConLNode*) uncached_makecon(TypeLong::make(l)); |
|
660 |
assert(lcon->is_Con(), ""); |
|
661 |
if (l >= _lcon_min && l <= _lcon_max) |
|
662 |
_lcons[l-_lcon_min] = lcon; // Cache small integers |
|
663 |
return lcon; |
|
664 |
} |
|
665 |
||
666 |
//------------------------------zerocon----------------------------------------- |
|
667 |
// Fast zero or null constant. Same as "transform(ConNode::make(Type::get_zero_type(bt)))" |
|
668 |
ConNode* PhaseTransform::zerocon(BasicType bt) { |
|
669 |
assert((uint)bt <= _zcon_max, "domain check"); |
|
670 |
ConNode* zcon = _zcons[bt]; |
|
671 |
if (zcon != NULL && zcon->in(TypeFunc::Control) != NULL) |
|
672 |
return zcon; |
|
673 |
zcon = (ConNode*) uncached_makecon(Type::get_zero_type(bt)); |
|
674 |
_zcons[bt] = zcon; |
|
675 |
return zcon; |
|
676 |
} |
|
677 |
||
678 |
||
679 |
||
680 |
//============================================================================= |
|
681 |
//------------------------------transform-------------------------------------- |
|
682 |
// Return a node which computes the same function as this node, but in a |
|
214
c5d9b4456687
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
1
diff
changeset
|
683 |
// faster or cheaper fashion. |
1 | 684 |
Node *PhaseGVN::transform( Node *n ) { |
214
c5d9b4456687
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
1
diff
changeset
|
685 |
return transform_no_reclaim(n); |
1 | 686 |
} |
687 |
||
688 |
//------------------------------transform-------------------------------------- |
|
689 |
// Return a node which computes the same function as this node, but |
|
690 |
// in a faster or cheaper fashion. |
|
691 |
Node *PhaseGVN::transform_no_reclaim( Node *n ) { |
|
692 |
NOT_PRODUCT( set_transforms(); ) |
|
693 |
||
694 |
// Apply the Ideal call in a loop until it no longer applies |
|
695 |
Node *k = n; |
|
696 |
NOT_PRODUCT( uint loop_count = 0; ) |
|
697 |
while( 1 ) { |
|
698 |
Node *i = k->Ideal(this, /*can_reshape=*/false); |
|
699 |
if( !i ) break; |
|
700 |
assert( i->_idx >= k->_idx, "Idealize should return new nodes, use Identity to return old nodes" ); |
|
701 |
k = i; |
|
702 |
assert(loop_count++ < K, "infinite loop in PhaseGVN::transform"); |
|
703 |
} |
|
704 |
NOT_PRODUCT( if( loop_count != 0 ) { set_progress(); } ) |
|
705 |
||
706 |
||
707 |
// If brand new node, make space in type array. |
|
708 |
ensure_type_or_null(k); |
|
709 |
||
710 |
// Since I just called 'Value' to compute the set of run-time values |
|
711 |
// for this Node, and 'Value' is non-local (and therefore expensive) I'll |
|
712 |
// cache Value. Later requests for the local phase->type of this Node can |
|
713 |
// use the cached Value instead of suffering with 'bottom_type'. |
|
714 |
const Type *t = k->Value(this); // Get runtime Value set |
|
715 |
assert(t != NULL, "value sanity"); |
|
716 |
if (type_or_null(k) != t) { |
|
717 |
#ifndef PRODUCT |
|
718 |
// Do not count initial visit to node as a transformation |
|
719 |
if (type_or_null(k) == NULL) { |
|
720 |
inc_new_values(); |
|
721 |
set_progress(); |
|
722 |
} |
|
723 |
#endif |
|
724 |
set_type(k, t); |
|
725 |
// If k is a TypeNode, capture any more-precise type permanently into Node |
|
726 |
k->raise_bottom_type(t); |
|
727 |
} |
|
728 |
||
729 |
if( t->singleton() && !k->is_Con() ) { |
|
730 |
NOT_PRODUCT( set_progress(); ) |
|
731 |
return makecon(t); // Turn into a constant |
|
732 |
} |
|
733 |
||
734 |
// Now check for Identities |
|
735 |
Node *i = k->Identity(this); // Look for a nearby replacement |
|
736 |
if( i != k ) { // Found? Return replacement! |
|
737 |
NOT_PRODUCT( set_progress(); ) |
|
738 |
return i; |
|
739 |
} |
|
740 |
||
741 |
// Global Value Numbering |
|
742 |
i = hash_find_insert(k); // Insert if new |
|
743 |
if( i && (i != k) ) { |
|
744 |
// Return the pre-existing node |
|
745 |
NOT_PRODUCT( set_progress(); ) |
|
746 |
return i; |
|
747 |
} |
|
748 |
||
749 |
// Return Idealized original |
|
750 |
return k; |
|
751 |
} |
|
752 |
||
753 |
#ifdef ASSERT |
|
754 |
//------------------------------dead_loop_check-------------------------------- |
|
2131 | 755 |
// Check for a simple dead loop when a data node references itself directly |
1 | 756 |
// or through an other data node excluding cons and phis. |
757 |
void PhaseGVN::dead_loop_check( Node *n ) { |
|
758 |
// Phi may reference itself in a loop |
|
759 |
if (n != NULL && !n->is_dead_loop_safe() && !n->is_CFG()) { |
|
760 |
// Do 2 levels check and only data inputs. |
|
761 |
bool no_dead_loop = true; |
|
762 |
uint cnt = n->req(); |
|
763 |
for (uint i = 1; i < cnt && no_dead_loop; i++) { |
|
764 |
Node *in = n->in(i); |
|
765 |
if (in == n) { |
|
766 |
no_dead_loop = false; |
|
767 |
} else if (in != NULL && !in->is_dead_loop_safe()) { |
|
768 |
uint icnt = in->req(); |
|
769 |
for (uint j = 1; j < icnt && no_dead_loop; j++) { |
|
770 |
if (in->in(j) == n || in->in(j) == in) |
|
771 |
no_dead_loop = false; |
|
772 |
} |
|
773 |
} |
|
774 |
} |
|
775 |
if (!no_dead_loop) n->dump(3); |
|
776 |
assert(no_dead_loop, "dead loop detected"); |
|
777 |
} |
|
778 |
} |
|
779 |
#endif |
|
780 |
||
781 |
//============================================================================= |
|
782 |
//------------------------------PhaseIterGVN----------------------------------- |
|
783 |
// Initialize hash table to fresh and clean for +VerifyOpto |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
238
diff
changeset
|
784 |
PhaseIterGVN::PhaseIterGVN( PhaseIterGVN *igvn, const char *dummy ) : PhaseGVN(igvn,dummy), _worklist( ), |
13312
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
785 |
_stack(C->unique() >> 1), |
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
238
diff
changeset
|
786 |
_delay_transform(false) { |
1 | 787 |
} |
788 |
||
789 |
//------------------------------PhaseIterGVN----------------------------------- |
|
790 |
// Initialize with previous PhaseIterGVN info; used by PhaseCCP |
|
791 |
PhaseIterGVN::PhaseIterGVN( PhaseIterGVN *igvn ) : PhaseGVN(igvn), |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
238
diff
changeset
|
792 |
_worklist( igvn->_worklist ), |
13312
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
793 |
_stack( igvn->_stack ), |
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
238
diff
changeset
|
794 |
_delay_transform(igvn->_delay_transform) |
1 | 795 |
{ |
796 |
} |
|
797 |
||
798 |
//------------------------------PhaseIterGVN----------------------------------- |
|
799 |
// Initialize with previous PhaseGVN info from Parser |
|
800 |
PhaseIterGVN::PhaseIterGVN( PhaseGVN *gvn ) : PhaseGVN(gvn), |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
238
diff
changeset
|
801 |
_worklist(*C->for_igvn()), |
13312
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
802 |
_stack(C->unique() >> 1), |
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
238
diff
changeset
|
803 |
_delay_transform(false) |
1 | 804 |
{ |
805 |
uint max; |
|
806 |
||
807 |
// Dead nodes in the hash table inherited from GVN were not treated as |
|
808 |
// roots during def-use info creation; hence they represent an invisible |
|
809 |
// use. Clear them out. |
|
810 |
max = _table.size(); |
|
811 |
for( uint i = 0; i < max; ++i ) { |
|
812 |
Node *n = _table.at(i); |
|
813 |
if(n != NULL && n != _table.sentinel() && n->outcnt() == 0) { |
|
814 |
if( n->is_top() ) continue; |
|
815 |
assert( false, "Parse::remove_useless_nodes missed this node"); |
|
816 |
hash_delete(n); |
|
817 |
} |
|
818 |
} |
|
819 |
||
820 |
// Any Phis or Regions on the worklist probably had uses that could not |
|
821 |
// make more progress because the uses were made while the Phis and Regions |
|
822 |
// were in half-built states. Put all uses of Phis and Regions on worklist. |
|
823 |
max = _worklist.size(); |
|
824 |
for( uint j = 0; j < max; j++ ) { |
|
825 |
Node *n = _worklist.at(j); |
|
826 |
uint uop = n->Opcode(); |
|
827 |
if( uop == Op_Phi || uop == Op_Region || |
|
828 |
n->is_Type() || |
|
829 |
n->is_Mem() ) |
|
830 |
add_users_to_worklist(n); |
|
831 |
} |
|
832 |
} |
|
833 |
||
24015 | 834 |
/** |
835 |
* Initialize worklist for each node. |
|
836 |
*/ |
|
837 |
void PhaseIterGVN::init_worklist(Node* first) { |
|
838 |
Unique_Node_List to_process; |
|
839 |
to_process.push(first); |
|
840 |
||
841 |
while (to_process.size() > 0) { |
|
842 |
Node* n = to_process.pop(); |
|
843 |
if (!_worklist.member(n)) { |
|
844 |
_worklist.push(n); |
|
845 |
||
846 |
uint cnt = n->req(); |
|
847 |
for(uint i = 0; i < cnt; i++) { |
|
848 |
Node* m = n->in(i); |
|
849 |
if (m != NULL) { |
|
850 |
to_process.push(m); |
|
851 |
} |
|
852 |
} |
|
853 |
} |
|
854 |
} |
|
855 |
} |
|
1 | 856 |
|
857 |
#ifndef PRODUCT |
|
858 |
void PhaseIterGVN::verify_step(Node* n) { |
|
24015 | 859 |
if (VerifyIterativeGVN) { |
860 |
_verify_window[_verify_counter % _verify_window_size] = n; |
|
861 |
++_verify_counter; |
|
862 |
ResourceMark rm; |
|
863 |
ResourceArea* area = Thread::current()->resource_area(); |
|
864 |
VectorSet old_space(area), new_space(area); |
|
865 |
if (C->unique() < 1000 || |
|
866 |
0 == _verify_counter % (C->unique() < 10000 ? 10 : 100)) { |
|
867 |
++_verify_full_passes; |
|
868 |
Node::verify_recur(C->root(), -1, old_space, new_space); |
|
1 | 869 |
} |
24015 | 870 |
const int verify_depth = 4; |
871 |
for ( int i = 0; i < _verify_window_size; i++ ) { |
|
872 |
Node* n = _verify_window[i]; |
|
873 |
if ( n == NULL ) continue; |
|
874 |
if( n->in(0) == NodeSentinel ) { // xform_idom |
|
875 |
_verify_window[i] = n->in(1); |
|
876 |
--i; continue; |
|
877 |
} |
|
878 |
// Typical fanout is 1-2, so this call visits about 6 nodes. |
|
879 |
Node::verify_recur(n, verify_depth, old_space, new_space); |
|
880 |
} |
|
1 | 881 |
} |
882 |
} |
|
883 |
||
24015 | 884 |
void PhaseIterGVN::trace_PhaseIterGVN(Node* n, Node* nn, const Type* oldtype) { |
885 |
if (TraceIterativeGVN) { |
|
886 |
uint wlsize = _worklist.size(); |
|
887 |
const Type* newtype = type_or_null(n); |
|
888 |
if (nn != n) { |
|
889 |
// print old node |
|
890 |
tty->print("< "); |
|
891 |
if (oldtype != newtype && oldtype != NULL) { |
|
892 |
oldtype->dump(); |
|
893 |
} |
|
894 |
do { tty->print("\t"); } while (tty->position() < 16); |
|
895 |
tty->print("<"); |
|
896 |
n->dump(); |
|
897 |
} |
|
898 |
if (oldtype != newtype || nn != n) { |
|
899 |
// print new node and/or new type |
|
900 |
if (oldtype == NULL) { |
|
901 |
tty->print("* "); |
|
902 |
} else if (nn != n) { |
|
903 |
tty->print("> "); |
|
904 |
} else { |
|
905 |
tty->print("= "); |
|
906 |
} |
|
907 |
if (newtype == NULL) { |
|
908 |
tty->print("null"); |
|
909 |
} else { |
|
910 |
newtype->dump(); |
|
911 |
} |
|
912 |
do { tty->print("\t"); } while (tty->position() < 16); |
|
913 |
nn->dump(); |
|
914 |
} |
|
915 |
if (Verbose && wlsize < _worklist.size()) { |
|
916 |
tty->print(" Push {"); |
|
917 |
while (wlsize != _worklist.size()) { |
|
918 |
Node* pushed = _worklist.at(wlsize++); |
|
919 |
tty->print(" %d", pushed->_idx); |
|
920 |
} |
|
921 |
tty->print_cr(" }"); |
|
922 |
} |
|
923 |
if (nn != n) { |
|
924 |
// ignore n, it might be subsumed |
|
925 |
verify_step((Node*) NULL); |
|
1 | 926 |
} |
927 |
} |
|
24015 | 928 |
} |
1 | 929 |
|
24015 | 930 |
void PhaseIterGVN::init_verifyPhaseIterGVN() { |
931 |
_verify_counter = 0; |
|
932 |
_verify_full_passes = 0; |
|
933 |
for (int i = 0; i < _verify_window_size; i++) { |
|
934 |
_verify_window[i] = NULL; |
|
1 | 935 |
} |
24015 | 936 |
} |
1 | 937 |
|
24015 | 938 |
void PhaseIterGVN::verify_PhaseIterGVN() { |
1 | 939 |
C->verify_graph_edges(); |
940 |
if( VerifyOpto && allow_progress() ) { |
|
941 |
// Must turn off allow_progress to enable assert and break recursion |
|
942 |
C->root()->verify(); |
|
943 |
{ // Check if any progress was missed using IterGVN |
|
944 |
// Def-Use info enables transformations not attempted in wash-pass |
|
945 |
// e.g. Region/Phi cleanup, ... |
|
946 |
// Null-check elision -- may not have reached fixpoint |
|
947 |
// do not propagate to dominated nodes |
|
948 |
ResourceMark rm; |
|
949 |
PhaseIterGVN igvn2(this,"Verify"); // Fresh and clean! |
|
950 |
// Fill worklist completely |
|
951 |
igvn2.init_worklist(C->root()); |
|
952 |
||
953 |
igvn2.set_allow_progress(false); |
|
954 |
igvn2.optimize(); |
|
955 |
igvn2.set_allow_progress(true); |
|
956 |
} |
|
957 |
} |
|
24015 | 958 |
if (VerifyIterativeGVN && PrintOpto) { |
959 |
if (_verify_counter == _verify_full_passes) { |
|
1 | 960 |
tty->print_cr("VerifyIterativeGVN: %d transforms and verify passes", |
961 |
_verify_full_passes); |
|
24015 | 962 |
} else { |
1 | 963 |
tty->print_cr("VerifyIterativeGVN: %d transforms, %d full verify passes", |
964 |
_verify_counter, _verify_full_passes); |
|
24015 | 965 |
} |
1 | 966 |
} |
24015 | 967 |
} |
968 |
#endif /* PRODUCT */ |
|
969 |
||
970 |
#ifdef ASSERT |
|
971 |
/** |
|
972 |
* Dumps information that can help to debug the problem. A debug |
|
973 |
* build fails with an assert. |
|
974 |
*/ |
|
975 |
void PhaseIterGVN::dump_infinite_loop_info(Node* n) { |
|
976 |
n->dump(4); |
|
977 |
_worklist.dump(); |
|
978 |
assert(false, "infinite loop in PhaseIterGVN::optimize"); |
|
979 |
} |
|
980 |
||
981 |
/** |
|
982 |
* Prints out information about IGVN if the 'verbose' option is used. |
|
983 |
*/ |
|
984 |
void PhaseIterGVN::trace_PhaseIterGVN_verbose(Node* n, int num_processed) { |
|
985 |
if (TraceIterativeGVN && Verbose) { |
|
986 |
tty->print(" Pop "); |
|
987 |
n->dump(); |
|
988 |
if ((num_processed % 100) == 0) { |
|
989 |
_worklist.print_set(); |
|
990 |
} |
|
991 |
} |
|
992 |
} |
|
993 |
#endif /* ASSERT */ |
|
994 |
||
995 |
void PhaseIterGVN::optimize() { |
|
996 |
DEBUG_ONLY(uint num_processed = 0;) |
|
997 |
NOT_PRODUCT(init_verifyPhaseIterGVN();) |
|
998 |
||
999 |
uint loop_count = 0; |
|
1000 |
// Pull from worklist and transform the node. If the node has changed, |
|
1001 |
// update edge info and put uses on worklist. |
|
1002 |
while(_worklist.size()) { |
|
1003 |
if (C->check_node_count(NodeLimitFudgeFactor * 2, "Out of nodes")) { |
|
1004 |
return; |
|
1005 |
} |
|
1006 |
Node* n = _worklist.pop(); |
|
1007 |
if (++loop_count >= K * C->live_nodes()) { |
|
1008 |
DEBUG_ONLY(dump_infinite_loop_info(n);) |
|
1009 |
C->record_method_not_compilable("infinite loop in PhaseIterGVN::optimize"); |
|
1010 |
return; |
|
1011 |
} |
|
1012 |
DEBUG_ONLY(trace_PhaseIterGVN_verbose(n, num_processed++);) |
|
1013 |
if (n->outcnt() != 0) { |
|
1014 |
NOT_PRODUCT(const Type* oldtype = type_or_null(n)); |
|
1015 |
// Do the transformation |
|
1016 |
Node* nn = transform_old(n); |
|
1017 |
NOT_PRODUCT(trace_PhaseIterGVN(n, nn, oldtype);) |
|
1018 |
} else if (!n->is_top()) { |
|
1019 |
remove_dead_node(n); |
|
1020 |
} |
|
1021 |
} |
|
1022 |
NOT_PRODUCT(verify_PhaseIterGVN();) |
|
1 | 1023 |
} |
1024 |
||
1025 |
||
24015 | 1026 |
/** |
1027 |
* Register a new node with the optimizer. Update the types array, the def-use |
|
1028 |
* info. Put on worklist. |
|
1029 |
*/ |
|
1 | 1030 |
Node* PhaseIterGVN::register_new_node_with_optimizer(Node* n, Node* orig) { |
1031 |
set_type_bottom(n); |
|
1032 |
_worklist.push(n); |
|
1033 |
if (orig != NULL) C->copy_node_notes_to(n, orig); |
|
1034 |
return n; |
|
1035 |
} |
|
1036 |
||
1037 |
//------------------------------transform-------------------------------------- |
|
1038 |
// Non-recursive: idealize Node 'n' with respect to its inputs and its value |
|
1039 |
Node *PhaseIterGVN::transform( Node *n ) { |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
238
diff
changeset
|
1040 |
if (_delay_transform) { |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
238
diff
changeset
|
1041 |
// Register the node but don't optimize for now |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
238
diff
changeset
|
1042 |
register_new_node_with_optimizer(n); |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
238
diff
changeset
|
1043 |
return n; |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
238
diff
changeset
|
1044 |
} |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
238
diff
changeset
|
1045 |
|
1 | 1046 |
// If brand new node, make space in type array, and give it a type. |
1047 |
ensure_type_or_null(n); |
|
1048 |
if (type_or_null(n) == NULL) { |
|
1049 |
set_type_bottom(n); |
|
1050 |
} |
|
1051 |
||
1052 |
return transform_old(n); |
|
1053 |
} |
|
1054 |
||
24015 | 1055 |
Node *PhaseIterGVN::transform_old(Node* n) { |
1056 |
DEBUG_ONLY(uint loop_count = 0;); |
|
1057 |
NOT_PRODUCT(set_transforms()); |
|
1058 |
||
1 | 1059 |
// Remove 'n' from hash table in case it gets modified |
1060 |
_table.hash_delete(n); |
|
24015 | 1061 |
if (VerifyIterativeGVN) { |
1062 |
assert(!_table.find_index(n->_idx), "found duplicate entry in table"); |
|
1 | 1063 |
} |
1064 |
||
1065 |
// Apply the Ideal call in a loop until it no longer applies |
|
24015 | 1066 |
Node* k = n; |
1 | 1067 |
DEBUG_ONLY(dead_loop_check(k);) |
1067 | 1068 |
DEBUG_ONLY(bool is_new = (k->outcnt() == 0);) |
24015 | 1069 |
Node* i = k->Ideal(this, /*can_reshape=*/true); |
1067 | 1070 |
assert(i != k || is_new || i->outcnt() > 0, "don't return dead nodes"); |
1 | 1071 |
#ifndef PRODUCT |
24015 | 1072 |
verify_step(k); |
1073 |
if (i && VerifyOpto ) { |
|
1074 |
if (!allow_progress()) { |
|
1075 |
if (i->is_Add() && (i->outcnt() == 1)) { |
|
1 | 1076 |
// Switched input to left side because this is the only use |
24015 | 1077 |
} else if (i->is_If() && (i->in(0) == NULL)) { |
1 | 1078 |
// This IF is dead because it is dominated by an equivalent IF When |
1079 |
// dominating if changed, info is not propagated sparsely to 'this' |
|
1080 |
// Propagating this info further will spuriously identify other |
|
1081 |
// progress. |
|
1082 |
return i; |
|
1083 |
} else |
|
1084 |
set_progress(); |
|
24015 | 1085 |
} else { |
1 | 1086 |
set_progress(); |
24015 | 1087 |
} |
1 | 1088 |
} |
1089 |
#endif |
|
1090 |
||
24015 | 1091 |
while (i != NULL) { |
1 | 1092 |
#ifndef PRODUCT |
24015 | 1093 |
if (loop_count >= K) { |
1094 |
dump_infinite_loop_info(i); |
|
1095 |
} |
|
1096 |
loop_count++; |
|
1 | 1097 |
#endif |
1098 |
assert((i->_idx >= k->_idx) || i->is_top(), "Idealize should return new nodes, use Identity to return old nodes"); |
|
1099 |
// Made a change; put users of original Node on worklist |
|
24015 | 1100 |
add_users_to_worklist(k); |
1 | 1101 |
// Replacing root of transform tree? |
24015 | 1102 |
if (k != i) { |
1 | 1103 |
// Make users of old Node now use new. |
24015 | 1104 |
subsume_node(k, i); |
1 | 1105 |
k = i; |
1106 |
} |
|
1107 |
DEBUG_ONLY(dead_loop_check(k);) |
|
1108 |
// Try idealizing again |
|
1067 | 1109 |
DEBUG_ONLY(is_new = (k->outcnt() == 0);) |
1 | 1110 |
i = k->Ideal(this, /*can_reshape=*/true); |
24015 | 1111 |
assert(i != k || is_new || (i->outcnt() > 0), "don't return dead nodes"); |
1 | 1112 |
#ifndef PRODUCT |
24015 | 1113 |
verify_step(k); |
1114 |
if (i && VerifyOpto) { |
|
1115 |
set_progress(); |
|
1116 |
} |
|
1 | 1117 |
#endif |
1118 |
} |
|
1119 |
||
1120 |
// If brand new node, make space in type array. |
|
1121 |
ensure_type_or_null(k); |
|
1122 |
||
1123 |
// See what kind of values 'k' takes on at runtime |
|
24015 | 1124 |
const Type* t = k->Value(this); |
1 | 1125 |
assert(t != NULL, "value sanity"); |
1126 |
||
1127 |
// Since I just called 'Value' to compute the set of run-time values |
|
1128 |
// for this Node, and 'Value' is non-local (and therefore expensive) I'll |
|
1129 |
// cache Value. Later requests for the local phase->type of this Node can |
|
1130 |
// use the cached Value instead of suffering with 'bottom_type'. |
|
24015 | 1131 |
if (type_or_null(k) != t) { |
1132 |
#ifndef PRODUCT |
|
1133 |
inc_new_values(); |
|
1134 |
set_progress(); |
|
1135 |
#endif |
|
1 | 1136 |
set_type(k, t); |
1137 |
// If k is a TypeNode, capture any more-precise type permanently into Node |
|
1138 |
k->raise_bottom_type(t); |
|
1139 |
// Move users of node to worklist |
|
24015 | 1140 |
add_users_to_worklist(k); |
1 | 1141 |
} |
1142 |
// If 'k' computes a constant, replace it with a constant |
|
24015 | 1143 |
if (t->singleton() && !k->is_Con()) { |
1144 |
NOT_PRODUCT(set_progress();) |
|
1145 |
Node* con = makecon(t); // Make a constant |
|
1146 |
add_users_to_worklist(k); |
|
1147 |
subsume_node(k, con); // Everybody using k now uses con |
|
1 | 1148 |
return con; |
1149 |
} |
|
1150 |
||
1151 |
// Now check for Identities |
|
24015 | 1152 |
i = k->Identity(this); // Look for a nearby replacement |
1153 |
if (i != k) { // Found? Return replacement! |
|
1154 |
NOT_PRODUCT(set_progress();) |
|
1155 |
add_users_to_worklist(k); |
|
1156 |
subsume_node(k, i); // Everybody using k now uses i |
|
1 | 1157 |
return i; |
1158 |
} |
|
1159 |
||
1160 |
// Global Value Numbering |
|
1161 |
i = hash_find_insert(k); // Check for pre-existing node |
|
24015 | 1162 |
if (i && (i != k)) { |
1 | 1163 |
// Return the pre-existing node if it isn't dead |
24015 | 1164 |
NOT_PRODUCT(set_progress();) |
1165 |
add_users_to_worklist(k); |
|
1166 |
subsume_node(k, i); // Everybody using k now uses i |
|
1 | 1167 |
return i; |
1168 |
} |
|
1169 |
||
1170 |
// Return Idealized original |
|
1171 |
return k; |
|
1172 |
} |
|
1173 |
||
1174 |
//---------------------------------saturate------------------------------------ |
|
1175 |
const Type* PhaseIterGVN::saturate(const Type* new_type, const Type* old_type, |
|
1176 |
const Type* limit_type) const { |
|
1177 |
return new_type->narrow(old_type); |
|
1178 |
} |
|
1179 |
||
1180 |
//------------------------------remove_globally_dead_node---------------------- |
|
1181 |
// Kill a globally dead Node. All uses are also globally dead and are |
|
1182 |
// aggressively trimmed. |
|
1183 |
void PhaseIterGVN::remove_globally_dead_node( Node *dead ) { |
|
13312
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1184 |
enum DeleteProgress { |
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1185 |
PROCESS_INPUTS, |
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1186 |
PROCESS_OUTPUTS |
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1187 |
}; |
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1188 |
assert(_stack.is_empty(), "not empty"); |
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1189 |
_stack.push(dead, PROCESS_INPUTS); |
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1190 |
|
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1191 |
while (_stack.is_nonempty()) { |
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1192 |
dead = _stack.node(); |
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1193 |
uint progress_state = _stack.index(); |
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1194 |
assert(dead != C->root(), "killing root, eh?"); |
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1195 |
assert(!dead->is_top(), "add check for top when pushing"); |
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1196 |
NOT_PRODUCT( set_progress(); ) |
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1197 |
if (progress_state == PROCESS_INPUTS) { |
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1198 |
// After following inputs, continue to outputs |
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1199 |
_stack.set_index(PROCESS_OUTPUTS); |
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1200 |
if (!dead->is_Con()) { // Don't kill cons but uses |
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1201 |
bool recurse = false; |
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1202 |
// Remove from hash table |
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1203 |
_table.hash_delete( dead ); |
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1204 |
// Smash all inputs to 'dead', isolating him completely |
16619
a0e531dcc9e9
8004640: C2 assert failure in memnode.cpp: NULL+offs not RAW address
kvn
parents:
15813
diff
changeset
|
1205 |
for (uint i = 0; i < dead->req(); i++) { |
13312
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1206 |
Node *in = dead->in(i); |
16619
a0e531dcc9e9
8004640: C2 assert failure in memnode.cpp: NULL+offs not RAW address
kvn
parents:
15813
diff
changeset
|
1207 |
if (in != NULL && in != C->top()) { // Points to something? |
a0e531dcc9e9
8004640: C2 assert failure in memnode.cpp: NULL+offs not RAW address
kvn
parents:
15813
diff
changeset
|
1208 |
int nrep = dead->replace_edge(in, NULL); // Kill edges |
a0e531dcc9e9
8004640: C2 assert failure in memnode.cpp: NULL+offs not RAW address
kvn
parents:
15813
diff
changeset
|
1209 |
assert((nrep > 0), "sanity"); |
a0e531dcc9e9
8004640: C2 assert failure in memnode.cpp: NULL+offs not RAW address
kvn
parents:
15813
diff
changeset
|
1210 |
if (in->outcnt() == 0) { // Made input go dead? |
13312
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1211 |
_stack.push(in, PROCESS_INPUTS); // Recursively remove |
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1212 |
recurse = true; |
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1213 |
} else if (in->outcnt() == 1 && |
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1214 |
in->has_special_unique_user()) { |
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1215 |
_worklist.push(in->unique_out()); |
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1216 |
} else if (in->outcnt() <= 2 && dead->is_Phi()) { |
16619
a0e531dcc9e9
8004640: C2 assert failure in memnode.cpp: NULL+offs not RAW address
kvn
parents:
15813
diff
changeset
|
1217 |
if (in->Opcode() == Op_Region) { |
13312
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1218 |
_worklist.push(in); |
16619
a0e531dcc9e9
8004640: C2 assert failure in memnode.cpp: NULL+offs not RAW address
kvn
parents:
15813
diff
changeset
|
1219 |
} else if (in->is_Store()) { |
13312
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1220 |
DUIterator_Fast imax, i = in->fast_outs(imax); |
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1221 |
_worklist.push(in->fast_out(i)); |
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1222 |
i++; |
16619
a0e531dcc9e9
8004640: C2 assert failure in memnode.cpp: NULL+offs not RAW address
kvn
parents:
15813
diff
changeset
|
1223 |
if (in->outcnt() == 2) { |
13312
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1224 |
_worklist.push(in->fast_out(i)); |
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1225 |
i++; |
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1226 |
} |
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1227 |
assert(!(i < imax), "sanity"); |
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1228 |
} |
1 | 1229 |
} |
15813
6efd4c793e47
8007294: ReduceFieldZeroing doesn't check for dependent load and can lead to incorrect execution
roland
parents:
15618
diff
changeset
|
1230 |
if (ReduceFieldZeroing && dead->is_Load() && i == MemNode::Memory && |
6efd4c793e47
8007294: ReduceFieldZeroing doesn't check for dependent load and can lead to incorrect execution
roland
parents:
15618
diff
changeset
|
1231 |
in->is_Proj() && in->in(0) != NULL && in->in(0)->is_Initialize()) { |
6efd4c793e47
8007294: ReduceFieldZeroing doesn't check for dependent load and can lead to incorrect execution
roland
parents:
15618
diff
changeset
|
1232 |
// A Load that directly follows an InitializeNode is |
6efd4c793e47
8007294: ReduceFieldZeroing doesn't check for dependent load and can lead to incorrect execution
roland
parents:
15618
diff
changeset
|
1233 |
// going away. The Stores that follow are candidates |
6efd4c793e47
8007294: ReduceFieldZeroing doesn't check for dependent load and can lead to incorrect execution
roland
parents:
15618
diff
changeset
|
1234 |
// again to be captured by the InitializeNode. |
6efd4c793e47
8007294: ReduceFieldZeroing doesn't check for dependent load and can lead to incorrect execution
roland
parents:
15618
diff
changeset
|
1235 |
for (DUIterator_Fast jmax, j = in->fast_outs(jmax); j < jmax; j++) { |
6efd4c793e47
8007294: ReduceFieldZeroing doesn't check for dependent load and can lead to incorrect execution
roland
parents:
15618
diff
changeset
|
1236 |
Node *n = in->fast_out(j); |
6efd4c793e47
8007294: ReduceFieldZeroing doesn't check for dependent load and can lead to incorrect execution
roland
parents:
15618
diff
changeset
|
1237 |
if (n->is_Store()) { |
6efd4c793e47
8007294: ReduceFieldZeroing doesn't check for dependent load and can lead to incorrect execution
roland
parents:
15618
diff
changeset
|
1238 |
_worklist.push(n); |
6efd4c793e47
8007294: ReduceFieldZeroing doesn't check for dependent load and can lead to incorrect execution
roland
parents:
15618
diff
changeset
|
1239 |
} |
6efd4c793e47
8007294: ReduceFieldZeroing doesn't check for dependent load and can lead to incorrect execution
roland
parents:
15618
diff
changeset
|
1240 |
} |
6efd4c793e47
8007294: ReduceFieldZeroing doesn't check for dependent load and can lead to incorrect execution
roland
parents:
15618
diff
changeset
|
1241 |
} |
16619
a0e531dcc9e9
8004640: C2 assert failure in memnode.cpp: NULL+offs not RAW address
kvn
parents:
15813
diff
changeset
|
1242 |
} // if (in != NULL && in != C->top()) |
a0e531dcc9e9
8004640: C2 assert failure in memnode.cpp: NULL+offs not RAW address
kvn
parents:
15813
diff
changeset
|
1243 |
} // for (uint i = 0; i < dead->req(); i++) |
13312
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1244 |
if (recurse) { |
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1245 |
continue; |
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1246 |
} |
16619
a0e531dcc9e9
8004640: C2 assert failure in memnode.cpp: NULL+offs not RAW address
kvn
parents:
15813
diff
changeset
|
1247 |
} // if (!dead->is_Con()) |
a0e531dcc9e9
8004640: C2 assert failure in memnode.cpp: NULL+offs not RAW address
kvn
parents:
15813
diff
changeset
|
1248 |
} // if (progress_state == PROCESS_INPUTS) |
1 | 1249 |
|
13312
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1250 |
// Aggressively kill globally dead uses |
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1251 |
// (Rather than pushing all the outs at once, we push one at a time, |
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1252 |
// plus the parent to resume later, because of the indefinite number |
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1253 |
// of edge deletions per loop trip.) |
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1254 |
if (dead->outcnt() > 0) { |
16619
a0e531dcc9e9
8004640: C2 assert failure in memnode.cpp: NULL+offs not RAW address
kvn
parents:
15813
diff
changeset
|
1255 |
// Recursively remove output edges |
13312
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1256 |
_stack.push(dead->raw_out(0), PROCESS_INPUTS); |
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1257 |
} else { |
16619
a0e531dcc9e9
8004640: C2 assert failure in memnode.cpp: NULL+offs not RAW address
kvn
parents:
15813
diff
changeset
|
1258 |
// Finished disconnecting all input and output edges. |
13312
a8e45429e01e
7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents:
10988
diff
changeset
|
1259 |
_stack.pop(); |
16619
a0e531dcc9e9
8004640: C2 assert failure in memnode.cpp: NULL+offs not RAW address
kvn
parents:
15813
diff
changeset
|
1260 |
// Remove dead node from iterative worklist |
a0e531dcc9e9
8004640: C2 assert failure in memnode.cpp: NULL+offs not RAW address
kvn
parents:
15813
diff
changeset
|
1261 |
_worklist.remove(dead); |
a0e531dcc9e9
8004640: C2 assert failure in memnode.cpp: NULL+offs not RAW address
kvn
parents:
15813
diff
changeset
|
1262 |
// Constant node that has no out-edges and has only one in-edge from |
a0e531dcc9e9
8004640: C2 assert failure in memnode.cpp: NULL+offs not RAW address
kvn
parents:
15813
diff
changeset
|
1263 |
// root is usually dead. However, sometimes reshaping walk makes |
a0e531dcc9e9
8004640: C2 assert failure in memnode.cpp: NULL+offs not RAW address
kvn
parents:
15813
diff
changeset
|
1264 |
// it reachable by adding use edges. So, we will NOT count Con nodes |
a0e531dcc9e9
8004640: C2 assert failure in memnode.cpp: NULL+offs not RAW address
kvn
parents:
15813
diff
changeset
|
1265 |
// as dead to be conservative about the dead node count at any |
a0e531dcc9e9
8004640: C2 assert failure in memnode.cpp: NULL+offs not RAW address
kvn
parents:
15813
diff
changeset
|
1266 |
// given time. |
a0e531dcc9e9
8004640: C2 assert failure in memnode.cpp: NULL+offs not RAW address
kvn
parents:
15813
diff
changeset
|
1267 |
if (!dead->is_Con()) { |
a0e531dcc9e9
8004640: C2 assert failure in memnode.cpp: NULL+offs not RAW address
kvn
parents:
15813
diff
changeset
|
1268 |
C->record_dead_node(dead->_idx); |
a0e531dcc9e9
8004640: C2 assert failure in memnode.cpp: NULL+offs not RAW address
kvn
parents:
15813
diff
changeset
|
1269 |
} |
a0e531dcc9e9
8004640: C2 assert failure in memnode.cpp: NULL+offs not RAW address
kvn
parents:
15813
diff
changeset
|
1270 |
if (dead->is_macro()) { |
a0e531dcc9e9
8004640: C2 assert failure in memnode.cpp: NULL+offs not RAW address
kvn
parents:
15813
diff
changeset
|
1271 |
C->remove_macro_node(dead); |
a0e531dcc9e9
8004640: C2 assert failure in memnode.cpp: NULL+offs not RAW address
kvn
parents:
15813
diff
changeset
|
1272 |
} |
a0e531dcc9e9
8004640: C2 assert failure in memnode.cpp: NULL+offs not RAW address
kvn
parents:
15813
diff
changeset
|
1273 |
if (dead->is_expensive()) { |
a0e531dcc9e9
8004640: C2 assert failure in memnode.cpp: NULL+offs not RAW address
kvn
parents:
15813
diff
changeset
|
1274 |
C->remove_expensive_node(dead); |
a0e531dcc9e9
8004640: C2 assert failure in memnode.cpp: NULL+offs not RAW address
kvn
parents:
15813
diff
changeset
|
1275 |
} |
1 | 1276 |
} |
16619
a0e531dcc9e9
8004640: C2 assert failure in memnode.cpp: NULL+offs not RAW address
kvn
parents:
15813
diff
changeset
|
1277 |
} // while (_stack.is_nonempty()) |
1 | 1278 |
} |
1279 |
||
1280 |
//------------------------------subsume_node----------------------------------- |
|
1281 |
// Remove users from node 'old' and add them to node 'nn'. |
|
1282 |
void PhaseIterGVN::subsume_node( Node *old, Node *nn ) { |
|
1283 |
assert( old != hash_find(old), "should already been removed" ); |
|
1284 |
assert( old != C->top(), "cannot subsume top node"); |
|
1285 |
// Copy debug or profile information to the new version: |
|
1286 |
C->copy_node_notes_to(nn, old); |
|
1287 |
// Move users of node 'old' to node 'nn' |
|
1288 |
for (DUIterator_Last imin, i = old->last_outs(imin); i >= imin; ) { |
|
1289 |
Node* use = old->last_out(i); // for each use... |
|
1290 |
// use might need re-hashing (but it won't if it's a new node) |
|
1291 |
bool is_in_table = _table.hash_delete( use ); |
|
1292 |
// Update use-def info as well |
|
1293 |
// We remove all occurrences of old within use->in, |
|
1294 |
// so as to avoid rehashing any node more than once. |
|
1295 |
// The hash table probe swamps any outer loop overhead. |
|
1296 |
uint num_edges = 0; |
|
1297 |
for (uint jmax = use->len(), j = 0; j < jmax; j++) { |
|
1298 |
if (use->in(j) == old) { |
|
1299 |
use->set_req(j, nn); |
|
1300 |
++num_edges; |
|
1301 |
} |
|
1302 |
} |
|
1303 |
// Insert into GVN hash table if unique |
|
1304 |
// If a duplicate, 'use' will be cleaned up when pulled off worklist |
|
1305 |
if( is_in_table ) { |
|
1306 |
hash_find_insert(use); |
|
1307 |
} |
|
1308 |
i -= num_edges; // we deleted 1 or more copies of this edge |
|
1309 |
} |
|
1310 |
||
1311 |
// Smash all inputs to 'old', isolating him completely |
|
13895
f6dfe4123709
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
13312
diff
changeset
|
1312 |
Node *temp = new (C) Node(1); |
1 | 1313 |
temp->init_req(0,nn); // Add a use to nn to prevent him from dying |
1314 |
remove_dead_node( old ); |
|
1315 |
temp->del_req(0); // Yank bogus edge |
|
1316 |
#ifndef PRODUCT |
|
1317 |
if( VerifyIterativeGVN ) { |
|
1318 |
for ( int i = 0; i < _verify_window_size; i++ ) { |
|
1319 |
if ( _verify_window[i] == old ) |
|
1320 |
_verify_window[i] = nn; |
|
1321 |
} |
|
1322 |
} |
|
1323 |
#endif |
|
1324 |
_worklist.remove(temp); // this can be necessary |
|
1325 |
temp->destruct(); // reuse the _idx of this little guy |
|
1326 |
} |
|
1327 |
||
1328 |
//------------------------------add_users_to_worklist-------------------------- |
|
1329 |
void PhaseIterGVN::add_users_to_worklist0( Node *n ) { |
|
1330 |
for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) { |
|
1331 |
_worklist.push(n->fast_out(i)); // Push on worklist |
|
1332 |
} |
|
1333 |
} |
|
1334 |
||
1335 |
void PhaseIterGVN::add_users_to_worklist( Node *n ) { |
|
1336 |
add_users_to_worklist0(n); |
|
1337 |
||
1338 |
// Move users of node to worklist |
|
1339 |
for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) { |
|
1340 |
Node* use = n->fast_out(i); // Get use |
|
1341 |
||
1342 |
if( use->is_Multi() || // Multi-definer? Push projs on worklist |
|
1343 |
use->is_Store() ) // Enable store/load same address |
|
1344 |
add_users_to_worklist0(use); |
|
1345 |
||
1346 |
// If we changed the receiver type to a call, we need to revisit |
|
1347 |
// the Catch following the call. It's looking for a non-NULL |
|
1348 |
// receiver to know when to enable the regular fall-through path |
|
1349 |
// in addition to the NullPtrException path. |
|
1350 |
if (use->is_CallDynamicJava() && n == use->in(TypeFunc::Parms)) { |
|
1351 |
Node* p = use->as_CallDynamicJava()->proj_out(TypeFunc::Control); |
|
1352 |
if (p != NULL) { |
|
1353 |
add_users_to_worklist0(p); |
|
1354 |
} |
|
1355 |
} |
|
1356 |
||
1357 |
if( use->is_Cmp() ) { // Enable CMP/BOOL optimization |
|
1358 |
add_users_to_worklist(use); // Put Bool on worklist |
|
1359 |
// Look for the 'is_x2logic' pattern: "x ? : 0 : 1" and put the |
|
1360 |
// phi merging either 0 or 1 onto the worklist |
|
1361 |
if (use->outcnt() > 0) { |
|
1362 |
Node* bol = use->raw_out(0); |
|
1363 |
if (bol->outcnt() > 0) { |
|
1364 |
Node* iff = bol->raw_out(0); |
|
1365 |
if (iff->outcnt() == 2) { |
|
1366 |
Node* ifproj0 = iff->raw_out(0); |
|
1367 |
Node* ifproj1 = iff->raw_out(1); |
|
1368 |
if (ifproj0->outcnt() > 0 && ifproj1->outcnt() > 0) { |
|
1369 |
Node* region0 = ifproj0->raw_out(0); |
|
1370 |
Node* region1 = ifproj1->raw_out(0); |
|
1371 |
if( region0 == region1 ) |
|
1372 |
add_users_to_worklist0(region0); |
|
1373 |
} |
|
1374 |
} |
|
1375 |
} |
|
1376 |
} |
|
1377 |
} |
|
1378 |
||
1379 |
uint use_op = use->Opcode(); |
|
1380 |
// If changed Cast input, check Phi users for simple cycles |
|
238
803c80713999
6674588: (Escape Analysis) Improve Escape Analysis code
kvn
parents:
214
diff
changeset
|
1381 |
if( use->is_ConstraintCast() || use->is_CheckCastPP() ) { |
1 | 1382 |
for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) { |
1383 |
Node* u = use->fast_out(i2); |
|
1384 |
if (u->is_Phi()) |
|
1385 |
_worklist.push(u); |
|
1386 |
} |
|
1387 |
} |
|
1388 |
// If changed LShift inputs, check RShift users for useless sign-ext |
|
1389 |
if( use_op == Op_LShiftI ) { |
|
1390 |
for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) { |
|
1391 |
Node* u = use->fast_out(i2); |
|
1392 |
if (u->Opcode() == Op_RShiftI) |
|
1393 |
_worklist.push(u); |
|
1394 |
} |
|
1395 |
} |
|
1396 |
// If changed AddP inputs, check Stores for loop invariant |
|
1397 |
if( use_op == Op_AddP ) { |
|
1398 |
for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) { |
|
1399 |
Node* u = use->fast_out(i2); |
|
1400 |
if (u->is_Mem()) |
|
1401 |
_worklist.push(u); |
|
1402 |
} |
|
1403 |
} |
|
1404 |
// If changed initialization activity, check dependent Stores |
|
1405 |
if (use_op == Op_Allocate || use_op == Op_AllocateArray) { |
|
1406 |
InitializeNode* init = use->as_Allocate()->initialization(); |
|
1407 |
if (init != NULL) { |
|
1408 |
Node* imem = init->proj_out(TypeFunc::Memory); |
|
1409 |
if (imem != NULL) add_users_to_worklist0(imem); |
|
1410 |
} |
|
1411 |
} |
|
1412 |
if (use_op == Op_Initialize) { |
|
1413 |
Node* imem = use->as_Initialize()->proj_out(TypeFunc::Memory); |
|
1414 |
if (imem != NULL) add_users_to_worklist0(imem); |
|
1415 |
} |
|
1416 |
} |
|
1417 |
} |
|
1418 |
||
21099 | 1419 |
/** |
1420 |
* Remove the speculative part of all types that we know of |
|
1421 |
*/ |
|
1422 |
void PhaseIterGVN::remove_speculative_types() { |
|
1423 |
assert(UseTypeSpeculation, "speculation is off"); |
|
1424 |
for (uint i = 0; i < _types.Size(); i++) { |
|
1425 |
const Type* t = _types.fast_lookup(i); |
|
22799
83e58bac7980
8027422: assert(_gvn.type(obj)->higher_equal(tjp)) failed: cast_up is no longer needed
roland
parents:
22234
diff
changeset
|
1426 |
if (t != NULL) { |
83e58bac7980
8027422: assert(_gvn.type(obj)->higher_equal(tjp)) failed: cast_up is no longer needed
roland
parents:
22234
diff
changeset
|
1427 |
_types.map(i, t->remove_speculative()); |
21099 | 1428 |
} |
1429 |
} |
|
22799
83e58bac7980
8027422: assert(_gvn.type(obj)->higher_equal(tjp)) failed: cast_up is no longer needed
roland
parents:
22234
diff
changeset
|
1430 |
_table.check_no_speculative_types(); |
21099 | 1431 |
} |
1432 |
||
1 | 1433 |
//============================================================================= |
1434 |
#ifndef PRODUCT |
|
1435 |
uint PhaseCCP::_total_invokes = 0; |
|
1436 |
uint PhaseCCP::_total_constants = 0; |
|
1437 |
#endif |
|
1438 |
//------------------------------PhaseCCP--------------------------------------- |
|
1439 |
// Conditional Constant Propagation, ala Wegman & Zadeck |
|
1440 |
PhaseCCP::PhaseCCP( PhaseIterGVN *igvn ) : PhaseIterGVN(igvn) { |
|
1441 |
NOT_PRODUCT( clear_constants(); ) |
|
1442 |
assert( _worklist.size() == 0, "" ); |
|
1443 |
// Clear out _nodes from IterGVN. Must be clear to transform call. |
|
1444 |
_nodes.clear(); // Clear out from IterGVN |
|
1445 |
analyze(); |
|
1446 |
} |
|
1447 |
||
1448 |
#ifndef PRODUCT |
|
1449 |
//------------------------------~PhaseCCP-------------------------------------- |
|
1450 |
PhaseCCP::~PhaseCCP() { |
|
1451 |
inc_invokes(); |
|
1452 |
_total_constants += count_constants(); |
|
1453 |
} |
|
1454 |
#endif |
|
1455 |
||
1456 |
||
1457 |
#ifdef ASSERT |
|
1458 |
static bool ccp_type_widens(const Type* t, const Type* t0) { |
|
1459 |
assert(t->meet(t0) == t, "Not monotonic"); |
|
1460 |
switch (t->base() == t0->base() ? t->base() : Type::Top) { |
|
1461 |
case Type::Int: |
|
1462 |
assert(t0->isa_int()->_widen <= t->isa_int()->_widen, "widen increases"); |
|
1463 |
break; |
|
1464 |
case Type::Long: |
|
1465 |
assert(t0->isa_long()->_widen <= t->isa_long()->_widen, "widen increases"); |
|
1466 |
break; |
|
1467 |
} |
|
1468 |
return true; |
|
1469 |
} |
|
1470 |
#endif //ASSERT |
|
1471 |
||
1472 |
//------------------------------analyze---------------------------------------- |
|
1473 |
void PhaseCCP::analyze() { |
|
1474 |
// Initialize all types to TOP, optimistic analysis |
|
1475 |
for (int i = C->unique() - 1; i >= 0; i--) { |
|
1476 |
_types.map(i,Type::TOP); |
|
1477 |
} |
|
1478 |
||
1479 |
// Push root onto worklist |
|
1480 |
Unique_Node_List worklist; |
|
1481 |
worklist.push(C->root()); |
|
1482 |
||
1483 |
// Pull from worklist; compute new value; push changes out. |
|
1484 |
// This loop is the meat of CCP. |
|
1485 |
while( worklist.size() ) { |
|
1486 |
Node *n = worklist.pop(); |
|
1487 |
const Type *t = n->Value(this); |
|
1488 |
if (t != type(n)) { |
|
1489 |
assert(ccp_type_widens(t, type(n)), "ccp type must widen"); |
|
1490 |
#ifndef PRODUCT |
|
1491 |
if( TracePhaseCCP ) { |
|
1492 |
t->dump(); |
|
1493 |
do { tty->print("\t"); } while (tty->position() < 16); |
|
1494 |
n->dump(); |
|
1495 |
} |
|
1496 |
#endif |
|
1497 |
set_type(n, t); |
|
1498 |
for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) { |
|
1499 |
Node* m = n->fast_out(i); // Get user |
|
1500 |
if( m->is_Region() ) { // New path to Region? Must recheck Phis too |
|
1501 |
for (DUIterator_Fast i2max, i2 = m->fast_outs(i2max); i2 < i2max; i2++) { |
|
1502 |
Node* p = m->fast_out(i2); // Propagate changes to uses |
|
1503 |
if( p->bottom_type() != type(p) ) // If not already bottomed out |
|
1504 |
worklist.push(p); // Propagate change to user |
|
1505 |
} |
|
1506 |
} |
|
2131 | 1507 |
// If we changed the receiver type to a call, we need to revisit |
1 | 1508 |
// the Catch following the call. It's looking for a non-NULL |
1509 |
// receiver to know when to enable the regular fall-through path |
|
1510 |
// in addition to the NullPtrException path |
|
1511 |
if (m->is_Call()) { |
|
1512 |
for (DUIterator_Fast i2max, i2 = m->fast_outs(i2max); i2 < i2max; i2++) { |
|
1513 |
Node* p = m->fast_out(i2); // Propagate changes to uses |
|
1514 |
if (p->is_Proj() && p->as_Proj()->_con == TypeFunc::Control && p->outcnt() == 1) |
|
1515 |
worklist.push(p->unique_out()); |
|
1516 |
} |
|
1517 |
} |
|
1518 |
if( m->bottom_type() != type(m) ) // If not already bottomed out |
|
1519 |
worklist.push(m); // Propagate change to user |
|
1520 |
} |
|
1521 |
} |
|
1522 |
} |
|
1523 |
} |
|
1524 |
||
1525 |
//------------------------------do_transform----------------------------------- |
|
1526 |
// Top level driver for the recursive transformer |
|
1527 |
void PhaseCCP::do_transform() { |
|
1528 |
// Correct leaves of new-space Nodes; they point to old-space. |
|
1529 |
C->set_root( transform(C->root())->as_Root() ); |
|
1530 |
assert( C->top(), "missing TOP node" ); |
|
1531 |
assert( C->root(), "missing root" ); |
|
24009
ec494183af7e
8034216: assert(false) failed: infinite loop in PhaseIterGVN::optimize
anoll
parents:
23528
diff
changeset
|
1532 |
|
ec494183af7e
8034216: assert(false) failed: infinite loop in PhaseIterGVN::optimize
anoll
parents:
23528
diff
changeset
|
1533 |
// Eagerly remove castPP nodes here. CastPP nodes might not be |
ec494183af7e
8034216: assert(false) failed: infinite loop in PhaseIterGVN::optimize
anoll
parents:
23528
diff
changeset
|
1534 |
// removed in the subsequent IGVN phase if a node that changes |
ec494183af7e
8034216: assert(false) failed: infinite loop in PhaseIterGVN::optimize
anoll
parents:
23528
diff
changeset
|
1535 |
// in(1) of a castPP is processed prior to the castPP node. |
ec494183af7e
8034216: assert(false) failed: infinite loop in PhaseIterGVN::optimize
anoll
parents:
23528
diff
changeset
|
1536 |
for (uint i = 0; i < _worklist.size(); i++) { |
ec494183af7e
8034216: assert(false) failed: infinite loop in PhaseIterGVN::optimize
anoll
parents:
23528
diff
changeset
|
1537 |
Node* n = _worklist.at(i); |
ec494183af7e
8034216: assert(false) failed: infinite loop in PhaseIterGVN::optimize
anoll
parents:
23528
diff
changeset
|
1538 |
|
ec494183af7e
8034216: assert(false) failed: infinite loop in PhaseIterGVN::optimize
anoll
parents:
23528
diff
changeset
|
1539 |
if (n->is_ConstraintCast()) { |
ec494183af7e
8034216: assert(false) failed: infinite loop in PhaseIterGVN::optimize
anoll
parents:
23528
diff
changeset
|
1540 |
Node* nn = n->Identity(this); |
ec494183af7e
8034216: assert(false) failed: infinite loop in PhaseIterGVN::optimize
anoll
parents:
23528
diff
changeset
|
1541 |
if (nn != n) { |
ec494183af7e
8034216: assert(false) failed: infinite loop in PhaseIterGVN::optimize
anoll
parents:
23528
diff
changeset
|
1542 |
replace_node(n, nn); |
ec494183af7e
8034216: assert(false) failed: infinite loop in PhaseIterGVN::optimize
anoll
parents:
23528
diff
changeset
|
1543 |
--i; |
ec494183af7e
8034216: assert(false) failed: infinite loop in PhaseIterGVN::optimize
anoll
parents:
23528
diff
changeset
|
1544 |
} |
ec494183af7e
8034216: assert(false) failed: infinite loop in PhaseIterGVN::optimize
anoll
parents:
23528
diff
changeset
|
1545 |
} |
ec494183af7e
8034216: assert(false) failed: infinite loop in PhaseIterGVN::optimize
anoll
parents:
23528
diff
changeset
|
1546 |
} |
1 | 1547 |
} |
1548 |
||
1549 |
//------------------------------transform-------------------------------------- |
|
1550 |
// Given a Node in old-space, clone him into new-space. |
|
1551 |
// Convert any of his old-space children into new-space children. |
|
1552 |
Node *PhaseCCP::transform( Node *n ) { |
|
1553 |
Node *new_node = _nodes[n->_idx]; // Check for transformed node |
|
1554 |
if( new_node != NULL ) |
|
1555 |
return new_node; // Been there, done that, return old answer |
|
1556 |
new_node = transform_once(n); // Check for constant |
|
1557 |
_nodes.map( n->_idx, new_node ); // Flag as having been cloned |
|
1558 |
||
1559 |
// Allocate stack of size _nodes.Size()/2 to avoid frequent realloc |
|
1560 |
GrowableArray <Node *> trstack(C->unique() >> 1); |
|
1561 |
||
1562 |
trstack.push(new_node); // Process children of cloned node |
|
1563 |
while ( trstack.is_nonempty() ) { |
|
1564 |
Node *clone = trstack.pop(); |
|
1565 |
uint cnt = clone->req(); |
|
1566 |
for( uint i = 0; i < cnt; i++ ) { // For all inputs do |
|
1567 |
Node *input = clone->in(i); |
|
1568 |
if( input != NULL ) { // Ignore NULLs |
|
1569 |
Node *new_input = _nodes[input->_idx]; // Check for cloned input node |
|
1570 |
if( new_input == NULL ) { |
|
1571 |
new_input = transform_once(input); // Check for constant |
|
1572 |
_nodes.map( input->_idx, new_input );// Flag as having been cloned |
|
1573 |
trstack.push(new_input); |
|
1574 |
} |
|
1575 |
assert( new_input == clone->in(i), "insanity check"); |
|
1576 |
} |
|
1577 |
} |
|
1578 |
} |
|
1579 |
return new_node; |
|
1580 |
} |
|
1581 |
||
1582 |
||
1583 |
//------------------------------transform_once--------------------------------- |
|
1584 |
// For PhaseCCP, transformation is IDENTITY unless Node computed a constant. |
|
1585 |
Node *PhaseCCP::transform_once( Node *n ) { |
|
1586 |
const Type *t = type(n); |
|
1587 |
// Constant? Use constant Node instead |
|
1588 |
if( t->singleton() ) { |
|
1589 |
Node *nn = n; // Default is to return the original constant |
|
1590 |
if( t == Type::TOP ) { |
|
1591 |
// cache my top node on the Compile instance |
|
1592 |
if( C->cached_top_node() == NULL || C->cached_top_node()->in(0) == NULL ) { |
|
1593 |
C->set_cached_top_node( ConNode::make(C, Type::TOP) ); |
|
1594 |
set_type(C->top(), Type::TOP); |
|
1595 |
} |
|
1596 |
nn = C->top(); |
|
1597 |
} |
|
1598 |
if( !n->is_Con() ) { |
|
1599 |
if( t != Type::TOP ) { |
|
1600 |
nn = makecon(t); // ConNode::make(t); |
|
1601 |
NOT_PRODUCT( inc_constants(); ) |
|
1602 |
} else if( n->is_Region() ) { // Unreachable region |
|
1603 |
// Note: nn == C->top() |
|
1604 |
n->set_req(0, NULL); // Cut selfreference |
|
1605 |
// Eagerly remove dead phis to avoid phis copies creation. |
|
1606 |
for (DUIterator i = n->outs(); n->has_out(i); i++) { |
|
1607 |
Node* m = n->out(i); |
|
1608 |
if( m->is_Phi() ) { |
|
1609 |
assert(type(m) == Type::TOP, "Unreachable region should not have live phis."); |
|
5901
c046f8e9c52b
6677629: PhaseIterGVN::subsume_node() should call hash_delete() and add_users_to_worklist()
kvn
parents:
5547
diff
changeset
|
1610 |
replace_node(m, nn); |
1 | 1611 |
--i; // deleted this phi; rescan starting with next position |
1612 |
} |
|
1613 |
} |
|
1614 |
} |
|
5901
c046f8e9c52b
6677629: PhaseIterGVN::subsume_node() should call hash_delete() and add_users_to_worklist()
kvn
parents:
5547
diff
changeset
|
1615 |
replace_node(n,nn); // Update DefUse edges for new constant |
1 | 1616 |
} |
1617 |
return nn; |
|
1618 |
} |
|
1619 |
||
1620 |
// If x is a TypeNode, capture any more-precise type permanently into Node |
|
1621 |
if (t != n->bottom_type()) { |
|
1622 |
hash_delete(n); // changing bottom type may force a rehash |
|
1623 |
n->raise_bottom_type(t); |
|
1624 |
_worklist.push(n); // n re-enters the hash table via the worklist |
|
1625 |
} |
|
1626 |
||
1627 |
// Idealize graph using DU info. Must clone() into new-space. |
|
1628 |
// DU info is generally used to show profitability, progress or safety |
|
1629 |
// (but generally not needed for correctness). |
|
1630 |
Node *nn = n->Ideal_DU_postCCP(this); |
|
1631 |
||
1632 |
// TEMPORARY fix to ensure that 2nd GVN pass eliminates NULL checks |
|
1633 |
switch( n->Opcode() ) { |
|
1634 |
case Op_FastLock: // Revisit FastLocks for lock coarsening |
|
1635 |
case Op_If: |
|
1636 |
case Op_CountedLoopEnd: |
|
1637 |
case Op_Region: |
|
1638 |
case Op_Loop: |
|
1639 |
case Op_CountedLoop: |
|
1640 |
case Op_Conv2B: |
|
1641 |
case Op_Opaque1: |
|
1642 |
case Op_Opaque2: |
|
1643 |
_worklist.push(n); |
|
1644 |
break; |
|
1645 |
default: |
|
1646 |
break; |
|
1647 |
} |
|
1648 |
if( nn ) { |
|
1649 |
_worklist.push(n); |
|
1650 |
// Put users of 'n' onto worklist for second igvn transform |
|
1651 |
add_users_to_worklist(n); |
|
1652 |
return nn; |
|
1653 |
} |
|
1654 |
||
1655 |
return n; |
|
1656 |
} |
|
1657 |
||
1658 |
//---------------------------------saturate------------------------------------ |
|
1659 |
const Type* PhaseCCP::saturate(const Type* new_type, const Type* old_type, |
|
1660 |
const Type* limit_type) const { |
|
4012
579b7bad9983
6885584: A particular class structure causes large allocation spike for jit
never
parents:
3682
diff
changeset
|
1661 |
const Type* wide_type = new_type->widen(old_type, limit_type); |
1 | 1662 |
if (wide_type != new_type) { // did we widen? |
1663 |
// If so, we may have widened beyond the limit type. Clip it back down. |
|
1664 |
new_type = wide_type->filter(limit_type); |
|
1665 |
} |
|
1666 |
return new_type; |
|
1667 |
} |
|
1668 |
||
1669 |
//------------------------------print_statistics------------------------------- |
|
1670 |
#ifndef PRODUCT |
|
1671 |
void PhaseCCP::print_statistics() { |
|
1672 |
tty->print_cr("CCP: %d constants found: %d", _total_invokes, _total_constants); |
|
1673 |
} |
|
1674 |
#endif |
|
1675 |
||
1676 |
||
1677 |
//============================================================================= |
|
1678 |
#ifndef PRODUCT |
|
1679 |
uint PhasePeephole::_total_peepholes = 0; |
|
1680 |
#endif |
|
1681 |
//------------------------------PhasePeephole---------------------------------- |
|
1682 |
// Conditional Constant Propagation, ala Wegman & Zadeck |
|
1683 |
PhasePeephole::PhasePeephole( PhaseRegAlloc *regalloc, PhaseCFG &cfg ) |
|
1684 |
: PhaseTransform(Peephole), _regalloc(regalloc), _cfg(cfg) { |
|
1685 |
NOT_PRODUCT( clear_peepholes(); ) |
|
1686 |
} |
|
1687 |
||
1688 |
#ifndef PRODUCT |
|
1689 |
//------------------------------~PhasePeephole--------------------------------- |
|
1690 |
PhasePeephole::~PhasePeephole() { |
|
1691 |
_total_peepholes += count_peepholes(); |
|
1692 |
} |
|
1693 |
#endif |
|
1694 |
||
1695 |
//------------------------------transform-------------------------------------- |
|
1696 |
Node *PhasePeephole::transform( Node *n ) { |
|
1697 |
ShouldNotCallThis(); |
|
1698 |
return NULL; |
|
1699 |
} |
|
1700 |
||
1701 |
//------------------------------do_transform----------------------------------- |
|
1702 |
void PhasePeephole::do_transform() { |
|
1703 |
bool method_name_not_printed = true; |
|
1704 |
||
1705 |
// Examine each basic block |
|
19330
49d6711171e6
8023003: Cleanup the public interface to PhaseCFG
adlertz
parents:
17383
diff
changeset
|
1706 |
for (uint block_number = 1; block_number < _cfg.number_of_blocks(); ++block_number) { |
49d6711171e6
8023003: Cleanup the public interface to PhaseCFG
adlertz
parents:
17383
diff
changeset
|
1707 |
Block* block = _cfg.get_block(block_number); |
1 | 1708 |
bool block_not_printed = true; |
1709 |
||
1710 |
// and each instruction within a block |
|
19717
7819ffdaf0ff
8023691: Create interface for nodes in class Block
adlertz
parents:
19330
diff
changeset
|
1711 |
uint end_index = block->number_of_nodes(); |
1 | 1712 |
// block->end_idx() not valid after PhaseRegAlloc |
1713 |
for( uint instruction_index = 1; instruction_index < end_index; ++instruction_index ) { |
|
19717
7819ffdaf0ff
8023691: Create interface for nodes in class Block
adlertz
parents:
19330
diff
changeset
|
1714 |
Node *n = block->get_node(instruction_index); |
1 | 1715 |
if( n->is_Mach() ) { |
1716 |
MachNode *m = n->as_Mach(); |
|
1717 |
int deleted_count = 0; |
|
1718 |
// check for peephole opportunities |
|
1719 |
MachNode *m2 = m->peephole( block, instruction_index, _regalloc, deleted_count, C ); |
|
1720 |
if( m2 != NULL ) { |
|
1721 |
#ifndef PRODUCT |
|
1722 |
if( PrintOptoPeephole ) { |
|
1723 |
// Print method, first time only |
|
1724 |
if( C->method() && method_name_not_printed ) { |
|
1725 |
C->method()->print_short_name(); tty->cr(); |
|
1726 |
method_name_not_printed = false; |
|
1727 |
} |
|
1728 |
// Print this block |
|
1729 |
if( Verbose && block_not_printed) { |
|
1730 |
tty->print_cr("in block"); |
|
1731 |
block->dump(); |
|
1732 |
block_not_printed = false; |
|
1733 |
} |
|
1734 |
// Print instructions being deleted |
|
1735 |
for( int i = (deleted_count - 1); i >= 0; --i ) { |
|
19717
7819ffdaf0ff
8023691: Create interface for nodes in class Block
adlertz
parents:
19330
diff
changeset
|
1736 |
block->get_node(instruction_index-i)->as_Mach()->format(_regalloc); tty->cr(); |
1 | 1737 |
} |
1738 |
tty->print_cr("replaced with"); |
|
1739 |
// Print new instruction |
|
1740 |
m2->format(_regalloc); |
|
1741 |
tty->print("\n\n"); |
|
1742 |
} |
|
1743 |
#endif |
|
1744 |
// Remove old nodes from basic block and update instruction_index |
|
1745 |
// (old nodes still exist and may have edges pointing to them |
|
1746 |
// as register allocation info is stored in the allocator using |
|
1747 |
// the node index to live range mappings.) |
|
1748 |
uint safe_instruction_index = (instruction_index - deleted_count); |
|
1749 |
for( ; (instruction_index > safe_instruction_index); --instruction_index ) { |
|
19717
7819ffdaf0ff
8023691: Create interface for nodes in class Block
adlertz
parents:
19330
diff
changeset
|
1750 |
block->remove_node( instruction_index ); |
1 | 1751 |
} |
1752 |
// install new node after safe_instruction_index |
|
19717
7819ffdaf0ff
8023691: Create interface for nodes in class Block
adlertz
parents:
19330
diff
changeset
|
1753 |
block->insert_node(m2, safe_instruction_index + 1); |
7819ffdaf0ff
8023691: Create interface for nodes in class Block
adlertz
parents:
19330
diff
changeset
|
1754 |
end_index = block->number_of_nodes() - 1; // Recompute new block size |
1 | 1755 |
NOT_PRODUCT( inc_peepholes(); ) |
1756 |
} |
|
1757 |
} |
|
1758 |
} |
|
1759 |
} |
|
1760 |
} |
|
1761 |
||
1762 |
//------------------------------print_statistics------------------------------- |
|
1763 |
#ifndef PRODUCT |
|
1764 |
void PhasePeephole::print_statistics() { |
|
1765 |
tty->print_cr("Peephole: peephole rules applied: %d", _total_peepholes); |
|
1766 |
} |
|
1767 |
#endif |
|
1768 |
||
1769 |
||
1770 |
//============================================================================= |
|
1771 |
//------------------------------set_req_X-------------------------------------- |
|
1772 |
void Node::set_req_X( uint i, Node *n, PhaseIterGVN *igvn ) { |
|
1773 |
assert( is_not_dead(n), "can not use dead node"); |
|
1774 |
assert( igvn->hash_find(this) != this, "Need to remove from hash before changing edges" ); |
|
1775 |
Node *old = in(i); |
|
1776 |
set_req(i, n); |
|
1777 |
||
1778 |
// old goes dead? |
|
1779 |
if( old ) { |
|
1780 |
switch (old->outcnt()) { |
|
3682
42de755d7d6e
6866651: Regression: simple int sum crashes jvm (build 1.6.0_14-b08 and 1.7.0-ea-b59)
cfang
parents:
2131
diff
changeset
|
1781 |
case 0: |
42de755d7d6e
6866651: Regression: simple int sum crashes jvm (build 1.6.0_14-b08 and 1.7.0-ea-b59)
cfang
parents:
2131
diff
changeset
|
1782 |
// Put into the worklist to kill later. We do not kill it now because the |
42de755d7d6e
6866651: Regression: simple int sum crashes jvm (build 1.6.0_14-b08 and 1.7.0-ea-b59)
cfang
parents:
2131
diff
changeset
|
1783 |
// recursive kill will delete the current node (this) if dead-loop exists |
1 | 1784 |
if (!old->is_top()) |
3682
42de755d7d6e
6866651: Regression: simple int sum crashes jvm (build 1.6.0_14-b08 and 1.7.0-ea-b59)
cfang
parents:
2131
diff
changeset
|
1785 |
igvn->_worklist.push( old ); |
1 | 1786 |
break; |
1787 |
case 1: |
|
1788 |
if( old->is_Store() || old->has_special_unique_user() ) |
|
1789 |
igvn->add_users_to_worklist( old ); |
|
1790 |
break; |
|
1791 |
case 2: |
|
1792 |
if( old->is_Store() ) |
|
1793 |
igvn->add_users_to_worklist( old ); |
|
1794 |
if( old->Opcode() == Op_Region ) |
|
1795 |
igvn->_worklist.push(old); |
|
1796 |
break; |
|
1797 |
case 3: |
|
1798 |
if( old->Opcode() == Op_Region ) { |
|
1799 |
igvn->_worklist.push(old); |
|
1800 |
igvn->add_users_to_worklist( old ); |
|
1801 |
} |
|
1802 |
break; |
|
1803 |
default: |
|
1804 |
break; |
|
1805 |
} |
|
1806 |
} |
|
1807 |
||
1808 |
} |
|
1809 |
||
1810 |
//-------------------------------replace_by----------------------------------- |
|
1811 |
// Using def-use info, replace one node for another. Follow the def-use info |
|
1812 |
// to all users of the OLD node. Then make all uses point to the NEW node. |
|
1813 |
void Node::replace_by(Node *new_node) { |
|
1814 |
assert(!is_top(), "top node has no DU info"); |
|
1815 |
for (DUIterator_Last imin, i = last_outs(imin); i >= imin; ) { |
|
1816 |
Node* use = last_out(i); |
|
1817 |
uint uses_found = 0; |
|
1818 |
for (uint j = 0; j < use->len(); j++) { |
|
1819 |
if (use->in(j) == this) { |
|
1820 |
if (j < use->req()) |
|
1821 |
use->set_req(j, new_node); |
|
1822 |
else use->set_prec(j, new_node); |
|
1823 |
uses_found++; |
|
1824 |
} |
|
1825 |
} |
|
1826 |
i -= uses_found; // we deleted 1 or more copies of this edge |
|
1827 |
} |
|
1828 |
} |
|
1829 |
||
1830 |
//============================================================================= |
|
1831 |
//----------------------------------------------------------------------------- |
|
1832 |
void Type_Array::grow( uint i ) { |
|
1833 |
if( !_max ) { |
|
1834 |
_max = 1; |
|
1835 |
_types = (const Type**)_a->Amalloc( _max * sizeof(Type*) ); |
|
1836 |
_types[0] = NULL; |
|
1837 |
} |
|
1838 |
uint old = _max; |
|
1839 |
while( i >= _max ) _max <<= 1; // Double to fit |
|
1840 |
_types = (const Type**)_a->Arealloc( _types, old*sizeof(Type*),_max*sizeof(Type*)); |
|
1841 |
memset( &_types[old], 0, (_max-old)*sizeof(Type*) ); |
|
1842 |
} |
|
1843 |
||
1844 |
//------------------------------dump------------------------------------------- |
|
1845 |
#ifndef PRODUCT |
|
1846 |
void Type_Array::dump() const { |
|
1847 |
uint max = Size(); |
|
1848 |
for( uint i = 0; i < max; i++ ) { |
|
1849 |
if( _types[i] != NULL ) { |
|
1850 |
tty->print(" %d\t== ", i); _types[i]->dump(); tty->cr(); |
|
1851 |
} |
|
1852 |
} |
|
1853 |
} |
|
1854 |
#endif |