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