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