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