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