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