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::external_word_type }, // 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 bool TypeInterfaces::has_non_array_interface() const { 3689 assert(TypeAryPtr::_array_interfaces != nullptr, "How come Type::Initialize_shared wasn't called yet?"); 3690 3691 return !TypeAryPtr::_array_interfaces->contains(this); 3692 } 3693 3694 //------------------------------TypeOopPtr------------------------------------- 3695 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int offset, 3696 int instance_id, const TypePtr* speculative, int inline_depth) 3697 : TypePtr(t, ptr, offset, speculative, inline_depth), 3698 _const_oop(o), _klass(k), 3699 _interfaces(interfaces), 3700 _klass_is_exact(xk), 3701 _is_ptr_to_narrowoop(false), 3702 _is_ptr_to_narrowklass(false), 3703 _is_ptr_to_boxed_value(false), 3704 _instance_id(instance_id) { 3705 #ifdef ASSERT 3706 if (klass() != nullptr && klass()->is_loaded()) { 3707 interfaces->verify_is_loaded(); 3708 } 3709 #endif 3710 if (Compile::current()->eliminate_boxing() && (t == InstPtr) && 3711 (offset > 0) && xk && (k != nullptr) && k->is_instance_klass()) { 3712 _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset); 3713 } 3714 #ifdef _LP64 3715 if (_offset > 0 || _offset == Type::OffsetTop || _offset == Type::OffsetBot) { 3716 if (_offset == oopDesc::klass_offset_in_bytes()) { 3717 _is_ptr_to_narrowklass = UseCompressedClassPointers; 3718 } else if (klass() == nullptr) { 3719 // Array with unknown body type 3720 assert(this->isa_aryptr(), "only arrays without klass"); 3721 _is_ptr_to_narrowoop = UseCompressedOops; 3722 } else if (this->isa_aryptr()) { 3723 _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() && 3724 _offset != arrayOopDesc::length_offset_in_bytes()); 3725 } else if (klass()->is_instance_klass()) { 3726 ciInstanceKlass* ik = klass()->as_instance_klass(); 3727 if (this->isa_klassptr()) { 3728 // Perm objects don't use compressed references 3729 } else if (_offset == OffsetBot || _offset == OffsetTop) { 3730 // unsafe access 3731 _is_ptr_to_narrowoop = UseCompressedOops; 3732 } else { 3733 assert(this->isa_instptr(), "must be an instance ptr."); 3734 3735 if (klass() == ciEnv::current()->Class_klass() && 3736 (_offset == java_lang_Class::klass_offset() || 3737 _offset == java_lang_Class::array_klass_offset())) { 3738 // Special hidden fields from the Class. 3739 assert(this->isa_instptr(), "must be an instance ptr."); 3740 _is_ptr_to_narrowoop = false; 3741 } else if (klass() == ciEnv::current()->Class_klass() && 3742 _offset >= InstanceMirrorKlass::offset_of_static_fields()) { 3743 // Static fields 3744 ciField* field = nullptr; 3745 if (const_oop() != nullptr) { 3746 ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass(); 3747 field = k->get_field_by_offset(_offset, true); 3748 } 3749 if (field != nullptr) { 3750 BasicType basic_elem_type = field->layout_type(); 3751 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type); 3752 } else { 3753 // unsafe access 3754 _is_ptr_to_narrowoop = UseCompressedOops; 3755 } 3756 } else { 3757 // Instance fields which contains a compressed oop references. 3758 ciField* field = ik->get_field_by_offset(_offset, false); 3759 if (field != nullptr) { 3760 BasicType basic_elem_type = field->layout_type(); 3761 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type); 3762 } else if (klass()->equals(ciEnv::current()->Object_klass())) { 3763 // Compile::find_alias_type() cast exactness on all types to verify 3764 // that it does not affect alias type. 3765 _is_ptr_to_narrowoop = UseCompressedOops; 3766 } else { 3767 // Type for the copy start in LibraryCallKit::inline_native_clone(). 3768 _is_ptr_to_narrowoop = UseCompressedOops; 3769 } 3770 } 3771 } 3772 } 3773 } 3774 #endif 3775 } 3776 3777 //------------------------------make------------------------------------------- 3778 const TypeOopPtr *TypeOopPtr::make(PTR ptr, int offset, int instance_id, 3779 const TypePtr* speculative, int inline_depth) { 3780 assert(ptr != Constant, "no constant generic pointers"); 3781 ciKlass* k = Compile::current()->env()->Object_klass(); 3782 bool xk = false; 3783 ciObject* o = nullptr; 3784 const TypeInterfaces* interfaces = TypeInterfaces::make(); 3785 return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, interfaces, xk, o, offset, instance_id, speculative, inline_depth))->hashcons(); 3786 } 3787 3788 3789 //------------------------------cast_to_ptr_type------------------------------- 3790 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const { 3791 assert(_base == OopPtr, "subclass must override cast_to_ptr_type"); 3792 if( ptr == _ptr ) return this; 3793 return make(ptr, _offset, _instance_id, _speculative, _inline_depth); 3794 } 3795 3796 //-----------------------------cast_to_instance_id---------------------------- 3797 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const { 3798 // There are no instances of a general oop. 3799 // Return self unchanged. 3800 return this; 3801 } 3802 3803 //-----------------------------cast_to_exactness------------------------------- 3804 const TypeOopPtr* TypeOopPtr::cast_to_exactness(bool klass_is_exact) const { 3805 // There is no such thing as an exact general oop. 3806 // Return self unchanged. 3807 return this; 3808 } 3809 3810 3811 //------------------------------as_klass_type---------------------------------- 3812 // Return the klass type corresponding to this instance or array type. 3813 // It is the type that is loaded from an object of this type. 3814 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const { 3815 ShouldNotReachHere(); 3816 return nullptr; 3817 } 3818 3819 //------------------------------meet------------------------------------------- 3820 // Compute the MEET of two types. It returns a new Type object. 3821 const Type *TypeOopPtr::xmeet_helper(const Type *t) const { 3822 // Perform a fast test for common case; meeting the same types together. 3823 if( this == t ) return this; // Meeting same type-rep? 3824 3825 // Current "this->_base" is OopPtr 3826 switch (t->base()) { // switch on original type 3827 3828 case Int: // Mixing ints & oops happens when javac 3829 case Long: // reuses local variables 3830 case HalfFloatTop: 3831 case HalfFloatCon: 3832 case HalfFloatBot: 3833 case FloatTop: 3834 case FloatCon: 3835 case FloatBot: 3836 case DoubleTop: 3837 case DoubleCon: 3838 case DoubleBot: 3839 case NarrowOop: 3840 case NarrowKlass: 3841 case Bottom: // Ye Olde Default 3842 return Type::BOTTOM; 3843 case Top: 3844 return this; 3845 3846 default: // All else is a mistake 3847 typerr(t); 3848 3849 case RawPtr: 3850 case MetadataPtr: 3851 case KlassPtr: 3852 case InstKlassPtr: 3853 case AryKlassPtr: 3854 return TypePtr::BOTTOM; // Oop meet raw is not well defined 3855 3856 case AnyPtr: { 3857 // Found an AnyPtr type vs self-OopPtr type 3858 const TypePtr *tp = t->is_ptr(); 3859 int offset = meet_offset(tp->offset()); 3860 PTR ptr = meet_ptr(tp->ptr()); 3861 const TypePtr* speculative = xmeet_speculative(tp); 3862 int depth = meet_inline_depth(tp->inline_depth()); 3863 switch (tp->ptr()) { 3864 case Null: 3865 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth); 3866 // else fall through: 3867 case TopPTR: 3868 case AnyNull: { 3869 int instance_id = meet_instance_id(InstanceTop); 3870 return make(ptr, offset, instance_id, speculative, depth); 3871 } 3872 case BotPTR: 3873 case NotNull: 3874 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth); 3875 default: typerr(t); 3876 } 3877 } 3878 3879 case OopPtr: { // Meeting to other OopPtrs 3880 const TypeOopPtr *tp = t->is_oopptr(); 3881 int instance_id = meet_instance_id(tp->instance_id()); 3882 const TypePtr* speculative = xmeet_speculative(tp); 3883 int depth = meet_inline_depth(tp->inline_depth()); 3884 return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth); 3885 } 3886 3887 case InstPtr: // For these, flip the call around to cut down 3888 case AryPtr: 3889 return t->xmeet(this); // Call in reverse direction 3890 3891 } // End of switch 3892 return this; // Return the double constant 3893 } 3894 3895 3896 //------------------------------xdual------------------------------------------ 3897 // Dual of a pure heap pointer. No relevant klass or oop information. 3898 const Type *TypeOopPtr::xdual() const { 3899 assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here"); 3900 assert(const_oop() == nullptr, "no constants here"); 3901 return new TypeOopPtr(_base, dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth()); 3902 } 3903 3904 //--------------------------make_from_klass_common----------------------------- 3905 // Computes the element-type given a klass. 3906 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling) { 3907 if (klass->is_instance_klass()) { 3908 Compile* C = Compile::current(); 3909 Dependencies* deps = C->dependencies(); 3910 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity"); 3911 // Element is an instance 3912 bool klass_is_exact = false; 3913 if (klass->is_loaded()) { 3914 // Try to set klass_is_exact. 3915 ciInstanceKlass* ik = klass->as_instance_klass(); 3916 klass_is_exact = ik->is_final(); 3917 if (!klass_is_exact && klass_change 3918 && deps != nullptr && UseUniqueSubclasses) { 3919 ciInstanceKlass* sub = ik->unique_concrete_subklass(); 3920 if (sub != nullptr) { 3921 deps->assert_abstract_with_unique_concrete_subtype(ik, sub); 3922 klass = ik = sub; 3923 klass_is_exact = sub->is_final(); 3924 } 3925 } 3926 if (!klass_is_exact && try_for_exact && deps != nullptr && 3927 !ik->is_interface() && !ik->has_subklass()) { 3928 // Add a dependence; if concrete subclass added we need to recompile 3929 deps->assert_leaf_type(ik); 3930 klass_is_exact = true; 3931 } 3932 } 3933 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling); 3934 return TypeInstPtr::make(TypePtr::BotPTR, klass, interfaces, klass_is_exact, nullptr, 0); 3935 } else if (klass->is_obj_array_klass()) { 3936 // Element is an object array. Recursively call ourself. 3937 ciKlass* eklass = klass->as_obj_array_klass()->element_klass(); 3938 const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(eklass, false, try_for_exact, interface_handling); 3939 bool xk = etype->klass_is_exact(); 3940 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS); 3941 // We used to pass NotNull in here, asserting that the sub-arrays 3942 // are all not-null. This is not true in generally, as code can 3943 // slam nulls down in the subarrays. 3944 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, nullptr, xk, 0); 3945 return arr; 3946 } else if (klass->is_type_array_klass()) { 3947 // Element is an typeArray 3948 const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type()); 3949 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS); 3950 // We used to pass NotNull in here, asserting that the array pointer 3951 // is not-null. That was not true in general. 3952 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, 0); 3953 return arr; 3954 } else { 3955 ShouldNotReachHere(); 3956 return nullptr; 3957 } 3958 } 3959 3960 //------------------------------make_from_constant----------------------------- 3961 // Make a java pointer from an oop constant 3962 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) { 3963 assert(!o->is_null_object(), "null object not yet handled here."); 3964 3965 const bool make_constant = require_constant || o->should_be_constant(); 3966 3967 ciKlass* klass = o->klass(); 3968 if (klass->is_instance_klass()) { 3969 // Element is an instance 3970 if (make_constant) { 3971 return TypeInstPtr::make(o); 3972 } else { 3973 return TypeInstPtr::make(TypePtr::NotNull, klass, true, nullptr, 0); 3974 } 3975 } else if (klass->is_obj_array_klass()) { 3976 // Element is an object array. Recursively call ourself. 3977 const TypeOopPtr *etype = 3978 TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass(), trust_interfaces); 3979 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length())); 3980 // We used to pass NotNull in here, asserting that the sub-arrays 3981 // are all not-null. This is not true in generally, as code can 3982 // slam nulls down in the subarrays. 3983 if (make_constant) { 3984 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0); 3985 } else { 3986 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0); 3987 } 3988 } else if (klass->is_type_array_klass()) { 3989 // Element is an typeArray 3990 const Type* etype = 3991 (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type()); 3992 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length())); 3993 // We used to pass NotNull in here, asserting that the array pointer 3994 // is not-null. That was not true in general. 3995 if (make_constant) { 3996 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0); 3997 } else { 3998 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0); 3999 } 4000 } 4001 4002 fatal("unhandled object type"); 4003 return nullptr; 4004 } 4005 4006 //------------------------------get_con---------------------------------------- 4007 intptr_t TypeOopPtr::get_con() const { 4008 assert( _ptr == Null || _ptr == Constant, "" ); 4009 assert( _offset >= 0, "" ); 4010 4011 if (_offset != 0) { 4012 // After being ported to the compiler interface, the compiler no longer 4013 // directly manipulates the addresses of oops. Rather, it only has a pointer 4014 // to a handle at compile time. This handle is embedded in the generated 4015 // code and dereferenced at the time the nmethod is made. Until that time, 4016 // it is not reasonable to do arithmetic with the addresses of oops (we don't 4017 // have access to the addresses!). This does not seem to currently happen, 4018 // but this assertion here is to help prevent its occurrence. 4019 tty->print_cr("Found oop constant with non-zero offset"); 4020 ShouldNotReachHere(); 4021 } 4022 4023 return (intptr_t)const_oop()->constant_encoding(); 4024 } 4025 4026 4027 //-----------------------------filter------------------------------------------ 4028 // Do not allow interface-vs.-noninterface joins to collapse to top. 4029 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const { 4030 4031 const Type* ft = join_helper(kills, include_speculative); 4032 4033 if (ft->empty()) { 4034 return Type::TOP; // Canonical empty value 4035 } 4036 4037 return ft; 4038 } 4039 4040 //------------------------------eq--------------------------------------------- 4041 // Structural equality check for Type representations 4042 bool TypeOopPtr::eq( const Type *t ) const { 4043 const TypeOopPtr *a = (const TypeOopPtr*)t; 4044 if (_klass_is_exact != a->_klass_is_exact || 4045 _instance_id != a->_instance_id) return false; 4046 ciObject* one = const_oop(); 4047 ciObject* two = a->const_oop(); 4048 if (one == nullptr || two == nullptr) { 4049 return (one == two) && TypePtr::eq(t); 4050 } else { 4051 return one->equals(two) && TypePtr::eq(t); 4052 } 4053 } 4054 4055 //------------------------------hash------------------------------------------- 4056 // Type-specific hashing function. 4057 uint TypeOopPtr::hash(void) const { 4058 return 4059 (uint)(const_oop() ? const_oop()->hash() : 0) + 4060 (uint)_klass_is_exact + 4061 (uint)_instance_id + TypePtr::hash(); 4062 } 4063 4064 //------------------------------dump2------------------------------------------ 4065 #ifndef PRODUCT 4066 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const { 4067 st->print("oopptr:%s", ptr_msg[_ptr]); 4068 if( _klass_is_exact ) st->print(":exact"); 4069 if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop())); 4070 switch( _offset ) { 4071 case OffsetTop: st->print("+top"); break; 4072 case OffsetBot: st->print("+any"); break; 4073 case 0: break; 4074 default: st->print("+%d",_offset); break; 4075 } 4076 if (_instance_id == InstanceTop) 4077 st->print(",iid=top"); 4078 else if (_instance_id != InstanceBot) 4079 st->print(",iid=%d",_instance_id); 4080 4081 dump_inline_depth(st); 4082 dump_speculative(st); 4083 } 4084 #endif 4085 4086 //------------------------------singleton-------------------------------------- 4087 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 4088 // constants 4089 bool TypeOopPtr::singleton(void) const { 4090 // detune optimizer to not generate constant oop + constant offset as a constant! 4091 // TopPTR, Null, AnyNull, Constant are all singletons 4092 return (_offset == 0) && !below_centerline(_ptr); 4093 } 4094 4095 //------------------------------add_offset------------------------------------- 4096 const TypePtr* TypeOopPtr::add_offset(intptr_t offset) const { 4097 return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth); 4098 } 4099 4100 const TypeOopPtr* TypeOopPtr::with_offset(intptr_t offset) const { 4101 return make(_ptr, offset, _instance_id, with_offset_speculative(offset), _inline_depth); 4102 } 4103 4104 /** 4105 * Return same type without a speculative part 4106 */ 4107 const TypeOopPtr* TypeOopPtr::remove_speculative() const { 4108 if (_speculative == nullptr) { 4109 return this; 4110 } 4111 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth"); 4112 return make(_ptr, _offset, _instance_id, nullptr, _inline_depth); 4113 } 4114 4115 /** 4116 * Return same type but drop speculative part if we know we won't use 4117 * it 4118 */ 4119 const Type* TypeOopPtr::cleanup_speculative() const { 4120 // If the klass is exact and the ptr is not null then there's 4121 // nothing that the speculative type can help us with 4122 if (klass_is_exact() && !maybe_null()) { 4123 return remove_speculative(); 4124 } 4125 return TypePtr::cleanup_speculative(); 4126 } 4127 4128 /** 4129 * Return same type but with a different inline depth (used for speculation) 4130 * 4131 * @param depth depth to meet with 4132 */ 4133 const TypePtr* TypeOopPtr::with_inline_depth(int depth) const { 4134 if (!UseInlineDepthForSpeculativeTypes) { 4135 return this; 4136 } 4137 return make(_ptr, _offset, _instance_id, _speculative, depth); 4138 } 4139 4140 //------------------------------with_instance_id-------------------------------- 4141 const TypePtr* TypeOopPtr::with_instance_id(int instance_id) const { 4142 assert(_instance_id != -1, "should be known"); 4143 return make(_ptr, _offset, instance_id, _speculative, _inline_depth); 4144 } 4145 4146 //------------------------------meet_instance_id-------------------------------- 4147 int TypeOopPtr::meet_instance_id( int instance_id ) const { 4148 // Either is 'TOP' instance? Return the other instance! 4149 if( _instance_id == InstanceTop ) return instance_id; 4150 if( instance_id == InstanceTop ) return _instance_id; 4151 // If either is different, return 'BOTTOM' instance 4152 if( _instance_id != instance_id ) return InstanceBot; 4153 return _instance_id; 4154 } 4155 4156 //------------------------------dual_instance_id-------------------------------- 4157 int TypeOopPtr::dual_instance_id( ) const { 4158 if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM 4159 if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP 4160 return _instance_id; // Map everything else into self 4161 } 4162 4163 4164 const TypeInterfaces* TypeOopPtr::meet_interfaces(const TypeOopPtr* other) const { 4165 if (above_centerline(_ptr) && above_centerline(other->_ptr)) { 4166 return _interfaces->union_with(other->_interfaces); 4167 } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) { 4168 return other->_interfaces; 4169 } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) { 4170 return _interfaces; 4171 } 4172 return _interfaces->intersection_with(other->_interfaces); 4173 } 4174 4175 /** 4176 * Check whether new profiling would improve speculative type 4177 * 4178 * @param exact_kls class from profiling 4179 * @param inline_depth inlining depth of profile point 4180 * 4181 * @return true if type profile is valuable 4182 */ 4183 bool TypeOopPtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const { 4184 // no way to improve an already exact type 4185 if (klass_is_exact()) { 4186 return false; 4187 } 4188 return TypePtr::would_improve_type(exact_kls, inline_depth); 4189 } 4190 4191 //============================================================================= 4192 // Convenience common pre-built types. 4193 const TypeInstPtr *TypeInstPtr::NOTNULL; 4194 const TypeInstPtr *TypeInstPtr::BOTTOM; 4195 const TypeInstPtr *TypeInstPtr::MIRROR; 4196 const TypeInstPtr *TypeInstPtr::MARK; 4197 const TypeInstPtr *TypeInstPtr::KLASS; 4198 4199 // Is there a single ciKlass* that can represent that type? 4200 ciKlass* TypeInstPtr::exact_klass_helper() const { 4201 if (_interfaces->empty()) { 4202 return _klass; 4203 } 4204 if (_klass != ciEnv::current()->Object_klass()) { 4205 if (_interfaces->eq(_klass->as_instance_klass())) { 4206 return _klass; 4207 } 4208 return nullptr; 4209 } 4210 return _interfaces->exact_klass(); 4211 } 4212 4213 //------------------------------TypeInstPtr------------------------------------- 4214 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int off, 4215 int instance_id, const TypePtr* speculative, int inline_depth) 4216 : TypeOopPtr(InstPtr, ptr, k, interfaces, xk, o, off, instance_id, speculative, inline_depth) { 4217 assert(k == nullptr || !k->is_loaded() || !k->is_interface(), "no interface here"); 4218 assert(k != nullptr && 4219 (k->is_loaded() || o == nullptr), 4220 "cannot have constants with non-loaded klass"); 4221 }; 4222 4223 //------------------------------make------------------------------------------- 4224 const TypeInstPtr *TypeInstPtr::make(PTR ptr, 4225 ciKlass* k, 4226 const TypeInterfaces* interfaces, 4227 bool xk, 4228 ciObject* o, 4229 int offset, 4230 int instance_id, 4231 const TypePtr* speculative, 4232 int inline_depth) { 4233 assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance"); 4234 // Either const_oop() is null or else ptr is Constant 4235 assert( (!o && ptr != Constant) || (o && ptr == Constant), 4236 "constant pointers must have a value supplied" ); 4237 // Ptr is never Null 4238 assert( ptr != Null, "null pointers are not typed" ); 4239 4240 assert(instance_id <= 0 || xk, "instances are always exactly typed"); 4241 if (ptr == Constant) { 4242 // Note: This case includes meta-object constants, such as methods. 4243 xk = true; 4244 } else if (k->is_loaded()) { 4245 ciInstanceKlass* ik = k->as_instance_klass(); 4246 if (!xk && ik->is_final()) xk = true; // no inexact final klass 4247 assert(!ik->is_interface(), "no interface here"); 4248 if (xk && ik->is_interface()) xk = false; // no exact interface 4249 } 4250 4251 // Now hash this baby 4252 TypeInstPtr *result = 4253 (TypeInstPtr*)(new TypeInstPtr(ptr, k, interfaces, xk, o ,offset, instance_id, speculative, inline_depth))->hashcons(); 4254 4255 return result; 4256 } 4257 4258 const TypeInterfaces* TypePtr::interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling) { 4259 if (k->is_instance_klass()) { 4260 if (k->is_loaded()) { 4261 if (k->is_interface() && interface_handling == ignore_interfaces) { 4262 assert(interface, "no interface expected"); 4263 k = ciEnv::current()->Object_klass(); 4264 const TypeInterfaces* interfaces = TypeInterfaces::make(); 4265 return interfaces; 4266 } 4267 GrowableArray<ciInstanceKlass *>* k_interfaces = k->as_instance_klass()->transitive_interfaces(); 4268 const TypeInterfaces* interfaces = TypeInterfaces::make(k_interfaces); 4269 if (k->is_interface()) { 4270 assert(interface, "no interface expected"); 4271 k = ciEnv::current()->Object_klass(); 4272 } else { 4273 assert(klass, "no instance klass expected"); 4274 } 4275 return interfaces; 4276 } 4277 const TypeInterfaces* interfaces = TypeInterfaces::make(); 4278 return interfaces; 4279 } 4280 assert(array, "no array expected"); 4281 assert(k->is_array_klass(), "Not an array?"); 4282 ciType* e = k->as_array_klass()->base_element_type(); 4283 if (e->is_loaded() && e->is_instance_klass() && e->as_instance_klass()->is_interface()) { 4284 if (interface_handling == ignore_interfaces) { 4285 k = ciObjArrayKlass::make(ciEnv::current()->Object_klass(), k->as_array_klass()->dimension()); 4286 } 4287 } 4288 return TypeAryPtr::_array_interfaces; 4289 } 4290 4291 /** 4292 * Create constant type for a constant boxed value 4293 */ 4294 const Type* TypeInstPtr::get_const_boxed_value() const { 4295 assert(is_ptr_to_boxed_value(), "should be called only for boxed value"); 4296 assert((const_oop() != nullptr), "should be called only for constant object"); 4297 ciConstant constant = const_oop()->as_instance()->field_value_by_offset(offset()); 4298 BasicType bt = constant.basic_type(); 4299 switch (bt) { 4300 case T_BOOLEAN: return TypeInt::make(constant.as_boolean()); 4301 case T_INT: return TypeInt::make(constant.as_int()); 4302 case T_CHAR: return TypeInt::make(constant.as_char()); 4303 case T_BYTE: return TypeInt::make(constant.as_byte()); 4304 case T_SHORT: return TypeInt::make(constant.as_short()); 4305 case T_FLOAT: return TypeF::make(constant.as_float()); 4306 case T_DOUBLE: return TypeD::make(constant.as_double()); 4307 case T_LONG: return TypeLong::make(constant.as_long()); 4308 default: break; 4309 } 4310 fatal("Invalid boxed value type '%s'", type2name(bt)); 4311 return nullptr; 4312 } 4313 4314 //------------------------------cast_to_ptr_type------------------------------- 4315 const TypeInstPtr* TypeInstPtr::cast_to_ptr_type(PTR ptr) const { 4316 if( ptr == _ptr ) return this; 4317 // Reconstruct _sig info here since not a problem with later lazy 4318 // construction, _sig will show up on demand. 4319 return make(ptr, klass(), _interfaces, klass_is_exact(), ptr == Constant ? const_oop() : nullptr, _offset, _instance_id, _speculative, _inline_depth); 4320 } 4321 4322 4323 //-----------------------------cast_to_exactness------------------------------- 4324 const TypeInstPtr* TypeInstPtr::cast_to_exactness(bool klass_is_exact) const { 4325 if( klass_is_exact == _klass_is_exact ) return this; 4326 if (!_klass->is_loaded()) return this; 4327 ciInstanceKlass* ik = _klass->as_instance_klass(); 4328 if( (ik->is_final() || _const_oop) ) return this; // cannot clear xk 4329 assert(!ik->is_interface(), "no interface here"); 4330 return make(ptr(), klass(), _interfaces, klass_is_exact, const_oop(), _offset, _instance_id, _speculative, _inline_depth); 4331 } 4332 4333 //-----------------------------cast_to_instance_id---------------------------- 4334 const TypeInstPtr* TypeInstPtr::cast_to_instance_id(int instance_id) const { 4335 if( instance_id == _instance_id ) return this; 4336 return make(_ptr, klass(), _interfaces, _klass_is_exact, const_oop(), _offset, instance_id, _speculative, _inline_depth); 4337 } 4338 4339 //------------------------------xmeet_unloaded--------------------------------- 4340 // Compute the MEET of two InstPtrs when at least one is unloaded. 4341 // Assume classes are different since called after check for same name/class-loader 4342 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst, const TypeInterfaces* interfaces) const { 4343 int off = meet_offset(tinst->offset()); 4344 PTR ptr = meet_ptr(tinst->ptr()); 4345 int instance_id = meet_instance_id(tinst->instance_id()); 4346 const TypePtr* speculative = xmeet_speculative(tinst); 4347 int depth = meet_inline_depth(tinst->inline_depth()); 4348 4349 const TypeInstPtr *loaded = is_loaded() ? this : tinst; 4350 const TypeInstPtr *unloaded = is_loaded() ? tinst : this; 4351 if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) { 4352 // 4353 // Meet unloaded class with java/lang/Object 4354 // 4355 // Meet 4356 // | Unloaded Class 4357 // Object | TOP | AnyNull | Constant | NotNull | BOTTOM | 4358 // =================================================================== 4359 // TOP | ..........................Unloaded......................| 4360 // AnyNull | U-AN |................Unloaded......................| 4361 // Constant | ... O-NN .................................. | O-BOT | 4362 // NotNull | ... O-NN .................................. | O-BOT | 4363 // BOTTOM | ........................Object-BOTTOM ..................| 4364 // 4365 assert(loaded->ptr() != TypePtr::Null, "insanity check"); 4366 // 4367 if (loaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); } 4368 else if (loaded->ptr() == TypePtr::AnyNull) { return make(ptr, unloaded->klass(), interfaces, false, nullptr, off, instance_id, speculative, depth); } 4369 else if (loaded->ptr() == TypePtr::BotPTR) { return TypeInstPtr::BOTTOM->with_speculative(speculative); } 4370 else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) { 4371 if (unloaded->ptr() == TypePtr::BotPTR) { return TypeInstPtr::BOTTOM->with_speculative(speculative); } 4372 else { return TypeInstPtr::NOTNULL->with_speculative(speculative); } 4373 } 4374 else if (unloaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); } 4375 4376 return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr()->with_speculative(speculative); 4377 } 4378 4379 // Both are unloaded, not the same class, not Object 4380 // Or meet unloaded with a different loaded class, not java/lang/Object 4381 if (ptr != TypePtr::BotPTR) { 4382 return TypeInstPtr::NOTNULL->with_speculative(speculative); 4383 } 4384 return TypeInstPtr::BOTTOM->with_speculative(speculative); 4385 } 4386 4387 4388 //------------------------------meet------------------------------------------- 4389 // Compute the MEET of two types. It returns a new Type object. 4390 const Type *TypeInstPtr::xmeet_helper(const Type *t) const { 4391 // Perform a fast test for common case; meeting the same types together. 4392 if( this == t ) return this; // Meeting same type-rep? 4393 4394 // Current "this->_base" is Pointer 4395 switch (t->base()) { // switch on original type 4396 4397 case Int: // Mixing ints & oops happens when javac 4398 case Long: // reuses local variables 4399 case HalfFloatTop: 4400 case HalfFloatCon: 4401 case HalfFloatBot: 4402 case FloatTop: 4403 case FloatCon: 4404 case FloatBot: 4405 case DoubleTop: 4406 case DoubleCon: 4407 case DoubleBot: 4408 case NarrowOop: 4409 case NarrowKlass: 4410 case Bottom: // Ye Olde Default 4411 return Type::BOTTOM; 4412 case Top: 4413 return this; 4414 4415 default: // All else is a mistake 4416 typerr(t); 4417 4418 case MetadataPtr: 4419 case KlassPtr: 4420 case InstKlassPtr: 4421 case AryKlassPtr: 4422 case RawPtr: return TypePtr::BOTTOM; 4423 4424 case AryPtr: { // All arrays inherit from Object class 4425 // Call in reverse direction to avoid duplication 4426 return t->is_aryptr()->xmeet_helper(this); 4427 } 4428 4429 case OopPtr: { // Meeting to OopPtrs 4430 // Found a OopPtr type vs self-InstPtr type 4431 const TypeOopPtr *tp = t->is_oopptr(); 4432 int offset = meet_offset(tp->offset()); 4433 PTR ptr = meet_ptr(tp->ptr()); 4434 switch (tp->ptr()) { 4435 case TopPTR: 4436 case AnyNull: { 4437 int instance_id = meet_instance_id(InstanceTop); 4438 const TypePtr* speculative = xmeet_speculative(tp); 4439 int depth = meet_inline_depth(tp->inline_depth()); 4440 return make(ptr, klass(), _interfaces, klass_is_exact(), 4441 (ptr == Constant ? const_oop() : nullptr), offset, instance_id, speculative, depth); 4442 } 4443 case NotNull: 4444 case BotPTR: { 4445 int instance_id = meet_instance_id(tp->instance_id()); 4446 const TypePtr* speculative = xmeet_speculative(tp); 4447 int depth = meet_inline_depth(tp->inline_depth()); 4448 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth); 4449 } 4450 default: typerr(t); 4451 } 4452 } 4453 4454 case AnyPtr: { // Meeting to AnyPtrs 4455 // Found an AnyPtr type vs self-InstPtr type 4456 const TypePtr *tp = t->is_ptr(); 4457 int offset = meet_offset(tp->offset()); 4458 PTR ptr = meet_ptr(tp->ptr()); 4459 int instance_id = meet_instance_id(InstanceTop); 4460 const TypePtr* speculative = xmeet_speculative(tp); 4461 int depth = meet_inline_depth(tp->inline_depth()); 4462 switch (tp->ptr()) { 4463 case Null: 4464 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth); 4465 // else fall through to AnyNull 4466 case TopPTR: 4467 case AnyNull: { 4468 return make(ptr, klass(), _interfaces, klass_is_exact(), 4469 (ptr == Constant ? const_oop() : nullptr), offset, instance_id, speculative, depth); 4470 } 4471 case NotNull: 4472 case BotPTR: 4473 return TypePtr::make(AnyPtr, ptr, offset, speculative,depth); 4474 default: typerr(t); 4475 } 4476 } 4477 4478 /* 4479 A-top } 4480 / | \ } Tops 4481 B-top A-any C-top } 4482 | / | \ | } Any-nulls 4483 B-any | C-any } 4484 | | | 4485 B-con A-con C-con } constants; not comparable across classes 4486 | | | 4487 B-not | C-not } 4488 | \ | / | } not-nulls 4489 B-bot A-not C-bot } 4490 \ | / } Bottoms 4491 A-bot } 4492 */ 4493 4494 case InstPtr: { // Meeting 2 Oops? 4495 // Found an InstPtr sub-type vs self-InstPtr type 4496 const TypeInstPtr *tinst = t->is_instptr(); 4497 int off = meet_offset(tinst->offset()); 4498 PTR ptr = meet_ptr(tinst->ptr()); 4499 int instance_id = meet_instance_id(tinst->instance_id()); 4500 const TypePtr* speculative = xmeet_speculative(tinst); 4501 int depth = meet_inline_depth(tinst->inline_depth()); 4502 const TypeInterfaces* interfaces = meet_interfaces(tinst); 4503 4504 ciKlass* tinst_klass = tinst->klass(); 4505 ciKlass* this_klass = klass(); 4506 4507 ciKlass* res_klass = nullptr; 4508 bool res_xk = false; 4509 const Type* res; 4510 MeetResult kind = meet_instptr(ptr, interfaces, this, tinst, res_klass, res_xk); 4511 4512 if (kind == UNLOADED) { 4513 // One of these classes has not been loaded 4514 const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst, interfaces); 4515 #ifndef PRODUCT 4516 if (PrintOpto && Verbose) { 4517 tty->print("meet of unloaded classes resulted in: "); 4518 unloaded_meet->dump(); 4519 tty->cr(); 4520 tty->print(" this == "); 4521 dump(); 4522 tty->cr(); 4523 tty->print(" tinst == "); 4524 tinst->dump(); 4525 tty->cr(); 4526 } 4527 #endif 4528 res = unloaded_meet; 4529 } else { 4530 if (kind == NOT_SUBTYPE && instance_id > 0) { 4531 instance_id = InstanceBot; 4532 } else if (kind == LCA) { 4533 instance_id = InstanceBot; 4534 } 4535 ciObject* o = nullptr; // Assume not constant when done 4536 ciObject* this_oop = const_oop(); 4537 ciObject* tinst_oop = tinst->const_oop(); 4538 if (ptr == Constant) { 4539 if (this_oop != nullptr && tinst_oop != nullptr && 4540 this_oop->equals(tinst_oop)) 4541 o = this_oop; 4542 else if (above_centerline(_ptr)) { 4543 assert(!tinst_klass->is_interface(), ""); 4544 o = tinst_oop; 4545 } else if (above_centerline(tinst->_ptr)) { 4546 assert(!this_klass->is_interface(), ""); 4547 o = this_oop; 4548 } else 4549 ptr = NotNull; 4550 } 4551 res = make(ptr, res_klass, interfaces, res_xk, o, off, instance_id, speculative, depth); 4552 } 4553 4554 return res; 4555 4556 } // End of case InstPtr 4557 4558 } // End of switch 4559 return this; // Return the double constant 4560 } 4561 4562 template<class T> TypePtr::MeetResult TypePtr::meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type, const T* other_type, 4563 ciKlass*& res_klass, bool& res_xk) { 4564 ciKlass* this_klass = this_type->klass(); 4565 ciKlass* other_klass = other_type->klass(); 4566 bool this_xk = this_type->klass_is_exact(); 4567 bool other_xk = other_type->klass_is_exact(); 4568 PTR this_ptr = this_type->ptr(); 4569 PTR other_ptr = other_type->ptr(); 4570 const TypeInterfaces* this_interfaces = this_type->interfaces(); 4571 const TypeInterfaces* other_interfaces = other_type->interfaces(); 4572 // Check for easy case; klasses are equal (and perhaps not loaded!) 4573 // If we have constants, then we created oops so classes are loaded 4574 // and we can handle the constants further down. This case handles 4575 // both-not-loaded or both-loaded classes 4576 if (ptr != Constant && this_klass->equals(other_klass) && this_xk == other_xk) { 4577 res_klass = this_klass; 4578 res_xk = this_xk; 4579 return QUICK; 4580 } 4581 4582 // Classes require inspection in the Java klass hierarchy. Must be loaded. 4583 if (!other_klass->is_loaded() || !this_klass->is_loaded()) { 4584 return UNLOADED; 4585 } 4586 4587 // !!! Here's how the symmetry requirement breaks down into invariants: 4588 // If we split one up & one down AND they subtype, take the down man. 4589 // If we split one up & one down AND they do NOT subtype, "fall hard". 4590 // If both are up and they subtype, take the subtype class. 4591 // If both are up and they do NOT subtype, "fall hard". 4592 // If both are down and they subtype, take the supertype class. 4593 // If both are down and they do NOT subtype, "fall hard". 4594 // Constants treated as down. 4595 4596 // Now, reorder the above list; observe that both-down+subtype is also 4597 // "fall hard"; "fall hard" becomes the default case: 4598 // If we split one up & one down AND they subtype, take the down man. 4599 // If both are up and they subtype, take the subtype class. 4600 4601 // If both are down and they subtype, "fall hard". 4602 // If both are down and they do NOT subtype, "fall hard". 4603 // If both are up and they do NOT subtype, "fall hard". 4604 // If we split one up & one down AND they do NOT subtype, "fall hard". 4605 4606 // If a proper subtype is exact, and we return it, we return it exactly. 4607 // If a proper supertype is exact, there can be no subtyping relationship! 4608 // If both types are equal to the subtype, exactness is and-ed below the 4609 // centerline and or-ed above it. (N.B. Constants are always exact.) 4610 4611 // Check for subtyping: 4612 const T* subtype = nullptr; 4613 bool subtype_exact = false; 4614 if (this_type->is_same_java_type_as(other_type)) { 4615 subtype = this_type; 4616 subtype_exact = below_centerline(ptr) ? (this_xk && other_xk) : (this_xk || other_xk); 4617 } else if (!other_xk && this_type->is_meet_subtype_of(other_type)) { 4618 subtype = this_type; // Pick subtyping class 4619 subtype_exact = this_xk; 4620 } else if(!this_xk && other_type->is_meet_subtype_of(this_type)) { 4621 subtype = other_type; // Pick subtyping class 4622 subtype_exact = other_xk; 4623 } 4624 4625 if (subtype) { 4626 if (above_centerline(ptr)) { // both are up? 4627 this_type = other_type = subtype; 4628 this_xk = other_xk = subtype_exact; 4629 } else if (above_centerline(this_ptr) && !above_centerline(other_ptr)) { 4630 this_type = other_type; // tinst is down; keep down man 4631 this_xk = other_xk; 4632 } else if (above_centerline(other_ptr) && !above_centerline(this_ptr)) { 4633 other_type = this_type; // this is down; keep down man 4634 other_xk = this_xk; 4635 } else { 4636 this_xk = subtype_exact; // either they are equal, or we'll do an LCA 4637 } 4638 } 4639 4640 // Check for classes now being equal 4641 if (this_type->is_same_java_type_as(other_type)) { 4642 // If the klasses are equal, the constants may still differ. Fall to 4643 // NotNull if they do (neither constant is null; that is a special case 4644 // handled elsewhere). 4645 res_klass = this_type->klass(); 4646 res_xk = this_xk; 4647 return SUBTYPE; 4648 } // Else classes are not equal 4649 4650 // Since klasses are different, we require a LCA in the Java 4651 // class hierarchy - which means we have to fall to at least NotNull. 4652 if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) { 4653 ptr = NotNull; 4654 } 4655 4656 interfaces = this_interfaces->intersection_with(other_interfaces); 4657 4658 // Now we find the LCA of Java classes 4659 ciKlass* k = this_klass->least_common_ancestor(other_klass); 4660 4661 res_klass = k; 4662 res_xk = false; 4663 4664 return LCA; 4665 } 4666 4667 //------------------------java_mirror_type-------------------------------------- 4668 ciType* TypeInstPtr::java_mirror_type() const { 4669 // must be a singleton type 4670 if( const_oop() == nullptr ) return nullptr; 4671 4672 // must be of type java.lang.Class 4673 if( klass() != ciEnv::current()->Class_klass() ) return nullptr; 4674 4675 return const_oop()->as_instance()->java_mirror_type(); 4676 } 4677 4678 4679 //------------------------------xdual------------------------------------------ 4680 // Dual: do NOT dual on klasses. This means I do NOT understand the Java 4681 // inheritance mechanism. 4682 const Type *TypeInstPtr::xdual() const { 4683 return new TypeInstPtr(dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth()); 4684 } 4685 4686 //------------------------------eq--------------------------------------------- 4687 // Structural equality check for Type representations 4688 bool TypeInstPtr::eq( const Type *t ) const { 4689 const TypeInstPtr *p = t->is_instptr(); 4690 return 4691 klass()->equals(p->klass()) && 4692 _interfaces->eq(p->_interfaces) && 4693 TypeOopPtr::eq(p); // Check sub-type stuff 4694 } 4695 4696 //------------------------------hash------------------------------------------- 4697 // Type-specific hashing function. 4698 uint TypeInstPtr::hash(void) const { 4699 return klass()->hash() + TypeOopPtr::hash() + _interfaces->hash(); 4700 } 4701 4702 bool TypeInstPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const { 4703 return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact); 4704 } 4705 4706 4707 bool TypeInstPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const { 4708 return TypePtr::is_same_java_type_as_helper_for_instance(this, other); 4709 } 4710 4711 bool TypeInstPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const { 4712 return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact); 4713 } 4714 4715 4716 //------------------------------dump2------------------------------------------ 4717 // Dump oop Type 4718 #ifndef PRODUCT 4719 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const { 4720 // Print the name of the klass. 4721 klass()->print_name_on(st); 4722 _interfaces->dump(st); 4723 4724 switch( _ptr ) { 4725 case Constant: 4726 if (WizardMode || Verbose) { 4727 ResourceMark rm; 4728 stringStream ss; 4729 4730 st->print(" " INTPTR_FORMAT, p2i(const_oop())); 4731 const_oop()->print_oop(&ss); 4732 // 'const_oop->print_oop()' may emit newlines('\n') into ss. 4733 // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node. 4734 char* buf = ss.as_string(/* c_heap= */false); 4735 StringUtils::replace_no_expand(buf, "\n", ""); 4736 st->print_raw(buf); 4737 } 4738 case BotPTR: 4739 if (!WizardMode && !Verbose) { 4740 if( _klass_is_exact ) st->print(":exact"); 4741 break; 4742 } 4743 case TopPTR: 4744 case AnyNull: 4745 case NotNull: 4746 st->print(":%s", ptr_msg[_ptr]); 4747 if( _klass_is_exact ) st->print(":exact"); 4748 break; 4749 default: 4750 break; 4751 } 4752 4753 if( _offset ) { // Dump offset, if any 4754 if( _offset == OffsetBot ) st->print("+any"); 4755 else if( _offset == OffsetTop ) st->print("+unknown"); 4756 else st->print("+%d", _offset); 4757 } 4758 4759 st->print(" *"); 4760 if (_instance_id == InstanceTop) 4761 st->print(",iid=top"); 4762 else if (_instance_id != InstanceBot) 4763 st->print(",iid=%d",_instance_id); 4764 4765 dump_inline_depth(st); 4766 dump_speculative(st); 4767 } 4768 #endif 4769 4770 //------------------------------add_offset------------------------------------- 4771 const TypePtr* TypeInstPtr::add_offset(intptr_t offset) const { 4772 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), xadd_offset(offset), 4773 _instance_id, add_offset_speculative(offset), _inline_depth); 4774 } 4775 4776 const TypeInstPtr* TypeInstPtr::with_offset(intptr_t offset) const { 4777 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), offset, 4778 _instance_id, with_offset_speculative(offset), _inline_depth); 4779 } 4780 4781 const TypeInstPtr* TypeInstPtr::remove_speculative() const { 4782 if (_speculative == nullptr) { 4783 return this; 4784 } 4785 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth"); 4786 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, 4787 _instance_id, nullptr, _inline_depth); 4788 } 4789 4790 const TypeInstPtr* TypeInstPtr::with_speculative(const TypePtr* speculative) const { 4791 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _instance_id, speculative, _inline_depth); 4792 } 4793 4794 const TypePtr* TypeInstPtr::with_inline_depth(int depth) const { 4795 if (!UseInlineDepthForSpeculativeTypes) { 4796 return this; 4797 } 4798 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth); 4799 } 4800 4801 const TypePtr* TypeInstPtr::with_instance_id(int instance_id) const { 4802 assert(is_known_instance(), "should be known"); 4803 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, instance_id, _speculative, _inline_depth); 4804 } 4805 4806 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const { 4807 bool xk = klass_is_exact(); 4808 ciInstanceKlass* ik = klass()->as_instance_klass(); 4809 if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final()) { 4810 if (_interfaces->eq(ik)) { 4811 Compile* C = Compile::current(); 4812 Dependencies* deps = C->dependencies(); 4813 deps->assert_leaf_type(ik); 4814 xk = true; 4815 } 4816 } 4817 return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), _interfaces, 0); 4818 } 4819 4820 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) { 4821 static_assert(std::is_base_of<T2, T1>::value, ""); 4822 4823 if (!this_one->is_instance_type(other)) { 4824 return false; 4825 } 4826 4827 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) { 4828 return true; 4829 } 4830 4831 return this_one->klass()->is_subtype_of(other->klass()) && 4832 (!this_xk || this_one->_interfaces->contains(other->_interfaces)); 4833 } 4834 4835 4836 bool TypeInstPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const { 4837 return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk); 4838 } 4839 4840 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) { 4841 static_assert(std::is_base_of<T2, T1>::value, ""); 4842 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) { 4843 return true; 4844 } 4845 4846 if (this_one->is_instance_type(other)) { 4847 return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces); 4848 } 4849 4850 int dummy; 4851 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM); 4852 if (this_top_or_bottom) { 4853 return false; 4854 } 4855 4856 const T1* other_ary = this_one->is_array_type(other); 4857 const TypePtr* other_elem = other_ary->elem()->make_ptr(); 4858 const TypePtr* this_elem = this_one->elem()->make_ptr(); 4859 if (other_elem != nullptr && this_elem != nullptr) { 4860 return this_one->is_reference_type(this_elem)->is_meet_subtype_of_helper(this_one->is_reference_type(other_elem), this_xk, other_xk); 4861 } 4862 4863 if (other_elem == nullptr && this_elem == nullptr) { 4864 return this_one->klass()->is_subtype_of(other->klass()); 4865 } 4866 4867 return false; 4868 } 4869 4870 bool TypeAryPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const { 4871 return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk); 4872 } 4873 4874 bool TypeInstKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const { 4875 return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk); 4876 } 4877 4878 bool TypeAryKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const { 4879 return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk); 4880 } 4881 4882 //============================================================================= 4883 // Convenience common pre-built types. 4884 const TypeAryPtr* TypeAryPtr::BOTTOM; 4885 const TypeAryPtr* TypeAryPtr::RANGE; 4886 const TypeAryPtr* TypeAryPtr::OOPS; 4887 const TypeAryPtr* TypeAryPtr::NARROWOOPS; 4888 const TypeAryPtr* TypeAryPtr::BYTES; 4889 const TypeAryPtr* TypeAryPtr::SHORTS; 4890 const TypeAryPtr* TypeAryPtr::CHARS; 4891 const TypeAryPtr* TypeAryPtr::INTS; 4892 const TypeAryPtr* TypeAryPtr::LONGS; 4893 const TypeAryPtr* TypeAryPtr::FLOATS; 4894 const TypeAryPtr* TypeAryPtr::DOUBLES; 4895 4896 //------------------------------make------------------------------------------- 4897 const TypeAryPtr *TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, 4898 int instance_id, const TypePtr* speculative, int inline_depth) { 4899 assert(!(k == nullptr && ary->_elem->isa_int()), 4900 "integral arrays must be pre-equipped with a class"); 4901 if (!xk) xk = ary->ary_must_be_exact(); 4902 assert(instance_id <= 0 || xk, "instances are always exactly typed"); 4903 if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() && 4904 k->as_obj_array_klass()->base_element_klass()->is_interface()) { 4905 k = nullptr; 4906 } 4907 return (TypeAryPtr*)(new TypeAryPtr(ptr, nullptr, ary, k, xk, offset, instance_id, false, speculative, inline_depth))->hashcons(); 4908 } 4909 4910 //------------------------------make------------------------------------------- 4911 const TypeAryPtr *TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, 4912 int instance_id, const TypePtr* speculative, int inline_depth, 4913 bool is_autobox_cache) { 4914 assert(!(k == nullptr && ary->_elem->isa_int()), 4915 "integral arrays must be pre-equipped with a class"); 4916 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" ); 4917 if (!xk) xk = (o != nullptr) || ary->ary_must_be_exact(); 4918 assert(instance_id <= 0 || xk, "instances are always exactly typed"); 4919 if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() && 4920 k->as_obj_array_klass()->base_element_klass()->is_interface()) { 4921 k = nullptr; 4922 } 4923 return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons(); 4924 } 4925 4926 //------------------------------cast_to_ptr_type------------------------------- 4927 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const { 4928 if( ptr == _ptr ) return this; 4929 return make(ptr, ptr == Constant ? const_oop() : nullptr, _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth); 4930 } 4931 4932 4933 //-----------------------------cast_to_exactness------------------------------- 4934 const TypeAryPtr* TypeAryPtr::cast_to_exactness(bool klass_is_exact) const { 4935 if( klass_is_exact == _klass_is_exact ) return this; 4936 if (_ary->ary_must_be_exact()) return this; // cannot clear xk 4937 return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id, _speculative, _inline_depth); 4938 } 4939 4940 //-----------------------------cast_to_instance_id---------------------------- 4941 const TypeAryPtr* TypeAryPtr::cast_to_instance_id(int instance_id) const { 4942 if( instance_id == _instance_id ) return this; 4943 return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative, _inline_depth); 4944 } 4945 4946 4947 //-----------------------------max_array_length------------------------------- 4948 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization. 4949 jint TypeAryPtr::max_array_length(BasicType etype) { 4950 if (!is_java_primitive(etype) && !::is_reference_type(etype)) { 4951 if (etype == T_NARROWOOP) { 4952 etype = T_OBJECT; 4953 } else if (etype == T_ILLEGAL) { // bottom[] 4954 etype = T_BYTE; // will produce conservatively high value 4955 } else { 4956 fatal("not an element type: %s", type2name(etype)); 4957 } 4958 } 4959 return arrayOopDesc::max_array_length(etype); 4960 } 4961 4962 //-----------------------------narrow_size_type------------------------------- 4963 // Narrow the given size type to the index range for the given array base type. 4964 // Return null if the resulting int type becomes empty. 4965 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const { 4966 jint hi = size->_hi; 4967 jint lo = size->_lo; 4968 jint min_lo = 0; 4969 jint max_hi = max_array_length(elem()->array_element_basic_type()); 4970 //if (index_not_size) --max_hi; // type of a valid array index, FTR 4971 bool chg = false; 4972 if (lo < min_lo) { 4973 lo = min_lo; 4974 if (size->is_con()) { 4975 hi = lo; 4976 } 4977 chg = true; 4978 } 4979 if (hi > max_hi) { 4980 hi = max_hi; 4981 if (size->is_con()) { 4982 lo = hi; 4983 } 4984 chg = true; 4985 } 4986 // Negative length arrays will produce weird intermediate dead fast-path code 4987 if (lo > hi) 4988 return TypeInt::ZERO; 4989 if (!chg) 4990 return size; 4991 return TypeInt::make(lo, hi, Type::WidenMin); 4992 } 4993 4994 //-------------------------------cast_to_size---------------------------------- 4995 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const { 4996 assert(new_size != nullptr, ""); 4997 new_size = narrow_size_type(new_size); 4998 if (new_size == size()) return this; 4999 const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable()); 5000 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth); 5001 } 5002 5003 //------------------------------cast_to_stable--------------------------------- 5004 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const { 5005 if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable())) 5006 return this; 5007 5008 const Type* elem = this->elem(); 5009 const TypePtr* elem_ptr = elem->make_ptr(); 5010 5011 if (stable_dimension > 1 && elem_ptr != nullptr && elem_ptr->isa_aryptr()) { 5012 // If this is widened from a narrow oop, TypeAry::make will re-narrow it. 5013 elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1); 5014 } 5015 5016 const TypeAry* new_ary = TypeAry::make(elem, size(), stable); 5017 5018 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth); 5019 } 5020 5021 //-----------------------------stable_dimension-------------------------------- 5022 int TypeAryPtr::stable_dimension() const { 5023 if (!is_stable()) return 0; 5024 int dim = 1; 5025 const TypePtr* elem_ptr = elem()->make_ptr(); 5026 if (elem_ptr != nullptr && elem_ptr->isa_aryptr()) 5027 dim += elem_ptr->is_aryptr()->stable_dimension(); 5028 return dim; 5029 } 5030 5031 //----------------------cast_to_autobox_cache----------------------------------- 5032 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const { 5033 if (is_autobox_cache()) return this; 5034 const TypeOopPtr* etype = elem()->make_oopptr(); 5035 if (etype == nullptr) return this; 5036 // The pointers in the autobox arrays are always non-null. 5037 etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr(); 5038 const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable()); 5039 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true); 5040 } 5041 5042 //------------------------------eq--------------------------------------------- 5043 // Structural equality check for Type representations 5044 bool TypeAryPtr::eq( const Type *t ) const { 5045 const TypeAryPtr *p = t->is_aryptr(); 5046 return 5047 _ary == p->_ary && // Check array 5048 TypeOopPtr::eq(p); // Check sub-parts 5049 } 5050 5051 //------------------------------hash------------------------------------------- 5052 // Type-specific hashing function. 5053 uint TypeAryPtr::hash(void) const { 5054 return (uint)(uintptr_t)_ary + TypeOopPtr::hash(); 5055 } 5056 5057 bool TypeAryPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const { 5058 return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact); 5059 } 5060 5061 bool TypeAryPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const { 5062 return TypePtr::is_same_java_type_as_helper_for_array(this, other); 5063 } 5064 5065 bool TypeAryPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const { 5066 return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact); 5067 } 5068 //------------------------------meet------------------------------------------- 5069 // Compute the MEET of two types. It returns a new Type object. 5070 const Type *TypeAryPtr::xmeet_helper(const Type *t) const { 5071 // Perform a fast test for common case; meeting the same types together. 5072 if( this == t ) return this; // Meeting same type-rep? 5073 // Current "this->_base" is Pointer 5074 switch (t->base()) { // switch on original type 5075 5076 // Mixing ints & oops happens when javac reuses local variables 5077 case Int: 5078 case Long: 5079 case HalfFloatTop: 5080 case HalfFloatCon: 5081 case HalfFloatBot: 5082 case FloatTop: 5083 case FloatCon: 5084 case FloatBot: 5085 case DoubleTop: 5086 case DoubleCon: 5087 case DoubleBot: 5088 case NarrowOop: 5089 case NarrowKlass: 5090 case Bottom: // Ye Olde Default 5091 return Type::BOTTOM; 5092 case Top: 5093 return this; 5094 5095 default: // All else is a mistake 5096 typerr(t); 5097 5098 case OopPtr: { // Meeting to OopPtrs 5099 // Found a OopPtr type vs self-AryPtr type 5100 const TypeOopPtr *tp = t->is_oopptr(); 5101 int offset = meet_offset(tp->offset()); 5102 PTR ptr = meet_ptr(tp->ptr()); 5103 int depth = meet_inline_depth(tp->inline_depth()); 5104 const TypePtr* speculative = xmeet_speculative(tp); 5105 switch (tp->ptr()) { 5106 case TopPTR: 5107 case AnyNull: { 5108 int instance_id = meet_instance_id(InstanceTop); 5109 return make(ptr, (ptr == Constant ? const_oop() : nullptr), 5110 _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth); 5111 } 5112 case BotPTR: 5113 case NotNull: { 5114 int instance_id = meet_instance_id(tp->instance_id()); 5115 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth); 5116 } 5117 default: ShouldNotReachHere(); 5118 } 5119 } 5120 5121 case AnyPtr: { // Meeting two AnyPtrs 5122 // Found an AnyPtr type vs self-AryPtr type 5123 const TypePtr *tp = t->is_ptr(); 5124 int offset = meet_offset(tp->offset()); 5125 PTR ptr = meet_ptr(tp->ptr()); 5126 const TypePtr* speculative = xmeet_speculative(tp); 5127 int depth = meet_inline_depth(tp->inline_depth()); 5128 switch (tp->ptr()) { 5129 case TopPTR: 5130 return this; 5131 case BotPTR: 5132 case NotNull: 5133 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth); 5134 case Null: 5135 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth); 5136 // else fall through to AnyNull 5137 case AnyNull: { 5138 int instance_id = meet_instance_id(InstanceTop); 5139 return make(ptr, (ptr == Constant ? const_oop() : nullptr), 5140 _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth); 5141 } 5142 default: ShouldNotReachHere(); 5143 } 5144 } 5145 5146 case MetadataPtr: 5147 case KlassPtr: 5148 case InstKlassPtr: 5149 case AryKlassPtr: 5150 case RawPtr: return TypePtr::BOTTOM; 5151 5152 case AryPtr: { // Meeting 2 references? 5153 const TypeAryPtr *tap = t->is_aryptr(); 5154 int off = meet_offset(tap->offset()); 5155 const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary(); 5156 PTR ptr = meet_ptr(tap->ptr()); 5157 int instance_id = meet_instance_id(tap->instance_id()); 5158 const TypePtr* speculative = xmeet_speculative(tap); 5159 int depth = meet_inline_depth(tap->inline_depth()); 5160 5161 ciKlass* res_klass = nullptr; 5162 bool res_xk = false; 5163 const Type* elem = tary->_elem; 5164 if (meet_aryptr(ptr, elem, this, tap, res_klass, res_xk) == NOT_SUBTYPE) { 5165 instance_id = InstanceBot; 5166 } 5167 5168 ciObject* o = nullptr; // Assume not constant when done 5169 ciObject* this_oop = const_oop(); 5170 ciObject* tap_oop = tap->const_oop(); 5171 if (ptr == Constant) { 5172 if (this_oop != nullptr && tap_oop != nullptr && 5173 this_oop->equals(tap_oop)) { 5174 o = tap_oop; 5175 } else if (above_centerline(_ptr)) { 5176 o = tap_oop; 5177 } else if (above_centerline(tap->_ptr)) { 5178 o = this_oop; 5179 } else { 5180 ptr = NotNull; 5181 } 5182 } 5183 return make(ptr, o, TypeAry::make(elem, tary->_size, tary->_stable), res_klass, res_xk, off, instance_id, speculative, depth); 5184 } 5185 5186 // All arrays inherit from Object class 5187 case InstPtr: { 5188 const TypeInstPtr *tp = t->is_instptr(); 5189 int offset = meet_offset(tp->offset()); 5190 PTR ptr = meet_ptr(tp->ptr()); 5191 int instance_id = meet_instance_id(tp->instance_id()); 5192 const TypePtr* speculative = xmeet_speculative(tp); 5193 int depth = meet_inline_depth(tp->inline_depth()); 5194 const TypeInterfaces* interfaces = meet_interfaces(tp); 5195 const TypeInterfaces* tp_interfaces = tp->_interfaces; 5196 const TypeInterfaces* this_interfaces = _interfaces; 5197 5198 switch (ptr) { 5199 case TopPTR: 5200 case AnyNull: // Fall 'down' to dual of object klass 5201 // For instances when a subclass meets a superclass we fall 5202 // below the centerline when the superclass is exact. We need to 5203 // do the same here. 5204 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact()) { 5205 return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth); 5206 } else { 5207 // cannot subclass, so the meet has to fall badly below the centerline 5208 ptr = NotNull; 5209 instance_id = InstanceBot; 5210 interfaces = this_interfaces->intersection_with(tp_interfaces); 5211 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr,offset, instance_id, speculative, depth); 5212 } 5213 case Constant: 5214 case NotNull: 5215 case BotPTR: // Fall down to object klass 5216 // LCA is object_klass, but if we subclass from the top we can do better 5217 if (above_centerline(tp->ptr())) { 5218 // If 'tp' is above the centerline and it is Object class 5219 // then we can subclass in the Java class hierarchy. 5220 // For instances when a subclass meets a superclass we fall 5221 // below the centerline when the superclass is exact. We need 5222 // to do the same here. 5223 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact()) { 5224 // that is, my array type is a subtype of 'tp' klass 5225 return make(ptr, (ptr == Constant ? const_oop() : nullptr), 5226 _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth); 5227 } 5228 } 5229 // The other case cannot happen, since t cannot be a subtype of an array. 5230 // The meet falls down to Object class below centerline. 5231 if (ptr == Constant) { 5232 ptr = NotNull; 5233 } 5234 if (instance_id > 0) { 5235 instance_id = InstanceBot; 5236 } 5237 interfaces = this_interfaces->intersection_with(tp_interfaces); 5238 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset, instance_id, speculative, depth); 5239 default: typerr(t); 5240 } 5241 } 5242 } 5243 return this; // Lint noise 5244 } 5245 5246 5247 template<class T> TypePtr::MeetResult TypePtr::meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary, 5248 const T* other_ary, ciKlass*& res_klass, bool& res_xk) { 5249 int dummy; 5250 bool this_top_or_bottom = (this_ary->base_element_type(dummy) == Type::TOP || this_ary->base_element_type(dummy) == Type::BOTTOM); 5251 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM); 5252 ciKlass* this_klass = this_ary->klass(); 5253 ciKlass* other_klass = other_ary->klass(); 5254 bool this_xk = this_ary->klass_is_exact(); 5255 bool other_xk = other_ary->klass_is_exact(); 5256 PTR this_ptr = this_ary->ptr(); 5257 PTR other_ptr = other_ary->ptr(); 5258 res_klass = nullptr; 5259 MeetResult result = SUBTYPE; 5260 if (elem->isa_int()) { 5261 // Integral array element types have irrelevant lattice relations. 5262 // It is the klass that determines array layout, not the element type. 5263 if (this_top_or_bottom) 5264 res_klass = other_klass; 5265 else if (other_top_or_bottom || other_klass == this_klass) { 5266 res_klass = this_klass; 5267 } else { 5268 // Something like byte[int+] meets char[int+]. 5269 // This must fall to bottom, not (int[-128..65535])[int+]. 5270 // instance_id = InstanceBot; 5271 elem = Type::BOTTOM; 5272 result = NOT_SUBTYPE; 5273 if (above_centerline(ptr) || ptr == Constant) { 5274 ptr = NotNull; 5275 res_xk = false; 5276 return NOT_SUBTYPE; 5277 } 5278 } 5279 } else {// Non integral arrays. 5280 // Must fall to bottom if exact klasses in upper lattice 5281 // are not equal or super klass is exact. 5282 if ((above_centerline(ptr) || ptr == Constant) && !this_ary->is_same_java_type_as(other_ary) && 5283 // meet with top[] and bottom[] are processed further down: 5284 !this_top_or_bottom && !other_top_or_bottom && 5285 // both are exact and not equal: 5286 ((other_xk && this_xk) || 5287 // 'tap' is exact and super or unrelated: 5288 (other_xk && !other_ary->is_meet_subtype_of(this_ary)) || 5289 // 'this' is exact and super or unrelated: 5290 (this_xk && !this_ary->is_meet_subtype_of(other_ary)))) { 5291 if (above_centerline(ptr) || (elem->make_ptr() && above_centerline(elem->make_ptr()->_ptr))) { 5292 elem = Type::BOTTOM; 5293 } 5294 ptr = NotNull; 5295 res_xk = false; 5296 return NOT_SUBTYPE; 5297 } 5298 } 5299 5300 res_xk = false; 5301 switch (other_ptr) { 5302 case AnyNull: 5303 case TopPTR: 5304 // Compute new klass on demand, do not use tap->_klass 5305 if (below_centerline(this_ptr)) { 5306 res_xk = this_xk; 5307 } else { 5308 res_xk = (other_xk || this_xk); 5309 } 5310 return result; 5311 case Constant: { 5312 if (this_ptr == Constant) { 5313 res_xk = true; 5314 } else if(above_centerline(this_ptr)) { 5315 res_xk = true; 5316 } else { 5317 // Only precise for identical arrays 5318 res_xk = this_xk && (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom)); 5319 } 5320 return result; 5321 } 5322 case NotNull: 5323 case BotPTR: 5324 // Compute new klass on demand, do not use tap->_klass 5325 if (above_centerline(this_ptr)) { 5326 res_xk = other_xk; 5327 } else { 5328 res_xk = (other_xk && this_xk) && 5329 (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom)); // Only precise for identical arrays 5330 } 5331 return result; 5332 default: { 5333 ShouldNotReachHere(); 5334 return result; 5335 } 5336 } 5337 return result; 5338 } 5339 5340 5341 //------------------------------xdual------------------------------------------ 5342 // Dual: compute field-by-field dual 5343 const Type *TypeAryPtr::xdual() const { 5344 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()); 5345 } 5346 5347 //------------------------------dump2------------------------------------------ 5348 #ifndef PRODUCT 5349 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const { 5350 _ary->dump2(d,depth,st); 5351 _interfaces->dump(st); 5352 5353 switch( _ptr ) { 5354 case Constant: 5355 st->print(" " INTPTR_FORMAT " ", p2i(const_oop())); 5356 const_oop()->print(st); 5357 break; 5358 case BotPTR: 5359 if (!WizardMode && !Verbose) { 5360 if( _klass_is_exact ) st->print(":exact"); 5361 break; 5362 } 5363 case TopPTR: 5364 case AnyNull: 5365 case NotNull: 5366 st->print(":%s", ptr_msg[_ptr]); 5367 if( _klass_is_exact ) st->print(":exact"); 5368 break; 5369 default: 5370 break; 5371 } 5372 5373 if( _offset != 0 ) { 5374 BasicType basic_elem_type = elem()->basic_type(); 5375 int header_size = arrayOopDesc::base_offset_in_bytes(basic_elem_type); 5376 if( _offset == OffsetTop ) st->print("+undefined"); 5377 else if( _offset == OffsetBot ) st->print("+any"); 5378 else if( _offset < header_size ) st->print("+%d", _offset); 5379 else { 5380 if (basic_elem_type == T_ILLEGAL) { 5381 st->print("+any"); 5382 } else { 5383 int elem_size = type2aelembytes(basic_elem_type); 5384 st->print("[%d]", (_offset - header_size)/elem_size); 5385 } 5386 } 5387 } 5388 st->print(" *"); 5389 if (_instance_id == InstanceTop) 5390 st->print(",iid=top"); 5391 else if (_instance_id != InstanceBot) 5392 st->print(",iid=%d",_instance_id); 5393 5394 dump_inline_depth(st); 5395 dump_speculative(st); 5396 } 5397 #endif 5398 5399 bool TypeAryPtr::empty(void) const { 5400 if (_ary->empty()) return true; 5401 return TypeOopPtr::empty(); 5402 } 5403 5404 //------------------------------add_offset------------------------------------- 5405 const TypePtr* TypeAryPtr::add_offset(intptr_t offset) const { 5406 return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth); 5407 } 5408 5409 const TypeAryPtr* TypeAryPtr::with_offset(intptr_t offset) const { 5410 return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, offset, _instance_id, with_offset_speculative(offset), _inline_depth); 5411 } 5412 5413 const TypeAryPtr* TypeAryPtr::with_ary(const TypeAry* ary) const { 5414 return make(_ptr, _const_oop, ary, _klass, _klass_is_exact, _offset, _instance_id, _speculative, _inline_depth); 5415 } 5416 5417 const TypeAryPtr* TypeAryPtr::remove_speculative() const { 5418 if (_speculative == nullptr) { 5419 return this; 5420 } 5421 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth"); 5422 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, nullptr, _inline_depth); 5423 } 5424 5425 const TypePtr* TypeAryPtr::with_inline_depth(int depth) const { 5426 if (!UseInlineDepthForSpeculativeTypes) { 5427 return this; 5428 } 5429 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, _speculative, depth); 5430 } 5431 5432 const TypePtr* TypeAryPtr::with_instance_id(int instance_id) const { 5433 assert(is_known_instance(), "should be known"); 5434 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, instance_id, _speculative, _inline_depth); 5435 } 5436 5437 //============================================================================= 5438 5439 //------------------------------hash------------------------------------------- 5440 // Type-specific hashing function. 5441 uint TypeNarrowPtr::hash(void) const { 5442 return _ptrtype->hash() + 7; 5443 } 5444 5445 bool TypeNarrowPtr::singleton(void) const { // TRUE if type is a singleton 5446 return _ptrtype->singleton(); 5447 } 5448 5449 bool TypeNarrowPtr::empty(void) const { 5450 return _ptrtype->empty(); 5451 } 5452 5453 intptr_t TypeNarrowPtr::get_con() const { 5454 return _ptrtype->get_con(); 5455 } 5456 5457 bool TypeNarrowPtr::eq( const Type *t ) const { 5458 const TypeNarrowPtr* tc = isa_same_narrowptr(t); 5459 if (tc != nullptr) { 5460 if (_ptrtype->base() != tc->_ptrtype->base()) { 5461 return false; 5462 } 5463 return tc->_ptrtype->eq(_ptrtype); 5464 } 5465 return false; 5466 } 5467 5468 const Type *TypeNarrowPtr::xdual() const { // Compute dual right now. 5469 const TypePtr* odual = _ptrtype->dual()->is_ptr(); 5470 return make_same_narrowptr(odual); 5471 } 5472 5473 5474 const Type *TypeNarrowPtr::filter_helper(const Type *kills, bool include_speculative) const { 5475 if (isa_same_narrowptr(kills)) { 5476 const Type* ft =_ptrtype->filter_helper(is_same_narrowptr(kills)->_ptrtype, include_speculative); 5477 if (ft->empty()) 5478 return Type::TOP; // Canonical empty value 5479 if (ft->isa_ptr()) { 5480 return make_hash_same_narrowptr(ft->isa_ptr()); 5481 } 5482 return ft; 5483 } else if (kills->isa_ptr()) { 5484 const Type* ft = _ptrtype->join_helper(kills, include_speculative); 5485 if (ft->empty()) 5486 return Type::TOP; // Canonical empty value 5487 return ft; 5488 } else { 5489 return Type::TOP; 5490 } 5491 } 5492 5493 //------------------------------xmeet------------------------------------------ 5494 // Compute the MEET of two types. It returns a new Type object. 5495 const Type *TypeNarrowPtr::xmeet( const Type *t ) const { 5496 // Perform a fast test for common case; meeting the same types together. 5497 if( this == t ) return this; // Meeting same type-rep? 5498 5499 if (t->base() == base()) { 5500 const Type* result = _ptrtype->xmeet(t->make_ptr()); 5501 if (result->isa_ptr()) { 5502 return make_hash_same_narrowptr(result->is_ptr()); 5503 } 5504 return result; 5505 } 5506 5507 // Current "this->_base" is NarrowKlass or NarrowOop 5508 switch (t->base()) { // switch on original type 5509 5510 case Int: // Mixing ints & oops happens when javac 5511 case Long: // reuses local variables 5512 case HalfFloatTop: 5513 case HalfFloatCon: 5514 case HalfFloatBot: 5515 case FloatTop: 5516 case FloatCon: 5517 case FloatBot: 5518 case DoubleTop: 5519 case DoubleCon: 5520 case DoubleBot: 5521 case AnyPtr: 5522 case RawPtr: 5523 case OopPtr: 5524 case InstPtr: 5525 case AryPtr: 5526 case MetadataPtr: 5527 case KlassPtr: 5528 case InstKlassPtr: 5529 case AryKlassPtr: 5530 case NarrowOop: 5531 case NarrowKlass: 5532 5533 case Bottom: // Ye Olde Default 5534 return Type::BOTTOM; 5535 case Top: 5536 return this; 5537 5538 default: // All else is a mistake 5539 typerr(t); 5540 5541 } // End of switch 5542 5543 return this; 5544 } 5545 5546 #ifndef PRODUCT 5547 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const { 5548 _ptrtype->dump2(d, depth, st); 5549 } 5550 #endif 5551 5552 const TypeNarrowOop *TypeNarrowOop::BOTTOM; 5553 const TypeNarrowOop *TypeNarrowOop::NULL_PTR; 5554 5555 5556 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) { 5557 return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons(); 5558 } 5559 5560 const TypeNarrowOop* TypeNarrowOop::remove_speculative() const { 5561 return make(_ptrtype->remove_speculative()->is_ptr()); 5562 } 5563 5564 const Type* TypeNarrowOop::cleanup_speculative() const { 5565 return make(_ptrtype->cleanup_speculative()->is_ptr()); 5566 } 5567 5568 #ifndef PRODUCT 5569 void TypeNarrowOop::dump2( Dict & d, uint depth, outputStream *st ) const { 5570 st->print("narrowoop: "); 5571 TypeNarrowPtr::dump2(d, depth, st); 5572 } 5573 #endif 5574 5575 const TypeNarrowKlass *TypeNarrowKlass::NULL_PTR; 5576 5577 const TypeNarrowKlass* TypeNarrowKlass::make(const TypePtr* type) { 5578 return (const TypeNarrowKlass*)(new TypeNarrowKlass(type))->hashcons(); 5579 } 5580 5581 #ifndef PRODUCT 5582 void TypeNarrowKlass::dump2( Dict & d, uint depth, outputStream *st ) const { 5583 st->print("narrowklass: "); 5584 TypeNarrowPtr::dump2(d, depth, st); 5585 } 5586 #endif 5587 5588 5589 //------------------------------eq--------------------------------------------- 5590 // Structural equality check for Type representations 5591 bool TypeMetadataPtr::eq( const Type *t ) const { 5592 const TypeMetadataPtr *a = (const TypeMetadataPtr*)t; 5593 ciMetadata* one = metadata(); 5594 ciMetadata* two = a->metadata(); 5595 if (one == nullptr || two == nullptr) { 5596 return (one == two) && TypePtr::eq(t); 5597 } else { 5598 return one->equals(two) && TypePtr::eq(t); 5599 } 5600 } 5601 5602 //------------------------------hash------------------------------------------- 5603 // Type-specific hashing function. 5604 uint TypeMetadataPtr::hash(void) const { 5605 return 5606 (metadata() ? metadata()->hash() : 0) + 5607 TypePtr::hash(); 5608 } 5609 5610 //------------------------------singleton-------------------------------------- 5611 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 5612 // constants 5613 bool TypeMetadataPtr::singleton(void) const { 5614 // detune optimizer to not generate constant metadata + constant offset as a constant! 5615 // TopPTR, Null, AnyNull, Constant are all singletons 5616 return (_offset == 0) && !below_centerline(_ptr); 5617 } 5618 5619 //------------------------------add_offset------------------------------------- 5620 const TypePtr* TypeMetadataPtr::add_offset( intptr_t offset ) const { 5621 return make( _ptr, _metadata, xadd_offset(offset)); 5622 } 5623 5624 //-----------------------------filter------------------------------------------ 5625 // Do not allow interface-vs.-noninterface joins to collapse to top. 5626 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const { 5627 const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr(); 5628 if (ft == nullptr || ft->empty()) 5629 return Type::TOP; // Canonical empty value 5630 return ft; 5631 } 5632 5633 //------------------------------get_con---------------------------------------- 5634 intptr_t TypeMetadataPtr::get_con() const { 5635 assert( _ptr == Null || _ptr == Constant, "" ); 5636 assert( _offset >= 0, "" ); 5637 5638 if (_offset != 0) { 5639 // After being ported to the compiler interface, the compiler no longer 5640 // directly manipulates the addresses of oops. Rather, it only has a pointer 5641 // to a handle at compile time. This handle is embedded in the generated 5642 // code and dereferenced at the time the nmethod is made. Until that time, 5643 // it is not reasonable to do arithmetic with the addresses of oops (we don't 5644 // have access to the addresses!). This does not seem to currently happen, 5645 // but this assertion here is to help prevent its occurrence. 5646 tty->print_cr("Found oop constant with non-zero offset"); 5647 ShouldNotReachHere(); 5648 } 5649 5650 return (intptr_t)metadata()->constant_encoding(); 5651 } 5652 5653 //------------------------------cast_to_ptr_type------------------------------- 5654 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const { 5655 if( ptr == _ptr ) return this; 5656 return make(ptr, metadata(), _offset); 5657 } 5658 5659 //------------------------------meet------------------------------------------- 5660 // Compute the MEET of two types. It returns a new Type object. 5661 const Type *TypeMetadataPtr::xmeet( const Type *t ) const { 5662 // Perform a fast test for common case; meeting the same types together. 5663 if( this == t ) return this; // Meeting same type-rep? 5664 5665 // Current "this->_base" is OopPtr 5666 switch (t->base()) { // switch on original type 5667 5668 case Int: // Mixing ints & oops happens when javac 5669 case Long: // reuses local variables 5670 case HalfFloatTop: 5671 case HalfFloatCon: 5672 case HalfFloatBot: 5673 case FloatTop: 5674 case FloatCon: 5675 case FloatBot: 5676 case DoubleTop: 5677 case DoubleCon: 5678 case DoubleBot: 5679 case NarrowOop: 5680 case NarrowKlass: 5681 case Bottom: // Ye Olde Default 5682 return Type::BOTTOM; 5683 case Top: 5684 return this; 5685 5686 default: // All else is a mistake 5687 typerr(t); 5688 5689 case AnyPtr: { 5690 // Found an AnyPtr type vs self-OopPtr type 5691 const TypePtr *tp = t->is_ptr(); 5692 int offset = meet_offset(tp->offset()); 5693 PTR ptr = meet_ptr(tp->ptr()); 5694 switch (tp->ptr()) { 5695 case Null: 5696 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth()); 5697 // else fall through: 5698 case TopPTR: 5699 case AnyNull: { 5700 return make(ptr, _metadata, offset); 5701 } 5702 case BotPTR: 5703 case NotNull: 5704 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth()); 5705 default: typerr(t); 5706 } 5707 } 5708 5709 case RawPtr: 5710 case KlassPtr: 5711 case InstKlassPtr: 5712 case AryKlassPtr: 5713 case OopPtr: 5714 case InstPtr: 5715 case AryPtr: 5716 return TypePtr::BOTTOM; // Oop meet raw is not well defined 5717 5718 case MetadataPtr: { 5719 const TypeMetadataPtr *tp = t->is_metadataptr(); 5720 int offset = meet_offset(tp->offset()); 5721 PTR tptr = tp->ptr(); 5722 PTR ptr = meet_ptr(tptr); 5723 ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata(); 5724 if (tptr == TopPTR || _ptr == TopPTR || 5725 metadata()->equals(tp->metadata())) { 5726 return make(ptr, md, offset); 5727 } 5728 // metadata is different 5729 if( ptr == Constant ) { // Cannot be equal constants, so... 5730 if( tptr == Constant && _ptr != Constant) return t; 5731 if( _ptr == Constant && tptr != Constant) return this; 5732 ptr = NotNull; // Fall down in lattice 5733 } 5734 return make(ptr, nullptr, offset); 5735 break; 5736 } 5737 } // End of switch 5738 return this; // Return the double constant 5739 } 5740 5741 5742 //------------------------------xdual------------------------------------------ 5743 // Dual of a pure metadata pointer. 5744 const Type *TypeMetadataPtr::xdual() const { 5745 return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset()); 5746 } 5747 5748 //------------------------------dump2------------------------------------------ 5749 #ifndef PRODUCT 5750 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const { 5751 st->print("metadataptr:%s", ptr_msg[_ptr]); 5752 if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata())); 5753 switch( _offset ) { 5754 case OffsetTop: st->print("+top"); break; 5755 case OffsetBot: st->print("+any"); break; 5756 case 0: break; 5757 default: st->print("+%d",_offset); break; 5758 } 5759 } 5760 #endif 5761 5762 5763 //============================================================================= 5764 // Convenience common pre-built type. 5765 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM; 5766 5767 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset): 5768 TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) { 5769 } 5770 5771 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) { 5772 return make(Constant, m, 0); 5773 } 5774 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) { 5775 return make(Constant, m, 0); 5776 } 5777 5778 //------------------------------make------------------------------------------- 5779 // Create a meta data constant 5780 const TypeMetadataPtr *TypeMetadataPtr::make(PTR ptr, ciMetadata* m, int offset) { 5781 assert(m == nullptr || !m->is_klass(), "wrong type"); 5782 return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons(); 5783 } 5784 5785 5786 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const { 5787 const Type* elem = _ary->_elem; 5788 bool xk = klass_is_exact(); 5789 if (elem->make_oopptr() != nullptr) { 5790 elem = elem->make_oopptr()->as_klass_type(try_for_exact); 5791 if (elem->is_klassptr()->klass_is_exact()) { 5792 xk = true; 5793 } 5794 } 5795 return TypeAryKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, elem, klass(), 0); 5796 } 5797 5798 const TypeKlassPtr* TypeKlassPtr::make(ciKlass *klass, InterfaceHandling interface_handling) { 5799 if (klass->is_instance_klass()) { 5800 return TypeInstKlassPtr::make(klass, interface_handling); 5801 } 5802 return TypeAryKlassPtr::make(klass, interface_handling); 5803 } 5804 5805 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* klass, int offset, InterfaceHandling interface_handling) { 5806 if (klass->is_instance_klass()) { 5807 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling); 5808 return TypeInstKlassPtr::make(ptr, klass, interfaces, offset); 5809 } 5810 return TypeAryKlassPtr::make(ptr, klass, offset, interface_handling); 5811 } 5812 5813 5814 //------------------------------TypeKlassPtr----------------------------------- 5815 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, int offset) 5816 : TypePtr(t, ptr, offset), _klass(klass), _interfaces(interfaces) { 5817 assert(klass == nullptr || !klass->is_loaded() || (klass->is_instance_klass() && !klass->is_interface()) || 5818 klass->is_type_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "no interface here"); 5819 } 5820 5821 // Is there a single ciKlass* that can represent that type? 5822 ciKlass* TypeKlassPtr::exact_klass_helper() const { 5823 assert(_klass->is_instance_klass() && !_klass->is_interface(), "No interface"); 5824 if (_interfaces->empty()) { 5825 return _klass; 5826 } 5827 if (_klass != ciEnv::current()->Object_klass()) { 5828 if (_interfaces->eq(_klass->as_instance_klass())) { 5829 return _klass; 5830 } 5831 return nullptr; 5832 } 5833 return _interfaces->exact_klass(); 5834 } 5835 5836 //------------------------------eq--------------------------------------------- 5837 // Structural equality check for Type representations 5838 bool TypeKlassPtr::eq(const Type *t) const { 5839 const TypeKlassPtr *p = t->is_klassptr(); 5840 return 5841 _interfaces->eq(p->_interfaces) && 5842 TypePtr::eq(p); 5843 } 5844 5845 //------------------------------hash------------------------------------------- 5846 // Type-specific hashing function. 5847 uint TypeKlassPtr::hash(void) const { 5848 return TypePtr::hash() + _interfaces->hash(); 5849 } 5850 5851 //------------------------------singleton-------------------------------------- 5852 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 5853 // constants 5854 bool TypeKlassPtr::singleton(void) const { 5855 // detune optimizer to not generate constant klass + constant offset as a constant! 5856 // TopPTR, Null, AnyNull, Constant are all singletons 5857 return (_offset == 0) && !below_centerline(_ptr); 5858 } 5859 5860 // Do not allow interface-vs.-noninterface joins to collapse to top. 5861 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const { 5862 // logic here mirrors the one from TypeOopPtr::filter. See comments 5863 // there. 5864 const Type* ft = join_helper(kills, include_speculative); 5865 5866 if (ft->empty()) { 5867 return Type::TOP; // Canonical empty value 5868 } 5869 5870 return ft; 5871 } 5872 5873 const TypeInterfaces* TypeKlassPtr::meet_interfaces(const TypeKlassPtr* other) const { 5874 if (above_centerline(_ptr) && above_centerline(other->_ptr)) { 5875 return _interfaces->union_with(other->_interfaces); 5876 } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) { 5877 return other->_interfaces; 5878 } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) { 5879 return _interfaces; 5880 } 5881 return _interfaces->intersection_with(other->_interfaces); 5882 } 5883 5884 //------------------------------get_con---------------------------------------- 5885 intptr_t TypeKlassPtr::get_con() const { 5886 assert( _ptr == Null || _ptr == Constant, "" ); 5887 assert( _offset >= 0, "" ); 5888 5889 if (_offset != 0) { 5890 // After being ported to the compiler interface, the compiler no longer 5891 // directly manipulates the addresses of oops. Rather, it only has a pointer 5892 // to a handle at compile time. This handle is embedded in the generated 5893 // code and dereferenced at the time the nmethod is made. Until that time, 5894 // it is not reasonable to do arithmetic with the addresses of oops (we don't 5895 // have access to the addresses!). This does not seem to currently happen, 5896 // but this assertion here is to help prevent its occurrence. 5897 tty->print_cr("Found oop constant with non-zero offset"); 5898 ShouldNotReachHere(); 5899 } 5900 5901 ciKlass* k = exact_klass(); 5902 5903 return (intptr_t)k->constant_encoding(); 5904 } 5905 5906 //------------------------------dump2------------------------------------------ 5907 // Dump Klass Type 5908 #ifndef PRODUCT 5909 void TypeKlassPtr::dump2(Dict & d, uint depth, outputStream *st) const { 5910 switch(_ptr) { 5911 case Constant: 5912 st->print("precise "); 5913 case NotNull: 5914 { 5915 const char *name = klass()->name()->as_utf8(); 5916 if (name) { 5917 st->print("%s: " INTPTR_FORMAT, name, p2i(klass())); 5918 } else { 5919 ShouldNotReachHere(); 5920 } 5921 _interfaces->dump(st); 5922 } 5923 case BotPTR: 5924 if (!WizardMode && !Verbose && _ptr != Constant) break; 5925 case TopPTR: 5926 case AnyNull: 5927 st->print(":%s", ptr_msg[_ptr]); 5928 if (_ptr == Constant) st->print(":exact"); 5929 break; 5930 default: 5931 break; 5932 } 5933 5934 if (_offset) { // Dump offset, if any 5935 if (_offset == OffsetBot) { st->print("+any"); } 5936 else if (_offset == OffsetTop) { st->print("+unknown"); } 5937 else { st->print("+%d", _offset); } 5938 } 5939 5940 st->print(" *"); 5941 } 5942 #endif 5943 5944 //============================================================================= 5945 // Convenience common pre-built types. 5946 5947 // Not-null object klass or below 5948 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT; 5949 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL; 5950 5951 bool TypeInstKlassPtr::eq(const Type *t) const { 5952 const TypeKlassPtr *p = t->is_klassptr(); 5953 return 5954 klass()->equals(p->klass()) && 5955 TypeKlassPtr::eq(p); 5956 } 5957 5958 uint TypeInstKlassPtr::hash(void) const { 5959 return klass()->hash() + TypeKlassPtr::hash(); 5960 } 5961 5962 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, int offset) { 5963 TypeInstKlassPtr *r = 5964 (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, interfaces, offset))->hashcons(); 5965 5966 return r; 5967 } 5968 5969 //------------------------------add_offset------------------------------------- 5970 // Access internals of klass object 5971 const TypePtr* TypeInstKlassPtr::add_offset( intptr_t offset ) const { 5972 return make( _ptr, klass(), _interfaces, xadd_offset(offset) ); 5973 } 5974 5975 const TypeInstKlassPtr* TypeInstKlassPtr::with_offset(intptr_t offset) const { 5976 return make(_ptr, klass(), _interfaces, offset); 5977 } 5978 5979 //------------------------------cast_to_ptr_type------------------------------- 5980 const TypeInstKlassPtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const { 5981 assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type"); 5982 if( ptr == _ptr ) return this; 5983 return make(ptr, _klass, _interfaces, _offset); 5984 } 5985 5986 5987 bool TypeInstKlassPtr::must_be_exact() const { 5988 if (!_klass->is_loaded()) return false; 5989 ciInstanceKlass* ik = _klass->as_instance_klass(); 5990 if (ik->is_final()) return true; // cannot clear xk 5991 return false; 5992 } 5993 5994 //-----------------------------cast_to_exactness------------------------------- 5995 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const { 5996 if (klass_is_exact == (_ptr == Constant)) return this; 5997 if (must_be_exact()) return this; 5998 ciKlass* k = klass(); 5999 return make(klass_is_exact ? Constant : NotNull, k, _interfaces, _offset); 6000 } 6001 6002 6003 //-----------------------------as_instance_type-------------------------------- 6004 // Corresponding type for an instance of the given class. 6005 // It will be NotNull, and exact if and only if the klass type is exact. 6006 const TypeOopPtr* TypeInstKlassPtr::as_instance_type(bool klass_change) const { 6007 ciKlass* k = klass(); 6008 bool xk = klass_is_exact(); 6009 Compile* C = Compile::current(); 6010 Dependencies* deps = C->dependencies(); 6011 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity"); 6012 // Element is an instance 6013 bool klass_is_exact = false; 6014 const TypeInterfaces* interfaces = _interfaces; 6015 if (k->is_loaded()) { 6016 // Try to set klass_is_exact. 6017 ciInstanceKlass* ik = k->as_instance_klass(); 6018 klass_is_exact = ik->is_final(); 6019 if (!klass_is_exact && klass_change 6020 && deps != nullptr && UseUniqueSubclasses) { 6021 ciInstanceKlass* sub = ik->unique_concrete_subklass(); 6022 if (sub != nullptr) { 6023 if (_interfaces->eq(sub)) { 6024 deps->assert_abstract_with_unique_concrete_subtype(ik, sub); 6025 k = ik = sub; 6026 xk = sub->is_final(); 6027 } 6028 } 6029 } 6030 } 6031 return TypeInstPtr::make(TypePtr::BotPTR, k, interfaces, xk, nullptr, 0); 6032 } 6033 6034 //------------------------------xmeet------------------------------------------ 6035 // Compute the MEET of two types, return a new Type object. 6036 const Type *TypeInstKlassPtr::xmeet( const Type *t ) const { 6037 // Perform a fast test for common case; meeting the same types together. 6038 if( this == t ) return this; // Meeting same type-rep? 6039 6040 // Current "this->_base" is Pointer 6041 switch (t->base()) { // switch on original type 6042 6043 case Int: // Mixing ints & oops happens when javac 6044 case Long: // reuses local variables 6045 case HalfFloatTop: 6046 case HalfFloatCon: 6047 case HalfFloatBot: 6048 case FloatTop: 6049 case FloatCon: 6050 case FloatBot: 6051 case DoubleTop: 6052 case DoubleCon: 6053 case DoubleBot: 6054 case NarrowOop: 6055 case NarrowKlass: 6056 case Bottom: // Ye Olde Default 6057 return Type::BOTTOM; 6058 case Top: 6059 return this; 6060 6061 default: // All else is a mistake 6062 typerr(t); 6063 6064 case AnyPtr: { // Meeting to AnyPtrs 6065 // Found an AnyPtr type vs self-KlassPtr type 6066 const TypePtr *tp = t->is_ptr(); 6067 int offset = meet_offset(tp->offset()); 6068 PTR ptr = meet_ptr(tp->ptr()); 6069 switch (tp->ptr()) { 6070 case TopPTR: 6071 return this; 6072 case Null: 6073 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth()); 6074 case AnyNull: 6075 return make( ptr, klass(), _interfaces, offset ); 6076 case BotPTR: 6077 case NotNull: 6078 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth()); 6079 default: typerr(t); 6080 } 6081 } 6082 6083 case RawPtr: 6084 case MetadataPtr: 6085 case OopPtr: 6086 case AryPtr: // Meet with AryPtr 6087 case InstPtr: // Meet with InstPtr 6088 return TypePtr::BOTTOM; 6089 6090 // 6091 // A-top } 6092 // / | \ } Tops 6093 // B-top A-any C-top } 6094 // | / | \ | } Any-nulls 6095 // B-any | C-any } 6096 // | | | 6097 // B-con A-con C-con } constants; not comparable across classes 6098 // | | | 6099 // B-not | C-not } 6100 // | \ | / | } not-nulls 6101 // B-bot A-not C-bot } 6102 // \ | / } Bottoms 6103 // A-bot } 6104 // 6105 6106 case InstKlassPtr: { // Meet two KlassPtr types 6107 const TypeInstKlassPtr *tkls = t->is_instklassptr(); 6108 int off = meet_offset(tkls->offset()); 6109 PTR ptr = meet_ptr(tkls->ptr()); 6110 const TypeInterfaces* interfaces = meet_interfaces(tkls); 6111 6112 ciKlass* res_klass = nullptr; 6113 bool res_xk = false; 6114 switch(meet_instptr(ptr, interfaces, this, tkls, res_klass, res_xk)) { 6115 case UNLOADED: 6116 ShouldNotReachHere(); 6117 case SUBTYPE: 6118 case NOT_SUBTYPE: 6119 case LCA: 6120 case QUICK: { 6121 assert(res_xk == (ptr == Constant), ""); 6122 const Type* res = make(ptr, res_klass, interfaces, off); 6123 return res; 6124 } 6125 default: 6126 ShouldNotReachHere(); 6127 } 6128 } // End of case KlassPtr 6129 case AryKlassPtr: { // All arrays inherit from Object class 6130 const TypeAryKlassPtr *tp = t->is_aryklassptr(); 6131 int offset = meet_offset(tp->offset()); 6132 PTR ptr = meet_ptr(tp->ptr()); 6133 const TypeInterfaces* interfaces = meet_interfaces(tp); 6134 const TypeInterfaces* tp_interfaces = tp->_interfaces; 6135 const TypeInterfaces* this_interfaces = _interfaces; 6136 6137 switch (ptr) { 6138 case TopPTR: 6139 case AnyNull: // Fall 'down' to dual of object klass 6140 // For instances when a subclass meets a superclass we fall 6141 // below the centerline when the superclass is exact. We need to 6142 // do the same here. 6143 if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) { 6144 return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset); 6145 } else { 6146 // cannot subclass, so the meet has to fall badly below the centerline 6147 ptr = NotNull; 6148 interfaces = _interfaces->intersection_with(tp->_interfaces); 6149 return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset); 6150 } 6151 case Constant: 6152 case NotNull: 6153 case BotPTR: // Fall down to object klass 6154 // LCA is object_klass, but if we subclass from the top we can do better 6155 if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull ) 6156 // If 'this' (InstPtr) is above the centerline and it is Object class 6157 // then we can subclass in the Java class hierarchy. 6158 // For instances when a subclass meets a superclass we fall 6159 // below the centerline when the superclass is exact. We need 6160 // to do the same here. 6161 if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) { 6162 // that is, tp's array type is a subtype of my klass 6163 return TypeAryKlassPtr::make(ptr, 6164 tp->elem(), tp->klass(), offset); 6165 } 6166 } 6167 // The other case cannot happen, since I cannot be a subtype of an array. 6168 // The meet falls down to Object class below centerline. 6169 if( ptr == Constant ) 6170 ptr = NotNull; 6171 interfaces = this_interfaces->intersection_with(tp_interfaces); 6172 return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset); 6173 default: typerr(t); 6174 } 6175 } 6176 6177 } // End of switch 6178 return this; // Return the double constant 6179 } 6180 6181 //------------------------------xdual------------------------------------------ 6182 // Dual: compute field-by-field dual 6183 const Type *TypeInstKlassPtr::xdual() const { 6184 return new TypeInstKlassPtr(dual_ptr(), klass(), _interfaces, dual_offset()); 6185 } 6186 6187 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) { 6188 static_assert(std::is_base_of<T2, T1>::value, ""); 6189 if (!this_one->is_loaded() || !other->is_loaded()) { 6190 return false; 6191 } 6192 if (!this_one->is_instance_type(other)) { 6193 return false; 6194 } 6195 6196 if (!other_exact) { 6197 return false; 6198 } 6199 6200 if (other->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces->empty()) { 6201 return true; 6202 } 6203 6204 return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces); 6205 } 6206 6207 bool TypeInstKlassPtr::might_be_an_array() const { 6208 if (!instance_klass()->is_java_lang_Object()) { 6209 // TypeInstKlassPtr can be an array only if it is java.lang.Object: the only supertype of array types. 6210 return false; 6211 } 6212 if (interfaces()->has_non_array_interface()) { 6213 // Arrays only implement Cloneable and Serializable. If we see any other interface, [this] cannot be an array. 6214 return false; 6215 } 6216 // Cannot prove it's not an array. 6217 return true; 6218 } 6219 6220 bool TypeInstKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const { 6221 return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact); 6222 } 6223 6224 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_instance(const T1* this_one, const T2* other) { 6225 static_assert(std::is_base_of<T2, T1>::value, ""); 6226 if (!this_one->is_loaded() || !other->is_loaded()) { 6227 return false; 6228 } 6229 if (!this_one->is_instance_type(other)) { 6230 return false; 6231 } 6232 return this_one->klass()->equals(other->klass()) && this_one->_interfaces->eq(other->_interfaces); 6233 } 6234 6235 bool TypeInstKlassPtr::is_same_java_type_as_helper(const TypeKlassPtr* other) const { 6236 return TypePtr::is_same_java_type_as_helper_for_instance(this, other); 6237 } 6238 6239 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) { 6240 static_assert(std::is_base_of<T2, T1>::value, ""); 6241 if (!this_one->is_loaded() || !other->is_loaded()) { 6242 return true; 6243 } 6244 6245 if (this_one->is_array_type(other)) { 6246 return !this_exact && this_one->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces->contains(this_one->_interfaces); 6247 } 6248 6249 assert(this_one->is_instance_type(other), "unsupported"); 6250 6251 if (this_exact && other_exact) { 6252 return this_one->is_java_subtype_of(other); 6253 } 6254 6255 if (!this_one->klass()->is_subtype_of(other->klass()) && !other->klass()->is_subtype_of(this_one->klass())) { 6256 return false; 6257 } 6258 6259 if (this_exact) { 6260 return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces); 6261 } 6262 6263 return true; 6264 } 6265 6266 bool TypeInstKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const { 6267 return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact); 6268 } 6269 6270 const TypeKlassPtr* TypeInstKlassPtr::try_improve() const { 6271 if (!UseUniqueSubclasses) { 6272 return this; 6273 } 6274 ciKlass* k = klass(); 6275 Compile* C = Compile::current(); 6276 Dependencies* deps = C->dependencies(); 6277 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity"); 6278 const TypeInterfaces* interfaces = _interfaces; 6279 if (k->is_loaded()) { 6280 ciInstanceKlass* ik = k->as_instance_klass(); 6281 bool klass_is_exact = ik->is_final(); 6282 if (!klass_is_exact && 6283 deps != nullptr) { 6284 ciInstanceKlass* sub = ik->unique_concrete_subklass(); 6285 if (sub != nullptr) { 6286 if (_interfaces->eq(sub)) { 6287 deps->assert_abstract_with_unique_concrete_subtype(ik, sub); 6288 k = ik = sub; 6289 klass_is_exact = sub->is_final(); 6290 return TypeKlassPtr::make(klass_is_exact ? Constant : _ptr, k, _offset); 6291 } 6292 } 6293 } 6294 } 6295 return this; 6296 } 6297 6298 6299 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, int offset) { 6300 return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset))->hashcons(); 6301 } 6302 6303 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, ciKlass* k, int offset, InterfaceHandling interface_handling) { 6304 if (k->is_obj_array_klass()) { 6305 // Element is an object array. Recursively call ourself. 6306 ciKlass* eklass = k->as_obj_array_klass()->element_klass(); 6307 const TypeKlassPtr *etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false); 6308 return TypeAryKlassPtr::make(ptr, etype, nullptr, offset); 6309 } else if (k->is_type_array_klass()) { 6310 // Element is an typeArray 6311 const Type* etype = get_const_basic_type(k->as_type_array_klass()->element_type()); 6312 return TypeAryKlassPtr::make(ptr, etype, k, offset); 6313 } else { 6314 ShouldNotReachHere(); 6315 return nullptr; 6316 } 6317 } 6318 6319 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) { 6320 return TypeAryKlassPtr::make(Constant, klass, 0, interface_handling); 6321 } 6322 6323 //------------------------------eq--------------------------------------------- 6324 // Structural equality check for Type representations 6325 bool TypeAryKlassPtr::eq(const Type *t) const { 6326 const TypeAryKlassPtr *p = t->is_aryklassptr(); 6327 return 6328 _elem == p->_elem && // Check array 6329 TypeKlassPtr::eq(p); // Check sub-parts 6330 } 6331 6332 //------------------------------hash------------------------------------------- 6333 // Type-specific hashing function. 6334 uint TypeAryKlassPtr::hash(void) const { 6335 return (uint)(uintptr_t)_elem + TypeKlassPtr::hash(); 6336 } 6337 6338 //----------------------compute_klass------------------------------------------ 6339 // Compute the defining klass for this class 6340 ciKlass* TypeAryPtr::compute_klass() const { 6341 // Compute _klass based on element type. 6342 ciKlass* k_ary = nullptr; 6343 const TypeInstPtr *tinst; 6344 const TypeAryPtr *tary; 6345 const Type* el = elem(); 6346 if (el->isa_narrowoop()) { 6347 el = el->make_ptr(); 6348 } 6349 6350 // Get element klass 6351 if ((tinst = el->isa_instptr()) != nullptr) { 6352 // Leave k_ary at null. 6353 } else if ((tary = el->isa_aryptr()) != nullptr) { 6354 // Leave k_ary at null. 6355 } else if ((el->base() == Type::Top) || 6356 (el->base() == Type::Bottom)) { 6357 // element type of Bottom occurs from meet of basic type 6358 // and object; Top occurs when doing join on Bottom. 6359 // Leave k_ary at null. 6360 } else { 6361 assert(!el->isa_int(), "integral arrays must be pre-equipped with a class"); 6362 // Compute array klass directly from basic type 6363 k_ary = ciTypeArrayKlass::make(el->basic_type()); 6364 } 6365 return k_ary; 6366 } 6367 6368 //------------------------------klass------------------------------------------ 6369 // Return the defining klass for this class 6370 ciKlass* TypeAryPtr::klass() const { 6371 if( _klass ) return _klass; // Return cached value, if possible 6372 6373 // Oops, need to compute _klass and cache it 6374 ciKlass* k_ary = compute_klass(); 6375 6376 if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) { 6377 // The _klass field acts as a cache of the underlying 6378 // ciKlass for this array type. In order to set the field, 6379 // we need to cast away const-ness. 6380 // 6381 // IMPORTANT NOTE: we *never* set the _klass field for the 6382 // type TypeAryPtr::OOPS. This Type is shared between all 6383 // active compilations. However, the ciKlass which represents 6384 // this Type is *not* shared between compilations, so caching 6385 // this value would result in fetching a dangling pointer. 6386 // 6387 // Recomputing the underlying ciKlass for each request is 6388 // a bit less efficient than caching, but calls to 6389 // TypeAryPtr::OOPS->klass() are not common enough to matter. 6390 ((TypeAryPtr*)this)->_klass = k_ary; 6391 } 6392 return k_ary; 6393 } 6394 6395 // Is there a single ciKlass* that can represent that type? 6396 ciKlass* TypeAryPtr::exact_klass_helper() const { 6397 if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) { 6398 ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper(); 6399 if (k == nullptr) { 6400 return nullptr; 6401 } 6402 k = ciObjArrayKlass::make(k); 6403 return k; 6404 } 6405 6406 return klass(); 6407 } 6408 6409 const Type* TypeAryPtr::base_element_type(int& dims) const { 6410 const Type* elem = this->elem(); 6411 dims = 1; 6412 while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) { 6413 elem = elem->make_ptr()->is_aryptr()->elem(); 6414 dims++; 6415 } 6416 return elem; 6417 } 6418 6419 //------------------------------add_offset------------------------------------- 6420 // Access internals of klass object 6421 const TypePtr* TypeAryKlassPtr::add_offset(intptr_t offset) const { 6422 return make(_ptr, elem(), klass(), xadd_offset(offset)); 6423 } 6424 6425 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const { 6426 return make(_ptr, elem(), klass(), offset); 6427 } 6428 6429 //------------------------------cast_to_ptr_type------------------------------- 6430 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const { 6431 assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type"); 6432 if (ptr == _ptr) return this; 6433 return make(ptr, elem(), _klass, _offset); 6434 } 6435 6436 bool TypeAryKlassPtr::must_be_exact() const { 6437 if (_elem == Type::BOTTOM) return false; 6438 if (_elem == Type::TOP ) return false; 6439 const TypeKlassPtr* tk = _elem->isa_klassptr(); 6440 if (!tk) return true; // a primitive type, like int 6441 return tk->must_be_exact(); 6442 } 6443 6444 6445 //-----------------------------cast_to_exactness------------------------------- 6446 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const { 6447 if (must_be_exact()) return this; // cannot clear xk 6448 ciKlass* k = _klass; 6449 const Type* elem = this->elem(); 6450 if (elem->isa_klassptr() && !klass_is_exact) { 6451 elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact); 6452 } 6453 return make(klass_is_exact ? Constant : NotNull, elem, k, _offset); 6454 } 6455 6456 6457 //-----------------------------as_instance_type-------------------------------- 6458 // Corresponding type for an instance of the given class. 6459 // It will be NotNull, and exact if and only if the klass type is exact. 6460 const TypeOopPtr* TypeAryKlassPtr::as_instance_type(bool klass_change) const { 6461 ciKlass* k = klass(); 6462 bool xk = klass_is_exact(); 6463 const Type* el = nullptr; 6464 if (elem()->isa_klassptr()) { 6465 el = elem()->is_klassptr()->as_instance_type(false)->cast_to_exactness(false); 6466 k = nullptr; 6467 } else { 6468 el = elem(); 6469 } 6470 return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS), k, xk, 0); 6471 } 6472 6473 6474 //------------------------------xmeet------------------------------------------ 6475 // Compute the MEET of two types, return a new Type object. 6476 const Type *TypeAryKlassPtr::xmeet( const Type *t ) const { 6477 // Perform a fast test for common case; meeting the same types together. 6478 if( this == t ) return this; // Meeting same type-rep? 6479 6480 // Current "this->_base" is Pointer 6481 switch (t->base()) { // switch on original type 6482 6483 case Int: // Mixing ints & oops happens when javac 6484 case Long: // reuses local variables 6485 case HalfFloatTop: 6486 case HalfFloatCon: 6487 case HalfFloatBot: 6488 case FloatTop: 6489 case FloatCon: 6490 case FloatBot: 6491 case DoubleTop: 6492 case DoubleCon: 6493 case DoubleBot: 6494 case NarrowOop: 6495 case NarrowKlass: 6496 case Bottom: // Ye Olde Default 6497 return Type::BOTTOM; 6498 case Top: 6499 return this; 6500 6501 default: // All else is a mistake 6502 typerr(t); 6503 6504 case AnyPtr: { // Meeting to AnyPtrs 6505 // Found an AnyPtr type vs self-KlassPtr type 6506 const TypePtr *tp = t->is_ptr(); 6507 int offset = meet_offset(tp->offset()); 6508 PTR ptr = meet_ptr(tp->ptr()); 6509 switch (tp->ptr()) { 6510 case TopPTR: 6511 return this; 6512 case Null: 6513 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth()); 6514 case AnyNull: 6515 return make( ptr, _elem, klass(), offset ); 6516 case BotPTR: 6517 case NotNull: 6518 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth()); 6519 default: typerr(t); 6520 } 6521 } 6522 6523 case RawPtr: 6524 case MetadataPtr: 6525 case OopPtr: 6526 case AryPtr: // Meet with AryPtr 6527 case InstPtr: // Meet with InstPtr 6528 return TypePtr::BOTTOM; 6529 6530 // 6531 // A-top } 6532 // / | \ } Tops 6533 // B-top A-any C-top } 6534 // | / | \ | } Any-nulls 6535 // B-any | C-any } 6536 // | | | 6537 // B-con A-con C-con } constants; not comparable across classes 6538 // | | | 6539 // B-not | C-not } 6540 // | \ | / | } not-nulls 6541 // B-bot A-not C-bot } 6542 // \ | / } Bottoms 6543 // A-bot } 6544 // 6545 6546 case AryKlassPtr: { // Meet two KlassPtr types 6547 const TypeAryKlassPtr *tap = t->is_aryklassptr(); 6548 int off = meet_offset(tap->offset()); 6549 const Type* elem = _elem->meet(tap->_elem); 6550 6551 PTR ptr = meet_ptr(tap->ptr()); 6552 ciKlass* res_klass = nullptr; 6553 bool res_xk = false; 6554 meet_aryptr(ptr, elem, this, tap, res_klass, res_xk); 6555 assert(res_xk == (ptr == Constant), ""); 6556 return make(ptr, elem, res_klass, off); 6557 } // End of case KlassPtr 6558 case InstKlassPtr: { 6559 const TypeInstKlassPtr *tp = t->is_instklassptr(); 6560 int offset = meet_offset(tp->offset()); 6561 PTR ptr = meet_ptr(tp->ptr()); 6562 const TypeInterfaces* interfaces = meet_interfaces(tp); 6563 const TypeInterfaces* tp_interfaces = tp->_interfaces; 6564 const TypeInterfaces* this_interfaces = _interfaces; 6565 6566 switch (ptr) { 6567 case TopPTR: 6568 case AnyNull: // Fall 'down' to dual of object klass 6569 // For instances when a subclass meets a superclass we fall 6570 // below the centerline when the superclass is exact. We need to 6571 // do the same here. 6572 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && 6573 !tp->klass_is_exact()) { 6574 return TypeAryKlassPtr::make(ptr, _elem, _klass, offset); 6575 } else { 6576 // cannot subclass, so the meet has to fall badly below the centerline 6577 ptr = NotNull; 6578 interfaces = this_interfaces->intersection_with(tp->_interfaces); 6579 return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset); 6580 } 6581 case Constant: 6582 case NotNull: 6583 case BotPTR: // Fall down to object klass 6584 // LCA is object_klass, but if we subclass from the top we can do better 6585 if (above_centerline(tp->ptr())) { 6586 // If 'tp' is above the centerline and it is Object class 6587 // then we can subclass in the Java class hierarchy. 6588 // For instances when a subclass meets a superclass we fall 6589 // below the centerline when the superclass is exact. We need 6590 // to do the same here. 6591 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && 6592 !tp->klass_is_exact()) { 6593 // that is, my array type is a subtype of 'tp' klass 6594 return make(ptr, _elem, _klass, offset); 6595 } 6596 } 6597 // The other case cannot happen, since t cannot be a subtype of an array. 6598 // The meet falls down to Object class below centerline. 6599 if (ptr == Constant) 6600 ptr = NotNull; 6601 interfaces = this_interfaces->intersection_with(tp_interfaces); 6602 return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset); 6603 default: typerr(t); 6604 } 6605 } 6606 6607 } // End of switch 6608 return this; // Return the double constant 6609 } 6610 6611 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) { 6612 static_assert(std::is_base_of<T2, T1>::value, ""); 6613 6614 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) { 6615 return true; 6616 } 6617 6618 int dummy; 6619 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM); 6620 6621 if (!this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) { 6622 return false; 6623 } 6624 6625 if (this_one->is_instance_type(other)) { 6626 return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces) && 6627 other_exact; 6628 } 6629 6630 assert(this_one->is_array_type(other), ""); 6631 const T1* other_ary = this_one->is_array_type(other); 6632 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM); 6633 if (other_top_or_bottom) { 6634 return false; 6635 } 6636 6637 const TypePtr* other_elem = other_ary->elem()->make_ptr(); 6638 const TypePtr* this_elem = this_one->elem()->make_ptr(); 6639 if (this_elem != nullptr && other_elem != nullptr) { 6640 return this_one->is_reference_type(this_elem)->is_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact); 6641 } 6642 if (this_elem == nullptr && other_elem == nullptr) { 6643 return this_one->klass()->is_subtype_of(other->klass()); 6644 } 6645 return false; 6646 } 6647 6648 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const { 6649 return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact); 6650 } 6651 6652 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other) { 6653 static_assert(std::is_base_of<T2, T1>::value, ""); 6654 6655 int dummy; 6656 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM); 6657 6658 if (!this_one->is_array_type(other) || 6659 !this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) { 6660 return false; 6661 } 6662 const T1* other_ary = this_one->is_array_type(other); 6663 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM); 6664 6665 if (other_top_or_bottom) { 6666 return false; 6667 } 6668 6669 const TypePtr* other_elem = other_ary->elem()->make_ptr(); 6670 const TypePtr* this_elem = this_one->elem()->make_ptr(); 6671 if (other_elem != nullptr && this_elem != nullptr) { 6672 return this_one->is_reference_type(this_elem)->is_same_java_type_as(this_one->is_reference_type(other_elem)); 6673 } 6674 if (other_elem == nullptr && this_elem == nullptr) { 6675 return this_one->klass()->equals(other->klass()); 6676 } 6677 return false; 6678 } 6679 6680 bool TypeAryKlassPtr::is_same_java_type_as_helper(const TypeKlassPtr* other) const { 6681 return TypePtr::is_same_java_type_as_helper_for_array(this, other); 6682 } 6683 6684 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) { 6685 static_assert(std::is_base_of<T2, T1>::value, ""); 6686 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) { 6687 return true; 6688 } 6689 if (!this_one->is_loaded() || !other->is_loaded()) { 6690 return true; 6691 } 6692 if (this_one->is_instance_type(other)) { 6693 return other->klass()->equals(ciEnv::current()->Object_klass()) && 6694 this_one->_interfaces->contains(other->_interfaces); 6695 } 6696 6697 int dummy; 6698 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM); 6699 if (this_top_or_bottom) { 6700 return true; 6701 } 6702 6703 assert(this_one->is_array_type(other), ""); 6704 6705 const T1* other_ary = this_one->is_array_type(other); 6706 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM); 6707 if (other_top_or_bottom) { 6708 return true; 6709 } 6710 if (this_exact && other_exact) { 6711 return this_one->is_java_subtype_of(other); 6712 } 6713 6714 const TypePtr* this_elem = this_one->elem()->make_ptr(); 6715 const TypePtr* other_elem = other_ary->elem()->make_ptr(); 6716 if (other_elem != nullptr && this_elem != nullptr) { 6717 return this_one->is_reference_type(this_elem)->maybe_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact); 6718 } 6719 if (other_elem == nullptr && this_elem == nullptr) { 6720 return this_one->klass()->is_subtype_of(other->klass()); 6721 } 6722 return false; 6723 } 6724 6725 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const { 6726 return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact); 6727 } 6728 6729 //------------------------------xdual------------------------------------------ 6730 // Dual: compute field-by-field dual 6731 const Type *TypeAryKlassPtr::xdual() const { 6732 return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset()); 6733 } 6734 6735 // Is there a single ciKlass* that can represent that type? 6736 ciKlass* TypeAryKlassPtr::exact_klass_helper() const { 6737 if (elem()->isa_klassptr()) { 6738 ciKlass* k = elem()->is_klassptr()->exact_klass_helper(); 6739 if (k == nullptr) { 6740 return nullptr; 6741 } 6742 k = ciObjArrayKlass::make(k); 6743 return k; 6744 } 6745 6746 return klass(); 6747 } 6748 6749 ciKlass* TypeAryKlassPtr::klass() const { 6750 if (_klass != nullptr) { 6751 return _klass; 6752 } 6753 ciKlass* k = nullptr; 6754 if (elem()->isa_klassptr()) { 6755 // leave null 6756 } else if ((elem()->base() == Type::Top) || 6757 (elem()->base() == Type::Bottom)) { 6758 } else { 6759 k = ciTypeArrayKlass::make(elem()->basic_type()); 6760 ((TypeAryKlassPtr*)this)->_klass = k; 6761 } 6762 return k; 6763 } 6764 6765 //------------------------------dump2------------------------------------------ 6766 // Dump Klass Type 6767 #ifndef PRODUCT 6768 void TypeAryKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const { 6769 switch( _ptr ) { 6770 case Constant: 6771 st->print("precise "); 6772 case NotNull: 6773 { 6774 st->print("["); 6775 _elem->dump2(d, depth, st); 6776 _interfaces->dump(st); 6777 st->print(": "); 6778 } 6779 case BotPTR: 6780 if( !WizardMode && !Verbose && _ptr != Constant ) break; 6781 case TopPTR: 6782 case AnyNull: 6783 st->print(":%s", ptr_msg[_ptr]); 6784 if( _ptr == Constant ) st->print(":exact"); 6785 break; 6786 default: 6787 break; 6788 } 6789 6790 if( _offset ) { // Dump offset, if any 6791 if( _offset == OffsetBot ) { st->print("+any"); } 6792 else if( _offset == OffsetTop ) { st->print("+unknown"); } 6793 else { st->print("+%d", _offset); } 6794 } 6795 6796 st->print(" *"); 6797 } 6798 #endif 6799 6800 const Type* TypeAryKlassPtr::base_element_type(int& dims) const { 6801 const Type* elem = this->elem(); 6802 dims = 1; 6803 while (elem->isa_aryklassptr()) { 6804 elem = elem->is_aryklassptr()->elem(); 6805 dims++; 6806 } 6807 return elem; 6808 } 6809 6810 //============================================================================= 6811 // Convenience common pre-built types. 6812 6813 //------------------------------make------------------------------------------- 6814 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) { 6815 return (TypeFunc*)(new TypeFunc(domain,range))->hashcons(); 6816 } 6817 6818 //------------------------------make------------------------------------------- 6819 const TypeFunc *TypeFunc::make(ciMethod* method) { 6820 Compile* C = Compile::current(); 6821 const TypeFunc* tf = C->last_tf(method); // check cache 6822 if (tf != nullptr) return tf; // The hit rate here is almost 50%. 6823 const TypeTuple *domain; 6824 if (method->is_static()) { 6825 domain = TypeTuple::make_domain(nullptr, method->signature(), ignore_interfaces); 6826 } else { 6827 domain = TypeTuple::make_domain(method->holder(), method->signature(), ignore_interfaces); 6828 } 6829 const TypeTuple *range = TypeTuple::make_range(method->signature(), ignore_interfaces); 6830 tf = TypeFunc::make(domain, range); 6831 C->set_last_tf(method, tf); // fill cache 6832 return tf; 6833 } 6834 6835 //------------------------------meet------------------------------------------- 6836 // Compute the MEET of two types. It returns a new Type object. 6837 const Type *TypeFunc::xmeet( const Type *t ) const { 6838 // Perform a fast test for common case; meeting the same types together. 6839 if( this == t ) return this; // Meeting same type-rep? 6840 6841 // Current "this->_base" is Func 6842 switch (t->base()) { // switch on original type 6843 6844 case Bottom: // Ye Olde Default 6845 return t; 6846 6847 default: // All else is a mistake 6848 typerr(t); 6849 6850 case Top: 6851 break; 6852 } 6853 return this; // Return the double constant 6854 } 6855 6856 //------------------------------xdual------------------------------------------ 6857 // Dual: compute field-by-field dual 6858 const Type *TypeFunc::xdual() const { 6859 return this; 6860 } 6861 6862 //------------------------------eq--------------------------------------------- 6863 // Structural equality check for Type representations 6864 bool TypeFunc::eq( const Type *t ) const { 6865 const TypeFunc *a = (const TypeFunc*)t; 6866 return _domain == a->_domain && 6867 _range == a->_range; 6868 } 6869 6870 //------------------------------hash------------------------------------------- 6871 // Type-specific hashing function. 6872 uint TypeFunc::hash(void) const { 6873 return (uint)(uintptr_t)_domain + (uint)(uintptr_t)_range; 6874 } 6875 6876 //------------------------------dump2------------------------------------------ 6877 // Dump Function Type 6878 #ifndef PRODUCT 6879 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const { 6880 if( _range->cnt() <= Parms ) 6881 st->print("void"); 6882 else { 6883 uint i; 6884 for (i = Parms; i < _range->cnt()-1; i++) { 6885 _range->field_at(i)->dump2(d,depth,st); 6886 st->print("/"); 6887 } 6888 _range->field_at(i)->dump2(d,depth,st); 6889 } 6890 st->print(" "); 6891 st->print("( "); 6892 if( !depth || d[this] ) { // Check for recursive dump 6893 st->print("...)"); 6894 return; 6895 } 6896 d.Insert((void*)this,(void*)this); // Stop recursion 6897 if (Parms < _domain->cnt()) 6898 _domain->field_at(Parms)->dump2(d,depth-1,st); 6899 for (uint i = Parms+1; i < _domain->cnt(); i++) { 6900 st->print(", "); 6901 _domain->field_at(i)->dump2(d,depth-1,st); 6902 } 6903 st->print(" )"); 6904 } 6905 #endif 6906 6907 //------------------------------singleton-------------------------------------- 6908 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 6909 // constants (Ldi nodes). Singletons are integer, float or double constants 6910 // or a single symbol. 6911 bool TypeFunc::singleton(void) const { 6912 return false; // Never a singleton 6913 } 6914 6915 bool TypeFunc::empty(void) const { 6916 return false; // Never empty 6917 } 6918 6919 6920 BasicType TypeFunc::return_type() const{ 6921 if (range()->cnt() == TypeFunc::Parms) { 6922 return T_VOID; 6923 } 6924 return range()->field_at(TypeFunc::Parms)->basic_type(); 6925 }