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