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