1 /* 2 * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 20 * CA 95054 USA or visit www.sun.com if you need additional information or 21 * have any questions. 22 * 23 */ 24 25 // Portions of code courtesy of Clifford Click 26 27 // Optimization - Graph Style 28 29 #include "incls/_precompiled.incl" 30 #include "incls/_type.cpp.incl" 31 32 // Dictionary of types shared among compilations. 33 Dict* Type::_shared_type_dict = NULL; 34 35 // Array which maps compiler types to Basic Types 36 const BasicType Type::_basic_type[Type::lastype] = { 37 T_ILLEGAL, // Bad 38 T_ILLEGAL, // Control 39 T_VOID, // Top 40 T_INT, // Int 41 T_LONG, // Long 42 T_VOID, // Half 43 T_NARROWOOP, // NarrowOop 44 45 T_ILLEGAL, // Tuple 46 T_ARRAY, // Array 47 48 T_ADDRESS, // AnyPtr // shows up in factory methods for NULL_PTR 49 T_ADDRESS, // RawPtr 50 T_OBJECT, // OopPtr 51 T_OBJECT, // InstPtr 52 T_OBJECT, // AryPtr 53 T_OBJECT, // KlassPtr 54 55 T_OBJECT, // Function 56 T_ILLEGAL, // Abio 57 T_ADDRESS, // Return_Address 58 T_ILLEGAL, // Memory 59 T_FLOAT, // FloatTop 60 T_FLOAT, // FloatCon 61 T_FLOAT, // FloatBot 62 T_DOUBLE, // DoubleTop 63 T_DOUBLE, // DoubleCon 64 T_DOUBLE, // DoubleBot 65 T_ILLEGAL, // Bottom 66 }; 67 68 // Map ideal registers (machine types) to ideal types 69 const Type *Type::mreg2type[_last_machine_leaf]; 70 71 // Map basic types to canonical Type* pointers. 72 const Type* Type:: _const_basic_type[T_CONFLICT+1]; 73 74 // Map basic types to constant-zero Types. 75 const Type* Type:: _zero_type[T_CONFLICT+1]; 76 77 // Map basic types to array-body alias types. 78 const TypeAryPtr* TypeAryPtr::_array_body_type[T_CONFLICT+1]; 79 80 //============================================================================= 81 // Convenience common pre-built types. 82 const Type *Type::ABIO; // State-of-machine only 83 const Type *Type::BOTTOM; // All values 84 const Type *Type::CONTROL; // Control only 85 const Type *Type::DOUBLE; // All doubles 86 const Type *Type::FLOAT; // All floats 87 const Type *Type::HALF; // Placeholder half of doublewide type 88 const Type *Type::MEMORY; // Abstract store only 89 const Type *Type::RETURN_ADDRESS; 90 const Type *Type::TOP; // No values in set 91 92 //------------------------------get_const_type--------------------------- 93 const Type* Type::get_const_type(ciType* type) { 94 if (type == NULL) { 95 return NULL; 96 } else if (type->is_primitive_type()) { 97 return get_const_basic_type(type->basic_type()); 98 } else { 99 return TypeOopPtr::make_from_klass(type->as_klass()); 100 } 101 } 102 103 //---------------------------array_element_basic_type--------------------------------- 104 // Mapping to the array element's basic type. 105 BasicType Type::array_element_basic_type() const { 106 BasicType bt = basic_type(); 107 if (bt == T_INT) { 108 if (this == TypeInt::INT) return T_INT; 109 if (this == TypeInt::CHAR) return T_CHAR; 110 if (this == TypeInt::BYTE) return T_BYTE; 111 if (this == TypeInt::BOOL) return T_BOOLEAN; 112 if (this == TypeInt::SHORT) return T_SHORT; 113 return T_VOID; 114 } 115 return bt; 116 } 117 118 //---------------------------get_typeflow_type--------------------------------- 119 // Import a type produced by ciTypeFlow. 120 const Type* Type::get_typeflow_type(ciType* type) { 121 switch (type->basic_type()) { 122 123 case ciTypeFlow::StateVector::T_BOTTOM: 124 assert(type == ciTypeFlow::StateVector::bottom_type(), ""); 125 return Type::BOTTOM; 126 127 case ciTypeFlow::StateVector::T_TOP: 128 assert(type == ciTypeFlow::StateVector::top_type(), ""); 129 return Type::TOP; 130 131 case ciTypeFlow::StateVector::T_NULL: 132 assert(type == ciTypeFlow::StateVector::null_type(), ""); 133 return TypePtr::NULL_PTR; 134 135 case ciTypeFlow::StateVector::T_LONG2: 136 // The ciTypeFlow pass pushes a long, then the half. 137 // We do the same. 138 assert(type == ciTypeFlow::StateVector::long2_type(), ""); 139 return TypeInt::TOP; 140 141 case ciTypeFlow::StateVector::T_DOUBLE2: 142 // The ciTypeFlow pass pushes double, then the half. 143 // Our convention is the same. 144 assert(type == ciTypeFlow::StateVector::double2_type(), ""); 145 return Type::TOP; 146 147 case T_ADDRESS: 148 assert(type->is_return_address(), ""); 149 return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci()); 150 151 default: 152 // make sure we did not mix up the cases: 153 assert(type != ciTypeFlow::StateVector::bottom_type(), ""); 154 assert(type != ciTypeFlow::StateVector::top_type(), ""); 155 assert(type != ciTypeFlow::StateVector::null_type(), ""); 156 assert(type != ciTypeFlow::StateVector::long2_type(), ""); 157 assert(type != ciTypeFlow::StateVector::double2_type(), ""); 158 assert(!type->is_return_address(), ""); 159 160 return Type::get_const_type(type); 161 } 162 } 163 164 165 //------------------------------make------------------------------------------- 166 // Create a simple Type, with default empty symbol sets. Then hashcons it 167 // and look for an existing copy in the type dictionary. 168 const Type *Type::make( enum TYPES t ) { 169 return (new Type(t))->hashcons(); 170 } 171 172 //------------------------------cmp-------------------------------------------- 173 int Type::cmp( const Type *const t1, const Type *const t2 ) { 174 if( t1->_base != t2->_base ) 175 return 1; // Missed badly 176 assert(t1 != t2 || t1->eq(t2), "eq must be reflexive"); 177 return !t1->eq(t2); // Return ZERO if equal 178 } 179 180 //------------------------------hash------------------------------------------- 181 int Type::uhash( const Type *const t ) { 182 return t->hash(); 183 } 184 185 //--------------------------Initialize_shared---------------------------------- 186 void Type::Initialize_shared(Compile* current) { 187 // This method does not need to be locked because the first system 188 // compilations (stub compilations) occur serially. If they are 189 // changed to proceed in parallel, then this section will need 190 // locking. 191 192 Arena* save = current->type_arena(); 193 Arena* shared_type_arena = new Arena(); 194 195 current->set_type_arena(shared_type_arena); 196 _shared_type_dict = 197 new (shared_type_arena) Dict( (CmpKey)Type::cmp, (Hash)Type::uhash, 198 shared_type_arena, 128 ); 199 current->set_type_dict(_shared_type_dict); 200 201 // Make shared pre-built types. 202 CONTROL = make(Control); // Control only 203 TOP = make(Top); // No values in set 204 MEMORY = make(Memory); // Abstract store only 205 ABIO = make(Abio); // State-of-machine only 206 RETURN_ADDRESS=make(Return_Address); 207 FLOAT = make(FloatBot); // All floats 208 DOUBLE = make(DoubleBot); // All doubles 209 BOTTOM = make(Bottom); // Everything 210 HALF = make(Half); // Placeholder half of doublewide type 211 212 TypeF::ZERO = TypeF::make(0.0); // Float 0 (positive zero) 213 TypeF::ONE = TypeF::make(1.0); // Float 1 214 215 TypeD::ZERO = TypeD::make(0.0); // Double 0 (positive zero) 216 TypeD::ONE = TypeD::make(1.0); // Double 1 217 218 TypeInt::MINUS_1 = TypeInt::make(-1); // -1 219 TypeInt::ZERO = TypeInt::make( 0); // 0 220 TypeInt::ONE = TypeInt::make( 1); // 1 221 TypeInt::BOOL = TypeInt::make(0,1, WidenMin); // 0 or 1, FALSE or TRUE. 222 TypeInt::CC = TypeInt::make(-1, 1, WidenMin); // -1, 0 or 1, condition codes 223 TypeInt::CC_LT = TypeInt::make(-1,-1, WidenMin); // == TypeInt::MINUS_1 224 TypeInt::CC_GT = TypeInt::make( 1, 1, WidenMin); // == TypeInt::ONE 225 TypeInt::CC_EQ = TypeInt::make( 0, 0, WidenMin); // == TypeInt::ZERO 226 TypeInt::CC_LE = TypeInt::make(-1, 0, WidenMin); 227 TypeInt::CC_GE = TypeInt::make( 0, 1, WidenMin); // == TypeInt::BOOL 228 TypeInt::BYTE = TypeInt::make(-128,127, WidenMin); // Bytes 229 TypeInt::UBYTE = TypeInt::make(0, 255, WidenMin); // Unsigned Bytes 230 TypeInt::CHAR = TypeInt::make(0,65535, WidenMin); // Java chars 231 TypeInt::SHORT = TypeInt::make(-32768,32767, WidenMin); // Java shorts 232 TypeInt::POS = TypeInt::make(0,max_jint, WidenMin); // Non-neg values 233 TypeInt::POS1 = TypeInt::make(1,max_jint, WidenMin); // Positive values 234 TypeInt::INT = TypeInt::make(min_jint,max_jint, WidenMax); // 32-bit integers 235 TypeInt::SYMINT = TypeInt::make(-max_jint,max_jint,WidenMin); // symmetric range 236 // CmpL is overloaded both as the bytecode computation returning 237 // a trinary (-1,0,+1) integer result AND as an efficient long 238 // compare returning optimizer ideal-type flags. 239 assert( TypeInt::CC_LT == TypeInt::MINUS_1, "types must match for CmpL to work" ); 240 assert( TypeInt::CC_GT == TypeInt::ONE, "types must match for CmpL to work" ); 241 assert( TypeInt::CC_EQ == TypeInt::ZERO, "types must match for CmpL to work" ); 242 assert( TypeInt::CC_GE == TypeInt::BOOL, "types must match for CmpL to work" ); 243 244 TypeLong::MINUS_1 = TypeLong::make(-1); // -1 245 TypeLong::ZERO = TypeLong::make( 0); // 0 246 TypeLong::ONE = TypeLong::make( 1); // 1 247 TypeLong::POS = TypeLong::make(0,max_jlong, WidenMin); // Non-neg values 248 TypeLong::LONG = TypeLong::make(min_jlong,max_jlong,WidenMax); // 64-bit integers 249 TypeLong::INT = TypeLong::make((jlong)min_jint,(jlong)max_jint,WidenMin); 250 TypeLong::UINT = TypeLong::make(0,(jlong)max_juint,WidenMin); 251 252 const Type **fboth =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*)); 253 fboth[0] = Type::CONTROL; 254 fboth[1] = Type::CONTROL; 255 TypeTuple::IFBOTH = TypeTuple::make( 2, fboth ); 256 257 const Type **ffalse =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*)); 258 ffalse[0] = Type::CONTROL; 259 ffalse[1] = Type::TOP; 260 TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse ); 261 262 const Type **fneither =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*)); 263 fneither[0] = Type::TOP; 264 fneither[1] = Type::TOP; 265 TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither ); 266 267 const Type **ftrue =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*)); 268 ftrue[0] = Type::TOP; 269 ftrue[1] = Type::CONTROL; 270 TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue ); 271 272 const Type **floop =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*)); 273 floop[0] = Type::CONTROL; 274 floop[1] = TypeInt::INT; 275 TypeTuple::LOOPBODY = TypeTuple::make( 2, floop ); 276 277 TypePtr::NULL_PTR= TypePtr::make( AnyPtr, TypePtr::Null, 0 ); 278 TypePtr::NOTNULL = TypePtr::make( AnyPtr, TypePtr::NotNull, OffsetBot ); 279 TypePtr::BOTTOM = TypePtr::make( AnyPtr, TypePtr::BotPTR, OffsetBot ); 280 281 TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR ); 282 TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull ); 283 284 const Type **fmembar = TypeTuple::fields(0); 285 TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar); 286 287 const Type **fsc = (const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*)); 288 fsc[0] = TypeInt::CC; 289 fsc[1] = Type::MEMORY; 290 TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc); 291 292 TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass()); 293 TypeInstPtr::BOTTOM = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass()); 294 TypeInstPtr::MIRROR = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass()); 295 TypeInstPtr::MARK = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(), 296 false, 0, oopDesc::mark_offset_in_bytes()); 297 TypeInstPtr::KLASS = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(), 298 false, 0, oopDesc::klass_offset_in_bytes()); 299 TypeOopPtr::BOTTOM = TypeOopPtr::make(TypePtr::BotPTR, OffsetBot); 300 301 TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR ); 302 TypeNarrowOop::BOTTOM = TypeNarrowOop::make( TypeInstPtr::BOTTOM ); 303 304 mreg2type[Op_Node] = Type::BOTTOM; 305 mreg2type[Op_Set ] = 0; 306 mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM; 307 mreg2type[Op_RegI] = TypeInt::INT; 308 mreg2type[Op_RegP] = TypePtr::BOTTOM; 309 mreg2type[Op_RegF] = Type::FLOAT; 310 mreg2type[Op_RegD] = Type::DOUBLE; 311 mreg2type[Op_RegL] = TypeLong::LONG; 312 mreg2type[Op_RegFlags] = TypeInt::CC; 313 314 TypeAryPtr::RANGE = TypeAryPtr::make( TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), current->env()->Object_klass(), false, arrayOopDesc::length_offset_in_bytes()); 315 316 TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS), NULL /*ciArrayKlass::make(o)*/, false, Type::OffsetBot); 317 318 #ifdef _LP64 319 if (UseCompressedOops) { 320 TypeAryPtr::OOPS = TypeAryPtr::NARROWOOPS; 321 } else 322 #endif 323 { 324 // There is no shared klass for Object[]. See note in TypeAryPtr::klass(). 325 TypeAryPtr::OOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS), NULL /*ciArrayKlass::make(o)*/, false, Type::OffsetBot); 326 } 327 TypeAryPtr::BYTES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE ,TypeInt::POS), ciTypeArrayKlass::make(T_BYTE), true, Type::OffsetBot); 328 TypeAryPtr::SHORTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT ,TypeInt::POS), ciTypeArrayKlass::make(T_SHORT), true, Type::OffsetBot); 329 TypeAryPtr::CHARS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR ,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR), true, Type::OffsetBot); 330 TypeAryPtr::INTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT ,TypeInt::POS), ciTypeArrayKlass::make(T_INT), true, Type::OffsetBot); 331 TypeAryPtr::LONGS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG ,TypeInt::POS), ciTypeArrayKlass::make(T_LONG), true, Type::OffsetBot); 332 TypeAryPtr::FLOATS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT ,TypeInt::POS), ciTypeArrayKlass::make(T_FLOAT), true, Type::OffsetBot); 333 TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE ,TypeInt::POS), ciTypeArrayKlass::make(T_DOUBLE), true, Type::OffsetBot); 334 335 // Nobody should ask _array_body_type[T_NARROWOOP]. Use NULL as assert. 336 TypeAryPtr::_array_body_type[T_NARROWOOP] = NULL; 337 TypeAryPtr::_array_body_type[T_OBJECT] = TypeAryPtr::OOPS; 338 TypeAryPtr::_array_body_type[T_ARRAY] = TypeAryPtr::OOPS; // arrays are stored in oop arrays 339 TypeAryPtr::_array_body_type[T_BYTE] = TypeAryPtr::BYTES; 340 TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES; // boolean[] is a byte array 341 TypeAryPtr::_array_body_type[T_SHORT] = TypeAryPtr::SHORTS; 342 TypeAryPtr::_array_body_type[T_CHAR] = TypeAryPtr::CHARS; 343 TypeAryPtr::_array_body_type[T_INT] = TypeAryPtr::INTS; 344 TypeAryPtr::_array_body_type[T_LONG] = TypeAryPtr::LONGS; 345 TypeAryPtr::_array_body_type[T_FLOAT] = TypeAryPtr::FLOATS; 346 TypeAryPtr::_array_body_type[T_DOUBLE] = TypeAryPtr::DOUBLES; 347 348 TypeKlassPtr::OBJECT = TypeKlassPtr::make( TypePtr::NotNull, current->env()->Object_klass(), 0 ); 349 TypeKlassPtr::OBJECT_OR_NULL = TypeKlassPtr::make( TypePtr::BotPTR, current->env()->Object_klass(), 0 ); 350 351 const Type **fi2c = TypeTuple::fields(2); 352 fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // methodOop 353 fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer 354 TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c); 355 356 const Type **intpair = TypeTuple::fields(2); 357 intpair[0] = TypeInt::INT; 358 intpair[1] = TypeInt::INT; 359 TypeTuple::INT_PAIR = TypeTuple::make(2, intpair); 360 361 const Type **longpair = TypeTuple::fields(2); 362 longpair[0] = TypeLong::LONG; 363 longpair[1] = TypeLong::LONG; 364 TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair); 365 366 _const_basic_type[T_NARROWOOP] = TypeNarrowOop::BOTTOM; 367 _const_basic_type[T_BOOLEAN] = TypeInt::BOOL; 368 _const_basic_type[T_CHAR] = TypeInt::CHAR; 369 _const_basic_type[T_BYTE] = TypeInt::BYTE; 370 _const_basic_type[T_SHORT] = TypeInt::SHORT; 371 _const_basic_type[T_INT] = TypeInt::INT; 372 _const_basic_type[T_LONG] = TypeLong::LONG; 373 _const_basic_type[T_FLOAT] = Type::FLOAT; 374 _const_basic_type[T_DOUBLE] = Type::DOUBLE; 375 _const_basic_type[T_OBJECT] = TypeInstPtr::BOTTOM; 376 _const_basic_type[T_ARRAY] = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays 377 _const_basic_type[T_VOID] = TypePtr::NULL_PTR; // reflection represents void this way 378 _const_basic_type[T_ADDRESS] = TypeRawPtr::BOTTOM; // both interpreter return addresses & random raw ptrs 379 _const_basic_type[T_CONFLICT]= Type::BOTTOM; // why not? 380 381 _zero_type[T_NARROWOOP] = TypeNarrowOop::NULL_PTR; 382 _zero_type[T_BOOLEAN] = TypeInt::ZERO; // false == 0 383 _zero_type[T_CHAR] = TypeInt::ZERO; // '\0' == 0 384 _zero_type[T_BYTE] = TypeInt::ZERO; // 0x00 == 0 385 _zero_type[T_SHORT] = TypeInt::ZERO; // 0x0000 == 0 386 _zero_type[T_INT] = TypeInt::ZERO; 387 _zero_type[T_LONG] = TypeLong::ZERO; 388 _zero_type[T_FLOAT] = TypeF::ZERO; 389 _zero_type[T_DOUBLE] = TypeD::ZERO; 390 _zero_type[T_OBJECT] = TypePtr::NULL_PTR; 391 _zero_type[T_ARRAY] = TypePtr::NULL_PTR; // null array is null oop 392 _zero_type[T_ADDRESS] = TypePtr::NULL_PTR; // raw pointers use the same null 393 _zero_type[T_VOID] = Type::TOP; // the only void value is no value at all 394 395 // get_zero_type() should not happen for T_CONFLICT 396 _zero_type[T_CONFLICT]= NULL; 397 398 // Restore working type arena. 399 current->set_type_arena(save); 400 current->set_type_dict(NULL); 401 } 402 403 //------------------------------Initialize------------------------------------- 404 void Type::Initialize(Compile* current) { 405 assert(current->type_arena() != NULL, "must have created type arena"); 406 407 if (_shared_type_dict == NULL) { 408 Initialize_shared(current); 409 } 410 411 Arena* type_arena = current->type_arena(); 412 413 // Create the hash-cons'ing dictionary with top-level storage allocation 414 Dict *tdic = new (type_arena) Dict( (CmpKey)Type::cmp,(Hash)Type::uhash, type_arena, 128 ); 415 current->set_type_dict(tdic); 416 417 // Transfer the shared types. 418 DictI i(_shared_type_dict); 419 for( ; i.test(); ++i ) { 420 Type* t = (Type*)i._value; 421 tdic->Insert(t,t); // New Type, insert into Type table 422 } 423 424 #ifdef ASSERT 425 verify_lastype(); 426 #endif 427 } 428 429 //------------------------------hashcons--------------------------------------- 430 // Do the hash-cons trick. If the Type already exists in the type table, 431 // delete the current Type and return the existing Type. Otherwise stick the 432 // current Type in the Type table. 433 const Type *Type::hashcons(void) { 434 debug_only(base()); // Check the assertion in Type::base(). 435 // Look up the Type in the Type dictionary 436 Dict *tdic = type_dict(); 437 Type* old = (Type*)(tdic->Insert(this, this, false)); 438 if( old ) { // Pre-existing Type? 439 if( old != this ) // Yes, this guy is not the pre-existing? 440 delete this; // Yes, Nuke this guy 441 assert( old->_dual, "" ); 442 return old; // Return pre-existing 443 } 444 445 // Every type has a dual (to make my lattice symmetric). 446 // Since we just discovered a new Type, compute its dual right now. 447 assert( !_dual, "" ); // No dual yet 448 _dual = xdual(); // Compute the dual 449 if( cmp(this,_dual)==0 ) { // Handle self-symmetric 450 _dual = this; 451 return this; 452 } 453 assert( !_dual->_dual, "" ); // No reverse dual yet 454 assert( !(*tdic)[_dual], "" ); // Dual not in type system either 455 // New Type, insert into Type table 456 tdic->Insert((void*)_dual,(void*)_dual); 457 ((Type*)_dual)->_dual = this; // Finish up being symmetric 458 #ifdef ASSERT 459 Type *dual_dual = (Type*)_dual->xdual(); 460 assert( eq(dual_dual), "xdual(xdual()) should be identity" ); 461 delete dual_dual; 462 #endif 463 return this; // Return new Type 464 } 465 466 //------------------------------eq--------------------------------------------- 467 // Structural equality check for Type representations 468 bool Type::eq( const Type * ) const { 469 return true; // Nothing else can go wrong 470 } 471 472 //------------------------------hash------------------------------------------- 473 // Type-specific hashing function. 474 int Type::hash(void) const { 475 return _base; 476 } 477 478 //------------------------------is_finite-------------------------------------- 479 // Has a finite value 480 bool Type::is_finite() const { 481 return false; 482 } 483 484 //------------------------------is_nan----------------------------------------- 485 // Is not a number (NaN) 486 bool Type::is_nan() const { 487 return false; 488 } 489 490 //----------------------interface_vs_oop--------------------------------------- 491 #ifdef ASSERT 492 bool Type::interface_vs_oop(const Type *t) const { 493 bool result = false; 494 495 const TypeInstPtr* this_inst = this->isa_instptr(); 496 const TypeInstPtr* t_inst = t->isa_instptr(); 497 if( this_inst && this_inst->is_loaded() && t_inst && t_inst->is_loaded() ) { 498 bool this_interface = this_inst->klass()->is_interface(); 499 bool t_interface = t_inst->klass()->is_interface(); 500 result = this_interface ^ t_interface; 501 } 502 503 return result; 504 } 505 #endif 506 507 //------------------------------meet------------------------------------------- 508 // Compute the MEET of two types. NOT virtual. It enforces that meet is 509 // commutative and the lattice is symmetric. 510 const Type *Type::meet( const Type *t ) const { 511 if (isa_narrowoop() && t->isa_narrowoop()) { 512 const Type* result = make_ptr()->meet(t->make_ptr()); 513 return result->make_narrowoop(); 514 } 515 516 const Type *mt = xmeet(t); 517 if (isa_narrowoop() || t->isa_narrowoop()) return mt; 518 #ifdef ASSERT 519 assert( mt == t->xmeet(this), "meet not commutative" ); 520 const Type* dual_join = mt->_dual; 521 const Type *t2t = dual_join->xmeet(t->_dual); 522 const Type *t2this = dual_join->xmeet( _dual); 523 524 // Interface meet Oop is Not Symmetric: 525 // Interface:AnyNull meet Oop:AnyNull == Interface:AnyNull 526 // Interface:NotNull meet Oop:NotNull == java/lang/Object:NotNull 527 528 if( !interface_vs_oop(t) && (t2t != t->_dual || t2this != _dual) ) { 529 tty->print_cr("=== Meet Not Symmetric ==="); 530 tty->print("t = "); t->dump(); tty->cr(); 531 tty->print("this= "); dump(); tty->cr(); 532 tty->print("mt=(t meet this)= "); mt->dump(); tty->cr(); 533 534 tty->print("t_dual= "); t->_dual->dump(); tty->cr(); 535 tty->print("this_dual= "); _dual->dump(); tty->cr(); 536 tty->print("mt_dual= "); mt->_dual->dump(); tty->cr(); 537 538 tty->print("mt_dual meet t_dual= "); t2t ->dump(); tty->cr(); 539 tty->print("mt_dual meet this_dual= "); t2this ->dump(); tty->cr(); 540 541 fatal("meet not symmetric" ); 542 } 543 #endif 544 return mt; 545 } 546 547 //------------------------------xmeet------------------------------------------ 548 // Compute the MEET of two types. It returns a new Type object. 549 const Type *Type::xmeet( const Type *t ) const { 550 // Perform a fast test for common case; meeting the same types together. 551 if( this == t ) return this; // Meeting same type-rep? 552 553 // Meeting TOP with anything? 554 if( _base == Top ) return t; 555 556 // Meeting BOTTOM with anything? 557 if( _base == Bottom ) return BOTTOM; 558 559 // Current "this->_base" is one of: Bad, Multi, Control, Top, 560 // Abio, Abstore, Floatxxx, Doublexxx, Bottom, lastype. 561 switch (t->base()) { // Switch on original type 562 563 // Cut in half the number of cases I must handle. Only need cases for when 564 // the given enum "t->type" is less than or equal to the local enum "type". 565 case FloatCon: 566 case DoubleCon: 567 case Int: 568 case Long: 569 return t->xmeet(this); 570 571 case OopPtr: 572 return t->xmeet(this); 573 574 case InstPtr: 575 return t->xmeet(this); 576 577 case KlassPtr: 578 return t->xmeet(this); 579 580 case AryPtr: 581 return t->xmeet(this); 582 583 case NarrowOop: 584 return t->xmeet(this); 585 586 case Bad: // Type check 587 default: // Bogus type not in lattice 588 typerr(t); 589 return Type::BOTTOM; 590 591 case Bottom: // Ye Olde Default 592 return t; 593 594 case FloatTop: 595 if( _base == FloatTop ) return this; 596 case FloatBot: // Float 597 if( _base == FloatBot || _base == FloatTop ) return FLOAT; 598 if( _base == DoubleTop || _base == DoubleBot ) return Type::BOTTOM; 599 typerr(t); 600 return Type::BOTTOM; 601 602 case DoubleTop: 603 if( _base == DoubleTop ) return this; 604 case DoubleBot: // Double 605 if( _base == DoubleBot || _base == DoubleTop ) return DOUBLE; 606 if( _base == FloatTop || _base == FloatBot ) return Type::BOTTOM; 607 typerr(t); 608 return Type::BOTTOM; 609 610 // These next few cases must match exactly or it is a compile-time error. 611 case Control: // Control of code 612 case Abio: // State of world outside of program 613 case Memory: 614 if( _base == t->_base ) return this; 615 typerr(t); 616 return Type::BOTTOM; 617 618 case Top: // Top of the lattice 619 return this; 620 } 621 622 // The type is unchanged 623 return this; 624 } 625 626 //-----------------------------filter------------------------------------------ 627 const Type *Type::filter( const Type *kills ) const { 628 const Type* ft = join(kills); 629 if (ft->empty()) 630 return Type::TOP; // Canonical empty value 631 return ft; 632 } 633 634 //------------------------------xdual------------------------------------------ 635 // Compute dual right now. 636 const Type::TYPES Type::dual_type[Type::lastype] = { 637 Bad, // Bad 638 Control, // Control 639 Bottom, // Top 640 Bad, // Int - handled in v-call 641 Bad, // Long - handled in v-call 642 Half, // Half 643 Bad, // NarrowOop - handled in v-call 644 645 Bad, // Tuple - handled in v-call 646 Bad, // Array - handled in v-call 647 648 Bad, // AnyPtr - handled in v-call 649 Bad, // RawPtr - handled in v-call 650 Bad, // OopPtr - handled in v-call 651 Bad, // InstPtr - handled in v-call 652 Bad, // AryPtr - handled in v-call 653 Bad, // KlassPtr - handled in v-call 654 655 Bad, // Function - handled in v-call 656 Abio, // Abio 657 Return_Address,// Return_Address 658 Memory, // Memory 659 FloatBot, // FloatTop 660 FloatCon, // FloatCon 661 FloatTop, // FloatBot 662 DoubleBot, // DoubleTop 663 DoubleCon, // DoubleCon 664 DoubleTop, // DoubleBot 665 Top // Bottom 666 }; 667 668 const Type *Type::xdual() const { 669 // Note: the base() accessor asserts the sanity of _base. 670 assert(dual_type[base()] != Bad, "implement with v-call"); 671 return new Type(dual_type[_base]); 672 } 673 674 //------------------------------has_memory------------------------------------- 675 bool Type::has_memory() const { 676 Type::TYPES tx = base(); 677 if (tx == Memory) return true; 678 if (tx == Tuple) { 679 const TypeTuple *t = is_tuple(); 680 for (uint i=0; i < t->cnt(); i++) { 681 tx = t->field_at(i)->base(); 682 if (tx == Memory) return true; 683 } 684 } 685 return false; 686 } 687 688 #ifndef PRODUCT 689 //------------------------------dump2------------------------------------------ 690 void Type::dump2( Dict &d, uint depth, outputStream *st ) const { 691 st->print(msg[_base]); 692 } 693 694 //------------------------------dump------------------------------------------- 695 void Type::dump_on(outputStream *st) const { 696 ResourceMark rm; 697 Dict d(cmpkey,hashkey); // Stop recursive type dumping 698 dump2(d,1, st); 699 if (is_ptr_to_narrowoop()) { 700 st->print(" [narrow]"); 701 } 702 } 703 704 //------------------------------data------------------------------------------- 705 const char * const Type::msg[Type::lastype] = { 706 "bad","control","top","int:","long:","half", "narrowoop:", 707 "tuple:", "aryptr", 708 "anyptr:", "rawptr:", "java:", "inst:", "ary:", "klass:", 709 "func", "abIO", "return_address", "memory", 710 "float_top", "ftcon:", "float", 711 "double_top", "dblcon:", "double", 712 "bottom" 713 }; 714 #endif 715 716 //------------------------------singleton-------------------------------------- 717 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 718 // constants (Ldi nodes). Singletons are integer, float or double constants. 719 bool Type::singleton(void) const { 720 return _base == Top || _base == Half; 721 } 722 723 //------------------------------empty------------------------------------------ 724 // TRUE if Type is a type with no values, FALSE otherwise. 725 bool Type::empty(void) const { 726 switch (_base) { 727 case DoubleTop: 728 case FloatTop: 729 case Top: 730 return true; 731 732 case Half: 733 case Abio: 734 case Return_Address: 735 case Memory: 736 case Bottom: 737 case FloatBot: 738 case DoubleBot: 739 return false; // never a singleton, therefore never empty 740 } 741 742 ShouldNotReachHere(); 743 return false; 744 } 745 746 //------------------------------dump_stats------------------------------------- 747 // Dump collected statistics to stderr 748 #ifndef PRODUCT 749 void Type::dump_stats() { 750 tty->print("Types made: %d\n", type_dict()->Size()); 751 } 752 #endif 753 754 //------------------------------typerr----------------------------------------- 755 void Type::typerr( const Type *t ) const { 756 #ifndef PRODUCT 757 tty->print("\nError mixing types: "); 758 dump(); 759 tty->print(" and "); 760 t->dump(); 761 tty->print("\n"); 762 #endif 763 ShouldNotReachHere(); 764 } 765 766 //------------------------------isa_oop_ptr------------------------------------ 767 // Return true if type is an oop pointer type. False for raw pointers. 768 static char isa_oop_ptr_tbl[Type::lastype] = { 769 0,0,0,0,0,0,0/*narrowoop*/,0/*tuple*/, 0/*ary*/, 770 0/*anyptr*/,0/*rawptr*/,1/*OopPtr*/,1/*InstPtr*/,1/*AryPtr*/,1/*KlassPtr*/, 771 0/*func*/,0,0/*return_address*/,0, 772 /*floats*/0,0,0, /*doubles*/0,0,0, 773 0 774 }; 775 bool Type::isa_oop_ptr() const { 776 return isa_oop_ptr_tbl[_base] != 0; 777 } 778 779 //------------------------------dump_stats------------------------------------- 780 // // Check that arrays match type enum 781 #ifndef PRODUCT 782 void Type::verify_lastype() { 783 // Check that arrays match enumeration 784 assert( Type::dual_type [Type::lastype - 1] == Type::Top, "did not update array"); 785 assert( strcmp(Type::msg [Type::lastype - 1],"bottom") == 0, "did not update array"); 786 // assert( PhiNode::tbl [Type::lastype - 1] == NULL, "did not update array"); 787 assert( Matcher::base2reg[Type::lastype - 1] == 0, "did not update array"); 788 assert( isa_oop_ptr_tbl [Type::lastype - 1] == (char)0, "did not update array"); 789 } 790 #endif 791 792 //============================================================================= 793 // Convenience common pre-built types. 794 const TypeF *TypeF::ZERO; // Floating point zero 795 const TypeF *TypeF::ONE; // Floating point one 796 797 //------------------------------make------------------------------------------- 798 // Create a float constant 799 const TypeF *TypeF::make(float f) { 800 return (TypeF*)(new TypeF(f))->hashcons(); 801 } 802 803 //------------------------------meet------------------------------------------- 804 // Compute the MEET of two types. It returns a new Type object. 805 const Type *TypeF::xmeet( const Type *t ) const { 806 // Perform a fast test for common case; meeting the same types together. 807 if( this == t ) return this; // Meeting same type-rep? 808 809 // Current "this->_base" is FloatCon 810 switch (t->base()) { // Switch on original type 811 case AnyPtr: // Mixing with oops happens when javac 812 case RawPtr: // reuses local variables 813 case OopPtr: 814 case InstPtr: 815 case KlassPtr: 816 case AryPtr: 817 case NarrowOop: 818 case Int: 819 case Long: 820 case DoubleTop: 821 case DoubleCon: 822 case DoubleBot: 823 case Bottom: // Ye Olde Default 824 return Type::BOTTOM; 825 826 case FloatBot: 827 return t; 828 829 default: // All else is a mistake 830 typerr(t); 831 832 case FloatCon: // Float-constant vs Float-constant? 833 if( jint_cast(_f) != jint_cast(t->getf()) ) // unequal constants? 834 // must compare bitwise as positive zero, negative zero and NaN have 835 // all the same representation in C++ 836 return FLOAT; // Return generic float 837 // Equal constants 838 case Top: 839 case FloatTop: 840 break; // Return the float constant 841 } 842 return this; // Return the float constant 843 } 844 845 //------------------------------xdual------------------------------------------ 846 // Dual: symmetric 847 const Type *TypeF::xdual() const { 848 return this; 849 } 850 851 //------------------------------eq--------------------------------------------- 852 // Structural equality check for Type representations 853 bool TypeF::eq( const Type *t ) const { 854 if( g_isnan(_f) || 855 g_isnan(t->getf()) ) { 856 // One or both are NANs. If both are NANs return true, else false. 857 return (g_isnan(_f) && g_isnan(t->getf())); 858 } 859 if (_f == t->getf()) { 860 // (NaN is impossible at this point, since it is not equal even to itself) 861 if (_f == 0.0) { 862 // difference between positive and negative zero 863 if (jint_cast(_f) != jint_cast(t->getf())) return false; 864 } 865 return true; 866 } 867 return false; 868 } 869 870 //------------------------------hash------------------------------------------- 871 // Type-specific hashing function. 872 int TypeF::hash(void) const { 873 return *(int*)(&_f); 874 } 875 876 //------------------------------is_finite-------------------------------------- 877 // Has a finite value 878 bool TypeF::is_finite() const { 879 return g_isfinite(getf()) != 0; 880 } 881 882 //------------------------------is_nan----------------------------------------- 883 // Is not a number (NaN) 884 bool TypeF::is_nan() const { 885 return g_isnan(getf()) != 0; 886 } 887 888 //------------------------------dump2------------------------------------------ 889 // Dump float constant Type 890 #ifndef PRODUCT 891 void TypeF::dump2( Dict &d, uint depth, outputStream *st ) const { 892 Type::dump2(d,depth, st); 893 st->print("%f", _f); 894 } 895 #endif 896 897 //------------------------------singleton-------------------------------------- 898 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 899 // constants (Ldi nodes). Singletons are integer, float or double constants 900 // or a single symbol. 901 bool TypeF::singleton(void) const { 902 return true; // Always a singleton 903 } 904 905 bool TypeF::empty(void) const { 906 return false; // always exactly a singleton 907 } 908 909 //============================================================================= 910 // Convenience common pre-built types. 911 const TypeD *TypeD::ZERO; // Floating point zero 912 const TypeD *TypeD::ONE; // Floating point one 913 914 //------------------------------make------------------------------------------- 915 const TypeD *TypeD::make(double d) { 916 return (TypeD*)(new TypeD(d))->hashcons(); 917 } 918 919 //------------------------------meet------------------------------------------- 920 // Compute the MEET of two types. It returns a new Type object. 921 const Type *TypeD::xmeet( const Type *t ) const { 922 // Perform a fast test for common case; meeting the same types together. 923 if( this == t ) return this; // Meeting same type-rep? 924 925 // Current "this->_base" is DoubleCon 926 switch (t->base()) { // Switch on original type 927 case AnyPtr: // Mixing with oops happens when javac 928 case RawPtr: // reuses local variables 929 case OopPtr: 930 case InstPtr: 931 case KlassPtr: 932 case AryPtr: 933 case NarrowOop: 934 case Int: 935 case Long: 936 case FloatTop: 937 case FloatCon: 938 case FloatBot: 939 case Bottom: // Ye Olde Default 940 return Type::BOTTOM; 941 942 case DoubleBot: 943 return t; 944 945 default: // All else is a mistake 946 typerr(t); 947 948 case DoubleCon: // Double-constant vs Double-constant? 949 if( jlong_cast(_d) != jlong_cast(t->getd()) ) // unequal constants? (see comment in TypeF::xmeet) 950 return DOUBLE; // Return generic double 951 case Top: 952 case DoubleTop: 953 break; 954 } 955 return this; // Return the double constant 956 } 957 958 //------------------------------xdual------------------------------------------ 959 // Dual: symmetric 960 const Type *TypeD::xdual() const { 961 return this; 962 } 963 964 //------------------------------eq--------------------------------------------- 965 // Structural equality check for Type representations 966 bool TypeD::eq( const Type *t ) const { 967 if( g_isnan(_d) || 968 g_isnan(t->getd()) ) { 969 // One or both are NANs. If both are NANs return true, else false. 970 return (g_isnan(_d) && g_isnan(t->getd())); 971 } 972 if (_d == t->getd()) { 973 // (NaN is impossible at this point, since it is not equal even to itself) 974 if (_d == 0.0) { 975 // difference between positive and negative zero 976 if (jlong_cast(_d) != jlong_cast(t->getd())) return false; 977 } 978 return true; 979 } 980 return false; 981 } 982 983 //------------------------------hash------------------------------------------- 984 // Type-specific hashing function. 985 int TypeD::hash(void) const { 986 return *(int*)(&_d); 987 } 988 989 //------------------------------is_finite-------------------------------------- 990 // Has a finite value 991 bool TypeD::is_finite() const { 992 return g_isfinite(getd()) != 0; 993 } 994 995 //------------------------------is_nan----------------------------------------- 996 // Is not a number (NaN) 997 bool TypeD::is_nan() const { 998 return g_isnan(getd()) != 0; 999 } 1000 1001 //------------------------------dump2------------------------------------------ 1002 // Dump double constant Type 1003 #ifndef PRODUCT 1004 void TypeD::dump2( Dict &d, uint depth, outputStream *st ) const { 1005 Type::dump2(d,depth,st); 1006 st->print("%f", _d); 1007 } 1008 #endif 1009 1010 //------------------------------singleton-------------------------------------- 1011 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 1012 // constants (Ldi nodes). Singletons are integer, float or double constants 1013 // or a single symbol. 1014 bool TypeD::singleton(void) const { 1015 return true; // Always a singleton 1016 } 1017 1018 bool TypeD::empty(void) const { 1019 return false; // always exactly a singleton 1020 } 1021 1022 //============================================================================= 1023 // Convience common pre-built types. 1024 const TypeInt *TypeInt::MINUS_1;// -1 1025 const TypeInt *TypeInt::ZERO; // 0 1026 const TypeInt *TypeInt::ONE; // 1 1027 const TypeInt *TypeInt::BOOL; // 0 or 1, FALSE or TRUE. 1028 const TypeInt *TypeInt::CC; // -1,0 or 1, condition codes 1029 const TypeInt *TypeInt::CC_LT; // [-1] == MINUS_1 1030 const TypeInt *TypeInt::CC_GT; // [1] == ONE 1031 const TypeInt *TypeInt::CC_EQ; // [0] == ZERO 1032 const TypeInt *TypeInt::CC_LE; // [-1,0] 1033 const TypeInt *TypeInt::CC_GE; // [0,1] == BOOL (!) 1034 const TypeInt *TypeInt::BYTE; // Bytes, -128 to 127 1035 const TypeInt *TypeInt::UBYTE; // Unsigned Bytes, 0 to 255 1036 const TypeInt *TypeInt::CHAR; // Java chars, 0-65535 1037 const TypeInt *TypeInt::SHORT; // Java shorts, -32768-32767 1038 const TypeInt *TypeInt::POS; // Positive 32-bit integers or zero 1039 const TypeInt *TypeInt::POS1; // Positive 32-bit integers 1040 const TypeInt *TypeInt::INT; // 32-bit integers 1041 const TypeInt *TypeInt::SYMINT; // symmetric range [-max_jint..max_jint] 1042 1043 //------------------------------TypeInt---------------------------------------- 1044 TypeInt::TypeInt( jint lo, jint hi, int w ) : Type(Int), _lo(lo), _hi(hi), _widen(w) { 1045 } 1046 1047 //------------------------------make------------------------------------------- 1048 const TypeInt *TypeInt::make( jint lo ) { 1049 return (TypeInt*)(new TypeInt(lo,lo,WidenMin))->hashcons(); 1050 } 1051 1052 #define SMALLINT ((juint)3) // a value too insignificant to consider widening 1053 1054 const TypeInt *TypeInt::make( jint lo, jint hi, int w ) { 1055 // Certain normalizations keep us sane when comparing types. 1056 // The 'SMALLINT' covers constants and also CC and its relatives. 1057 assert(CC == NULL || (juint)(CC->_hi - CC->_lo) <= SMALLINT, "CC is truly small"); 1058 if (lo <= hi) { 1059 if ((juint)(hi - lo) <= SMALLINT) w = Type::WidenMin; 1060 if ((juint)(hi - lo) >= max_juint) w = Type::WidenMax; // plain int 1061 } 1062 return (TypeInt*)(new TypeInt(lo,hi,w))->hashcons(); 1063 } 1064 1065 //------------------------------meet------------------------------------------- 1066 // Compute the MEET of two types. It returns a new Type representation object 1067 // with reference count equal to the number of Types pointing at it. 1068 // Caller should wrap a Types around it. 1069 const Type *TypeInt::xmeet( const Type *t ) const { 1070 // Perform a fast test for common case; meeting the same types together. 1071 if( this == t ) return this; // Meeting same type? 1072 1073 // Currently "this->_base" is a TypeInt 1074 switch (t->base()) { // Switch on original type 1075 case AnyPtr: // Mixing with oops happens when javac 1076 case RawPtr: // reuses local variables 1077 case OopPtr: 1078 case InstPtr: 1079 case KlassPtr: 1080 case AryPtr: 1081 case NarrowOop: 1082 case Long: 1083 case FloatTop: 1084 case FloatCon: 1085 case FloatBot: 1086 case DoubleTop: 1087 case DoubleCon: 1088 case DoubleBot: 1089 case Bottom: // Ye Olde Default 1090 return Type::BOTTOM; 1091 default: // All else is a mistake 1092 typerr(t); 1093 case Top: // No change 1094 return this; 1095 case Int: // Int vs Int? 1096 break; 1097 } 1098 1099 // Expand covered set 1100 const TypeInt *r = t->is_int(); 1101 // (Avoid TypeInt::make, to avoid the argument normalizations it enforces.) 1102 return (new TypeInt( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) ))->hashcons(); 1103 } 1104 1105 //------------------------------xdual------------------------------------------ 1106 // Dual: reverse hi & lo; flip widen 1107 const Type *TypeInt::xdual() const { 1108 return new TypeInt(_hi,_lo,WidenMax-_widen); 1109 } 1110 1111 //------------------------------widen------------------------------------------ 1112 // Only happens for optimistic top-down optimizations. 1113 const Type *TypeInt::widen( const Type *old ) const { 1114 // Coming from TOP or such; no widening 1115 if( old->base() != Int ) return this; 1116 const TypeInt *ot = old->is_int(); 1117 1118 // If new guy is equal to old guy, no widening 1119 if( _lo == ot->_lo && _hi == ot->_hi ) 1120 return old; 1121 1122 // If new guy contains old, then we widened 1123 if( _lo <= ot->_lo && _hi >= ot->_hi ) { 1124 // New contains old 1125 // If new guy is already wider than old, no widening 1126 if( _widen > ot->_widen ) return this; 1127 // If old guy was a constant, do not bother 1128 if (ot->_lo == ot->_hi) return this; 1129 // Now widen new guy. 1130 // Check for widening too far 1131 if (_widen == WidenMax) { 1132 if (min_jint < _lo && _hi < max_jint) { 1133 // If neither endpoint is extremal yet, push out the endpoint 1134 // which is closer to its respective limit. 1135 if (_lo >= 0 || // easy common case 1136 (juint)(_lo - min_jint) >= (juint)(max_jint - _hi)) { 1137 // Try to widen to an unsigned range type of 31 bits: 1138 return make(_lo, max_jint, WidenMax); 1139 } else { 1140 return make(min_jint, _hi, WidenMax); 1141 } 1142 } 1143 return TypeInt::INT; 1144 } 1145 // Returned widened new guy 1146 return make(_lo,_hi,_widen+1); 1147 } 1148 1149 // If old guy contains new, then we probably widened too far & dropped to 1150 // bottom. Return the wider fellow. 1151 if ( ot->_lo <= _lo && ot->_hi >= _hi ) 1152 return old; 1153 1154 //fatal("Integer value range is not subset"); 1155 //return this; 1156 return TypeInt::INT; 1157 } 1158 1159 //------------------------------narrow--------------------------------------- 1160 // Only happens for pessimistic optimizations. 1161 const Type *TypeInt::narrow( const Type *old ) const { 1162 if (_lo >= _hi) return this; // already narrow enough 1163 if (old == NULL) return this; 1164 const TypeInt* ot = old->isa_int(); 1165 if (ot == NULL) return this; 1166 jint olo = ot->_lo; 1167 jint ohi = ot->_hi; 1168 1169 // If new guy is equal to old guy, no narrowing 1170 if (_lo == olo && _hi == ohi) return old; 1171 1172 // If old guy was maximum range, allow the narrowing 1173 if (olo == min_jint && ohi == max_jint) return this; 1174 1175 if (_lo < olo || _hi > ohi) 1176 return this; // doesn't narrow; pretty wierd 1177 1178 // The new type narrows the old type, so look for a "death march". 1179 // See comments on PhaseTransform::saturate. 1180 juint nrange = _hi - _lo; 1181 juint orange = ohi - olo; 1182 if (nrange < max_juint - 1 && nrange > (orange >> 1) + (SMALLINT*2)) { 1183 // Use the new type only if the range shrinks a lot. 1184 // We do not want the optimizer computing 2^31 point by point. 1185 return old; 1186 } 1187 1188 return this; 1189 } 1190 1191 //-----------------------------filter------------------------------------------ 1192 const Type *TypeInt::filter( const Type *kills ) const { 1193 const TypeInt* ft = join(kills)->isa_int(); 1194 if (ft == NULL || ft->_lo > ft->_hi) 1195 return Type::TOP; // Canonical empty value 1196 if (ft->_widen < this->_widen) { 1197 // Do not allow the value of kill->_widen to affect the outcome. 1198 // The widen bits must be allowed to run freely through the graph. 1199 ft = TypeInt::make(ft->_lo, ft->_hi, this->_widen); 1200 } 1201 return ft; 1202 } 1203 1204 //------------------------------eq--------------------------------------------- 1205 // Structural equality check for Type representations 1206 bool TypeInt::eq( const Type *t ) const { 1207 const TypeInt *r = t->is_int(); // Handy access 1208 return r->_lo == _lo && r->_hi == _hi && r->_widen == _widen; 1209 } 1210 1211 //------------------------------hash------------------------------------------- 1212 // Type-specific hashing function. 1213 int TypeInt::hash(void) const { 1214 return _lo+_hi+_widen+(int)Type::Int; 1215 } 1216 1217 //------------------------------is_finite-------------------------------------- 1218 // Has a finite value 1219 bool TypeInt::is_finite() const { 1220 return true; 1221 } 1222 1223 //------------------------------dump2------------------------------------------ 1224 // Dump TypeInt 1225 #ifndef PRODUCT 1226 static const char* intname(char* buf, jint n) { 1227 if (n == min_jint) 1228 return "min"; 1229 else if (n < min_jint + 10000) 1230 sprintf(buf, "min+" INT32_FORMAT, n - min_jint); 1231 else if (n == max_jint) 1232 return "max"; 1233 else if (n > max_jint - 10000) 1234 sprintf(buf, "max-" INT32_FORMAT, max_jint - n); 1235 else 1236 sprintf(buf, INT32_FORMAT, n); 1237 return buf; 1238 } 1239 1240 void TypeInt::dump2( Dict &d, uint depth, outputStream *st ) const { 1241 char buf[40], buf2[40]; 1242 if (_lo == min_jint && _hi == max_jint) 1243 st->print("int"); 1244 else if (is_con()) 1245 st->print("int:%s", intname(buf, get_con())); 1246 else if (_lo == BOOL->_lo && _hi == BOOL->_hi) 1247 st->print("bool"); 1248 else if (_lo == BYTE->_lo && _hi == BYTE->_hi) 1249 st->print("byte"); 1250 else if (_lo == CHAR->_lo && _hi == CHAR->_hi) 1251 st->print("char"); 1252 else if (_lo == SHORT->_lo && _hi == SHORT->_hi) 1253 st->print("short"); 1254 else if (_hi == max_jint) 1255 st->print("int:>=%s", intname(buf, _lo)); 1256 else if (_lo == min_jint) 1257 st->print("int:<=%s", intname(buf, _hi)); 1258 else 1259 st->print("int:%s..%s", intname(buf, _lo), intname(buf2, _hi)); 1260 1261 if (_widen != 0 && this != TypeInt::INT) 1262 st->print(":%.*s", _widen, "wwww"); 1263 } 1264 #endif 1265 1266 //------------------------------singleton-------------------------------------- 1267 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 1268 // constants. 1269 bool TypeInt::singleton(void) const { 1270 return _lo >= _hi; 1271 } 1272 1273 bool TypeInt::empty(void) const { 1274 return _lo > _hi; 1275 } 1276 1277 //============================================================================= 1278 // Convenience common pre-built types. 1279 const TypeLong *TypeLong::MINUS_1;// -1 1280 const TypeLong *TypeLong::ZERO; // 0 1281 const TypeLong *TypeLong::ONE; // 1 1282 const TypeLong *TypeLong::POS; // >=0 1283 const TypeLong *TypeLong::LONG; // 64-bit integers 1284 const TypeLong *TypeLong::INT; // 32-bit subrange 1285 const TypeLong *TypeLong::UINT; // 32-bit unsigned subrange 1286 1287 //------------------------------TypeLong--------------------------------------- 1288 TypeLong::TypeLong( jlong lo, jlong hi, int w ) : Type(Long), _lo(lo), _hi(hi), _widen(w) { 1289 } 1290 1291 //------------------------------make------------------------------------------- 1292 const TypeLong *TypeLong::make( jlong lo ) { 1293 return (TypeLong*)(new TypeLong(lo,lo,WidenMin))->hashcons(); 1294 } 1295 1296 const TypeLong *TypeLong::make( jlong lo, jlong hi, int w ) { 1297 // Certain normalizations keep us sane when comparing types. 1298 // The '1' covers constants. 1299 if (lo <= hi) { 1300 if ((julong)(hi - lo) <= SMALLINT) w = Type::WidenMin; 1301 if ((julong)(hi - lo) >= max_julong) w = Type::WidenMax; // plain long 1302 } 1303 return (TypeLong*)(new TypeLong(lo,hi,w))->hashcons(); 1304 } 1305 1306 1307 //------------------------------meet------------------------------------------- 1308 // Compute the MEET of two types. It returns a new Type representation object 1309 // with reference count equal to the number of Types pointing at it. 1310 // Caller should wrap a Types around it. 1311 const Type *TypeLong::xmeet( const Type *t ) const { 1312 // Perform a fast test for common case; meeting the same types together. 1313 if( this == t ) return this; // Meeting same type? 1314 1315 // Currently "this->_base" is a TypeLong 1316 switch (t->base()) { // Switch on original type 1317 case AnyPtr: // Mixing with oops happens when javac 1318 case RawPtr: // reuses local variables 1319 case OopPtr: 1320 case InstPtr: 1321 case KlassPtr: 1322 case AryPtr: 1323 case NarrowOop: 1324 case Int: 1325 case FloatTop: 1326 case FloatCon: 1327 case FloatBot: 1328 case DoubleTop: 1329 case DoubleCon: 1330 case DoubleBot: 1331 case Bottom: // Ye Olde Default 1332 return Type::BOTTOM; 1333 default: // All else is a mistake 1334 typerr(t); 1335 case Top: // No change 1336 return this; 1337 case Long: // Long vs Long? 1338 break; 1339 } 1340 1341 // Expand covered set 1342 const TypeLong *r = t->is_long(); // Turn into a TypeLong 1343 // (Avoid TypeLong::make, to avoid the argument normalizations it enforces.) 1344 return (new TypeLong( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) ))->hashcons(); 1345 } 1346 1347 //------------------------------xdual------------------------------------------ 1348 // Dual: reverse hi & lo; flip widen 1349 const Type *TypeLong::xdual() const { 1350 return new TypeLong(_hi,_lo,WidenMax-_widen); 1351 } 1352 1353 //------------------------------widen------------------------------------------ 1354 // Only happens for optimistic top-down optimizations. 1355 const Type *TypeLong::widen( const Type *old ) const { 1356 // Coming from TOP or such; no widening 1357 if( old->base() != Long ) return this; 1358 const TypeLong *ot = old->is_long(); 1359 1360 // If new guy is equal to old guy, no widening 1361 if( _lo == ot->_lo && _hi == ot->_hi ) 1362 return old; 1363 1364 // If new guy contains old, then we widened 1365 if( _lo <= ot->_lo && _hi >= ot->_hi ) { 1366 // New contains old 1367 // If new guy is already wider than old, no widening 1368 if( _widen > ot->_widen ) return this; 1369 // If old guy was a constant, do not bother 1370 if (ot->_lo == ot->_hi) return this; 1371 // Now widen new guy. 1372 // Check for widening too far 1373 if (_widen == WidenMax) { 1374 if (min_jlong < _lo && _hi < max_jlong) { 1375 // If neither endpoint is extremal yet, push out the endpoint 1376 // which is closer to its respective limit. 1377 if (_lo >= 0 || // easy common case 1378 (julong)(_lo - min_jlong) >= (julong)(max_jlong - _hi)) { 1379 // Try to widen to an unsigned range type of 32/63 bits: 1380 if (_hi < max_juint) 1381 return make(_lo, max_juint, WidenMax); 1382 else 1383 return make(_lo, max_jlong, WidenMax); 1384 } else { 1385 return make(min_jlong, _hi, WidenMax); 1386 } 1387 } 1388 return TypeLong::LONG; 1389 } 1390 // Returned widened new guy 1391 return make(_lo,_hi,_widen+1); 1392 } 1393 1394 // If old guy contains new, then we probably widened too far & dropped to 1395 // bottom. Return the wider fellow. 1396 if ( ot->_lo <= _lo && ot->_hi >= _hi ) 1397 return old; 1398 1399 // fatal("Long value range is not subset"); 1400 // return this; 1401 return TypeLong::LONG; 1402 } 1403 1404 //------------------------------narrow---------------------------------------- 1405 // Only happens for pessimistic optimizations. 1406 const Type *TypeLong::narrow( const Type *old ) const { 1407 if (_lo >= _hi) return this; // already narrow enough 1408 if (old == NULL) return this; 1409 const TypeLong* ot = old->isa_long(); 1410 if (ot == NULL) return this; 1411 jlong olo = ot->_lo; 1412 jlong ohi = ot->_hi; 1413 1414 // If new guy is equal to old guy, no narrowing 1415 if (_lo == olo && _hi == ohi) return old; 1416 1417 // If old guy was maximum range, allow the narrowing 1418 if (olo == min_jlong && ohi == max_jlong) return this; 1419 1420 if (_lo < olo || _hi > ohi) 1421 return this; // doesn't narrow; pretty wierd 1422 1423 // The new type narrows the old type, so look for a "death march". 1424 // See comments on PhaseTransform::saturate. 1425 julong nrange = _hi - _lo; 1426 julong orange = ohi - olo; 1427 if (nrange < max_julong - 1 && nrange > (orange >> 1) + (SMALLINT*2)) { 1428 // Use the new type only if the range shrinks a lot. 1429 // We do not want the optimizer computing 2^31 point by point. 1430 return old; 1431 } 1432 1433 return this; 1434 } 1435 1436 //-----------------------------filter------------------------------------------ 1437 const Type *TypeLong::filter( const Type *kills ) const { 1438 const TypeLong* ft = join(kills)->isa_long(); 1439 if (ft == NULL || ft->_lo > ft->_hi) 1440 return Type::TOP; // Canonical empty value 1441 if (ft->_widen < this->_widen) { 1442 // Do not allow the value of kill->_widen to affect the outcome. 1443 // The widen bits must be allowed to run freely through the graph. 1444 ft = TypeLong::make(ft->_lo, ft->_hi, this->_widen); 1445 } 1446 return ft; 1447 } 1448 1449 //------------------------------eq--------------------------------------------- 1450 // Structural equality check for Type representations 1451 bool TypeLong::eq( const Type *t ) const { 1452 const TypeLong *r = t->is_long(); // Handy access 1453 return r->_lo == _lo && r->_hi == _hi && r->_widen == _widen; 1454 } 1455 1456 //------------------------------hash------------------------------------------- 1457 // Type-specific hashing function. 1458 int TypeLong::hash(void) const { 1459 return (int)(_lo+_hi+_widen+(int)Type::Long); 1460 } 1461 1462 //------------------------------is_finite-------------------------------------- 1463 // Has a finite value 1464 bool TypeLong::is_finite() const { 1465 return true; 1466 } 1467 1468 //------------------------------dump2------------------------------------------ 1469 // Dump TypeLong 1470 #ifndef PRODUCT 1471 static const char* longnamenear(jlong x, const char* xname, char* buf, jlong n) { 1472 if (n > x) { 1473 if (n >= x + 10000) return NULL; 1474 sprintf(buf, "%s+" INT64_FORMAT, xname, n - x); 1475 } else if (n < x) { 1476 if (n <= x - 10000) return NULL; 1477 sprintf(buf, "%s-" INT64_FORMAT, xname, x - n); 1478 } else { 1479 return xname; 1480 } 1481 return buf; 1482 } 1483 1484 static const char* longname(char* buf, jlong n) { 1485 const char* str; 1486 if (n == min_jlong) 1487 return "min"; 1488 else if (n < min_jlong + 10000) 1489 sprintf(buf, "min+" INT64_FORMAT, n - min_jlong); 1490 else if (n == max_jlong) 1491 return "max"; 1492 else if (n > max_jlong - 10000) 1493 sprintf(buf, "max-" INT64_FORMAT, max_jlong - n); 1494 else if ((str = longnamenear(max_juint, "maxuint", buf, n)) != NULL) 1495 return str; 1496 else if ((str = longnamenear(max_jint, "maxint", buf, n)) != NULL) 1497 return str; 1498 else if ((str = longnamenear(min_jint, "minint", buf, n)) != NULL) 1499 return str; 1500 else 1501 sprintf(buf, INT64_FORMAT, n); 1502 return buf; 1503 } 1504 1505 void TypeLong::dump2( Dict &d, uint depth, outputStream *st ) const { 1506 char buf[80], buf2[80]; 1507 if (_lo == min_jlong && _hi == max_jlong) 1508 st->print("long"); 1509 else if (is_con()) 1510 st->print("long:%s", longname(buf, get_con())); 1511 else if (_hi == max_jlong) 1512 st->print("long:>=%s", longname(buf, _lo)); 1513 else if (_lo == min_jlong) 1514 st->print("long:<=%s", longname(buf, _hi)); 1515 else 1516 st->print("long:%s..%s", longname(buf, _lo), longname(buf2, _hi)); 1517 1518 if (_widen != 0 && this != TypeLong::LONG) 1519 st->print(":%.*s", _widen, "wwww"); 1520 } 1521 #endif 1522 1523 //------------------------------singleton-------------------------------------- 1524 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 1525 // constants 1526 bool TypeLong::singleton(void) const { 1527 return _lo >= _hi; 1528 } 1529 1530 bool TypeLong::empty(void) const { 1531 return _lo > _hi; 1532 } 1533 1534 //============================================================================= 1535 // Convenience common pre-built types. 1536 const TypeTuple *TypeTuple::IFBOTH; // Return both arms of IF as reachable 1537 const TypeTuple *TypeTuple::IFFALSE; 1538 const TypeTuple *TypeTuple::IFTRUE; 1539 const TypeTuple *TypeTuple::IFNEITHER; 1540 const TypeTuple *TypeTuple::LOOPBODY; 1541 const TypeTuple *TypeTuple::MEMBAR; 1542 const TypeTuple *TypeTuple::STORECONDITIONAL; 1543 const TypeTuple *TypeTuple::START_I2C; 1544 const TypeTuple *TypeTuple::INT_PAIR; 1545 const TypeTuple *TypeTuple::LONG_PAIR; 1546 1547 1548 //------------------------------make------------------------------------------- 1549 // Make a TypeTuple from the range of a method signature 1550 const TypeTuple *TypeTuple::make_range(ciSignature* sig) { 1551 ciType* return_type = sig->return_type(); 1552 uint total_fields = TypeFunc::Parms + return_type->size(); 1553 const Type **field_array = fields(total_fields); 1554 switch (return_type->basic_type()) { 1555 case T_LONG: 1556 field_array[TypeFunc::Parms] = TypeLong::LONG; 1557 field_array[TypeFunc::Parms+1] = Type::HALF; 1558 break; 1559 case T_DOUBLE: 1560 field_array[TypeFunc::Parms] = Type::DOUBLE; 1561 field_array[TypeFunc::Parms+1] = Type::HALF; 1562 break; 1563 case T_OBJECT: 1564 case T_ARRAY: 1565 case T_BOOLEAN: 1566 case T_CHAR: 1567 case T_FLOAT: 1568 case T_BYTE: 1569 case T_SHORT: 1570 case T_INT: 1571 field_array[TypeFunc::Parms] = get_const_type(return_type); 1572 break; 1573 case T_VOID: 1574 break; 1575 default: 1576 ShouldNotReachHere(); 1577 } 1578 return (TypeTuple*)(new TypeTuple(total_fields,field_array))->hashcons(); 1579 } 1580 1581 // Make a TypeTuple from the domain of a method signature 1582 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig) { 1583 uint total_fields = TypeFunc::Parms + sig->size(); 1584 1585 uint pos = TypeFunc::Parms; 1586 const Type **field_array; 1587 if (recv != NULL) { 1588 total_fields++; 1589 field_array = fields(total_fields); 1590 // Use get_const_type here because it respects UseUniqueSubclasses: 1591 field_array[pos++] = get_const_type(recv)->join(TypePtr::NOTNULL); 1592 } else { 1593 field_array = fields(total_fields); 1594 } 1595 1596 int i = 0; 1597 while (pos < total_fields) { 1598 ciType* type = sig->type_at(i); 1599 1600 switch (type->basic_type()) { 1601 case T_LONG: 1602 field_array[pos++] = TypeLong::LONG; 1603 field_array[pos++] = Type::HALF; 1604 break; 1605 case T_DOUBLE: 1606 field_array[pos++] = Type::DOUBLE; 1607 field_array[pos++] = Type::HALF; 1608 break; 1609 case T_OBJECT: 1610 case T_ARRAY: 1611 case T_BOOLEAN: 1612 case T_CHAR: 1613 case T_FLOAT: 1614 case T_BYTE: 1615 case T_SHORT: 1616 case T_INT: 1617 field_array[pos++] = get_const_type(type); 1618 break; 1619 default: 1620 ShouldNotReachHere(); 1621 } 1622 i++; 1623 } 1624 return (TypeTuple*)(new TypeTuple(total_fields,field_array))->hashcons(); 1625 } 1626 1627 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) { 1628 return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons(); 1629 } 1630 1631 //------------------------------fields----------------------------------------- 1632 // Subroutine call type with space allocated for argument types 1633 const Type **TypeTuple::fields( uint arg_cnt ) { 1634 const Type **flds = (const Type **)(Compile::current()->type_arena()->Amalloc_4((TypeFunc::Parms+arg_cnt)*sizeof(Type*) )); 1635 flds[TypeFunc::Control ] = Type::CONTROL; 1636 flds[TypeFunc::I_O ] = Type::ABIO; 1637 flds[TypeFunc::Memory ] = Type::MEMORY; 1638 flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM; 1639 flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS; 1640 1641 return flds; 1642 } 1643 1644 //------------------------------meet------------------------------------------- 1645 // Compute the MEET of two types. It returns a new Type object. 1646 const Type *TypeTuple::xmeet( const Type *t ) const { 1647 // Perform a fast test for common case; meeting the same types together. 1648 if( this == t ) return this; // Meeting same type-rep? 1649 1650 // Current "this->_base" is Tuple 1651 switch (t->base()) { // switch on original type 1652 1653 case Bottom: // Ye Olde Default 1654 return t; 1655 1656 default: // All else is a mistake 1657 typerr(t); 1658 1659 case Tuple: { // Meeting 2 signatures? 1660 const TypeTuple *x = t->is_tuple(); 1661 assert( _cnt == x->_cnt, "" ); 1662 const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) )); 1663 for( uint i=0; i<_cnt; i++ ) 1664 fields[i] = field_at(i)->xmeet( x->field_at(i) ); 1665 return TypeTuple::make(_cnt,fields); 1666 } 1667 case Top: 1668 break; 1669 } 1670 return this; // Return the double constant 1671 } 1672 1673 //------------------------------xdual------------------------------------------ 1674 // Dual: compute field-by-field dual 1675 const Type *TypeTuple::xdual() const { 1676 const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) )); 1677 for( uint i=0; i<_cnt; i++ ) 1678 fields[i] = _fields[i]->dual(); 1679 return new TypeTuple(_cnt,fields); 1680 } 1681 1682 //------------------------------eq--------------------------------------------- 1683 // Structural equality check for Type representations 1684 bool TypeTuple::eq( const Type *t ) const { 1685 const TypeTuple *s = (const TypeTuple *)t; 1686 if (_cnt != s->_cnt) return false; // Unequal field counts 1687 for (uint i = 0; i < _cnt; i++) 1688 if (field_at(i) != s->field_at(i)) // POINTER COMPARE! NO RECURSION! 1689 return false; // Missed 1690 return true; 1691 } 1692 1693 //------------------------------hash------------------------------------------- 1694 // Type-specific hashing function. 1695 int TypeTuple::hash(void) const { 1696 intptr_t sum = _cnt; 1697 for( uint i=0; i<_cnt; i++ ) 1698 sum += (intptr_t)_fields[i]; // Hash on pointers directly 1699 return sum; 1700 } 1701 1702 //------------------------------dump2------------------------------------------ 1703 // Dump signature Type 1704 #ifndef PRODUCT 1705 void TypeTuple::dump2( Dict &d, uint depth, outputStream *st ) const { 1706 st->print("{"); 1707 if( !depth || d[this] ) { // Check for recursive print 1708 st->print("...}"); 1709 return; 1710 } 1711 d.Insert((void*)this, (void*)this); // Stop recursion 1712 if( _cnt ) { 1713 uint i; 1714 for( i=0; i<_cnt-1; i++ ) { 1715 st->print("%d:", i); 1716 _fields[i]->dump2(d, depth-1, st); 1717 st->print(", "); 1718 } 1719 st->print("%d:", i); 1720 _fields[i]->dump2(d, depth-1, st); 1721 } 1722 st->print("}"); 1723 } 1724 #endif 1725 1726 //------------------------------singleton-------------------------------------- 1727 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 1728 // constants (Ldi nodes). Singletons are integer, float or double constants 1729 // or a single symbol. 1730 bool TypeTuple::singleton(void) const { 1731 return false; // Never a singleton 1732 } 1733 1734 bool TypeTuple::empty(void) const { 1735 for( uint i=0; i<_cnt; i++ ) { 1736 if (_fields[i]->empty()) return true; 1737 } 1738 return false; 1739 } 1740 1741 //============================================================================= 1742 // Convenience common pre-built types. 1743 1744 inline const TypeInt* normalize_array_size(const TypeInt* size) { 1745 // Certain normalizations keep us sane when comparing types. 1746 // We do not want arrayOop variables to differ only by the wideness 1747 // of their index types. Pick minimum wideness, since that is the 1748 // forced wideness of small ranges anyway. 1749 if (size->_widen != Type::WidenMin) 1750 return TypeInt::make(size->_lo, size->_hi, Type::WidenMin); 1751 else 1752 return size; 1753 } 1754 1755 //------------------------------make------------------------------------------- 1756 const TypeAry *TypeAry::make( const Type *elem, const TypeInt *size) { 1757 if (UseCompressedOops && elem->isa_oopptr()) { 1758 elem = elem->make_narrowoop(); 1759 } 1760 size = normalize_array_size(size); 1761 return (TypeAry*)(new TypeAry(elem,size))->hashcons(); 1762 } 1763 1764 //------------------------------meet------------------------------------------- 1765 // Compute the MEET of two types. It returns a new Type object. 1766 const Type *TypeAry::xmeet( const Type *t ) const { 1767 // Perform a fast test for common case; meeting the same types together. 1768 if( this == t ) return this; // Meeting same type-rep? 1769 1770 // Current "this->_base" is Ary 1771 switch (t->base()) { // switch on original type 1772 1773 case Bottom: // Ye Olde Default 1774 return t; 1775 1776 default: // All else is a mistake 1777 typerr(t); 1778 1779 case Array: { // Meeting 2 arrays? 1780 const TypeAry *a = t->is_ary(); 1781 return TypeAry::make(_elem->meet(a->_elem), 1782 _size->xmeet(a->_size)->is_int()); 1783 } 1784 case Top: 1785 break; 1786 } 1787 return this; // Return the double constant 1788 } 1789 1790 //------------------------------xdual------------------------------------------ 1791 // Dual: compute field-by-field dual 1792 const Type *TypeAry::xdual() const { 1793 const TypeInt* size_dual = _size->dual()->is_int(); 1794 size_dual = normalize_array_size(size_dual); 1795 return new TypeAry( _elem->dual(), size_dual); 1796 } 1797 1798 //------------------------------eq--------------------------------------------- 1799 // Structural equality check for Type representations 1800 bool TypeAry::eq( const Type *t ) const { 1801 const TypeAry *a = (const TypeAry*)t; 1802 return _elem == a->_elem && 1803 _size == a->_size; 1804 } 1805 1806 //------------------------------hash------------------------------------------- 1807 // Type-specific hashing function. 1808 int TypeAry::hash(void) const { 1809 return (intptr_t)_elem + (intptr_t)_size; 1810 } 1811 1812 //----------------------interface_vs_oop--------------------------------------- 1813 #ifdef ASSERT 1814 bool TypeAry::interface_vs_oop(const Type *t) const { 1815 const TypeAry* t_ary = t->is_ary(); 1816 if (t_ary) { 1817 return _elem->interface_vs_oop(t_ary->_elem); 1818 } 1819 return false; 1820 } 1821 #endif 1822 1823 //------------------------------dump2------------------------------------------ 1824 #ifndef PRODUCT 1825 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const { 1826 _elem->dump2(d, depth, st); 1827 st->print("["); 1828 _size->dump2(d, depth, st); 1829 st->print("]"); 1830 } 1831 #endif 1832 1833 //------------------------------singleton-------------------------------------- 1834 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 1835 // constants (Ldi nodes). Singletons are integer, float or double constants 1836 // or a single symbol. 1837 bool TypeAry::singleton(void) const { 1838 return false; // Never a singleton 1839 } 1840 1841 bool TypeAry::empty(void) const { 1842 return _elem->empty() || _size->empty(); 1843 } 1844 1845 //--------------------------ary_must_be_exact---------------------------------- 1846 bool TypeAry::ary_must_be_exact() const { 1847 if (!UseExactTypes) return false; 1848 // This logic looks at the element type of an array, and returns true 1849 // if the element type is either a primitive or a final instance class. 1850 // In such cases, an array built on this ary must have no subclasses. 1851 if (_elem == BOTTOM) return false; // general array not exact 1852 if (_elem == TOP ) return false; // inverted general array not exact 1853 const TypeOopPtr* toop = NULL; 1854 if (UseCompressedOops && _elem->isa_narrowoop()) { 1855 toop = _elem->make_ptr()->isa_oopptr(); 1856 } else { 1857 toop = _elem->isa_oopptr(); 1858 } 1859 if (!toop) return true; // a primitive type, like int 1860 ciKlass* tklass = toop->klass(); 1861 if (tklass == NULL) return false; // unloaded class 1862 if (!tklass->is_loaded()) return false; // unloaded class 1863 const TypeInstPtr* tinst; 1864 if (_elem->isa_narrowoop()) 1865 tinst = _elem->make_ptr()->isa_instptr(); 1866 else 1867 tinst = _elem->isa_instptr(); 1868 if (tinst) 1869 return tklass->as_instance_klass()->is_final(); 1870 const TypeAryPtr* tap; 1871 if (_elem->isa_narrowoop()) 1872 tap = _elem->make_ptr()->isa_aryptr(); 1873 else 1874 tap = _elem->isa_aryptr(); 1875 if (tap) 1876 return tap->ary()->ary_must_be_exact(); 1877 return false; 1878 } 1879 1880 //============================================================================= 1881 // Convenience common pre-built types. 1882 const TypePtr *TypePtr::NULL_PTR; 1883 const TypePtr *TypePtr::NOTNULL; 1884 const TypePtr *TypePtr::BOTTOM; 1885 1886 //------------------------------meet------------------------------------------- 1887 // Meet over the PTR enum 1888 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = { 1889 // TopPTR, AnyNull, Constant, Null, NotNull, BotPTR, 1890 { /* Top */ TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,}, 1891 { /* AnyNull */ AnyNull, AnyNull, Constant, BotPTR, NotNull, BotPTR,}, 1892 { /* Constant*/ Constant, Constant, Constant, BotPTR, NotNull, BotPTR,}, 1893 { /* Null */ Null, BotPTR, BotPTR, Null, BotPTR, BotPTR,}, 1894 { /* NotNull */ NotNull, NotNull, NotNull, BotPTR, NotNull, BotPTR,}, 1895 { /* BotPTR */ BotPTR, BotPTR, BotPTR, BotPTR, BotPTR, BotPTR,} 1896 }; 1897 1898 //------------------------------make------------------------------------------- 1899 const TypePtr *TypePtr::make( TYPES t, enum PTR ptr, int offset ) { 1900 return (TypePtr*)(new TypePtr(t,ptr,offset))->hashcons(); 1901 } 1902 1903 //------------------------------cast_to_ptr_type------------------------------- 1904 const Type *TypePtr::cast_to_ptr_type(PTR ptr) const { 1905 assert(_base == AnyPtr, "subclass must override cast_to_ptr_type"); 1906 if( ptr == _ptr ) return this; 1907 return make(_base, ptr, _offset); 1908 } 1909 1910 //------------------------------get_con---------------------------------------- 1911 intptr_t TypePtr::get_con() const { 1912 assert( _ptr == Null, "" ); 1913 return _offset; 1914 } 1915 1916 //------------------------------meet------------------------------------------- 1917 // Compute the MEET of two types. It returns a new Type object. 1918 const Type *TypePtr::xmeet( const Type *t ) const { 1919 // Perform a fast test for common case; meeting the same types together. 1920 if( this == t ) return this; // Meeting same type-rep? 1921 1922 // Current "this->_base" is AnyPtr 1923 switch (t->base()) { // switch on original type 1924 case Int: // Mixing ints & oops happens when javac 1925 case Long: // reuses local variables 1926 case FloatTop: 1927 case FloatCon: 1928 case FloatBot: 1929 case DoubleTop: 1930 case DoubleCon: 1931 case DoubleBot: 1932 case NarrowOop: 1933 case Bottom: // Ye Olde Default 1934 return Type::BOTTOM; 1935 case Top: 1936 return this; 1937 1938 case AnyPtr: { // Meeting to AnyPtrs 1939 const TypePtr *tp = t->is_ptr(); 1940 return make( AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()) ); 1941 } 1942 case RawPtr: // For these, flip the call around to cut down 1943 case OopPtr: 1944 case InstPtr: // on the cases I have to handle. 1945 case KlassPtr: 1946 case AryPtr: 1947 return t->xmeet(this); // Call in reverse direction 1948 default: // All else is a mistake 1949 typerr(t); 1950 1951 } 1952 return this; 1953 } 1954 1955 //------------------------------meet_offset------------------------------------ 1956 int TypePtr::meet_offset( int offset ) const { 1957 // Either is 'TOP' offset? Return the other offset! 1958 if( _offset == OffsetTop ) return offset; 1959 if( offset == OffsetTop ) return _offset; 1960 // If either is different, return 'BOTTOM' offset 1961 if( _offset != offset ) return OffsetBot; 1962 return _offset; 1963 } 1964 1965 //------------------------------dual_offset------------------------------------ 1966 int TypePtr::dual_offset( ) const { 1967 if( _offset == OffsetTop ) return OffsetBot;// Map 'TOP' into 'BOTTOM' 1968 if( _offset == OffsetBot ) return OffsetTop;// Map 'BOTTOM' into 'TOP' 1969 return _offset; // Map everything else into self 1970 } 1971 1972 //------------------------------xdual------------------------------------------ 1973 // Dual: compute field-by-field dual 1974 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = { 1975 BotPTR, NotNull, Constant, Null, AnyNull, TopPTR 1976 }; 1977 const Type *TypePtr::xdual() const { 1978 return new TypePtr( AnyPtr, dual_ptr(), dual_offset() ); 1979 } 1980 1981 //------------------------------xadd_offset------------------------------------ 1982 int TypePtr::xadd_offset( intptr_t offset ) const { 1983 // Adding to 'TOP' offset? Return 'TOP'! 1984 if( _offset == OffsetTop || offset == OffsetTop ) return OffsetTop; 1985 // Adding to 'BOTTOM' offset? Return 'BOTTOM'! 1986 if( _offset == OffsetBot || offset == OffsetBot ) return OffsetBot; 1987 // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'! 1988 offset += (intptr_t)_offset; 1989 if (offset != (int)offset || offset == OffsetTop) return OffsetBot; 1990 1991 // assert( _offset >= 0 && _offset+offset >= 0, "" ); 1992 // It is possible to construct a negative offset during PhaseCCP 1993 1994 return (int)offset; // Sum valid offsets 1995 } 1996 1997 //------------------------------add_offset------------------------------------- 1998 const TypePtr *TypePtr::add_offset( intptr_t offset ) const { 1999 return make( AnyPtr, _ptr, xadd_offset(offset) ); 2000 } 2001 2002 //------------------------------eq--------------------------------------------- 2003 // Structural equality check for Type representations 2004 bool TypePtr::eq( const Type *t ) const { 2005 const TypePtr *a = (const TypePtr*)t; 2006 return _ptr == a->ptr() && _offset == a->offset(); 2007 } 2008 2009 //------------------------------hash------------------------------------------- 2010 // Type-specific hashing function. 2011 int TypePtr::hash(void) const { 2012 return _ptr + _offset; 2013 } 2014 2015 //------------------------------dump2------------------------------------------ 2016 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = { 2017 "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR" 2018 }; 2019 2020 #ifndef PRODUCT 2021 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const { 2022 if( _ptr == Null ) st->print("NULL"); 2023 else st->print("%s *", ptr_msg[_ptr]); 2024 if( _offset == OffsetTop ) st->print("+top"); 2025 else if( _offset == OffsetBot ) st->print("+bot"); 2026 else if( _offset ) st->print("+%d", _offset); 2027 } 2028 #endif 2029 2030 //------------------------------singleton-------------------------------------- 2031 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 2032 // constants 2033 bool TypePtr::singleton(void) const { 2034 // TopPTR, Null, AnyNull, Constant are all singletons 2035 return (_offset != OffsetBot) && !below_centerline(_ptr); 2036 } 2037 2038 bool TypePtr::empty(void) const { 2039 return (_offset == OffsetTop) || above_centerline(_ptr); 2040 } 2041 2042 //============================================================================= 2043 // Convenience common pre-built types. 2044 const TypeRawPtr *TypeRawPtr::BOTTOM; 2045 const TypeRawPtr *TypeRawPtr::NOTNULL; 2046 2047 //------------------------------make------------------------------------------- 2048 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) { 2049 assert( ptr != Constant, "what is the constant?" ); 2050 assert( ptr != Null, "Use TypePtr for NULL" ); 2051 return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons(); 2052 } 2053 2054 const TypeRawPtr *TypeRawPtr::make( address bits ) { 2055 assert( bits, "Use TypePtr for NULL" ); 2056 return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons(); 2057 } 2058 2059 //------------------------------cast_to_ptr_type------------------------------- 2060 const Type *TypeRawPtr::cast_to_ptr_type(PTR ptr) const { 2061 assert( ptr != Constant, "what is the constant?" ); 2062 assert( ptr != Null, "Use TypePtr for NULL" ); 2063 assert( _bits==0, "Why cast a constant address?"); 2064 if( ptr == _ptr ) return this; 2065 return make(ptr); 2066 } 2067 2068 //------------------------------get_con---------------------------------------- 2069 intptr_t TypeRawPtr::get_con() const { 2070 assert( _ptr == Null || _ptr == Constant, "" ); 2071 return (intptr_t)_bits; 2072 } 2073 2074 //------------------------------meet------------------------------------------- 2075 // Compute the MEET of two types. It returns a new Type object. 2076 const Type *TypeRawPtr::xmeet( const Type *t ) const { 2077 // Perform a fast test for common case; meeting the same types together. 2078 if( this == t ) return this; // Meeting same type-rep? 2079 2080 // Current "this->_base" is RawPtr 2081 switch( t->base() ) { // switch on original type 2082 case Bottom: // Ye Olde Default 2083 return t; 2084 case Top: 2085 return this; 2086 case AnyPtr: // Meeting to AnyPtrs 2087 break; 2088 case RawPtr: { // might be top, bot, any/not or constant 2089 enum PTR tptr = t->is_ptr()->ptr(); 2090 enum PTR ptr = meet_ptr( tptr ); 2091 if( ptr == Constant ) { // Cannot be equal constants, so... 2092 if( tptr == Constant && _ptr != Constant) return t; 2093 if( _ptr == Constant && tptr != Constant) return this; 2094 ptr = NotNull; // Fall down in lattice 2095 } 2096 return make( ptr ); 2097 } 2098 2099 case OopPtr: 2100 case InstPtr: 2101 case KlassPtr: 2102 case AryPtr: 2103 return TypePtr::BOTTOM; // Oop meet raw is not well defined 2104 default: // All else is a mistake 2105 typerr(t); 2106 } 2107 2108 // Found an AnyPtr type vs self-RawPtr type 2109 const TypePtr *tp = t->is_ptr(); 2110 switch (tp->ptr()) { 2111 case TypePtr::TopPTR: return this; 2112 case TypePtr::BotPTR: return t; 2113 case TypePtr::Null: 2114 if( _ptr == TypePtr::TopPTR ) return t; 2115 return TypeRawPtr::BOTTOM; 2116 case TypePtr::NotNull: return TypePtr::make( AnyPtr, meet_ptr(TypePtr::NotNull), tp->meet_offset(0) ); 2117 case TypePtr::AnyNull: 2118 if( _ptr == TypePtr::Constant) return this; 2119 return make( meet_ptr(TypePtr::AnyNull) ); 2120 default: ShouldNotReachHere(); 2121 } 2122 return this; 2123 } 2124 2125 //------------------------------xdual------------------------------------------ 2126 // Dual: compute field-by-field dual 2127 const Type *TypeRawPtr::xdual() const { 2128 return new TypeRawPtr( dual_ptr(), _bits ); 2129 } 2130 2131 //------------------------------add_offset------------------------------------- 2132 const TypePtr *TypeRawPtr::add_offset( intptr_t offset ) const { 2133 if( offset == OffsetTop ) return BOTTOM; // Undefined offset-> undefined pointer 2134 if( offset == OffsetBot ) return BOTTOM; // Unknown offset-> unknown pointer 2135 if( offset == 0 ) return this; // No change 2136 switch (_ptr) { 2137 case TypePtr::TopPTR: 2138 case TypePtr::BotPTR: 2139 case TypePtr::NotNull: 2140 return this; 2141 case TypePtr::Null: 2142 case TypePtr::Constant: 2143 return make( _bits+offset ); 2144 default: ShouldNotReachHere(); 2145 } 2146 return NULL; // Lint noise 2147 } 2148 2149 //------------------------------eq--------------------------------------------- 2150 // Structural equality check for Type representations 2151 bool TypeRawPtr::eq( const Type *t ) const { 2152 const TypeRawPtr *a = (const TypeRawPtr*)t; 2153 return _bits == a->_bits && TypePtr::eq(t); 2154 } 2155 2156 //------------------------------hash------------------------------------------- 2157 // Type-specific hashing function. 2158 int TypeRawPtr::hash(void) const { 2159 return (intptr_t)_bits + TypePtr::hash(); 2160 } 2161 2162 //------------------------------dump2------------------------------------------ 2163 #ifndef PRODUCT 2164 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const { 2165 if( _ptr == Constant ) 2166 st->print(INTPTR_FORMAT, _bits); 2167 else 2168 st->print("rawptr:%s", ptr_msg[_ptr]); 2169 } 2170 #endif 2171 2172 //============================================================================= 2173 // Convenience common pre-built type. 2174 const TypeOopPtr *TypeOopPtr::BOTTOM; 2175 2176 //------------------------------TypeOopPtr------------------------------------- 2177 TypeOopPtr::TypeOopPtr( TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id ) 2178 : TypePtr(t, ptr, offset), 2179 _const_oop(o), _klass(k), 2180 _klass_is_exact(xk), 2181 _is_ptr_to_narrowoop(false), 2182 _instance_id(instance_id) { 2183 #ifdef _LP64 2184 if (UseCompressedOops && _offset != 0) { 2185 if (klass() == NULL) { 2186 assert(this->isa_aryptr(), "only arrays without klass"); 2187 _is_ptr_to_narrowoop = true; 2188 } else if (_offset == oopDesc::klass_offset_in_bytes()) { 2189 _is_ptr_to_narrowoop = true; 2190 } else if (this->isa_aryptr()) { 2191 _is_ptr_to_narrowoop = (klass()->is_obj_array_klass() && 2192 _offset != arrayOopDesc::length_offset_in_bytes()); 2193 } else if (klass() == ciEnv::current()->Class_klass() && 2194 (_offset == java_lang_Class::klass_offset_in_bytes() || 2195 _offset == java_lang_Class::array_klass_offset_in_bytes())) { 2196 // Special hidden fields from the Class. 2197 assert(this->isa_instptr(), "must be an instance ptr."); 2198 _is_ptr_to_narrowoop = true; 2199 } else if (klass()->is_instance_klass()) { 2200 ciInstanceKlass* ik = klass()->as_instance_klass(); 2201 ciField* field = NULL; 2202 if (this->isa_klassptr()) { 2203 // Perm objects don't use compressed references, except for 2204 // static fields which are currently compressed. 2205 field = ik->get_field_by_offset(_offset, true); 2206 if (field != NULL) { 2207 BasicType basic_elem_type = field->layout_type(); 2208 _is_ptr_to_narrowoop = (basic_elem_type == T_OBJECT || 2209 basic_elem_type == T_ARRAY); 2210 } 2211 } else if (_offset == OffsetBot || _offset == OffsetTop) { 2212 // unsafe access 2213 _is_ptr_to_narrowoop = true; 2214 } else { // exclude unsafe ops 2215 assert(this->isa_instptr(), "must be an instance ptr."); 2216 // Field which contains a compressed oop references. 2217 field = ik->get_field_by_offset(_offset, false); 2218 if (field != NULL) { 2219 BasicType basic_elem_type = field->layout_type(); 2220 _is_ptr_to_narrowoop = (basic_elem_type == T_OBJECT || 2221 basic_elem_type == T_ARRAY); 2222 } else if (klass()->equals(ciEnv::current()->Object_klass())) { 2223 // Compile::find_alias_type() cast exactness on all types to verify 2224 // that it does not affect alias type. 2225 _is_ptr_to_narrowoop = true; 2226 } else { 2227 // Type for the copy start in LibraryCallKit::inline_native_clone(). 2228 assert(!klass_is_exact(), "only non-exact klass"); 2229 _is_ptr_to_narrowoop = true; 2230 } 2231 } 2232 } 2233 } 2234 #endif 2235 } 2236 2237 //------------------------------make------------------------------------------- 2238 const TypeOopPtr *TypeOopPtr::make(PTR ptr, 2239 int offset) { 2240 assert(ptr != Constant, "no constant generic pointers"); 2241 ciKlass* k = ciKlassKlass::make(); 2242 bool xk = false; 2243 ciObject* o = NULL; 2244 return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, InstanceBot))->hashcons(); 2245 } 2246 2247 2248 //------------------------------cast_to_ptr_type------------------------------- 2249 const Type *TypeOopPtr::cast_to_ptr_type(PTR ptr) const { 2250 assert(_base == OopPtr, "subclass must override cast_to_ptr_type"); 2251 if( ptr == _ptr ) return this; 2252 return make(ptr, _offset); 2253 } 2254 2255 //-----------------------------cast_to_instance_id---------------------------- 2256 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const { 2257 // There are no instances of a general oop. 2258 // Return self unchanged. 2259 return this; 2260 } 2261 2262 //-----------------------------cast_to_exactness------------------------------- 2263 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const { 2264 // There is no such thing as an exact general oop. 2265 // Return self unchanged. 2266 return this; 2267 } 2268 2269 2270 //------------------------------as_klass_type---------------------------------- 2271 // Return the klass type corresponding to this instance or array type. 2272 // It is the type that is loaded from an object of this type. 2273 const TypeKlassPtr* TypeOopPtr::as_klass_type() const { 2274 ciKlass* k = klass(); 2275 bool xk = klass_is_exact(); 2276 if (k == NULL || !k->is_java_klass()) 2277 return TypeKlassPtr::OBJECT; 2278 else 2279 return TypeKlassPtr::make(xk? Constant: NotNull, k, 0); 2280 } 2281 2282 2283 //------------------------------meet------------------------------------------- 2284 // Compute the MEET of two types. It returns a new Type object. 2285 const Type *TypeOopPtr::xmeet( const Type *t ) const { 2286 // Perform a fast test for common case; meeting the same types together. 2287 if( this == t ) return this; // Meeting same type-rep? 2288 2289 // Current "this->_base" is OopPtr 2290 switch (t->base()) { // switch on original type 2291 2292 case Int: // Mixing ints & oops happens when javac 2293 case Long: // reuses local variables 2294 case FloatTop: 2295 case FloatCon: 2296 case FloatBot: 2297 case DoubleTop: 2298 case DoubleCon: 2299 case DoubleBot: 2300 case NarrowOop: 2301 case Bottom: // Ye Olde Default 2302 return Type::BOTTOM; 2303 case Top: 2304 return this; 2305 2306 default: // All else is a mistake 2307 typerr(t); 2308 2309 case RawPtr: 2310 return TypePtr::BOTTOM; // Oop meet raw is not well defined 2311 2312 case AnyPtr: { 2313 // Found an AnyPtr type vs self-OopPtr type 2314 const TypePtr *tp = t->is_ptr(); 2315 int offset = meet_offset(tp->offset()); 2316 PTR ptr = meet_ptr(tp->ptr()); 2317 switch (tp->ptr()) { 2318 case Null: 2319 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset); 2320 // else fall through: 2321 case TopPTR: 2322 case AnyNull: 2323 return make(ptr, offset); 2324 case BotPTR: 2325 case NotNull: 2326 return TypePtr::make(AnyPtr, ptr, offset); 2327 default: typerr(t); 2328 } 2329 } 2330 2331 case OopPtr: { // Meeting to other OopPtrs 2332 const TypeOopPtr *tp = t->is_oopptr(); 2333 return make( meet_ptr(tp->ptr()), meet_offset(tp->offset()) ); 2334 } 2335 2336 case InstPtr: // For these, flip the call around to cut down 2337 case KlassPtr: // on the cases I have to handle. 2338 case AryPtr: 2339 return t->xmeet(this); // Call in reverse direction 2340 2341 } // End of switch 2342 return this; // Return the double constant 2343 } 2344 2345 2346 //------------------------------xdual------------------------------------------ 2347 // Dual of a pure heap pointer. No relevant klass or oop information. 2348 const Type *TypeOopPtr::xdual() const { 2349 assert(klass() == ciKlassKlass::make(), "no klasses here"); 2350 assert(const_oop() == NULL, "no constants here"); 2351 return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id() ); 2352 } 2353 2354 //--------------------------make_from_klass_common----------------------------- 2355 // Computes the element-type given a klass. 2356 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) { 2357 assert(klass->is_java_klass(), "must be java language klass"); 2358 if (klass->is_instance_klass()) { 2359 Compile* C = Compile::current(); 2360 Dependencies* deps = C->dependencies(); 2361 assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity"); 2362 // Element is an instance 2363 bool klass_is_exact = false; 2364 if (klass->is_loaded()) { 2365 // Try to set klass_is_exact. 2366 ciInstanceKlass* ik = klass->as_instance_klass(); 2367 klass_is_exact = ik->is_final(); 2368 if (!klass_is_exact && klass_change 2369 && deps != NULL && UseUniqueSubclasses) { 2370 ciInstanceKlass* sub = ik->unique_concrete_subklass(); 2371 if (sub != NULL) { 2372 deps->assert_abstract_with_unique_concrete_subtype(ik, sub); 2373 klass = ik = sub; 2374 klass_is_exact = sub->is_final(); 2375 } 2376 } 2377 if (!klass_is_exact && try_for_exact 2378 && deps != NULL && UseExactTypes) { 2379 if (!ik->is_interface() && !ik->has_subklass()) { 2380 // Add a dependence; if concrete subclass added we need to recompile 2381 deps->assert_leaf_type(ik); 2382 klass_is_exact = true; 2383 } 2384 } 2385 } 2386 return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, 0); 2387 } else if (klass->is_obj_array_klass()) { 2388 // Element is an object array. Recursively call ourself. 2389 const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(klass->as_obj_array_klass()->element_klass(), false, try_for_exact); 2390 bool xk = etype->klass_is_exact(); 2391 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS); 2392 // We used to pass NotNull in here, asserting that the sub-arrays 2393 // are all not-null. This is not true in generally, as code can 2394 // slam NULLs down in the subarrays. 2395 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, 0); 2396 return arr; 2397 } else if (klass->is_type_array_klass()) { 2398 // Element is an typeArray 2399 const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type()); 2400 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS); 2401 // We used to pass NotNull in here, asserting that the array pointer 2402 // is not-null. That was not true in general. 2403 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, 0); 2404 return arr; 2405 } else { 2406 ShouldNotReachHere(); 2407 return NULL; 2408 } 2409 } 2410 2411 //------------------------------make_from_constant----------------------------- 2412 // Make a java pointer from an oop constant 2413 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o) { 2414 if (o->is_method_data() || o->is_method()) { 2415 // Treat much like a typeArray of bytes, like below, but fake the type... 2416 assert(o->has_encoding(), "must be a perm space object"); 2417 const Type* etype = (Type*)get_const_basic_type(T_BYTE); 2418 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS); 2419 ciKlass *klass = ciTypeArrayKlass::make((BasicType) T_BYTE); 2420 assert(o->has_encoding(), "method data oops should be tenured"); 2421 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0); 2422 return arr; 2423 } else { 2424 assert(o->is_java_object(), "must be java language object"); 2425 assert(!o->is_null_object(), "null object not yet handled here."); 2426 ciKlass *klass = o->klass(); 2427 if (klass->is_instance_klass()) { 2428 // Element is an instance 2429 if (!o->has_encoding()) { // not a perm-space constant 2430 // %%% remove this restriction by rewriting non-perm ConPNodes in a later phase 2431 return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, 0); 2432 } 2433 return TypeInstPtr::make(o); 2434 } else if (klass->is_obj_array_klass()) { 2435 // Element is an object array. Recursively call ourself. 2436 const Type *etype = 2437 TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass()); 2438 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length())); 2439 // We used to pass NotNull in here, asserting that the sub-arrays 2440 // are all not-null. This is not true in generally, as code can 2441 // slam NULLs down in the subarrays. 2442 if (!o->has_encoding()) { // not a perm-space constant 2443 // %%% remove this restriction by rewriting non-perm ConPNodes in a later phase 2444 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0); 2445 } 2446 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0); 2447 return arr; 2448 } else if (klass->is_type_array_klass()) { 2449 // Element is an typeArray 2450 const Type* etype = 2451 (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type()); 2452 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length())); 2453 // We used to pass NotNull in here, asserting that the array pointer 2454 // is not-null. That was not true in general. 2455 if (!o->has_encoding()) { // not a perm-space constant 2456 // %%% remove this restriction by rewriting non-perm ConPNodes in a later phase 2457 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0); 2458 } 2459 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0); 2460 return arr; 2461 } 2462 } 2463 2464 ShouldNotReachHere(); 2465 return NULL; 2466 } 2467 2468 //------------------------------get_con---------------------------------------- 2469 intptr_t TypeOopPtr::get_con() const { 2470 assert( _ptr == Null || _ptr == Constant, "" ); 2471 assert( _offset >= 0, "" ); 2472 2473 if (_offset != 0) { 2474 // After being ported to the compiler interface, the compiler no longer 2475 // directly manipulates the addresses of oops. Rather, it only has a pointer 2476 // to a handle at compile time. This handle is embedded in the generated 2477 // code and dereferenced at the time the nmethod is made. Until that time, 2478 // it is not reasonable to do arithmetic with the addresses of oops (we don't 2479 // have access to the addresses!). This does not seem to currently happen, 2480 // but this assertion here is to help prevent its occurence. 2481 tty->print_cr("Found oop constant with non-zero offset"); 2482 ShouldNotReachHere(); 2483 } 2484 2485 return (intptr_t)const_oop()->encoding(); 2486 } 2487 2488 2489 //-----------------------------filter------------------------------------------ 2490 // Do not allow interface-vs.-noninterface joins to collapse to top. 2491 const Type *TypeOopPtr::filter( const Type *kills ) const { 2492 2493 const Type* ft = join(kills); 2494 const TypeInstPtr* ftip = ft->isa_instptr(); 2495 const TypeInstPtr* ktip = kills->isa_instptr(); 2496 const TypeKlassPtr* ftkp = ft->isa_klassptr(); 2497 const TypeKlassPtr* ktkp = kills->isa_klassptr(); 2498 2499 if (ft->empty()) { 2500 // Check for evil case of 'this' being a class and 'kills' expecting an 2501 // interface. This can happen because the bytecodes do not contain 2502 // enough type info to distinguish a Java-level interface variable 2503 // from a Java-level object variable. If we meet 2 classes which 2504 // both implement interface I, but their meet is at 'j/l/O' which 2505 // doesn't implement I, we have no way to tell if the result should 2506 // be 'I' or 'j/l/O'. Thus we'll pick 'j/l/O'. If this then flows 2507 // into a Phi which "knows" it's an Interface type we'll have to 2508 // uplift the type. 2509 if (!empty() && ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface()) 2510 return kills; // Uplift to interface 2511 if (!empty() && ktkp != NULL && ktkp->klass()->is_loaded() && ktkp->klass()->is_interface()) 2512 return kills; // Uplift to interface 2513 2514 return Type::TOP; // Canonical empty value 2515 } 2516 2517 // If we have an interface-typed Phi or cast and we narrow to a class type, 2518 // the join should report back the class. However, if we have a J/L/Object 2519 // class-typed Phi and an interface flows in, it's possible that the meet & 2520 // join report an interface back out. This isn't possible but happens 2521 // because the type system doesn't interact well with interfaces. 2522 if (ftip != NULL && ktip != NULL && 2523 ftip->is_loaded() && ftip->klass()->is_interface() && 2524 ktip->is_loaded() && !ktip->klass()->is_interface()) { 2525 // Happens in a CTW of rt.jar, 320-341, no extra flags 2526 return ktip->cast_to_ptr_type(ftip->ptr()); 2527 } 2528 if (ftkp != NULL && ktkp != NULL && 2529 ftkp->is_loaded() && ftkp->klass()->is_interface() && 2530 ktkp->is_loaded() && !ktkp->klass()->is_interface()) { 2531 // Happens in a CTW of rt.jar, 320-341, no extra flags 2532 return ktkp->cast_to_ptr_type(ftkp->ptr()); 2533 } 2534 2535 return ft; 2536 } 2537 2538 //------------------------------eq--------------------------------------------- 2539 // Structural equality check for Type representations 2540 bool TypeOopPtr::eq( const Type *t ) const { 2541 const TypeOopPtr *a = (const TypeOopPtr*)t; 2542 if (_klass_is_exact != a->_klass_is_exact || 2543 _instance_id != a->_instance_id) return false; 2544 ciObject* one = const_oop(); 2545 ciObject* two = a->const_oop(); 2546 if (one == NULL || two == NULL) { 2547 return (one == two) && TypePtr::eq(t); 2548 } else { 2549 return one->equals(two) && TypePtr::eq(t); 2550 } 2551 } 2552 2553 //------------------------------hash------------------------------------------- 2554 // Type-specific hashing function. 2555 int TypeOopPtr::hash(void) const { 2556 return 2557 (const_oop() ? const_oop()->hash() : 0) + 2558 _klass_is_exact + 2559 _instance_id + 2560 TypePtr::hash(); 2561 } 2562 2563 //------------------------------dump2------------------------------------------ 2564 #ifndef PRODUCT 2565 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const { 2566 st->print("oopptr:%s", ptr_msg[_ptr]); 2567 if( _klass_is_exact ) st->print(":exact"); 2568 if( const_oop() ) st->print(INTPTR_FORMAT, const_oop()); 2569 switch( _offset ) { 2570 case OffsetTop: st->print("+top"); break; 2571 case OffsetBot: st->print("+any"); break; 2572 case 0: break; 2573 default: st->print("+%d",_offset); break; 2574 } 2575 if (_instance_id == InstanceTop) 2576 st->print(",iid=top"); 2577 else if (_instance_id != InstanceBot) 2578 st->print(",iid=%d",_instance_id); 2579 } 2580 #endif 2581 2582 //------------------------------singleton-------------------------------------- 2583 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 2584 // constants 2585 bool TypeOopPtr::singleton(void) const { 2586 // detune optimizer to not generate constant oop + constant offset as a constant! 2587 // TopPTR, Null, AnyNull, Constant are all singletons 2588 return (_offset == 0) && !below_centerline(_ptr); 2589 } 2590 2591 //------------------------------add_offset------------------------------------- 2592 const TypePtr *TypeOopPtr::add_offset( intptr_t offset ) const { 2593 return make( _ptr, xadd_offset(offset) ); 2594 } 2595 2596 //------------------------------meet_instance_id-------------------------------- 2597 int TypeOopPtr::meet_instance_id( int instance_id ) const { 2598 // Either is 'TOP' instance? Return the other instance! 2599 if( _instance_id == InstanceTop ) return instance_id; 2600 if( instance_id == InstanceTop ) return _instance_id; 2601 // If either is different, return 'BOTTOM' instance 2602 if( _instance_id != instance_id ) return InstanceBot; 2603 return _instance_id; 2604 } 2605 2606 //------------------------------dual_instance_id-------------------------------- 2607 int TypeOopPtr::dual_instance_id( ) const { 2608 if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM 2609 if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP 2610 return _instance_id; // Map everything else into self 2611 } 2612 2613 2614 //============================================================================= 2615 // Convenience common pre-built types. 2616 const TypeInstPtr *TypeInstPtr::NOTNULL; 2617 const TypeInstPtr *TypeInstPtr::BOTTOM; 2618 const TypeInstPtr *TypeInstPtr::MIRROR; 2619 const TypeInstPtr *TypeInstPtr::MARK; 2620 const TypeInstPtr *TypeInstPtr::KLASS; 2621 2622 //------------------------------TypeInstPtr------------------------------------- 2623 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int off, int instance_id) 2624 : TypeOopPtr(InstPtr, ptr, k, xk, o, off, instance_id), _name(k->name()) { 2625 assert(k != NULL && 2626 (k->is_loaded() || o == NULL), 2627 "cannot have constants with non-loaded klass"); 2628 }; 2629 2630 //------------------------------make------------------------------------------- 2631 const TypeInstPtr *TypeInstPtr::make(PTR ptr, 2632 ciKlass* k, 2633 bool xk, 2634 ciObject* o, 2635 int offset, 2636 int instance_id) { 2637 assert( !k->is_loaded() || k->is_instance_klass() || 2638 k->is_method_klass(), "Must be for instance or method"); 2639 // Either const_oop() is NULL or else ptr is Constant 2640 assert( (!o && ptr != Constant) || (o && ptr == Constant), 2641 "constant pointers must have a value supplied" ); 2642 // Ptr is never Null 2643 assert( ptr != Null, "NULL pointers are not typed" ); 2644 2645 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed"); 2646 if (!UseExactTypes) xk = false; 2647 if (ptr == Constant) { 2648 // Note: This case includes meta-object constants, such as methods. 2649 xk = true; 2650 } else if (k->is_loaded()) { 2651 ciInstanceKlass* ik = k->as_instance_klass(); 2652 if (!xk && ik->is_final()) xk = true; // no inexact final klass 2653 if (xk && ik->is_interface()) xk = false; // no exact interface 2654 } 2655 2656 // Now hash this baby 2657 TypeInstPtr *result = 2658 (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o ,offset, instance_id))->hashcons(); 2659 2660 return result; 2661 } 2662 2663 2664 //------------------------------cast_to_ptr_type------------------------------- 2665 const Type *TypeInstPtr::cast_to_ptr_type(PTR ptr) const { 2666 if( ptr == _ptr ) return this; 2667 // Reconstruct _sig info here since not a problem with later lazy 2668 // construction, _sig will show up on demand. 2669 return make(ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id); 2670 } 2671 2672 2673 //-----------------------------cast_to_exactness------------------------------- 2674 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const { 2675 if( klass_is_exact == _klass_is_exact ) return this; 2676 if (!UseExactTypes) return this; 2677 if (!_klass->is_loaded()) return this; 2678 ciInstanceKlass* ik = _klass->as_instance_klass(); 2679 if( (ik->is_final() || _const_oop) ) return this; // cannot clear xk 2680 if( ik->is_interface() ) return this; // cannot set xk 2681 return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id); 2682 } 2683 2684 //-----------------------------cast_to_instance_id---------------------------- 2685 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const { 2686 if( instance_id == _instance_id ) return this; 2687 return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id); 2688 } 2689 2690 //------------------------------xmeet_unloaded--------------------------------- 2691 // Compute the MEET of two InstPtrs when at least one is unloaded. 2692 // Assume classes are different since called after check for same name/class-loader 2693 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const { 2694 int off = meet_offset(tinst->offset()); 2695 PTR ptr = meet_ptr(tinst->ptr()); 2696 2697 const TypeInstPtr *loaded = is_loaded() ? this : tinst; 2698 const TypeInstPtr *unloaded = is_loaded() ? tinst : this; 2699 if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) { 2700 // 2701 // Meet unloaded class with java/lang/Object 2702 // 2703 // Meet 2704 // | Unloaded Class 2705 // Object | TOP | AnyNull | Constant | NotNull | BOTTOM | 2706 // =================================================================== 2707 // TOP | ..........................Unloaded......................| 2708 // AnyNull | U-AN |................Unloaded......................| 2709 // Constant | ... O-NN .................................. | O-BOT | 2710 // NotNull | ... O-NN .................................. | O-BOT | 2711 // BOTTOM | ........................Object-BOTTOM ..................| 2712 // 2713 assert(loaded->ptr() != TypePtr::Null, "insanity check"); 2714 // 2715 if( loaded->ptr() == TypePtr::TopPTR ) { return unloaded; } 2716 else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make( ptr, unloaded->klass() ); } 2717 else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; } 2718 else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) { 2719 if (unloaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; } 2720 else { return TypeInstPtr::NOTNULL; } 2721 } 2722 else if( unloaded->ptr() == TypePtr::TopPTR ) { return unloaded; } 2723 2724 return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr(); 2725 } 2726 2727 // Both are unloaded, not the same class, not Object 2728 // Or meet unloaded with a different loaded class, not java/lang/Object 2729 if( ptr != TypePtr::BotPTR ) { 2730 return TypeInstPtr::NOTNULL; 2731 } 2732 return TypeInstPtr::BOTTOM; 2733 } 2734 2735 2736 //------------------------------meet------------------------------------------- 2737 // Compute the MEET of two types. It returns a new Type object. 2738 const Type *TypeInstPtr::xmeet( const Type *t ) const { 2739 // Perform a fast test for common case; meeting the same types together. 2740 if( this == t ) return this; // Meeting same type-rep? 2741 2742 // Current "this->_base" is Pointer 2743 switch (t->base()) { // switch on original type 2744 2745 case Int: // Mixing ints & oops happens when javac 2746 case Long: // reuses local variables 2747 case FloatTop: 2748 case FloatCon: 2749 case FloatBot: 2750 case DoubleTop: 2751 case DoubleCon: 2752 case DoubleBot: 2753 case NarrowOop: 2754 case Bottom: // Ye Olde Default 2755 return Type::BOTTOM; 2756 case Top: 2757 return this; 2758 2759 default: // All else is a mistake 2760 typerr(t); 2761 2762 case RawPtr: return TypePtr::BOTTOM; 2763 2764 case AryPtr: { // All arrays inherit from Object class 2765 const TypeAryPtr *tp = t->is_aryptr(); 2766 int offset = meet_offset(tp->offset()); 2767 PTR ptr = meet_ptr(tp->ptr()); 2768 int instance_id = meet_instance_id(tp->instance_id()); 2769 switch (ptr) { 2770 case TopPTR: 2771 case AnyNull: // Fall 'down' to dual of object klass 2772 if (klass()->equals(ciEnv::current()->Object_klass())) { 2773 return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id); 2774 } else { 2775 // cannot subclass, so the meet has to fall badly below the centerline 2776 ptr = NotNull; 2777 instance_id = InstanceBot; 2778 return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id); 2779 } 2780 case Constant: 2781 case NotNull: 2782 case BotPTR: // Fall down to object klass 2783 // LCA is object_klass, but if we subclass from the top we can do better 2784 if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull ) 2785 // If 'this' (InstPtr) is above the centerline and it is Object class 2786 // then we can subclass in the Java class hierarchy. 2787 if (klass()->equals(ciEnv::current()->Object_klass())) { 2788 // that is, tp's array type is a subtype of my klass 2789 return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id); 2790 } 2791 } 2792 // The other case cannot happen, since I cannot be a subtype of an array. 2793 // The meet falls down to Object class below centerline. 2794 if( ptr == Constant ) 2795 ptr = NotNull; 2796 instance_id = InstanceBot; 2797 return make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id ); 2798 default: typerr(t); 2799 } 2800 } 2801 2802 case OopPtr: { // Meeting to OopPtrs 2803 // Found a OopPtr type vs self-InstPtr type 2804 const TypePtr *tp = t->is_oopptr(); 2805 int offset = meet_offset(tp->offset()); 2806 PTR ptr = meet_ptr(tp->ptr()); 2807 switch (tp->ptr()) { 2808 case TopPTR: 2809 case AnyNull: { 2810 int instance_id = meet_instance_id(InstanceTop); 2811 return make(ptr, klass(), klass_is_exact(), 2812 (ptr == Constant ? const_oop() : NULL), offset, instance_id); 2813 } 2814 case NotNull: 2815 case BotPTR: 2816 return TypeOopPtr::make(ptr, offset); 2817 default: typerr(t); 2818 } 2819 } 2820 2821 case AnyPtr: { // Meeting to AnyPtrs 2822 // Found an AnyPtr type vs self-InstPtr type 2823 const TypePtr *tp = t->is_ptr(); 2824 int offset = meet_offset(tp->offset()); 2825 PTR ptr = meet_ptr(tp->ptr()); 2826 switch (tp->ptr()) { 2827 case Null: 2828 if( ptr == Null ) return TypePtr::make( AnyPtr, ptr, offset ); 2829 // else fall through to AnyNull 2830 case TopPTR: 2831 case AnyNull: { 2832 int instance_id = meet_instance_id(InstanceTop); 2833 return make( ptr, klass(), klass_is_exact(), 2834 (ptr == Constant ? const_oop() : NULL), offset, instance_id); 2835 } 2836 case NotNull: 2837 case BotPTR: 2838 return TypePtr::make( AnyPtr, ptr, offset ); 2839 default: typerr(t); 2840 } 2841 } 2842 2843 /* 2844 A-top } 2845 / | \ } Tops 2846 B-top A-any C-top } 2847 | / | \ | } Any-nulls 2848 B-any | C-any } 2849 | | | 2850 B-con A-con C-con } constants; not comparable across classes 2851 | | | 2852 B-not | C-not } 2853 | \ | / | } not-nulls 2854 B-bot A-not C-bot } 2855 \ | / } Bottoms 2856 A-bot } 2857 */ 2858 2859 case InstPtr: { // Meeting 2 Oops? 2860 // Found an InstPtr sub-type vs self-InstPtr type 2861 const TypeInstPtr *tinst = t->is_instptr(); 2862 int off = meet_offset( tinst->offset() ); 2863 PTR ptr = meet_ptr( tinst->ptr() ); 2864 int instance_id = meet_instance_id(tinst->instance_id()); 2865 2866 // Check for easy case; klasses are equal (and perhaps not loaded!) 2867 // If we have constants, then we created oops so classes are loaded 2868 // and we can handle the constants further down. This case handles 2869 // both-not-loaded or both-loaded classes 2870 if (ptr != Constant && klass()->equals(tinst->klass()) && klass_is_exact() == tinst->klass_is_exact()) { 2871 return make( ptr, klass(), klass_is_exact(), NULL, off, instance_id ); 2872 } 2873 2874 // Classes require inspection in the Java klass hierarchy. Must be loaded. 2875 ciKlass* tinst_klass = tinst->klass(); 2876 ciKlass* this_klass = this->klass(); 2877 bool tinst_xk = tinst->klass_is_exact(); 2878 bool this_xk = this->klass_is_exact(); 2879 if (!tinst_klass->is_loaded() || !this_klass->is_loaded() ) { 2880 // One of these classes has not been loaded 2881 const TypeInstPtr *unloaded_meet = xmeet_unloaded(tinst); 2882 #ifndef PRODUCT 2883 if( PrintOpto && Verbose ) { 2884 tty->print("meet of unloaded classes resulted in: "); unloaded_meet->dump(); tty->cr(); 2885 tty->print(" this == "); this->dump(); tty->cr(); 2886 tty->print(" tinst == "); tinst->dump(); tty->cr(); 2887 } 2888 #endif 2889 return unloaded_meet; 2890 } 2891 2892 // Handle mixing oops and interfaces first. 2893 if( this_klass->is_interface() && !tinst_klass->is_interface() ) { 2894 ciKlass *tmp = tinst_klass; // Swap interface around 2895 tinst_klass = this_klass; 2896 this_klass = tmp; 2897 bool tmp2 = tinst_xk; 2898 tinst_xk = this_xk; 2899 this_xk = tmp2; 2900 } 2901 if (tinst_klass->is_interface() && 2902 !(this_klass->is_interface() || 2903 // Treat java/lang/Object as an honorary interface, 2904 // because we need a bottom for the interface hierarchy. 2905 this_klass == ciEnv::current()->Object_klass())) { 2906 // Oop meets interface! 2907 2908 // See if the oop subtypes (implements) interface. 2909 ciKlass *k; 2910 bool xk; 2911 if( this_klass->is_subtype_of( tinst_klass ) ) { 2912 // Oop indeed subtypes. Now keep oop or interface depending 2913 // on whether we are both above the centerline or either is 2914 // below the centerline. If we are on the centerline 2915 // (e.g., Constant vs. AnyNull interface), use the constant. 2916 k = below_centerline(ptr) ? tinst_klass : this_klass; 2917 // If we are keeping this_klass, keep its exactness too. 2918 xk = below_centerline(ptr) ? tinst_xk : this_xk; 2919 } else { // Does not implement, fall to Object 2920 // Oop does not implement interface, so mixing falls to Object 2921 // just like the verifier does (if both are above the 2922 // centerline fall to interface) 2923 k = above_centerline(ptr) ? tinst_klass : ciEnv::current()->Object_klass(); 2924 xk = above_centerline(ptr) ? tinst_xk : false; 2925 // Watch out for Constant vs. AnyNull interface. 2926 if (ptr == Constant) ptr = NotNull; // forget it was a constant 2927 instance_id = InstanceBot; 2928 } 2929 ciObject* o = NULL; // the Constant value, if any 2930 if (ptr == Constant) { 2931 // Find out which constant. 2932 o = (this_klass == klass()) ? const_oop() : tinst->const_oop(); 2933 } 2934 return make( ptr, k, xk, o, off, instance_id ); 2935 } 2936 2937 // Either oop vs oop or interface vs interface or interface vs Object 2938 2939 // !!! Here's how the symmetry requirement breaks down into invariants: 2940 // If we split one up & one down AND they subtype, take the down man. 2941 // If we split one up & one down AND they do NOT subtype, "fall hard". 2942 // If both are up and they subtype, take the subtype class. 2943 // If both are up and they do NOT subtype, "fall hard". 2944 // If both are down and they subtype, take the supertype class. 2945 // If both are down and they do NOT subtype, "fall hard". 2946 // Constants treated as down. 2947 2948 // Now, reorder the above list; observe that both-down+subtype is also 2949 // "fall hard"; "fall hard" becomes the default case: 2950 // If we split one up & one down AND they subtype, take the down man. 2951 // If both are up and they subtype, take the subtype class. 2952 2953 // If both are down and they subtype, "fall hard". 2954 // If both are down and they do NOT subtype, "fall hard". 2955 // If both are up and they do NOT subtype, "fall hard". 2956 // If we split one up & one down AND they do NOT subtype, "fall hard". 2957 2958 // If a proper subtype is exact, and we return it, we return it exactly. 2959 // If a proper supertype is exact, there can be no subtyping relationship! 2960 // If both types are equal to the subtype, exactness is and-ed below the 2961 // centerline and or-ed above it. (N.B. Constants are always exact.) 2962 2963 // Check for subtyping: 2964 ciKlass *subtype = NULL; 2965 bool subtype_exact = false; 2966 if( tinst_klass->equals(this_klass) ) { 2967 subtype = this_klass; 2968 subtype_exact = below_centerline(ptr) ? (this_xk & tinst_xk) : (this_xk | tinst_xk); 2969 } else if( !tinst_xk && this_klass->is_subtype_of( tinst_klass ) ) { 2970 subtype = this_klass; // Pick subtyping class 2971 subtype_exact = this_xk; 2972 } else if( !this_xk && tinst_klass->is_subtype_of( this_klass ) ) { 2973 subtype = tinst_klass; // Pick subtyping class 2974 subtype_exact = tinst_xk; 2975 } 2976 2977 if( subtype ) { 2978 if( above_centerline(ptr) ) { // both are up? 2979 this_klass = tinst_klass = subtype; 2980 this_xk = tinst_xk = subtype_exact; 2981 } else if( above_centerline(this ->_ptr) && !above_centerline(tinst->_ptr) ) { 2982 this_klass = tinst_klass; // tinst is down; keep down man 2983 this_xk = tinst_xk; 2984 } else if( above_centerline(tinst->_ptr) && !above_centerline(this ->_ptr) ) { 2985 tinst_klass = this_klass; // this is down; keep down man 2986 tinst_xk = this_xk; 2987 } else { 2988 this_xk = subtype_exact; // either they are equal, or we'll do an LCA 2989 } 2990 } 2991 2992 // Check for classes now being equal 2993 if (tinst_klass->equals(this_klass)) { 2994 // If the klasses are equal, the constants may still differ. Fall to 2995 // NotNull if they do (neither constant is NULL; that is a special case 2996 // handled elsewhere). 2997 ciObject* o = NULL; // Assume not constant when done 2998 ciObject* this_oop = const_oop(); 2999 ciObject* tinst_oop = tinst->const_oop(); 3000 if( ptr == Constant ) { 3001 if (this_oop != NULL && tinst_oop != NULL && 3002 this_oop->equals(tinst_oop) ) 3003 o = this_oop; 3004 else if (above_centerline(this ->_ptr)) 3005 o = tinst_oop; 3006 else if (above_centerline(tinst ->_ptr)) 3007 o = this_oop; 3008 else 3009 ptr = NotNull; 3010 } 3011 return make( ptr, this_klass, this_xk, o, off, instance_id ); 3012 } // Else classes are not equal 3013 3014 // Since klasses are different, we require a LCA in the Java 3015 // class hierarchy - which means we have to fall to at least NotNull. 3016 if( ptr == TopPTR || ptr == AnyNull || ptr == Constant ) 3017 ptr = NotNull; 3018 instance_id = InstanceBot; 3019 3020 // Now we find the LCA of Java classes 3021 ciKlass* k = this_klass->least_common_ancestor(tinst_klass); 3022 return make( ptr, k, false, NULL, off, instance_id ); 3023 } // End of case InstPtr 3024 3025 case KlassPtr: 3026 return TypeInstPtr::BOTTOM; 3027 3028 } // End of switch 3029 return this; // Return the double constant 3030 } 3031 3032 3033 //------------------------java_mirror_type-------------------------------------- 3034 ciType* TypeInstPtr::java_mirror_type() const { 3035 // must be a singleton type 3036 if( const_oop() == NULL ) return NULL; 3037 3038 // must be of type java.lang.Class 3039 if( klass() != ciEnv::current()->Class_klass() ) return NULL; 3040 3041 return const_oop()->as_instance()->java_mirror_type(); 3042 } 3043 3044 3045 //------------------------------xdual------------------------------------------ 3046 // Dual: do NOT dual on klasses. This means I do NOT understand the Java 3047 // inheritance mechanism. 3048 const Type *TypeInstPtr::xdual() const { 3049 return new TypeInstPtr( dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id() ); 3050 } 3051 3052 //------------------------------eq--------------------------------------------- 3053 // Structural equality check for Type representations 3054 bool TypeInstPtr::eq( const Type *t ) const { 3055 const TypeInstPtr *p = t->is_instptr(); 3056 return 3057 klass()->equals(p->klass()) && 3058 TypeOopPtr::eq(p); // Check sub-type stuff 3059 } 3060 3061 //------------------------------hash------------------------------------------- 3062 // Type-specific hashing function. 3063 int TypeInstPtr::hash(void) const { 3064 int hash = klass()->hash() + TypeOopPtr::hash(); 3065 return hash; 3066 } 3067 3068 //------------------------------dump2------------------------------------------ 3069 // Dump oop Type 3070 #ifndef PRODUCT 3071 void TypeInstPtr::dump2( Dict &d, uint depth, outputStream *st ) const { 3072 // Print the name of the klass. 3073 klass()->print_name_on(st); 3074 3075 switch( _ptr ) { 3076 case Constant: 3077 // TO DO: Make CI print the hex address of the underlying oop. 3078 if (WizardMode || Verbose) { 3079 const_oop()->print_oop(st); 3080 } 3081 case BotPTR: 3082 if (!WizardMode && !Verbose) { 3083 if( _klass_is_exact ) st->print(":exact"); 3084 break; 3085 } 3086 case TopPTR: 3087 case AnyNull: 3088 case NotNull: 3089 st->print(":%s", ptr_msg[_ptr]); 3090 if( _klass_is_exact ) st->print(":exact"); 3091 break; 3092 } 3093 3094 if( _offset ) { // Dump offset, if any 3095 if( _offset == OffsetBot ) st->print("+any"); 3096 else if( _offset == OffsetTop ) st->print("+unknown"); 3097 else st->print("+%d", _offset); 3098 } 3099 3100 st->print(" *"); 3101 if (_instance_id == InstanceTop) 3102 st->print(",iid=top"); 3103 else if (_instance_id != InstanceBot) 3104 st->print(",iid=%d",_instance_id); 3105 } 3106 #endif 3107 3108 //------------------------------add_offset------------------------------------- 3109 const TypePtr *TypeInstPtr::add_offset( intptr_t offset ) const { 3110 return make( _ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset), _instance_id ); 3111 } 3112 3113 //============================================================================= 3114 // Convenience common pre-built types. 3115 const TypeAryPtr *TypeAryPtr::RANGE; 3116 const TypeAryPtr *TypeAryPtr::OOPS; 3117 const TypeAryPtr *TypeAryPtr::NARROWOOPS; 3118 const TypeAryPtr *TypeAryPtr::BYTES; 3119 const TypeAryPtr *TypeAryPtr::SHORTS; 3120 const TypeAryPtr *TypeAryPtr::CHARS; 3121 const TypeAryPtr *TypeAryPtr::INTS; 3122 const TypeAryPtr *TypeAryPtr::LONGS; 3123 const TypeAryPtr *TypeAryPtr::FLOATS; 3124 const TypeAryPtr *TypeAryPtr::DOUBLES; 3125 3126 //------------------------------make------------------------------------------- 3127 const TypeAryPtr *TypeAryPtr::make( PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id ) { 3128 assert(!(k == NULL && ary->_elem->isa_int()), 3129 "integral arrays must be pre-equipped with a class"); 3130 if (!xk) xk = ary->ary_must_be_exact(); 3131 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed"); 3132 if (!UseExactTypes) xk = (ptr == Constant); 3133 return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id))->hashcons(); 3134 } 3135 3136 //------------------------------make------------------------------------------- 3137 const TypeAryPtr *TypeAryPtr::make( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id ) { 3138 assert(!(k == NULL && ary->_elem->isa_int()), 3139 "integral arrays must be pre-equipped with a class"); 3140 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" ); 3141 if (!xk) xk = (o != NULL) || ary->ary_must_be_exact(); 3142 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed"); 3143 if (!UseExactTypes) xk = (ptr == Constant); 3144 return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id))->hashcons(); 3145 } 3146 3147 //------------------------------cast_to_ptr_type------------------------------- 3148 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const { 3149 if( ptr == _ptr ) return this; 3150 return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _instance_id); 3151 } 3152 3153 3154 //-----------------------------cast_to_exactness------------------------------- 3155 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const { 3156 if( klass_is_exact == _klass_is_exact ) return this; 3157 if (!UseExactTypes) return this; 3158 if (_ary->ary_must_be_exact()) return this; // cannot clear xk 3159 return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id); 3160 } 3161 3162 //-----------------------------cast_to_instance_id---------------------------- 3163 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const { 3164 if( instance_id == _instance_id ) return this; 3165 return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id); 3166 } 3167 3168 //-----------------------------narrow_size_type------------------------------- 3169 // Local cache for arrayOopDesc::max_array_length(etype), 3170 // which is kind of slow (and cached elsewhere by other users). 3171 static jint max_array_length_cache[T_CONFLICT+1]; 3172 static jint max_array_length(BasicType etype) { 3173 jint& cache = max_array_length_cache[etype]; 3174 jint res = cache; 3175 if (res == 0) { 3176 switch (etype) { 3177 case T_NARROWOOP: 3178 etype = T_OBJECT; 3179 break; 3180 case T_CONFLICT: 3181 case T_ILLEGAL: 3182 case T_VOID: 3183 etype = T_BYTE; // will produce conservatively high value 3184 } 3185 cache = res = arrayOopDesc::max_array_length(etype); 3186 } 3187 return res; 3188 } 3189 3190 // Narrow the given size type to the index range for the given array base type. 3191 // Return NULL if the resulting int type becomes empty. 3192 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const { 3193 jint hi = size->_hi; 3194 jint lo = size->_lo; 3195 jint min_lo = 0; 3196 jint max_hi = max_array_length(elem()->basic_type()); 3197 //if (index_not_size) --max_hi; // type of a valid array index, FTR 3198 bool chg = false; 3199 if (lo < min_lo) { lo = min_lo; chg = true; } 3200 if (hi > max_hi) { hi = max_hi; chg = true; } 3201 // Negative length arrays will produce weird intermediate dead fast-path code 3202 if (lo > hi) 3203 return TypeInt::ZERO; 3204 if (!chg) 3205 return size; 3206 return TypeInt::make(lo, hi, Type::WidenMin); 3207 } 3208 3209 //-------------------------------cast_to_size---------------------------------- 3210 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const { 3211 assert(new_size != NULL, ""); 3212 new_size = narrow_size_type(new_size); 3213 if (new_size == size()) return this; 3214 const TypeAry* new_ary = TypeAry::make(elem(), new_size); 3215 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id); 3216 } 3217 3218 3219 //------------------------------eq--------------------------------------------- 3220 // Structural equality check for Type representations 3221 bool TypeAryPtr::eq( const Type *t ) const { 3222 const TypeAryPtr *p = t->is_aryptr(); 3223 return 3224 _ary == p->_ary && // Check array 3225 TypeOopPtr::eq(p); // Check sub-parts 3226 } 3227 3228 //------------------------------hash------------------------------------------- 3229 // Type-specific hashing function. 3230 int TypeAryPtr::hash(void) const { 3231 return (intptr_t)_ary + TypeOopPtr::hash(); 3232 } 3233 3234 //------------------------------meet------------------------------------------- 3235 // Compute the MEET of two types. It returns a new Type object. 3236 const Type *TypeAryPtr::xmeet( const Type *t ) const { 3237 // Perform a fast test for common case; meeting the same types together. 3238 if( this == t ) return this; // Meeting same type-rep? 3239 // Current "this->_base" is Pointer 3240 switch (t->base()) { // switch on original type 3241 3242 // Mixing ints & oops happens when javac reuses local variables 3243 case Int: 3244 case Long: 3245 case FloatTop: 3246 case FloatCon: 3247 case FloatBot: 3248 case DoubleTop: 3249 case DoubleCon: 3250 case DoubleBot: 3251 case NarrowOop: 3252 case Bottom: // Ye Olde Default 3253 return Type::BOTTOM; 3254 case Top: 3255 return this; 3256 3257 default: // All else is a mistake 3258 typerr(t); 3259 3260 case OopPtr: { // Meeting to OopPtrs 3261 // Found a OopPtr type vs self-AryPtr type 3262 const TypePtr *tp = t->is_oopptr(); 3263 int offset = meet_offset(tp->offset()); 3264 PTR ptr = meet_ptr(tp->ptr()); 3265 switch (tp->ptr()) { 3266 case TopPTR: 3267 case AnyNull: { 3268 int instance_id = meet_instance_id(InstanceTop); 3269 return make(ptr, (ptr == Constant ? const_oop() : NULL), 3270 _ary, _klass, _klass_is_exact, offset, instance_id); 3271 } 3272 case BotPTR: 3273 case NotNull: 3274 return TypeOopPtr::make(ptr, offset); 3275 default: ShouldNotReachHere(); 3276 } 3277 } 3278 3279 case AnyPtr: { // Meeting two AnyPtrs 3280 // Found an AnyPtr type vs self-AryPtr type 3281 const TypePtr *tp = t->is_ptr(); 3282 int offset = meet_offset(tp->offset()); 3283 PTR ptr = meet_ptr(tp->ptr()); 3284 switch (tp->ptr()) { 3285 case TopPTR: 3286 return this; 3287 case BotPTR: 3288 case NotNull: 3289 return TypePtr::make(AnyPtr, ptr, offset); 3290 case Null: 3291 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset); 3292 // else fall through to AnyNull 3293 case AnyNull: { 3294 int instance_id = meet_instance_id(InstanceTop); 3295 return make( ptr, (ptr == Constant ? const_oop() : NULL), 3296 _ary, _klass, _klass_is_exact, offset, instance_id); 3297 } 3298 default: ShouldNotReachHere(); 3299 } 3300 } 3301 3302 case RawPtr: return TypePtr::BOTTOM; 3303 3304 case AryPtr: { // Meeting 2 references? 3305 const TypeAryPtr *tap = t->is_aryptr(); 3306 int off = meet_offset(tap->offset()); 3307 const TypeAry *tary = _ary->meet(tap->_ary)->is_ary(); 3308 PTR ptr = meet_ptr(tap->ptr()); 3309 int instance_id = meet_instance_id(tap->instance_id()); 3310 ciKlass* lazy_klass = NULL; 3311 if (tary->_elem->isa_int()) { 3312 // Integral array element types have irrelevant lattice relations. 3313 // It is the klass that determines array layout, not the element type. 3314 if (_klass == NULL) 3315 lazy_klass = tap->_klass; 3316 else if (tap->_klass == NULL || tap->_klass == _klass) { 3317 lazy_klass = _klass; 3318 } else { 3319 // Something like byte[int+] meets char[int+]. 3320 // This must fall to bottom, not (int[-128..65535])[int+]. 3321 instance_id = InstanceBot; 3322 tary = TypeAry::make(Type::BOTTOM, tary->_size); 3323 } 3324 } 3325 bool xk; 3326 switch (tap->ptr()) { 3327 case AnyNull: 3328 case TopPTR: 3329 // Compute new klass on demand, do not use tap->_klass 3330 xk = (tap->_klass_is_exact | this->_klass_is_exact); 3331 return make( ptr, const_oop(), tary, lazy_klass, xk, off, instance_id ); 3332 case Constant: { 3333 ciObject* o = const_oop(); 3334 if( _ptr == Constant ) { 3335 if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) { 3336 ptr = NotNull; 3337 o = NULL; 3338 instance_id = InstanceBot; 3339 } 3340 } else if( above_centerline(_ptr) ) { 3341 o = tap->const_oop(); 3342 } 3343 xk = true; 3344 return TypeAryPtr::make( ptr, o, tary, tap->_klass, xk, off, instance_id ); 3345 } 3346 case NotNull: 3347 case BotPTR: 3348 // Compute new klass on demand, do not use tap->_klass 3349 if (above_centerline(this->_ptr)) 3350 xk = tap->_klass_is_exact; 3351 else if (above_centerline(tap->_ptr)) 3352 xk = this->_klass_is_exact; 3353 else xk = (tap->_klass_is_exact & this->_klass_is_exact) && 3354 (klass() == tap->klass()); // Only precise for identical arrays 3355 return TypeAryPtr::make( ptr, NULL, tary, lazy_klass, xk, off, instance_id ); 3356 default: ShouldNotReachHere(); 3357 } 3358 } 3359 3360 // All arrays inherit from Object class 3361 case InstPtr: { 3362 const TypeInstPtr *tp = t->is_instptr(); 3363 int offset = meet_offset(tp->offset()); 3364 PTR ptr = meet_ptr(tp->ptr()); 3365 int instance_id = meet_instance_id(tp->instance_id()); 3366 switch (ptr) { 3367 case TopPTR: 3368 case AnyNull: // Fall 'down' to dual of object klass 3369 if( tp->klass()->equals(ciEnv::current()->Object_klass()) ) { 3370 return TypeAryPtr::make( ptr, _ary, _klass, _klass_is_exact, offset, instance_id ); 3371 } else { 3372 // cannot subclass, so the meet has to fall badly below the centerline 3373 ptr = NotNull; 3374 instance_id = InstanceBot; 3375 return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id); 3376 } 3377 case Constant: 3378 case NotNull: 3379 case BotPTR: // Fall down to object klass 3380 // LCA is object_klass, but if we subclass from the top we can do better 3381 if (above_centerline(tp->ptr())) { 3382 // If 'tp' is above the centerline and it is Object class 3383 // then we can subclass in the Java class hierarchy. 3384 if( tp->klass()->equals(ciEnv::current()->Object_klass()) ) { 3385 // that is, my array type is a subtype of 'tp' klass 3386 return make( ptr, _ary, _klass, _klass_is_exact, offset, instance_id ); 3387 } 3388 } 3389 // The other case cannot happen, since t cannot be a subtype of an array. 3390 // The meet falls down to Object class below centerline. 3391 if( ptr == Constant ) 3392 ptr = NotNull; 3393 instance_id = InstanceBot; 3394 return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id); 3395 default: typerr(t); 3396 } 3397 } 3398 3399 case KlassPtr: 3400 return TypeInstPtr::BOTTOM; 3401 3402 } 3403 return this; // Lint noise 3404 } 3405 3406 //------------------------------xdual------------------------------------------ 3407 // Dual: compute field-by-field dual 3408 const Type *TypeAryPtr::xdual() const { 3409 return new TypeAryPtr( dual_ptr(), _const_oop, _ary->dual()->is_ary(),_klass, _klass_is_exact, dual_offset(), dual_instance_id() ); 3410 } 3411 3412 //----------------------interface_vs_oop--------------------------------------- 3413 #ifdef ASSERT 3414 bool TypeAryPtr::interface_vs_oop(const Type *t) const { 3415 const TypeAryPtr* t_aryptr = t->isa_aryptr(); 3416 if (t_aryptr) { 3417 return _ary->interface_vs_oop(t_aryptr->_ary); 3418 } 3419 return false; 3420 } 3421 #endif 3422 3423 //------------------------------dump2------------------------------------------ 3424 #ifndef PRODUCT 3425 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const { 3426 _ary->dump2(d,depth,st); 3427 switch( _ptr ) { 3428 case Constant: 3429 const_oop()->print(st); 3430 break; 3431 case BotPTR: 3432 if (!WizardMode && !Verbose) { 3433 if( _klass_is_exact ) st->print(":exact"); 3434 break; 3435 } 3436 case TopPTR: 3437 case AnyNull: 3438 case NotNull: 3439 st->print(":%s", ptr_msg[_ptr]); 3440 if( _klass_is_exact ) st->print(":exact"); 3441 break; 3442 } 3443 3444 if( _offset != 0 ) { 3445 int header_size = objArrayOopDesc::header_size() * wordSize; 3446 if( _offset == OffsetTop ) st->print("+undefined"); 3447 else if( _offset == OffsetBot ) st->print("+any"); 3448 else if( _offset < header_size ) st->print("+%d", _offset); 3449 else { 3450 BasicType basic_elem_type = elem()->basic_type(); 3451 int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type); 3452 int elem_size = type2aelembytes(basic_elem_type); 3453 st->print("[%d]", (_offset - array_base)/elem_size); 3454 } 3455 } 3456 st->print(" *"); 3457 if (_instance_id == InstanceTop) 3458 st->print(",iid=top"); 3459 else if (_instance_id != InstanceBot) 3460 st->print(",iid=%d",_instance_id); 3461 } 3462 #endif 3463 3464 bool TypeAryPtr::empty(void) const { 3465 if (_ary->empty()) return true; 3466 return TypeOopPtr::empty(); 3467 } 3468 3469 //------------------------------add_offset------------------------------------- 3470 const TypePtr *TypeAryPtr::add_offset( intptr_t offset ) const { 3471 return make( _ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id ); 3472 } 3473 3474 3475 //============================================================================= 3476 const TypeNarrowOop *TypeNarrowOop::BOTTOM; 3477 const TypeNarrowOop *TypeNarrowOop::NULL_PTR; 3478 3479 3480 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) { 3481 return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons(); 3482 } 3483 3484 //------------------------------hash------------------------------------------- 3485 // Type-specific hashing function. 3486 int TypeNarrowOop::hash(void) const { 3487 return _ptrtype->hash() + 7; 3488 } 3489 3490 3491 bool TypeNarrowOop::eq( const Type *t ) const { 3492 const TypeNarrowOop* tc = t->isa_narrowoop(); 3493 if (tc != NULL) { 3494 if (_ptrtype->base() != tc->_ptrtype->base()) { 3495 return false; 3496 } 3497 return tc->_ptrtype->eq(_ptrtype); 3498 } 3499 return false; 3500 } 3501 3502 bool TypeNarrowOop::singleton(void) const { // TRUE if type is a singleton 3503 return _ptrtype->singleton(); 3504 } 3505 3506 bool TypeNarrowOop::empty(void) const { 3507 return _ptrtype->empty(); 3508 } 3509 3510 //------------------------------xmeet------------------------------------------ 3511 // Compute the MEET of two types. It returns a new Type object. 3512 const Type *TypeNarrowOop::xmeet( const Type *t ) const { 3513 // Perform a fast test for common case; meeting the same types together. 3514 if( this == t ) return this; // Meeting same type-rep? 3515 3516 3517 // Current "this->_base" is OopPtr 3518 switch (t->base()) { // switch on original type 3519 3520 case Int: // Mixing ints & oops happens when javac 3521 case Long: // reuses local variables 3522 case FloatTop: 3523 case FloatCon: 3524 case FloatBot: 3525 case DoubleTop: 3526 case DoubleCon: 3527 case DoubleBot: 3528 case AnyPtr: 3529 case RawPtr: 3530 case OopPtr: 3531 case InstPtr: 3532 case KlassPtr: 3533 case AryPtr: 3534 3535 case Bottom: // Ye Olde Default 3536 return Type::BOTTOM; 3537 case Top: 3538 return this; 3539 3540 case NarrowOop: { 3541 const Type* result = _ptrtype->xmeet(t->make_ptr()); 3542 if (result->isa_ptr()) { 3543 return TypeNarrowOop::make(result->is_ptr()); 3544 } 3545 return result; 3546 } 3547 3548 default: // All else is a mistake 3549 typerr(t); 3550 3551 } // End of switch 3552 3553 return this; 3554 } 3555 3556 const Type *TypeNarrowOop::xdual() const { // Compute dual right now. 3557 const TypePtr* odual = _ptrtype->dual()->is_ptr(); 3558 return new TypeNarrowOop(odual); 3559 } 3560 3561 const Type *TypeNarrowOop::filter( const Type *kills ) const { 3562 if (kills->isa_narrowoop()) { 3563 const Type* ft =_ptrtype->filter(kills->is_narrowoop()->_ptrtype); 3564 if (ft->empty()) 3565 return Type::TOP; // Canonical empty value 3566 if (ft->isa_ptr()) { 3567 return make(ft->isa_ptr()); 3568 } 3569 return ft; 3570 } else if (kills->isa_ptr()) { 3571 const Type* ft = _ptrtype->join(kills); 3572 if (ft->empty()) 3573 return Type::TOP; // Canonical empty value 3574 return ft; 3575 } else { 3576 return Type::TOP; 3577 } 3578 } 3579 3580 3581 intptr_t TypeNarrowOop::get_con() const { 3582 return _ptrtype->get_con(); 3583 } 3584 3585 #ifndef PRODUCT 3586 void TypeNarrowOop::dump2( Dict & d, uint depth, outputStream *st ) const { 3587 st->print("narrowoop: "); 3588 _ptrtype->dump2(d, depth, st); 3589 } 3590 #endif 3591 3592 3593 //============================================================================= 3594 // Convenience common pre-built types. 3595 3596 // Not-null object klass or below 3597 const TypeKlassPtr *TypeKlassPtr::OBJECT; 3598 const TypeKlassPtr *TypeKlassPtr::OBJECT_OR_NULL; 3599 3600 //------------------------------TypeKlasPtr------------------------------------ 3601 TypeKlassPtr::TypeKlassPtr( PTR ptr, ciKlass* klass, int offset ) 3602 : TypeOopPtr(KlassPtr, ptr, klass, (ptr==Constant), (ptr==Constant ? klass : NULL), offset, 0) { 3603 } 3604 3605 //------------------------------make------------------------------------------- 3606 // ptr to klass 'k', if Constant, or possibly to a sub-klass if not a Constant 3607 const TypeKlassPtr *TypeKlassPtr::make( PTR ptr, ciKlass* k, int offset ) { 3608 assert( k != NULL, "Expect a non-NULL klass"); 3609 assert(k->is_instance_klass() || k->is_array_klass() || 3610 k->is_method_klass(), "Incorrect type of klass oop"); 3611 TypeKlassPtr *r = 3612 (TypeKlassPtr*)(new TypeKlassPtr(ptr, k, offset))->hashcons(); 3613 3614 return r; 3615 } 3616 3617 //------------------------------eq--------------------------------------------- 3618 // Structural equality check for Type representations 3619 bool TypeKlassPtr::eq( const Type *t ) const { 3620 const TypeKlassPtr *p = t->is_klassptr(); 3621 return 3622 klass()->equals(p->klass()) && 3623 TypeOopPtr::eq(p); 3624 } 3625 3626 //------------------------------hash------------------------------------------- 3627 // Type-specific hashing function. 3628 int TypeKlassPtr::hash(void) const { 3629 return klass()->hash() + TypeOopPtr::hash(); 3630 } 3631 3632 3633 //------------------------------klass------------------------------------------ 3634 // Return the defining klass for this class 3635 ciKlass* TypeAryPtr::klass() const { 3636 if( _klass ) return _klass; // Return cached value, if possible 3637 3638 // Oops, need to compute _klass and cache it 3639 ciKlass* k_ary = NULL; 3640 const TypeInstPtr *tinst; 3641 const TypeAryPtr *tary; 3642 const Type* el = elem(); 3643 if (el->isa_narrowoop()) { 3644 el = el->make_ptr(); 3645 } 3646 3647 // Get element klass 3648 if ((tinst = el->isa_instptr()) != NULL) { 3649 // Compute array klass from element klass 3650 k_ary = ciObjArrayKlass::make(tinst->klass()); 3651 } else if ((tary = el->isa_aryptr()) != NULL) { 3652 // Compute array klass from element klass 3653 ciKlass* k_elem = tary->klass(); 3654 // If element type is something like bottom[], k_elem will be null. 3655 if (k_elem != NULL) 3656 k_ary = ciObjArrayKlass::make(k_elem); 3657 } else if ((el->base() == Type::Top) || 3658 (el->base() == Type::Bottom)) { 3659 // element type of Bottom occurs from meet of basic type 3660 // and object; Top occurs when doing join on Bottom. 3661 // Leave k_ary at NULL. 3662 } else { 3663 // Cannot compute array klass directly from basic type, 3664 // since subtypes of TypeInt all have basic type T_INT. 3665 assert(!el->isa_int(), 3666 "integral arrays must be pre-equipped with a class"); 3667 // Compute array klass directly from basic type 3668 k_ary = ciTypeArrayKlass::make(el->basic_type()); 3669 } 3670 3671 if( this != TypeAryPtr::OOPS ) { 3672 // The _klass field acts as a cache of the underlying 3673 // ciKlass for this array type. In order to set the field, 3674 // we need to cast away const-ness. 3675 // 3676 // IMPORTANT NOTE: we *never* set the _klass field for the 3677 // type TypeAryPtr::OOPS. This Type is shared between all 3678 // active compilations. However, the ciKlass which represents 3679 // this Type is *not* shared between compilations, so caching 3680 // this value would result in fetching a dangling pointer. 3681 // 3682 // Recomputing the underlying ciKlass for each request is 3683 // a bit less efficient than caching, but calls to 3684 // TypeAryPtr::OOPS->klass() are not common enough to matter. 3685 ((TypeAryPtr*)this)->_klass = k_ary; 3686 if (UseCompressedOops && k_ary != NULL && k_ary->is_obj_array_klass() && 3687 _offset != 0 && _offset != arrayOopDesc::length_offset_in_bytes()) { 3688 ((TypeAryPtr*)this)->_is_ptr_to_narrowoop = true; 3689 } 3690 } 3691 return k_ary; 3692 } 3693 3694 3695 //------------------------------add_offset------------------------------------- 3696 // Access internals of klass object 3697 const TypePtr *TypeKlassPtr::add_offset( intptr_t offset ) const { 3698 return make( _ptr, klass(), xadd_offset(offset) ); 3699 } 3700 3701 //------------------------------cast_to_ptr_type------------------------------- 3702 const Type *TypeKlassPtr::cast_to_ptr_type(PTR ptr) const { 3703 assert(_base == KlassPtr, "subclass must override cast_to_ptr_type"); 3704 if( ptr == _ptr ) return this; 3705 return make(ptr, _klass, _offset); 3706 } 3707 3708 3709 //-----------------------------cast_to_exactness------------------------------- 3710 const Type *TypeKlassPtr::cast_to_exactness(bool klass_is_exact) const { 3711 if( klass_is_exact == _klass_is_exact ) return this; 3712 if (!UseExactTypes) return this; 3713 return make(klass_is_exact ? Constant : NotNull, _klass, _offset); 3714 } 3715 3716 3717 //-----------------------------as_instance_type-------------------------------- 3718 // Corresponding type for an instance of the given class. 3719 // It will be NotNull, and exact if and only if the klass type is exact. 3720 const TypeOopPtr* TypeKlassPtr::as_instance_type() const { 3721 ciKlass* k = klass(); 3722 bool xk = klass_is_exact(); 3723 //return TypeInstPtr::make(TypePtr::NotNull, k, xk, NULL, 0); 3724 const TypeOopPtr* toop = TypeOopPtr::make_from_klass_raw(k); 3725 toop = toop->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr(); 3726 return toop->cast_to_exactness(xk)->is_oopptr(); 3727 } 3728 3729 3730 //------------------------------xmeet------------------------------------------ 3731 // Compute the MEET of two types, return a new Type object. 3732 const Type *TypeKlassPtr::xmeet( const Type *t ) const { 3733 // Perform a fast test for common case; meeting the same types together. 3734 if( this == t ) return this; // Meeting same type-rep? 3735 3736 // Current "this->_base" is Pointer 3737 switch (t->base()) { // switch on original type 3738 3739 case Int: // Mixing ints & oops happens when javac 3740 case Long: // reuses local variables 3741 case FloatTop: 3742 case FloatCon: 3743 case FloatBot: 3744 case DoubleTop: 3745 case DoubleCon: 3746 case DoubleBot: 3747 case NarrowOop: 3748 case Bottom: // Ye Olde Default 3749 return Type::BOTTOM; 3750 case Top: 3751 return this; 3752 3753 default: // All else is a mistake 3754 typerr(t); 3755 3756 case RawPtr: return TypePtr::BOTTOM; 3757 3758 case OopPtr: { // Meeting to OopPtrs 3759 // Found a OopPtr type vs self-KlassPtr type 3760 const TypePtr *tp = t->is_oopptr(); 3761 int offset = meet_offset(tp->offset()); 3762 PTR ptr = meet_ptr(tp->ptr()); 3763 switch (tp->ptr()) { 3764 case TopPTR: 3765 case AnyNull: 3766 return make(ptr, klass(), offset); 3767 case BotPTR: 3768 case NotNull: 3769 return TypePtr::make(AnyPtr, ptr, offset); 3770 default: typerr(t); 3771 } 3772 } 3773 3774 case AnyPtr: { // Meeting to AnyPtrs 3775 // Found an AnyPtr type vs self-KlassPtr type 3776 const TypePtr *tp = t->is_ptr(); 3777 int offset = meet_offset(tp->offset()); 3778 PTR ptr = meet_ptr(tp->ptr()); 3779 switch (tp->ptr()) { 3780 case TopPTR: 3781 return this; 3782 case Null: 3783 if( ptr == Null ) return TypePtr::make( AnyPtr, ptr, offset ); 3784 case AnyNull: 3785 return make( ptr, klass(), offset ); 3786 case BotPTR: 3787 case NotNull: 3788 return TypePtr::make(AnyPtr, ptr, offset); 3789 default: typerr(t); 3790 } 3791 } 3792 3793 case AryPtr: // Meet with AryPtr 3794 case InstPtr: // Meet with InstPtr 3795 return TypeInstPtr::BOTTOM; 3796 3797 // 3798 // A-top } 3799 // / | \ } Tops 3800 // B-top A-any C-top } 3801 // | / | \ | } Any-nulls 3802 // B-any | C-any } 3803 // | | | 3804 // B-con A-con C-con } constants; not comparable across classes 3805 // | | | 3806 // B-not | C-not } 3807 // | \ | / | } not-nulls 3808 // B-bot A-not C-bot } 3809 // \ | / } Bottoms 3810 // A-bot } 3811 // 3812 3813 case KlassPtr: { // Meet two KlassPtr types 3814 const TypeKlassPtr *tkls = t->is_klassptr(); 3815 int off = meet_offset(tkls->offset()); 3816 PTR ptr = meet_ptr(tkls->ptr()); 3817 3818 // Check for easy case; klasses are equal (and perhaps not loaded!) 3819 // If we have constants, then we created oops so classes are loaded 3820 // and we can handle the constants further down. This case handles 3821 // not-loaded classes 3822 if( ptr != Constant && tkls->klass()->equals(klass()) ) { 3823 return make( ptr, klass(), off ); 3824 } 3825 3826 // Classes require inspection in the Java klass hierarchy. Must be loaded. 3827 ciKlass* tkls_klass = tkls->klass(); 3828 ciKlass* this_klass = this->klass(); 3829 assert( tkls_klass->is_loaded(), "This class should have been loaded."); 3830 assert( this_klass->is_loaded(), "This class should have been loaded."); 3831 3832 // If 'this' type is above the centerline and is a superclass of the 3833 // other, we can treat 'this' as having the same type as the other. 3834 if ((above_centerline(this->ptr())) && 3835 tkls_klass->is_subtype_of(this_klass)) { 3836 this_klass = tkls_klass; 3837 } 3838 // If 'tinst' type is above the centerline and is a superclass of the 3839 // other, we can treat 'tinst' as having the same type as the other. 3840 if ((above_centerline(tkls->ptr())) && 3841 this_klass->is_subtype_of(tkls_klass)) { 3842 tkls_klass = this_klass; 3843 } 3844 3845 // Check for classes now being equal 3846 if (tkls_klass->equals(this_klass)) { 3847 // If the klasses are equal, the constants may still differ. Fall to 3848 // NotNull if they do (neither constant is NULL; that is a special case 3849 // handled elsewhere). 3850 ciObject* o = NULL; // Assume not constant when done 3851 ciObject* this_oop = const_oop(); 3852 ciObject* tkls_oop = tkls->const_oop(); 3853 if( ptr == Constant ) { 3854 if (this_oop != NULL && tkls_oop != NULL && 3855 this_oop->equals(tkls_oop) ) 3856 o = this_oop; 3857 else if (above_centerline(this->ptr())) 3858 o = tkls_oop; 3859 else if (above_centerline(tkls->ptr())) 3860 o = this_oop; 3861 else 3862 ptr = NotNull; 3863 } 3864 return make( ptr, this_klass, off ); 3865 } // Else classes are not equal 3866 3867 // Since klasses are different, we require the LCA in the Java 3868 // class hierarchy - which means we have to fall to at least NotNull. 3869 if( ptr == TopPTR || ptr == AnyNull || ptr == Constant ) 3870 ptr = NotNull; 3871 // Now we find the LCA of Java classes 3872 ciKlass* k = this_klass->least_common_ancestor(tkls_klass); 3873 return make( ptr, k, off ); 3874 } // End of case KlassPtr 3875 3876 } // End of switch 3877 return this; // Return the double constant 3878 } 3879 3880 //------------------------------xdual------------------------------------------ 3881 // Dual: compute field-by-field dual 3882 const Type *TypeKlassPtr::xdual() const { 3883 return new TypeKlassPtr( dual_ptr(), klass(), dual_offset() ); 3884 } 3885 3886 //------------------------------dump2------------------------------------------ 3887 // Dump Klass Type 3888 #ifndef PRODUCT 3889 void TypeKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const { 3890 switch( _ptr ) { 3891 case Constant: 3892 st->print("precise "); 3893 case NotNull: 3894 { 3895 const char *name = klass()->name()->as_utf8(); 3896 if( name ) { 3897 st->print("klass %s: " INTPTR_FORMAT, name, klass()); 3898 } else { 3899 ShouldNotReachHere(); 3900 } 3901 } 3902 case BotPTR: 3903 if( !WizardMode && !Verbose && !_klass_is_exact ) break; 3904 case TopPTR: 3905 case AnyNull: 3906 st->print(":%s", ptr_msg[_ptr]); 3907 if( _klass_is_exact ) st->print(":exact"); 3908 break; 3909 } 3910 3911 if( _offset ) { // Dump offset, if any 3912 if( _offset == OffsetBot ) { st->print("+any"); } 3913 else if( _offset == OffsetTop ) { st->print("+unknown"); } 3914 else { st->print("+%d", _offset); } 3915 } 3916 3917 st->print(" *"); 3918 } 3919 #endif 3920 3921 3922 3923 //============================================================================= 3924 // Convenience common pre-built types. 3925 3926 //------------------------------make------------------------------------------- 3927 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) { 3928 return (TypeFunc*)(new TypeFunc(domain,range))->hashcons(); 3929 } 3930 3931 //------------------------------make------------------------------------------- 3932 const TypeFunc *TypeFunc::make(ciMethod* method) { 3933 Compile* C = Compile::current(); 3934 const TypeFunc* tf = C->last_tf(method); // check cache 3935 if (tf != NULL) return tf; // The hit rate here is almost 50%. 3936 const TypeTuple *domain; 3937 if (method->flags().is_static()) { 3938 domain = TypeTuple::make_domain(NULL, method->signature()); 3939 } else { 3940 domain = TypeTuple::make_domain(method->holder(), method->signature()); 3941 } 3942 const TypeTuple *range = TypeTuple::make_range(method->signature()); 3943 tf = TypeFunc::make(domain, range); 3944 C->set_last_tf(method, tf); // fill cache 3945 return tf; 3946 } 3947 3948 //------------------------------meet------------------------------------------- 3949 // Compute the MEET of two types. It returns a new Type object. 3950 const Type *TypeFunc::xmeet( const Type *t ) const { 3951 // Perform a fast test for common case; meeting the same types together. 3952 if( this == t ) return this; // Meeting same type-rep? 3953 3954 // Current "this->_base" is Func 3955 switch (t->base()) { // switch on original type 3956 3957 case Bottom: // Ye Olde Default 3958 return t; 3959 3960 default: // All else is a mistake 3961 typerr(t); 3962 3963 case Top: 3964 break; 3965 } 3966 return this; // Return the double constant 3967 } 3968 3969 //------------------------------xdual------------------------------------------ 3970 // Dual: compute field-by-field dual 3971 const Type *TypeFunc::xdual() const { 3972 return this; 3973 } 3974 3975 //------------------------------eq--------------------------------------------- 3976 // Structural equality check for Type representations 3977 bool TypeFunc::eq( const Type *t ) const { 3978 const TypeFunc *a = (const TypeFunc*)t; 3979 return _domain == a->_domain && 3980 _range == a->_range; 3981 } 3982 3983 //------------------------------hash------------------------------------------- 3984 // Type-specific hashing function. 3985 int TypeFunc::hash(void) const { 3986 return (intptr_t)_domain + (intptr_t)_range; 3987 } 3988 3989 //------------------------------dump2------------------------------------------ 3990 // Dump Function Type 3991 #ifndef PRODUCT 3992 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const { 3993 if( _range->_cnt <= Parms ) 3994 st->print("void"); 3995 else { 3996 uint i; 3997 for (i = Parms; i < _range->_cnt-1; i++) { 3998 _range->field_at(i)->dump2(d,depth,st); 3999 st->print("/"); 4000 } 4001 _range->field_at(i)->dump2(d,depth,st); 4002 } 4003 st->print(" "); 4004 st->print("( "); 4005 if( !depth || d[this] ) { // Check for recursive dump 4006 st->print("...)"); 4007 return; 4008 } 4009 d.Insert((void*)this,(void*)this); // Stop recursion 4010 if (Parms < _domain->_cnt) 4011 _domain->field_at(Parms)->dump2(d,depth-1,st); 4012 for (uint i = Parms+1; i < _domain->_cnt; i++) { 4013 st->print(", "); 4014 _domain->field_at(i)->dump2(d,depth-1,st); 4015 } 4016 st->print(" )"); 4017 } 4018 4019 //------------------------------print_flattened-------------------------------- 4020 // Print a 'flattened' signature 4021 static const char * const flat_type_msg[Type::lastype] = { 4022 "bad","control","top","int","long","_", "narrowoop", 4023 "tuple:", "array:", 4024 "ptr", "rawptr", "ptr", "ptr", "ptr", "ptr", 4025 "func", "abIO", "return_address", "mem", 4026 "float_top", "ftcon:", "flt", 4027 "double_top", "dblcon:", "dbl", 4028 "bottom" 4029 }; 4030 4031 void TypeFunc::print_flattened() const { 4032 if( _range->_cnt <= Parms ) 4033 tty->print("void"); 4034 else { 4035 uint i; 4036 for (i = Parms; i < _range->_cnt-1; i++) 4037 tty->print("%s/",flat_type_msg[_range->field_at(i)->base()]); 4038 tty->print("%s",flat_type_msg[_range->field_at(i)->base()]); 4039 } 4040 tty->print(" ( "); 4041 if (Parms < _domain->_cnt) 4042 tty->print("%s",flat_type_msg[_domain->field_at(Parms)->base()]); 4043 for (uint i = Parms+1; i < _domain->_cnt; i++) 4044 tty->print(", %s",flat_type_msg[_domain->field_at(i)->base()]); 4045 tty->print(" )"); 4046 } 4047 #endif 4048 4049 //------------------------------singleton-------------------------------------- 4050 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 4051 // constants (Ldi nodes). Singletons are integer, float or double constants 4052 // or a single symbol. 4053 bool TypeFunc::singleton(void) const { 4054 return false; // Never a singleton 4055 } 4056 4057 bool TypeFunc::empty(void) const { 4058 return false; // Never empty 4059 } 4060 4061 4062 BasicType TypeFunc::return_type() const{ 4063 if (range()->cnt() == TypeFunc::Parms) { 4064 return T_VOID; 4065 } 4066 return range()->field_at(TypeFunc::Parms)->basic_type(); 4067 }