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