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