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, int instance_id) { 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, instance_id))->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 int instance_id = meet_instance_id(tp->instance_id()); 2334 return make( meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id ); 2335 } 2336 2337 case InstPtr: // For these, flip the call around to cut down 2338 case KlassPtr: // on the cases I have to handle. 2339 case AryPtr: 2340 return t->xmeet(this); // Call in reverse direction 2341 2342 } // End of switch 2343 return this; // Return the double constant 2344 } 2345 2346 2347 //------------------------------xdual------------------------------------------ 2348 // Dual of a pure heap pointer. No relevant klass or oop information. 2349 const Type *TypeOopPtr::xdual() const { 2350 assert(klass() == ciKlassKlass::make(), "no klasses here"); 2351 assert(const_oop() == NULL, "no constants here"); 2352 return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id() ); 2353 } 2354 2355 //--------------------------make_from_klass_common----------------------------- 2356 // Computes the element-type given a klass. 2357 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) { 2358 assert(klass->is_java_klass(), "must be java language klass"); 2359 if (klass->is_instance_klass()) { 2360 Compile* C = Compile::current(); 2361 Dependencies* deps = C->dependencies(); 2362 assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity"); 2363 // Element is an instance 2364 bool klass_is_exact = false; 2365 if (klass->is_loaded()) { 2366 // Try to set klass_is_exact. 2367 ciInstanceKlass* ik = klass->as_instance_klass(); 2368 klass_is_exact = ik->is_final(); 2369 if (!klass_is_exact && klass_change 2370 && deps != NULL && UseUniqueSubclasses) { 2371 ciInstanceKlass* sub = ik->unique_concrete_subklass(); 2372 if (sub != NULL) { 2373 deps->assert_abstract_with_unique_concrete_subtype(ik, sub); 2374 klass = ik = sub; 2375 klass_is_exact = sub->is_final(); 2376 } 2377 } 2378 if (!klass_is_exact && try_for_exact 2379 && deps != NULL && UseExactTypes) { 2380 if (!ik->is_interface() && !ik->has_subklass()) { 2381 // Add a dependence; if concrete subclass added we need to recompile 2382 deps->assert_leaf_type(ik); 2383 klass_is_exact = true; 2384 } 2385 } 2386 } 2387 return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, 0); 2388 } else if (klass->is_obj_array_klass()) { 2389 // Element is an object array. Recursively call ourself. 2390 const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(klass->as_obj_array_klass()->element_klass(), false, try_for_exact); 2391 bool xk = etype->klass_is_exact(); 2392 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS); 2393 // We used to pass NotNull in here, asserting that the sub-arrays 2394 // are all not-null. This is not true in generally, as code can 2395 // slam NULLs down in the subarrays. 2396 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, 0); 2397 return arr; 2398 } else if (klass->is_type_array_klass()) { 2399 // Element is an typeArray 2400 const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type()); 2401 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS); 2402 // We used to pass NotNull in here, asserting that the array pointer 2403 // is not-null. That was not true in general. 2404 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, 0); 2405 return arr; 2406 } else { 2407 ShouldNotReachHere(); 2408 return NULL; 2409 } 2410 } 2411 2412 //------------------------------make_from_constant----------------------------- 2413 // Make a java pointer from an oop constant 2414 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o) { 2415 if (o->is_method_data() || o->is_method()) { 2416 // Treat much like a typeArray of bytes, like below, but fake the type... 2417 assert(o->has_encoding(), "must be a perm space object"); 2418 const Type* etype = (Type*)get_const_basic_type(T_BYTE); 2419 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS); 2420 ciKlass *klass = ciTypeArrayKlass::make((BasicType) T_BYTE); 2421 assert(o->has_encoding(), "method data oops should be tenured"); 2422 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0); 2423 return arr; 2424 } else { 2425 assert(o->is_java_object(), "must be java language object"); 2426 assert(!o->is_null_object(), "null object not yet handled here."); 2427 ciKlass *klass = o->klass(); 2428 if (klass->is_instance_klass()) { 2429 // Element is an instance 2430 if (!o->has_encoding()) { // not a perm-space constant 2431 // %%% remove this restriction by rewriting non-perm ConPNodes in a later phase 2432 return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, 0); 2433 } 2434 return TypeInstPtr::make(o); 2435 } else if (klass->is_obj_array_klass()) { 2436 // Element is an object array. Recursively call ourself. 2437 const Type *etype = 2438 TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass()); 2439 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length())); 2440 // We used to pass NotNull in here, asserting that the sub-arrays 2441 // are all not-null. This is not true in generally, as code can 2442 // slam NULLs down in the subarrays. 2443 if (!o->has_encoding()) { // not a perm-space constant 2444 // %%% remove this restriction by rewriting non-perm ConPNodes in a later phase 2445 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0); 2446 } 2447 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0); 2448 return arr; 2449 } else if (klass->is_type_array_klass()) { 2450 // Element is an typeArray 2451 const Type* etype = 2452 (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type()); 2453 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length())); 2454 // We used to pass NotNull in here, asserting that the array pointer 2455 // is not-null. That was not true in general. 2456 if (!o->has_encoding()) { // not a perm-space constant 2457 // %%% remove this restriction by rewriting non-perm ConPNodes in a later phase 2458 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0); 2459 } 2460 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0); 2461 return arr; 2462 } 2463 } 2464 2465 ShouldNotReachHere(); 2466 return NULL; 2467 } 2468 2469 //------------------------------get_con---------------------------------------- 2470 intptr_t TypeOopPtr::get_con() const { 2471 assert( _ptr == Null || _ptr == Constant, "" ); 2472 assert( _offset >= 0, "" ); 2473 2474 if (_offset != 0) { 2475 // After being ported to the compiler interface, the compiler no longer 2476 // directly manipulates the addresses of oops. Rather, it only has a pointer 2477 // to a handle at compile time. This handle is embedded in the generated 2478 // code and dereferenced at the time the nmethod is made. Until that time, 2479 // it is not reasonable to do arithmetic with the addresses of oops (we don't 2480 // have access to the addresses!). This does not seem to currently happen, 2481 // but this assertion here is to help prevent its occurence. 2482 tty->print_cr("Found oop constant with non-zero offset"); 2483 ShouldNotReachHere(); 2484 } 2485 2486 return (intptr_t)const_oop()->encoding(); 2487 } 2488 2489 2490 //-----------------------------filter------------------------------------------ 2491 // Do not allow interface-vs.-noninterface joins to collapse to top. 2492 const Type *TypeOopPtr::filter( const Type *kills ) const { 2493 2494 const Type* ft = join(kills); 2495 const TypeInstPtr* ftip = ft->isa_instptr(); 2496 const TypeInstPtr* ktip = kills->isa_instptr(); 2497 const TypeKlassPtr* ftkp = ft->isa_klassptr(); 2498 const TypeKlassPtr* ktkp = kills->isa_klassptr(); 2499 2500 if (ft->empty()) { 2501 // Check for evil case of 'this' being a class and 'kills' expecting an 2502 // interface. This can happen because the bytecodes do not contain 2503 // enough type info to distinguish a Java-level interface variable 2504 // from a Java-level object variable. If we meet 2 classes which 2505 // both implement interface I, but their meet is at 'j/l/O' which 2506 // doesn't implement I, we have no way to tell if the result should 2507 // be 'I' or 'j/l/O'. Thus we'll pick 'j/l/O'. If this then flows 2508 // into a Phi which "knows" it's an Interface type we'll have to 2509 // uplift the type. 2510 if (!empty() && ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface()) 2511 return kills; // Uplift to interface 2512 if (!empty() && ktkp != NULL && ktkp->klass()->is_loaded() && ktkp->klass()->is_interface()) 2513 return kills; // Uplift to interface 2514 2515 return Type::TOP; // Canonical empty value 2516 } 2517 2518 // If we have an interface-typed Phi or cast and we narrow to a class type, 2519 // the join should report back the class. However, if we have a J/L/Object 2520 // class-typed Phi and an interface flows in, it's possible that the meet & 2521 // join report an interface back out. This isn't possible but happens 2522 // because the type system doesn't interact well with interfaces. 2523 if (ftip != NULL && ktip != NULL && 2524 ftip->is_loaded() && ftip->klass()->is_interface() && 2525 ktip->is_loaded() && !ktip->klass()->is_interface()) { 2526 // Happens in a CTW of rt.jar, 320-341, no extra flags 2527 return ktip->cast_to_ptr_type(ftip->ptr()); 2528 } 2529 if (ftkp != NULL && ktkp != NULL && 2530 ftkp->is_loaded() && ftkp->klass()->is_interface() && 2531 ktkp->is_loaded() && !ktkp->klass()->is_interface()) { 2532 // Happens in a CTW of rt.jar, 320-341, no extra flags 2533 return ktkp->cast_to_ptr_type(ftkp->ptr()); 2534 } 2535 2536 return ft; 2537 } 2538 2539 //------------------------------eq--------------------------------------------- 2540 // Structural equality check for Type representations 2541 bool TypeOopPtr::eq( const Type *t ) const { 2542 const TypeOopPtr *a = (const TypeOopPtr*)t; 2543 if (_klass_is_exact != a->_klass_is_exact || 2544 _instance_id != a->_instance_id) return false; 2545 ciObject* one = const_oop(); 2546 ciObject* two = a->const_oop(); 2547 if (one == NULL || two == NULL) { 2548 return (one == two) && TypePtr::eq(t); 2549 } else { 2550 return one->equals(two) && TypePtr::eq(t); 2551 } 2552 } 2553 2554 //------------------------------hash------------------------------------------- 2555 // Type-specific hashing function. 2556 int TypeOopPtr::hash(void) const { 2557 return 2558 (const_oop() ? const_oop()->hash() : 0) + 2559 _klass_is_exact + 2560 _instance_id + 2561 TypePtr::hash(); 2562 } 2563 2564 //------------------------------dump2------------------------------------------ 2565 #ifndef PRODUCT 2566 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const { 2567 st->print("oopptr:%s", ptr_msg[_ptr]); 2568 if( _klass_is_exact ) st->print(":exact"); 2569 if( const_oop() ) st->print(INTPTR_FORMAT, const_oop()); 2570 switch( _offset ) { 2571 case OffsetTop: st->print("+top"); break; 2572 case OffsetBot: st->print("+any"); break; 2573 case 0: break; 2574 default: st->print("+%d",_offset); break; 2575 } 2576 if (_instance_id == InstanceTop) 2577 st->print(",iid=top"); 2578 else if (_instance_id != InstanceBot) 2579 st->print(",iid=%d",_instance_id); 2580 } 2581 #endif 2582 2583 //------------------------------singleton-------------------------------------- 2584 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 2585 // constants 2586 bool TypeOopPtr::singleton(void) const { 2587 // detune optimizer to not generate constant oop + constant offset as a constant! 2588 // TopPTR, Null, AnyNull, Constant are all singletons 2589 return (_offset == 0) && !below_centerline(_ptr); 2590 } 2591 2592 //------------------------------add_offset------------------------------------- 2593 const TypePtr *TypeOopPtr::add_offset( intptr_t offset ) const { 2594 return make( _ptr, xadd_offset(offset) ); 2595 } 2596 2597 //------------------------------meet_instance_id-------------------------------- 2598 int TypeOopPtr::meet_instance_id( int instance_id ) const { 2599 // Either is 'TOP' instance? Return the other instance! 2600 if( _instance_id == InstanceTop ) return instance_id; 2601 if( instance_id == InstanceTop ) return _instance_id; 2602 // If either is different, return 'BOTTOM' instance 2603 if( _instance_id != instance_id ) return InstanceBot; 2604 return _instance_id; 2605 } 2606 2607 //------------------------------dual_instance_id-------------------------------- 2608 int TypeOopPtr::dual_instance_id( ) const { 2609 if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM 2610 if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP 2611 return _instance_id; // Map everything else into self 2612 } 2613 2614 2615 //============================================================================= 2616 // Convenience common pre-built types. 2617 const TypeInstPtr *TypeInstPtr::NOTNULL; 2618 const TypeInstPtr *TypeInstPtr::BOTTOM; 2619 const TypeInstPtr *TypeInstPtr::MIRROR; 2620 const TypeInstPtr *TypeInstPtr::MARK; 2621 const TypeInstPtr *TypeInstPtr::KLASS; 2622 2623 //------------------------------TypeInstPtr------------------------------------- 2624 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int off, int instance_id) 2625 : TypeOopPtr(InstPtr, ptr, k, xk, o, off, instance_id), _name(k->name()) { 2626 assert(k != NULL && 2627 (k->is_loaded() || o == NULL), 2628 "cannot have constants with non-loaded klass"); 2629 }; 2630 2631 //------------------------------make------------------------------------------- 2632 const TypeInstPtr *TypeInstPtr::make(PTR ptr, 2633 ciKlass* k, 2634 bool xk, 2635 ciObject* o, 2636 int offset, 2637 int instance_id) { 2638 assert( !k->is_loaded() || k->is_instance_klass() || 2639 k->is_method_klass(), "Must be for instance or method"); 2640 // Either const_oop() is NULL or else ptr is Constant 2641 assert( (!o && ptr != Constant) || (o && ptr == Constant), 2642 "constant pointers must have a value supplied" ); 2643 // Ptr is never Null 2644 assert( ptr != Null, "NULL pointers are not typed" ); 2645 2646 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed"); 2647 if (!UseExactTypes) xk = false; 2648 if (ptr == Constant) { 2649 // Note: This case includes meta-object constants, such as methods. 2650 xk = true; 2651 } else if (k->is_loaded()) { 2652 ciInstanceKlass* ik = k->as_instance_klass(); 2653 if (!xk && ik->is_final()) xk = true; // no inexact final klass 2654 if (xk && ik->is_interface()) xk = false; // no exact interface 2655 } 2656 2657 // Now hash this baby 2658 TypeInstPtr *result = 2659 (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o ,offset, instance_id))->hashcons(); 2660 2661 return result; 2662 } 2663 2664 2665 //------------------------------cast_to_ptr_type------------------------------- 2666 const Type *TypeInstPtr::cast_to_ptr_type(PTR ptr) const { 2667 if( ptr == _ptr ) return this; 2668 // Reconstruct _sig info here since not a problem with later lazy 2669 // construction, _sig will show up on demand. 2670 return make(ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id); 2671 } 2672 2673 2674 //-----------------------------cast_to_exactness------------------------------- 2675 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const { 2676 if( klass_is_exact == _klass_is_exact ) return this; 2677 if (!UseExactTypes) return this; 2678 if (!_klass->is_loaded()) return this; 2679 ciInstanceKlass* ik = _klass->as_instance_klass(); 2680 if( (ik->is_final() || _const_oop) ) return this; // cannot clear xk 2681 if( ik->is_interface() ) return this; // cannot set xk 2682 return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id); 2683 } 2684 2685 //-----------------------------cast_to_instance_id---------------------------- 2686 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const { 2687 if( instance_id == _instance_id ) return this; 2688 return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id); 2689 } 2690 2691 //------------------------------xmeet_unloaded--------------------------------- 2692 // Compute the MEET of two InstPtrs when at least one is unloaded. 2693 // Assume classes are different since called after check for same name/class-loader 2694 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const { 2695 int off = meet_offset(tinst->offset()); 2696 PTR ptr = meet_ptr(tinst->ptr()); 2697 2698 const TypeInstPtr *loaded = is_loaded() ? this : tinst; 2699 const TypeInstPtr *unloaded = is_loaded() ? tinst : this; 2700 if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) { 2701 // 2702 // Meet unloaded class with java/lang/Object 2703 // 2704 // Meet 2705 // | Unloaded Class 2706 // Object | TOP | AnyNull | Constant | NotNull | BOTTOM | 2707 // =================================================================== 2708 // TOP | ..........................Unloaded......................| 2709 // AnyNull | U-AN |................Unloaded......................| 2710 // Constant | ... O-NN .................................. | O-BOT | 2711 // NotNull | ... O-NN .................................. | O-BOT | 2712 // BOTTOM | ........................Object-BOTTOM ..................| 2713 // 2714 assert(loaded->ptr() != TypePtr::Null, "insanity check"); 2715 // 2716 if( loaded->ptr() == TypePtr::TopPTR ) { return unloaded; } 2717 else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make( ptr, unloaded->klass() ); } 2718 else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; } 2719 else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) { 2720 if (unloaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; } 2721 else { return TypeInstPtr::NOTNULL; } 2722 } 2723 else if( unloaded->ptr() == TypePtr::TopPTR ) { return unloaded; } 2724 2725 return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr(); 2726 } 2727 2728 // Both are unloaded, not the same class, not Object 2729 // Or meet unloaded with a different loaded class, not java/lang/Object 2730 if( ptr != TypePtr::BotPTR ) { 2731 return TypeInstPtr::NOTNULL; 2732 } 2733 return TypeInstPtr::BOTTOM; 2734 } 2735 2736 2737 //------------------------------meet------------------------------------------- 2738 // Compute the MEET of two types. It returns a new Type object. 2739 const Type *TypeInstPtr::xmeet( const Type *t ) const { 2740 // Perform a fast test for common case; meeting the same types together. 2741 if( this == t ) return this; // Meeting same type-rep? 2742 2743 // Current "this->_base" is Pointer 2744 switch (t->base()) { // switch on original type 2745 2746 case Int: // Mixing ints & oops happens when javac 2747 case Long: // reuses local variables 2748 case FloatTop: 2749 case FloatCon: 2750 case FloatBot: 2751 case DoubleTop: 2752 case DoubleCon: 2753 case DoubleBot: 2754 case NarrowOop: 2755 case Bottom: // Ye Olde Default 2756 return Type::BOTTOM; 2757 case Top: 2758 return this; 2759 2760 default: // All else is a mistake 2761 typerr(t); 2762 2763 case RawPtr: return TypePtr::BOTTOM; 2764 2765 case AryPtr: { // All arrays inherit from Object class 2766 const TypeAryPtr *tp = t->is_aryptr(); 2767 int offset = meet_offset(tp->offset()); 2768 PTR ptr = meet_ptr(tp->ptr()); 2769 int instance_id = meet_instance_id(tp->instance_id()); 2770 switch (ptr) { 2771 case TopPTR: 2772 case AnyNull: // Fall 'down' to dual of object klass 2773 if (klass()->equals(ciEnv::current()->Object_klass())) { 2774 return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id); 2775 } else { 2776 // cannot subclass, so the meet has to fall badly below the centerline 2777 ptr = NotNull; 2778 instance_id = InstanceBot; 2779 return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id); 2780 } 2781 case Constant: 2782 case NotNull: 2783 case BotPTR: // Fall down to object klass 2784 // LCA is object_klass, but if we subclass from the top we can do better 2785 if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull ) 2786 // If 'this' (InstPtr) is above the centerline and it is Object class 2787 // then we can subclass in the Java class hierarchy. 2788 if (klass()->equals(ciEnv::current()->Object_klass())) { 2789 // that is, tp's array type is a subtype of my klass 2790 return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id); 2791 } 2792 } 2793 // The other case cannot happen, since I cannot be a subtype of an array. 2794 // The meet falls down to Object class below centerline. 2795 if( ptr == Constant ) 2796 ptr = NotNull; 2797 instance_id = InstanceBot; 2798 return make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id ); 2799 default: typerr(t); 2800 } 2801 } 2802 2803 case OopPtr: { // Meeting to OopPtrs 2804 // Found a OopPtr type vs self-InstPtr type 2805 const TypeOopPtr *tp = t->is_oopptr(); 2806 int offset = meet_offset(tp->offset()); 2807 PTR ptr = meet_ptr(tp->ptr()); 2808 switch (tp->ptr()) { 2809 case TopPTR: 2810 case AnyNull: { 2811 int instance_id = meet_instance_id(InstanceTop); 2812 return make(ptr, klass(), klass_is_exact(), 2813 (ptr == Constant ? const_oop() : NULL), offset, instance_id); 2814 } 2815 case NotNull: 2816 case BotPTR: { 2817 int instance_id = meet_instance_id(tp->instance_id()); 2818 return TypeOopPtr::make(ptr, offset, instance_id); 2819 } 2820 default: typerr(t); 2821 } 2822 } 2823 2824 case AnyPtr: { // Meeting to AnyPtrs 2825 // Found an AnyPtr type vs self-InstPtr type 2826 const TypePtr *tp = t->is_ptr(); 2827 int offset = meet_offset(tp->offset()); 2828 PTR ptr = meet_ptr(tp->ptr()); 2829 switch (tp->ptr()) { 2830 case Null: 2831 if( ptr == Null ) return TypePtr::make( AnyPtr, ptr, offset ); 2832 // else fall through to AnyNull 2833 case TopPTR: 2834 case AnyNull: { 2835 int instance_id = meet_instance_id(InstanceTop); 2836 return make( ptr, klass(), klass_is_exact(), 2837 (ptr == Constant ? const_oop() : NULL), offset, instance_id); 2838 } 2839 case NotNull: 2840 case BotPTR: 2841 return TypePtr::make( AnyPtr, ptr, offset ); 2842 default: typerr(t); 2843 } 2844 } 2845 2846 /* 2847 A-top } 2848 / | \ } Tops 2849 B-top A-any C-top } 2850 | / | \ | } Any-nulls 2851 B-any | C-any } 2852 | | | 2853 B-con A-con C-con } constants; not comparable across classes 2854 | | | 2855 B-not | C-not } 2856 | \ | / | } not-nulls 2857 B-bot A-not C-bot } 2858 \ | / } Bottoms 2859 A-bot } 2860 */ 2861 2862 case InstPtr: { // Meeting 2 Oops? 2863 // Found an InstPtr sub-type vs self-InstPtr type 2864 const TypeInstPtr *tinst = t->is_instptr(); 2865 int off = meet_offset( tinst->offset() ); 2866 PTR ptr = meet_ptr( tinst->ptr() ); 2867 int instance_id = meet_instance_id(tinst->instance_id()); 2868 2869 // Check for easy case; klasses are equal (and perhaps not loaded!) 2870 // If we have constants, then we created oops so classes are loaded 2871 // and we can handle the constants further down. This case handles 2872 // both-not-loaded or both-loaded classes 2873 if (ptr != Constant && klass()->equals(tinst->klass()) && klass_is_exact() == tinst->klass_is_exact()) { 2874 return make( ptr, klass(), klass_is_exact(), NULL, off, instance_id ); 2875 } 2876 2877 // Classes require inspection in the Java klass hierarchy. Must be loaded. 2878 ciKlass* tinst_klass = tinst->klass(); 2879 ciKlass* this_klass = this->klass(); 2880 bool tinst_xk = tinst->klass_is_exact(); 2881 bool this_xk = this->klass_is_exact(); 2882 if (!tinst_klass->is_loaded() || !this_klass->is_loaded() ) { 2883 // One of these classes has not been loaded 2884 const TypeInstPtr *unloaded_meet = xmeet_unloaded(tinst); 2885 #ifndef PRODUCT 2886 if( PrintOpto && Verbose ) { 2887 tty->print("meet of unloaded classes resulted in: "); unloaded_meet->dump(); tty->cr(); 2888 tty->print(" this == "); this->dump(); tty->cr(); 2889 tty->print(" tinst == "); tinst->dump(); tty->cr(); 2890 } 2891 #endif 2892 return unloaded_meet; 2893 } 2894 2895 // Handle mixing oops and interfaces first. 2896 if( this_klass->is_interface() && !tinst_klass->is_interface() ) { 2897 ciKlass *tmp = tinst_klass; // Swap interface around 2898 tinst_klass = this_klass; 2899 this_klass = tmp; 2900 bool tmp2 = tinst_xk; 2901 tinst_xk = this_xk; 2902 this_xk = tmp2; 2903 } 2904 if (tinst_klass->is_interface() && 2905 !(this_klass->is_interface() || 2906 // Treat java/lang/Object as an honorary interface, 2907 // because we need a bottom for the interface hierarchy. 2908 this_klass == ciEnv::current()->Object_klass())) { 2909 // Oop meets interface! 2910 2911 // See if the oop subtypes (implements) interface. 2912 ciKlass *k; 2913 bool xk; 2914 if( this_klass->is_subtype_of( tinst_klass ) ) { 2915 // Oop indeed subtypes. Now keep oop or interface depending 2916 // on whether we are both above the centerline or either is 2917 // below the centerline. If we are on the centerline 2918 // (e.g., Constant vs. AnyNull interface), use the constant. 2919 k = below_centerline(ptr) ? tinst_klass : this_klass; 2920 // If we are keeping this_klass, keep its exactness too. 2921 xk = below_centerline(ptr) ? tinst_xk : this_xk; 2922 } else { // Does not implement, fall to Object 2923 // Oop does not implement interface, so mixing falls to Object 2924 // just like the verifier does (if both are above the 2925 // centerline fall to interface) 2926 k = above_centerline(ptr) ? tinst_klass : ciEnv::current()->Object_klass(); 2927 xk = above_centerline(ptr) ? tinst_xk : false; 2928 // Watch out for Constant vs. AnyNull interface. 2929 if (ptr == Constant) ptr = NotNull; // forget it was a constant 2930 instance_id = InstanceBot; 2931 } 2932 ciObject* o = NULL; // the Constant value, if any 2933 if (ptr == Constant) { 2934 // Find out which constant. 2935 o = (this_klass == klass()) ? const_oop() : tinst->const_oop(); 2936 } 2937 return make( ptr, k, xk, o, off, instance_id ); 2938 } 2939 2940 // Either oop vs oop or interface vs interface or interface vs Object 2941 2942 // !!! Here's how the symmetry requirement breaks down into invariants: 2943 // If we split one up & one down AND they subtype, take the down man. 2944 // If we split one up & one down AND they do NOT subtype, "fall hard". 2945 // If both are up and they subtype, take the subtype class. 2946 // If both are up and they do NOT subtype, "fall hard". 2947 // If both are down and they subtype, take the supertype class. 2948 // If both are down and they do NOT subtype, "fall hard". 2949 // Constants treated as down. 2950 2951 // Now, reorder the above list; observe that both-down+subtype is also 2952 // "fall hard"; "fall hard" becomes the default case: 2953 // If we split one up & one down AND they subtype, take the down man. 2954 // If both are up and they subtype, take the subtype class. 2955 2956 // If both are down and they subtype, "fall hard". 2957 // If both are down and they do NOT subtype, "fall hard". 2958 // If both are up and they do NOT subtype, "fall hard". 2959 // If we split one up & one down AND they do NOT subtype, "fall hard". 2960 2961 // If a proper subtype is exact, and we return it, we return it exactly. 2962 // If a proper supertype is exact, there can be no subtyping relationship! 2963 // If both types are equal to the subtype, exactness is and-ed below the 2964 // centerline and or-ed above it. (N.B. Constants are always exact.) 2965 2966 // Check for subtyping: 2967 ciKlass *subtype = NULL; 2968 bool subtype_exact = false; 2969 if( tinst_klass->equals(this_klass) ) { 2970 subtype = this_klass; 2971 subtype_exact = below_centerline(ptr) ? (this_xk & tinst_xk) : (this_xk | tinst_xk); 2972 } else if( !tinst_xk && this_klass->is_subtype_of( tinst_klass ) ) { 2973 subtype = this_klass; // Pick subtyping class 2974 subtype_exact = this_xk; 2975 } else if( !this_xk && tinst_klass->is_subtype_of( this_klass ) ) { 2976 subtype = tinst_klass; // Pick subtyping class 2977 subtype_exact = tinst_xk; 2978 } 2979 2980 if( subtype ) { 2981 if( above_centerline(ptr) ) { // both are up? 2982 this_klass = tinst_klass = subtype; 2983 this_xk = tinst_xk = subtype_exact; 2984 } else if( above_centerline(this ->_ptr) && !above_centerline(tinst->_ptr) ) { 2985 this_klass = tinst_klass; // tinst is down; keep down man 2986 this_xk = tinst_xk; 2987 } else if( above_centerline(tinst->_ptr) && !above_centerline(this ->_ptr) ) { 2988 tinst_klass = this_klass; // this is down; keep down man 2989 tinst_xk = this_xk; 2990 } else { 2991 this_xk = subtype_exact; // either they are equal, or we'll do an LCA 2992 } 2993 } 2994 2995 // Check for classes now being equal 2996 if (tinst_klass->equals(this_klass)) { 2997 // If the klasses are equal, the constants may still differ. Fall to 2998 // NotNull if they do (neither constant is NULL; that is a special case 2999 // handled elsewhere). 3000 ciObject* o = NULL; // Assume not constant when done 3001 ciObject* this_oop = const_oop(); 3002 ciObject* tinst_oop = tinst->const_oop(); 3003 if( ptr == Constant ) { 3004 if (this_oop != NULL && tinst_oop != NULL && 3005 this_oop->equals(tinst_oop) ) 3006 o = this_oop; 3007 else if (above_centerline(this ->_ptr)) 3008 o = tinst_oop; 3009 else if (above_centerline(tinst ->_ptr)) 3010 o = this_oop; 3011 else 3012 ptr = NotNull; 3013 } 3014 return make( ptr, this_klass, this_xk, o, off, instance_id ); 3015 } // Else classes are not equal 3016 3017 // Since klasses are different, we require a LCA in the Java 3018 // class hierarchy - which means we have to fall to at least NotNull. 3019 if( ptr == TopPTR || ptr == AnyNull || ptr == Constant ) 3020 ptr = NotNull; 3021 instance_id = InstanceBot; 3022 3023 // Now we find the LCA of Java classes 3024 ciKlass* k = this_klass->least_common_ancestor(tinst_klass); 3025 return make( ptr, k, false, NULL, off, instance_id ); 3026 } // End of case InstPtr 3027 3028 case KlassPtr: 3029 return TypeInstPtr::BOTTOM; 3030 3031 } // End of switch 3032 return this; // Return the double constant 3033 } 3034 3035 3036 //------------------------java_mirror_type-------------------------------------- 3037 ciType* TypeInstPtr::java_mirror_type() const { 3038 // must be a singleton type 3039 if( const_oop() == NULL ) return NULL; 3040 3041 // must be of type java.lang.Class 3042 if( klass() != ciEnv::current()->Class_klass() ) return NULL; 3043 3044 return const_oop()->as_instance()->java_mirror_type(); 3045 } 3046 3047 3048 //------------------------------xdual------------------------------------------ 3049 // Dual: do NOT dual on klasses. This means I do NOT understand the Java 3050 // inheritance mechanism. 3051 const Type *TypeInstPtr::xdual() const { 3052 return new TypeInstPtr( dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id() ); 3053 } 3054 3055 //------------------------------eq--------------------------------------------- 3056 // Structural equality check for Type representations 3057 bool TypeInstPtr::eq( const Type *t ) const { 3058 const TypeInstPtr *p = t->is_instptr(); 3059 return 3060 klass()->equals(p->klass()) && 3061 TypeOopPtr::eq(p); // Check sub-type stuff 3062 } 3063 3064 //------------------------------hash------------------------------------------- 3065 // Type-specific hashing function. 3066 int TypeInstPtr::hash(void) const { 3067 int hash = klass()->hash() + TypeOopPtr::hash(); 3068 return hash; 3069 } 3070 3071 //------------------------------dump2------------------------------------------ 3072 // Dump oop Type 3073 #ifndef PRODUCT 3074 void TypeInstPtr::dump2( Dict &d, uint depth, outputStream *st ) const { 3075 // Print the name of the klass. 3076 klass()->print_name_on(st); 3077 3078 switch( _ptr ) { 3079 case Constant: 3080 // TO DO: Make CI print the hex address of the underlying oop. 3081 if (WizardMode || Verbose) { 3082 const_oop()->print_oop(st); 3083 } 3084 case BotPTR: 3085 if (!WizardMode && !Verbose) { 3086 if( _klass_is_exact ) st->print(":exact"); 3087 break; 3088 } 3089 case TopPTR: 3090 case AnyNull: 3091 case NotNull: 3092 st->print(":%s", ptr_msg[_ptr]); 3093 if( _klass_is_exact ) st->print(":exact"); 3094 break; 3095 } 3096 3097 if( _offset ) { // Dump offset, if any 3098 if( _offset == OffsetBot ) st->print("+any"); 3099 else if( _offset == OffsetTop ) st->print("+unknown"); 3100 else st->print("+%d", _offset); 3101 } 3102 3103 st->print(" *"); 3104 if (_instance_id == InstanceTop) 3105 st->print(",iid=top"); 3106 else if (_instance_id != InstanceBot) 3107 st->print(",iid=%d",_instance_id); 3108 } 3109 #endif 3110 3111 //------------------------------add_offset------------------------------------- 3112 const TypePtr *TypeInstPtr::add_offset( intptr_t offset ) const { 3113 return make( _ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset), _instance_id ); 3114 } 3115 3116 //============================================================================= 3117 // Convenience common pre-built types. 3118 const TypeAryPtr *TypeAryPtr::RANGE; 3119 const TypeAryPtr *TypeAryPtr::OOPS; 3120 const TypeAryPtr *TypeAryPtr::NARROWOOPS; 3121 const TypeAryPtr *TypeAryPtr::BYTES; 3122 const TypeAryPtr *TypeAryPtr::SHORTS; 3123 const TypeAryPtr *TypeAryPtr::CHARS; 3124 const TypeAryPtr *TypeAryPtr::INTS; 3125 const TypeAryPtr *TypeAryPtr::LONGS; 3126 const TypeAryPtr *TypeAryPtr::FLOATS; 3127 const TypeAryPtr *TypeAryPtr::DOUBLES; 3128 3129 //------------------------------make------------------------------------------- 3130 const TypeAryPtr *TypeAryPtr::make( PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id ) { 3131 assert(!(k == NULL && ary->_elem->isa_int()), 3132 "integral arrays must be pre-equipped with a class"); 3133 if (!xk) xk = ary->ary_must_be_exact(); 3134 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed"); 3135 if (!UseExactTypes) xk = (ptr == Constant); 3136 return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id))->hashcons(); 3137 } 3138 3139 //------------------------------make------------------------------------------- 3140 const TypeAryPtr *TypeAryPtr::make( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id ) { 3141 assert(!(k == NULL && ary->_elem->isa_int()), 3142 "integral arrays must be pre-equipped with a class"); 3143 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" ); 3144 if (!xk) xk = (o != NULL) || ary->ary_must_be_exact(); 3145 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed"); 3146 if (!UseExactTypes) xk = (ptr == Constant); 3147 return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id))->hashcons(); 3148 } 3149 3150 //------------------------------cast_to_ptr_type------------------------------- 3151 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const { 3152 if( ptr == _ptr ) return this; 3153 return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _instance_id); 3154 } 3155 3156 3157 //-----------------------------cast_to_exactness------------------------------- 3158 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const { 3159 if( klass_is_exact == _klass_is_exact ) return this; 3160 if (!UseExactTypes) return this; 3161 if (_ary->ary_must_be_exact()) return this; // cannot clear xk 3162 return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id); 3163 } 3164 3165 //-----------------------------cast_to_instance_id---------------------------- 3166 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const { 3167 if( instance_id == _instance_id ) return this; 3168 return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id); 3169 } 3170 3171 //-----------------------------narrow_size_type------------------------------- 3172 // Local cache for arrayOopDesc::max_array_length(etype), 3173 // which is kind of slow (and cached elsewhere by other users). 3174 static jint max_array_length_cache[T_CONFLICT+1]; 3175 static jint max_array_length(BasicType etype) { 3176 jint& cache = max_array_length_cache[etype]; 3177 jint res = cache; 3178 if (res == 0) { 3179 switch (etype) { 3180 case T_NARROWOOP: 3181 etype = T_OBJECT; 3182 break; 3183 case T_CONFLICT: 3184 case T_ILLEGAL: 3185 case T_VOID: 3186 etype = T_BYTE; // will produce conservatively high value 3187 } 3188 cache = res = arrayOopDesc::max_array_length(etype); 3189 } 3190 return res; 3191 } 3192 3193 // Narrow the given size type to the index range for the given array base type. 3194 // Return NULL if the resulting int type becomes empty. 3195 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const { 3196 jint hi = size->_hi; 3197 jint lo = size->_lo; 3198 jint min_lo = 0; 3199 jint max_hi = max_array_length(elem()->basic_type()); 3200 //if (index_not_size) --max_hi; // type of a valid array index, FTR 3201 bool chg = false; 3202 if (lo < min_lo) { lo = min_lo; chg = true; } 3203 if (hi > max_hi) { hi = max_hi; chg = true; } 3204 // Negative length arrays will produce weird intermediate dead fast-path code 3205 if (lo > hi) 3206 return TypeInt::ZERO; 3207 if (!chg) 3208 return size; 3209 return TypeInt::make(lo, hi, Type::WidenMin); 3210 } 3211 3212 //-------------------------------cast_to_size---------------------------------- 3213 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const { 3214 assert(new_size != NULL, ""); 3215 new_size = narrow_size_type(new_size); 3216 if (new_size == size()) return this; 3217 const TypeAry* new_ary = TypeAry::make(elem(), new_size); 3218 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id); 3219 } 3220 3221 3222 //------------------------------eq--------------------------------------------- 3223 // Structural equality check for Type representations 3224 bool TypeAryPtr::eq( const Type *t ) const { 3225 const TypeAryPtr *p = t->is_aryptr(); 3226 return 3227 _ary == p->_ary && // Check array 3228 TypeOopPtr::eq(p); // Check sub-parts 3229 } 3230 3231 //------------------------------hash------------------------------------------- 3232 // Type-specific hashing function. 3233 int TypeAryPtr::hash(void) const { 3234 return (intptr_t)_ary + TypeOopPtr::hash(); 3235 } 3236 3237 //------------------------------meet------------------------------------------- 3238 // Compute the MEET of two types. It returns a new Type object. 3239 const Type *TypeAryPtr::xmeet( const Type *t ) const { 3240 // Perform a fast test for common case; meeting the same types together. 3241 if( this == t ) return this; // Meeting same type-rep? 3242 // Current "this->_base" is Pointer 3243 switch (t->base()) { // switch on original type 3244 3245 // Mixing ints & oops happens when javac reuses local variables 3246 case Int: 3247 case Long: 3248 case FloatTop: 3249 case FloatCon: 3250 case FloatBot: 3251 case DoubleTop: 3252 case DoubleCon: 3253 case DoubleBot: 3254 case NarrowOop: 3255 case Bottom: // Ye Olde Default 3256 return Type::BOTTOM; 3257 case Top: 3258 return this; 3259 3260 default: // All else is a mistake 3261 typerr(t); 3262 3263 case OopPtr: { // Meeting to OopPtrs 3264 // Found a OopPtr type vs self-AryPtr type 3265 const TypeOopPtr *tp = t->is_oopptr(); 3266 int offset = meet_offset(tp->offset()); 3267 PTR ptr = meet_ptr(tp->ptr()); 3268 switch (tp->ptr()) { 3269 case TopPTR: 3270 case AnyNull: { 3271 int instance_id = meet_instance_id(InstanceTop); 3272 return make(ptr, (ptr == Constant ? const_oop() : NULL), 3273 _ary, _klass, _klass_is_exact, offset, instance_id); 3274 } 3275 case BotPTR: 3276 case NotNull: { 3277 int instance_id = meet_instance_id(tp->instance_id()); 3278 return TypeOopPtr::make(ptr, offset, instance_id); 3279 } 3280 default: ShouldNotReachHere(); 3281 } 3282 } 3283 3284 case AnyPtr: { // Meeting two AnyPtrs 3285 // Found an AnyPtr type vs self-AryPtr type 3286 const TypePtr *tp = t->is_ptr(); 3287 int offset = meet_offset(tp->offset()); 3288 PTR ptr = meet_ptr(tp->ptr()); 3289 switch (tp->ptr()) { 3290 case TopPTR: 3291 return this; 3292 case BotPTR: 3293 case NotNull: 3294 return TypePtr::make(AnyPtr, ptr, offset); 3295 case Null: 3296 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset); 3297 // else fall through to AnyNull 3298 case AnyNull: { 3299 int instance_id = meet_instance_id(InstanceTop); 3300 return make( ptr, (ptr == Constant ? const_oop() : NULL), 3301 _ary, _klass, _klass_is_exact, offset, instance_id); 3302 } 3303 default: ShouldNotReachHere(); 3304 } 3305 } 3306 3307 case RawPtr: return TypePtr::BOTTOM; 3308 3309 case AryPtr: { // Meeting 2 references? 3310 const TypeAryPtr *tap = t->is_aryptr(); 3311 int off = meet_offset(tap->offset()); 3312 const TypeAry *tary = _ary->meet(tap->_ary)->is_ary(); 3313 PTR ptr = meet_ptr(tap->ptr()); 3314 int instance_id = meet_instance_id(tap->instance_id()); 3315 ciKlass* lazy_klass = NULL; 3316 if (tary->_elem->isa_int()) { 3317 // Integral array element types have irrelevant lattice relations. 3318 // It is the klass that determines array layout, not the element type. 3319 if (_klass == NULL) 3320 lazy_klass = tap->_klass; 3321 else if (tap->_klass == NULL || tap->_klass == _klass) { 3322 lazy_klass = _klass; 3323 } else { 3324 // Something like byte[int+] meets char[int+]. 3325 // This must fall to bottom, not (int[-128..65535])[int+]. 3326 instance_id = InstanceBot; 3327 tary = TypeAry::make(Type::BOTTOM, tary->_size); 3328 } 3329 } 3330 bool xk; 3331 switch (tap->ptr()) { 3332 case AnyNull: 3333 case TopPTR: 3334 // Compute new klass on demand, do not use tap->_klass 3335 xk = (tap->_klass_is_exact | this->_klass_is_exact); 3336 return make( ptr, const_oop(), tary, lazy_klass, xk, off, instance_id ); 3337 case Constant: { 3338 ciObject* o = const_oop(); 3339 if( _ptr == Constant ) { 3340 if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) { 3341 ptr = NotNull; 3342 o = NULL; 3343 instance_id = InstanceBot; 3344 } 3345 } else if( above_centerline(_ptr) ) { 3346 o = tap->const_oop(); 3347 } 3348 xk = true; 3349 return TypeAryPtr::make( ptr, o, tary, tap->_klass, xk, off, instance_id ); 3350 } 3351 case NotNull: 3352 case BotPTR: 3353 // Compute new klass on demand, do not use tap->_klass 3354 if (above_centerline(this->_ptr)) 3355 xk = tap->_klass_is_exact; 3356 else if (above_centerline(tap->_ptr)) 3357 xk = this->_klass_is_exact; 3358 else xk = (tap->_klass_is_exact & this->_klass_is_exact) && 3359 (klass() == tap->klass()); // Only precise for identical arrays 3360 return TypeAryPtr::make( ptr, NULL, tary, lazy_klass, xk, off, instance_id ); 3361 default: ShouldNotReachHere(); 3362 } 3363 } 3364 3365 // All arrays inherit from Object class 3366 case InstPtr: { 3367 const TypeInstPtr *tp = t->is_instptr(); 3368 int offset = meet_offset(tp->offset()); 3369 PTR ptr = meet_ptr(tp->ptr()); 3370 int instance_id = meet_instance_id(tp->instance_id()); 3371 switch (ptr) { 3372 case TopPTR: 3373 case AnyNull: // Fall 'down' to dual of object klass 3374 if( tp->klass()->equals(ciEnv::current()->Object_klass()) ) { 3375 return TypeAryPtr::make( ptr, _ary, _klass, _klass_is_exact, offset, instance_id ); 3376 } else { 3377 // cannot subclass, so the meet has to fall badly below the centerline 3378 ptr = NotNull; 3379 instance_id = InstanceBot; 3380 return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id); 3381 } 3382 case Constant: 3383 case NotNull: 3384 case BotPTR: // Fall down to object klass 3385 // LCA is object_klass, but if we subclass from the top we can do better 3386 if (above_centerline(tp->ptr())) { 3387 // If 'tp' is above the centerline and it is Object class 3388 // then we can subclass in the Java class hierarchy. 3389 if( tp->klass()->equals(ciEnv::current()->Object_klass()) ) { 3390 // that is, my array type is a subtype of 'tp' klass 3391 return make( ptr, _ary, _klass, _klass_is_exact, offset, instance_id ); 3392 } 3393 } 3394 // The other case cannot happen, since t cannot be a subtype of an array. 3395 // The meet falls down to Object class below centerline. 3396 if( ptr == Constant ) 3397 ptr = NotNull; 3398 instance_id = InstanceBot; 3399 return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id); 3400 default: typerr(t); 3401 } 3402 } 3403 3404 case KlassPtr: 3405 return TypeInstPtr::BOTTOM; 3406 3407 } 3408 return this; // Lint noise 3409 } 3410 3411 //------------------------------xdual------------------------------------------ 3412 // Dual: compute field-by-field dual 3413 const Type *TypeAryPtr::xdual() const { 3414 return new TypeAryPtr( dual_ptr(), _const_oop, _ary->dual()->is_ary(),_klass, _klass_is_exact, dual_offset(), dual_instance_id() ); 3415 } 3416 3417 //----------------------interface_vs_oop--------------------------------------- 3418 #ifdef ASSERT 3419 bool TypeAryPtr::interface_vs_oop(const Type *t) const { 3420 const TypeAryPtr* t_aryptr = t->isa_aryptr(); 3421 if (t_aryptr) { 3422 return _ary->interface_vs_oop(t_aryptr->_ary); 3423 } 3424 return false; 3425 } 3426 #endif 3427 3428 //------------------------------dump2------------------------------------------ 3429 #ifndef PRODUCT 3430 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const { 3431 _ary->dump2(d,depth,st); 3432 switch( _ptr ) { 3433 case Constant: 3434 const_oop()->print(st); 3435 break; 3436 case BotPTR: 3437 if (!WizardMode && !Verbose) { 3438 if( _klass_is_exact ) st->print(":exact"); 3439 break; 3440 } 3441 case TopPTR: 3442 case AnyNull: 3443 case NotNull: 3444 st->print(":%s", ptr_msg[_ptr]); 3445 if( _klass_is_exact ) st->print(":exact"); 3446 break; 3447 } 3448 3449 if( _offset != 0 ) { 3450 int header_size = objArrayOopDesc::header_size() * wordSize; 3451 if( _offset == OffsetTop ) st->print("+undefined"); 3452 else if( _offset == OffsetBot ) st->print("+any"); 3453 else if( _offset < header_size ) st->print("+%d", _offset); 3454 else { 3455 BasicType basic_elem_type = elem()->basic_type(); 3456 int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type); 3457 int elem_size = type2aelembytes(basic_elem_type); 3458 st->print("[%d]", (_offset - array_base)/elem_size); 3459 } 3460 } 3461 st->print(" *"); 3462 if (_instance_id == InstanceTop) 3463 st->print(",iid=top"); 3464 else if (_instance_id != InstanceBot) 3465 st->print(",iid=%d",_instance_id); 3466 } 3467 #endif 3468 3469 bool TypeAryPtr::empty(void) const { 3470 if (_ary->empty()) return true; 3471 return TypeOopPtr::empty(); 3472 } 3473 3474 //------------------------------add_offset------------------------------------- 3475 const TypePtr *TypeAryPtr::add_offset( intptr_t offset ) const { 3476 return make( _ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id ); 3477 } 3478 3479 3480 //============================================================================= 3481 const TypeNarrowOop *TypeNarrowOop::BOTTOM; 3482 const TypeNarrowOop *TypeNarrowOop::NULL_PTR; 3483 3484 3485 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) { 3486 return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons(); 3487 } 3488 3489 //------------------------------hash------------------------------------------- 3490 // Type-specific hashing function. 3491 int TypeNarrowOop::hash(void) const { 3492 return _ptrtype->hash() + 7; 3493 } 3494 3495 3496 bool TypeNarrowOop::eq( const Type *t ) const { 3497 const TypeNarrowOop* tc = t->isa_narrowoop(); 3498 if (tc != NULL) { 3499 if (_ptrtype->base() != tc->_ptrtype->base()) { 3500 return false; 3501 } 3502 return tc->_ptrtype->eq(_ptrtype); 3503 } 3504 return false; 3505 } 3506 3507 bool TypeNarrowOop::singleton(void) const { // TRUE if type is a singleton 3508 return _ptrtype->singleton(); 3509 } 3510 3511 bool TypeNarrowOop::empty(void) const { 3512 return _ptrtype->empty(); 3513 } 3514 3515 //------------------------------xmeet------------------------------------------ 3516 // Compute the MEET of two types. It returns a new Type object. 3517 const Type *TypeNarrowOop::xmeet( const Type *t ) const { 3518 // Perform a fast test for common case; meeting the same types together. 3519 if( this == t ) return this; // Meeting same type-rep? 3520 3521 3522 // Current "this->_base" is OopPtr 3523 switch (t->base()) { // switch on original type 3524 3525 case Int: // Mixing ints & oops happens when javac 3526 case Long: // reuses local variables 3527 case FloatTop: 3528 case FloatCon: 3529 case FloatBot: 3530 case DoubleTop: 3531 case DoubleCon: 3532 case DoubleBot: 3533 case AnyPtr: 3534 case RawPtr: 3535 case OopPtr: 3536 case InstPtr: 3537 case KlassPtr: 3538 case AryPtr: 3539 3540 case Bottom: // Ye Olde Default 3541 return Type::BOTTOM; 3542 case Top: 3543 return this; 3544 3545 case NarrowOop: { 3546 const Type* result = _ptrtype->xmeet(t->make_ptr()); 3547 if (result->isa_ptr()) { 3548 return TypeNarrowOop::make(result->is_ptr()); 3549 } 3550 return result; 3551 } 3552 3553 default: // All else is a mistake 3554 typerr(t); 3555 3556 } // End of switch 3557 3558 return this; 3559 } 3560 3561 const Type *TypeNarrowOop::xdual() const { // Compute dual right now. 3562 const TypePtr* odual = _ptrtype->dual()->is_ptr(); 3563 return new TypeNarrowOop(odual); 3564 } 3565 3566 const Type *TypeNarrowOop::filter( const Type *kills ) const { 3567 if (kills->isa_narrowoop()) { 3568 const Type* ft =_ptrtype->filter(kills->is_narrowoop()->_ptrtype); 3569 if (ft->empty()) 3570 return Type::TOP; // Canonical empty value 3571 if (ft->isa_ptr()) { 3572 return make(ft->isa_ptr()); 3573 } 3574 return ft; 3575 } else if (kills->isa_ptr()) { 3576 const Type* ft = _ptrtype->join(kills); 3577 if (ft->empty()) 3578 return Type::TOP; // Canonical empty value 3579 return ft; 3580 } else { 3581 return Type::TOP; 3582 } 3583 } 3584 3585 3586 intptr_t TypeNarrowOop::get_con() const { 3587 return _ptrtype->get_con(); 3588 } 3589 3590 #ifndef PRODUCT 3591 void TypeNarrowOop::dump2( Dict & d, uint depth, outputStream *st ) const { 3592 st->print("narrowoop: "); 3593 _ptrtype->dump2(d, depth, st); 3594 } 3595 #endif 3596 3597 3598 //============================================================================= 3599 // Convenience common pre-built types. 3600 3601 // Not-null object klass or below 3602 const TypeKlassPtr *TypeKlassPtr::OBJECT; 3603 const TypeKlassPtr *TypeKlassPtr::OBJECT_OR_NULL; 3604 3605 //------------------------------TypeKlasPtr------------------------------------ 3606 TypeKlassPtr::TypeKlassPtr( PTR ptr, ciKlass* klass, int offset ) 3607 : TypeOopPtr(KlassPtr, ptr, klass, (ptr==Constant), (ptr==Constant ? klass : NULL), offset, 0) { 3608 } 3609 3610 //------------------------------make------------------------------------------- 3611 // ptr to klass 'k', if Constant, or possibly to a sub-klass if not a Constant 3612 const TypeKlassPtr *TypeKlassPtr::make( PTR ptr, ciKlass* k, int offset ) { 3613 assert( k != NULL, "Expect a non-NULL klass"); 3614 assert(k->is_instance_klass() || k->is_array_klass() || 3615 k->is_method_klass(), "Incorrect type of klass oop"); 3616 TypeKlassPtr *r = 3617 (TypeKlassPtr*)(new TypeKlassPtr(ptr, k, offset))->hashcons(); 3618 3619 return r; 3620 } 3621 3622 //------------------------------eq--------------------------------------------- 3623 // Structural equality check for Type representations 3624 bool TypeKlassPtr::eq( const Type *t ) const { 3625 const TypeKlassPtr *p = t->is_klassptr(); 3626 return 3627 klass()->equals(p->klass()) && 3628 TypeOopPtr::eq(p); 3629 } 3630 3631 //------------------------------hash------------------------------------------- 3632 // Type-specific hashing function. 3633 int TypeKlassPtr::hash(void) const { 3634 return klass()->hash() + TypeOopPtr::hash(); 3635 } 3636 3637 3638 //------------------------------klass------------------------------------------ 3639 // Return the defining klass for this class 3640 ciKlass* TypeAryPtr::klass() const { 3641 if( _klass ) return _klass; // Return cached value, if possible 3642 3643 // Oops, need to compute _klass and cache it 3644 ciKlass* k_ary = NULL; 3645 const TypeInstPtr *tinst; 3646 const TypeAryPtr *tary; 3647 const Type* el = elem(); 3648 if (el->isa_narrowoop()) { 3649 el = el->make_ptr(); 3650 } 3651 3652 // Get element klass 3653 if ((tinst = el->isa_instptr()) != NULL) { 3654 // Compute array klass from element klass 3655 k_ary = ciObjArrayKlass::make(tinst->klass()); 3656 } else if ((tary = el->isa_aryptr()) != NULL) { 3657 // Compute array klass from element klass 3658 ciKlass* k_elem = tary->klass(); 3659 // If element type is something like bottom[], k_elem will be null. 3660 if (k_elem != NULL) 3661 k_ary = ciObjArrayKlass::make(k_elem); 3662 } else if ((el->base() == Type::Top) || 3663 (el->base() == Type::Bottom)) { 3664 // element type of Bottom occurs from meet of basic type 3665 // and object; Top occurs when doing join on Bottom. 3666 // Leave k_ary at NULL. 3667 } else { 3668 // Cannot compute array klass directly from basic type, 3669 // since subtypes of TypeInt all have basic type T_INT. 3670 assert(!el->isa_int(), 3671 "integral arrays must be pre-equipped with a class"); 3672 // Compute array klass directly from basic type 3673 k_ary = ciTypeArrayKlass::make(el->basic_type()); 3674 } 3675 3676 if( this != TypeAryPtr::OOPS ) { 3677 // The _klass field acts as a cache of the underlying 3678 // ciKlass for this array type. In order to set the field, 3679 // we need to cast away const-ness. 3680 // 3681 // IMPORTANT NOTE: we *never* set the _klass field for the 3682 // type TypeAryPtr::OOPS. This Type is shared between all 3683 // active compilations. However, the ciKlass which represents 3684 // this Type is *not* shared between compilations, so caching 3685 // this value would result in fetching a dangling pointer. 3686 // 3687 // Recomputing the underlying ciKlass for each request is 3688 // a bit less efficient than caching, but calls to 3689 // TypeAryPtr::OOPS->klass() are not common enough to matter. 3690 ((TypeAryPtr*)this)->_klass = k_ary; 3691 if (UseCompressedOops && k_ary != NULL && k_ary->is_obj_array_klass() && 3692 _offset != 0 && _offset != arrayOopDesc::length_offset_in_bytes()) { 3693 ((TypeAryPtr*)this)->_is_ptr_to_narrowoop = true; 3694 } 3695 } 3696 return k_ary; 3697 } 3698 3699 3700 //------------------------------add_offset------------------------------------- 3701 // Access internals of klass object 3702 const TypePtr *TypeKlassPtr::add_offset( intptr_t offset ) const { 3703 return make( _ptr, klass(), xadd_offset(offset) ); 3704 } 3705 3706 //------------------------------cast_to_ptr_type------------------------------- 3707 const Type *TypeKlassPtr::cast_to_ptr_type(PTR ptr) const { 3708 assert(_base == KlassPtr, "subclass must override cast_to_ptr_type"); 3709 if( ptr == _ptr ) return this; 3710 return make(ptr, _klass, _offset); 3711 } 3712 3713 3714 //-----------------------------cast_to_exactness------------------------------- 3715 const Type *TypeKlassPtr::cast_to_exactness(bool klass_is_exact) const { 3716 if( klass_is_exact == _klass_is_exact ) return this; 3717 if (!UseExactTypes) return this; 3718 return make(klass_is_exact ? Constant : NotNull, _klass, _offset); 3719 } 3720 3721 3722 //-----------------------------as_instance_type-------------------------------- 3723 // Corresponding type for an instance of the given class. 3724 // It will be NotNull, and exact if and only if the klass type is exact. 3725 const TypeOopPtr* TypeKlassPtr::as_instance_type() const { 3726 ciKlass* k = klass(); 3727 bool xk = klass_is_exact(); 3728 //return TypeInstPtr::make(TypePtr::NotNull, k, xk, NULL, 0); 3729 const TypeOopPtr* toop = TypeOopPtr::make_from_klass_raw(k); 3730 toop = toop->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr(); 3731 return toop->cast_to_exactness(xk)->is_oopptr(); 3732 } 3733 3734 3735 //------------------------------xmeet------------------------------------------ 3736 // Compute the MEET of two types, return a new Type object. 3737 const Type *TypeKlassPtr::xmeet( const Type *t ) const { 3738 // Perform a fast test for common case; meeting the same types together. 3739 if( this == t ) return this; // Meeting same type-rep? 3740 3741 // Current "this->_base" is Pointer 3742 switch (t->base()) { // switch on original type 3743 3744 case Int: // Mixing ints & oops happens when javac 3745 case Long: // reuses local variables 3746 case FloatTop: 3747 case FloatCon: 3748 case FloatBot: 3749 case DoubleTop: 3750 case DoubleCon: 3751 case DoubleBot: 3752 case NarrowOop: 3753 case Bottom: // Ye Olde Default 3754 return Type::BOTTOM; 3755 case Top: 3756 return this; 3757 3758 default: // All else is a mistake 3759 typerr(t); 3760 3761 case RawPtr: return TypePtr::BOTTOM; 3762 3763 case OopPtr: { // Meeting to OopPtrs 3764 // Found a OopPtr type vs self-KlassPtr type 3765 const TypePtr *tp = t->is_oopptr(); 3766 int offset = meet_offset(tp->offset()); 3767 PTR ptr = meet_ptr(tp->ptr()); 3768 switch (tp->ptr()) { 3769 case TopPTR: 3770 case AnyNull: 3771 return make(ptr, klass(), offset); 3772 case BotPTR: 3773 case NotNull: 3774 return TypePtr::make(AnyPtr, ptr, offset); 3775 default: typerr(t); 3776 } 3777 } 3778 3779 case AnyPtr: { // Meeting to AnyPtrs 3780 // Found an AnyPtr type vs self-KlassPtr type 3781 const TypePtr *tp = t->is_ptr(); 3782 int offset = meet_offset(tp->offset()); 3783 PTR ptr = meet_ptr(tp->ptr()); 3784 switch (tp->ptr()) { 3785 case TopPTR: 3786 return this; 3787 case Null: 3788 if( ptr == Null ) return TypePtr::make( AnyPtr, ptr, offset ); 3789 case AnyNull: 3790 return make( ptr, klass(), offset ); 3791 case BotPTR: 3792 case NotNull: 3793 return TypePtr::make(AnyPtr, ptr, offset); 3794 default: typerr(t); 3795 } 3796 } 3797 3798 case AryPtr: // Meet with AryPtr 3799 case InstPtr: // Meet with InstPtr 3800 return TypeInstPtr::BOTTOM; 3801 3802 // 3803 // A-top } 3804 // / | \ } Tops 3805 // B-top A-any C-top } 3806 // | / | \ | } Any-nulls 3807 // B-any | C-any } 3808 // | | | 3809 // B-con A-con C-con } constants; not comparable across classes 3810 // | | | 3811 // B-not | C-not } 3812 // | \ | / | } not-nulls 3813 // B-bot A-not C-bot } 3814 // \ | / } Bottoms 3815 // A-bot } 3816 // 3817 3818 case KlassPtr: { // Meet two KlassPtr types 3819 const TypeKlassPtr *tkls = t->is_klassptr(); 3820 int off = meet_offset(tkls->offset()); 3821 PTR ptr = meet_ptr(tkls->ptr()); 3822 3823 // Check for easy case; klasses are equal (and perhaps not loaded!) 3824 // If we have constants, then we created oops so classes are loaded 3825 // and we can handle the constants further down. This case handles 3826 // not-loaded classes 3827 if( ptr != Constant && tkls->klass()->equals(klass()) ) { 3828 return make( ptr, klass(), off ); 3829 } 3830 3831 // Classes require inspection in the Java klass hierarchy. Must be loaded. 3832 ciKlass* tkls_klass = tkls->klass(); 3833 ciKlass* this_klass = this->klass(); 3834 assert( tkls_klass->is_loaded(), "This class should have been loaded."); 3835 assert( this_klass->is_loaded(), "This class should have been loaded."); 3836 3837 // If 'this' type is above the centerline and is a superclass of the 3838 // other, we can treat 'this' as having the same type as the other. 3839 if ((above_centerline(this->ptr())) && 3840 tkls_klass->is_subtype_of(this_klass)) { 3841 this_klass = tkls_klass; 3842 } 3843 // If 'tinst' type is above the centerline and is a superclass of the 3844 // other, we can treat 'tinst' as having the same type as the other. 3845 if ((above_centerline(tkls->ptr())) && 3846 this_klass->is_subtype_of(tkls_klass)) { 3847 tkls_klass = this_klass; 3848 } 3849 3850 // Check for classes now being equal 3851 if (tkls_klass->equals(this_klass)) { 3852 // If the klasses are equal, the constants may still differ. Fall to 3853 // NotNull if they do (neither constant is NULL; that is a special case 3854 // handled elsewhere). 3855 ciObject* o = NULL; // Assume not constant when done 3856 ciObject* this_oop = const_oop(); 3857 ciObject* tkls_oop = tkls->const_oop(); 3858 if( ptr == Constant ) { 3859 if (this_oop != NULL && tkls_oop != NULL && 3860 this_oop->equals(tkls_oop) ) 3861 o = this_oop; 3862 else if (above_centerline(this->ptr())) 3863 o = tkls_oop; 3864 else if (above_centerline(tkls->ptr())) 3865 o = this_oop; 3866 else 3867 ptr = NotNull; 3868 } 3869 return make( ptr, this_klass, off ); 3870 } // Else classes are not equal 3871 3872 // Since klasses are different, we require the LCA in the Java 3873 // class hierarchy - which means we have to fall to at least NotNull. 3874 if( ptr == TopPTR || ptr == AnyNull || ptr == Constant ) 3875 ptr = NotNull; 3876 // Now we find the LCA of Java classes 3877 ciKlass* k = this_klass->least_common_ancestor(tkls_klass); 3878 return make( ptr, k, off ); 3879 } // End of case KlassPtr 3880 3881 } // End of switch 3882 return this; // Return the double constant 3883 } 3884 3885 //------------------------------xdual------------------------------------------ 3886 // Dual: compute field-by-field dual 3887 const Type *TypeKlassPtr::xdual() const { 3888 return new TypeKlassPtr( dual_ptr(), klass(), dual_offset() ); 3889 } 3890 3891 //------------------------------dump2------------------------------------------ 3892 // Dump Klass Type 3893 #ifndef PRODUCT 3894 void TypeKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const { 3895 switch( _ptr ) { 3896 case Constant: 3897 st->print("precise "); 3898 case NotNull: 3899 { 3900 const char *name = klass()->name()->as_utf8(); 3901 if( name ) { 3902 st->print("klass %s: " INTPTR_FORMAT, name, klass()); 3903 } else { 3904 ShouldNotReachHere(); 3905 } 3906 } 3907 case BotPTR: 3908 if( !WizardMode && !Verbose && !_klass_is_exact ) break; 3909 case TopPTR: 3910 case AnyNull: 3911 st->print(":%s", ptr_msg[_ptr]); 3912 if( _klass_is_exact ) st->print(":exact"); 3913 break; 3914 } 3915 3916 if( _offset ) { // Dump offset, if any 3917 if( _offset == OffsetBot ) { st->print("+any"); } 3918 else if( _offset == OffsetTop ) { st->print("+unknown"); } 3919 else { st->print("+%d", _offset); } 3920 } 3921 3922 st->print(" *"); 3923 } 3924 #endif 3925 3926 3927 3928 //============================================================================= 3929 // Convenience common pre-built types. 3930 3931 //------------------------------make------------------------------------------- 3932 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) { 3933 return (TypeFunc*)(new TypeFunc(domain,range))->hashcons(); 3934 } 3935 3936 //------------------------------make------------------------------------------- 3937 const TypeFunc *TypeFunc::make(ciMethod* method) { 3938 Compile* C = Compile::current(); 3939 const TypeFunc* tf = C->last_tf(method); // check cache 3940 if (tf != NULL) return tf; // The hit rate here is almost 50%. 3941 const TypeTuple *domain; 3942 if (method->flags().is_static()) { 3943 domain = TypeTuple::make_domain(NULL, method->signature()); 3944 } else { 3945 domain = TypeTuple::make_domain(method->holder(), method->signature()); 3946 } 3947 const TypeTuple *range = TypeTuple::make_range(method->signature()); 3948 tf = TypeFunc::make(domain, range); 3949 C->set_last_tf(method, tf); // fill cache 3950 return tf; 3951 } 3952 3953 //------------------------------meet------------------------------------------- 3954 // Compute the MEET of two types. It returns a new Type object. 3955 const Type *TypeFunc::xmeet( const Type *t ) const { 3956 // Perform a fast test for common case; meeting the same types together. 3957 if( this == t ) return this; // Meeting same type-rep? 3958 3959 // Current "this->_base" is Func 3960 switch (t->base()) { // switch on original type 3961 3962 case Bottom: // Ye Olde Default 3963 return t; 3964 3965 default: // All else is a mistake 3966 typerr(t); 3967 3968 case Top: 3969 break; 3970 } 3971 return this; // Return the double constant 3972 } 3973 3974 //------------------------------xdual------------------------------------------ 3975 // Dual: compute field-by-field dual 3976 const Type *TypeFunc::xdual() const { 3977 return this; 3978 } 3979 3980 //------------------------------eq--------------------------------------------- 3981 // Structural equality check for Type representations 3982 bool TypeFunc::eq( const Type *t ) const { 3983 const TypeFunc *a = (const TypeFunc*)t; 3984 return _domain == a->_domain && 3985 _range == a->_range; 3986 } 3987 3988 //------------------------------hash------------------------------------------- 3989 // Type-specific hashing function. 3990 int TypeFunc::hash(void) const { 3991 return (intptr_t)_domain + (intptr_t)_range; 3992 } 3993 3994 //------------------------------dump2------------------------------------------ 3995 // Dump Function Type 3996 #ifndef PRODUCT 3997 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const { 3998 if( _range->_cnt <= Parms ) 3999 st->print("void"); 4000 else { 4001 uint i; 4002 for (i = Parms; i < _range->_cnt-1; i++) { 4003 _range->field_at(i)->dump2(d,depth,st); 4004 st->print("/"); 4005 } 4006 _range->field_at(i)->dump2(d,depth,st); 4007 } 4008 st->print(" "); 4009 st->print("( "); 4010 if( !depth || d[this] ) { // Check for recursive dump 4011 st->print("...)"); 4012 return; 4013 } 4014 d.Insert((void*)this,(void*)this); // Stop recursion 4015 if (Parms < _domain->_cnt) 4016 _domain->field_at(Parms)->dump2(d,depth-1,st); 4017 for (uint i = Parms+1; i < _domain->_cnt; i++) { 4018 st->print(", "); 4019 _domain->field_at(i)->dump2(d,depth-1,st); 4020 } 4021 st->print(" )"); 4022 } 4023 4024 //------------------------------print_flattened-------------------------------- 4025 // Print a 'flattened' signature 4026 static const char * const flat_type_msg[Type::lastype] = { 4027 "bad","control","top","int","long","_", "narrowoop", 4028 "tuple:", "array:", 4029 "ptr", "rawptr", "ptr", "ptr", "ptr", "ptr", 4030 "func", "abIO", "return_address", "mem", 4031 "float_top", "ftcon:", "flt", 4032 "double_top", "dblcon:", "dbl", 4033 "bottom" 4034 }; 4035 4036 void TypeFunc::print_flattened() const { 4037 if( _range->_cnt <= Parms ) 4038 tty->print("void"); 4039 else { 4040 uint i; 4041 for (i = Parms; i < _range->_cnt-1; i++) 4042 tty->print("%s/",flat_type_msg[_range->field_at(i)->base()]); 4043 tty->print("%s",flat_type_msg[_range->field_at(i)->base()]); 4044 } 4045 tty->print(" ( "); 4046 if (Parms < _domain->_cnt) 4047 tty->print("%s",flat_type_msg[_domain->field_at(Parms)->base()]); 4048 for (uint i = Parms+1; i < _domain->_cnt; i++) 4049 tty->print(", %s",flat_type_msg[_domain->field_at(i)->base()]); 4050 tty->print(" )"); 4051 } 4052 #endif 4053 4054 //------------------------------singleton-------------------------------------- 4055 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 4056 // constants (Ldi nodes). Singletons are integer, float or double constants 4057 // or a single symbol. 4058 bool TypeFunc::singleton(void) const { 4059 return false; // Never a singleton 4060 } 4061 4062 bool TypeFunc::empty(void) const { 4063 return false; // Never empty 4064 } 4065 4066 4067 BasicType TypeFunc::return_type() const{ 4068 if (range()->cnt() == TypeFunc::Parms) { 4069 return T_VOID; 4070 } 4071 return range()->field_at(TypeFunc::Parms)->basic_type(); 4072 }