Mercurial > hg > truffle
annotate src/share/vm/opto/connode.cpp @ 452:00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
Summary: When we encounter marking stack overflow during precleaning of Reference lists, we were using the overflow list mechanism, which can cause problems on account of mutating the mark word of the header because of conflicts with mutator accesses and updates of that field. Instead we should use the usual mechanism for overflow handling in concurrent phases, namely dirtying of the card on which the overflowed object lies. Since precleaning effectively does a form of discovered list processing, albeit with discovery enabled, we needed to adjust some code to be correct in the face of interleaved processing and discovery.
Reviewed-by: apetrusenko, jcoomes
author | ysr |
---|---|
date | Thu, 20 Nov 2008 12:27:41 -0800 |
parents | 36ccc817fca4 |
children | 98cb887364d3 |
rev | line source |
---|---|
0 | 1 /* |
196 | 2 * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 // Optimization - Graph Style | |
26 | |
27 #include "incls/_precompiled.incl" | |
28 #include "incls/_connode.cpp.incl" | |
29 | |
30 //============================================================================= | |
31 //------------------------------hash------------------------------------------- | |
32 uint ConNode::hash() const { | |
33 return (uintptr_t)in(TypeFunc::Control) + _type->hash(); | |
34 } | |
35 | |
36 //------------------------------make------------------------------------------- | |
37 ConNode *ConNode::make( Compile* C, const Type *t ) { | |
38 switch( t->basic_type() ) { | |
39 case T_INT: return new (C, 1) ConINode( t->is_int() ); | |
40 case T_LONG: return new (C, 1) ConLNode( t->is_long() ); | |
41 case T_FLOAT: return new (C, 1) ConFNode( t->is_float_constant() ); | |
42 case T_DOUBLE: return new (C, 1) ConDNode( t->is_double_constant() ); | |
43 case T_VOID: return new (C, 1) ConNode ( Type::TOP ); | |
44 case T_OBJECT: return new (C, 1) ConPNode( t->is_oopptr() ); | |
164
c436414a719e
6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents:
163
diff
changeset
|
45 case T_ARRAY: return new (C, 1) ConPNode( t->is_aryptr() ); |
0 | 46 case T_ADDRESS: return new (C, 1) ConPNode( t->is_ptr() ); |
168
7793bd37a336
6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents:
164
diff
changeset
|
47 case T_NARROWOOP: return new (C, 1) ConNNode( t->is_narrowoop() ); |
0 | 48 // Expected cases: TypePtr::NULL_PTR, any is_rawptr() |
49 // Also seen: AnyPtr(TopPTR *+top); from command line: | |
50 // r -XX:+PrintOpto -XX:CIStart=285 -XX:+CompileTheWorld -XX:CompileTheWorldStartAt=660 | |
51 // %%%% Stop using TypePtr::NULL_PTR to represent nulls: use either TypeRawPtr::NULL_PTR | |
52 // or else TypeOopPtr::NULL_PTR. Then set Type::_basic_type[AnyPtr] = T_ILLEGAL | |
53 } | |
54 ShouldNotReachHere(); | |
55 return NULL; | |
56 } | |
57 | |
58 //============================================================================= | |
59 /* | |
60 The major change is for CMoveP and StrComp. They have related but slightly | |
61 different problems. They both take in TWO oops which are both null-checked | |
62 independently before the using Node. After CCP removes the CastPP's they need | |
63 to pick up the guarding test edge - in this case TWO control edges. I tried | |
64 various solutions, all have problems: | |
65 | |
66 (1) Do nothing. This leads to a bug where we hoist a Load from a CMoveP or a | |
67 StrComp above a guarding null check. I've seen both cases in normal -Xcomp | |
68 testing. | |
69 | |
70 (2) Plug the control edge from 1 of the 2 oops in. Apparent problem here is | |
71 to figure out which test post-dominates. The real problem is that it doesn't | |
72 matter which one you pick. After you pick up, the dominating-test elider in | |
73 IGVN can remove the test and allow you to hoist up to the dominating test on | |
74 the choosen oop bypassing the test on the not-choosen oop. Seen in testing. | |
75 Oops. | |
76 | |
77 (3) Leave the CastPP's in. This makes the graph more accurate in some sense; | |
78 we get to keep around the knowledge that an oop is not-null after some test. | |
79 Alas, the CastPP's interfere with GVN (some values are the regular oop, some | |
80 are the CastPP of the oop, all merge at Phi's which cannot collapse, etc). | |
81 This cost us 10% on SpecJVM, even when I removed some of the more trivial | |
82 cases in the optimizer. Removing more useless Phi's started allowing Loads to | |
83 illegally float above null checks. I gave up on this approach. | |
84 | |
85 (4) Add BOTH control edges to both tests. Alas, too much code knows that | |
86 control edges are in slot-zero ONLY. Many quick asserts fail; no way to do | |
87 this one. Note that I really want to allow the CMoveP to float and add both | |
88 control edges to the dependent Load op - meaning I can select early but I | |
89 cannot Load until I pass both tests. | |
90 | |
91 (5) Do not hoist CMoveP and StrComp. To this end I added the v-call | |
92 depends_only_on_test(). No obvious performance loss on Spec, but we are | |
93 clearly conservative on CMoveP (also so on StrComp but that's unlikely to | |
94 matter ever). | |
95 | |
96 */ | |
97 | |
98 | |
99 //------------------------------Ideal------------------------------------------ | |
100 // Return a node which is more "ideal" than the current node. | |
101 // Move constants to the right. | |
102 Node *CMoveNode::Ideal(PhaseGVN *phase, bool can_reshape) { | |
103 if( in(0) && remove_dead_region(phase, can_reshape) ) return this; | |
305 | 104 // Don't bother trying to transform a dead node |
105 if( in(0) && in(0)->is_top() ) return NULL; | |
0 | 106 assert( !phase->eqv(in(Condition), this) && |
107 !phase->eqv(in(IfFalse), this) && | |
108 !phase->eqv(in(IfTrue), this), "dead loop in CMoveNode::Ideal" ); | |
109 if( phase->type(in(Condition)) == Type::TOP ) | |
110 return NULL; // return NULL when Condition is dead | |
111 | |
112 if( in(IfFalse)->is_Con() && !in(IfTrue)->is_Con() ) { | |
113 if( in(Condition)->is_Bool() ) { | |
114 BoolNode* b = in(Condition)->as_Bool(); | |
115 BoolNode* b2 = b->negate(phase); | |
116 return make( phase->C, in(Control), phase->transform(b2), in(IfTrue), in(IfFalse), _type ); | |
117 } | |
118 } | |
119 return NULL; | |
120 } | |
121 | |
122 //------------------------------is_cmove_id------------------------------------ | |
123 // Helper function to check for CMOVE identity. Shared with PhiNode::Identity | |
124 Node *CMoveNode::is_cmove_id( PhaseTransform *phase, Node *cmp, Node *t, Node *f, BoolNode *b ) { | |
125 // Check for Cmp'ing and CMove'ing same values | |
126 if( (phase->eqv(cmp->in(1),f) && | |
127 phase->eqv(cmp->in(2),t)) || | |
128 // Swapped Cmp is OK | |
129 (phase->eqv(cmp->in(2),f) && | |
130 phase->eqv(cmp->in(1),t)) ) { | |
131 // Check for "(t==f)?t:f;" and replace with "f" | |
132 if( b->_test._test == BoolTest::eq ) | |
133 return f; | |
134 // Allow the inverted case as well | |
135 // Check for "(t!=f)?t:f;" and replace with "t" | |
136 if( b->_test._test == BoolTest::ne ) | |
137 return t; | |
138 } | |
139 return NULL; | |
140 } | |
141 | |
142 //------------------------------Identity--------------------------------------- | |
143 // Conditional-move is an identity if both inputs are the same, or the test | |
144 // true or false. | |
145 Node *CMoveNode::Identity( PhaseTransform *phase ) { | |
146 if( phase->eqv(in(IfFalse),in(IfTrue)) ) // C-moving identical inputs? | |
147 return in(IfFalse); // Then it doesn't matter | |
148 if( phase->type(in(Condition)) == TypeInt::ZERO ) | |
149 return in(IfFalse); // Always pick left(false) input | |
150 if( phase->type(in(Condition)) == TypeInt::ONE ) | |
151 return in(IfTrue); // Always pick right(true) input | |
152 | |
153 // Check for CMove'ing a constant after comparing against the constant. | |
154 // Happens all the time now, since if we compare equality vs a constant in | |
155 // the parser, we "know" the variable is constant on one path and we force | |
156 // it. Thus code like "if( x==0 ) {/*EMPTY*/}" ends up inserting a | |
157 // conditional move: "x = (x==0)?0:x;". Yucko. This fix is slightly more | |
158 // general in that we don't need constants. | |
159 if( in(Condition)->is_Bool() ) { | |
160 BoolNode *b = in(Condition)->as_Bool(); | |
161 Node *cmp = b->in(1); | |
162 if( cmp->is_Cmp() ) { | |
163 Node *id = is_cmove_id( phase, cmp, in(IfTrue), in(IfFalse), b ); | |
164 if( id ) return id; | |
165 } | |
166 } | |
167 | |
168 return this; | |
169 } | |
170 | |
171 //------------------------------Value------------------------------------------ | |
172 // Result is the meet of inputs | |
173 const Type *CMoveNode::Value( PhaseTransform *phase ) const { | |
174 if( phase->type(in(Condition)) == Type::TOP ) | |
175 return Type::TOP; | |
176 return phase->type(in(IfFalse))->meet(phase->type(in(IfTrue))); | |
177 } | |
178 | |
179 //------------------------------make------------------------------------------- | |
180 // Make a correctly-flavored CMove. Since _type is directly determined | |
181 // from the inputs we do not need to specify it here. | |
182 CMoveNode *CMoveNode::make( Compile *C, Node *c, Node *bol, Node *left, Node *right, const Type *t ) { | |
183 switch( t->basic_type() ) { | |
184 case T_INT: return new (C, 4) CMoveINode( bol, left, right, t->is_int() ); | |
185 case T_FLOAT: return new (C, 4) CMoveFNode( bol, left, right, t ); | |
186 case T_DOUBLE: return new (C, 4) CMoveDNode( bol, left, right, t ); | |
187 case T_LONG: return new (C, 4) CMoveLNode( bol, left, right, t->is_long() ); | |
188 case T_OBJECT: return new (C, 4) CMovePNode( c, bol, left, right, t->is_oopptr() ); | |
189 case T_ADDRESS: return new (C, 4) CMovePNode( c, bol, left, right, t->is_ptr() ); | |
164
c436414a719e
6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents:
163
diff
changeset
|
190 case T_NARROWOOP: return new (C, 4) CMoveNNode( c, bol, left, right, t ); |
0 | 191 default: |
192 ShouldNotReachHere(); | |
193 return NULL; | |
194 } | |
195 } | |
196 | |
197 //============================================================================= | |
198 //------------------------------Ideal------------------------------------------ | |
199 // Return a node which is more "ideal" than the current node. | |
200 // Check for conversions to boolean | |
201 Node *CMoveINode::Ideal(PhaseGVN *phase, bool can_reshape) { | |
202 // Try generic ideal's first | |
203 Node *x = CMoveNode::Ideal(phase, can_reshape); | |
204 if( x ) return x; | |
205 | |
206 // If zero is on the left (false-case, no-move-case) it must mean another | |
207 // constant is on the right (otherwise the shared CMove::Ideal code would | |
208 // have moved the constant to the right). This situation is bad for Intel | |
209 // and a don't-care for Sparc. It's bad for Intel because the zero has to | |
210 // be manifested in a register with a XOR which kills flags, which are live | |
211 // on input to the CMoveI, leading to a situation which causes excessive | |
212 // spilling on Intel. For Sparc, if the zero in on the left the Sparc will | |
213 // zero a register via G0 and conditionally-move the other constant. If the | |
214 // zero is on the right, the Sparc will load the first constant with a | |
215 // 13-bit set-lo and conditionally move G0. See bug 4677505. | |
216 if( phase->type(in(IfFalse)) == TypeInt::ZERO && !(phase->type(in(IfTrue)) == TypeInt::ZERO) ) { | |
217 if( in(Condition)->is_Bool() ) { | |
218 BoolNode* b = in(Condition)->as_Bool(); | |
219 BoolNode* b2 = b->negate(phase); | |
220 return make( phase->C, in(Control), phase->transform(b2), in(IfTrue), in(IfFalse), _type ); | |
221 } | |
222 } | |
223 | |
224 // Now check for booleans | |
225 int flip = 0; | |
226 | |
227 // Check for picking from zero/one | |
228 if( phase->type(in(IfFalse)) == TypeInt::ZERO && phase->type(in(IfTrue)) == TypeInt::ONE ) { | |
229 flip = 1 - flip; | |
230 } else if( phase->type(in(IfFalse)) == TypeInt::ONE && phase->type(in(IfTrue)) == TypeInt::ZERO ) { | |
231 } else return NULL; | |
232 | |
233 // Check for eq/ne test | |
234 if( !in(1)->is_Bool() ) return NULL; | |
235 BoolNode *bol = in(1)->as_Bool(); | |
236 if( bol->_test._test == BoolTest::eq ) { | |
237 } else if( bol->_test._test == BoolTest::ne ) { | |
238 flip = 1-flip; | |
239 } else return NULL; | |
240 | |
241 // Check for vs 0 or 1 | |
242 if( !bol->in(1)->is_Cmp() ) return NULL; | |
243 const CmpNode *cmp = bol->in(1)->as_Cmp(); | |
244 if( phase->type(cmp->in(2)) == TypeInt::ZERO ) { | |
245 } else if( phase->type(cmp->in(2)) == TypeInt::ONE ) { | |
246 // Allow cmp-vs-1 if the other input is bounded by 0-1 | |
247 if( phase->type(cmp->in(1)) != TypeInt::BOOL ) | |
248 return NULL; | |
249 flip = 1 - flip; | |
250 } else return NULL; | |
251 | |
252 // Convert to a bool (flipped) | |
253 // Build int->bool conversion | |
254 #ifndef PRODUCT | |
255 if( PrintOpto ) tty->print_cr("CMOV to I2B"); | |
256 #endif | |
257 Node *n = new (phase->C, 2) Conv2BNode( cmp->in(1) ); | |
258 if( flip ) | |
259 n = new (phase->C, 3) XorINode( phase->transform(n), phase->intcon(1) ); | |
260 | |
261 return n; | |
262 } | |
263 | |
264 //============================================================================= | |
265 //------------------------------Ideal------------------------------------------ | |
266 // Return a node which is more "ideal" than the current node. | |
267 // Check for absolute value | |
268 Node *CMoveFNode::Ideal(PhaseGVN *phase, bool can_reshape) { | |
269 // Try generic ideal's first | |
270 Node *x = CMoveNode::Ideal(phase, can_reshape); | |
271 if( x ) return x; | |
272 | |
273 int cmp_zero_idx = 0; // Index of compare input where to look for zero | |
274 int phi_x_idx = 0; // Index of phi input where to find naked x | |
275 | |
276 // Find the Bool | |
277 if( !in(1)->is_Bool() ) return NULL; | |
278 BoolNode *bol = in(1)->as_Bool(); | |
279 // Check bool sense | |
280 switch( bol->_test._test ) { | |
281 case BoolTest::lt: cmp_zero_idx = 1; phi_x_idx = IfTrue; break; | |
282 case BoolTest::le: cmp_zero_idx = 2; phi_x_idx = IfFalse; break; | |
283 case BoolTest::gt: cmp_zero_idx = 2; phi_x_idx = IfTrue; break; | |
284 case BoolTest::ge: cmp_zero_idx = 1; phi_x_idx = IfFalse; break; | |
285 default: return NULL; break; | |
286 } | |
287 | |
288 // Find zero input of CmpF; the other input is being abs'd | |
289 Node *cmpf = bol->in(1); | |
290 if( cmpf->Opcode() != Op_CmpF ) return NULL; | |
291 Node *X = NULL; | |
292 bool flip = false; | |
293 if( phase->type(cmpf->in(cmp_zero_idx)) == TypeF::ZERO ) { | |
294 X = cmpf->in(3 - cmp_zero_idx); | |
295 } else if (phase->type(cmpf->in(3 - cmp_zero_idx)) == TypeF::ZERO) { | |
296 // The test is inverted, we should invert the result... | |
297 X = cmpf->in(cmp_zero_idx); | |
298 flip = true; | |
299 } else { | |
300 return NULL; | |
301 } | |
302 | |
303 // If X is found on the appropriate phi input, find the subtract on the other | |
304 if( X != in(phi_x_idx) ) return NULL; | |
305 int phi_sub_idx = phi_x_idx == IfTrue ? IfFalse : IfTrue; | |
306 Node *sub = in(phi_sub_idx); | |
307 | |
308 // Allow only SubF(0,X) and fail out for all others; NegF is not OK | |
309 if( sub->Opcode() != Op_SubF || | |
310 sub->in(2) != X || | |
311 phase->type(sub->in(1)) != TypeF::ZERO ) return NULL; | |
312 | |
313 Node *abs = new (phase->C, 2) AbsFNode( X ); | |
314 if( flip ) | |
315 abs = new (phase->C, 3) SubFNode(sub->in(1), phase->transform(abs)); | |
316 | |
317 return abs; | |
318 } | |
319 | |
320 //============================================================================= | |
321 //------------------------------Ideal------------------------------------------ | |
322 // Return a node which is more "ideal" than the current node. | |
323 // Check for absolute value | |
324 Node *CMoveDNode::Ideal(PhaseGVN *phase, bool can_reshape) { | |
325 // Try generic ideal's first | |
326 Node *x = CMoveNode::Ideal(phase, can_reshape); | |
327 if( x ) return x; | |
328 | |
329 int cmp_zero_idx = 0; // Index of compare input where to look for zero | |
330 int phi_x_idx = 0; // Index of phi input where to find naked x | |
331 | |
332 // Find the Bool | |
333 if( !in(1)->is_Bool() ) return NULL; | |
334 BoolNode *bol = in(1)->as_Bool(); | |
335 // Check bool sense | |
336 switch( bol->_test._test ) { | |
337 case BoolTest::lt: cmp_zero_idx = 1; phi_x_idx = IfTrue; break; | |
338 case BoolTest::le: cmp_zero_idx = 2; phi_x_idx = IfFalse; break; | |
339 case BoolTest::gt: cmp_zero_idx = 2; phi_x_idx = IfTrue; break; | |
340 case BoolTest::ge: cmp_zero_idx = 1; phi_x_idx = IfFalse; break; | |
341 default: return NULL; break; | |
342 } | |
343 | |
344 // Find zero input of CmpD; the other input is being abs'd | |
345 Node *cmpd = bol->in(1); | |
346 if( cmpd->Opcode() != Op_CmpD ) return NULL; | |
347 Node *X = NULL; | |
348 bool flip = false; | |
349 if( phase->type(cmpd->in(cmp_zero_idx)) == TypeD::ZERO ) { | |
350 X = cmpd->in(3 - cmp_zero_idx); | |
351 } else if (phase->type(cmpd->in(3 - cmp_zero_idx)) == TypeD::ZERO) { | |
352 // The test is inverted, we should invert the result... | |
353 X = cmpd->in(cmp_zero_idx); | |
354 flip = true; | |
355 } else { | |
356 return NULL; | |
357 } | |
358 | |
359 // If X is found on the appropriate phi input, find the subtract on the other | |
360 if( X != in(phi_x_idx) ) return NULL; | |
361 int phi_sub_idx = phi_x_idx == IfTrue ? IfFalse : IfTrue; | |
362 Node *sub = in(phi_sub_idx); | |
363 | |
364 // Allow only SubD(0,X) and fail out for all others; NegD is not OK | |
365 if( sub->Opcode() != Op_SubD || | |
366 sub->in(2) != X || | |
367 phase->type(sub->in(1)) != TypeD::ZERO ) return NULL; | |
368 | |
369 Node *abs = new (phase->C, 2) AbsDNode( X ); | |
370 if( flip ) | |
371 abs = new (phase->C, 3) SubDNode(sub->in(1), phase->transform(abs)); | |
372 | |
373 return abs; | |
374 } | |
375 | |
376 | |
377 //============================================================================= | |
378 // If input is already higher or equal to cast type, then this is an identity. | |
379 Node *ConstraintCastNode::Identity( PhaseTransform *phase ) { | |
380 return phase->type(in(1))->higher_equal(_type) ? in(1) : this; | |
381 } | |
382 | |
383 //------------------------------Value------------------------------------------ | |
384 // Take 'join' of input and cast-up type | |
385 const Type *ConstraintCastNode::Value( PhaseTransform *phase ) const { | |
386 if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP; | |
387 const Type* ft = phase->type(in(1))->filter(_type); | |
388 | |
389 #ifdef ASSERT | |
390 // Previous versions of this function had some special case logic, | |
391 // which is no longer necessary. Make sure of the required effects. | |
392 switch (Opcode()) { | |
393 case Op_CastII: | |
394 { | |
395 const Type* t1 = phase->type(in(1)); | |
396 if( t1 == Type::TOP ) assert(ft == Type::TOP, "special case #1"); | |
397 const Type* rt = t1->join(_type); | |
398 if (rt->empty()) assert(ft == Type::TOP, "special case #2"); | |
399 break; | |
400 } | |
401 case Op_CastPP: | |
402 if (phase->type(in(1)) == TypePtr::NULL_PTR && | |
403 _type->isa_ptr() && _type->is_ptr()->_ptr == TypePtr::NotNull) | |
404 assert(ft == Type::TOP, "special case #3"); | |
405 break; | |
406 } | |
407 #endif //ASSERT | |
408 | |
409 return ft; | |
410 } | |
411 | |
412 //------------------------------Ideal------------------------------------------ | |
413 // Return a node which is more "ideal" than the current node. Strip out | |
414 // control copies | |
415 Node *ConstraintCastNode::Ideal(PhaseGVN *phase, bool can_reshape){ | |
416 return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL; | |
417 } | |
418 | |
419 //------------------------------Ideal_DU_postCCP------------------------------- | |
420 // Throw away cast after constant propagation | |
421 Node *ConstraintCastNode::Ideal_DU_postCCP( PhaseCCP *ccp ) { | |
422 const Type *t = ccp->type(in(1)); | |
423 ccp->hash_delete(this); | |
424 set_type(t); // Turn into ID function | |
425 ccp->hash_insert(this); | |
426 return this; | |
427 } | |
428 | |
429 | |
430 //============================================================================= | |
431 | |
432 //------------------------------Ideal_DU_postCCP------------------------------- | |
433 // If not converting int->oop, throw away cast after constant propagation | |
434 Node *CastPPNode::Ideal_DU_postCCP( PhaseCCP *ccp ) { | |
435 const Type *t = ccp->type(in(1)); | |
368
36ccc817fca4
6747051: Improve code and implicit null check generation for compressed oops
kvn
parents:
305
diff
changeset
|
436 if (!t->isa_oop_ptr() || in(1)->is_DecodeN()) { |
36ccc817fca4
6747051: Improve code and implicit null check generation for compressed oops
kvn
parents:
305
diff
changeset
|
437 return NULL; // do not transform raw pointers or narrow oops |
0 | 438 } |
439 return ConstraintCastNode::Ideal_DU_postCCP(ccp); | |
440 } | |
441 | |
442 | |
443 | |
444 //============================================================================= | |
445 //------------------------------Identity--------------------------------------- | |
446 // If input is already higher or equal to cast type, then this is an identity. | |
447 Node *CheckCastPPNode::Identity( PhaseTransform *phase ) { | |
448 // Toned down to rescue meeting at a Phi 3 different oops all implementing | |
449 // the same interface. CompileTheWorld starting at 502, kd12rc1.zip. | |
450 return (phase->type(in(1)) == phase->type(this)) ? in(1) : this; | |
451 } | |
452 | |
453 // Determine whether "n" is a node which can cause an alias of one of its inputs. Node types | |
454 // which can create aliases are: CheckCastPP, Phi, and any store (if there is also a load from | |
455 // the location.) | |
456 // Note: this checks for aliases created in this compilation, not ones which may | |
457 // be potentially created at call sites. | |
458 static bool can_cause_alias(Node *n, PhaseTransform *phase) { | |
459 bool possible_alias = false; | |
460 | |
461 if (n->is_Store()) { | |
462 possible_alias = !n->as_Store()->value_never_loaded(phase); | |
463 } else { | |
464 int opc = n->Opcode(); | |
465 possible_alias = n->is_Phi() || | |
466 opc == Op_CheckCastPP || | |
467 opc == Op_StorePConditional || | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
36
diff
changeset
|
468 opc == Op_CompareAndSwapP || |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
36
diff
changeset
|
469 opc == Op_CompareAndSwapN; |
0 | 470 } |
471 return possible_alias; | |
472 } | |
473 | |
474 //------------------------------Value------------------------------------------ | |
475 // Take 'join' of input and cast-up type, unless working with an Interface | |
476 const Type *CheckCastPPNode::Value( PhaseTransform *phase ) const { | |
477 if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP; | |
478 | |
479 const Type *inn = phase->type(in(1)); | |
480 if( inn == Type::TOP ) return Type::TOP; // No information yet | |
481 | |
482 const TypePtr *in_type = inn->isa_ptr(); | |
483 const TypePtr *my_type = _type->isa_ptr(); | |
484 const Type *result = _type; | |
485 if( in_type != NULL && my_type != NULL ) { | |
486 TypePtr::PTR in_ptr = in_type->ptr(); | |
487 if( in_ptr == TypePtr::Null ) { | |
488 result = in_type; | |
489 } else if( in_ptr == TypePtr::Constant ) { | |
490 // Casting a constant oop to an interface? | |
491 // (i.e., a String to a Comparable?) | |
492 // Then return the interface. | |
493 const TypeOopPtr *jptr = my_type->isa_oopptr(); | |
494 assert( jptr, "" ); | |
495 result = (jptr->klass()->is_interface() || !in_type->higher_equal(_type)) | |
496 ? my_type->cast_to_ptr_type( TypePtr::NotNull ) | |
497 : in_type; | |
498 } else { | |
499 result = my_type->cast_to_ptr_type( my_type->join_ptr(in_ptr) ); | |
500 } | |
501 } | |
502 return result; | |
503 | |
504 // JOIN NOT DONE HERE BECAUSE OF INTERFACE ISSUES. | |
505 // FIX THIS (DO THE JOIN) WHEN UNION TYPES APPEAR! | |
506 | |
507 // | |
508 // Remove this code after overnight run indicates no performance | |
509 // loss from not performing JOIN at CheckCastPPNode | |
510 // | |
511 // const TypeInstPtr *in_oop = in->isa_instptr(); | |
512 // const TypeInstPtr *my_oop = _type->isa_instptr(); | |
513 // // If either input is an 'interface', return destination type | |
514 // assert (in_oop == NULL || in_oop->klass() != NULL, ""); | |
515 // assert (my_oop == NULL || my_oop->klass() != NULL, ""); | |
516 // if( (in_oop && in_oop->klass()->klass_part()->is_interface()) | |
517 // ||(my_oop && my_oop->klass()->klass_part()->is_interface()) ) { | |
518 // TypePtr::PTR in_ptr = in->isa_ptr() ? in->is_ptr()->_ptr : TypePtr::BotPTR; | |
519 // // Preserve cast away nullness for interfaces | |
520 // if( in_ptr == TypePtr::NotNull && my_oop && my_oop->_ptr == TypePtr::BotPTR ) { | |
521 // return my_oop->cast_to_ptr_type(TypePtr::NotNull); | |
522 // } | |
523 // return _type; | |
524 // } | |
525 // | |
526 // // Neither the input nor the destination type is an interface, | |
527 // | |
528 // // history: JOIN used to cause weird corner case bugs | |
529 // // return (in == TypeOopPtr::NULL_PTR) ? in : _type; | |
530 // // JOIN picks up NotNull in common instance-of/check-cast idioms, both oops. | |
531 // // JOIN does not preserve NotNull in other cases, e.g. RawPtr vs InstPtr | |
532 // const Type *join = in->join(_type); | |
533 // // Check if join preserved NotNull'ness for pointers | |
534 // if( join->isa_ptr() && _type->isa_ptr() ) { | |
535 // TypePtr::PTR join_ptr = join->is_ptr()->_ptr; | |
536 // TypePtr::PTR type_ptr = _type->is_ptr()->_ptr; | |
537 // // If there isn't any NotNull'ness to preserve | |
538 // // OR if join preserved NotNull'ness then return it | |
539 // if( type_ptr == TypePtr::BotPTR || type_ptr == TypePtr::Null || | |
540 // join_ptr == TypePtr::NotNull || join_ptr == TypePtr::Constant ) { | |
541 // return join; | |
542 // } | |
543 // // ELSE return same old type as before | |
544 // return _type; | |
545 // } | |
546 // // Not joining two pointers | |
547 // return join; | |
548 } | |
549 | |
550 //------------------------------Ideal------------------------------------------ | |
551 // Return a node which is more "ideal" than the current node. Strip out | |
552 // control copies | |
553 Node *CheckCastPPNode::Ideal(PhaseGVN *phase, bool can_reshape){ | |
554 return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL; | |
555 } | |
556 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
36
diff
changeset
|
557 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
36
diff
changeset
|
558 Node* DecodeNNode::Identity(PhaseTransform* phase) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
36
diff
changeset
|
559 const Type *t = phase->type( in(1) ); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
36
diff
changeset
|
560 if( t == Type::TOP ) return in(1); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
36
diff
changeset
|
561 |
168
7793bd37a336
6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents:
164
diff
changeset
|
562 if (in(1)->is_EncodeP()) { |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
36
diff
changeset
|
563 // (DecodeN (EncodeP p)) -> p |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
36
diff
changeset
|
564 return in(1)->in(1); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
36
diff
changeset
|
565 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
36
diff
changeset
|
566 return this; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
36
diff
changeset
|
567 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
36
diff
changeset
|
568 |
124
b130b98db9cf
6689060: Escape Analysis does not work with Compressed Oops
kvn
parents:
113
diff
changeset
|
569 const Type *DecodeNNode::Value( PhaseTransform *phase ) const { |
216
8d191a7697e2
6715633: when matching a memory node the adr_type should not change
kvn
parents:
168
diff
changeset
|
570 const Type *t = phase->type( in(1) ); |
8d191a7697e2
6715633: when matching a memory node the adr_type should not change
kvn
parents:
168
diff
changeset
|
571 if (t == Type::TOP) return Type::TOP; |
8d191a7697e2
6715633: when matching a memory node the adr_type should not change
kvn
parents:
168
diff
changeset
|
572 if (t == TypeNarrowOop::NULL_PTR) return TypePtr::NULL_PTR; |
8d191a7697e2
6715633: when matching a memory node the adr_type should not change
kvn
parents:
168
diff
changeset
|
573 |
8d191a7697e2
6715633: when matching a memory node the adr_type should not change
kvn
parents:
168
diff
changeset
|
574 assert(t->isa_narrowoop(), "only narrowoop here"); |
221
1e026f8da827
6710487: More than half of JDI Regression tests hang with COOPs in -Xcomp mode
kvn
parents:
216
diff
changeset
|
575 return t->make_ptr(); |
124
b130b98db9cf
6689060: Escape Analysis does not work with Compressed Oops
kvn
parents:
113
diff
changeset
|
576 } |
b130b98db9cf
6689060: Escape Analysis does not work with Compressed Oops
kvn
parents:
113
diff
changeset
|
577 |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
36
diff
changeset
|
578 Node* EncodePNode::Identity(PhaseTransform* phase) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
36
diff
changeset
|
579 const Type *t = phase->type( in(1) ); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
36
diff
changeset
|
580 if( t == Type::TOP ) return in(1); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
36
diff
changeset
|
581 |
168
7793bd37a336
6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents:
164
diff
changeset
|
582 if (in(1)->is_DecodeN()) { |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
36
diff
changeset
|
583 // (EncodeP (DecodeN p)) -> p |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
36
diff
changeset
|
584 return in(1)->in(1); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
36
diff
changeset
|
585 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
36
diff
changeset
|
586 return this; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
36
diff
changeset
|
587 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
36
diff
changeset
|
588 |
124
b130b98db9cf
6689060: Escape Analysis does not work with Compressed Oops
kvn
parents:
113
diff
changeset
|
589 const Type *EncodePNode::Value( PhaseTransform *phase ) const { |
216
8d191a7697e2
6715633: when matching a memory node the adr_type should not change
kvn
parents:
168
diff
changeset
|
590 const Type *t = phase->type( in(1) ); |
8d191a7697e2
6715633: when matching a memory node the adr_type should not change
kvn
parents:
168
diff
changeset
|
591 if (t == Type::TOP) return Type::TOP; |
8d191a7697e2
6715633: when matching a memory node the adr_type should not change
kvn
parents:
168
diff
changeset
|
592 if (t == TypePtr::NULL_PTR) return TypeNarrowOop::NULL_PTR; |
8d191a7697e2
6715633: when matching a memory node the adr_type should not change
kvn
parents:
168
diff
changeset
|
593 |
8d191a7697e2
6715633: when matching a memory node the adr_type should not change
kvn
parents:
168
diff
changeset
|
594 assert(t->isa_oopptr(), "only oopptr here"); |
221
1e026f8da827
6710487: More than half of JDI Regression tests hang with COOPs in -Xcomp mode
kvn
parents:
216
diff
changeset
|
595 return t->make_narrowoop(); |
124
b130b98db9cf
6689060: Escape Analysis does not work with Compressed Oops
kvn
parents:
113
diff
changeset
|
596 } |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
36
diff
changeset
|
597 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
36
diff
changeset
|
598 |
163 | 599 Node *EncodePNode::Ideal_DU_postCCP( PhaseCCP *ccp ) { |
600 return MemNode::Ideal_common_DU_postCCP(ccp, this, in(1)); | |
601 } | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
36
diff
changeset
|
602 |
0 | 603 //============================================================================= |
604 //------------------------------Identity--------------------------------------- | |
605 Node *Conv2BNode::Identity( PhaseTransform *phase ) { | |
606 const Type *t = phase->type( in(1) ); | |
607 if( t == Type::TOP ) return in(1); | |
608 if( t == TypeInt::ZERO ) return in(1); | |
609 if( t == TypeInt::ONE ) return in(1); | |
610 if( t == TypeInt::BOOL ) return in(1); | |
611 return this; | |
612 } | |
613 | |
614 //------------------------------Value------------------------------------------ | |
615 const Type *Conv2BNode::Value( PhaseTransform *phase ) const { | |
616 const Type *t = phase->type( in(1) ); | |
617 if( t == Type::TOP ) return Type::TOP; | |
618 if( t == TypeInt::ZERO ) return TypeInt::ZERO; | |
619 if( t == TypePtr::NULL_PTR ) return TypeInt::ZERO; | |
620 const TypePtr *tp = t->isa_ptr(); | |
621 if( tp != NULL ) { | |
622 if( tp->ptr() == TypePtr::AnyNull ) return Type::TOP; | |
623 if( tp->ptr() == TypePtr::Constant) return TypeInt::ONE; | |
624 if (tp->ptr() == TypePtr::NotNull) return TypeInt::ONE; | |
625 return TypeInt::BOOL; | |
626 } | |
627 if (t->base() != Type::Int) return TypeInt::BOOL; | |
628 const TypeInt *ti = t->is_int(); | |
629 if( ti->_hi < 0 || ti->_lo > 0 ) return TypeInt::ONE; | |
630 return TypeInt::BOOL; | |
631 } | |
632 | |
633 | |
634 // The conversions operations are all Alpha sorted. Please keep it that way! | |
635 //============================================================================= | |
636 //------------------------------Value------------------------------------------ | |
637 const Type *ConvD2FNode::Value( PhaseTransform *phase ) const { | |
638 const Type *t = phase->type( in(1) ); | |
639 if( t == Type::TOP ) return Type::TOP; | |
640 if( t == Type::DOUBLE ) return Type::FLOAT; | |
641 const TypeD *td = t->is_double_constant(); | |
642 return TypeF::make( (float)td->getd() ); | |
643 } | |
644 | |
645 //------------------------------Identity--------------------------------------- | |
646 // Float's can be converted to doubles with no loss of bits. Hence | |
647 // converting a float to a double and back to a float is a NOP. | |
648 Node *ConvD2FNode::Identity(PhaseTransform *phase) { | |
649 return (in(1)->Opcode() == Op_ConvF2D) ? in(1)->in(1) : this; | |
650 } | |
651 | |
652 //============================================================================= | |
653 //------------------------------Value------------------------------------------ | |
654 const Type *ConvD2INode::Value( PhaseTransform *phase ) const { | |
655 const Type *t = phase->type( in(1) ); | |
656 if( t == Type::TOP ) return Type::TOP; | |
657 if( t == Type::DOUBLE ) return TypeInt::INT; | |
658 const TypeD *td = t->is_double_constant(); | |
659 return TypeInt::make( SharedRuntime::d2i( td->getd() ) ); | |
660 } | |
661 | |
662 //------------------------------Ideal------------------------------------------ | |
663 // If converting to an int type, skip any rounding nodes | |
664 Node *ConvD2INode::Ideal(PhaseGVN *phase, bool can_reshape) { | |
665 if( in(1)->Opcode() == Op_RoundDouble ) | |
666 set_req(1,in(1)->in(1)); | |
667 return NULL; | |
668 } | |
669 | |
670 //------------------------------Identity--------------------------------------- | |
671 // Int's can be converted to doubles with no loss of bits. Hence | |
672 // converting an integer to a double and back to an integer is a NOP. | |
673 Node *ConvD2INode::Identity(PhaseTransform *phase) { | |
674 return (in(1)->Opcode() == Op_ConvI2D) ? in(1)->in(1) : this; | |
675 } | |
676 | |
677 //============================================================================= | |
678 //------------------------------Value------------------------------------------ | |
679 const Type *ConvD2LNode::Value( PhaseTransform *phase ) const { | |
680 const Type *t = phase->type( in(1) ); | |
681 if( t == Type::TOP ) return Type::TOP; | |
682 if( t == Type::DOUBLE ) return TypeLong::LONG; | |
683 const TypeD *td = t->is_double_constant(); | |
684 return TypeLong::make( SharedRuntime::d2l( td->getd() ) ); | |
685 } | |
686 | |
687 //------------------------------Identity--------------------------------------- | |
688 Node *ConvD2LNode::Identity(PhaseTransform *phase) { | |
689 // Remove ConvD2L->ConvL2D->ConvD2L sequences. | |
690 if( in(1) ->Opcode() == Op_ConvL2D && | |
691 in(1)->in(1)->Opcode() == Op_ConvD2L ) | |
692 return in(1)->in(1); | |
693 return this; | |
694 } | |
695 | |
696 //------------------------------Ideal------------------------------------------ | |
697 // If converting to an int type, skip any rounding nodes | |
698 Node *ConvD2LNode::Ideal(PhaseGVN *phase, bool can_reshape) { | |
699 if( in(1)->Opcode() == Op_RoundDouble ) | |
700 set_req(1,in(1)->in(1)); | |
701 return NULL; | |
702 } | |
703 | |
704 //============================================================================= | |
705 //------------------------------Value------------------------------------------ | |
706 const Type *ConvF2DNode::Value( PhaseTransform *phase ) const { | |
707 const Type *t = phase->type( in(1) ); | |
708 if( t == Type::TOP ) return Type::TOP; | |
709 if( t == Type::FLOAT ) return Type::DOUBLE; | |
710 const TypeF *tf = t->is_float_constant(); | |
711 #ifndef IA64 | |
712 return TypeD::make( (double)tf->getf() ); | |
713 #else | |
714 float x = tf->getf(); | |
715 return TypeD::make( (x == 0.0f) ? (double)x : (double)x + ia64_double_zero ); | |
716 #endif | |
717 } | |
718 | |
719 //============================================================================= | |
720 //------------------------------Value------------------------------------------ | |
721 const Type *ConvF2INode::Value( PhaseTransform *phase ) const { | |
722 const Type *t = phase->type( in(1) ); | |
723 if( t == Type::TOP ) return Type::TOP; | |
724 if( t == Type::FLOAT ) return TypeInt::INT; | |
725 const TypeF *tf = t->is_float_constant(); | |
726 return TypeInt::make( SharedRuntime::f2i( tf->getf() ) ); | |
727 } | |
728 | |
729 //------------------------------Identity--------------------------------------- | |
730 Node *ConvF2INode::Identity(PhaseTransform *phase) { | |
731 // Remove ConvF2I->ConvI2F->ConvF2I sequences. | |
732 if( in(1) ->Opcode() == Op_ConvI2F && | |
733 in(1)->in(1)->Opcode() == Op_ConvF2I ) | |
734 return in(1)->in(1); | |
735 return this; | |
736 } | |
737 | |
738 //------------------------------Ideal------------------------------------------ | |
739 // If converting to an int type, skip any rounding nodes | |
740 Node *ConvF2INode::Ideal(PhaseGVN *phase, bool can_reshape) { | |
741 if( in(1)->Opcode() == Op_RoundFloat ) | |
742 set_req(1,in(1)->in(1)); | |
743 return NULL; | |
744 } | |
745 | |
746 //============================================================================= | |
747 //------------------------------Value------------------------------------------ | |
748 const Type *ConvF2LNode::Value( PhaseTransform *phase ) const { | |
749 const Type *t = phase->type( in(1) ); | |
750 if( t == Type::TOP ) return Type::TOP; | |
751 if( t == Type::FLOAT ) return TypeLong::LONG; | |
752 const TypeF *tf = t->is_float_constant(); | |
753 return TypeLong::make( SharedRuntime::f2l( tf->getf() ) ); | |
754 } | |
755 | |
756 //------------------------------Identity--------------------------------------- | |
757 Node *ConvF2LNode::Identity(PhaseTransform *phase) { | |
758 // Remove ConvF2L->ConvL2F->ConvF2L sequences. | |
759 if( in(1) ->Opcode() == Op_ConvL2F && | |
760 in(1)->in(1)->Opcode() == Op_ConvF2L ) | |
761 return in(1)->in(1); | |
762 return this; | |
763 } | |
764 | |
765 //------------------------------Ideal------------------------------------------ | |
766 // If converting to an int type, skip any rounding nodes | |
767 Node *ConvF2LNode::Ideal(PhaseGVN *phase, bool can_reshape) { | |
768 if( in(1)->Opcode() == Op_RoundFloat ) | |
769 set_req(1,in(1)->in(1)); | |
770 return NULL; | |
771 } | |
772 | |
773 //============================================================================= | |
774 //------------------------------Value------------------------------------------ | |
775 const Type *ConvI2DNode::Value( PhaseTransform *phase ) const { | |
776 const Type *t = phase->type( in(1) ); | |
777 if( t == Type::TOP ) return Type::TOP; | |
778 const TypeInt *ti = t->is_int(); | |
779 if( ti->is_con() ) return TypeD::make( (double)ti->get_con() ); | |
780 return bottom_type(); | |
781 } | |
782 | |
783 //============================================================================= | |
784 //------------------------------Value------------------------------------------ | |
785 const Type *ConvI2FNode::Value( PhaseTransform *phase ) const { | |
786 const Type *t = phase->type( in(1) ); | |
787 if( t == Type::TOP ) return Type::TOP; | |
788 const TypeInt *ti = t->is_int(); | |
789 if( ti->is_con() ) return TypeF::make( (float)ti->get_con() ); | |
790 return bottom_type(); | |
791 } | |
792 | |
793 //------------------------------Identity--------------------------------------- | |
794 Node *ConvI2FNode::Identity(PhaseTransform *phase) { | |
795 // Remove ConvI2F->ConvF2I->ConvI2F sequences. | |
796 if( in(1) ->Opcode() == Op_ConvF2I && | |
797 in(1)->in(1)->Opcode() == Op_ConvI2F ) | |
798 return in(1)->in(1); | |
799 return this; | |
800 } | |
801 | |
802 //============================================================================= | |
803 //------------------------------Value------------------------------------------ | |
804 const Type *ConvI2LNode::Value( PhaseTransform *phase ) const { | |
805 const Type *t = phase->type( in(1) ); | |
806 if( t == Type::TOP ) return Type::TOP; | |
807 const TypeInt *ti = t->is_int(); | |
808 const Type* tl = TypeLong::make(ti->_lo, ti->_hi, ti->_widen); | |
809 // Join my declared type against my incoming type. | |
810 tl = tl->filter(_type); | |
811 return tl; | |
812 } | |
813 | |
814 #ifdef _LP64 | |
815 static inline bool long_ranges_overlap(jlong lo1, jlong hi1, | |
816 jlong lo2, jlong hi2) { | |
817 // Two ranges overlap iff one range's low point falls in the other range. | |
818 return (lo2 <= lo1 && lo1 <= hi2) || (lo1 <= lo2 && lo2 <= hi1); | |
819 } | |
820 #endif | |
821 | |
822 //------------------------------Ideal------------------------------------------ | |
823 Node *ConvI2LNode::Ideal(PhaseGVN *phase, bool can_reshape) { | |
824 const TypeLong* this_type = this->type()->is_long(); | |
825 Node* this_changed = NULL; | |
826 | |
827 // If _major_progress, then more loop optimizations follow. Do NOT | |
828 // remove this node's type assertion until no more loop ops can happen. | |
829 // The progress bit is set in the major loop optimizations THEN comes the | |
830 // call to IterGVN and any chance of hitting this code. Cf. Opaque1Node. | |
831 if (can_reshape && !phase->C->major_progress()) { | |
832 const TypeInt* in_type = phase->type(in(1))->isa_int(); | |
833 if (in_type != NULL && this_type != NULL && | |
834 (in_type->_lo != this_type->_lo || | |
835 in_type->_hi != this_type->_hi)) { | |
836 // Although this WORSENS the type, it increases GVN opportunities, | |
837 // because I2L nodes with the same input will common up, regardless | |
838 // of slightly differing type assertions. Such slight differences | |
839 // arise routinely as a result of loop unrolling, so this is a | |
840 // post-unrolling graph cleanup. Choose a type which depends only | |
841 // on my input. (Exception: Keep a range assertion of >=0 or <0.) | |
842 jlong lo1 = this_type->_lo; | |
843 jlong hi1 = this_type->_hi; | |
844 int w1 = this_type->_widen; | |
845 if (lo1 != (jint)lo1 || | |
846 hi1 != (jint)hi1 || | |
847 lo1 > hi1) { | |
848 // Overflow leads to wraparound, wraparound leads to range saturation. | |
849 lo1 = min_jint; hi1 = max_jint; | |
850 } else if (lo1 >= 0) { | |
851 // Keep a range assertion of >=0. | |
852 lo1 = 0; hi1 = max_jint; | |
853 } else if (hi1 < 0) { | |
854 // Keep a range assertion of <0. | |
855 lo1 = min_jint; hi1 = -1; | |
856 } else { | |
857 lo1 = min_jint; hi1 = max_jint; | |
858 } | |
859 const TypeLong* wtype = TypeLong::make(MAX2((jlong)in_type->_lo, lo1), | |
860 MIN2((jlong)in_type->_hi, hi1), | |
861 MAX2((int)in_type->_widen, w1)); | |
862 if (wtype != type()) { | |
863 set_type(wtype); | |
864 // Note: this_type still has old type value, for the logic below. | |
865 this_changed = this; | |
866 } | |
867 } | |
868 } | |
869 | |
870 #ifdef _LP64 | |
871 // Convert ConvI2L(AddI(x, y)) to AddL(ConvI2L(x), ConvI2L(y)) , | |
872 // but only if x and y have subranges that cannot cause 32-bit overflow, | |
873 // under the assumption that x+y is in my own subrange this->type(). | |
874 | |
875 // This assumption is based on a constraint (i.e., type assertion) | |
876 // established in Parse::array_addressing or perhaps elsewhere. | |
877 // This constraint has been adjoined to the "natural" type of | |
878 // the incoming argument in(0). We know (because of runtime | |
879 // checks) - that the result value I2L(x+y) is in the joined range. | |
880 // Hence we can restrict the incoming terms (x, y) to values such | |
881 // that their sum also lands in that range. | |
882 | |
883 // This optimization is useful only on 64-bit systems, where we hope | |
884 // the addition will end up subsumed in an addressing mode. | |
885 // It is necessary to do this when optimizing an unrolled array | |
886 // copy loop such as x[i++] = y[i++]. | |
887 | |
888 // On 32-bit systems, it's better to perform as much 32-bit math as | |
889 // possible before the I2L conversion, because 32-bit math is cheaper. | |
890 // There's no common reason to "leak" a constant offset through the I2L. | |
891 // Addressing arithmetic will not absorb it as part of a 64-bit AddL. | |
892 | |
893 Node* z = in(1); | |
894 int op = z->Opcode(); | |
895 if (op == Op_AddI || op == Op_SubI) { | |
896 Node* x = z->in(1); | |
897 Node* y = z->in(2); | |
898 assert (x != z && y != z, "dead loop in ConvI2LNode::Ideal"); | |
899 if (phase->type(x) == Type::TOP) return this_changed; | |
900 if (phase->type(y) == Type::TOP) return this_changed; | |
901 const TypeInt* tx = phase->type(x)->is_int(); | |
902 const TypeInt* ty = phase->type(y)->is_int(); | |
903 const TypeLong* tz = this_type; | |
904 jlong xlo = tx->_lo; | |
905 jlong xhi = tx->_hi; | |
906 jlong ylo = ty->_lo; | |
907 jlong yhi = ty->_hi; | |
908 jlong zlo = tz->_lo; | |
909 jlong zhi = tz->_hi; | |
910 jlong vbit = CONST64(1) << BitsPerInt; | |
911 int widen = MAX2(tx->_widen, ty->_widen); | |
912 if (op == Op_SubI) { | |
913 jlong ylo0 = ylo; | |
914 ylo = -yhi; | |
915 yhi = -ylo0; | |
916 } | |
917 // See if x+y can cause positive overflow into z+2**32 | |
918 if (long_ranges_overlap(xlo+ylo, xhi+yhi, zlo+vbit, zhi+vbit)) { | |
919 return this_changed; | |
920 } | |
921 // See if x+y can cause negative overflow into z-2**32 | |
922 if (long_ranges_overlap(xlo+ylo, xhi+yhi, zlo-vbit, zhi-vbit)) { | |
923 return this_changed; | |
924 } | |
925 // Now it's always safe to assume x+y does not overflow. | |
926 // This is true even if some pairs x,y might cause overflow, as long | |
927 // as that overflow value cannot fall into [zlo,zhi]. | |
928 | |
929 // Confident that the arithmetic is "as if infinite precision", | |
930 // we can now use z's range to put constraints on those of x and y. | |
931 // The "natural" range of x [xlo,xhi] can perhaps be narrowed to a | |
932 // more "restricted" range by intersecting [xlo,xhi] with the | |
933 // range obtained by subtracting y's range from the asserted range | |
934 // of the I2L conversion. Here's the interval arithmetic algebra: | |
935 // x == z-y == [zlo,zhi]-[ylo,yhi] == [zlo,zhi]+[-yhi,-ylo] | |
936 // => x in [zlo-yhi, zhi-ylo] | |
937 // => x in [zlo-yhi, zhi-ylo] INTERSECT [xlo,xhi] | |
938 // => x in [xlo MAX zlo-yhi, xhi MIN zhi-ylo] | |
939 jlong rxlo = MAX2(xlo, zlo - yhi); | |
940 jlong rxhi = MIN2(xhi, zhi - ylo); | |
941 // And similarly, x changing place with y: | |
942 jlong rylo = MAX2(ylo, zlo - xhi); | |
943 jlong ryhi = MIN2(yhi, zhi - xlo); | |
944 if (rxlo > rxhi || rylo > ryhi) { | |
945 return this_changed; // x or y is dying; don't mess w/ it | |
946 } | |
947 if (op == Op_SubI) { | |
948 jlong rylo0 = rylo; | |
949 rylo = -ryhi; | |
950 ryhi = -rylo0; | |
951 } | |
952 | |
953 Node* cx = phase->transform( new (phase->C, 2) ConvI2LNode(x, TypeLong::make(rxlo, rxhi, widen)) ); | |
954 Node* cy = phase->transform( new (phase->C, 2) ConvI2LNode(y, TypeLong::make(rylo, ryhi, widen)) ); | |
955 switch (op) { | |
956 case Op_AddI: return new (phase->C, 3) AddLNode(cx, cy); | |
957 case Op_SubI: return new (phase->C, 3) SubLNode(cx, cy); | |
958 default: ShouldNotReachHere(); | |
959 } | |
960 } | |
961 #endif //_LP64 | |
962 | |
963 return this_changed; | |
964 } | |
965 | |
966 //============================================================================= | |
967 //------------------------------Value------------------------------------------ | |
968 const Type *ConvL2DNode::Value( PhaseTransform *phase ) const { | |
969 const Type *t = phase->type( in(1) ); | |
970 if( t == Type::TOP ) return Type::TOP; | |
971 const TypeLong *tl = t->is_long(); | |
972 if( tl->is_con() ) return TypeD::make( (double)tl->get_con() ); | |
973 return bottom_type(); | |
974 } | |
975 | |
976 //============================================================================= | |
977 //------------------------------Value------------------------------------------ | |
978 const Type *ConvL2FNode::Value( PhaseTransform *phase ) const { | |
979 const Type *t = phase->type( in(1) ); | |
980 if( t == Type::TOP ) return Type::TOP; | |
981 const TypeLong *tl = t->is_long(); | |
982 if( tl->is_con() ) return TypeF::make( (float)tl->get_con() ); | |
983 return bottom_type(); | |
984 } | |
985 | |
986 //============================================================================= | |
987 //----------------------------Identity----------------------------------------- | |
988 Node *ConvL2INode::Identity( PhaseTransform *phase ) { | |
989 // Convert L2I(I2L(x)) => x | |
990 if (in(1)->Opcode() == Op_ConvI2L) return in(1)->in(1); | |
991 return this; | |
992 } | |
993 | |
994 //------------------------------Value------------------------------------------ | |
995 const Type *ConvL2INode::Value( PhaseTransform *phase ) const { | |
996 const Type *t = phase->type( in(1) ); | |
997 if( t == Type::TOP ) return Type::TOP; | |
998 const TypeLong *tl = t->is_long(); | |
999 if (tl->is_con()) | |
1000 // Easy case. | |
1001 return TypeInt::make((jint)tl->get_con()); | |
1002 return bottom_type(); | |
1003 } | |
1004 | |
1005 //------------------------------Ideal------------------------------------------ | |
1006 // Return a node which is more "ideal" than the current node. | |
1007 // Blow off prior masking to int | |
1008 Node *ConvL2INode::Ideal(PhaseGVN *phase, bool can_reshape) { | |
1009 Node *andl = in(1); | |
1010 uint andl_op = andl->Opcode(); | |
1011 if( andl_op == Op_AndL ) { | |
1012 // Blow off prior masking to int | |
1013 if( phase->type(andl->in(2)) == TypeLong::make( 0xFFFFFFFF ) ) { | |
1014 set_req(1,andl->in(1)); | |
1015 return this; | |
1016 } | |
1017 } | |
1018 | |
1019 // Swap with a prior add: convL2I(addL(x,y)) ==> addI(convL2I(x),convL2I(y)) | |
1020 // This replaces an 'AddL' with an 'AddI'. | |
1021 if( andl_op == Op_AddL ) { | |
1022 // Don't do this for nodes which have more than one user since | |
1023 // we'll end up computing the long add anyway. | |
1024 if (andl->outcnt() > 1) return NULL; | |
1025 | |
1026 Node* x = andl->in(1); | |
1027 Node* y = andl->in(2); | |
1028 assert( x != andl && y != andl, "dead loop in ConvL2INode::Ideal" ); | |
1029 if (phase->type(x) == Type::TOP) return NULL; | |
1030 if (phase->type(y) == Type::TOP) return NULL; | |
1031 Node *add1 = phase->transform(new (phase->C, 2) ConvL2INode(x)); | |
1032 Node *add2 = phase->transform(new (phase->C, 2) ConvL2INode(y)); | |
1033 return new (phase->C, 3) AddINode(add1,add2); | |
1034 } | |
1035 | |
36 | 1036 // Disable optimization: LoadL->ConvL2I ==> LoadI. |
1037 // It causes problems (sizes of Load and Store nodes do not match) | |
1038 // in objects initialization code and Escape Analysis. | |
0 | 1039 return NULL; |
1040 } | |
1041 | |
1042 //============================================================================= | |
1043 //------------------------------Value------------------------------------------ | |
1044 const Type *CastX2PNode::Value( PhaseTransform *phase ) const { | |
1045 const Type* t = phase->type(in(1)); | |
1046 if (t->base() == Type_X && t->singleton()) { | |
1047 uintptr_t bits = (uintptr_t) t->is_intptr_t()->get_con(); | |
1048 if (bits == 0) return TypePtr::NULL_PTR; | |
1049 return TypeRawPtr::make((address) bits); | |
1050 } | |
1051 return CastX2PNode::bottom_type(); | |
1052 } | |
1053 | |
1054 //------------------------------Idealize--------------------------------------- | |
1055 static inline bool fits_in_int(const Type* t, bool but_not_min_int = false) { | |
1056 if (t == Type::TOP) return false; | |
1057 const TypeX* tl = t->is_intptr_t(); | |
1058 jint lo = min_jint; | |
1059 jint hi = max_jint; | |
1060 if (but_not_min_int) ++lo; // caller wants to negate the value w/o overflow | |
1061 return (tl->_lo >= lo) && (tl->_hi <= hi); | |
1062 } | |
1063 | |
1064 static inline Node* addP_of_X2P(PhaseGVN *phase, | |
1065 Node* base, | |
1066 Node* dispX, | |
1067 bool negate = false) { | |
1068 if (negate) { | |
1069 dispX = new (phase->C, 3) SubXNode(phase->MakeConX(0), phase->transform(dispX)); | |
1070 } | |
1071 return new (phase->C, 4) AddPNode(phase->C->top(), | |
1072 phase->transform(new (phase->C, 2) CastX2PNode(base)), | |
1073 phase->transform(dispX)); | |
1074 } | |
1075 | |
1076 Node *CastX2PNode::Ideal(PhaseGVN *phase, bool can_reshape) { | |
1077 // convert CastX2P(AddX(x, y)) to AddP(CastX2P(x), y) if y fits in an int | |
1078 int op = in(1)->Opcode(); | |
1079 Node* x; | |
1080 Node* y; | |
1081 switch (op) { | |
1082 case Op_SubX: | |
1083 x = in(1)->in(1); | |
1084 y = in(1)->in(2); | |
1085 if (fits_in_int(phase->type(y), true)) { | |
1086 return addP_of_X2P(phase, x, y, true); | |
1087 } | |
1088 break; | |
1089 case Op_AddX: | |
1090 x = in(1)->in(1); | |
1091 y = in(1)->in(2); | |
1092 if (fits_in_int(phase->type(y))) { | |
1093 return addP_of_X2P(phase, x, y); | |
1094 } | |
1095 if (fits_in_int(phase->type(x))) { | |
1096 return addP_of_X2P(phase, y, x); | |
1097 } | |
1098 break; | |
1099 } | |
1100 return NULL; | |
1101 } | |
1102 | |
1103 //------------------------------Identity--------------------------------------- | |
1104 Node *CastX2PNode::Identity( PhaseTransform *phase ) { | |
1105 if (in(1)->Opcode() == Op_CastP2X) return in(1)->in(1); | |
1106 return this; | |
1107 } | |
1108 | |
1109 //============================================================================= | |
1110 //------------------------------Value------------------------------------------ | |
1111 const Type *CastP2XNode::Value( PhaseTransform *phase ) const { | |
1112 const Type* t = phase->type(in(1)); | |
1113 if (t->base() == Type::RawPtr && t->singleton()) { | |
1114 uintptr_t bits = (uintptr_t) t->is_rawptr()->get_con(); | |
1115 return TypeX::make(bits); | |
1116 } | |
1117 return CastP2XNode::bottom_type(); | |
1118 } | |
1119 | |
1120 Node *CastP2XNode::Ideal(PhaseGVN *phase, bool can_reshape) { | |
1121 return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL; | |
1122 } | |
1123 | |
1124 //------------------------------Identity--------------------------------------- | |
1125 Node *CastP2XNode::Identity( PhaseTransform *phase ) { | |
1126 if (in(1)->Opcode() == Op_CastX2P) return in(1)->in(1); | |
1127 return this; | |
1128 } | |
1129 | |
1130 | |
1131 //============================================================================= | |
1132 //------------------------------Identity--------------------------------------- | |
1133 // Remove redundant roundings | |
1134 Node *RoundFloatNode::Identity( PhaseTransform *phase ) { | |
1135 assert(Matcher::strict_fp_requires_explicit_rounding, "should only generate for Intel"); | |
1136 // Do not round constants | |
1137 if (phase->type(in(1))->base() == Type::FloatCon) return in(1); | |
1138 int op = in(1)->Opcode(); | |
1139 // Redundant rounding | |
1140 if( op == Op_RoundFloat ) return in(1); | |
1141 // Already rounded | |
1142 if( op == Op_Parm ) return in(1); | |
1143 if( op == Op_LoadF ) return in(1); | |
1144 return this; | |
1145 } | |
1146 | |
1147 //------------------------------Value------------------------------------------ | |
1148 const Type *RoundFloatNode::Value( PhaseTransform *phase ) const { | |
1149 return phase->type( in(1) ); | |
1150 } | |
1151 | |
1152 //============================================================================= | |
1153 //------------------------------Identity--------------------------------------- | |
1154 // Remove redundant roundings. Incoming arguments are already rounded. | |
1155 Node *RoundDoubleNode::Identity( PhaseTransform *phase ) { | |
1156 assert(Matcher::strict_fp_requires_explicit_rounding, "should only generate for Intel"); | |
1157 // Do not round constants | |
1158 if (phase->type(in(1))->base() == Type::DoubleCon) return in(1); | |
1159 int op = in(1)->Opcode(); | |
1160 // Redundant rounding | |
1161 if( op == Op_RoundDouble ) return in(1); | |
1162 // Already rounded | |
1163 if( op == Op_Parm ) return in(1); | |
1164 if( op == Op_LoadD ) return in(1); | |
1165 if( op == Op_ConvF2D ) return in(1); | |
1166 if( op == Op_ConvI2D ) return in(1); | |
1167 return this; | |
1168 } | |
1169 | |
1170 //------------------------------Value------------------------------------------ | |
1171 const Type *RoundDoubleNode::Value( PhaseTransform *phase ) const { | |
1172 return phase->type( in(1) ); | |
1173 } | |
1174 | |
1175 | |
1176 //============================================================================= | |
1177 // Do not allow value-numbering | |
1178 uint Opaque1Node::hash() const { return NO_HASH; } | |
1179 uint Opaque1Node::cmp( const Node &n ) const { | |
1180 return (&n == this); // Always fail except on self | |
1181 } | |
1182 | |
1183 //------------------------------Identity--------------------------------------- | |
1184 // If _major_progress, then more loop optimizations follow. Do NOT remove | |
1185 // the opaque Node until no more loop ops can happen. Note the timing of | |
1186 // _major_progress; it's set in the major loop optimizations THEN comes the | |
1187 // call to IterGVN and any chance of hitting this code. Hence there's no | |
1188 // phase-ordering problem with stripping Opaque1 in IGVN followed by some | |
1189 // more loop optimizations that require it. | |
1190 Node *Opaque1Node::Identity( PhaseTransform *phase ) { | |
1191 return phase->C->major_progress() ? this : in(1); | |
1192 } | |
1193 | |
1194 //============================================================================= | |
1195 // A node to prevent unwanted optimizations. Allows constant folding. Stops | |
1196 // value-numbering, most Ideal calls or Identity functions. This Node is | |
1197 // specifically designed to prevent the pre-increment value of a loop trip | |
1198 // counter from being live out of the bottom of the loop (hence causing the | |
1199 // pre- and post-increment values both being live and thus requiring an extra | |
1200 // temp register and an extra move). If we "accidentally" optimize through | |
1201 // this kind of a Node, we'll get slightly pessimal, but correct, code. Thus | |
1202 // it's OK to be slightly sloppy on optimizations here. | |
1203 | |
1204 // Do not allow value-numbering | |
1205 uint Opaque2Node::hash() const { return NO_HASH; } | |
1206 uint Opaque2Node::cmp( const Node &n ) const { | |
1207 return (&n == this); // Always fail except on self | |
1208 } | |
1209 | |
1210 | |
1211 //------------------------------Value------------------------------------------ | |
1212 const Type *MoveL2DNode::Value( PhaseTransform *phase ) const { | |
1213 const Type *t = phase->type( in(1) ); | |
1214 if( t == Type::TOP ) return Type::TOP; | |
1215 const TypeLong *tl = t->is_long(); | |
1216 if( !tl->is_con() ) return bottom_type(); | |
1217 JavaValue v; | |
1218 v.set_jlong(tl->get_con()); | |
1219 return TypeD::make( v.get_jdouble() ); | |
1220 } | |
1221 | |
1222 //------------------------------Value------------------------------------------ | |
1223 const Type *MoveI2FNode::Value( PhaseTransform *phase ) const { | |
1224 const Type *t = phase->type( in(1) ); | |
1225 if( t == Type::TOP ) return Type::TOP; | |
1226 const TypeInt *ti = t->is_int(); | |
1227 if( !ti->is_con() ) return bottom_type(); | |
1228 JavaValue v; | |
1229 v.set_jint(ti->get_con()); | |
1230 return TypeF::make( v.get_jfloat() ); | |
1231 } | |
1232 | |
1233 //------------------------------Value------------------------------------------ | |
1234 const Type *MoveF2INode::Value( PhaseTransform *phase ) const { | |
1235 const Type *t = phase->type( in(1) ); | |
1236 if( t == Type::TOP ) return Type::TOP; | |
1237 if( t == Type::FLOAT ) return TypeInt::INT; | |
1238 const TypeF *tf = t->is_float_constant(); | |
1239 JavaValue v; | |
1240 v.set_jfloat(tf->getf()); | |
1241 return TypeInt::make( v.get_jint() ); | |
1242 } | |
1243 | |
1244 //------------------------------Value------------------------------------------ | |
1245 const Type *MoveD2LNode::Value( PhaseTransform *phase ) const { | |
1246 const Type *t = phase->type( in(1) ); | |
1247 if( t == Type::TOP ) return Type::TOP; | |
1248 if( t == Type::DOUBLE ) return TypeLong::LONG; | |
1249 const TypeD *td = t->is_double_constant(); | |
1250 JavaValue v; | |
1251 v.set_jdouble(td->getd()); | |
1252 return TypeLong::make( v.get_jlong() ); | |
1253 } |