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