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