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