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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "opto/addnode.hpp" 27 #include "opto/callnode.hpp" 28 #include "opto/castnode.hpp" 29 #include "opto/connode.hpp" 30 #include "opto/matcher.hpp" 31 #include "opto/phaseX.hpp" 32 #include "opto/subnode.hpp" 33 #include "opto/type.hpp" 34 35 //============================================================================= 36 // If input is already higher or equal to cast type, then this is an identity. 37 Node* ConstraintCastNode::Identity(PhaseGVN* phase) { 38 Node* dom = dominating_cast(phase); 39 if (dom != NULL) { 40 return dom; 41 } 42 if (_carry_dependency) { 43 return this; 44 } 45 return phase->type(in(1))->higher_equal_speculative(_type) ? in(1) : this; 46 } 47 48 //------------------------------Value------------------------------------------ 49 // Take 'join' of input and cast-up type 50 const Type* ConstraintCastNode::Value(PhaseGVN* phase) const { 51 if (in(0) && phase->type(in(0)) == Type::TOP) return Type::TOP; 52 const Type* ft = phase->type(in(1))->filter_speculative(_type); 53 263 return ConstraintCastNode::cmp(n) && ((CastIINode&)n)._range_check_dependency == _range_check_dependency; 264 } 265 266 uint CastIINode::size_of() const { 267 return sizeof(*this); 268 } 269 270 #ifndef PRODUCT 271 void CastIINode::dump_spec(outputStream* st) const { 272 ConstraintCastNode::dump_spec(st); 273 if (_range_check_dependency) { 274 st->print(" range check dependency"); 275 } 276 } 277 #endif 278 279 //============================================================================= 280 //------------------------------Identity--------------------------------------- 281 // If input is already higher or equal to cast type, then this is an identity. 282 Node* CheckCastPPNode::Identity(PhaseGVN* phase) { 283 Node* dom = dominating_cast(phase); 284 if (dom != NULL) { 285 return dom; 286 } 287 if (_carry_dependency) { 288 return this; 289 } 290 // Toned down to rescue meeting at a Phi 3 different oops all implementing 291 // the same interface. CompileTheWorld starting at 502, kd12rc1.zip. 292 return (phase->type(in(1)) == phase->type(this)) ? in(1) : this; 293 } 294 295 //------------------------------Value------------------------------------------ 296 // Take 'join' of input and cast-up type, unless working with an Interface 297 const Type* CheckCastPPNode::Value(PhaseGVN* phase) const { 298 if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP; 299 300 const Type *inn = phase->type(in(1)); 301 if( inn == Type::TOP ) return Type::TOP; // No information yet 302 356 // // history: JOIN used to cause weird corner case bugs 357 // // return (in == TypeOopPtr::NULL_PTR) ? in : _type; 358 // // JOIN picks up NotNull in common instance-of/check-cast idioms, both oops. 359 // // JOIN does not preserve NotNull in other cases, e.g. RawPtr vs InstPtr 360 // const Type *join = in->join(_type); 361 // // Check if join preserved NotNull'ness for pointers 362 // if( join->isa_ptr() && _type->isa_ptr() ) { 363 // TypePtr::PTR join_ptr = join->is_ptr()->_ptr; 364 // TypePtr::PTR type_ptr = _type->is_ptr()->_ptr; 365 // // If there isn't any NotNull'ness to preserve 366 // // OR if join preserved NotNull'ness then return it 367 // if( type_ptr == TypePtr::BotPTR || type_ptr == TypePtr::Null || 368 // join_ptr == TypePtr::NotNull || join_ptr == TypePtr::Constant ) { 369 // return join; 370 // } 371 // // ELSE return same old type as before 372 // return _type; 373 // } 374 // // Not joining two pointers 375 // return join; 376 } 377 378 //============================================================================= 379 //------------------------------Value------------------------------------------ 380 const Type* CastX2PNode::Value(PhaseGVN* phase) const { 381 const Type* t = phase->type(in(1)); 382 if (t == Type::TOP) return Type::TOP; 383 if (t->base() == Type_X && t->singleton()) { 384 uintptr_t bits = (uintptr_t) t->is_intptr_t()->get_con(); 385 if (bits == 0) return TypePtr::NULL_PTR; 386 return TypeRawPtr::make((address) bits); 387 } 388 return CastX2PNode::bottom_type(); 389 } 390 391 //------------------------------Idealize--------------------------------------- 392 static inline bool fits_in_int(const Type* t, bool but_not_min_int = false) { 393 if (t == Type::TOP) return false; 394 const TypeX* tl = t->is_intptr_t(); 395 jint lo = min_jint; | 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "opto/addnode.hpp" 27 #include "opto/callnode.hpp" 28 #include "opto/castnode.hpp" 29 #include "opto/connode.hpp" 30 #include "opto/matcher.hpp" 31 #include "opto/phaseX.hpp" 32 #include "opto/rootnode.hpp" 33 #include "opto/subnode.hpp" 34 #include "opto/type.hpp" 35 #include "opto/valuetypenode.hpp" 36 37 //============================================================================= 38 // If input is already higher or equal to cast type, then this is an identity. 39 Node* ConstraintCastNode::Identity(PhaseGVN* phase) { 40 Node* dom = dominating_cast(phase); 41 if (dom != NULL) { 42 return dom; 43 } 44 if (_carry_dependency) { 45 return this; 46 } 47 return phase->type(in(1))->higher_equal_speculative(_type) ? in(1) : this; 48 } 49 50 //------------------------------Value------------------------------------------ 51 // Take 'join' of input and cast-up type 52 const Type* ConstraintCastNode::Value(PhaseGVN* phase) const { 53 if (in(0) && phase->type(in(0)) == Type::TOP) return Type::TOP; 54 const Type* ft = phase->type(in(1))->filter_speculative(_type); 55 265 return ConstraintCastNode::cmp(n) && ((CastIINode&)n)._range_check_dependency == _range_check_dependency; 266 } 267 268 uint CastIINode::size_of() const { 269 return sizeof(*this); 270 } 271 272 #ifndef PRODUCT 273 void CastIINode::dump_spec(outputStream* st) const { 274 ConstraintCastNode::dump_spec(st); 275 if (_range_check_dependency) { 276 st->print(" range check dependency"); 277 } 278 } 279 #endif 280 281 //============================================================================= 282 //------------------------------Identity--------------------------------------- 283 // If input is already higher or equal to cast type, then this is an identity. 284 Node* CheckCastPPNode::Identity(PhaseGVN* phase) { 285 // This is a value type, its input is a phi. That phi is also a 286 // value type of that same type and its inputs are value types of 287 // the same type: push the cast through the phi. 288 if (phase->is_IterGVN() && 289 in(0) == NULL && 290 type()->isa_valuetypeptr() && 291 in(1) != NULL && 292 in(1)->is_Phi()) { 293 PhaseIterGVN* igvn = phase->is_IterGVN(); 294 Node* phi = in(1); 295 const Type* vtptr = type(); 296 for (uint i = 1; i < phi->req(); i++) { 297 if (phi->in(i) != NULL && !phase->type(phi->in(i))->higher_equal(vtptr)) { 298 Node* cast = phase->transform(new CheckCastPPNode(NULL, phi->in(i), vtptr)); 299 igvn->replace_input_of(phi, i, cast); 300 } 301 } 302 return phi; 303 } 304 305 Node* dom = dominating_cast(phase); 306 if (dom != NULL) { 307 return dom; 308 } 309 if (_carry_dependency) { 310 return this; 311 } 312 // Toned down to rescue meeting at a Phi 3 different oops all implementing 313 // the same interface. CompileTheWorld starting at 502, kd12rc1.zip. 314 return (phase->type(in(1)) == phase->type(this)) ? in(1) : this; 315 } 316 317 //------------------------------Value------------------------------------------ 318 // Take 'join' of input and cast-up type, unless working with an Interface 319 const Type* CheckCastPPNode::Value(PhaseGVN* phase) const { 320 if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP; 321 322 const Type *inn = phase->type(in(1)); 323 if( inn == Type::TOP ) return Type::TOP; // No information yet 324 378 // // history: JOIN used to cause weird corner case bugs 379 // // return (in == TypeOopPtr::NULL_PTR) ? in : _type; 380 // // JOIN picks up NotNull in common instance-of/check-cast idioms, both oops. 381 // // JOIN does not preserve NotNull in other cases, e.g. RawPtr vs InstPtr 382 // const Type *join = in->join(_type); 383 // // Check if join preserved NotNull'ness for pointers 384 // if( join->isa_ptr() && _type->isa_ptr() ) { 385 // TypePtr::PTR join_ptr = join->is_ptr()->_ptr; 386 // TypePtr::PTR type_ptr = _type->is_ptr()->_ptr; 387 // // If there isn't any NotNull'ness to preserve 388 // // OR if join preserved NotNull'ness then return it 389 // if( type_ptr == TypePtr::BotPTR || type_ptr == TypePtr::Null || 390 // join_ptr == TypePtr::NotNull || join_ptr == TypePtr::Constant ) { 391 // return join; 392 // } 393 // // ELSE return same old type as before 394 // return _type; 395 // } 396 // // Not joining two pointers 397 // return join; 398 } 399 400 static void replace_in_uses(PhaseIterGVN *igvn, Node* n, Node* m, uint last) { 401 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) { 402 Node* u = n->fast_out(i); 403 if (u->_idx < last) { 404 assert(n != u && m != u, "cycle!"); 405 igvn->rehash_node_delayed(u); 406 int nb = u->replace_edge(n, m); 407 --i, imax -= nb; 408 } 409 } 410 } 411 412 Node* CheckCastPPNode::Ideal(PhaseGVN *phase, bool can_reshape) { 413 // This is a value type. Its input is the return of a call: the call 414 // returns a value type and we now know its exact type: build a 415 // ValueTypePtrNode from the call. 416 if (can_reshape && 417 in(0) == NULL && 418 phase->C->can_add_value_type_ptr() && 419 type()->isa_valuetypeptr() && 420 in(1) != NULL && in(1)->is_Proj() && 421 in(1)->in(0) != NULL && in(1)->in(0)->is_CallStaticJava() && 422 in(1)->as_Proj()->_con == TypeFunc::Parms) { 423 ciValueKlass* vk = type()->is_valuetypeptr()->value_type()->value_klass(); 424 assert(vk != phase->C->env()->___Value_klass(), "why cast to __Value?"); 425 PhaseIterGVN *igvn = phase->is_IterGVN(); 426 427 if (ValueTypeReturnedAsFields && vk->can_be_returned_as_fields()) { 428 CallNode* call = in(1)->in(0)->as_Call(); 429 // We now know the return type of the call 430 const TypeTuple *range_sig = TypeTuple::make_range(vk, false); 431 const TypeTuple *range_cc = TypeTuple::make_range(vk, true); 432 assert(range_sig != call->_tf->range_sig() && range_cc != call->_tf->range_cc(), "type should change"); 433 call->_tf = TypeFunc::make(call->_tf->domain_sig(), call->_tf->domain_cc(), 434 range_sig, range_cc); 435 phase->set_type(call, call->Value(phase)); 436 437 CallProjections projs; 438 call->extract_projections(&projs, true, true); 439 Node* ctl = projs.fallthrough_catchproj; 440 Node* mem = projs.fallthrough_memproj; 441 Node* io = projs.fallthrough_ioproj; 442 Node* ex_ctl = projs.catchall_catchproj; 443 Node* ex_mem = projs.catchall_memproj; 444 Node* ex_io = projs.catchall_ioproj; 445 446 uint last = phase->C->unique(); 447 448 Node* r = new RegionNode(3); 449 Node* mem_phi = new PhiNode(r, Type::MEMORY, TypePtr::BOTTOM); 450 Node* io_phi = new PhiNode(r, Type::ABIO); 451 452 r->init_req(2, ex_ctl); 453 mem_phi->init_req(2, ex_mem); 454 io_phi->init_req(2, ex_io); 455 456 // We need an oop pointer in case allocation elimination 457 // fails. Allocate a new instance here. 458 Node* javaoop = ValueTypeBaseNode::allocate(type(), ctl, mem, io, 459 call->in(TypeFunc::FramePtr), 460 ex_ctl, ex_mem, ex_io, 461 call->jvms(), igvn); 462 463 464 465 r->init_req(1, ex_ctl); 466 mem_phi->init_req(1, ex_mem); 467 io_phi->init_req(1, ex_io); 468 469 r = igvn->transform(r); 470 mem_phi = igvn->transform(mem_phi); 471 io_phi = igvn->transform(io_phi); 472 473 replace_in_uses(igvn, ex_ctl, r, last); 474 replace_in_uses(igvn, ex_mem, mem_phi, last); 475 replace_in_uses(igvn, ex_io, io_phi, last); 476 477 // Create the ValueTypePtrNode. This will add extra projections 478 // to the call. 479 ValueTypePtrNode* vtptr = ValueTypePtrNode::make(igvn, this); 480 igvn->set_delay_transform(true); // stores can be captured. If 481 // they are the whole subgraph 482 // shouldn't go away. 483 484 // Newly allocated value type must be initialized 485 vtptr->store(igvn, ctl, mem->as_MergeMem(), javaoop); 486 igvn->set_delay_transform(false); 487 vtptr->set_oop(javaoop); 488 489 mem = igvn->transform(mem); 490 replace_in_uses(igvn, projs.fallthrough_catchproj, ctl, last); 491 replace_in_uses(igvn, projs.fallthrough_memproj, mem, last); 492 replace_in_uses(igvn, projs.fallthrough_ioproj, io, last); 493 494 igvn->replace_node(in(1), igvn->transform(vtptr)); 495 496 return this; 497 } else { 498 CallNode* call = in(1)->in(0)->as_Call(); 499 // We now know the return type of the call 500 const TypeTuple *range = TypeTuple::make_range(vk, false); 501 if (range != call->_tf->range_sig()) { 502 // Build the ValueTypePtrNode by loading the fields. Use call 503 // return as oop edge in the ValueTypePtrNode. 504 call->_tf = TypeFunc::make(call->_tf->domain_sig(), call->_tf->domain_cc(), 505 range, range); 506 phase->set_type(call, call->Value(phase)); 507 phase->set_type(in(1), in(1)->Value(phase)); 508 uint last = phase->C->unique(); 509 CallNode* call = in(1)->in(0)->as_Call(); 510 CallProjections projs; 511 call->extract_projections(&projs, true, true); 512 Node* mem = projs.fallthrough_memproj; 513 Node* vtptr = ValueTypePtrNode::make(*phase, mem, in(1)); 514 515 return vtptr; 516 } 517 } 518 } 519 return NULL; 520 } 521 522 //============================================================================= 523 //------------------------------Value------------------------------------------ 524 const Type* CastX2PNode::Value(PhaseGVN* phase) const { 525 const Type* t = phase->type(in(1)); 526 if (t == Type::TOP) return Type::TOP; 527 if (t->base() == Type_X && t->singleton()) { 528 uintptr_t bits = (uintptr_t) t->is_intptr_t()->get_con(); 529 if (bits == 0) return TypePtr::NULL_PTR; 530 return TypeRawPtr::make((address) bits); 531 } 532 return CastX2PNode::bottom_type(); 533 } 534 535 //------------------------------Idealize--------------------------------------- 536 static inline bool fits_in_int(const Type* t, bool but_not_min_int = false) { 537 if (t == Type::TOP) return false; 538 const TypeX* tl = t->is_intptr_t(); 539 jint lo = min_jint; |