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