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