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