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