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