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