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