1 /*
   2  * Copyright (c) 1997, 2026, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "ci/ciField.hpp"
  26 #include "ci/ciFlatArray.hpp"
  27 #include "ci/ciFlatArrayKlass.hpp"
  28 #include "ci/ciInlineKlass.hpp"
  29 #include "ci/ciMethodData.hpp"
  30 #include "ci/ciObjArrayKlass.hpp"
  31 #include "ci/ciTypeFlow.hpp"
  32 #include "classfile/javaClasses.hpp"
  33 #include "classfile/symbolTable.hpp"
  34 #include "classfile/vmSymbols.hpp"
  35 #include "compiler/compileLog.hpp"
  36 #include "libadt/dict.hpp"
  37 #include "memory/oopFactory.hpp"
  38 #include "memory/resourceArea.hpp"
  39 #include "oops/instanceKlass.hpp"
  40 #include "oops/instanceMirrorKlass.hpp"
  41 #include "oops/objArrayKlass.hpp"
  42 #include "oops/typeArrayKlass.hpp"
  43 #include "opto/arraycopynode.hpp"
  44 #include "opto/callnode.hpp"
  45 #include "opto/matcher.hpp"
  46 #include "opto/node.hpp"
  47 #include "opto/opcodes.hpp"
  48 #include "opto/rangeinference.hpp"
  49 #include "opto/runtime.hpp"
  50 #include "opto/type.hpp"
  51 #include "runtime/globals.hpp"
  52 #include "runtime/stubRoutines.hpp"
  53 #include "utilities/checkedCast.hpp"
  54 #include "utilities/debug.hpp"
  55 #include "utilities/globalDefinitions.hpp"
  56 #include "utilities/ostream.hpp"
  57 #include "utilities/powerOfTwo.hpp"
  58 #include "utilities/stringUtils.hpp"
  59 #if INCLUDE_SHENANDOAHGC
  60 #include "gc/shenandoah/c2/shenandoahBarrierSetC2.hpp"
  61 #endif // INCLUDE_SHENANDOAHGC
  62 
  63 // Portions of code courtesy of Clifford Click
  64 
  65 // Optimization - Graph Style
  66 
  67 // Dictionary of types shared among compilations.
  68 Dict* Type::_shared_type_dict = nullptr;
  69 const Type::Offset Type::Offset::top(Type::OffsetTop);
  70 const Type::Offset Type::Offset::bottom(Type::OffsetBot);
  71 
  72 const Type::Offset Type::Offset::meet(const Type::Offset other) const {
  73   // Either is 'TOP' offset?  Return the other offset!
  74   if (_offset == OffsetTop) return other;
  75   if (other._offset == OffsetTop) return *this;
  76   // If either is different, return 'BOTTOM' offset
  77   if (_offset != other._offset) return bottom;
  78   return Offset(_offset);
  79 }
  80 
  81 const Type::Offset Type::Offset::dual() const {
  82   if (_offset == OffsetTop) return bottom;// Map 'TOP' into 'BOTTOM'
  83   if (_offset == OffsetBot) return top;// Map 'BOTTOM' into 'TOP'
  84   return Offset(_offset);               // Map everything else into self
  85 }
  86 
  87 const Type::Offset Type::Offset::add(intptr_t offset) const {
  88   // Adding to 'TOP' offset?  Return 'TOP'!
  89   if (_offset == OffsetTop || offset == OffsetTop) return top;
  90   // Adding to 'BOTTOM' offset?  Return 'BOTTOM'!
  91   if (_offset == OffsetBot || offset == OffsetBot) return bottom;
  92   // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
  93   offset += (intptr_t)_offset;
  94   if (offset != (int)offset || offset == OffsetTop) return bottom;
  95 
  96   // assert( _offset >= 0 && _offset+offset >= 0, "" );
  97   // It is possible to construct a negative offset during PhaseCCP
  98 
  99   return Offset((int)offset);        // Sum valid offsets
 100 }
 101 
 102 void Type::Offset::dump2(outputStream *st) const {
 103   if (_offset == 0) {
 104     return;
 105   } else if (_offset == OffsetTop) {
 106     st->print("+top");
 107   } else if (_offset == OffsetBot) {
 108     st->print("+bot");
 109   } else {
 110     st->print("+%d", _offset);
 111   }
 112 }
 113 
 114 // Array which maps compiler types to Basic Types
 115 const Type::TypeInfo Type::_type_info[Type::lastype] = {
 116   { Bad,             T_ILLEGAL,    "bad",           false, Node::NotAMachineReg, relocInfo::none          },  // Bad
 117   { Control,         T_ILLEGAL,    "control",       false, 0,                    relocInfo::none          },  // Control
 118   { Bottom,          T_VOID,       "top",           false, 0,                    relocInfo::none          },  // Top
 119   { Bad,             T_INT,        "int:",          false, Op_RegI,              relocInfo::none          },  // Int
 120   { Bad,             T_LONG,       "long:",         false, Op_RegL,              relocInfo::none          },  // Long
 121   { Half,            T_VOID,       "half",          false, 0,                    relocInfo::none          },  // Half
 122   { Bad,             T_NARROWOOP,  "narrowoop:",    false, Op_RegN,              relocInfo::none          },  // NarrowOop
 123   { Bad,             T_NARROWKLASS,"narrowklass:",  false, Op_RegN,              relocInfo::none          },  // NarrowKlass
 124   { Bad,             T_ILLEGAL,    "tuple:",        false, Node::NotAMachineReg, relocInfo::none          },  // Tuple
 125   { Bad,             T_ARRAY,      "array:",        false, Node::NotAMachineReg, relocInfo::none          },  // Array
 126   { Bad,             T_ARRAY,      "interfaces:",   false, Node::NotAMachineReg, relocInfo::none          },  // Interfaces
 127 
 128 #if defined(PPC64)
 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 #elif defined(S390)
 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, 0,                    relocInfo::none          },  // VectorS
 140   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_RegL,              relocInfo::none          },  // VectorD
 141   { Bad,             T_ILLEGAL,    "vectorx:",      false, Op_VecX,              relocInfo::none          },  // VectorX
 142   { Bad,             T_ILLEGAL,    "vectory:",      false, 0,                    relocInfo::none          },  // VectorY
 143   { Bad,             T_ILLEGAL,    "vectorz:",      false, 0,                    relocInfo::none          },  // VectorZ
 144 #else // all other
 145   { Bad,             T_ILLEGAL,    "vectormask:",   false, Op_RegVectMask,       relocInfo::none          },  // VectorMask.
 146   { Bad,             T_ILLEGAL,    "vectora:",      false, Op_VecA,              relocInfo::none          },  // VectorA.
 147   { Bad,             T_ILLEGAL,    "vectors:",      false, Op_VecS,              relocInfo::none          },  // VectorS
 148   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_VecD,              relocInfo::none          },  // VectorD
 149   { Bad,             T_ILLEGAL,    "vectorx:",      false, Op_VecX,              relocInfo::none          },  // VectorX
 150   { Bad,             T_ILLEGAL,    "vectory:",      false, Op_VecY,              relocInfo::none          },  // VectorY
 151   { Bad,             T_ILLEGAL,    "vectorz:",      false, Op_VecZ,              relocInfo::none          },  // VectorZ
 152 #endif
 153   { Bad,             T_ADDRESS,    "anyptr:",       false, Op_RegP,              relocInfo::none          },  // AnyPtr
 154   { Bad,             T_ADDRESS,    "rawptr:",       false, Op_RegP,              relocInfo::external_word_type },  // RawPtr
 155   { Bad,             T_OBJECT,     "oop:",          true,  Op_RegP,              relocInfo::oop_type      },  // OopPtr
 156   { Bad,             T_OBJECT,     "inst:",         true,  Op_RegP,              relocInfo::oop_type      },  // InstPtr
 157   { Bad,             T_OBJECT,     "ary:",          true,  Op_RegP,              relocInfo::oop_type      },  // AryPtr
 158   { Bad,             T_METADATA,   "metadata:",     false, Op_RegP,              relocInfo::metadata_type },  // MetadataPtr
 159   { Bad,             T_METADATA,   "klass:",        false, Op_RegP,              relocInfo::metadata_type },  // KlassPtr
 160   { Bad,             T_METADATA,   "instklass:",    false, Op_RegP,              relocInfo::metadata_type },  // InstKlassPtr
 161   { Bad,             T_METADATA,   "aryklass:",     false, Op_RegP,              relocInfo::metadata_type },  // AryKlassPtr
 162   { Bad,             T_OBJECT,     "func",          false, 0,                    relocInfo::none          },  // Function
 163   { Abio,            T_ILLEGAL,    "abIO",          false, 0,                    relocInfo::none          },  // Abio
 164   { Return_Address,  T_ADDRESS,    "return_address",false, Op_RegP,              relocInfo::none          },  // Return_Address
 165   { Memory,          T_ILLEGAL,    "memory",        false, 0,                    relocInfo::none          },  // Memory
 166   { HalfFloatBot,    T_SHORT,      "halffloat_top", false, Op_RegF,              relocInfo::none          },  // HalfFloatTop
 167   { HalfFloatCon,    T_SHORT,      "hfcon:",        false, Op_RegF,              relocInfo::none          },  // HalfFloatCon
 168   { HalfFloatTop,    T_SHORT,      "short",         false, Op_RegF,              relocInfo::none          },  // HalfFloatBot
 169   { FloatBot,        T_FLOAT,      "float_top",     false, Op_RegF,              relocInfo::none          },  // FloatTop
 170   { FloatCon,        T_FLOAT,      "ftcon:",        false, Op_RegF,              relocInfo::none          },  // FloatCon
 171   { FloatTop,        T_FLOAT,      "float",         false, Op_RegF,              relocInfo::none          },  // FloatBot
 172   { DoubleBot,       T_DOUBLE,     "double_top",    false, Op_RegD,              relocInfo::none          },  // DoubleTop
 173   { DoubleCon,       T_DOUBLE,     "dblcon:",       false, Op_RegD,              relocInfo::none          },  // DoubleCon
 174   { DoubleTop,       T_DOUBLE,     "double",        false, Op_RegD,              relocInfo::none          },  // DoubleBot
 175   { Top,             T_ILLEGAL,    "bottom",        false, 0,                    relocInfo::none          }   // Bottom
 176 };
 177 
 178 // Map ideal registers (machine types) to ideal types
 179 const Type *Type::mreg2type[_last_machine_leaf];
 180 
 181 // Map basic types to canonical Type* pointers.
 182 const Type* Type::     _const_basic_type[T_CONFLICT+1];
 183 
 184 // Map basic types to constant-zero Types.
 185 const Type* Type::            _zero_type[T_CONFLICT+1];
 186 
 187 // Map basic types to array-body alias types.
 188 const TypeAryPtr* TypeAryPtr::_array_body_type[T_CONFLICT+1];
 189 const TypeInterfaces* TypeAryPtr::_array_interfaces = nullptr;
 190 const TypeInterfaces* TypeAryKlassPtr::_array_interfaces = nullptr;
 191 
 192 //=============================================================================
 193 // Convenience common pre-built types.
 194 const Type *Type::ABIO;         // State-of-machine only
 195 const Type *Type::BOTTOM;       // All values
 196 const Type *Type::CONTROL;      // Control only
 197 const Type *Type::DOUBLE;       // All doubles
 198 const Type *Type::HALF_FLOAT;   // All half floats
 199 const Type *Type::FLOAT;        // All floats
 200 const Type *Type::HALF;         // Placeholder half of doublewide type
 201 const Type *Type::MEMORY;       // Abstract store only
 202 const Type *Type::RETURN_ADDRESS;
 203 const Type *Type::TOP;          // No values in set
 204 
 205 //------------------------------get_const_type---------------------------
 206 const Type* Type::get_const_type(ciType* type, InterfaceHandling interface_handling) {
 207   if (type == nullptr) {
 208     return nullptr;
 209   } else if (type->is_primitive_type()) {
 210     return get_const_basic_type(type->basic_type());
 211   } else {
 212     return TypeOopPtr::make_from_klass(type->as_klass(), interface_handling);
 213   }
 214 }
 215 
 216 //---------------------------array_element_basic_type---------------------------------
 217 // Mapping to the array element's basic type.
 218 BasicType Type::array_element_basic_type() const {
 219   BasicType bt = basic_type();
 220   if (bt == T_INT) {
 221     if (this == TypeInt::INT)   return T_INT;
 222     if (this == TypeInt::CHAR)  return T_CHAR;
 223     if (this == TypeInt::BYTE)  return T_BYTE;
 224     if (this == TypeInt::BOOL)  return T_BOOLEAN;
 225     if (this == TypeInt::SHORT) return T_SHORT;
 226     return T_VOID;
 227   }
 228   return bt;
 229 }
 230 
 231 // For two instance arrays of same dimension, return the base element types.
 232 // Otherwise or if the arrays have different dimensions, return null.
 233 void Type::get_arrays_base_elements(const Type *a1, const Type *a2,
 234                                     const TypeInstPtr **e1, const TypeInstPtr **e2) {
 235 
 236   if (e1) *e1 = nullptr;
 237   if (e2) *e2 = nullptr;
 238   const TypeAryPtr* a1tap = (a1 == nullptr) ? nullptr : a1->isa_aryptr();
 239   const TypeAryPtr* a2tap = (a2 == nullptr) ? nullptr : a2->isa_aryptr();
 240 
 241   if (a1tap != nullptr && a2tap != nullptr) {
 242     // Handle multidimensional arrays
 243     const TypePtr* a1tp = a1tap->elem()->make_ptr();
 244     const TypePtr* a2tp = a2tap->elem()->make_ptr();
 245     while (a1tp && a1tp->isa_aryptr() && a2tp && a2tp->isa_aryptr()) {
 246       a1tap = a1tp->is_aryptr();
 247       a2tap = a2tp->is_aryptr();
 248       a1tp = a1tap->elem()->make_ptr();
 249       a2tp = a2tap->elem()->make_ptr();
 250     }
 251     if (a1tp && a1tp->isa_instptr() && a2tp && a2tp->isa_instptr()) {
 252       if (e1) *e1 = a1tp->is_instptr();
 253       if (e2) *e2 = a2tp->is_instptr();
 254     }
 255   }
 256 }
 257 
 258 //---------------------------get_typeflow_type---------------------------------
 259 // Import a type produced by ciTypeFlow.
 260 const Type* Type::get_typeflow_type(ciType* type) {
 261   switch (type->basic_type()) {
 262 
 263   case ciTypeFlow::StateVector::T_BOTTOM:
 264     assert(type == ciTypeFlow::StateVector::bottom_type(), "");
 265     return Type::BOTTOM;
 266 
 267   case ciTypeFlow::StateVector::T_TOP:
 268     assert(type == ciTypeFlow::StateVector::top_type(), "");
 269     return Type::TOP;
 270 
 271   case ciTypeFlow::StateVector::T_NULL:
 272     assert(type == ciTypeFlow::StateVector::null_type(), "");
 273     return TypePtr::NULL_PTR;
 274 
 275   case ciTypeFlow::StateVector::T_LONG2:
 276     // The ciTypeFlow pass pushes a long, then the half.
 277     // We do the same.
 278     assert(type == ciTypeFlow::StateVector::long2_type(), "");
 279     return TypeInt::TOP;
 280 
 281   case ciTypeFlow::StateVector::T_DOUBLE2:
 282     // The ciTypeFlow pass pushes double, then the half.
 283     // Our convention is the same.
 284     assert(type == ciTypeFlow::StateVector::double2_type(), "");
 285     return Type::TOP;
 286 
 287   case T_ADDRESS:
 288     assert(type->is_return_address(), "");
 289     return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci());
 290 
 291   case T_OBJECT:
 292     return Type::get_const_type(type->unwrap())->join_speculative(type->is_null_free() ? TypePtr::NOTNULL : TypePtr::BOTTOM);
 293 
 294   default:
 295     // make sure we did not mix up the cases:
 296     assert(type != ciTypeFlow::StateVector::bottom_type(), "");
 297     assert(type != ciTypeFlow::StateVector::top_type(), "");
 298     assert(type != ciTypeFlow::StateVector::null_type(), "");
 299     assert(type != ciTypeFlow::StateVector::long2_type(), "");
 300     assert(type != ciTypeFlow::StateVector::double2_type(), "");
 301     assert(!type->is_return_address(), "");
 302 
 303     return Type::get_const_type(type);
 304   }
 305 }
 306 
 307 
 308 //-----------------------make_from_constant------------------------------------
 309 const Type* Type::make_from_constant(ciConstant constant, bool require_constant,
 310                                      int stable_dimension, bool is_narrow_oop,
 311                                      bool is_autobox_cache) {
 312   switch (constant.basic_type()) {
 313     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
 314     case T_CHAR:     return TypeInt::make(constant.as_char());
 315     case T_BYTE:     return TypeInt::make(constant.as_byte());
 316     case T_SHORT:    return TypeInt::make(constant.as_short());
 317     case T_INT:      return TypeInt::make(constant.as_int());
 318     case T_LONG:     return TypeLong::make(constant.as_long());
 319     case T_FLOAT:    return TypeF::make(constant.as_float());
 320     case T_DOUBLE:   return TypeD::make(constant.as_double());
 321     case T_ARRAY:
 322     case T_OBJECT: {
 323         const Type* con_type = nullptr;
 324         ciObject* oop_constant = constant.as_object();
 325         if (oop_constant->is_null_object()) {
 326           con_type = Type::get_zero_type(T_OBJECT);
 327         } else {
 328           guarantee(require_constant || oop_constant->should_be_constant(), "con_type must get computed");
 329           con_type = TypeOopPtr::make_from_constant(oop_constant, require_constant);
 330           if (Compile::current()->eliminate_boxing() && is_autobox_cache) {
 331             con_type = con_type->is_aryptr()->cast_to_autobox_cache();
 332           }
 333           if (stable_dimension > 0) {
 334             assert(FoldStableValues, "sanity");
 335             assert(!con_type->is_zero_type(), "default value for stable field");
 336             con_type = con_type->is_aryptr()->cast_to_stable(true, stable_dimension);
 337           }
 338         }
 339         if (is_narrow_oop) {
 340           con_type = con_type->make_narrowoop();
 341         }
 342         return con_type;
 343       }
 344     case T_ILLEGAL:
 345       // Invalid ciConstant returned due to OutOfMemoryError in the CI
 346       assert(Compile::current()->env()->failing(), "otherwise should not see this");
 347       return nullptr;
 348     default:
 349       // Fall through to failure
 350       return nullptr;
 351   }
 352 }
 353 
 354 static ciConstant check_mismatched_access(ciConstant con, BasicType loadbt, bool is_unsigned) {
 355   BasicType conbt = con.basic_type();
 356   switch (conbt) {
 357     case T_BOOLEAN: conbt = T_BYTE;   break;
 358     case T_ARRAY:   conbt = T_OBJECT; break;
 359     default:                          break;
 360   }
 361   switch (loadbt) {
 362     case T_BOOLEAN:   loadbt = T_BYTE;   break;
 363     case T_NARROWOOP: loadbt = T_OBJECT; break;
 364     case T_ARRAY:     loadbt = T_OBJECT; break;
 365     case T_ADDRESS:   loadbt = T_OBJECT; break;
 366     default:                             break;
 367   }
 368   if (conbt == loadbt) {
 369     if (is_unsigned && conbt == T_BYTE) {
 370       // LoadB (T_BYTE) with a small mask (<=8-bit) is converted to LoadUB (T_BYTE).
 371       return ciConstant(T_INT, con.as_int() & 0xFF);
 372     } else {
 373       return con;
 374     }
 375   }
 376   if (conbt == T_SHORT && loadbt == T_CHAR) {
 377     // LoadS (T_SHORT) with a small mask (<=16-bit) is converted to LoadUS (T_CHAR).
 378     return ciConstant(T_INT, con.as_int() & 0xFFFF);
 379   }
 380   return ciConstant(); // T_ILLEGAL
 381 }
 382 
 383 static const Type* make_constant_from_non_flat_array_element(ciArray* array, int off, int stable_dimension,

 384                                                    BasicType loadbt, bool is_unsigned_load) {
 385   // Decode the results of GraphKit::array_element_address.
 386   ciConstant element_value = array->element_value_by_offset(off);
 387   if (element_value.basic_type() == T_ILLEGAL) {
 388     return nullptr; // wrong offset
 389   }
 390   ciConstant con = check_mismatched_access(element_value, loadbt, is_unsigned_load);
 391 
 392   assert(con.basic_type() != T_ILLEGAL, "elembt=%s; loadbt=%s; unsigned=%d",
 393          type2name(element_value.basic_type()), type2name(loadbt), is_unsigned_load);
 394 
 395   if (con.is_valid() &&          // not a mismatched access
 396       !con.is_null_or_zero()) {  // not a default value
 397     bool is_narrow_oop = (loadbt == T_NARROWOOP);
 398     return Type::make_from_constant(con, /*require_constant=*/true, stable_dimension, is_narrow_oop, /*is_autobox_cache=*/false);
 399   }
 400   return nullptr;
 401 }
 402 
 403 static const Type* make_constant_from_flat_array_element(ciFlatArray* array, int off, int field_offset, int stable_dimension,
 404                                                          BasicType loadbt, bool is_unsigned_load) {
 405   if (!array->is_null_free()) {
 406     ciConstant nm_value = array->null_marker_of_element_by_offset(off);
 407     if (!nm_value.is_valid() || !nm_value.as_boolean()) {
 408       return nullptr;
 409     }
 410   }
 411   ciConstant element_value = array->field_value_by_offset(off + field_offset);
 412   if (element_value.basic_type() == T_ILLEGAL) {
 413     return nullptr; // wrong offset
 414   }
 415   ciConstant con = check_mismatched_access(element_value, loadbt, is_unsigned_load);
 416 
 417   assert(con.basic_type() != T_ILLEGAL, "elembt=%s; loadbt=%s; unsigned=%d",
 418          type2name(element_value.basic_type()), type2name(loadbt), is_unsigned_load);
 419 
 420   if (con.is_valid()) { // not a mismatched access
 421     bool is_narrow_oop = (loadbt == T_NARROWOOP);
 422     return Type::make_from_constant(con, /*require_constant=*/true, stable_dimension, is_narrow_oop, /*is_autobox_cache=*/false);
 423   }
 424   return nullptr;
 425 }
 426 
 427 // Try to constant-fold a stable array element.
 428 const Type* Type::make_constant_from_array_element(ciArray* array, int off, int field_offset, int stable_dimension,
 429                                                    BasicType loadbt, bool is_unsigned_load) {
 430   if (array->is_flat()) {
 431     return make_constant_from_flat_array_element(array->as_flat_array(), off, field_offset, stable_dimension, loadbt, is_unsigned_load);
 432   }
 433   return make_constant_from_non_flat_array_element(array, off, stable_dimension, loadbt, is_unsigned_load);
 434 }
 435 
 436 const Type* Type::make_constant_from_field(ciInstance* holder, int off, bool is_unsigned_load, BasicType loadbt) {
 437   ciField* field;
 438   ciType* type = holder->java_mirror_type();
 439   if (type != nullptr && type->is_instance_klass() && off >= InstanceMirrorKlass::offset_of_static_fields()) {
 440     // Static field
 441     field = type->as_instance_klass()->get_field_by_offset(off, /*is_static=*/true);
 442   } else {
 443     // Instance field
 444     field = holder->klass()->as_instance_klass()->get_field_by_offset(off, /*is_static=*/false);
 445   }
 446   if (field == nullptr) {
 447     return nullptr; // Wrong offset
 448   }
 449   return Type::make_constant_from_field(field, holder, loadbt, is_unsigned_load);
 450 }
 451 
 452 const Type* Type::make_constant_from_field(ciField* field, ciInstance* holder,
 453                                            BasicType loadbt, bool is_unsigned_load) {
 454   if (!field->is_constant()) {
 455     return nullptr; // Non-constant field
 456   }
 457   ciConstant field_value;
 458   if (field->is_static()) {
 459     // final static field
 460     field_value = field->constant_value();
 461   } else if (holder != nullptr) {
 462     // final or stable non-static field
 463     // Treat final non-static fields of trusted classes (classes in
 464     // java.lang.invoke and sun.invoke packages and subpackages) as
 465     // compile time constants.
 466     field_value = field->constant_value_of(holder);
 467   }
 468   if (!field_value.is_valid()) {
 469     return nullptr; // Not a constant
 470   }
 471 
 472   ciConstant con = check_mismatched_access(field_value, loadbt, is_unsigned_load);
 473 
 474   assert(con.is_valid(), "elembt=%s; loadbt=%s; unsigned=%d",
 475          type2name(field_value.basic_type()), type2name(loadbt), is_unsigned_load);
 476 
 477   bool is_stable_array = FoldStableValues && field->is_stable() && field->type()->is_array_klass();
 478   int stable_dimension = (is_stable_array ? field->type()->as_array_klass()->dimension() : 0);
 479   bool is_narrow_oop = (loadbt == T_NARROWOOP);
 480 
 481   const Type* con_type = make_from_constant(con, /*require_constant=*/ true,
 482                                             stable_dimension, is_narrow_oop,
 483                                             field->is_autobox_cache());
 484   if (con_type != nullptr && field->is_call_site_target()) {
 485     ciCallSite* call_site = holder->as_call_site();
 486     if (!call_site->is_fully_initialized_constant_call_site()) {
 487       ciMethodHandle* target = con.as_object()->as_method_handle();
 488       Compile::current()->dependencies()->assert_call_site_target_value(call_site, target);
 489     }
 490   }
 491   return con_type;
 492 }
 493 
 494 //------------------------------make-------------------------------------------
 495 // Create a simple Type, with default empty symbol sets.  Then hashcons it
 496 // and look for an existing copy in the type dictionary.
 497 const Type *Type::make( enum TYPES t ) {
 498   return (new Type(t))->hashcons();
 499 }
 500 
 501 //------------------------------cmp--------------------------------------------
 502 bool Type::equals(const Type* t1, const Type* t2) {
 503   if (t1->_base != t2->_base) {
 504     return false; // Missed badly
 505   }
 506 
 507   assert(t1 != t2 || t1->eq(t2), "eq must be reflexive");
 508   return t1->eq(t2);
 509 }
 510 
 511 const Type* Type::maybe_remove_speculative(bool include_speculative) const {
 512   if (!include_speculative) {
 513     return remove_speculative();
 514   }
 515   return this;
 516 }
 517 
 518 //------------------------------hash-------------------------------------------
 519 int Type::uhash( const Type *const t ) {
 520   return (int)t->hash();
 521 }
 522 
 523 #define POSITIVE_INFINITE_F 0x7f800000 // hex representation for IEEE 754 single precision positive infinite
 524 #define POSITIVE_INFINITE_D 0x7ff0000000000000 // hex representation for IEEE 754 double precision positive infinite
 525 
 526 //--------------------------Initialize_shared----------------------------------
 527 void Type::Initialize_shared(Compile* current) {
 528   // This method does not need to be locked because the first system
 529   // compilations (stub compilations) occur serially.  If they are
 530   // changed to proceed in parallel, then this section will need
 531   // locking.
 532 
 533   Arena* save = current->type_arena();
 534   Arena* shared_type_arena = new (mtCompiler)Arena(mtCompiler, Arena::Tag::tag_type);
 535 
 536   current->set_type_arena(shared_type_arena);
 537 
 538   // Map the boolean result of Type::equals into a comparator result that CmpKey expects.
 539   CmpKey type_cmp = [](const void* t1, const void* t2) -> int32_t {
 540     return Type::equals((Type*) t1, (Type*) t2) ? 0 : 1;
 541   };
 542 
 543   _shared_type_dict = new (shared_type_arena) Dict(type_cmp, (Hash) Type::uhash, shared_type_arena, 128);
 544   current->set_type_dict(_shared_type_dict);
 545 
 546   // Make shared pre-built types.
 547   CONTROL = make(Control);      // Control only
 548   TOP     = make(Top);          // No values in set
 549   MEMORY  = make(Memory);       // Abstract store only
 550   ABIO    = make(Abio);         // State-of-machine only
 551   RETURN_ADDRESS=make(Return_Address);
 552   FLOAT   = make(FloatBot);     // All floats
 553   HALF_FLOAT = make(HalfFloatBot); // All half floats
 554   DOUBLE  = make(DoubleBot);    // All doubles
 555   BOTTOM  = make(Bottom);       // Everything
 556   HALF    = make(Half);         // Placeholder half of doublewide type
 557 
 558   TypeF::MAX = TypeF::make(max_jfloat); // Float MAX
 559   TypeF::MIN = TypeF::make(min_jfloat); // Float MIN
 560   TypeF::ZERO = TypeF::make(0.0); // Float 0 (positive zero)
 561   TypeF::ONE  = TypeF::make(1.0); // Float 1
 562   TypeF::POS_INF = TypeF::make(jfloat_cast(POSITIVE_INFINITE_F));
 563   TypeF::NEG_INF = TypeF::make(-jfloat_cast(POSITIVE_INFINITE_F));
 564 
 565   TypeH::MAX = TypeH::make(max_jfloat16); // HalfFloat MAX
 566   TypeH::MIN = TypeH::make(min_jfloat16); // HalfFloat MIN
 567   TypeH::ZERO = TypeH::make((jshort)0); // HalfFloat 0 (positive zero)
 568   TypeH::ONE  = TypeH::make(one_jfloat16); // HalfFloat 1
 569   TypeH::POS_INF = TypeH::make(pos_inf_jfloat16);
 570   TypeH::NEG_INF = TypeH::make(neg_inf_jfloat16);
 571 
 572   TypeD::MAX = TypeD::make(max_jdouble); // Double MAX
 573   TypeD::MIN = TypeD::make(min_jdouble); // Double MIN
 574   TypeD::ZERO = TypeD::make(0.0); // Double 0 (positive zero)
 575   TypeD::ONE  = TypeD::make(1.0); // Double 1
 576   TypeD::POS_INF = TypeD::make(jdouble_cast(POSITIVE_INFINITE_D));
 577   TypeD::NEG_INF = TypeD::make(-jdouble_cast(POSITIVE_INFINITE_D));
 578 
 579   TypeInt::MAX = TypeInt::make(max_jint); // Int MAX
 580   TypeInt::MIN = TypeInt::make(min_jint); // Int MIN
 581   TypeInt::MINUS_1  = TypeInt::make(-1);  // -1
 582   TypeInt::ZERO     = TypeInt::make( 0);  //  0
 583   TypeInt::ONE      = TypeInt::make( 1);  //  1
 584   TypeInt::BOOL     = TypeInt::make( 0, 1, WidenMin);  // 0 or 1, FALSE or TRUE.
 585   TypeInt::CC       = TypeInt::make(-1, 1, WidenMin);  // -1, 0 or 1, condition codes
 586   TypeInt::CC_LT    = TypeInt::make(-1,-1, WidenMin);  // == TypeInt::MINUS_1
 587   TypeInt::CC_GT    = TypeInt::make( 1, 1, WidenMin);  // == TypeInt::ONE
 588   TypeInt::CC_EQ    = TypeInt::make( 0, 0, WidenMin);  // == TypeInt::ZERO
 589   TypeInt::CC_NE    = TypeInt::make_or_top(TypeIntPrototype<jint, juint>{{-1, 1}, {1, max_juint}, {0, 1}}, WidenMin)->is_int();
 590   TypeInt::CC_LE    = TypeInt::make(-1, 0, WidenMin);
 591   TypeInt::CC_GE    = TypeInt::make( 0, 1, WidenMin);  // == TypeInt::BOOL
 592   TypeInt::BYTE     = TypeInt::make(-128, 127,     WidenMin); // Bytes
 593   TypeInt::UBYTE    = TypeInt::make(0, 255,        WidenMin); // Unsigned Bytes
 594   TypeInt::CHAR     = TypeInt::make(0, 65535,      WidenMin); // Java chars
 595   TypeInt::SHORT    = TypeInt::make(-32768, 32767, WidenMin); // Java shorts
 596   TypeInt::NON_ZERO = TypeInt::make_or_top(TypeIntPrototype<jint, juint>{{min_jint, max_jint}, {1, max_juint}, {0, 0}}, WidenMin)->is_int();
 597   TypeInt::POS      = TypeInt::make(0, max_jint,   WidenMin); // Non-neg values
 598   TypeInt::POS1     = TypeInt::make(1, max_jint,   WidenMin); // Positive values
 599   TypeInt::INT      = TypeInt::make(min_jint, max_jint, WidenMax); // 32-bit integers
 600   TypeInt::SYMINT   = TypeInt::make(-max_jint, max_jint, WidenMin); // symmetric range
 601   TypeInt::TYPE_DOMAIN = TypeInt::INT;
 602   // CmpL is overloaded both as the bytecode computation returning
 603   // a trinary (-1, 0, +1) integer result AND as an efficient long
 604   // compare returning optimizer ideal-type flags.
 605   assert(TypeInt::CC_LT == TypeInt::MINUS_1, "types must match for CmpL to work" );
 606   assert(TypeInt::CC_GT == TypeInt::ONE,     "types must match for CmpL to work" );
 607   assert(TypeInt::CC_EQ == TypeInt::ZERO,    "types must match for CmpL to work" );
 608   assert(TypeInt::CC_GE == TypeInt::BOOL,    "types must match for CmpL to work" );
 609 
 610   TypeLong::MAX = TypeLong::make(max_jlong); // Long MAX
 611   TypeLong::MIN = TypeLong::make(min_jlong); // Long MIN
 612   TypeLong::MINUS_1  = TypeLong::make(-1);   // -1
 613   TypeLong::ZERO     = TypeLong::make( 0);   //  0
 614   TypeLong::ONE      = TypeLong::make( 1);   //  1
 615   TypeLong::NON_ZERO = TypeLong::make_or_top(TypeIntPrototype<jlong, julong>{{min_jlong, max_jlong}, {1, max_julong}, {0, 0}}, WidenMin)->is_long();
 616   TypeLong::POS      = TypeLong::make(0, max_jlong, WidenMin); // Non-neg values
 617   TypeLong::NEG      = TypeLong::make(min_jlong, -1, WidenMin);
 618   TypeLong::LONG     = TypeLong::make(min_jlong, max_jlong, WidenMax); // 64-bit integers
 619   TypeLong::INT      = TypeLong::make((jlong)min_jint, (jlong)max_jint,WidenMin);
 620   TypeLong::UINT     = TypeLong::make(0, (jlong)max_juint, WidenMin);
 621   TypeLong::TYPE_DOMAIN = TypeLong::LONG;
 622 
 623   const Type **fboth =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 624   fboth[0] = Type::CONTROL;
 625   fboth[1] = Type::CONTROL;
 626   TypeTuple::IFBOTH = TypeTuple::make( 2, fboth );
 627 
 628   const Type **ffalse =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 629   ffalse[0] = Type::CONTROL;
 630   ffalse[1] = Type::TOP;
 631   TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
 632 
 633   const Type **fneither =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 634   fneither[0] = Type::TOP;
 635   fneither[1] = Type::TOP;
 636   TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
 637 
 638   const Type **ftrue =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 639   ftrue[0] = Type::TOP;
 640   ftrue[1] = Type::CONTROL;
 641   TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
 642 
 643   const Type **floop =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 644   floop[0] = Type::CONTROL;
 645   floop[1] = TypeInt::INT;
 646   TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
 647 
 648   TypePtr::NULL_PTR= TypePtr::make(AnyPtr, TypePtr::Null, Offset(0));
 649   TypePtr::NOTNULL = TypePtr::make(AnyPtr, TypePtr::NotNull, Offset::bottom);
 650   TypePtr::BOTTOM  = TypePtr::make(AnyPtr, TypePtr::BotPTR, Offset::bottom);
 651 
 652   TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
 653   TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
 654 
 655   const Type **fmembar = TypeTuple::fields(0);
 656   TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
 657 
 658   const Type **fsc = (const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 659   fsc[0] = TypeInt::CC;
 660   fsc[1] = Type::MEMORY;
 661   TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
 662 
 663   TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
 664   TypeInstPtr::BOTTOM  = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass());
 665   TypeInstPtr::MIRROR  = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
 666   TypeInstPtr::MARK    = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
 667                                            false, nullptr, Offset(oopDesc::mark_offset_in_bytes()));
 668   TypeInstPtr::KLASS   = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
 669                                            false, nullptr, Offset(oopDesc::klass_offset_in_bytes()));
 670   TypeOopPtr::BOTTOM  = TypeOopPtr::make(TypePtr::BotPTR, Offset::bottom, TypeOopPtr::InstanceBot);
 671 
 672   TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, nullptr, Offset::bottom);
 673 
 674   TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
 675   TypeNarrowOop::BOTTOM   = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
 676 
 677   TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
 678 
 679   mreg2type[Op_Node] = Type::BOTTOM;
 680   mreg2type[Op_Set ] = nullptr;
 681   mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
 682   mreg2type[Op_RegI] = TypeInt::INT;
 683   mreg2type[Op_RegP] = TypePtr::BOTTOM;
 684   mreg2type[Op_RegF] = Type::FLOAT;
 685   mreg2type[Op_RegD] = Type::DOUBLE;
 686   mreg2type[Op_RegL] = TypeLong::LONG;
 687   mreg2type[Op_RegFlags] = TypeInt::CC;
 688 
 689   GrowableArray<ciInstanceKlass*> array_interfaces;
 690   array_interfaces.push(current->env()->Cloneable_klass());
 691   array_interfaces.push(current->env()->Serializable_klass());
 692   TypeAryPtr::_array_interfaces = TypeInterfaces::make(&array_interfaces);
 693   TypeAryKlassPtr::_array_interfaces = TypeAryPtr::_array_interfaces;
 694 
 695   TypeAryPtr::BOTTOM = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::BOTTOM, TypeInt::POS, false, false, false, false, false), nullptr, false, Offset::bottom);
 696   TypeAryPtr::RANGE   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS, false, false, false, false, false), nullptr /* current->env()->Object_klass() */, false, Offset(arrayOopDesc::length_offset_in_bytes()));
 697 
 698   TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS, false, false, false, false, false), nullptr /*ciArrayKlass::make(o)*/,  false,  Offset::bottom);
 699 
 700 #ifdef _LP64
 701   if (UseCompressedOops) {
 702     assert(TypeAryPtr::NARROWOOPS->is_ptr_to_narrowoop(), "array of narrow oops must be ptr to narrow oop");
 703     TypeAryPtr::OOPS  = TypeAryPtr::NARROWOOPS;
 704   } else
 705 #endif
 706   {
 707     // There is no shared klass for Object[].  See note in TypeAryPtr::klass().
 708     TypeAryPtr::OOPS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS, false, false, false, false, false), nullptr /*ciArrayKlass::make(o)*/,  false,  Offset::bottom);
 709   }
 710   TypeAryPtr::BYTES   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE      ,TypeInt::POS, false, false, true, true, true), ciTypeArrayKlass::make(T_BYTE),   true,  Offset::bottom);
 711   TypeAryPtr::SHORTS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT     ,TypeInt::POS, false, false, true, true, true), ciTypeArrayKlass::make(T_SHORT),  true,  Offset::bottom);
 712   TypeAryPtr::CHARS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR      ,TypeInt::POS, false, false, true, true, true), ciTypeArrayKlass::make(T_CHAR),   true,  Offset::bottom);
 713   TypeAryPtr::INTS    = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT       ,TypeInt::POS, false, false, true, true, true), ciTypeArrayKlass::make(T_INT),    true,  Offset::bottom);
 714   TypeAryPtr::LONGS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG     ,TypeInt::POS, false, false, true, true, true), ciTypeArrayKlass::make(T_LONG),   true,  Offset::bottom);
 715   TypeAryPtr::FLOATS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT        ,TypeInt::POS, false, false, true, true, true), ciTypeArrayKlass::make(T_FLOAT),  true,  Offset::bottom);
 716   TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE       ,TypeInt::POS, false, false, true, true, true), ciTypeArrayKlass::make(T_DOUBLE), true,  Offset::bottom);
 717   TypeAryPtr::INLINES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS, /* stable= */ false, /* flat= */ true, false, false, false), nullptr, false, Offset::bottom);
 718 
 719   // Nobody should ask _array_body_type[T_NARROWOOP]. Use null as assert.
 720   TypeAryPtr::_array_body_type[T_NARROWOOP] = nullptr;
 721   TypeAryPtr::_array_body_type[T_OBJECT]  = TypeAryPtr::OOPS;
 722   TypeAryPtr::_array_body_type[T_FLAT_ELEMENT] = TypeAryPtr::OOPS;
 723   TypeAryPtr::_array_body_type[T_ARRAY]   = TypeAryPtr::OOPS; // arrays are stored in oop arrays
 724   TypeAryPtr::_array_body_type[T_BYTE]    = TypeAryPtr::BYTES;
 725   TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES;  // boolean[] is a byte array
 726   TypeAryPtr::_array_body_type[T_SHORT]   = TypeAryPtr::SHORTS;
 727   TypeAryPtr::_array_body_type[T_CHAR]    = TypeAryPtr::CHARS;
 728   TypeAryPtr::_array_body_type[T_INT]     = TypeAryPtr::INTS;
 729   TypeAryPtr::_array_body_type[T_LONG]    = TypeAryPtr::LONGS;
 730   TypeAryPtr::_array_body_type[T_FLOAT]   = TypeAryPtr::FLOATS;
 731   TypeAryPtr::_array_body_type[T_DOUBLE]  = TypeAryPtr::DOUBLES;
 732 
 733   TypeInstKlassPtr::OBJECT = TypeInstKlassPtr::make(TypePtr::NotNull, current->env()->Object_klass(), Offset(0));
 734   TypeInstKlassPtr::OBJECT_OR_NULL = TypeInstKlassPtr::make(TypePtr::BotPTR, current->env()->Object_klass(), Offset(0));
 735 
 736   const Type **fi2c = TypeTuple::fields(2);
 737   fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // Method*
 738   fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
 739   TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
 740 
 741   const Type **intpair = TypeTuple::fields(2);
 742   intpair[0] = TypeInt::INT;
 743   intpair[1] = TypeInt::INT;
 744   TypeTuple::INT_PAIR = TypeTuple::make(2, intpair);
 745 
 746   const Type **longpair = TypeTuple::fields(2);
 747   longpair[0] = TypeLong::LONG;
 748   longpair[1] = TypeLong::LONG;
 749   TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
 750 
 751   const Type **intccpair = TypeTuple::fields(2);
 752   intccpair[0] = TypeInt::INT;
 753   intccpair[1] = TypeInt::CC;
 754   TypeTuple::INT_CC_PAIR = TypeTuple::make(2, intccpair);
 755 
 756   const Type **longccpair = TypeTuple::fields(2);
 757   longccpair[0] = TypeLong::LONG;
 758   longccpair[1] = TypeInt::CC;
 759   TypeTuple::LONG_CC_PAIR = TypeTuple::make(2, longccpair);
 760 
 761   _const_basic_type[T_NARROWOOP]   = TypeNarrowOop::BOTTOM;
 762   _const_basic_type[T_NARROWKLASS] = Type::BOTTOM;
 763   _const_basic_type[T_BOOLEAN]     = TypeInt::BOOL;
 764   _const_basic_type[T_CHAR]        = TypeInt::CHAR;
 765   _const_basic_type[T_BYTE]        = TypeInt::BYTE;
 766   _const_basic_type[T_SHORT]       = TypeInt::SHORT;
 767   _const_basic_type[T_INT]         = TypeInt::INT;
 768   _const_basic_type[T_LONG]        = TypeLong::LONG;
 769   _const_basic_type[T_FLOAT]       = Type::FLOAT;
 770   _const_basic_type[T_DOUBLE]      = Type::DOUBLE;
 771   _const_basic_type[T_OBJECT]      = TypeInstPtr::BOTTOM;
 772   _const_basic_type[T_ARRAY]       = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays
 773   _const_basic_type[T_FLAT_ELEMENT] = TypeInstPtr::BOTTOM;
 774   _const_basic_type[T_VOID]        = TypePtr::NULL_PTR;   // reflection represents void this way
 775   _const_basic_type[T_ADDRESS]     = TypeRawPtr::BOTTOM;  // both interpreter return addresses & random raw ptrs
 776   _const_basic_type[T_CONFLICT]    = Type::BOTTOM;        // why not?
 777 
 778   _zero_type[T_NARROWOOP]   = TypeNarrowOop::NULL_PTR;
 779   _zero_type[T_NARROWKLASS] = TypeNarrowKlass::NULL_PTR;
 780   _zero_type[T_BOOLEAN]     = TypeInt::ZERO;     // false == 0
 781   _zero_type[T_CHAR]        = TypeInt::ZERO;     // '\0' == 0
 782   _zero_type[T_BYTE]        = TypeInt::ZERO;     // 0x00 == 0
 783   _zero_type[T_SHORT]       = TypeInt::ZERO;     // 0x0000 == 0
 784   _zero_type[T_INT]         = TypeInt::ZERO;
 785   _zero_type[T_LONG]        = TypeLong::ZERO;
 786   _zero_type[T_FLOAT]       = TypeF::ZERO;
 787   _zero_type[T_DOUBLE]      = TypeD::ZERO;
 788   _zero_type[T_OBJECT]      = TypePtr::NULL_PTR;
 789   _zero_type[T_ARRAY]       = TypePtr::NULL_PTR; // null array is null oop
 790   _zero_type[T_FLAT_ELEMENT] = TypePtr::NULL_PTR;
 791   _zero_type[T_ADDRESS]     = TypePtr::NULL_PTR; // raw pointers use the same null
 792   _zero_type[T_VOID]        = Type::TOP;         // the only void value is no value at all
 793 
 794   // get_zero_type() should not happen for T_CONFLICT
 795   _zero_type[T_CONFLICT]= nullptr;
 796 
 797   TypeVect::VECTMASK = (TypeVect*)(new TypeVectMask(T_BOOLEAN, MaxVectorSize))->hashcons();
 798   mreg2type[Op_RegVectMask] = TypeVect::VECTMASK;
 799 
 800   if (Matcher::supports_scalable_vector()) {
 801     TypeVect::VECTA = TypeVect::make(T_BYTE, Matcher::scalable_vector_reg_size(T_BYTE));
 802   }
 803 
 804   // Vector predefined types, it needs initialized _const_basic_type[].
 805   if (Matcher::vector_size_supported(T_BYTE, 4)) {
 806     TypeVect::VECTS = TypeVect::make(T_BYTE, 4);
 807   }
 808   if (Matcher::vector_size_supported(T_FLOAT, 2)) {
 809     TypeVect::VECTD = TypeVect::make(T_FLOAT, 2);
 810   }
 811   if (Matcher::vector_size_supported(T_FLOAT, 4)) {
 812     TypeVect::VECTX = TypeVect::make(T_FLOAT, 4);
 813   }
 814   if (Matcher::vector_size_supported(T_FLOAT, 8)) {
 815     TypeVect::VECTY = TypeVect::make(T_FLOAT, 8);
 816   }
 817   if (Matcher::vector_size_supported(T_FLOAT, 16)) {
 818     TypeVect::VECTZ = TypeVect::make(T_FLOAT, 16);
 819   }
 820 
 821   mreg2type[Op_VecA] = TypeVect::VECTA;
 822   mreg2type[Op_VecS] = TypeVect::VECTS;
 823   mreg2type[Op_VecD] = TypeVect::VECTD;
 824   mreg2type[Op_VecX] = TypeVect::VECTX;
 825   mreg2type[Op_VecY] = TypeVect::VECTY;
 826   mreg2type[Op_VecZ] = TypeVect::VECTZ;
 827 
 828 #if INCLUDE_SHENANDOAHGC
 829   ShenandoahBarrierSetC2::init();
 830 #endif //INCLUDE_SHENANDOAHGC
 831 
 832   BarrierSetC2::make_clone_type();
 833   LockNode::initialize_lock_Type();
 834   ArrayCopyNode::initialize_arraycopy_Type();
 835   OptoRuntime::initialize_types();
 836 
 837   // Restore working type arena.
 838   current->set_type_arena(save);
 839   current->set_type_dict(nullptr);
 840 }
 841 
 842 //------------------------------Initialize-------------------------------------
 843 void Type::Initialize(Compile* current) {
 844   assert(current->type_arena() != nullptr, "must have created type arena");
 845 
 846   if (_shared_type_dict == nullptr) {
 847     Initialize_shared(current);
 848   }
 849 
 850   Arena* type_arena = current->type_arena();
 851 
 852   // Create the hash-cons'ing dictionary with top-level storage allocation
 853   Dict *tdic = new (type_arena) Dict(*_shared_type_dict, type_arena);
 854   current->set_type_dict(tdic);
 855 }
 856 
 857 //------------------------------hashcons---------------------------------------
 858 // Do the hash-cons trick.  If the Type already exists in the type table,
 859 // delete the current Type and return the existing Type.  Otherwise stick the
 860 // current Type in the Type table.
 861 const Type *Type::hashcons(void) {
 862   DEBUG_ONLY(base());           // Check the assertion in Type::base().
 863   // Look up the Type in the Type dictionary
 864   Dict *tdic = type_dict();
 865   Type* old = (Type*)(tdic->Insert(this, this, false));
 866   if( old ) {                   // Pre-existing Type?
 867     if( old != this )           // Yes, this guy is not the pre-existing?
 868       delete this;              // Yes, Nuke this guy
 869     assert( old->_dual, "" );
 870     return old;                 // Return pre-existing
 871   }
 872 
 873   // Every type has a dual (to make my lattice symmetric).
 874   // Since we just discovered a new Type, compute its dual right now.
 875   assert( !_dual, "" );         // No dual yet
 876   _dual = xdual();              // Compute the dual
 877   if (equals(this, _dual)) {    // Handle self-symmetric
 878     if (_dual != this) {
 879       delete _dual;
 880       _dual = this;
 881     }
 882     return this;
 883   }
 884   assert( !_dual->_dual, "" );  // No reverse dual yet
 885   assert( !(*tdic)[_dual], "" ); // Dual not in type system either
 886   // New Type, insert into Type table
 887   tdic->Insert((void*)_dual,(void*)_dual);
 888   ((Type*)_dual)->_dual = this; // Finish up being symmetric
 889 #ifdef ASSERT
 890   Type *dual_dual = (Type*)_dual->xdual();
 891   assert( eq(dual_dual), "xdual(xdual()) should be identity" );
 892   delete dual_dual;
 893 #endif
 894   return this;                  // Return new Type
 895 }
 896 
 897 //------------------------------eq---------------------------------------------
 898 // Structural equality check for Type representations
 899 bool Type::eq( const Type * ) const {
 900   return true;                  // Nothing else can go wrong
 901 }
 902 
 903 //------------------------------hash-------------------------------------------
 904 // Type-specific hashing function.
 905 uint Type::hash(void) const {
 906   return _base;
 907 }
 908 
 909 //------------------------------is_finite--------------------------------------
 910 // Has a finite value
 911 bool Type::is_finite() const {
 912   return false;
 913 }
 914 
 915 //------------------------------is_nan-----------------------------------------
 916 // Is not a number (NaN)
 917 bool Type::is_nan()    const {
 918   return false;
 919 }
 920 
 921 #ifdef ASSERT
 922 class VerifyMeet;
 923 class VerifyMeetResult : public ArenaObj {
 924   friend class VerifyMeet;
 925   friend class Type;
 926 private:
 927   class VerifyMeetResultEntry {
 928   private:
 929     const Type* _in1;
 930     const Type* _in2;
 931     const Type* _res;
 932   public:
 933     VerifyMeetResultEntry(const Type* in1, const Type* in2, const Type* res):
 934             _in1(in1), _in2(in2), _res(res) {
 935     }
 936     VerifyMeetResultEntry():
 937             _in1(nullptr), _in2(nullptr), _res(nullptr) {
 938     }
 939 
 940     bool operator==(const VerifyMeetResultEntry& rhs) const {
 941       return _in1 == rhs._in1 &&
 942              _in2 == rhs._in2 &&
 943              _res == rhs._res;
 944     }
 945 
 946     bool operator!=(const VerifyMeetResultEntry& rhs) const {
 947       return !(rhs == *this);
 948     }
 949 
 950     static int compare(const VerifyMeetResultEntry& v1, const VerifyMeetResultEntry& v2) {
 951       if ((intptr_t) v1._in1 < (intptr_t) v2._in1) {
 952         return -1;
 953       } else if (v1._in1 == v2._in1) {
 954         if ((intptr_t) v1._in2 < (intptr_t) v2._in2) {
 955           return -1;
 956         } else if (v1._in2 == v2._in2) {
 957           assert(v1._res == v2._res || v1._res == nullptr || v2._res == nullptr, "same inputs should lead to same result");
 958           return 0;
 959         }
 960         return 1;
 961       }
 962       return 1;
 963     }
 964     const Type* res() const { return _res; }
 965   };
 966   uint _depth;
 967   GrowableArray<VerifyMeetResultEntry> _cache;
 968 
 969   // With verification code, the meet of A and B causes the computation of:
 970   // 1- meet(A, B)
 971   // 2- meet(B, A)
 972   // 3- meet(dual(meet(A, B)), dual(A))
 973   // 4- meet(dual(meet(A, B)), dual(B))
 974   // 5- meet(dual(A), dual(B))
 975   // 6- meet(dual(B), dual(A))
 976   // 7- meet(dual(meet(dual(A), dual(B))), A)
 977   // 8- meet(dual(meet(dual(A), dual(B))), B)
 978   //
 979   // In addition the meet of A[] and B[] requires the computation of the meet of A and B.
 980   //
 981   // The meet of A[] and B[] triggers the computation of:
 982   // 1- meet(A[], B[][)
 983   //   1.1- meet(A, B)
 984   //   1.2- meet(B, A)
 985   //   1.3- meet(dual(meet(A, B)), dual(A))
 986   //   1.4- meet(dual(meet(A, B)), dual(B))
 987   //   1.5- meet(dual(A), dual(B))
 988   //   1.6- meet(dual(B), dual(A))
 989   //   1.7- meet(dual(meet(dual(A), dual(B))), A)
 990   //   1.8- meet(dual(meet(dual(A), dual(B))), B)
 991   // 2- meet(B[], A[])
 992   //   2.1- meet(B, A) = 1.2
 993   //   2.2- meet(A, B) = 1.1
 994   //   2.3- meet(dual(meet(B, A)), dual(B)) = 1.4
 995   //   2.4- meet(dual(meet(B, A)), dual(A)) = 1.3
 996   //   2.5- meet(dual(B), dual(A)) = 1.6
 997   //   2.6- meet(dual(A), dual(B)) = 1.5
 998   //   2.7- meet(dual(meet(dual(B), dual(A))), B) = 1.8
 999   //   2.8- meet(dual(meet(dual(B), dual(A))), B) = 1.7
1000   // etc.
1001   // The number of meet operations performed grows exponentially with the number of dimensions of the arrays but the number
1002   // of different meet operations is linear in the number of dimensions. The function below caches meet results for the
1003   // duration of the meet at the root of the recursive calls.
1004   //
1005   const Type* meet(const Type* t1, const Type* t2) {
1006     bool found = false;
1007     const VerifyMeetResultEntry meet(t1, t2, nullptr);
1008     int pos = _cache.find_sorted<VerifyMeetResultEntry, VerifyMeetResultEntry::compare>(meet, found);
1009     const Type* res = nullptr;
1010     if (found) {
1011       res = _cache.at(pos).res();
1012     } else {
1013       res = t1->xmeet(t2);
1014       _cache.insert_sorted<VerifyMeetResultEntry::compare>(VerifyMeetResultEntry(t1, t2, res));
1015       found = false;
1016       _cache.find_sorted<VerifyMeetResultEntry, VerifyMeetResultEntry::compare>(meet, found);
1017       assert(found, "should be in table after it's added");
1018     }
1019     return res;
1020   }
1021 
1022   void add(const Type* t1, const Type* t2, const Type* res) {
1023     _cache.insert_sorted<VerifyMeetResultEntry::compare>(VerifyMeetResultEntry(t1, t2, res));
1024   }
1025 
1026   bool empty_cache() const {
1027     return _cache.length() == 0;
1028   }
1029 public:
1030   VerifyMeetResult(Compile* C) :
1031           _depth(0), _cache(C->comp_arena(), 2, 0, VerifyMeetResultEntry()) {
1032   }
1033 };
1034 
1035 void Type::assert_type_verify_empty() const {
1036   assert(Compile::current()->_type_verify == nullptr || Compile::current()->_type_verify->empty_cache(), "cache should have been discarded");
1037 }
1038 
1039 class VerifyMeet {
1040 private:
1041   Compile* _C;
1042 public:
1043   VerifyMeet(Compile* C) : _C(C) {
1044     if (C->_type_verify == nullptr) {
1045       C->_type_verify = new (C->comp_arena())VerifyMeetResult(C);
1046     }
1047     _C->_type_verify->_depth++;
1048   }
1049 
1050   ~VerifyMeet() {
1051     assert(_C->_type_verify->_depth != 0, "");
1052     _C->_type_verify->_depth--;
1053     if (_C->_type_verify->_depth == 0) {
1054       _C->_type_verify->_cache.trunc_to(0);
1055     }
1056   }
1057 
1058   const Type* meet(const Type* t1, const Type* t2) const {
1059     return _C->_type_verify->meet(t1, t2);
1060   }
1061 
1062   void add(const Type* t1, const Type* t2, const Type* res) const {
1063     _C->_type_verify->add(t1, t2, res);
1064   }
1065 };
1066 
1067 void Type::check_symmetrical(const Type* t, const Type* mt, const VerifyMeet& verify) const {
1068   Compile* C = Compile::current();
1069   const Type* mt2 = verify.meet(t, this);
1070 
1071   // Verify that:
1072   //      this meet t == t meet this
1073   if (mt != mt2) {
1074     tty->print_cr("=== Meet Not Commutative ===");
1075     tty->print("t           = ");   t->dump(); tty->cr();
1076     tty->print("this        = ");      dump(); tty->cr();
1077     tty->print("t meet this = "); mt2->dump(); tty->cr();
1078     tty->print("this meet t = ");  mt->dump(); tty->cr();
1079     fatal("meet not commutative");
1080   }
1081   const Type* dual_join = mt->_dual;
1082   const Type* t2t    = verify.meet(dual_join,t->_dual);
1083   const Type* t2this = verify.meet(dual_join,this->_dual);
1084 
1085   // Interface meet Oop is Not Symmetric:
1086   // Interface:AnyNull meet Oop:AnyNull == Interface:AnyNull
1087   // Interface:NotNull meet Oop:NotNull == java/lang/Object:NotNull
1088 
1089   // Verify that:
1090   // 1)     mt_dual meet t_dual    == t_dual
1091   //    which corresponds to
1092   //       !(t meet this)  meet !t ==
1093   //       (!t join !this) meet !t == !t
1094   // 2)    mt_dual meet this_dual     == this_dual
1095   //    which corresponds to
1096   //       !(t meet this)  meet !this ==
1097   //       (!t join !this) meet !this == !this
1098   if (t2t != t->_dual || t2this != this->_dual) {
1099     tty->print_cr("=== Meet Not Symmetric ===");
1100     tty->print("t   =                   ");              t->dump(); tty->cr();
1101     tty->print("this=                   ");                 dump(); tty->cr();
1102     tty->print("mt=(t meet this)=       ");             mt->dump(); tty->cr();
1103 
1104     tty->print("t_dual=                 ");       t->_dual->dump(); tty->cr();
1105     tty->print("this_dual=              ");          _dual->dump(); tty->cr();
1106     tty->print("mt_dual=                ");      mt->_dual->dump(); tty->cr();
1107 
1108     // 1)
1109     tty->print("mt_dual meet t_dual=    "); t2t           ->dump(); tty->cr();
1110     // 2)
1111     tty->print("mt_dual meet this_dual= "); t2this        ->dump(); tty->cr();
1112     tty->cr();
1113     tty->print_cr("Fail: ");
1114     if (t2t != t->_dual) {
1115       tty->print_cr("- mt_dual meet t_dual != t_dual");
1116     }
1117     if (t2this != this->_dual) {
1118       tty->print_cr("- mt_dual meet this_dual != this_dual");
1119     }
1120     tty->cr();
1121 
1122     fatal("meet not symmetric");
1123   }
1124 }
1125 #endif
1126 
1127 //------------------------------meet-------------------------------------------
1128 // Compute the MEET of two types.  NOT virtual.  It enforces that meet is
1129 // commutative and the lattice is symmetric.
1130 const Type *Type::meet_helper(const Type *t, bool include_speculative) const {
1131   if (isa_narrowoop() && t->isa_narrowoop()) {
1132     const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
1133     return result->make_narrowoop();
1134   }
1135   if (isa_narrowklass() && t->isa_narrowklass()) {
1136     const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
1137     return result->make_narrowklass();
1138   }
1139 
1140 #ifdef ASSERT
1141   Compile* C = Compile::current();
1142   VerifyMeet verify(C);
1143 #endif
1144 
1145   const Type *this_t = maybe_remove_speculative(include_speculative);
1146   t = t->maybe_remove_speculative(include_speculative);
1147 
1148   const Type *mt = this_t->xmeet(t);
1149 #ifdef ASSERT
1150   verify.add(this_t, t, mt);
1151   if (isa_narrowoop() || t->isa_narrowoop()) {
1152     return mt;
1153   }
1154   if (isa_narrowklass() || t->isa_narrowklass()) {
1155     return mt;
1156   }
1157   // TODO 8350865 This currently triggers a verification failure, the code around "// Even though MyValue is final" needs adjustments
1158   if ((this_t->isa_ptr() && this_t->is_ptr()->is_not_flat()) ||
1159       (this_t->_dual->isa_ptr() && this_t->_dual->is_ptr()->is_not_flat())) return mt;
1160   this_t->check_symmetrical(t, mt, verify);
1161   const Type *mt_dual = verify.meet(this_t->_dual, t->_dual);
1162   this_t->_dual->check_symmetrical(t->_dual, mt_dual, verify);
1163 #endif
1164   return mt;
1165 }
1166 
1167 //------------------------------xmeet------------------------------------------
1168 // Compute the MEET of two types.  It returns a new Type object.
1169 const Type *Type::xmeet( const Type *t ) const {
1170   // Perform a fast test for common case; meeting the same types together.
1171   if( this == t ) return this;  // Meeting same type-rep?
1172 
1173   // Meeting TOP with anything?
1174   if( _base == Top ) return t;
1175 
1176   // Meeting BOTTOM with anything?
1177   if( _base == Bottom ) return BOTTOM;
1178 
1179   // Current "this->_base" is one of: Bad, Multi, Control, Top,
1180   // Abio, Abstore, Floatxxx, Doublexxx, Bottom, lastype.
1181   switch (t->base()) {  // Switch on original type
1182 
1183   // Cut in half the number of cases I must handle.  Only need cases for when
1184   // the given enum "t->type" is less than or equal to the local enum "type".
1185   case HalfFloatCon:
1186   case FloatCon:
1187   case DoubleCon:
1188   case Int:
1189   case Long:
1190     return t->xmeet(this);
1191 
1192   case OopPtr:
1193     return t->xmeet(this);
1194 
1195   case InstPtr:
1196     return t->xmeet(this);
1197 
1198   case MetadataPtr:
1199   case KlassPtr:
1200   case InstKlassPtr:
1201   case AryKlassPtr:
1202     return t->xmeet(this);
1203 
1204   case AryPtr:
1205     return t->xmeet(this);
1206 
1207   case NarrowOop:
1208     return t->xmeet(this);
1209 
1210   case NarrowKlass:
1211     return t->xmeet(this);
1212 
1213   case Bad:                     // Type check
1214   default:                      // Bogus type not in lattice
1215     typerr(t);
1216     return Type::BOTTOM;
1217 
1218   case Bottom:                  // Ye Olde Default
1219     return t;
1220 
1221   case HalfFloatTop:
1222     if (_base == HalfFloatTop) { return this; }
1223   case HalfFloatBot:            // Half Float
1224     if (_base == HalfFloatBot || _base == HalfFloatTop) { return HALF_FLOAT; }
1225     if (_base == FloatBot || _base == FloatTop) { return Type::BOTTOM; }
1226     if (_base == DoubleTop || _base == DoubleBot) { return Type::BOTTOM; }
1227     typerr(t);
1228     return Type::BOTTOM;
1229 
1230   case FloatTop:
1231     if (_base == FloatTop ) { return this; }
1232   case FloatBot:                // Float
1233     if (_base == FloatBot || _base == FloatTop) { return FLOAT; }
1234     if (_base == HalfFloatTop || _base == HalfFloatBot) { return Type::BOTTOM; }
1235     if (_base == DoubleTop || _base == DoubleBot) { return Type::BOTTOM; }
1236     typerr(t);
1237     return Type::BOTTOM;
1238 
1239   case DoubleTop:
1240     if (_base == DoubleTop) { return this; }
1241   case DoubleBot:               // Double
1242     if (_base == DoubleBot || _base == DoubleTop) { return DOUBLE; }
1243     if (_base == HalfFloatTop || _base == HalfFloatBot) { return Type::BOTTOM; }
1244     if (_base == FloatTop || _base == FloatBot) { return Type::BOTTOM; }
1245     typerr(t);
1246     return Type::BOTTOM;
1247 
1248   // These next few cases must match exactly or it is a compile-time error.
1249   case Control:                 // Control of code
1250   case Abio:                    // State of world outside of program
1251   case Memory:
1252     if (_base == t->_base)  { return this; }
1253     typerr(t);
1254     return Type::BOTTOM;
1255 
1256   case Top:                     // Top of the lattice
1257     return this;
1258   }
1259 
1260   // The type is unchanged
1261   return this;
1262 }
1263 
1264 //-----------------------------filter------------------------------------------
1265 const Type *Type::filter_helper(const Type *kills, bool include_speculative) const {
1266   const Type* ft = join_helper(kills, include_speculative);
1267   if (ft->empty())
1268     return Type::TOP;           // Canonical empty value
1269   return ft;
1270 }
1271 
1272 //------------------------------xdual------------------------------------------
1273 const Type *Type::xdual() const {
1274   // Note: the base() accessor asserts the sanity of _base.
1275   assert(_type_info[base()].dual_type != Bad, "implement with v-call");
1276   return new Type(_type_info[_base].dual_type);
1277 }
1278 
1279 //------------------------------has_memory-------------------------------------
1280 bool Type::has_memory() const {
1281   Type::TYPES tx = base();
1282   if (tx == Memory) return true;
1283   if (tx == Tuple) {
1284     const TypeTuple *t = is_tuple();
1285     for (uint i=0; i < t->cnt(); i++) {
1286       tx = t->field_at(i)->base();
1287       if (tx == Memory)  return true;
1288     }
1289   }
1290   return false;
1291 }
1292 
1293 #ifndef PRODUCT
1294 //------------------------------dump2------------------------------------------
1295 void Type::dump2( Dict &d, uint depth, outputStream *st ) const {
1296   st->print("%s", _type_info[_base].msg);
1297 }
1298 
1299 //------------------------------dump-------------------------------------------
1300 void Type::dump_on(outputStream *st) const {
1301   ResourceMark rm;
1302   Dict d(cmpkey,hashkey);       // Stop recursive type dumping
1303   dump2(d,1, st);
1304   if (is_ptr_to_narrowoop()) {
1305     st->print(" [narrow]");
1306   } else if (is_ptr_to_narrowklass()) {
1307     st->print(" [narrowklass]");
1308   }
1309 }
1310 
1311 //-----------------------------------------------------------------------------
1312 const char* Type::str(const Type* t) {
1313   stringStream ss;
1314   t->dump_on(&ss);
1315   return ss.as_string();
1316 }
1317 #endif
1318 
1319 //------------------------------singleton--------------------------------------
1320 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
1321 // constants (Ldi nodes).  Singletons are integer, float or double constants.
1322 bool Type::singleton(void) const {
1323   return _base == Top || _base == Half;
1324 }
1325 
1326 //------------------------------empty------------------------------------------
1327 // TRUE if Type is a type with no values, FALSE otherwise.
1328 bool Type::empty(void) const {
1329   switch (_base) {
1330   case DoubleTop:
1331   case FloatTop:
1332   case HalfFloatTop:
1333   case Top:
1334     return true;
1335 
1336   case Half:
1337   case Abio:
1338   case Return_Address:
1339   case Memory:
1340   case Bottom:
1341   case HalfFloatBot:
1342   case FloatBot:
1343   case DoubleBot:
1344     return false;  // never a singleton, therefore never empty
1345 
1346   default:
1347     ShouldNotReachHere();
1348     return false;
1349   }
1350 }
1351 
1352 //------------------------------dump_stats-------------------------------------
1353 // Dump collected statistics to stderr
1354 #ifndef PRODUCT
1355 void Type::dump_stats() {
1356   tty->print("Types made: %d\n", type_dict()->Size());
1357 }
1358 #endif
1359 
1360 //------------------------------category---------------------------------------
1361 #ifndef PRODUCT
1362 Type::Category Type::category() const {
1363   const TypeTuple* tuple;
1364   switch (base()) {
1365     case Type::Int:
1366     case Type::Long:
1367     case Type::Half:
1368     case Type::NarrowOop:
1369     case Type::NarrowKlass:
1370     case Type::Array:
1371     case Type::VectorA:
1372     case Type::VectorS:
1373     case Type::VectorD:
1374     case Type::VectorX:
1375     case Type::VectorY:
1376     case Type::VectorZ:
1377     case Type::VectorMask:
1378     case Type::AnyPtr:
1379     case Type::RawPtr:
1380     case Type::OopPtr:
1381     case Type::InstPtr:
1382     case Type::AryPtr:
1383     case Type::MetadataPtr:
1384     case Type::KlassPtr:
1385     case Type::InstKlassPtr:
1386     case Type::AryKlassPtr:
1387     case Type::Function:
1388     case Type::Return_Address:
1389     case Type::HalfFloatTop:
1390     case Type::HalfFloatCon:
1391     case Type::HalfFloatBot:
1392     case Type::FloatTop:
1393     case Type::FloatCon:
1394     case Type::FloatBot:
1395     case Type::DoubleTop:
1396     case Type::DoubleCon:
1397     case Type::DoubleBot:
1398       return Category::Data;
1399     case Type::Memory:
1400       return Category::Memory;
1401     case Type::Control:
1402       return Category::Control;
1403     case Type::Top:
1404     case Type::Abio:
1405     case Type::Bottom:
1406       return Category::Other;
1407     case Type::Bad:
1408     case Type::lastype:
1409       return Category::Undef;
1410     case Type::Tuple:
1411       // Recursive case. Return CatMixed if the tuple contains types of
1412       // different categories (e.g. CallStaticJavaNode's type), or the specific
1413       // category if all types are of the same category (e.g. IfNode's type).
1414       tuple = is_tuple();
1415       if (tuple->cnt() == 0) {
1416         return Category::Undef;
1417       } else {
1418         Category first = tuple->field_at(0)->category();
1419         for (uint i = 1; i < tuple->cnt(); i++) {
1420           if (tuple->field_at(i)->category() != first) {
1421             return Category::Mixed;
1422           }
1423         }
1424         return first;
1425       }
1426     default:
1427       assert(false, "unmatched base type: all base types must be categorized");
1428   }
1429   return Category::Undef;
1430 }
1431 
1432 bool Type::has_category(Type::Category cat) const {
1433   if (category() == cat) {
1434     return true;
1435   }
1436   if (category() == Category::Mixed) {
1437     const TypeTuple* tuple = is_tuple();
1438     for (uint i = 0; i < tuple->cnt(); i++) {
1439       if (tuple->field_at(i)->has_category(cat)) {
1440         return true;
1441       }
1442     }
1443   }
1444   return false;
1445 }
1446 #endif
1447 
1448 //------------------------------typerr-----------------------------------------
1449 void Type::typerr( const Type *t ) const {
1450 #ifndef PRODUCT
1451   tty->print("\nError mixing types: ");
1452   dump();
1453   tty->print(" and ");
1454   t->dump();
1455   tty->print("\n");
1456 #endif
1457   ShouldNotReachHere();
1458 }
1459 
1460 
1461 //=============================================================================
1462 // Convenience common pre-built types.
1463 const TypeF *TypeF::MAX;        // Floating point max
1464 const TypeF *TypeF::MIN;        // Floating point min
1465 const TypeF *TypeF::ZERO;       // Floating point zero
1466 const TypeF *TypeF::ONE;        // Floating point one
1467 const TypeF *TypeF::POS_INF;    // Floating point positive infinity
1468 const TypeF *TypeF::NEG_INF;    // Floating point negative infinity
1469 
1470 //------------------------------make-------------------------------------------
1471 // Create a float constant
1472 const TypeF *TypeF::make(float f) {
1473   return (TypeF*)(new TypeF(f))->hashcons();
1474 }
1475 
1476 //------------------------------meet-------------------------------------------
1477 // Compute the MEET of two types.  It returns a new Type object.
1478 const Type *TypeF::xmeet( const Type *t ) const {
1479   // Perform a fast test for common case; meeting the same types together.
1480   if( this == t ) return this;  // Meeting same type-rep?
1481 
1482   // Current "this->_base" is FloatCon
1483   switch (t->base()) {          // Switch on original type
1484   case AnyPtr:                  // Mixing with oops happens when javac
1485   case RawPtr:                  // reuses local variables
1486   case OopPtr:
1487   case InstPtr:
1488   case AryPtr:
1489   case MetadataPtr:
1490   case KlassPtr:
1491   case InstKlassPtr:
1492   case AryKlassPtr:
1493   case NarrowOop:
1494   case NarrowKlass:
1495   case Int:
1496   case Long:
1497   case HalfFloatTop:
1498   case HalfFloatCon:
1499   case HalfFloatBot:
1500   case DoubleTop:
1501   case DoubleCon:
1502   case DoubleBot:
1503   case Bottom:                  // Ye Olde Default
1504     return Type::BOTTOM;
1505 
1506   case FloatBot:
1507     return t;
1508 
1509   default:                      // All else is a mistake
1510     typerr(t);
1511 
1512   case FloatCon:                // Float-constant vs Float-constant?
1513     if( jint_cast(_f) != jint_cast(t->getf()) )         // unequal constants?
1514                                 // must compare bitwise as positive zero, negative zero and NaN have
1515                                 // all the same representation in C++
1516       return FLOAT;             // Return generic float
1517                                 // Equal constants
1518   case Top:
1519   case FloatTop:
1520     break;                      // Return the float constant
1521   }
1522   return this;                  // Return the float constant
1523 }
1524 
1525 //------------------------------xdual------------------------------------------
1526 // Dual: symmetric
1527 const Type *TypeF::xdual() const {
1528   return this;
1529 }
1530 
1531 //------------------------------eq---------------------------------------------
1532 // Structural equality check for Type representations
1533 bool TypeF::eq(const Type *t) const {
1534   // Bitwise comparison to distinguish between +/-0. These values must be treated
1535   // as different to be consistent with C1 and the interpreter.
1536   return (jint_cast(_f) == jint_cast(t->getf()));
1537 }
1538 
1539 //------------------------------hash-------------------------------------------
1540 // Type-specific hashing function.
1541 uint TypeF::hash(void) const {
1542   return *(uint*)(&_f);
1543 }
1544 
1545 //------------------------------is_finite--------------------------------------
1546 // Has a finite value
1547 bool TypeF::is_finite() const {
1548   return g_isfinite(getf()) != 0;
1549 }
1550 
1551 //------------------------------is_nan-----------------------------------------
1552 // Is not a number (NaN)
1553 bool TypeF::is_nan()    const {
1554   return g_isnan(getf()) != 0;
1555 }
1556 
1557 //------------------------------dump2------------------------------------------
1558 // Dump float constant Type
1559 #ifndef PRODUCT
1560 void TypeF::dump2( Dict &d, uint depth, outputStream *st ) const {
1561   Type::dump2(d,depth, st);
1562   st->print("%f", _f);
1563 }
1564 #endif
1565 
1566 //------------------------------singleton--------------------------------------
1567 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
1568 // constants (Ldi nodes).  Singletons are integer, float or double constants
1569 // or a single symbol.
1570 bool TypeF::singleton(void) const {
1571   return true;                  // Always a singleton
1572 }
1573 
1574 bool TypeF::empty(void) const {
1575   return false;                 // always exactly a singleton
1576 }
1577 
1578 //=============================================================================
1579 // Convenience common pre-built types.
1580 const TypeH* TypeH::MAX;        // Half float max
1581 const TypeH* TypeH::MIN;        // Half float min
1582 const TypeH* TypeH::ZERO;       // Half float zero
1583 const TypeH* TypeH::ONE;        // Half float one
1584 const TypeH* TypeH::POS_INF;    // Half float positive infinity
1585 const TypeH* TypeH::NEG_INF;    // Half float negative infinity
1586 
1587 //------------------------------make-------------------------------------------
1588 // Create a halffloat constant
1589 const TypeH* TypeH::make(short f) {
1590   return (TypeH*)(new TypeH(f))->hashcons();
1591 }
1592 
1593 const TypeH* TypeH::make(float f) {
1594   assert(StubRoutines::f2hf_adr() != nullptr, "");
1595   short hf = StubRoutines::f2hf(f);
1596   return (TypeH*)(new TypeH(hf))->hashcons();
1597 }
1598 
1599 //------------------------------xmeet-------------------------------------------
1600 // Compute the MEET of two types.  It returns a new Type object.
1601 const Type* TypeH::xmeet(const Type* t) const {
1602   // Perform a fast test for common case; meeting the same types together.
1603   if (this == t) return this;  // Meeting same type-rep?
1604 
1605   // Current "this->_base" is FloatCon
1606   switch (t->base()) {          // Switch on original type
1607   case AnyPtr:                  // Mixing with oops happens when javac
1608   case RawPtr:                  // reuses local variables
1609   case OopPtr:
1610   case InstPtr:
1611   case AryPtr:
1612   case MetadataPtr:
1613   case KlassPtr:
1614   case InstKlassPtr:
1615   case AryKlassPtr:
1616   case NarrowOop:
1617   case NarrowKlass:
1618   case Int:
1619   case Long:
1620   case FloatTop:
1621   case FloatCon:
1622   case FloatBot:
1623   case DoubleTop:
1624   case DoubleCon:
1625   case DoubleBot:
1626   case Bottom:                  // Ye Olde Default
1627     return Type::BOTTOM;
1628 
1629   case HalfFloatBot:
1630     return t;
1631 
1632   default:                      // All else is a mistake
1633     typerr(t);
1634 
1635   case HalfFloatCon:            // Half float-constant vs Half float-constant?
1636     if (_f != t->geth()) {      // unequal constants?
1637                                 // must compare bitwise as positive zero, negative zero and NaN have
1638                                 // all the same representation in C++
1639       return HALF_FLOAT;        // Return generic float
1640     }                           // Equal constants
1641   case Top:
1642   case HalfFloatTop:
1643     break;                      // Return the Half float constant
1644   }
1645   return this;                  // Return the Half float constant
1646 }
1647 
1648 //------------------------------xdual------------------------------------------
1649 // Dual: symmetric
1650 const Type* TypeH::xdual() const {
1651   return this;
1652 }
1653 
1654 //------------------------------eq---------------------------------------------
1655 // Structural equality check for Type representations
1656 bool TypeH::eq(const Type* t) const {
1657   // Bitwise comparison to distinguish between +/-0. These values must be treated
1658   // as different to be consistent with C1 and the interpreter.
1659   return (_f == t->geth());
1660 }
1661 
1662 //------------------------------hash-------------------------------------------
1663 // Type-specific hashing function.
1664 uint TypeH::hash(void) const {
1665   return *(jshort*)(&_f);
1666 }
1667 
1668 //------------------------------is_finite--------------------------------------
1669 // Has a finite value
1670 bool TypeH::is_finite() const {
1671   assert(StubRoutines::hf2f_adr() != nullptr, "");
1672   float f = StubRoutines::hf2f(geth());
1673   return g_isfinite(f) != 0;
1674 }
1675 
1676 float TypeH::getf() const {
1677   assert(StubRoutines::hf2f_adr() != nullptr, "");
1678   return StubRoutines::hf2f(geth());
1679 }
1680 
1681 //------------------------------is_nan-----------------------------------------
1682 // Is not a number (NaN)
1683 bool TypeH::is_nan() const {
1684   assert(StubRoutines::hf2f_adr() != nullptr, "");
1685   float f = StubRoutines::hf2f(geth());
1686   return g_isnan(f) != 0;
1687 }
1688 
1689 //------------------------------dump2------------------------------------------
1690 // Dump float constant Type
1691 #ifndef PRODUCT
1692 void TypeH::dump2(Dict &d, uint depth, outputStream* st) const {
1693   Type::dump2(d,depth, st);
1694   st->print("%f", getf());
1695 }
1696 #endif
1697 
1698 //------------------------------singleton--------------------------------------
1699 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
1700 // constants (Ldi nodes).  Singletons are integer, half float, float or double constants
1701 // or a single symbol.
1702 bool TypeH::singleton(void) const {
1703   return true;                  // Always a singleton
1704 }
1705 
1706 bool TypeH::empty(void) const {
1707   return false;                 // always exactly a singleton
1708 }
1709 
1710 //=============================================================================
1711 // Convenience common pre-built types.
1712 const TypeD *TypeD::MAX;        // Floating point max
1713 const TypeD *TypeD::MIN;        // Floating point min
1714 const TypeD *TypeD::ZERO;       // Floating point zero
1715 const TypeD *TypeD::ONE;        // Floating point one
1716 const TypeD *TypeD::POS_INF;    // Floating point positive infinity
1717 const TypeD *TypeD::NEG_INF;    // Floating point negative infinity
1718 
1719 //------------------------------make-------------------------------------------
1720 const TypeD *TypeD::make(double d) {
1721   return (TypeD*)(new TypeD(d))->hashcons();
1722 }
1723 
1724 //------------------------------meet-------------------------------------------
1725 // Compute the MEET of two types.  It returns a new Type object.
1726 const Type *TypeD::xmeet( const Type *t ) const {
1727   // Perform a fast test for common case; meeting the same types together.
1728   if( this == t ) return this;  // Meeting same type-rep?
1729 
1730   // Current "this->_base" is DoubleCon
1731   switch (t->base()) {          // Switch on original type
1732   case AnyPtr:                  // Mixing with oops happens when javac
1733   case RawPtr:                  // reuses local variables
1734   case OopPtr:
1735   case InstPtr:
1736   case AryPtr:
1737   case MetadataPtr:
1738   case KlassPtr:
1739   case InstKlassPtr:
1740   case AryKlassPtr:
1741   case NarrowOop:
1742   case NarrowKlass:
1743   case Int:
1744   case Long:
1745   case HalfFloatTop:
1746   case HalfFloatCon:
1747   case HalfFloatBot:
1748   case FloatTop:
1749   case FloatCon:
1750   case FloatBot:
1751   case Bottom:                  // Ye Olde Default
1752     return Type::BOTTOM;
1753 
1754   case DoubleBot:
1755     return t;
1756 
1757   default:                      // All else is a mistake
1758     typerr(t);
1759 
1760   case DoubleCon:               // Double-constant vs Double-constant?
1761     if( jlong_cast(_d) != jlong_cast(t->getd()) )       // unequal constants? (see comment in TypeF::xmeet)
1762       return DOUBLE;            // Return generic double
1763   case Top:
1764   case DoubleTop:
1765     break;
1766   }
1767   return this;                  // Return the double constant
1768 }
1769 
1770 //------------------------------xdual------------------------------------------
1771 // Dual: symmetric
1772 const Type *TypeD::xdual() const {
1773   return this;
1774 }
1775 
1776 //------------------------------eq---------------------------------------------
1777 // Structural equality check for Type representations
1778 bool TypeD::eq(const Type *t) const {
1779   // Bitwise comparison to distinguish between +/-0. These values must be treated
1780   // as different to be consistent with C1 and the interpreter.
1781   return (jlong_cast(_d) == jlong_cast(t->getd()));
1782 }
1783 
1784 //------------------------------hash-------------------------------------------
1785 // Type-specific hashing function.
1786 uint TypeD::hash(void) const {
1787   return *(uint*)(&_d);
1788 }
1789 
1790 //------------------------------is_finite--------------------------------------
1791 // Has a finite value
1792 bool TypeD::is_finite() const {
1793   return g_isfinite(getd()) != 0;
1794 }
1795 
1796 //------------------------------is_nan-----------------------------------------
1797 // Is not a number (NaN)
1798 bool TypeD::is_nan()    const {
1799   return g_isnan(getd()) != 0;
1800 }
1801 
1802 //------------------------------dump2------------------------------------------
1803 // Dump double constant Type
1804 #ifndef PRODUCT
1805 void TypeD::dump2( Dict &d, uint depth, outputStream *st ) const {
1806   Type::dump2(d,depth,st);
1807   st->print("%f", _d);
1808 }
1809 #endif
1810 
1811 //------------------------------singleton--------------------------------------
1812 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
1813 // constants (Ldi nodes).  Singletons are integer, float or double constants
1814 // or a single symbol.
1815 bool TypeD::singleton(void) const {
1816   return true;                  // Always a singleton
1817 }
1818 
1819 bool TypeD::empty(void) const {
1820   return false;                 // always exactly a singleton
1821 }
1822 
1823 const TypeInteger* TypeInteger::make(jlong lo, jlong hi, int w, BasicType bt) {
1824   if (bt == T_INT) {
1825     return TypeInt::make(checked_cast<jint>(lo), checked_cast<jint>(hi), w);
1826   }
1827   assert(bt == T_LONG, "basic type not an int or long");
1828   return TypeLong::make(lo, hi, w);
1829 }
1830 
1831 const TypeInteger* TypeInteger::make(jlong con, BasicType bt) {
1832   return make(con, con, WidenMin, bt);
1833 }
1834 
1835 jlong TypeInteger::get_con_as_long(BasicType bt) const {
1836   if (bt == T_INT) {
1837     return is_int()->get_con();
1838   }
1839   assert(bt == T_LONG, "basic type not an int or long");
1840   return is_long()->get_con();
1841 }
1842 
1843 const TypeInteger* TypeInteger::bottom(BasicType bt) {
1844   if (bt == T_INT) {
1845     return TypeInt::INT;
1846   }
1847   assert(bt == T_LONG, "basic type not an int or long");
1848   return TypeLong::LONG;
1849 }
1850 
1851 const TypeInteger* TypeInteger::zero(BasicType bt) {
1852   if (bt == T_INT) {
1853     return TypeInt::ZERO;
1854   }
1855   assert(bt == T_LONG, "basic type not an int or long");
1856   return TypeLong::ZERO;
1857 }
1858 
1859 const TypeInteger* TypeInteger::one(BasicType bt) {
1860   if (bt == T_INT) {
1861     return TypeInt::ONE;
1862   }
1863   assert(bt == T_LONG, "basic type not an int or long");
1864   return TypeLong::ONE;
1865 }
1866 
1867 const TypeInteger* TypeInteger::minus_1(BasicType bt) {
1868   if (bt == T_INT) {
1869     return TypeInt::MINUS_1;
1870   }
1871   assert(bt == T_LONG, "basic type not an int or long");
1872   return TypeLong::MINUS_1;
1873 }
1874 
1875 //=============================================================================
1876 // Convenience common pre-built types.
1877 const TypeInt* TypeInt::MAX;    // INT_MAX
1878 const TypeInt* TypeInt::MIN;    // INT_MIN
1879 const TypeInt* TypeInt::MINUS_1;// -1
1880 const TypeInt* TypeInt::ZERO;   // 0
1881 const TypeInt* TypeInt::ONE;    // 1
1882 const TypeInt* TypeInt::BOOL;   // 0 or 1, FALSE or TRUE.
1883 const TypeInt* TypeInt::CC;     // -1,0 or 1, condition codes
1884 const TypeInt* TypeInt::CC_LT;  // [-1]  == MINUS_1
1885 const TypeInt* TypeInt::CC_GT;  // [1]   == ONE
1886 const TypeInt* TypeInt::CC_EQ;  // [0]   == ZERO
1887 const TypeInt* TypeInt::CC_NE;
1888 const TypeInt* TypeInt::CC_LE;  // [-1,0]
1889 const TypeInt* TypeInt::CC_GE;  // [0,1] == BOOL (!)
1890 const TypeInt* TypeInt::BYTE;   // Bytes, -128 to 127
1891 const TypeInt* TypeInt::UBYTE;  // Unsigned Bytes, 0 to 255
1892 const TypeInt* TypeInt::CHAR;   // Java chars, 0-65535
1893 const TypeInt* TypeInt::SHORT;  // Java shorts, -32768-32767
1894 const TypeInt* TypeInt::NON_ZERO;
1895 const TypeInt* TypeInt::POS;    // Positive 32-bit integers or zero
1896 const TypeInt* TypeInt::POS1;   // Positive 32-bit integers
1897 const TypeInt* TypeInt::INT;    // 32-bit integers
1898 const TypeInt* TypeInt::SYMINT; // symmetric range [-max_jint..max_jint]
1899 const TypeInt* TypeInt::TYPE_DOMAIN; // alias for TypeInt::INT
1900 
1901 TypeInt::TypeInt(const TypeIntPrototype<jint, juint>& t, int widen, bool dual)
1902   : TypeInteger(Int, t.normalize_widen(widen), dual), _lo(t._srange._lo), _hi(t._srange._hi),
1903     _ulo(t._urange._lo), _uhi(t._urange._hi), _bits(t._bits) {
1904   DEBUG_ONLY(t.verify_constraints());
1905 }
1906 
1907 const Type* TypeInt::make_or_top(const TypeIntPrototype<jint, juint>& t, int widen, bool dual) {
1908   auto canonicalized_t = t.canonicalize_constraints();
1909   if (canonicalized_t.empty()) {
1910     return dual ? Type::BOTTOM : Type::TOP;
1911   }
1912   return (new TypeInt(canonicalized_t._data, widen, dual))->hashcons()->is_int();
1913 }
1914 
1915 const TypeInt* TypeInt::make(jint con) {
1916   juint ucon = con;
1917   return (new TypeInt(TypeIntPrototype<jint, juint>{{con, con}, {ucon, ucon}, {~ucon, ucon}},
1918                       WidenMin, false))->hashcons()->is_int();
1919 }
1920 
1921 const TypeInt* TypeInt::make(jint lo, jint hi, int widen) {
1922   assert(lo <= hi, "must be legal bounds");
1923   return make_or_top(TypeIntPrototype<jint, juint>{{lo, hi}, {0, max_juint}, {0, 0}}, widen)->is_int();
1924 }
1925 
1926 const Type* TypeInt::make_or_top(const TypeIntPrototype<jint, juint>& t, int widen) {
1927   return make_or_top(t, widen, false);
1928 }
1929 
1930 bool TypeInt::contains(jint i) const {
1931   assert(!_is_dual, "dual types should only be used for join calculation");
1932   juint u = i;
1933   return i >= _lo && i <= _hi &&
1934          u >= _ulo && u <= _uhi &&
1935          _bits.is_satisfied_by(u);
1936 }
1937 
1938 bool TypeInt::contains(const TypeInt* t) const {
1939   assert(!_is_dual && !t->_is_dual, "dual types should only be used for join calculation");
1940   return TypeIntHelper::int_type_is_subset(this, t);
1941 }
1942 
1943 #ifdef ASSERT
1944 bool TypeInt::strictly_contains(const TypeInt* t) const {
1945   assert(!_is_dual && !t->_is_dual, "dual types should only be used for join calculation");
1946   return TypeIntHelper::int_type_is_subset(this, t) && !TypeIntHelper::int_type_is_equal(this, t);
1947 }
1948 #endif // ASSERT
1949 
1950 const Type* TypeInt::xmeet(const Type* t) const {
1951   return TypeIntHelper::int_type_xmeet(this, t);
1952 }
1953 
1954 const Type* TypeInt::xdual() const {
1955   return new TypeInt(TypeIntPrototype<jint, juint>{{_lo, _hi}, {_ulo, _uhi}, _bits},
1956                      _widen, !_is_dual);
1957 }
1958 
1959 const Type* TypeInt::widen(const Type* old, const Type* limit) const {
1960   assert(!_is_dual, "dual types should only be used for join calculation");
1961   return TypeIntHelper::int_type_widen(this, old->isa_int(), limit->isa_int());
1962 }
1963 
1964 const Type* TypeInt::narrow(const Type* old) const {
1965   assert(!_is_dual, "dual types should only be used for join calculation");
1966   if (old == nullptr) {
1967     return this;
1968   }
1969 
1970   return TypeIntHelper::int_type_narrow(this, old->isa_int());
1971 }
1972 
1973 //-----------------------------filter------------------------------------------
1974 const Type* TypeInt::filter_helper(const Type* kills, bool include_speculative) const {
1975   assert(!_is_dual, "dual types should only be used for join calculation");
1976   const TypeInt* ft = join_helper(kills, include_speculative)->isa_int();
1977   if (ft == nullptr) {
1978     return Type::TOP;           // Canonical empty value
1979   }
1980   assert(!ft->_is_dual, "dual types should only be used for join calculation");
1981   if (ft->_widen < this->_widen) {
1982     // Do not allow the value of kill->_widen to affect the outcome.
1983     // The widen bits must be allowed to run freely through the graph.
1984     return (new TypeInt(TypeIntPrototype<jint, juint>{{ft->_lo, ft->_hi}, {ft->_ulo, ft->_uhi}, ft->_bits},
1985                         this->_widen, false))->hashcons();
1986   }
1987   return ft;
1988 }
1989 
1990 //------------------------------eq---------------------------------------------
1991 // Structural equality check for Type representations
1992 bool TypeInt::eq(const Type* t) const {
1993   const TypeInt* r = t->is_int();
1994   return TypeIntHelper::int_type_is_equal(this, r) && _widen == r->_widen && _is_dual == r->_is_dual;
1995 }
1996 
1997 //------------------------------hash-------------------------------------------
1998 // Type-specific hashing function.
1999 uint TypeInt::hash(void) const {
2000   return (uint)_lo + (uint)_hi + (uint)_ulo + (uint)_uhi +
2001          (uint)_bits._zeros + (uint)_bits._ones + (uint)_widen + (uint)_is_dual + (uint)Type::Int;
2002 }
2003 
2004 //------------------------------is_finite--------------------------------------
2005 // Has a finite value
2006 bool TypeInt::is_finite() const {
2007   return true;
2008 }
2009 
2010 //------------------------------singleton--------------------------------------
2011 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2012 // constants.
2013 bool TypeInt::singleton(void) const {
2014   return _lo == _hi;
2015 }
2016 
2017 bool TypeInt::empty(void) const {
2018   return false;
2019 }
2020 
2021 //=============================================================================
2022 // Convenience common pre-built types.
2023 const TypeLong* TypeLong::MAX;
2024 const TypeLong* TypeLong::MIN;
2025 const TypeLong* TypeLong::MINUS_1;// -1
2026 const TypeLong* TypeLong::ZERO; // 0
2027 const TypeLong* TypeLong::ONE;  // 1
2028 const TypeLong* TypeLong::NON_ZERO;
2029 const TypeLong* TypeLong::POS;  // >=0
2030 const TypeLong* TypeLong::NEG;
2031 const TypeLong* TypeLong::LONG; // 64-bit integers
2032 const TypeLong* TypeLong::INT;  // 32-bit subrange
2033 const TypeLong* TypeLong::UINT; // 32-bit unsigned subrange
2034 const TypeLong* TypeLong::TYPE_DOMAIN; // alias for TypeLong::LONG
2035 
2036 TypeLong::TypeLong(const TypeIntPrototype<jlong, julong>& t, int widen, bool dual)
2037   : TypeInteger(Long, t.normalize_widen(widen), dual), _lo(t._srange._lo), _hi(t._srange._hi),
2038     _ulo(t._urange._lo), _uhi(t._urange._hi), _bits(t._bits) {
2039   DEBUG_ONLY(t.verify_constraints());
2040 }
2041 
2042 const Type* TypeLong::make_or_top(const TypeIntPrototype<jlong, julong>& t, int widen, bool dual) {
2043   auto canonicalized_t = t.canonicalize_constraints();
2044   if (canonicalized_t.empty()) {
2045     return dual ? Type::BOTTOM : Type::TOP;
2046   }
2047   return (new TypeLong(canonicalized_t._data, widen, dual))->hashcons()->is_long();
2048 }
2049 
2050 const TypeLong* TypeLong::make(jlong con) {
2051   julong ucon = con;
2052   return (new TypeLong(TypeIntPrototype<jlong, julong>{{con, con}, {ucon, ucon}, {~ucon, ucon}},
2053                        WidenMin, false))->hashcons()->is_long();
2054 }
2055 
2056 const TypeLong* TypeLong::make(jlong lo, jlong hi, int widen) {
2057   assert(lo <= hi, "must be legal bounds");
2058   return make_or_top(TypeIntPrototype<jlong, julong>{{lo, hi}, {0, max_julong}, {0, 0}}, widen)->is_long();
2059 }
2060 
2061 const Type* TypeLong::make_or_top(const TypeIntPrototype<jlong, julong>& t, int widen) {
2062   return make_or_top(t, widen, false);
2063 }
2064 
2065 bool TypeLong::contains(jlong i) const {
2066   assert(!_is_dual, "dual types should only be used for join calculation");
2067   julong u = i;
2068   return i >= _lo && i <= _hi &&
2069          u >= _ulo && u <= _uhi &&
2070          _bits.is_satisfied_by(u);
2071 }
2072 
2073 bool TypeLong::contains(const TypeLong* t) const {
2074   assert(!_is_dual && !t->_is_dual, "dual types should only be used for join calculation");
2075   return TypeIntHelper::int_type_is_subset(this, t);
2076 }
2077 
2078 #ifdef ASSERT
2079 bool TypeLong::strictly_contains(const TypeLong* t) const {
2080   assert(!_is_dual && !t->_is_dual, "dual types should only be used for join calculation");
2081   return TypeIntHelper::int_type_is_subset(this, t) && !TypeIntHelper::int_type_is_equal(this, t);
2082 }
2083 #endif // ASSERT
2084 
2085 const Type* TypeLong::xmeet(const Type* t) const {
2086   return TypeIntHelper::int_type_xmeet(this, t);
2087 }
2088 
2089 const Type* TypeLong::xdual() const {
2090   return new TypeLong(TypeIntPrototype<jlong, julong>{{_lo, _hi}, {_ulo, _uhi}, _bits},
2091                       _widen, !_is_dual);
2092 }
2093 
2094 const Type* TypeLong::widen(const Type* old, const Type* limit) const {
2095   assert(!_is_dual, "dual types should only be used for join calculation");
2096   return TypeIntHelper::int_type_widen(this, old->isa_long(), limit->isa_long());
2097 }
2098 
2099 const Type* TypeLong::narrow(const Type* old) const {
2100   assert(!_is_dual, "dual types should only be used for join calculation");
2101   if (old == nullptr) {
2102     return this;
2103   }
2104 
2105   return TypeIntHelper::int_type_narrow(this, old->isa_long());
2106 }
2107 
2108 //-----------------------------filter------------------------------------------
2109 const Type* TypeLong::filter_helper(const Type* kills, bool include_speculative) const {
2110   assert(!_is_dual, "dual types should only be used for join calculation");
2111   const TypeLong* ft = join_helper(kills, include_speculative)->isa_long();
2112   if (ft == nullptr) {
2113     return Type::TOP;           // Canonical empty value
2114   }
2115   assert(!ft->_is_dual, "dual types should only be used for join calculation");
2116   if (ft->_widen < this->_widen) {
2117     // Do not allow the value of kill->_widen to affect the outcome.
2118     // The widen bits must be allowed to run freely through the graph.
2119     return (new TypeLong(TypeIntPrototype<jlong, julong>{{ft->_lo, ft->_hi}, {ft->_ulo, ft->_uhi}, ft->_bits},
2120                          this->_widen, false))->hashcons();
2121   }
2122   return ft;
2123 }
2124 
2125 //------------------------------eq---------------------------------------------
2126 // Structural equality check for Type representations
2127 bool TypeLong::eq(const Type* t) const {
2128   const TypeLong* r = t->is_long();
2129   return TypeIntHelper::int_type_is_equal(this, r) && _widen == r->_widen && _is_dual == r->_is_dual;
2130 }
2131 
2132 //------------------------------hash-------------------------------------------
2133 // Type-specific hashing function.
2134 uint TypeLong::hash(void) const {
2135   return (uint)_lo + (uint)_hi + (uint)_ulo + (uint)_uhi +
2136          (uint)_bits._zeros + (uint)_bits._ones + (uint)_widen + (uint)_is_dual + (uint)Type::Long;
2137 }
2138 
2139 //------------------------------is_finite--------------------------------------
2140 // Has a finite value
2141 bool TypeLong::is_finite() const {
2142   return true;
2143 }
2144 
2145 //------------------------------singleton--------------------------------------
2146 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2147 // constants
2148 bool TypeLong::singleton(void) const {
2149   return _lo == _hi;
2150 }
2151 
2152 bool TypeLong::empty(void) const {
2153   return false;
2154 }
2155 
2156 //------------------------------dump2------------------------------------------
2157 #ifndef PRODUCT
2158 void TypeInt::dump2(Dict& d, uint depth, outputStream* st) const {
2159   TypeIntHelper::int_type_dump(this, st, false);
2160 }
2161 
2162 void TypeInt::dump_verbose() const {
2163   TypeIntHelper::int_type_dump(this, tty, true);
2164 }
2165 
2166 void TypeLong::dump2(Dict& d, uint depth, outputStream* st) const {
2167   TypeIntHelper::int_type_dump(this, st, false);
2168 }
2169 
2170 void TypeLong::dump_verbose() const {
2171   TypeIntHelper::int_type_dump(this, tty, true);
2172 }
2173 #endif
2174 
2175 //=============================================================================
2176 // Convenience common pre-built types.
2177 const TypeTuple *TypeTuple::IFBOTH;     // Return both arms of IF as reachable
2178 const TypeTuple *TypeTuple::IFFALSE;
2179 const TypeTuple *TypeTuple::IFTRUE;
2180 const TypeTuple *TypeTuple::IFNEITHER;
2181 const TypeTuple *TypeTuple::LOOPBODY;
2182 const TypeTuple *TypeTuple::MEMBAR;
2183 const TypeTuple *TypeTuple::STORECONDITIONAL;
2184 const TypeTuple *TypeTuple::START_I2C;
2185 const TypeTuple *TypeTuple::INT_PAIR;
2186 const TypeTuple *TypeTuple::LONG_PAIR;
2187 const TypeTuple *TypeTuple::INT_CC_PAIR;
2188 const TypeTuple *TypeTuple::LONG_CC_PAIR;
2189 
2190 static void collect_inline_fields(ciInlineKlass* vk, const Type** field_array, uint& pos) {
2191   for (int i = 0; i < vk->nof_declared_nonstatic_fields(); i++) {
2192     ciField* field = vk->declared_nonstatic_field_at(i);
2193     if (field->is_flat()) {
2194       collect_inline_fields(field->type()->as_inline_klass(), field_array, pos);
2195       if (!field->is_null_free()) {
2196         // Use T_INT instead of T_BOOLEAN here because the upper bits can contain garbage if the holder
2197         // is null and C2 will only zero them for T_INT assuming that T_BOOLEAN is already canonicalized.
2198         field_array[pos++] = Type::get_const_basic_type(T_INT);
2199       }
2200     } else {
2201       BasicType bt = field->type()->basic_type();
2202       const Type* ft = Type::get_const_type(field->type());
2203       field_array[pos++] = ft;
2204       if (type2size[bt] == 2) {
2205         field_array[pos++] = Type::HALF;
2206       }
2207     }
2208   }
2209 }
2210 
2211 //------------------------------make-------------------------------------------
2212 // Make a TypeTuple from the range of a method signature
2213 const TypeTuple* TypeTuple::make_range(ciSignature* sig, InterfaceHandling interface_handling, bool ret_vt_fields, bool is_call) {
2214   ciType* return_type = sig->return_type();
2215   uint arg_cnt = return_type->size();
2216   if (ret_vt_fields) {
2217     arg_cnt = return_type->as_inline_klass()->inline_arg_slots() + 1;
2218     if (is_call) {
2219       // InlineTypeNode::NullMarker field returned by scalarized calls
2220       arg_cnt++;
2221     }
2222   }
2223   const Type **field_array = fields(arg_cnt);
2224   switch (return_type->basic_type()) {
2225   case T_LONG:
2226     field_array[TypeFunc::Parms]   = TypeLong::LONG;
2227     field_array[TypeFunc::Parms+1] = Type::HALF;
2228     break;
2229   case T_DOUBLE:
2230     field_array[TypeFunc::Parms]   = Type::DOUBLE;
2231     field_array[TypeFunc::Parms+1] = Type::HALF;
2232     break;
2233   case T_OBJECT:
2234     if (ret_vt_fields) {
2235       uint pos = TypeFunc::Parms;
2236       field_array[pos++] = get_const_type(return_type); // Oop might be null when returning as fields
2237       collect_inline_fields(return_type->as_inline_klass(), field_array, pos);
2238       if (is_call) {
2239         // InlineTypeNode::NullMarker field returned by scalarized calls
2240         field_array[pos++] = get_const_basic_type(T_BOOLEAN);
2241       }
2242       assert(pos == (TypeFunc::Parms + arg_cnt), "out of bounds");
2243       break;
2244     } else {
2245       field_array[TypeFunc::Parms] = get_const_type(return_type, interface_handling)->join_speculative(TypePtr::BOTTOM);
2246     }
2247     break;
2248   case T_ARRAY:
2249   case T_BOOLEAN:
2250   case T_CHAR:
2251   case T_FLOAT:
2252   case T_BYTE:
2253   case T_SHORT:
2254   case T_INT:
2255     field_array[TypeFunc::Parms] = get_const_type(return_type, interface_handling);
2256     break;
2257   case T_VOID:
2258     break;
2259   default:
2260     ShouldNotReachHere();
2261   }
2262   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2263 }
2264 
2265 // Make a TypeTuple from the domain of a method signature
2266 const TypeTuple *TypeTuple::make_domain(ciMethod* method, InterfaceHandling interface_handling, bool vt_fields_as_args) {
2267   ciSignature* sig = method->signature();
2268   uint arg_cnt = sig->size() + (method->is_static() ? 0 : 1);
2269   if (vt_fields_as_args) {
2270     arg_cnt = 0;
2271     assert(method->get_sig_cc() != nullptr, "Should have scalarized signature");
2272     for (ExtendedSignature sig_cc = ExtendedSignature(method->get_sig_cc(), SigEntryFilter()); !sig_cc.at_end(); ++sig_cc) {
2273       arg_cnt += type2size[(*sig_cc)._bt];
2274     }
2275   }
2276 
2277   uint pos = TypeFunc::Parms;
2278   const Type** field_array = fields(arg_cnt);
2279   if (!method->is_static()) {
2280     ciInstanceKlass* recv = method->holder();
2281     if (vt_fields_as_args && recv->is_inlinetype() && recv->as_inline_klass()->can_be_passed_as_fields() && method->is_scalarized_arg(0)) {
2282       field_array[pos++] = get_const_type(recv, interface_handling); // buffer argument
2283       collect_inline_fields(recv->as_inline_klass(), field_array, pos);
2284     } else {
2285       field_array[pos++] = get_const_type(recv, interface_handling)->join_speculative(TypePtr::NOTNULL);
2286     }
2287   }
2288 
2289   int i = 0;
2290   while (pos < TypeFunc::Parms + arg_cnt) {
2291     ciType* type = sig->type_at(i);
2292     BasicType bt = type->basic_type();
2293 
2294     switch (bt) {
2295     case T_LONG:
2296       field_array[pos++] = TypeLong::LONG;
2297       field_array[pos++] = Type::HALF;
2298       break;
2299     case T_DOUBLE:
2300       field_array[pos++] = Type::DOUBLE;
2301       field_array[pos++] = Type::HALF;
2302       break;
2303     case T_OBJECT:
2304       if (type->is_inlinetype() && vt_fields_as_args && method->is_scalarized_arg(i + (method->is_static() ? 0 : 1))) {
2305         field_array[pos++] = get_const_type(type, interface_handling); // buffer argument
2306         // InlineTypeNode::NullMarker field used for null checking
2307         field_array[pos++] = get_const_basic_type(T_BOOLEAN);
2308         collect_inline_fields(type->as_inline_klass(), field_array, pos);
2309       } else {
2310         field_array[pos++] = get_const_type(type, interface_handling);
2311       }
2312       break;
2313     case T_ARRAY:
2314     case T_FLOAT:
2315     case T_INT:
2316       field_array[pos++] = get_const_type(type, interface_handling);
2317       break;
2318     case T_BOOLEAN:
2319     case T_CHAR:
2320     case T_BYTE:
2321     case T_SHORT:
2322       field_array[pos++] = TypeInt::INT;
2323       break;
2324     default:
2325       ShouldNotReachHere();
2326     }
2327     i++;
2328   }
2329   assert(pos == TypeFunc::Parms + arg_cnt, "wrong number of arguments");
2330 
2331   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2332 }
2333 
2334 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2335   return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2336 }
2337 
2338 //------------------------------fields-----------------------------------------
2339 // Subroutine call type with space allocated for argument types
2340 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
2341 const Type **TypeTuple::fields( uint arg_cnt ) {
2342   const Type **flds = (const Type **)(Compile::current()->type_arena()->AmallocWords((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
2343   flds[TypeFunc::Control  ] = Type::CONTROL;
2344   flds[TypeFunc::I_O      ] = Type::ABIO;
2345   flds[TypeFunc::Memory   ] = Type::MEMORY;
2346   flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
2347   flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
2348 
2349   return flds;
2350 }
2351 
2352 //------------------------------meet-------------------------------------------
2353 // Compute the MEET of two types.  It returns a new Type object.
2354 const Type *TypeTuple::xmeet( const Type *t ) const {
2355   // Perform a fast test for common case; meeting the same types together.
2356   if( this == t ) return this;  // Meeting same type-rep?
2357 
2358   // Current "this->_base" is Tuple
2359   switch (t->base()) {          // switch on original type
2360 
2361   case Bottom:                  // Ye Olde Default
2362     return t;
2363 
2364   default:                      // All else is a mistake
2365     typerr(t);
2366 
2367   case Tuple: {                 // Meeting 2 signatures?
2368     const TypeTuple *x = t->is_tuple();
2369     assert( _cnt == x->_cnt, "" );
2370     const Type **fields = (const Type **)(Compile::current()->type_arena()->AmallocWords( _cnt*sizeof(Type*) ));
2371     for( uint i=0; i<_cnt; i++ )
2372       fields[i] = field_at(i)->xmeet( x->field_at(i) );
2373     return TypeTuple::make(_cnt,fields);
2374   }
2375   case Top:
2376     break;
2377   }
2378   return this;                  // Return the double constant
2379 }
2380 
2381 //------------------------------xdual------------------------------------------
2382 // Dual: compute field-by-field dual
2383 const Type *TypeTuple::xdual() const {
2384   const Type **fields = (const Type **)(Compile::current()->type_arena()->AmallocWords( _cnt*sizeof(Type*) ));
2385   for( uint i=0; i<_cnt; i++ )
2386     fields[i] = _fields[i]->dual();
2387   return new TypeTuple(_cnt,fields);
2388 }
2389 
2390 //------------------------------eq---------------------------------------------
2391 // Structural equality check for Type representations
2392 bool TypeTuple::eq( const Type *t ) const {
2393   const TypeTuple *s = (const TypeTuple *)t;
2394   if (_cnt != s->_cnt)  return false;  // Unequal field counts
2395   for (uint i = 0; i < _cnt; i++)
2396     if (field_at(i) != s->field_at(i)) // POINTER COMPARE!  NO RECURSION!
2397       return false;             // Missed
2398   return true;
2399 }
2400 
2401 //------------------------------hash-------------------------------------------
2402 // Type-specific hashing function.
2403 uint TypeTuple::hash(void) const {
2404   uintptr_t sum = _cnt;
2405   for( uint i=0; i<_cnt; i++ )
2406     sum += (uintptr_t)_fields[i];     // Hash on pointers directly
2407   return (uint)sum;
2408 }
2409 
2410 //------------------------------dump2------------------------------------------
2411 // Dump signature Type
2412 #ifndef PRODUCT
2413 void TypeTuple::dump2( Dict &d, uint depth, outputStream *st ) const {
2414   st->print("{");
2415   if( !depth || d[this] ) {     // Check for recursive print
2416     st->print("...}");
2417     return;
2418   }
2419   d.Insert((void*)this, (void*)this);   // Stop recursion
2420   if( _cnt ) {
2421     uint i;
2422     for( i=0; i<_cnt-1; i++ ) {
2423       st->print("%d:", i);
2424       _fields[i]->dump2(d, depth-1, st);
2425       st->print(", ");
2426     }
2427     st->print("%d:", i);
2428     _fields[i]->dump2(d, depth-1, st);
2429   }
2430   st->print("}");
2431 }
2432 #endif
2433 
2434 //------------------------------singleton--------------------------------------
2435 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2436 // constants (Ldi nodes).  Singletons are integer, float or double constants
2437 // or a single symbol.
2438 bool TypeTuple::singleton(void) const {
2439   return false;                 // Never a singleton
2440 }
2441 
2442 bool TypeTuple::empty(void) const {
2443   for( uint i=0; i<_cnt; i++ ) {
2444     if (_fields[i]->empty())  return true;
2445   }
2446   return false;
2447 }
2448 
2449 //=============================================================================
2450 // Convenience common pre-built types.
2451 
2452 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2453   // Certain normalizations keep us sane when comparing types.
2454   // We do not want arrayOop variables to differ only by the wideness
2455   // of their index types.  Pick minimum wideness, since that is the
2456   // forced wideness of small ranges anyway.
2457   if (size->_widen != Type::WidenMin)
2458     return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2459   else
2460     return size;
2461 }
2462 
2463 //------------------------------make-------------------------------------------
2464 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable,
2465                              bool flat, bool not_flat, bool not_null_free, bool atomic) {
2466   if (UseCompressedOops && elem->isa_oopptr()) {
2467     elem = elem->make_narrowoop();
2468   }
2469   size = normalize_array_size(size);
2470   return (TypeAry*)(new TypeAry(elem, size, stable, flat, not_flat, not_null_free, atomic))->hashcons();
2471 }
2472 
2473 //------------------------------meet-------------------------------------------
2474 // Compute the MEET of two types.  It returns a new Type object.
2475 const Type *TypeAry::xmeet( const Type *t ) const {
2476   // Perform a fast test for common case; meeting the same types together.
2477   if( this == t ) return this;  // Meeting same type-rep?
2478 
2479   // Current "this->_base" is Ary
2480   switch (t->base()) {          // switch on original type
2481 
2482   case Bottom:                  // Ye Olde Default
2483     return t;
2484 
2485   default:                      // All else is a mistake
2486     typerr(t);
2487 
2488   case Array: {                 // Meeting 2 arrays?
2489     const TypeAry* a = t->is_ary();
2490     const Type* size = _size->xmeet(a->_size);
2491     const TypeInt* isize = size->isa_int();
2492     if (isize == nullptr) {
2493       assert(size == Type::TOP || size == Type::BOTTOM, "");
2494       return size;
2495     }
2496     return TypeAry::make(_elem->meet_speculative(a->_elem),
2497                          isize, _stable && a->_stable,
2498                          _flat && a->_flat,
2499                          _not_flat && a->_not_flat,
2500                          _not_null_free && a->_not_null_free,
2501                          _atomic && a->_atomic);
2502   }
2503   case Top:
2504     break;
2505   }
2506   return this;                  // Return the double constant
2507 }
2508 
2509 //------------------------------xdual------------------------------------------
2510 // Dual: compute field-by-field dual
2511 const Type *TypeAry::xdual() const {
2512   const TypeInt* size_dual = _size->dual()->is_int();
2513   size_dual = normalize_array_size(size_dual);
2514   return new TypeAry(_elem->dual(), size_dual, !_stable, !_flat, !_not_flat, !_not_null_free, !_atomic);
2515 }
2516 
2517 //------------------------------eq---------------------------------------------
2518 // Structural equality check for Type representations
2519 bool TypeAry::eq( const Type *t ) const {
2520   const TypeAry *a = (const TypeAry*)t;
2521   return _elem == a->_elem &&
2522     _stable == a->_stable &&
2523     _size == a->_size &&
2524     _flat == a->_flat &&
2525     _not_flat == a->_not_flat &&
2526     _not_null_free == a->_not_null_free &&
2527     _atomic == a->_atomic;
2528 
2529 }
2530 
2531 //------------------------------hash-------------------------------------------
2532 // Type-specific hashing function.
2533 uint TypeAry::hash(void) const {
2534   return (uint)(uintptr_t)_elem + (uint)(uintptr_t)_size + (uint)(_stable ? 43 : 0) +
2535       (uint)(_flat ? 44 : 0) + (uint)(_not_flat ? 45 : 0) + (uint)(_not_null_free ? 46 : 0) + (uint)(_atomic ? 47 : 0);
2536 }
2537 
2538 /**
2539  * Return same type without a speculative part in the element
2540  */
2541 const TypeAry* TypeAry::remove_speculative() const {
2542   return make(_elem->remove_speculative(), _size, _stable, _flat, _not_flat, _not_null_free, _atomic);
2543 }
2544 
2545 /**
2546  * Return same type with cleaned up speculative part of element
2547  */
2548 const Type* TypeAry::cleanup_speculative() const {
2549   return make(_elem->cleanup_speculative(), _size, _stable, _flat, _not_flat, _not_null_free, _atomic);
2550 }
2551 
2552 /**
2553  * Return same type but with a different inline depth (used for speculation)
2554  *
2555  * @param depth  depth to meet with
2556  */
2557 const TypePtr* TypePtr::with_inline_depth(int depth) const {
2558   if (!UseInlineDepthForSpeculativeTypes) {
2559     return this;
2560   }
2561   return make(AnyPtr, _ptr, _offset, _speculative, depth);
2562 }
2563 
2564 //------------------------------dump2------------------------------------------
2565 #ifndef PRODUCT
2566 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2567   if (_stable)  st->print("stable:");
2568   if (_flat) st->print("flat:");
2569   if (Verbose) {
2570     if (_not_flat) st->print("not flat:");
2571     if (_not_null_free) st->print("not null free:");
2572   }
2573   if (_atomic) st->print("atomic:");
2574   _elem->dump2(d, depth, st);
2575   st->print("[");
2576   _size->dump2(d, depth, st);
2577   st->print("]");
2578 }
2579 #endif
2580 
2581 //------------------------------singleton--------------------------------------
2582 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2583 // constants (Ldi nodes).  Singletons are integer, float or double constants
2584 // or a single symbol.
2585 bool TypeAry::singleton(void) const {
2586   return false;                 // Never a singleton
2587 }
2588 
2589 bool TypeAry::empty(void) const {
2590   return _elem->empty() || _size->empty();
2591 }
2592 
2593 //--------------------------ary_must_be_exact----------------------------------
2594 bool TypeAry::ary_must_be_exact() const {
2595   // This logic looks at the element type of an array, and returns true
2596   // if the element type is either a primitive or a final instance class.
2597   // In such cases, an array built on this ary must have no subclasses.
2598   if (_elem == BOTTOM)      return false;  // general array not exact
2599   if (_elem == TOP   )      return false;  // inverted general array not exact
2600   const TypeOopPtr*  toop = nullptr;
2601   if (UseCompressedOops && _elem->isa_narrowoop()) {
2602     toop = _elem->make_ptr()->isa_oopptr();
2603   } else {
2604     toop = _elem->isa_oopptr();
2605   }
2606   if (!toop)                return true;   // a primitive type, like int
2607   if (!toop->is_loaded())   return false;  // unloaded class
2608   const TypeInstPtr* tinst;
2609   if (_elem->isa_narrowoop())
2610     tinst = _elem->make_ptr()->isa_instptr();
2611   else
2612     tinst = _elem->isa_instptr();
2613   if (tinst) {
2614     if (tinst->instance_klass()->is_final()) {
2615       // Even though MyValue is final, [LMyValue is only exact if the array
2616       // is (not) null-free due to null-free [LMyValue <: null-able [LMyValue.
2617       // TODO 8350865 If we know that the array can't be null-free, it's allowed to be exact, right?
2618       // If so, we should add '&& !_not_null_free'
2619       if (tinst->is_inlinetypeptr() && (tinst->ptr() != TypePtr::NotNull)) {
2620         return false;
2621       }
2622       return true;
2623     }
2624     return false;
2625   }
2626   const TypeAryPtr*  tap;
2627   if (_elem->isa_narrowoop())
2628     tap = _elem->make_ptr()->isa_aryptr();
2629   else
2630     tap = _elem->isa_aryptr();
2631   if (tap)
2632     return tap->ary()->ary_must_be_exact();
2633   return false;
2634 }
2635 
2636 //==============================TypeVect=======================================
2637 // Convenience common pre-built types.
2638 const TypeVect* TypeVect::VECTA = nullptr; // vector length agnostic
2639 const TypeVect* TypeVect::VECTS = nullptr; //  32-bit vectors
2640 const TypeVect* TypeVect::VECTD = nullptr; //  64-bit vectors
2641 const TypeVect* TypeVect::VECTX = nullptr; // 128-bit vectors
2642 const TypeVect* TypeVect::VECTY = nullptr; // 256-bit vectors
2643 const TypeVect* TypeVect::VECTZ = nullptr; // 512-bit vectors
2644 const TypeVect* TypeVect::VECTMASK = nullptr; // predicate/mask vector
2645 
2646 //------------------------------make-------------------------------------------
2647 const TypeVect* TypeVect::make(BasicType elem_bt, uint length, bool is_mask) {
2648   if (is_mask) {
2649     return makemask(elem_bt, length);
2650   }
2651   assert(is_java_primitive(elem_bt), "only primitive types in vector");
2652   assert(Matcher::vector_size_supported(elem_bt, length), "length in range");
2653   int size = length * type2aelembytes(elem_bt);
2654   switch (Matcher::vector_ideal_reg(size)) {
2655   case Op_VecA:
2656     return (TypeVect*)(new TypeVectA(elem_bt, length))->hashcons();
2657   case Op_VecS:
2658     return (TypeVect*)(new TypeVectS(elem_bt, length))->hashcons();
2659   case Op_RegL:
2660   case Op_VecD:
2661   case Op_RegD:
2662     return (TypeVect*)(new TypeVectD(elem_bt, length))->hashcons();
2663   case Op_VecX:
2664     return (TypeVect*)(new TypeVectX(elem_bt, length))->hashcons();
2665   case Op_VecY:
2666     return (TypeVect*)(new TypeVectY(elem_bt, length))->hashcons();
2667   case Op_VecZ:
2668     return (TypeVect*)(new TypeVectZ(elem_bt, length))->hashcons();
2669   }
2670  ShouldNotReachHere();
2671   return nullptr;
2672 }
2673 
2674 // Create a vector mask type with the given element basic type and length.
2675 // - Returns "TypeVectMask" (PVectMask) for platforms that support the predicate
2676 //   feature and it is implemented properly in the backend, allowing the mask to
2677 //   be stored in a predicate/mask register.
2678 // - Returns a normal vector type "TypeVectA ~ TypeVectZ" (NVectMask) otherwise,
2679 //   where the vector mask is stored in a vector register.
2680 const TypeVect* TypeVect::makemask(BasicType elem_bt, uint length) {
2681   if (Matcher::has_predicated_vectors() &&
2682       Matcher::match_rule_supported_vector_masked(Op_VectorLoadMask, length, elem_bt)) {
2683     return TypeVectMask::make(elem_bt, length);
2684   } else {
2685     return make(elem_bt, length);
2686   }
2687 }
2688 
2689 //------------------------------meet-------------------------------------------
2690 // Compute the MEET of two types. Since each TypeVect is the only instance of
2691 // its species, meeting often returns itself
2692 const Type* TypeVect::xmeet(const Type* t) const {
2693   // Perform a fast test for common case; meeting the same types together.
2694   if (this == t) {
2695     return this;
2696   }
2697 
2698   // Current "this->_base" is Vector
2699   switch (t->base()) {          // switch on original type
2700 
2701   case Bottom:                  // Ye Olde Default
2702     return t;
2703 
2704   default:                      // All else is a mistake
2705     typerr(t);
2706   case VectorMask:
2707   case VectorA:
2708   case VectorS:
2709   case VectorD:
2710   case VectorX:
2711   case VectorY:
2712   case VectorZ: {                // Meeting 2 vectors?
2713     const TypeVect* v = t->is_vect();
2714     assert(base() == v->base(), "");
2715     assert(length() == v->length(), "");
2716     assert(element_basic_type() == v->element_basic_type(), "");
2717     return this;
2718   }
2719   case Top:
2720     break;
2721   }
2722   return this;
2723 }
2724 
2725 //------------------------------xdual------------------------------------------
2726 // Since each TypeVect is the only instance of its species, it is self-dual
2727 const Type* TypeVect::xdual() const {
2728   return this;
2729 }
2730 
2731 //------------------------------eq---------------------------------------------
2732 // Structural equality check for Type representations
2733 bool TypeVect::eq(const Type* t) const {
2734   const TypeVect* v = t->is_vect();
2735   return (element_basic_type() == v->element_basic_type()) && (length() == v->length());
2736 }
2737 
2738 //------------------------------hash-------------------------------------------
2739 // Type-specific hashing function.
2740 uint TypeVect::hash(void) const {
2741   return (uint)base() + (uint)(uintptr_t)_elem_bt + (uint)(uintptr_t)_length;
2742 }
2743 
2744 //------------------------------singleton--------------------------------------
2745 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2746 // constants (Ldi nodes).  Vector is singleton if all elements are the same
2747 // constant value (when vector is created with Replicate code).
2748 bool TypeVect::singleton(void) const {
2749 // There is no Con node for vectors yet.
2750 //  return _elem->singleton();
2751   return false;
2752 }
2753 
2754 bool TypeVect::empty(void) const {
2755   return false;
2756 }
2757 
2758 //------------------------------dump2------------------------------------------
2759 #ifndef PRODUCT
2760 void TypeVect::dump2(Dict& d, uint depth, outputStream* st) const {
2761   switch (base()) {
2762   case VectorA:
2763     st->print("vectora"); break;
2764   case VectorS:
2765     st->print("vectors"); break;
2766   case VectorD:
2767     st->print("vectord"); break;
2768   case VectorX:
2769     st->print("vectorx"); break;
2770   case VectorY:
2771     st->print("vectory"); break;
2772   case VectorZ:
2773     st->print("vectorz"); break;
2774   case VectorMask:
2775     st->print("vectormask"); break;
2776   default:
2777     ShouldNotReachHere();
2778   }
2779   st->print("<%c,%u>", type2char(element_basic_type()), length());
2780 }
2781 #endif
2782 
2783 const TypeVectMask* TypeVectMask::make(const BasicType elem_bt, uint length) {
2784   return (TypeVectMask*) (new TypeVectMask(elem_bt, length))->hashcons();
2785 }
2786 
2787 //=============================================================================
2788 // Convenience common pre-built types.
2789 const TypePtr *TypePtr::NULL_PTR;
2790 const TypePtr *TypePtr::NOTNULL;
2791 const TypePtr *TypePtr::BOTTOM;
2792 
2793 //------------------------------meet-------------------------------------------
2794 // Meet over the PTR enum
2795 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2796   //              TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,
2797   { /* Top     */ TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,},
2798   { /* AnyNull */ AnyNull,   AnyNull,   Constant, BotPTR, NotNull, BotPTR,},
2799   { /* Constant*/ Constant,  Constant,  Constant, BotPTR, NotNull, BotPTR,},
2800   { /* Null    */ Null,      BotPTR,    BotPTR,   Null,   BotPTR,  BotPTR,},
2801   { /* NotNull */ NotNull,   NotNull,   NotNull,  BotPTR, NotNull, BotPTR,},
2802   { /* BotPTR  */ BotPTR,    BotPTR,    BotPTR,   BotPTR, BotPTR,  BotPTR,}
2803 };
2804 
2805 //------------------------------make-------------------------------------------
2806 const TypePtr* TypePtr::make(TYPES t, enum PTR ptr, Offset offset, const TypePtr* speculative, int inline_depth) {
2807   return (TypePtr*)(new TypePtr(t,ptr,offset, speculative, inline_depth))->hashcons();
2808 }
2809 
2810 //------------------------------cast_to_ptr_type-------------------------------
2811 const TypePtr* TypePtr::cast_to_ptr_type(PTR ptr) const {
2812   assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2813   if( ptr == _ptr ) return this;
2814   return make(_base, ptr, _offset, _speculative, _inline_depth);
2815 }
2816 
2817 //------------------------------get_con----------------------------------------
2818 intptr_t TypePtr::get_con() const {
2819   assert( _ptr == Null, "" );
2820   return offset();
2821 }
2822 
2823 //------------------------------meet-------------------------------------------
2824 // Compute the MEET of two types.  It returns a new Type object.
2825 const Type *TypePtr::xmeet(const Type *t) const {
2826   const Type* res = xmeet_helper(t);
2827   if (res->isa_ptr() == nullptr) {
2828     return res;
2829   }
2830 
2831   const TypePtr* res_ptr = res->is_ptr();
2832   if (res_ptr->speculative() != nullptr) {
2833     // type->speculative() is null means that speculation is no better
2834     // than type, i.e. type->speculative() == type. So there are 2
2835     // ways to represent the fact that we have no useful speculative
2836     // data and we should use a single one to be able to test for
2837     // equality between types. Check whether type->speculative() ==
2838     // type and set speculative to null if it is the case.
2839     if (res_ptr->remove_speculative() == res_ptr->speculative()) {
2840       return res_ptr->remove_speculative();
2841     }
2842   }
2843 
2844   return res;
2845 }
2846 
2847 const Type *TypePtr::xmeet_helper(const Type *t) const {
2848   // Perform a fast test for common case; meeting the same types together.
2849   if( this == t ) return this;  // Meeting same type-rep?
2850 
2851   // Current "this->_base" is AnyPtr
2852   switch (t->base()) {          // switch on original type
2853   case Int:                     // Mixing ints & oops happens when javac
2854   case Long:                    // reuses local variables
2855   case HalfFloatTop:
2856   case HalfFloatCon:
2857   case HalfFloatBot:
2858   case FloatTop:
2859   case FloatCon:
2860   case FloatBot:
2861   case DoubleTop:
2862   case DoubleCon:
2863   case DoubleBot:
2864   case NarrowOop:
2865   case NarrowKlass:
2866   case Bottom:                  // Ye Olde Default
2867     return Type::BOTTOM;
2868   case Top:
2869     return this;
2870 
2871   case AnyPtr: {                // Meeting to AnyPtrs
2872     const TypePtr *tp = t->is_ptr();
2873     const TypePtr* speculative = xmeet_speculative(tp);
2874     int depth = meet_inline_depth(tp->inline_depth());
2875     return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2876   }
2877   case RawPtr:                  // For these, flip the call around to cut down
2878   case OopPtr:
2879   case InstPtr:                 // on the cases I have to handle.
2880   case AryPtr:
2881   case MetadataPtr:
2882   case KlassPtr:
2883   case InstKlassPtr:
2884   case AryKlassPtr:
2885     return t->xmeet(this);      // Call in reverse direction
2886   default:                      // All else is a mistake
2887     typerr(t);
2888 
2889   }
2890   return this;
2891 }
2892 
2893 //------------------------------meet_offset------------------------------------
2894 Type::Offset TypePtr::meet_offset(int offset) const {
2895   return _offset.meet(Offset(offset));





2896 }
2897 
2898 //------------------------------dual_offset------------------------------------
2899 Type::Offset TypePtr::dual_offset() const {
2900   return _offset.dual();


2901 }
2902 
2903 //------------------------------xdual------------------------------------------
2904 // Dual: compute field-by-field dual
2905 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2906   BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2907 };
2908 
2909 const TypePtr::FlatInArray TypePtr::flat_in_array_dual[Uninitialized] = {
2910   /* TopFlat   -> */ MaybeFlat,
2911   /* Flat      -> */ NotFlat,
2912   /* NotFlat   -> */ Flat,
2913   /* MaybeFlat -> */ TopFlat
2914 };
2915 
2916 const char* const TypePtr::flat_in_array_msg[Uninitialized] = {
2917   "TOP flat in array", "flat in array", "not flat in array", "maybe flat in array"
2918 };
2919 
2920 const Type *TypePtr::xdual() const {
2921   return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
2922 }
2923 
2924 //------------------------------xadd_offset------------------------------------
2925 Type::Offset TypePtr::xadd_offset(intptr_t offset) const {
2926   return _offset.add(offset);











2927 }
2928 
2929 //------------------------------add_offset-------------------------------------
2930 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2931   return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth);
2932 }
2933 
2934 const TypePtr *TypePtr::with_offset(intptr_t offset) const {
2935   return make(AnyPtr, _ptr, Offset(offset), _speculative, _inline_depth);
2936 }
2937 
2938 //------------------------------eq---------------------------------------------
2939 // Structural equality check for Type representations
2940 bool TypePtr::eq( const Type *t ) const {
2941   const TypePtr *a = (const TypePtr*)t;
2942   return _ptr == a->ptr() && _offset == a->_offset && eq_speculative(a) && _inline_depth == a->_inline_depth;
2943 }
2944 
2945 //------------------------------hash-------------------------------------------
2946 // Type-specific hashing function.
2947 uint TypePtr::hash(void) const {
2948   return (uint)_ptr + (uint)offset() + (uint)hash_speculative() + (uint)_inline_depth;
2949 }
2950 
2951 /**
2952  * Return same type without a speculative part
2953  */
2954 const TypePtr* TypePtr::remove_speculative() const {
2955   if (_speculative == nullptr) {
2956     return this;
2957   }
2958   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2959   return make(AnyPtr, _ptr, _offset, nullptr, _inline_depth);
2960 }
2961 
2962 /**
2963  * Return same type but drop speculative part if we know we won't use
2964  * it
2965  */
2966 const Type* TypePtr::cleanup_speculative() const {
2967   if (speculative() == nullptr) {
2968     return this;
2969   }
2970   const Type* no_spec = remove_speculative();
2971   // If this is NULL_PTR then we don't need the speculative type
2972   // (with_inline_depth in case the current type inline depth is
2973   // InlineDepthTop)
2974   if (no_spec == NULL_PTR->with_inline_depth(inline_depth())) {
2975     return no_spec;
2976   }
2977   if (above_centerline(speculative()->ptr())) {
2978     return no_spec;
2979   }
2980   const TypeOopPtr* spec_oopptr = speculative()->isa_oopptr();
2981   // If the speculative may be null and is an inexact klass then it
2982   // doesn't help
2983   if (speculative() != TypePtr::NULL_PTR && speculative()->maybe_null() &&
2984       (spec_oopptr == nullptr || !spec_oopptr->klass_is_exact())) {
2985     return no_spec;
2986   }
2987   return this;
2988 }
2989 
2990 /**
2991  * dual of the speculative part of the type
2992  */
2993 const TypePtr* TypePtr::dual_speculative() const {
2994   if (_speculative == nullptr) {
2995     return nullptr;
2996   }
2997   return _speculative->dual()->is_ptr();
2998 }
2999 
3000 /**
3001  * meet of the speculative parts of 2 types
3002  *
3003  * @param other  type to meet with
3004  */
3005 const TypePtr* TypePtr::xmeet_speculative(const TypePtr* other) const {
3006   bool this_has_spec = (_speculative != nullptr);
3007   bool other_has_spec = (other->speculative() != nullptr);
3008 
3009   if (!this_has_spec && !other_has_spec) {
3010     return nullptr;
3011   }
3012 
3013   // If we are at a point where control flow meets and one branch has
3014   // a speculative type and the other has not, we meet the speculative
3015   // type of one branch with the actual type of the other. If the
3016   // actual type is exact and the speculative is as well, then the
3017   // result is a speculative type which is exact and we can continue
3018   // speculation further.
3019   const TypePtr* this_spec = _speculative;
3020   const TypePtr* other_spec = other->speculative();
3021 
3022   if (!this_has_spec) {
3023     this_spec = this;
3024   }
3025 
3026   if (!other_has_spec) {
3027     other_spec = other;
3028   }
3029 
3030   return this_spec->meet(other_spec)->is_ptr();
3031 }
3032 
3033 /**
3034  * dual of the inline depth for this type (used for speculation)
3035  */
3036 int TypePtr::dual_inline_depth() const {
3037   return -inline_depth();
3038 }
3039 
3040 /**
3041  * meet of 2 inline depths (used for speculation)
3042  *
3043  * @param depth  depth to meet with
3044  */
3045 int TypePtr::meet_inline_depth(int depth) const {
3046   return MAX2(inline_depth(), depth);
3047 }
3048 
3049 /**
3050  * Are the speculative parts of 2 types equal?
3051  *
3052  * @param other  type to compare this one to
3053  */
3054 bool TypePtr::eq_speculative(const TypePtr* other) const {
3055   if (_speculative == nullptr || other->speculative() == nullptr) {
3056     return _speculative == other->speculative();
3057   }
3058 
3059   if (_speculative->base() != other->speculative()->base()) {
3060     return false;
3061   }
3062 
3063   return _speculative->eq(other->speculative());
3064 }
3065 
3066 /**
3067  * Hash of the speculative part of the type
3068  */
3069 int TypePtr::hash_speculative() const {
3070   if (_speculative == nullptr) {
3071     return 0;
3072   }
3073 
3074   return _speculative->hash();
3075 }
3076 
3077 /**
3078  * add offset to the speculative part of the type
3079  *
3080  * @param offset  offset to add
3081  */
3082 const TypePtr* TypePtr::add_offset_speculative(intptr_t offset) const {
3083   if (_speculative == nullptr) {
3084     return nullptr;
3085   }
3086   return _speculative->add_offset(offset)->is_ptr();
3087 }
3088 
3089 const TypePtr* TypePtr::with_offset_speculative(intptr_t offset) const {
3090   if (_speculative == nullptr) {
3091     return nullptr;
3092   }
3093   return _speculative->with_offset(offset)->is_ptr();
3094 }
3095 
3096 /**
3097  * return exact klass from the speculative type if there's one
3098  */
3099 ciKlass* TypePtr::speculative_type() const {
3100   if (_speculative != nullptr && _speculative->isa_oopptr()) {
3101     const TypeOopPtr* speculative = _speculative->join(this)->is_oopptr();
3102     if (speculative->klass_is_exact()) {
3103       return speculative->exact_klass();
3104     }
3105   }
3106   return nullptr;
3107 }
3108 
3109 /**
3110  * return true if speculative type may be null
3111  */
3112 bool TypePtr::speculative_maybe_null() const {
3113   if (_speculative != nullptr) {
3114     const TypePtr* speculative = _speculative->join(this)->is_ptr();
3115     return speculative->maybe_null();
3116   }
3117   return true;
3118 }
3119 
3120 bool TypePtr::speculative_always_null() const {
3121   if (_speculative != nullptr) {
3122     const TypePtr* speculative = _speculative->join(this)->is_ptr();
3123     return speculative == TypePtr::NULL_PTR;
3124   }
3125   return false;
3126 }
3127 
3128 /**
3129  * Same as TypePtr::speculative_type() but return the klass only if
3130  * the speculative tells us is not null
3131  */
3132 ciKlass* TypePtr::speculative_type_not_null() const {
3133   if (speculative_maybe_null()) {
3134     return nullptr;
3135   }
3136   return speculative_type();
3137 }
3138 
3139 /**
3140  * Check whether new profiling would improve speculative type
3141  *
3142  * @param   exact_kls    class from profiling
3143  * @param   inline_depth inlining depth of profile point
3144  *
3145  * @return  true if type profile is valuable
3146  */
3147 bool TypePtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
3148   // no profiling?
3149   if (exact_kls == nullptr) {
3150     return false;
3151   }
3152   if (speculative() == TypePtr::NULL_PTR) {
3153     return false;
3154   }
3155   // no speculative type or non exact speculative type?
3156   if (speculative_type() == nullptr) {
3157     return true;
3158   }
3159   // If the node already has an exact speculative type keep it,
3160   // unless it was provided by profiling that is at a deeper
3161   // inlining level. Profiling at a higher inlining depth is
3162   // expected to be less accurate.
3163   if (_speculative->inline_depth() == InlineDepthBottom) {
3164     return false;
3165   }
3166   assert(_speculative->inline_depth() != InlineDepthTop, "can't do the comparison");
3167   return inline_depth < _speculative->inline_depth();
3168 }
3169 
3170 /**
3171  * Check whether new profiling would improve ptr (= tells us it is non
3172  * null)
3173  *
3174  * @param   ptr_kind always null or not null?
3175  *
3176  * @return  true if ptr profile is valuable
3177  */
3178 bool TypePtr::would_improve_ptr(ProfilePtrKind ptr_kind) const {
3179   // profiling doesn't tell us anything useful
3180   if (ptr_kind != ProfileAlwaysNull && ptr_kind != ProfileNeverNull) {
3181     return false;
3182   }
3183   // We already know this is not null
3184   if (!this->maybe_null()) {
3185     return false;
3186   }
3187   // We already know the speculative type cannot be null
3188   if (!speculative_maybe_null()) {
3189     return false;
3190   }
3191   // We already know this is always null
3192   if (this == TypePtr::NULL_PTR) {
3193     return false;
3194   }
3195   // We already know the speculative type is always null
3196   if (speculative_always_null()) {
3197     return false;
3198   }
3199   if (ptr_kind == ProfileAlwaysNull && speculative() != nullptr && speculative()->isa_oopptr()) {
3200     return false;
3201   }
3202   return true;
3203 }
3204 
3205 TypePtr::FlatInArray TypePtr::compute_flat_in_array(ciInstanceKlass* instance_klass, bool is_exact) {
3206   if (!instance_klass->can_be_inline_klass(is_exact)) {
3207     // Definitely not a value class and thus never flat in an array.
3208     return NotFlat;
3209   }
3210   if (instance_klass->is_inlinetype() && instance_klass->as_inline_klass()->is_always_flat_in_array()) {
3211     return Flat;
3212   }
3213   // We don't know.
3214   return MaybeFlat;
3215 }
3216 
3217 // Compute flat in array property if we don't know anything about it (i.e. old_flat_in_array == MaybeFlat).
3218 TypePtr::FlatInArray TypePtr::compute_flat_in_array_if_unknown(ciInstanceKlass* instance_klass, bool is_exact,
3219   FlatInArray old_flat_in_array) {
3220   // It is tempting to add verification code that "NotFlat == no value class" and "Flat == value class".
3221   // However, with type speculation, we could get contradicting flat in array properties that propagate through the
3222   // graph. We could try to stop the introduction of contradicting speculative types in terms of their flat in array
3223   // property. But this is hard because it is sometimes only recognized further down in the graph. Thus, we let an
3224   // inconsistent flat in array property propagating through the graph. This could lead to fold an actual live path
3225   // away. But in this case, the speculated type is wrong and we would trap earlier.
3226   if (old_flat_in_array == MaybeFlat) {
3227       return compute_flat_in_array(instance_klass, is_exact);
3228   }
3229   return old_flat_in_array;
3230 }
3231 
3232 //------------------------------dump2------------------------------------------
3233 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
3234   "TopPTR","AnyNull","Constant","null","NotNull","BotPTR"
3235 };
3236 
3237 #ifndef PRODUCT
3238 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3239   st->print("ptr:%s", ptr_msg[_ptr]);
3240   dump_offset(st);
3241   dump_inline_depth(st);
3242   dump_speculative(st);
3243 }
3244 
3245 void TypePtr::dump_offset(outputStream* st) const {
3246   _offset.dump2(st);






3247 }
3248 
3249 /**
3250  *dump the speculative part of the type
3251  */
3252 void TypePtr::dump_speculative(outputStream *st) const {
3253   if (_speculative != nullptr) {
3254     st->print(" (speculative=");
3255     _speculative->dump_on(st);
3256     st->print(")");
3257   }
3258 }
3259 
3260 /**
3261  *dump the inline depth of the type
3262  */
3263 void TypePtr::dump_inline_depth(outputStream *st) const {
3264   if (_inline_depth != InlineDepthBottom) {
3265     if (_inline_depth == InlineDepthTop) {
3266       st->print(" (inline_depth=InlineDepthTop)");
3267     } else {
3268       st->print(" (inline_depth=%d)", _inline_depth);
3269     }
3270   }
3271 }
3272 
3273 void TypePtr::dump_flat_in_array(FlatInArray flat_in_array, outputStream* st) {
3274   switch (flat_in_array) {
3275     case MaybeFlat:
3276     case NotFlat:
3277       if (!Verbose) {
3278         break;
3279       }
3280     case TopFlat:
3281     case Flat:
3282       st->print(" (%s)", flat_in_array_msg[flat_in_array]);
3283       break;
3284     default:
3285       ShouldNotReachHere();
3286   }
3287 }
3288 #endif
3289 
3290 //------------------------------singleton--------------------------------------
3291 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3292 // constants
3293 bool TypePtr::singleton(void) const {
3294   // TopPTR, Null, AnyNull, Constant are all singletons
3295   return (_offset != Offset::bottom) && !below_centerline(_ptr);
3296 }
3297 
3298 bool TypePtr::empty(void) const {
3299   return (_offset == Offset::top) || above_centerline(_ptr);
3300 }
3301 
3302 //=============================================================================
3303 // Convenience common pre-built types.
3304 const TypeRawPtr *TypeRawPtr::BOTTOM;
3305 const TypeRawPtr *TypeRawPtr::NOTNULL;
3306 
3307 //------------------------------make-------------------------------------------
3308 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
3309   assert( ptr != Constant, "what is the constant?" );
3310   assert( ptr != Null, "Use TypePtr for null" );
3311   return (TypeRawPtr*)(new TypeRawPtr(ptr,nullptr))->hashcons();
3312 }
3313 
3314 const TypeRawPtr *TypeRawPtr::make(address bits) {
3315   assert(bits != nullptr, "Use TypePtr for null");
3316   return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
3317 }
3318 
3319 //------------------------------cast_to_ptr_type-------------------------------
3320 const TypeRawPtr* TypeRawPtr::cast_to_ptr_type(PTR ptr) const {
3321   assert( ptr != Constant, "what is the constant?" );
3322   assert( ptr != Null, "Use TypePtr for null" );
3323   assert( _bits == nullptr, "Why cast a constant address?");
3324   if( ptr == _ptr ) return this;
3325   return make(ptr);
3326 }
3327 
3328 //------------------------------get_con----------------------------------------
3329 intptr_t TypeRawPtr::get_con() const {
3330   assert( _ptr == Null || _ptr == Constant, "" );
3331   return (intptr_t)_bits;
3332 }
3333 
3334 //------------------------------meet-------------------------------------------
3335 // Compute the MEET of two types.  It returns a new Type object.
3336 const Type *TypeRawPtr::xmeet( const Type *t ) const {
3337   // Perform a fast test for common case; meeting the same types together.
3338   if( this == t ) return this;  // Meeting same type-rep?
3339 
3340   // Current "this->_base" is RawPtr
3341   switch( t->base() ) {         // switch on original type
3342   case Bottom:                  // Ye Olde Default
3343     return t;
3344   case Top:
3345     return this;
3346   case AnyPtr:                  // Meeting to AnyPtrs
3347     break;
3348   case RawPtr: {                // might be top, bot, any/not or constant
3349     enum PTR tptr = t->is_ptr()->ptr();
3350     enum PTR ptr = meet_ptr( tptr );
3351     if( ptr == Constant ) {     // Cannot be equal constants, so...
3352       if( tptr == Constant && _ptr != Constant)  return t;
3353       if( _ptr == Constant && tptr != Constant)  return this;
3354       ptr = NotNull;            // Fall down in lattice
3355     }
3356     return make( ptr );
3357   }
3358 
3359   case OopPtr:
3360   case InstPtr:
3361   case AryPtr:
3362   case MetadataPtr:
3363   case KlassPtr:
3364   case InstKlassPtr:
3365   case AryKlassPtr:
3366     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3367   default:                      // All else is a mistake
3368     typerr(t);
3369   }
3370 
3371   // Found an AnyPtr type vs self-RawPtr type
3372   const TypePtr *tp = t->is_ptr();
3373   switch (tp->ptr()) {
3374   case TypePtr::TopPTR:  return this;
3375   case TypePtr::BotPTR:  return t;
3376   case TypePtr::Null:
3377     if( _ptr == TypePtr::TopPTR ) return t;
3378     return TypeRawPtr::BOTTOM;
3379   case TypePtr::NotNull: return TypePtr::make(AnyPtr, meet_ptr(TypePtr::NotNull), tp->meet_offset(0), tp->speculative(), tp->inline_depth());
3380   case TypePtr::AnyNull:
3381     if( _ptr == TypePtr::Constant) return this;
3382     return make( meet_ptr(TypePtr::AnyNull) );
3383   default: ShouldNotReachHere();
3384   }
3385   return this;
3386 }
3387 
3388 //------------------------------xdual------------------------------------------
3389 // Dual: compute field-by-field dual
3390 const Type *TypeRawPtr::xdual() const {
3391   return new TypeRawPtr( dual_ptr(), _bits );
3392 }
3393 
3394 //------------------------------add_offset-------------------------------------
3395 const TypePtr* TypeRawPtr::add_offset(intptr_t offset) const {
3396   if( offset == OffsetTop ) return BOTTOM; // Undefined offset-> undefined pointer
3397   if( offset == OffsetBot ) return BOTTOM; // Unknown offset-> unknown pointer
3398   if( offset == 0 ) return this; // No change
3399   switch (_ptr) {
3400   case TypePtr::TopPTR:
3401   case TypePtr::BotPTR:
3402   case TypePtr::NotNull:
3403     return this;
3404   case TypePtr::Constant: {
3405     uintptr_t bits = (uintptr_t)_bits;
3406     uintptr_t sum = bits + offset;
3407     if (( offset < 0 )
3408         ? ( sum > bits )        // Underflow?
3409         : ( sum < bits )) {     // Overflow?
3410       return BOTTOM;
3411     } else if ( sum == 0 ) {
3412       return TypePtr::NULL_PTR;
3413     } else {
3414       return make( (address)sum );
3415     }
3416   }
3417   default:  ShouldNotReachHere();
3418   }
3419 }
3420 
3421 //------------------------------eq---------------------------------------------
3422 // Structural equality check for Type representations
3423 bool TypeRawPtr::eq( const Type *t ) const {
3424   const TypeRawPtr *a = (const TypeRawPtr*)t;
3425   return _bits == a->_bits && TypePtr::eq(t);
3426 }
3427 
3428 //------------------------------hash-------------------------------------------
3429 // Type-specific hashing function.
3430 uint TypeRawPtr::hash(void) const {
3431   return (uint)(uintptr_t)_bits + (uint)TypePtr::hash();
3432 }
3433 
3434 //------------------------------dump2------------------------------------------
3435 #ifndef PRODUCT
3436 void TypeRawPtr::dump2(Dict& d, uint depth, outputStream* st) const {
3437   if (_ptr == Constant) {
3438     st->print("rawptr:Constant:" INTPTR_FORMAT, p2i(_bits));
3439   } else {
3440     st->print("rawptr:%s", ptr_msg[_ptr]);
3441   }
3442 }
3443 #endif
3444 
3445 //=============================================================================
3446 // Convenience common pre-built type.
3447 const TypeOopPtr *TypeOopPtr::BOTTOM;
3448 
3449 TypeInterfaces::TypeInterfaces(ciInstanceKlass** interfaces_base, int nb_interfaces)
3450         : Type(Interfaces), _interfaces(interfaces_base, nb_interfaces),
3451           _hash(0), _exact_klass(nullptr) {
3452   _interfaces.sort(compare);
3453   initialize();
3454 }
3455 
3456 const TypeInterfaces* TypeInterfaces::make(GrowableArray<ciInstanceKlass*>* interfaces) {
3457   // hashcons() can only delete the last thing that was allocated: to
3458   // make sure all memory for the newly created TypeInterfaces can be
3459   // freed if an identical one exists, allocate space for the array of
3460   // interfaces right after the TypeInterfaces object so that they
3461   // form a contiguous piece of memory.
3462   int nb_interfaces = interfaces == nullptr ? 0 : interfaces->length();
3463   size_t total_size = sizeof(TypeInterfaces) + nb_interfaces * sizeof(ciInstanceKlass*);
3464 
3465   void* allocated_mem = operator new(total_size);
3466   ciInstanceKlass** interfaces_base = (ciInstanceKlass**)((char*)allocated_mem + sizeof(TypeInterfaces));
3467   for (int i = 0; i < nb_interfaces; ++i) {
3468     interfaces_base[i] = interfaces->at(i);
3469   }
3470   TypeInterfaces* result = ::new (allocated_mem) TypeInterfaces(interfaces_base, nb_interfaces);
3471   return (const TypeInterfaces*)result->hashcons();
3472 }
3473 
3474 void TypeInterfaces::initialize() {
3475   compute_hash();
3476   compute_exact_klass();
3477   DEBUG_ONLY(_initialized = true;)
3478 }
3479 
3480 int TypeInterfaces::compare(ciInstanceKlass* const& k1, ciInstanceKlass* const& k2) {
3481   if ((intptr_t)k1 < (intptr_t)k2) {
3482     return -1;
3483   } else if ((intptr_t)k1 > (intptr_t)k2) {
3484     return 1;
3485   }
3486   return 0;
3487 }
3488 
3489 int TypeInterfaces::compare(ciInstanceKlass** k1, ciInstanceKlass** k2) {
3490   return compare(*k1, *k2);
3491 }
3492 
3493 bool TypeInterfaces::eq(const Type* t) const {
3494   const TypeInterfaces* other = (const TypeInterfaces*)t;
3495   if (_interfaces.length() != other->_interfaces.length()) {
3496     return false;
3497   }
3498   for (int i = 0; i < _interfaces.length(); i++) {
3499     ciKlass* k1 = _interfaces.at(i);
3500     ciKlass* k2 = other->_interfaces.at(i);
3501     if (!k1->equals(k2)) {
3502       return false;
3503     }
3504   }
3505   return true;
3506 }
3507 
3508 bool TypeInterfaces::eq(ciInstanceKlass* k) const {
3509   assert(k->is_loaded(), "should be loaded");
3510   GrowableArray<ciInstanceKlass *>* interfaces = k->transitive_interfaces();
3511   if (_interfaces.length() != interfaces->length()) {
3512     return false;
3513   }
3514   for (int i = 0; i < interfaces->length(); i++) {
3515     bool found = false;
3516     _interfaces.find_sorted<ciInstanceKlass*, compare>(interfaces->at(i), found);
3517     if (!found) {
3518       return false;
3519     }
3520   }
3521   return true;
3522 }
3523 
3524 
3525 uint TypeInterfaces::hash() const {
3526   assert(_initialized, "must be");
3527   return _hash;
3528 }
3529 
3530 const Type* TypeInterfaces::xdual() const {
3531   return this;
3532 }
3533 
3534 void TypeInterfaces::compute_hash() {
3535   uint hash = 0;
3536   for (int i = 0; i < _interfaces.length(); i++) {
3537     ciKlass* k = _interfaces.at(i);
3538     hash += k->hash();
3539   }
3540   _hash = hash;
3541 }
3542 
3543 static int compare_interfaces(ciInstanceKlass** k1, ciInstanceKlass** k2) {
3544   return (int)((*k1)->ident() - (*k2)->ident());
3545 }
3546 
3547 void TypeInterfaces::dump(outputStream* st) const {
3548   if (_interfaces.length() == 0) {
3549     return;
3550   }
3551   ResourceMark rm;
3552   st->print(" (");
3553   GrowableArray<ciInstanceKlass*> interfaces;
3554   interfaces.appendAll(&_interfaces);
3555   // Sort the interfaces so they are listed in the same order from one run to the other of the same compilation
3556   interfaces.sort(compare_interfaces);
3557   for (int i = 0; i < interfaces.length(); i++) {
3558     if (i > 0) {
3559       st->print(",");
3560     }
3561     ciKlass* k = interfaces.at(i);
3562     k->print_name_on(st);
3563   }
3564   st->print(")");
3565 }
3566 
3567 #ifdef ASSERT
3568 void TypeInterfaces::verify() const {
3569   for (int i = 1; i < _interfaces.length(); i++) {
3570     ciInstanceKlass* k1 = _interfaces.at(i-1);
3571     ciInstanceKlass* k2 = _interfaces.at(i);
3572     assert(compare(k2, k1) > 0, "should be ordered");
3573     assert(k1 != k2, "no duplicate");
3574   }
3575 }
3576 #endif
3577 
3578 const TypeInterfaces* TypeInterfaces::union_with(const TypeInterfaces* other) const {
3579   GrowableArray<ciInstanceKlass*> result_list;
3580   int i = 0;
3581   int j = 0;
3582   while (i < _interfaces.length() || j < other->_interfaces.length()) {
3583     while (i < _interfaces.length() &&
3584            (j >= other->_interfaces.length() ||
3585             compare(_interfaces.at(i), other->_interfaces.at(j)) < 0)) {
3586       result_list.push(_interfaces.at(i));
3587       i++;
3588     }
3589     while (j < other->_interfaces.length() &&
3590            (i >= _interfaces.length() ||
3591             compare(other->_interfaces.at(j), _interfaces.at(i)) < 0)) {
3592       result_list.push(other->_interfaces.at(j));
3593       j++;
3594     }
3595     if (i < _interfaces.length() &&
3596         j < other->_interfaces.length() &&
3597         _interfaces.at(i) == other->_interfaces.at(j)) {
3598       result_list.push(_interfaces.at(i));
3599       i++;
3600       j++;
3601     }
3602   }
3603   const TypeInterfaces* result = TypeInterfaces::make(&result_list);
3604 #ifdef ASSERT
3605   result->verify();
3606   for (int i = 0; i < _interfaces.length(); i++) {
3607     assert(result->_interfaces.contains(_interfaces.at(i)), "missing");
3608   }
3609   for (int i = 0; i < other->_interfaces.length(); i++) {
3610     assert(result->_interfaces.contains(other->_interfaces.at(i)), "missing");
3611   }
3612   for (int i = 0; i < result->_interfaces.length(); i++) {
3613     assert(_interfaces.contains(result->_interfaces.at(i)) || other->_interfaces.contains(result->_interfaces.at(i)), "missing");
3614   }
3615 #endif
3616   return result;
3617 }
3618 
3619 const TypeInterfaces* TypeInterfaces::intersection_with(const TypeInterfaces* other) const {
3620   GrowableArray<ciInstanceKlass*> result_list;
3621   int i = 0;
3622   int j = 0;
3623   while (i < _interfaces.length() || j < other->_interfaces.length()) {
3624     while (i < _interfaces.length() &&
3625            (j >= other->_interfaces.length() ||
3626             compare(_interfaces.at(i), other->_interfaces.at(j)) < 0)) {
3627       i++;
3628     }
3629     while (j < other->_interfaces.length() &&
3630            (i >= _interfaces.length() ||
3631             compare(other->_interfaces.at(j), _interfaces.at(i)) < 0)) {
3632       j++;
3633     }
3634     if (i < _interfaces.length() &&
3635         j < other->_interfaces.length() &&
3636         _interfaces.at(i) == other->_interfaces.at(j)) {
3637       result_list.push(_interfaces.at(i));
3638       i++;
3639       j++;
3640     }
3641   }
3642   const TypeInterfaces* result = TypeInterfaces::make(&result_list);
3643 #ifdef ASSERT
3644   result->verify();
3645   for (int i = 0; i < _interfaces.length(); i++) {
3646     assert(!other->_interfaces.contains(_interfaces.at(i)) || result->_interfaces.contains(_interfaces.at(i)), "missing");
3647   }
3648   for (int i = 0; i < other->_interfaces.length(); i++) {
3649     assert(!_interfaces.contains(other->_interfaces.at(i)) || result->_interfaces.contains(other->_interfaces.at(i)), "missing");
3650   }
3651   for (int i = 0; i < result->_interfaces.length(); i++) {
3652     assert(_interfaces.contains(result->_interfaces.at(i)) && other->_interfaces.contains(result->_interfaces.at(i)), "missing");
3653   }
3654 #endif
3655   return result;
3656 }
3657 
3658 // Is there a single ciKlass* that can represent the interface set?
3659 ciInstanceKlass* TypeInterfaces::exact_klass() const {
3660   assert(_initialized, "must be");
3661   return _exact_klass;
3662 }
3663 
3664 void TypeInterfaces::compute_exact_klass() {
3665   if (_interfaces.length() == 0) {
3666     _exact_klass = nullptr;
3667     return;
3668   }
3669   ciInstanceKlass* res = nullptr;
3670   for (int i = 0; i < _interfaces.length(); i++) {
3671     ciInstanceKlass* interface = _interfaces.at(i);
3672     if (eq(interface)) {
3673       assert(res == nullptr, "");
3674       res = interface;
3675     }
3676   }
3677   _exact_klass = res;
3678 }
3679 
3680 #ifdef ASSERT
3681 void TypeInterfaces::verify_is_loaded() const {
3682   for (int i = 0; i < _interfaces.length(); i++) {
3683     ciKlass* interface = _interfaces.at(i);
3684     assert(interface->is_loaded(), "Interface not loaded");
3685   }
3686 }
3687 #endif
3688 
3689 // Can't be implemented because there's no way to know if the type is above or below the center line.
3690 const Type* TypeInterfaces::xmeet(const Type* t) const {
3691   ShouldNotReachHere();
3692   return Type::xmeet(t);
3693 }
3694 
3695 bool TypeInterfaces::singleton(void) const {
3696   ShouldNotReachHere();
3697   return Type::singleton();
3698 }
3699 
3700 bool TypeInterfaces::has_non_array_interface() const {
3701   assert(TypeAryPtr::_array_interfaces != nullptr, "How come Type::Initialize_shared wasn't called yet?");
3702 
3703   return !TypeAryPtr::_array_interfaces->contains(this);
3704 }
3705 
3706 //------------------------------TypeOopPtr-------------------------------------
3707 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset offset, Offset field_offset,
3708                        int instance_id, const TypePtr* speculative, int inline_depth)
3709   : TypePtr(t, ptr, offset, speculative, inline_depth),
3710     _const_oop(o), _klass(k),
3711     _interfaces(interfaces),
3712     _klass_is_exact(xk),
3713     _is_ptr_to_narrowoop(false),
3714     _is_ptr_to_narrowklass(false),
3715     _is_ptr_to_boxed_value(false),
3716     _is_ptr_to_strict_final_field(false),
3717     _instance_id(instance_id) {
3718 #ifdef ASSERT
3719   if (klass() != nullptr && klass()->is_loaded()) {
3720     interfaces->verify_is_loaded();
3721   }
3722 #endif
3723   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3724       (offset.get() > 0) && xk && (k != nullptr) && k->is_instance_klass()) {
3725     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset.get());
3726     _is_ptr_to_strict_final_field = _is_ptr_to_boxed_value;
3727   }
3728 
3729   if (klass() != nullptr && klass()->is_instance_klass() && klass()->is_loaded() &&
3730       this->offset() != Type::OffsetBot && this->offset() != Type::OffsetTop) {
3731     ciField* field = klass()->as_instance_klass()->get_field_by_offset(this->offset(), false);
3732     if (field != nullptr && field->is_strict() && field->is_final()) {
3733       _is_ptr_to_strict_final_field = true;
3734     }
3735   }
3736 
3737 #ifdef _LP64
3738   if (this->offset() > 0 || this->offset() == Type::OffsetTop || this->offset() == Type::OffsetBot) {
3739     if (this->offset() == oopDesc::klass_offset_in_bytes()) {
3740       _is_ptr_to_narrowklass = true;
3741     } else if (klass() == nullptr) {
3742       // Array with unknown body type
3743       assert(this->isa_aryptr(), "only arrays without klass");
3744       _is_ptr_to_narrowoop = UseCompressedOops;
3745     } else if (UseCompressedOops && this->isa_aryptr() && this->offset() != arrayOopDesc::length_offset_in_bytes()) {
3746       if (klass()->is_flat_array_klass() && field_offset != Offset::top && field_offset != Offset::bottom) {
3747         // Check if the field of the inline type array element contains oops
3748         ciInlineKlass* vk = klass()->as_flat_array_klass()->element_klass()->as_inline_klass();
3749         int foffset = field_offset.get() + vk->payload_offset();
3750         BasicType field_bt;
3751         ciField* field = vk->get_field_by_offset(foffset, false);
3752         if (field != nullptr) {
3753           field_bt = field->layout_type();
3754         } else {
3755           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);
3756           field_bt = T_BOOLEAN;
3757         }
3758         _is_ptr_to_narrowoop = ::is_reference_type(field_bt);
3759       } else if (klass()->is_obj_array_klass()) {
3760         _is_ptr_to_narrowoop = true;
3761       }
3762     } else if (klass()->is_instance_klass()) {

3763       if (this->isa_klassptr()) {
3764         // Perm objects don't use compressed references
3765       } else if (_offset == Offset::bottom || _offset == Offset::top) {
3766         // unsafe access
3767         _is_ptr_to_narrowoop = UseCompressedOops;
3768       } else {
3769         assert(this->isa_instptr(), "must be an instance ptr.");

3770         if (klass() == ciEnv::current()->Class_klass() &&
3771             (this->offset() == java_lang_Class::klass_offset() ||
3772              this->offset() == java_lang_Class::array_klass_offset())) {
3773           // Special hidden fields from the Class.
3774           assert(this->isa_instptr(), "must be an instance ptr.");
3775           _is_ptr_to_narrowoop = false;
3776         } else if (klass() == ciEnv::current()->Class_klass() &&
3777                    this->offset() >= InstanceMirrorKlass::offset_of_static_fields()) {
3778           // Static fields
3779           BasicType basic_elem_type = T_ILLEGAL;
3780           if (const_oop() != nullptr) {
3781             ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3782             basic_elem_type = k->get_field_type_by_offset(this->offset(), true);
3783           }
3784           if (basic_elem_type != T_ILLEGAL) {
3785             _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3786           } else {
3787             // unsafe access
3788             _is_ptr_to_narrowoop = UseCompressedOops;
3789           }
3790         } else {
3791           // Instance fields which contains a compressed oop references.
3792           ciInstanceKlass* ik = klass()->as_instance_klass();
3793           BasicType basic_elem_type = ik->get_field_type_by_offset(this->offset(), false);
3794           if (basic_elem_type != T_ILLEGAL) {
3795             _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3796           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3797             // Compile::find_alias_type() cast exactness on all types to verify
3798             // that it does not affect alias type.
3799             _is_ptr_to_narrowoop = UseCompressedOops;
3800           } else {
3801             // Type for the copy start in LibraryCallKit::inline_native_clone().
3802             _is_ptr_to_narrowoop = UseCompressedOops;
3803           }
3804         }
3805       }
3806     }
3807   }
3808 #endif // _LP64
3809 }
3810 
3811 //------------------------------make-------------------------------------------
3812 const TypeOopPtr *TypeOopPtr::make(PTR ptr, Offset offset, int instance_id,
3813                                    const TypePtr* speculative, int inline_depth) {
3814   assert(ptr != Constant, "no constant generic pointers");
3815   ciKlass*  k = Compile::current()->env()->Object_klass();
3816   bool      xk = false;
3817   ciObject* o = nullptr;
3818   const TypeInterfaces* interfaces = TypeInterfaces::make();
3819   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, interfaces, xk, o, offset, Offset::bottom, instance_id, speculative, inline_depth))->hashcons();
3820 }
3821 
3822 
3823 //------------------------------cast_to_ptr_type-------------------------------
3824 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3825   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3826   if( ptr == _ptr ) return this;
3827   return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3828 }
3829 
3830 //-----------------------------cast_to_instance_id----------------------------
3831 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3832   // There are no instances of a general oop.
3833   // Return self unchanged.
3834   return this;
3835 }
3836 
3837 //-----------------------------cast_to_exactness-------------------------------
3838 const TypeOopPtr* TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3839   // There is no such thing as an exact general oop.
3840   // Return self unchanged.
3841   return this;
3842 }
3843 

3844 //------------------------------as_klass_type----------------------------------
3845 // Return the klass type corresponding to this instance or array type.
3846 // It is the type that is loaded from an object of this type.
3847 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3848   ShouldNotReachHere();
3849   return nullptr;
3850 }
3851 
3852 //------------------------------meet-------------------------------------------
3853 // Compute the MEET of two types.  It returns a new Type object.
3854 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3855   // Perform a fast test for common case; meeting the same types together.
3856   if( this == t ) return this;  // Meeting same type-rep?
3857 
3858   // Current "this->_base" is OopPtr
3859   switch (t->base()) {          // switch on original type
3860 
3861   case Int:                     // Mixing ints & oops happens when javac
3862   case Long:                    // reuses local variables
3863   case HalfFloatTop:
3864   case HalfFloatCon:
3865   case HalfFloatBot:
3866   case FloatTop:
3867   case FloatCon:
3868   case FloatBot:
3869   case DoubleTop:
3870   case DoubleCon:
3871   case DoubleBot:
3872   case NarrowOop:
3873   case NarrowKlass:
3874   case Bottom:                  // Ye Olde Default
3875     return Type::BOTTOM;
3876   case Top:
3877     return this;
3878 
3879   default:                      // All else is a mistake
3880     typerr(t);
3881 
3882   case RawPtr:
3883   case MetadataPtr:
3884   case KlassPtr:
3885   case InstKlassPtr:
3886   case AryKlassPtr:
3887     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3888 
3889   case AnyPtr: {
3890     // Found an AnyPtr type vs self-OopPtr type
3891     const TypePtr *tp = t->is_ptr();
3892     Offset offset = meet_offset(tp->offset());
3893     PTR ptr = meet_ptr(tp->ptr());
3894     const TypePtr* speculative = xmeet_speculative(tp);
3895     int depth = meet_inline_depth(tp->inline_depth());
3896     switch (tp->ptr()) {
3897     case Null:
3898       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3899       // else fall through:
3900     case TopPTR:
3901     case AnyNull: {
3902       int instance_id = meet_instance_id(InstanceTop);
3903       return make(ptr, offset, instance_id, speculative, depth);
3904     }
3905     case BotPTR:
3906     case NotNull:
3907       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3908     default: typerr(t);
3909     }
3910   }
3911 
3912   case OopPtr: {                 // Meeting to other OopPtrs
3913     const TypeOopPtr *tp = t->is_oopptr();
3914     int instance_id = meet_instance_id(tp->instance_id());
3915     const TypePtr* speculative = xmeet_speculative(tp);
3916     int depth = meet_inline_depth(tp->inline_depth());
3917     return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3918   }
3919 
3920   case InstPtr:                  // For these, flip the call around to cut down
3921   case AryPtr:
3922     return t->xmeet(this);      // Call in reverse direction
3923 
3924   } // End of switch
3925   return this;                  // Return the double constant
3926 }
3927 
3928 
3929 //------------------------------xdual------------------------------------------
3930 // Dual of a pure heap pointer.  No relevant klass or oop information.
3931 const Type *TypeOopPtr::xdual() const {
3932   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3933   assert(const_oop() == nullptr,             "no constants here");
3934   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());
3935 }
3936 
3937 //--------------------------make_from_klass_common-----------------------------
3938 // Computes the element-type given a klass.
3939 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling) {
3940   if (klass->is_instance_klass() || klass->is_inlinetype()) {
3941     Compile* C = Compile::current();
3942     Dependencies* deps = C->dependencies();
3943     assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
3944     // Element is an instance
3945     bool klass_is_exact = false;
3946     ciInstanceKlass* ik = klass->as_instance_klass();
3947     if (klass->is_loaded()) {
3948       // Try to set klass_is_exact.

3949       klass_is_exact = ik->is_final();
3950       if (!klass_is_exact && klass_change
3951           && deps != nullptr && UseUniqueSubclasses) {
3952         ciInstanceKlass* sub = ik->unique_concrete_subklass();
3953         if (sub != nullptr) {
3954           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3955           klass = ik = sub;
3956           klass_is_exact = sub->is_final();
3957         }
3958       }
3959       if (!klass_is_exact && try_for_exact && deps != nullptr &&
3960           !ik->is_interface() && !ik->has_subklass()) {
3961         // Add a dependence; if concrete subclass added we need to recompile
3962         deps->assert_leaf_type(ik);
3963         klass_is_exact = true;
3964       }
3965     }
3966     FlatInArray flat_in_array = compute_flat_in_array(ik, klass_is_exact);
3967     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
3968     return TypeInstPtr::make(TypePtr::BotPTR, klass, interfaces, klass_is_exact, nullptr, Offset(0), flat_in_array);
3969   } else if (klass->is_obj_array_klass()) {
3970     // Element is an object or inline type array. Recursively call ourself.
3971     ciObjArrayKlass* array_klass = klass->as_obj_array_klass();
3972     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_common(array_klass->element_klass(), /* klass_change= */ false, try_for_exact, interface_handling);
3973     bool xk = array_klass->is_loaded() && array_klass->is_refined();
3974 
3975     // Determine null-free/flat properties
3976     bool flat;
3977     bool not_flat;
3978     bool is_null_free;
3979     bool not_null_free;
3980     bool atomic;
3981     if (xk) {
3982       flat = array_klass->is_flat_array_klass();
3983       not_flat = !flat;
3984       is_null_free = array_klass->is_elem_null_free();
3985       not_null_free = !is_null_free;
3986       atomic = array_klass->is_elem_atomic();
3987 
3988       if (is_null_free) {
3989         etype = etype->join_speculative(NOTNULL)->is_oopptr();
3990       }
3991     } else {
3992       const TypeOopPtr* exact_etype = etype;
3993       if (etype->can_be_inline_type()) {
3994         // Use exact type if element can be an inline type
3995         exact_etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), /* klass_change= */ true, /* try_for_exact= */ true, interface_handling);
3996       }
3997 
3998       flat = false;
3999       bool not_inline = !exact_etype->can_be_inline_type();
4000       not_null_free = not_inline;
4001       not_flat = !UseArrayFlattening || not_inline || (exact_etype->is_inlinetypeptr() && !exact_etype->inline_klass()->maybe_flat_in_array());
4002       atomic = not_flat;
4003     }
4004 
4005     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS, /* stable= */ false, flat, not_flat, not_null_free, atomic);
4006     // We used to pass NotNull in here, asserting that the sub-arrays
4007     // are all not-null.  This is not true in generally, as code can
4008     // slam nullptrs down in the subarrays.
4009     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, nullptr, xk, Offset(0));
4010     return arr;
4011   } else if (klass->is_type_array_klass()) {
4012     // Element is an typeArray
4013     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
4014     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS,
4015                                         /* stable= */ false, /* flat= */ false, /* not_flat= */ true, /* not_null_free= */ true, true);
4016     // We used to pass NotNull in here, asserting that the array pointer
4017     // is not-null. That was not true in general.
4018     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
4019     return arr;
4020   } else {
4021     ShouldNotReachHere();
4022     return nullptr;
4023   }
4024 }
4025 
4026 //------------------------------make_from_constant-----------------------------
4027 // Make a java pointer from an oop constant
4028 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
4029   assert(!o->is_null_object(), "null object not yet handled here.");
4030 
4031   const bool make_constant = require_constant || o->should_be_constant();
4032 
4033   ciKlass* klass = o->klass();
4034   if (klass->is_instance_klass() || klass->is_inlinetype()) {
4035     // Element is an instance or inline type
4036     if (make_constant) {
4037       return TypeInstPtr::make(o);
4038     } else {
4039       return TypeInstPtr::make(TypePtr::NotNull, klass, true, nullptr, Offset(0));
4040     }
4041   } else if (klass->is_obj_array_klass()) {
4042     // Element is an object array. Recursively call ourself.
4043     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass(), trust_interfaces);
4044     bool is_flat = o->as_array()->is_flat();
4045     bool is_null_free = o->as_array()->is_null_free();
4046     if (is_null_free) {
4047       etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
4048     }
4049     bool is_atomic = o->as_array()->is_atomic();
4050     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()), /* stable= */ false, /* flat= */ is_flat,
4051                                         /* not_flat= */ !is_flat, /* not_null_free= */ !is_null_free, /* atomic= */ is_atomic);
4052     // We used to pass NotNull in here, asserting that the sub-arrays
4053     // are all not-null.  This is not true in generally, as code can
4054     // slam nulls down in the subarrays.
4055     if (make_constant) {
4056       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
4057     } else {
4058       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
4059     }
4060   } else if (klass->is_type_array_klass()) {
4061     // Element is an typeArray
4062     const Type* etype = (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
4063     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()), /* stable= */ false, /* flat= */ false,
4064                                         /* not_flat= */ true, /* not_null_free= */ true, true);
4065     // We used to pass NotNull in here, asserting that the array pointer
4066     // is not-null. That was not true in general.
4067     if (make_constant) {
4068       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
4069     } else {
4070       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
4071     }
4072   }
4073 
4074   fatal("unhandled object type");
4075   return nullptr;
4076 }
4077 
4078 //------------------------------get_con----------------------------------------
4079 intptr_t TypeOopPtr::get_con() const {
4080   assert( _ptr == Null || _ptr == Constant, "" );
4081   assert(offset() >= 0, "");
4082 
4083   if (offset() != 0) {
4084     // After being ported to the compiler interface, the compiler no longer
4085     // directly manipulates the addresses of oops.  Rather, it only has a pointer
4086     // to a handle at compile time.  This handle is embedded in the generated
4087     // code and dereferenced at the time the nmethod is made.  Until that time,
4088     // it is not reasonable to do arithmetic with the addresses of oops (we don't
4089     // have access to the addresses!).  This does not seem to currently happen,
4090     // but this assertion here is to help prevent its occurrence.
4091     tty->print_cr("Found oop constant with non-zero offset");
4092     ShouldNotReachHere();
4093   }
4094 
4095   return (intptr_t)const_oop()->constant_encoding();
4096 }
4097 
4098 
4099 //-----------------------------filter------------------------------------------
4100 // Do not allow interface-vs.-noninterface joins to collapse to top.
4101 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
4102 
4103   const Type* ft = join_helper(kills, include_speculative);
4104 
4105   if (ft->empty()) {
4106     return Type::TOP;           // Canonical empty value
4107   }
4108 
4109   return ft;
4110 }
4111 
4112 //------------------------------eq---------------------------------------------
4113 // Structural equality check for Type representations
4114 bool TypeOopPtr::eq( const Type *t ) const {
4115   const TypeOopPtr *a = (const TypeOopPtr*)t;
4116   if (_klass_is_exact != a->_klass_is_exact ||
4117       _instance_id != a->_instance_id)  return false;
4118   ciObject* one = const_oop();
4119   ciObject* two = a->const_oop();
4120   if (one == nullptr || two == nullptr) {
4121     return (one == two) && TypePtr::eq(t);
4122   } else {
4123     return one->equals(two) && TypePtr::eq(t);
4124   }
4125 }
4126 
4127 //------------------------------hash-------------------------------------------
4128 // Type-specific hashing function.
4129 uint TypeOopPtr::hash(void) const {
4130   return
4131     (uint)(const_oop() ? const_oop()->hash() : 0) +
4132     (uint)_klass_is_exact +
4133     (uint)_instance_id + TypePtr::hash();
4134 }
4135 
4136 //------------------------------dump2------------------------------------------
4137 #ifndef PRODUCT
4138 void TypeOopPtr::dump2(Dict& d, uint depth, outputStream* st) const {
4139   st->print("oopptr:%s", ptr_msg[_ptr]);
4140   if (_klass_is_exact) {
4141     st->print(":exact");
4142   }
4143   if (const_oop() != nullptr) {
4144     st->print(":" INTPTR_FORMAT, p2i(const_oop()));
4145   }
4146   dump_offset(st);
4147   dump_instance_id(st);
4148   dump_inline_depth(st);
4149   dump_speculative(st);
4150 }
4151 
4152 void TypeOopPtr::dump_instance_id(outputStream* st) const {
4153   if (_instance_id == InstanceTop) {
4154     st->print(",iid=top");
4155   } else if (_instance_id == InstanceBot) {
4156     st->print(",iid=bot");
4157   } else {
4158     st->print(",iid=%d", _instance_id);
4159   }
4160 }
4161 #endif
4162 
4163 //------------------------------singleton--------------------------------------
4164 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
4165 // constants
4166 bool TypeOopPtr::singleton(void) const {
4167   // detune optimizer to not generate constant oop + constant offset as a constant!
4168   // TopPTR, Null, AnyNull, Constant are all singletons
4169   return (offset() == 0) && !below_centerline(_ptr);
4170 }
4171 
4172 //------------------------------add_offset-------------------------------------
4173 const TypePtr* TypeOopPtr::add_offset(intptr_t offset) const {
4174   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
4175 }
4176 
4177 const TypeOopPtr* TypeOopPtr::with_offset(intptr_t offset) const {
4178   return make(_ptr, Offset(offset), _instance_id, with_offset_speculative(offset), _inline_depth);
4179 }
4180 
4181 /**
4182  * Return same type without a speculative part
4183  */
4184 const TypeOopPtr* TypeOopPtr::remove_speculative() const {
4185   if (_speculative == nullptr) {
4186     return this;
4187   }
4188   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4189   return make(_ptr, _offset, _instance_id, nullptr, _inline_depth);
4190 }
4191 
4192 /**
4193  * Return same type but drop speculative part if we know we won't use
4194  * it
4195  */
4196 const Type* TypeOopPtr::cleanup_speculative() const {
4197   // If the klass is exact and the ptr is not null then there's
4198   // nothing that the speculative type can help us with
4199   if (klass_is_exact() && !maybe_null()) {
4200     return remove_speculative();
4201   }
4202   return TypePtr::cleanup_speculative();
4203 }
4204 
4205 /**
4206  * Return same type but with a different inline depth (used for speculation)
4207  *
4208  * @param depth  depth to meet with
4209  */
4210 const TypePtr* TypeOopPtr::with_inline_depth(int depth) const {
4211   if (!UseInlineDepthForSpeculativeTypes) {
4212     return this;
4213   }
4214   return make(_ptr, _offset, _instance_id, _speculative, depth);
4215 }
4216 
4217 //------------------------------with_instance_id--------------------------------
4218 const TypePtr* TypeOopPtr::with_instance_id(int instance_id) const {
4219   assert(_instance_id != -1, "should be known");
4220   return make(_ptr, _offset, instance_id, _speculative, _inline_depth);
4221 }
4222 
4223 //------------------------------meet_instance_id--------------------------------
4224 int TypeOopPtr::meet_instance_id( int instance_id ) const {
4225   // Either is 'TOP' instance?  Return the other instance!
4226   if( _instance_id == InstanceTop ) return  instance_id;
4227   if(  instance_id == InstanceTop ) return _instance_id;
4228   // If either is different, return 'BOTTOM' instance
4229   if( _instance_id != instance_id ) return InstanceBot;
4230   return _instance_id;
4231 }
4232 
4233 //------------------------------dual_instance_id--------------------------------
4234 int TypeOopPtr::dual_instance_id( ) const {
4235   if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM
4236   if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP
4237   return _instance_id;              // Map everything else into self
4238 }
4239 
4240 
4241 const TypeInterfaces* TypeOopPtr::meet_interfaces(const TypeOopPtr* other) const {
4242   if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
4243     return _interfaces->union_with(other->_interfaces);
4244   } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
4245     return other->_interfaces;
4246   } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
4247     return _interfaces;
4248   }
4249   return _interfaces->intersection_with(other->_interfaces);
4250 }
4251 
4252 /**
4253  * Check whether new profiling would improve speculative type
4254  *
4255  * @param   exact_kls    class from profiling
4256  * @param   inline_depth inlining depth of profile point
4257  *
4258  * @return  true if type profile is valuable
4259  */
4260 bool TypeOopPtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
4261   // no way to improve an already exact type
4262   if (klass_is_exact()) {
4263     return false;
4264   }
4265   return TypePtr::would_improve_type(exact_kls, inline_depth);
4266 }
4267 
4268 //=============================================================================
4269 // Convenience common pre-built types.
4270 const TypeInstPtr *TypeInstPtr::NOTNULL;
4271 const TypeInstPtr *TypeInstPtr::BOTTOM;
4272 const TypeInstPtr *TypeInstPtr::MIRROR;
4273 const TypeInstPtr *TypeInstPtr::MARK;
4274 const TypeInstPtr *TypeInstPtr::KLASS;
4275 
4276 // Is there a single ciKlass* that can represent that type?
4277 ciKlass* TypeInstPtr::exact_klass_helper() const {
4278   if (_interfaces->empty()) {
4279     return _klass;
4280   }
4281   if (_klass != ciEnv::current()->Object_klass()) {
4282     if (_interfaces->eq(_klass->as_instance_klass())) {
4283       return _klass;
4284     }
4285     return nullptr;
4286   }
4287   return _interfaces->exact_klass();
4288 }
4289 
4290 //------------------------------TypeInstPtr-------------------------------------
4291 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset off,
4292                          FlatInArray flat_in_array, int instance_id, const TypePtr* speculative, int inline_depth)
4293   : TypeOopPtr(InstPtr, ptr, k, interfaces, xk, o, off, Offset::bottom, instance_id, speculative, inline_depth),
4294     _flat_in_array(flat_in_array) {
4295 
4296   assert(flat_in_array != Uninitialized, "must be set now");
4297   assert(k == nullptr || !k->is_loaded() || !k->is_interface(), "no interface here");
4298   assert(k != nullptr &&
4299          (k->is_loaded() || o == nullptr),
4300          "cannot have constants with non-loaded klass");
4301 };
4302 
4303 //------------------------------make-------------------------------------------
4304 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
4305                                      ciKlass* k,
4306                                      const TypeInterfaces* interfaces,
4307                                      bool xk,
4308                                      ciObject* o,
4309                                      Offset offset,
4310                                      FlatInArray flat_in_array,
4311                                      int instance_id,
4312                                      const TypePtr* speculative,
4313                                      int inline_depth) {
4314   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
4315   // Either const_oop() is null or else ptr is Constant
4316   assert( (!o && ptr != Constant) || (o && ptr == Constant),
4317           "constant pointers must have a value supplied" );
4318   // Ptr is never Null
4319   assert( ptr != Null, "null pointers are not typed" );
4320 
4321   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4322   ciInstanceKlass* ik = k->as_instance_klass();
4323   if (ptr == Constant) {
4324     // Note:  This case includes meta-object constants, such as methods.
4325     xk = true;
4326   } else if (k->is_loaded()) {

4327     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
4328     assert(!ik->is_interface(), "no interface here");
4329     if (xk && ik->is_interface())  xk = false;  // no exact interface
4330   }
4331 
4332   if (flat_in_array == Uninitialized) {
4333     flat_in_array = compute_flat_in_array(ik, xk);
4334   }
4335   // Now hash this baby
4336   TypeInstPtr *result =
4337     (TypeInstPtr*)(new TypeInstPtr(ptr, k, interfaces, xk, o, offset, flat_in_array, instance_id, speculative, inline_depth))->hashcons();
4338 
4339   return result;
4340 }
4341 
4342 const TypeInterfaces* TypePtr::interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling) {
4343   if (k->is_instance_klass()) {
4344     if (k->is_loaded()) {
4345       if (k->is_interface() && interface_handling == ignore_interfaces) {
4346         assert(interface, "no interface expected");
4347         k = ciEnv::current()->Object_klass();
4348         const TypeInterfaces* interfaces = TypeInterfaces::make();
4349         return interfaces;
4350       }
4351       GrowableArray<ciInstanceKlass *>* k_interfaces = k->as_instance_klass()->transitive_interfaces();
4352       const TypeInterfaces* interfaces = TypeInterfaces::make(k_interfaces);
4353       if (k->is_interface()) {
4354         assert(interface, "no interface expected");
4355         k = ciEnv::current()->Object_klass();
4356       } else {
4357         assert(klass, "no instance klass expected");
4358       }
4359       return interfaces;
4360     }
4361     const TypeInterfaces* interfaces = TypeInterfaces::make();
4362     return interfaces;
4363   }
4364   assert(array, "no array expected");
4365   assert(k->is_array_klass(), "Not an array?");
4366   ciType* e = k->as_array_klass()->base_element_type();
4367   if (e->is_loaded() && e->is_instance_klass() && e->as_instance_klass()->is_interface()) {
4368     if (interface_handling == ignore_interfaces) {
4369       k = ciObjArrayKlass::make(ciEnv::current()->Object_klass(), k->as_array_klass()->dimension());
4370     }
4371   }
4372   return TypeAryPtr::_array_interfaces;
4373 }
4374 
4375 /**
4376  *  Create constant type for a constant boxed value
4377  */
4378 const Type* TypeInstPtr::get_const_boxed_value() const {
4379   assert(is_ptr_to_boxed_value(), "should be called only for boxed value");
4380   assert((const_oop() != nullptr), "should be called only for constant object");
4381   ciConstant constant = const_oop()->as_instance()->field_value_by_offset(offset());
4382   BasicType bt = constant.basic_type();
4383   switch (bt) {
4384     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
4385     case T_INT:      return TypeInt::make(constant.as_int());
4386     case T_CHAR:     return TypeInt::make(constant.as_char());
4387     case T_BYTE:     return TypeInt::make(constant.as_byte());
4388     case T_SHORT:    return TypeInt::make(constant.as_short());
4389     case T_FLOAT:    return TypeF::make(constant.as_float());
4390     case T_DOUBLE:   return TypeD::make(constant.as_double());
4391     case T_LONG:     return TypeLong::make(constant.as_long());
4392     default:         break;
4393   }
4394   fatal("Invalid boxed value type '%s'", type2name(bt));
4395   return nullptr;
4396 }
4397 
4398 //------------------------------cast_to_ptr_type-------------------------------
4399 const TypeInstPtr* TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
4400   if( ptr == _ptr ) return this;
4401   // Reconstruct _sig info here since not a problem with later lazy
4402   // construction, _sig will show up on demand.
4403   return make(ptr, klass(), _interfaces, klass_is_exact(), ptr == Constant ? const_oop() : nullptr, _offset, _flat_in_array, _instance_id, _speculative, _inline_depth);
4404 }
4405 
4406 
4407 //-----------------------------cast_to_exactness-------------------------------
4408 const TypeInstPtr* TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
4409   if( klass_is_exact == _klass_is_exact ) return this;
4410   if (!_klass->is_loaded())  return this;
4411   ciInstanceKlass* ik = _klass->as_instance_klass();
4412   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
4413   assert(!ik->is_interface(), "no interface here");
4414   FlatInArray flat_in_array = compute_flat_in_array(ik, klass_is_exact);
4415   return make(ptr(), klass(), _interfaces, klass_is_exact, const_oop(), _offset, flat_in_array, _instance_id, _speculative, _inline_depth);
4416 }
4417 
4418 //-----------------------------cast_to_instance_id----------------------------
4419 const TypeInstPtr* TypeInstPtr::cast_to_instance_id(int instance_id) const {
4420   if( instance_id == _instance_id ) return this;
4421   return make(_ptr, klass(), _interfaces, _klass_is_exact, const_oop(), _offset, _flat_in_array, instance_id, _speculative, _inline_depth);
4422 }
4423 
4424 //------------------------------xmeet_unloaded---------------------------------
4425 // Compute the MEET of two InstPtrs when at least one is unloaded.
4426 // Assume classes are different since called after check for same name/class-loader
4427 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst, const TypeInterfaces* interfaces) const {
4428   Offset off = meet_offset(tinst->offset());
4429   PTR ptr = meet_ptr(tinst->ptr());
4430   int instance_id = meet_instance_id(tinst->instance_id());
4431   const TypePtr* speculative = xmeet_speculative(tinst);
4432   int depth = meet_inline_depth(tinst->inline_depth());
4433 
4434   const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
4435   const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
4436   if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
4437     //
4438     // Meet unloaded class with java/lang/Object
4439     //
4440     // Meet
4441     //          |                     Unloaded Class
4442     //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
4443     //  ===================================================================
4444     //   TOP    | ..........................Unloaded......................|
4445     //  AnyNull |  U-AN    |................Unloaded......................|
4446     // Constant | ... O-NN .................................. |   O-BOT   |
4447     //  NotNull | ... O-NN .................................. |   O-BOT   |
4448     //  BOTTOM  | ........................Object-BOTTOM ..................|
4449     //
4450     assert(loaded->ptr() != TypePtr::Null, "insanity check");
4451     //
4452     if (loaded->ptr() == TypePtr::TopPTR)        { return unloaded->with_speculative(speculative); }
4453     else if (loaded->ptr() == TypePtr::AnyNull)  {
4454       FlatInArray flat_in_array = meet_flat_in_array(_flat_in_array, tinst->flat_in_array());
4455       return make(ptr, unloaded->klass(), interfaces, false, nullptr, off, flat_in_array, instance_id,
4456                   speculative, depth);
4457     }
4458     else if (loaded->ptr() == TypePtr::BotPTR)   { return TypeInstPtr::BOTTOM->with_speculative(speculative); }
4459     else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
4460       if (unloaded->ptr() == TypePtr::BotPTR)    { return TypeInstPtr::BOTTOM->with_speculative(speculative);  }
4461       else                                       { return TypeInstPtr::NOTNULL->with_speculative(speculative); }
4462     }
4463     else if (unloaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); }
4464 
4465     return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr()->with_speculative(speculative);
4466   }
4467 
4468   // Both are unloaded, not the same class, not Object
4469   // Or meet unloaded with a different loaded class, not java/lang/Object
4470   if (ptr != TypePtr::BotPTR) {
4471     return TypeInstPtr::NOTNULL->with_speculative(speculative);
4472   }
4473   return TypeInstPtr::BOTTOM->with_speculative(speculative);
4474 }
4475 
4476 
4477 //------------------------------meet-------------------------------------------
4478 // Compute the MEET of two types.  It returns a new Type object.
4479 const Type *TypeInstPtr::xmeet_helper(const Type *t) const {
4480   // Perform a fast test for common case; meeting the same types together.
4481   if( this == t ) return this;  // Meeting same type-rep?
4482 
4483   // Current "this->_base" is Pointer
4484   switch (t->base()) {          // switch on original type
4485 
4486   case Int:                     // Mixing ints & oops happens when javac
4487   case Long:                    // reuses local variables
4488   case HalfFloatTop:
4489   case HalfFloatCon:
4490   case HalfFloatBot:
4491   case FloatTop:
4492   case FloatCon:
4493   case FloatBot:
4494   case DoubleTop:
4495   case DoubleCon:
4496   case DoubleBot:
4497   case NarrowOop:
4498   case NarrowKlass:
4499   case Bottom:                  // Ye Olde Default
4500     return Type::BOTTOM;
4501   case Top:
4502     return this;
4503 
4504   default:                      // All else is a mistake
4505     typerr(t);
4506 
4507   case MetadataPtr:
4508   case KlassPtr:
4509   case InstKlassPtr:
4510   case AryKlassPtr:
4511   case RawPtr: return TypePtr::BOTTOM;
4512 
4513   case AryPtr: {                // All arrays inherit from Object class
4514     // Call in reverse direction to avoid duplication
4515     return t->is_aryptr()->xmeet_helper(this);
4516   }
4517 
4518   case OopPtr: {                // Meeting to OopPtrs
4519     // Found a OopPtr type vs self-InstPtr type
4520     const TypeOopPtr *tp = t->is_oopptr();
4521     Offset offset = meet_offset(tp->offset());
4522     PTR ptr = meet_ptr(tp->ptr());
4523     switch (tp->ptr()) {
4524     case TopPTR:
4525     case AnyNull: {
4526       int instance_id = meet_instance_id(InstanceTop);
4527       const TypePtr* speculative = xmeet_speculative(tp);
4528       int depth = meet_inline_depth(tp->inline_depth());
4529       return make(ptr, klass(), _interfaces, klass_is_exact(),
4530                   (ptr == Constant ? const_oop() : nullptr), offset, flat_in_array(), instance_id, speculative, depth);
4531     }
4532     case NotNull:
4533     case BotPTR: {
4534       int instance_id = meet_instance_id(tp->instance_id());
4535       const TypePtr* speculative = xmeet_speculative(tp);
4536       int depth = meet_inline_depth(tp->inline_depth());
4537       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4538     }
4539     default: typerr(t);
4540     }
4541   }
4542 
4543   case AnyPtr: {                // Meeting to AnyPtrs
4544     // Found an AnyPtr type vs self-InstPtr type
4545     const TypePtr *tp = t->is_ptr();
4546     Offset offset = meet_offset(tp->offset());
4547     PTR ptr = meet_ptr(tp->ptr());
4548     int instance_id = meet_instance_id(InstanceTop);
4549     const TypePtr* speculative = xmeet_speculative(tp);
4550     int depth = meet_inline_depth(tp->inline_depth());
4551     switch (tp->ptr()) {
4552     case Null:
4553       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4554       // else fall through to AnyNull
4555     case TopPTR:
4556     case AnyNull: {
4557       return make(ptr, klass(), _interfaces, klass_is_exact(),
4558                   (ptr == Constant ? const_oop() : nullptr), offset, flat_in_array(), instance_id, speculative, depth);
4559     }
4560     case NotNull:
4561     case BotPTR:
4562       return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4563     default: typerr(t);
4564     }
4565   }
4566 
4567   /*
4568                  A-top         }
4569                /   |   \       }  Tops
4570            B-top A-any C-top   }
4571               | /  |  \ |      }  Any-nulls
4572            B-any   |   C-any   }
4573               |    |    |
4574            B-con A-con C-con   } constants; not comparable across classes
4575               |    |    |
4576            B-not   |   C-not   }
4577               | \  |  / |      }  not-nulls
4578            B-bot A-not C-bot   }
4579                \   |   /       }  Bottoms
4580                  A-bot         }
4581   */
4582 
4583   case InstPtr: {                // Meeting 2 Oops?
4584     // Found an InstPtr sub-type vs self-InstPtr type
4585     const TypeInstPtr *tinst = t->is_instptr();
4586     Offset off = meet_offset(tinst->offset());
4587     PTR ptr = meet_ptr(tinst->ptr());
4588     int instance_id = meet_instance_id(tinst->instance_id());
4589     const TypePtr* speculative = xmeet_speculative(tinst);
4590     int depth = meet_inline_depth(tinst->inline_depth());
4591     const TypeInterfaces* interfaces = meet_interfaces(tinst);
4592 
4593     ciKlass* tinst_klass = tinst->klass();
4594     ciKlass* this_klass  = klass();
4595 
4596     ciKlass* res_klass = nullptr;
4597     bool res_xk = false;
4598     const Type* res;
4599     MeetResult kind = meet_instptr(ptr, interfaces, this, tinst, res_klass, res_xk);
4600 
4601     if (kind == UNLOADED) {
4602       // One of these classes has not been loaded
4603       const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst, interfaces);
4604 #ifndef PRODUCT
4605       if (PrintOpto && Verbose) {
4606         tty->print("meet of unloaded classes resulted in: ");
4607         unloaded_meet->dump();
4608         tty->cr();
4609         tty->print("  this == ");
4610         dump();
4611         tty->cr();
4612         tty->print(" tinst == ");
4613         tinst->dump();
4614         tty->cr();
4615       }
4616 #endif
4617       res = unloaded_meet;
4618     } else {
4619       FlatInArray flat_in_array = meet_flat_in_array(_flat_in_array, tinst->flat_in_array());
4620       if (kind == NOT_SUBTYPE && instance_id > 0) {
4621         instance_id = InstanceBot;
4622       } else if (kind == LCA) {
4623         instance_id = InstanceBot;
4624       }
4625       ciObject* o = nullptr;             // Assume not constant when done
4626       ciObject* this_oop = const_oop();
4627       ciObject* tinst_oop = tinst->const_oop();
4628       if (ptr == Constant) {
4629         if (this_oop != nullptr && tinst_oop != nullptr &&
4630             this_oop->equals(tinst_oop))
4631           o = this_oop;
4632         else if (above_centerline(_ptr)) {
4633           assert(!tinst_klass->is_interface(), "");
4634           o = tinst_oop;
4635         } else if (above_centerline(tinst->_ptr)) {
4636           assert(!this_klass->is_interface(), "");
4637           o = this_oop;
4638         } else
4639           ptr = NotNull;
4640       }
4641       res = make(ptr, res_klass, interfaces, res_xk, o, off, flat_in_array, instance_id, speculative, depth);
4642     }
4643 
4644     return res;
4645 
4646   } // End of case InstPtr
4647 
4648   } // End of switch
4649   return this;                  // Return the double constant
4650 }
4651 
4652 template<class T> TypePtr::MeetResult TypePtr::meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type, const T* other_type,
4653                                                             ciKlass*& res_klass, bool& res_xk) {
4654   ciKlass* this_klass = this_type->klass();
4655   ciKlass* other_klass = other_type->klass();
4656 
4657   bool this_xk = this_type->klass_is_exact();
4658   bool other_xk = other_type->klass_is_exact();
4659   PTR this_ptr = this_type->ptr();
4660   PTR other_ptr = other_type->ptr();
4661   const TypeInterfaces* this_interfaces = this_type->interfaces();
4662   const TypeInterfaces* other_interfaces = other_type->interfaces();
4663   // Check for easy case; klasses are equal (and perhaps not loaded!)
4664   // If we have constants, then we created oops so classes are loaded
4665   // and we can handle the constants further down.  This case handles
4666   // both-not-loaded or both-loaded classes
4667   if (ptr != Constant && this_klass->equals(other_klass) && this_xk == other_xk) {
4668     res_klass = this_klass;
4669     res_xk = this_xk;
4670     return QUICK;
4671   }
4672 
4673   // Classes require inspection in the Java klass hierarchy.  Must be loaded.
4674   if (!other_klass->is_loaded() || !this_klass->is_loaded()) {
4675     return UNLOADED;
4676   }
4677 
4678   // !!! Here's how the symmetry requirement breaks down into invariants:
4679   // If we split one up & one down AND they subtype, take the down man.
4680   // If we split one up & one down AND they do NOT subtype, "fall hard".
4681   // If both are up and they subtype, take the subtype class.
4682   // If both are up and they do NOT subtype, "fall hard".
4683   // If both are down and they subtype, take the supertype class.
4684   // If both are down and they do NOT subtype, "fall hard".
4685   // Constants treated as down.
4686 
4687   // Now, reorder the above list; observe that both-down+subtype is also
4688   // "fall hard"; "fall hard" becomes the default case:
4689   // If we split one up & one down AND they subtype, take the down man.
4690   // If both are up and they subtype, take the subtype class.
4691 
4692   // If both are down and they subtype, "fall hard".
4693   // If both are down and they do NOT subtype, "fall hard".
4694   // If both are up and they do NOT subtype, "fall hard".
4695   // If we split one up & one down AND they do NOT subtype, "fall hard".
4696 
4697   // If a proper subtype is exact, and we return it, we return it exactly.
4698   // If a proper supertype is exact, there can be no subtyping relationship!
4699   // If both types are equal to the subtype, exactness is and-ed below the
4700   // centerline and or-ed above it.  (N.B. Constants are always exact.)
4701 

4702   const T* subtype = nullptr;
4703   bool subtype_exact = false;
4704   if (this_type->is_same_java_type_as(other_type)) {
4705     // Same klass
4706     subtype = this_type;
4707     subtype_exact = below_centerline(ptr) ? (this_xk && other_xk) : (this_xk || other_xk);
4708   } else if (!other_xk && this_type->is_meet_subtype_of(other_type)) {
4709     subtype = this_type;     // Pick subtyping class
4710     subtype_exact = this_xk;
4711   } else if (!this_xk && other_type->is_meet_subtype_of(this_type)) {
4712     subtype = other_type;    // Pick subtyping class
4713     subtype_exact = other_xk;
4714   }
4715 
4716   if (subtype != nullptr) {
4717     if (above_centerline(ptr)) {
4718       // Both types are empty.
4719       this_type = other_type = subtype;
4720       this_xk = other_xk = subtype_exact;
4721     } else if (above_centerline(this_ptr) && !above_centerline(other_ptr)) {
4722       // this_type is empty while other_type is not. Take other_type.
4723       this_type = other_type;
4724       this_xk = other_xk;
4725     } else if (above_centerline(other_ptr) && !above_centerline(this_ptr)) {
4726       // other_type is empty while this_type is not. Take this_type.
4727       other_type = this_type; // this is down; keep down man

4728     } else {
4729       // this_type and other_type are both non-empty.
4730       this_xk = subtype_exact;  // either they are equal, or we'll do an LCA
4731     }
4732   }
4733 
4734   // Check for classes now being equal
4735   if (this_type->is_same_java_type_as(other_type)) {
4736     // If the klasses are equal, the constants may still differ.  Fall to
4737     // NotNull if they do (neither constant is null; that is a special case
4738     // handled elsewhere).
4739     res_klass = this_type->klass();
4740     res_xk = this_xk;
4741     return SUBTYPE;
4742   } // Else classes are not equal
4743 
4744   // Since klasses are different, we require a LCA in the Java
4745   // class hierarchy - which means we have to fall to at least NotNull.
4746   if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4747     ptr = NotNull;
4748   }
4749 
4750   interfaces = this_interfaces->intersection_with(other_interfaces);
4751 
4752   // Now we find the LCA of Java classes
4753   ciKlass* k = this_klass->least_common_ancestor(other_klass);
4754 
4755   res_klass = k;
4756   res_xk = false;

4757   return LCA;
4758 }
4759 
4760 //                Top-Flat    Flat        Not-Flat    Maybe-Flat
4761 // -------------------------------------------------------------
4762 //    Top-Flat    Top-Flat    Flat        Not-Flat    Maybe-Flat
4763 //        Flat    Flat        Flat        Maybe-Flat  Maybe-Flat
4764 //    Not-Flat    Not-Flat    Maybe-Flat  Not-Flat    Maybe-Flat
4765 //  Maybe-Flat    Maybe-Flat  Maybe-Flat  Maybe-Flat  Maybe-flat
4766 TypePtr::FlatInArray TypePtr::meet_flat_in_array(const FlatInArray left, const FlatInArray right) {
4767   if (left == TopFlat) {
4768     return right;
4769   }
4770   if (right == TopFlat) {
4771     return left;
4772   }
4773   if (left == MaybeFlat || right == MaybeFlat) {
4774     return MaybeFlat;
4775   }
4776 
4777   switch (left) {
4778     case Flat:
4779       if (right == Flat) {
4780         return Flat;
4781       }
4782       return MaybeFlat;
4783     case NotFlat:
4784       if (right == NotFlat) {
4785         return NotFlat;
4786       }
4787       return MaybeFlat;
4788     default:
4789       ShouldNotReachHere();
4790       return Uninitialized;
4791   }
4792 }
4793 
4794 //------------------------java_mirror_type--------------------------------------
4795 ciType* TypeInstPtr::java_mirror_type() const {
4796   // must be a singleton type
4797   if( const_oop() == nullptr )  return nullptr;
4798 
4799   // must be of type java.lang.Class
4800   if( klass() != ciEnv::current()->Class_klass() )  return nullptr;

4801   return const_oop()->as_instance()->java_mirror_type();
4802 }
4803 
4804 
4805 //------------------------------xdual------------------------------------------
4806 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
4807 // inheritance mechanism.
4808 const Type* TypeInstPtr::xdual() const {
4809   return new TypeInstPtr(dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(),
4810                          dual_flat_in_array(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4811 }
4812 
4813 //------------------------------eq---------------------------------------------
4814 // Structural equality check for Type representations
4815 bool TypeInstPtr::eq( const Type *t ) const {
4816   const TypeInstPtr *p = t->is_instptr();
4817   return
4818     klass()->equals(p->klass()) &&
4819     _flat_in_array == p->_flat_in_array &&
4820     _interfaces->eq(p->_interfaces) &&
4821     TypeOopPtr::eq(p);          // Check sub-type stuff
4822 }
4823 
4824 //------------------------------hash-------------------------------------------
4825 // Type-specific hashing function.
4826 uint TypeInstPtr::hash() const {
4827   return klass()->hash() + TypeOopPtr::hash() + _interfaces->hash() + static_cast<uint>(_flat_in_array);
4828 }
4829 
4830 bool TypeInstPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4831   return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4832 }
4833 
4834 
4835 bool TypeInstPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4836   return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
4837 }
4838 
4839 bool TypeInstPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4840   return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4841 }
4842 
4843 
4844 //------------------------------dump2------------------------------------------
4845 // Dump oop Type
4846 #ifndef PRODUCT
4847 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {
4848   // Print the name of the klass.
4849   st->print("instptr:");
4850   klass()->print_name_on(st);
4851   _interfaces->dump(st);
4852 
4853   if (_ptr == Constant && (WizardMode || Verbose)) {
4854     ResourceMark rm;
4855     stringStream ss;
4856 
4857     st->print(" ");
4858     const_oop()->print_oop(&ss);
4859     // 'const_oop->print_oop()' may emit newlines('\n') into ss.
4860     // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4861     char* buf = ss.as_string(/* c_heap= */false);
4862     StringUtils::replace_no_expand(buf, "\n", "");
4863     st->print_raw(buf);
4864   }
4865 
4866   st->print(":%s", ptr_msg[_ptr]);
4867   if (_klass_is_exact) {
4868     st->print(":exact");
4869   }
4870 
4871   st->print(" *");
4872 
4873   dump_offset(st);
4874   dump_instance_id(st);
4875   dump_inline_depth(st);
4876   dump_speculative(st);
4877   dump_flat_in_array(_flat_in_array, st);
4878 }
4879 #endif
4880 
4881 bool TypeInstPtr::empty() const {
4882   if (_flat_in_array == TopFlat) {
4883     return true;
4884   }
4885   return TypeOopPtr::empty();
4886 }
4887 
4888 //------------------------------add_offset-------------------------------------
4889 const TypePtr* TypeInstPtr::add_offset(intptr_t offset) const {
4890   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), xadd_offset(offset), _flat_in_array,
4891               _instance_id, add_offset_speculative(offset), _inline_depth);
4892 }
4893 
4894 const TypeInstPtr* TypeInstPtr::with_offset(intptr_t offset) const {
4895   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), Offset(offset), _flat_in_array,
4896               _instance_id, with_offset_speculative(offset), _inline_depth);
4897 }
4898 
4899 const TypeInstPtr* TypeInstPtr::remove_speculative() const {
4900   if (_speculative == nullptr) {
4901     return this;
4902   }
4903   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4904   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _flat_in_array,
4905               _instance_id, nullptr, _inline_depth);
4906 }
4907 
4908 const TypeInstPtr* TypeInstPtr::with_speculative(const TypePtr* speculative) const {
4909   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _flat_in_array, _instance_id, speculative, _inline_depth);
4910 }
4911 
4912 const TypePtr* TypeInstPtr::with_inline_depth(int depth) const {
4913   if (!UseInlineDepthForSpeculativeTypes) {
4914     return this;
4915   }
4916   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _flat_in_array, _instance_id, _speculative, depth);
4917 }
4918 
4919 const TypePtr* TypeInstPtr::with_instance_id(int instance_id) const {
4920   assert(is_known_instance(), "should be known");
4921   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _flat_in_array, instance_id, _speculative, _inline_depth);
4922 }
4923 
4924 const TypeInstPtr *TypeInstPtr::cast_to_flat_in_array() const {
4925   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, Flat, _instance_id, _speculative, _inline_depth);
4926 }
4927 
4928 const TypeInstPtr *TypeInstPtr::cast_to_maybe_flat_in_array() const {
4929   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, MaybeFlat, _instance_id, _speculative, _inline_depth);
4930 }
4931 
4932 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4933   bool xk = klass_is_exact();
4934   ciInstanceKlass* ik = klass()->as_instance_klass();
4935   if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final()) {
4936     if (_interfaces->eq(ik)) {
4937       Compile* C = Compile::current();
4938       Dependencies* deps = C->dependencies();
4939       deps->assert_leaf_type(ik);
4940       xk = true;
4941     }
4942   }
4943   FlatInArray flat_in_array = compute_flat_in_array_if_unknown(ik, xk, _flat_in_array);
4944   return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), _interfaces, Offset(0), flat_in_array);
4945 }
4946 
4947 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) {
4948   static_assert(std::is_base_of<T2, T1>::value, "");
4949 
4950   if (!this_one->is_instance_type(other)) {
4951     return false;
4952   }
4953 
4954   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4955     return true;
4956   }
4957 
4958   return this_one->klass()->is_subtype_of(other->klass()) &&
4959          (!this_xk || this_one->_interfaces->contains(other->_interfaces));
4960 }
4961 
4962 
4963 bool TypeInstPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4964   return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4965 }
4966 
4967 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) {
4968   static_assert(std::is_base_of<T2, T1>::value, "");
4969   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4970     return true;
4971   }
4972 
4973   if (this_one->is_instance_type(other)) {
4974     return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces);
4975   }
4976 
4977   int dummy;
4978   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
4979   if (this_top_or_bottom) {
4980     return false;
4981   }
4982 
4983   const T1* other_ary = this_one->is_array_type(other);
4984   const TypePtr* other_elem = other_ary->elem()->make_ptr();
4985   const TypePtr* this_elem = this_one->elem()->make_ptr();
4986   if (other_elem != nullptr && this_elem != nullptr) {
4987     return this_one->is_reference_type(this_elem)->is_meet_subtype_of_helper(this_one->is_reference_type(other_elem), this_xk, other_xk);
4988   }

4989   if (other_elem == nullptr && this_elem == nullptr) {
4990     return this_one->klass()->is_subtype_of(other->klass());
4991   }
4992 
4993   return false;
4994 }
4995 
4996 bool TypeAryPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4997   return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4998 }
4999 
5000 bool TypeInstKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
5001   return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
5002 }
5003 
5004 bool TypeAryKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
5005   return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
5006 }
5007 
5008 //=============================================================================
5009 // Convenience common pre-built types.
5010 const TypeAryPtr* TypeAryPtr::BOTTOM;
5011 const TypeAryPtr *TypeAryPtr::RANGE;
5012 const TypeAryPtr *TypeAryPtr::OOPS;
5013 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
5014 const TypeAryPtr *TypeAryPtr::BYTES;
5015 const TypeAryPtr *TypeAryPtr::SHORTS;
5016 const TypeAryPtr *TypeAryPtr::CHARS;
5017 const TypeAryPtr *TypeAryPtr::INTS;
5018 const TypeAryPtr *TypeAryPtr::LONGS;
5019 const TypeAryPtr *TypeAryPtr::FLOATS;
5020 const TypeAryPtr *TypeAryPtr::DOUBLES;
5021 const TypeAryPtr *TypeAryPtr::INLINES;
5022 
5023 //------------------------------make-------------------------------------------
5024 const TypeAryPtr* TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
5025                                    int instance_id, const TypePtr* speculative, int inline_depth) {
5026   assert(!(k == nullptr && ary->_elem->isa_int()),
5027          "integral arrays must be pre-equipped with a class");
5028   if (!xk)  xk = ary->ary_must_be_exact();
5029   assert(instance_id <= 0 || xk, "instances are always exactly typed");
5030   if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
5031       k->as_obj_array_klass()->base_element_klass()->is_interface()) {
5032     k = nullptr;
5033   }
5034   return (TypeAryPtr*)(new TypeAryPtr(ptr, nullptr, ary, k, xk, offset, field_offset, instance_id, false, speculative, inline_depth))->hashcons();
5035 }
5036 
5037 //------------------------------make-------------------------------------------
5038 const TypeAryPtr* TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
5039                                    int instance_id, const TypePtr* speculative, int inline_depth,
5040                                    bool is_autobox_cache) {
5041   assert(!(k == nullptr && ary->_elem->isa_int()),
5042          "integral arrays must be pre-equipped with a class");
5043   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
5044   if (!xk)  xk = (o != nullptr) || ary->ary_must_be_exact();
5045   assert(instance_id <= 0 || xk, "instances are always exactly typed");
5046   if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
5047       k->as_obj_array_klass()->base_element_klass()->is_interface()) {
5048     k = nullptr;
5049   }
5050   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, field_offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
5051 }
5052 
5053 //------------------------------cast_to_ptr_type-------------------------------
5054 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
5055   if( ptr == _ptr ) return this;
5056   return make(ptr, ptr == Constant ? const_oop() : nullptr, _ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5057 }
5058 
5059 
5060 //-----------------------------cast_to_exactness-------------------------------
5061 const TypeAryPtr* TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
5062   if( klass_is_exact == _klass_is_exact ) return this;
5063   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
5064   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5065 }
5066 
5067 //-----------------------------cast_to_instance_id----------------------------
5068 const TypeAryPtr* TypeAryPtr::cast_to_instance_id(int instance_id) const {
5069   if( instance_id == _instance_id ) return this;
5070   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth, _is_autobox_cache);
5071 }
5072 
5073 
5074 //-----------------------------max_array_length-------------------------------
5075 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
5076 jint TypeAryPtr::max_array_length(BasicType etype) {
5077   if (!is_java_primitive(etype) && !::is_reference_type(etype)) {
5078     if (etype == T_NARROWOOP) {
5079       etype = T_OBJECT;
5080     } else if (etype == T_ILLEGAL) { // bottom[]
5081       etype = T_BYTE; // will produce conservatively high value
5082     } else {
5083       fatal("not an element type: %s", type2name(etype));
5084     }
5085   }
5086   return arrayOopDesc::max_array_length(etype);
5087 }
5088 
5089 //-----------------------------narrow_size_type-------------------------------
5090 // Narrow the given size type to the index range for the given array base type.
5091 // Return null if the resulting int type becomes empty.
5092 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const {
5093   jint hi = size->_hi;
5094   jint lo = size->_lo;
5095   jint min_lo = 0;
5096   jint max_hi = max_array_length(elem()->array_element_basic_type());
5097   //if (index_not_size)  --max_hi;     // type of a valid array index, FTR
5098   bool chg = false;
5099   if (lo < min_lo) {
5100     lo = min_lo;
5101     if (size->is_con()) {
5102       hi = lo;
5103     }
5104     chg = true;
5105   }
5106   if (hi > max_hi) {
5107     hi = max_hi;
5108     if (size->is_con()) {
5109       lo = hi;
5110     }
5111     chg = true;
5112   }
5113   // Negative length arrays will produce weird intermediate dead fast-path code
5114   if (lo > hi) {
5115     return TypeInt::ZERO;
5116   }
5117   if (!chg) {
5118     return size;
5119   }
5120   return TypeInt::make(lo, hi, Type::WidenMin);
5121 }
5122 
5123 //-------------------------------cast_to_size----------------------------------
5124 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
5125   assert(new_size != nullptr, "");
5126   new_size = narrow_size_type(new_size);
5127   if (new_size == size())  return this;
5128   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable(), is_flat(), is_not_flat(), is_not_null_free(), is_atomic());
5129   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5130 }
5131 
5132 const TypeAryPtr* TypeAryPtr::cast_to_flat(bool flat) const {
5133   if (flat == is_flat()) {
5134     return this;
5135   }
5136   assert(!flat || !is_not_flat(), "inconsistency");
5137   const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), flat, is_not_flat(), is_not_null_free(), is_atomic());
5138   const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5139   if (res->speculative() == res->remove_speculative()) {
5140     return res->remove_speculative();
5141   }
5142   return res;
5143 }
5144 
5145 //-------------------------------cast_to_not_flat------------------------------
5146 const TypeAryPtr* TypeAryPtr::cast_to_not_flat(bool not_flat) const {
5147   if (not_flat == is_not_flat()) {
5148     return this;
5149   }
5150   assert(!not_flat || !is_flat(), "inconsistency");
5151   const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), is_flat(), not_flat, is_not_null_free(), is_atomic());
5152   const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5153   // We keep the speculative part if it contains information about flat-/nullability.
5154   // Make sure it's removed if it's not better than the non-speculative type anymore.
5155   if (res->speculative() == res->remove_speculative()) {
5156     return res->remove_speculative();
5157   }
5158   return res;
5159 }
5160 
5161 const TypeAryPtr* TypeAryPtr::cast_to_null_free(bool null_free) const {
5162   if (null_free == is_null_free()) {
5163     return this;
5164   }
5165   assert(!null_free || !is_not_null_free(), "inconsistency");
5166   const Type* elem = this->elem();
5167   const Type* new_elem = elem->make_ptr();
5168   if (null_free) {
5169     new_elem = new_elem->join_speculative(TypePtr::NOTNULL);
5170   } else {
5171     new_elem = new_elem->meet_speculative(TypePtr::NULL_PTR);
5172   }
5173   new_elem = elem->isa_narrowoop() ? new_elem->make_narrowoop() : new_elem;
5174   const TypeAry* new_ary = TypeAry::make(new_elem, size(), is_stable(), is_flat(), is_not_flat(), is_not_null_free(), is_atomic());
5175   const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5176   if (res->speculative() == res->remove_speculative()) {
5177     return res->remove_speculative();
5178   }
5179   assert(res->speculative() == nullptr || res->speculative()->with_inline_depth(res->inline_depth())->higher_equal(res->remove_speculative()),
5180            "speculative type must not be narrower than non-speculative type");
5181   return res;
5182 }
5183 
5184 //-------------------------------cast_to_not_null_free-------------------------
5185 const TypeAryPtr* TypeAryPtr::cast_to_not_null_free(bool not_null_free) const {
5186   if (not_null_free == is_not_null_free()) {
5187     return this;
5188   }
5189   assert(!not_null_free || !is_null_free(), "inconsistency");
5190   const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), is_flat(), is_not_flat(), not_null_free, is_atomic());
5191   const TypePtr* new_spec = _speculative;
5192   if (new_spec != nullptr) {
5193     // Could be 'null free' from profiling, which would contradict the cast.
5194     new_spec = new_spec->is_aryptr()->cast_to_null_free(false)->cast_to_not_null_free();
5195   }
5196   const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset,
5197                                _instance_id, new_spec, _inline_depth, _is_autobox_cache);
5198   // We keep the speculative part if it contains information about flat-/nullability.
5199   // Make sure it's removed if it's not better than the non-speculative type anymore.
5200   if (res->speculative() == res->remove_speculative()) {
5201     return res->remove_speculative();
5202   }
5203   assert(res->speculative() == nullptr || res->speculative()->with_inline_depth(res->inline_depth())->higher_equal(res->remove_speculative()),
5204            "speculative type must not be narrower than non-speculative type");
5205   return res;
5206 }
5207 
5208 //---------------------------------update_properties---------------------------
5209 const TypeAryPtr* TypeAryPtr::update_properties(const TypeAryPtr* from) const {
5210   if ((from->is_flat()          && is_not_flat()) ||
5211       (from->is_not_flat()      && is_flat()) ||
5212       (from->is_null_free()     && is_not_null_free()) ||
5213       (from->is_not_null_free() && is_null_free())) {
5214     return nullptr; // Inconsistent properties
5215   }
5216   const TypeAryPtr* res = this;
5217   if (from->is_not_null_free()) {
5218     res = res->cast_to_not_null_free();
5219   }
5220   if (from->is_not_flat()) {
5221     res = res->cast_to_not_flat();
5222   }
5223   return res;
5224 }
5225 
5226 jint TypeAryPtr::flat_layout_helper() const {
5227   return exact_klass()->as_flat_array_klass()->layout_helper();
5228 }
5229 
5230 int TypeAryPtr::flat_elem_size() const {
5231   return exact_klass()->as_flat_array_klass()->element_byte_size();
5232 }
5233 
5234 int TypeAryPtr::flat_log_elem_size() const {
5235   return exact_klass()->as_flat_array_klass()->log2_element_size();
5236 }
5237 
5238 //------------------------------cast_to_stable---------------------------------
5239 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
5240   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
5241     return this;
5242 
5243   const Type* elem = this->elem();
5244   const TypePtr* elem_ptr = elem->make_ptr();
5245 
5246   if (stable_dimension > 1 && elem_ptr != nullptr && elem_ptr->isa_aryptr()) {
5247     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
5248     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
5249   }
5250 
5251   const TypeAry* new_ary = TypeAry::make(elem, size(), stable, is_flat(), is_not_flat(), is_not_null_free(), is_atomic());
5252 
5253   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5254 }
5255 
5256 //-----------------------------stable_dimension--------------------------------
5257 int TypeAryPtr::stable_dimension() const {
5258   if (!is_stable())  return 0;
5259   int dim = 1;
5260   const TypePtr* elem_ptr = elem()->make_ptr();
5261   if (elem_ptr != nullptr && elem_ptr->isa_aryptr())
5262     dim += elem_ptr->is_aryptr()->stable_dimension();
5263   return dim;
5264 }
5265 
5266 //----------------------cast_to_autobox_cache-----------------------------------
5267 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
5268   if (is_autobox_cache())  return this;
5269   const TypeOopPtr* etype = elem()->make_oopptr();
5270   if (etype == nullptr)  return this;
5271   // The pointers in the autobox arrays are always non-null.
5272   etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
5273   const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable(), is_flat(), is_not_flat(), is_not_null_free(), is_atomic());
5274   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
5275 }
5276 
5277 //------------------------------eq---------------------------------------------
5278 // Structural equality check for Type representations
5279 bool TypeAryPtr::eq( const Type *t ) const {
5280   const TypeAryPtr *p = t->is_aryptr();
5281   return
5282     _ary == p->_ary &&  // Check array
5283     TypeOopPtr::eq(p) &&// Check sub-parts
5284     _field_offset == p->_field_offset;
5285 }
5286 
5287 //------------------------------hash-------------------------------------------
5288 // Type-specific hashing function.
5289 uint TypeAryPtr::hash(void) const {
5290   return (uint)(uintptr_t)_ary + TypeOopPtr::hash() + _field_offset.get();
5291 }
5292 
5293 bool TypeAryPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
5294   return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
5295 }
5296 
5297 bool TypeAryPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
5298   return TypePtr::is_same_java_type_as_helper_for_array(this, other);
5299 }
5300 
5301 bool TypeAryPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
5302   return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
5303 }
5304 //------------------------------meet-------------------------------------------
5305 // Compute the MEET of two types.  It returns a new Type object.
5306 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
5307   // Perform a fast test for common case; meeting the same types together.
5308   if( this == t ) return this;  // Meeting same type-rep?
5309   // Current "this->_base" is Pointer
5310   switch (t->base()) {          // switch on original type
5311 
5312   // Mixing ints & oops happens when javac reuses local variables
5313   case Int:
5314   case Long:
5315   case HalfFloatTop:
5316   case HalfFloatCon:
5317   case HalfFloatBot:
5318   case FloatTop:
5319   case FloatCon:
5320   case FloatBot:
5321   case DoubleTop:
5322   case DoubleCon:
5323   case DoubleBot:
5324   case NarrowOop:
5325   case NarrowKlass:
5326   case Bottom:                  // Ye Olde Default
5327     return Type::BOTTOM;
5328   case Top:
5329     return this;
5330 
5331   default:                      // All else is a mistake
5332     typerr(t);
5333 
5334   case OopPtr: {                // Meeting to OopPtrs
5335     // Found a OopPtr type vs self-AryPtr type
5336     const TypeOopPtr *tp = t->is_oopptr();
5337     Offset offset = meet_offset(tp->offset());
5338     PTR ptr = meet_ptr(tp->ptr());
5339     int depth = meet_inline_depth(tp->inline_depth());
5340     const TypePtr* speculative = xmeet_speculative(tp);
5341     switch (tp->ptr()) {
5342     case TopPTR:
5343     case AnyNull: {
5344       int instance_id = meet_instance_id(InstanceTop);
5345       return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5346                   _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5347     }
5348     case BotPTR:
5349     case NotNull: {
5350       int instance_id = meet_instance_id(tp->instance_id());
5351       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
5352     }
5353     default: ShouldNotReachHere();
5354     }
5355   }
5356 
5357   case AnyPtr: {                // Meeting two AnyPtrs
5358     // Found an AnyPtr type vs self-AryPtr type
5359     const TypePtr *tp = t->is_ptr();
5360     Offset offset = meet_offset(tp->offset());
5361     PTR ptr = meet_ptr(tp->ptr());
5362     const TypePtr* speculative = xmeet_speculative(tp);
5363     int depth = meet_inline_depth(tp->inline_depth());
5364     switch (tp->ptr()) {
5365     case TopPTR:
5366       return this;
5367     case BotPTR:
5368     case NotNull:
5369       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5370     case Null:
5371       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5372       // else fall through to AnyNull
5373     case AnyNull: {
5374       int instance_id = meet_instance_id(InstanceTop);
5375       return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5376                   _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5377     }
5378     default: ShouldNotReachHere();
5379     }
5380   }
5381 
5382   case MetadataPtr:
5383   case KlassPtr:
5384   case InstKlassPtr:
5385   case AryKlassPtr:
5386   case RawPtr: return TypePtr::BOTTOM;
5387 
5388   case AryPtr: {                // Meeting 2 references?
5389     const TypeAryPtr *tap = t->is_aryptr();
5390     Offset off = meet_offset(tap->offset());
5391     Offset field_off = meet_field_offset(tap->field_offset());
5392     const Type* tm = _ary->meet_speculative(tap->_ary);
5393     const TypeAry* tary = tm->isa_ary();
5394     if (tary == nullptr) {
5395       assert(tm == Type::TOP || tm == Type::BOTTOM, "");
5396       return tm;
5397     }
5398     PTR ptr = meet_ptr(tap->ptr());
5399     int instance_id = meet_instance_id(tap->instance_id());
5400     const TypePtr* speculative = xmeet_speculative(tap);
5401     int depth = meet_inline_depth(tap->inline_depth());
5402 
5403     ciKlass* res_klass = nullptr;
5404     bool res_xk = false;
5405     bool res_flat = false;
5406     bool res_not_flat = false;
5407     bool res_not_null_free = false;
5408     bool res_atomic = false;
5409     const Type* elem = tary->_elem;
5410     if (meet_aryptr(ptr, elem, this, tap, res_klass, res_xk, res_flat, res_not_flat, res_not_null_free, res_atomic) == NOT_SUBTYPE) {
5411       instance_id = InstanceBot;
5412     } else if (this->is_flat() != tap->is_flat()) {
5413       // Meeting flat inline type array with non-flat array. Adjust (field) offset accordingly.
5414       if (tary->_flat) {
5415         // Result is in a flat representation
5416         off = Offset(is_flat() ? offset() : tap->offset());
5417         field_off = is_flat() ? field_offset() : tap->field_offset();
5418       } else if (below_centerline(ptr)) {
5419         // Result is in a non-flat representation
5420         off = Offset(flat_offset()).meet(Offset(tap->flat_offset()));
5421         field_off = (field_off == Offset::top) ? Offset::top : Offset::bottom;
5422       } else if (flat_offset() == tap->flat_offset()) {
5423         off = Offset(!is_flat() ? offset() : tap->offset());
5424         field_off = !is_flat() ? field_offset() : tap->field_offset();
5425       }
5426     }
5427 
5428     ciObject* o = nullptr;             // Assume not constant when done
5429     ciObject* this_oop = const_oop();
5430     ciObject* tap_oop = tap->const_oop();
5431     if (ptr == Constant) {
5432       if (this_oop != nullptr && tap_oop != nullptr &&
5433           this_oop->equals(tap_oop)) {
5434         o = tap_oop;
5435       } else if (above_centerline(_ptr)) {
5436         o = tap_oop;
5437       } else if (above_centerline(tap->_ptr)) {
5438         o = this_oop;
5439       } else {
5440         ptr = NotNull;
5441       }
5442     }
5443     return make(ptr, o, TypeAry::make(elem, tary->_size, tary->_stable, res_flat, res_not_flat, res_not_null_free, res_atomic), res_klass, res_xk, off, field_off, instance_id, speculative, depth);
5444   }
5445 
5446   // All arrays inherit from Object class
5447   case InstPtr: {
5448     const TypeInstPtr *tp = t->is_instptr();
5449     Offset offset = meet_offset(tp->offset());
5450     PTR ptr = meet_ptr(tp->ptr());
5451     int instance_id = meet_instance_id(tp->instance_id());
5452     const TypePtr* speculative = xmeet_speculative(tp);
5453     int depth = meet_inline_depth(tp->inline_depth());
5454     const TypeInterfaces* interfaces = meet_interfaces(tp);
5455     const TypeInterfaces* tp_interfaces = tp->_interfaces;
5456     const TypeInterfaces* this_interfaces = _interfaces;
5457 
5458     switch (ptr) {
5459     case TopPTR:
5460     case AnyNull:                // Fall 'down' to dual of object klass
5461       // For instances when a subclass meets a superclass we fall
5462       // below the centerline when the superclass is exact. We need to
5463       // do the same here.
5464       //
5465       // Flat in array:
5466       // We do
5467       //   dual(TypeAryPtr) MEET dual(TypeInstPtr)
5468       // If TypeInstPtr is anything else than Object, then the result of the meet is bottom Object (i.e. we could have
5469       // instances or arrays).
5470       // If TypeInstPtr is an Object and either
5471       // - exact
5472       // - inexact AND flat in array == dual(not flat in array) (i.e. not an array type)
5473       // then the result of the meet is bottom Object (i.e. we could have instances or arrays).
5474       // Otherwise, we meet two array pointers and create a new TypeAryPtr.
5475       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
5476           !tp->klass_is_exact() && !tp->is_not_flat_in_array()) {
5477         return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5478       } else {
5479         // cannot subclass, so the meet has to fall badly below the centerline
5480         ptr = NotNull;
5481         instance_id = InstanceBot;
5482         interfaces = this_interfaces->intersection_with(tp_interfaces);
5483         FlatInArray flat_in_array = meet_flat_in_array(NotFlat, tp->flat_in_array());
5484         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset, flat_in_array, instance_id, speculative, depth);
5485       }
5486     case Constant:
5487     case NotNull:
5488     case BotPTR: { // Fall down to object klass
5489       // LCA is object_klass, but if we subclass from the top we can do better
5490       if (above_centerline(tp->ptr())) {
5491         // If 'tp'  is above the centerline and it is Object class
5492         // then we can subclass in the Java class hierarchy.
5493         // For instances when a subclass meets a superclass we fall
5494         // below the centerline when the superclass is exact. We need
5495         // to do the same here.
5496 
5497         // Flat in array: We do TypeAryPtr MEET dual(TypeInstPtr), same applies as above in TopPTR/AnyNull case.
5498         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
5499             !tp->klass_is_exact() && !tp->is_not_flat_in_array()) {
5500           // that is, my array type is a subtype of 'tp' klass
5501           return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5502                       _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5503         }
5504       }
5505       // The other case cannot happen, since t cannot be a subtype of an array.
5506       // The meet falls down to Object class below centerline.
5507       if (ptr == Constant) {
5508         ptr = NotNull;
5509       }
5510       if (instance_id > 0) {
5511         instance_id = InstanceBot;
5512       }
5513 
5514       FlatInArray flat_in_array = meet_flat_in_array(NotFlat, tp->flat_in_array());
5515       interfaces = this_interfaces->intersection_with(tp_interfaces);
5516       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset,
5517                                flat_in_array, instance_id, speculative, depth);
5518     }
5519     default: typerr(t);
5520     }
5521   }
5522   }
5523   return this;                  // Lint noise
5524 }
5525 
5526 
5527 template<class T> TypePtr::MeetResult TypePtr::meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary, const T* other_ary,
5528                                                            ciKlass*& res_klass, bool& res_xk, bool &res_flat, bool& res_not_flat, bool& res_not_null_free, bool &res_atomic) {
5529   int dummy;
5530   bool this_top_or_bottom = (this_ary->base_element_type(dummy) == Type::TOP || this_ary->base_element_type(dummy) == Type::BOTTOM);
5531   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
5532   ciKlass* this_klass = this_ary->klass();
5533   ciKlass* other_klass = other_ary->klass();
5534   bool this_xk = this_ary->klass_is_exact();
5535   bool other_xk = other_ary->klass_is_exact();
5536   PTR this_ptr = this_ary->ptr();
5537   PTR other_ptr = other_ary->ptr();
5538   bool this_flat = this_ary->is_flat();
5539   bool this_not_flat = this_ary->is_not_flat();
5540   bool other_flat = other_ary->is_flat();
5541   bool other_not_flat = other_ary->is_not_flat();
5542   bool this_not_null_free = this_ary->is_not_null_free();
5543   bool other_not_null_free = other_ary->is_not_null_free();
5544   bool this_atomic = this_ary->is_atomic();
5545   bool other_atomic = other_ary->is_atomic();
5546   const bool same_nullness = this_ary->is_null_free() == other_ary->is_null_free();
5547   res_klass = nullptr;
5548   MeetResult result = SUBTYPE;
5549   res_flat = this_flat && other_flat;
5550   bool res_null_free = this_ary->is_null_free() && other_ary->is_null_free();
5551   res_not_flat = this_not_flat && other_not_flat;
5552   res_not_null_free = this_not_null_free && other_not_null_free;
5553   res_atomic = this_atomic && other_atomic;
5554 
5555   if (elem->isa_int()) {
5556     // Integral array element types have irrelevant lattice relations.
5557     // It is the klass that determines array layout, not the element type.
5558       if (this_top_or_bottom) {
5559         res_klass = other_klass;
5560       } else if (other_top_or_bottom || other_klass == this_klass) {
5561       res_klass = this_klass;
5562     } else {
5563       // Something like byte[int+] meets char[int+].
5564       // This must fall to bottom, not (int[-128..65535])[int+].
5565       // instance_id = InstanceBot;
5566       elem = Type::BOTTOM;
5567       result = NOT_SUBTYPE;
5568       if (above_centerline(ptr) || ptr == Constant) {
5569         ptr = NotNull;
5570         res_xk = false;
5571         return NOT_SUBTYPE;
5572       }
5573     }
5574   } else {// Non integral arrays.
5575     // Must fall to bottom if exact klasses in upper lattice
5576     // are not equal or super klass is exact.
5577     if ((above_centerline(ptr) || ptr == Constant) && !this_ary->is_same_java_type_as(other_ary) &&
5578         // meet with top[] and bottom[] are processed further down:
5579         !this_top_or_bottom && !other_top_or_bottom &&
5580         // both are exact and not equal:
5581         ((other_xk && this_xk) ||
5582          // 'tap'  is exact and super or unrelated:
5583          (other_xk && !other_ary->is_meet_subtype_of(this_ary)) ||
5584          // 'this' is exact and super or unrelated:
5585          (this_xk && !this_ary->is_meet_subtype_of(other_ary)))) {
5586       if (above_centerline(ptr) || (elem->make_ptr() && above_centerline(elem->make_ptr()->_ptr))) {
5587         elem = Type::BOTTOM;
5588       }
5589       ptr = NotNull;
5590       res_xk = false;
5591       return NOT_SUBTYPE;
5592     }
5593   }
5594 
5595   res_xk = false;
5596   switch (other_ptr) {
5597     case AnyNull:
5598     case TopPTR:
5599       // Compute new klass on demand, do not use tap->_klass
5600       if (below_centerline(this_ptr)) {
5601         res_xk = this_xk;
5602         if (this_ary->is_flat()) {
5603           elem = this_ary->elem();
5604         }
5605       } else {
5606         res_xk = (other_xk || this_xk);
5607       }
5608       break;
5609     case Constant: {
5610       if (this_ptr == Constant && same_nullness) {
5611         // Only exact if same nullness since:
5612         //     null-free [LMyValue <: nullable [LMyValue.
5613         res_xk = true;
5614       } else if (above_centerline(this_ptr)) {
5615         res_xk = true;
5616       } else {
5617         // Only precise for identical arrays
5618         res_xk = this_xk && (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom));
5619         // Even though MyValue is final, [LMyValue is only exact if the array
5620         // is (not) null-free due to null-free [LMyValue <: null-able [LMyValue.
5621         if (res_xk && !res_null_free && !res_not_null_free) {
5622           ptr = NotNull;
5623           res_xk = false;
5624         }
5625       }
5626       break;
5627     }
5628     case NotNull:
5629     case BotPTR:
5630       // Compute new klass on demand, do not use tap->_klass
5631       if (above_centerline(this_ptr)) {
5632         res_xk = other_xk;
5633         if (other_ary->is_flat()) {
5634           elem = other_ary->elem();
5635         }
5636       } else {
5637         res_xk = (other_xk && this_xk) &&
5638                  (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom)); // Only precise for identical arrays
5639         // Even though MyValue is final, [LMyValue is only exact if the array
5640         // is (not) null-free due to null-free [LMyValue <: null-able [LMyValue.
5641         if (res_xk && !res_null_free && !res_not_null_free) {
5642           ptr = NotNull;
5643           res_xk = false;
5644         }
5645       }
5646       break;
5647     default:  {
5648       ShouldNotReachHere();
5649       return result;
5650     }
5651   }
5652   return result;
5653 }
5654 
5655 
5656 //------------------------------xdual------------------------------------------
5657 // Dual: compute field-by-field dual
5658 const Type *TypeAryPtr::xdual() const {
5659   bool xk = _klass_is_exact;
5660   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());
5661 }
5662 
5663 Type::Offset TypeAryPtr::meet_field_offset(const Type::Offset offset) const {
5664   return _field_offset.meet(offset);
5665 }
5666 
5667 //------------------------------dual_offset------------------------------------
5668 Type::Offset TypeAryPtr::dual_field_offset() const {
5669   return _field_offset.dual();
5670 }
5671 
5672 //------------------------------dump2------------------------------------------
5673 #ifndef PRODUCT
5674 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5675   st->print("aryptr:");
5676   _ary->dump2(d, depth, st);
5677   _interfaces->dump(st);
5678 
5679   if (_ptr == Constant) {
5680     const_oop()->print(st);
5681   }
5682 
5683   st->print(":%s", ptr_msg[_ptr]);
5684   if (_klass_is_exact) {
5685     st->print(":exact");
5686   }
5687 
5688   if (is_flat()) {
5689     st->print(":flat");
5690     st->print("(");
5691     _field_offset.dump2(st);
5692     st->print(")");
5693   } else if (is_not_flat()) {
5694     st->print(":not_flat");
5695   }
5696   if (is_null_free()) {
5697     st->print(":null free");
5698   }
5699   if (is_atomic()) {
5700     st->print(":atomic");
5701   }
5702   if (Verbose) {
5703     if (is_not_flat()) {
5704       st->print(":not flat");
5705     }
5706     if (is_not_null_free()) {
5707       st->print(":nullable");
5708     }
5709   }
5710   if (offset() != 0) {
5711     BasicType basic_elem_type = elem()->basic_type();
5712     int header_size = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5713     if( _offset == Offset::top )       st->print("+undefined");
5714     else if( _offset == Offset::bottom )  st->print("+any");
5715     else if( offset() < header_size ) st->print("+%d", offset());
5716     else {
5717       if (basic_elem_type == T_ILLEGAL) {
5718         st->print("+any");
5719       } else {
5720         int elem_size = type2aelembytes(basic_elem_type);
5721         st->print("[%d]", (offset() - header_size)/elem_size);
5722       }
5723     }
5724   }
5725 
5726   dump_instance_id(st);
5727   dump_inline_depth(st);
5728   dump_speculative(st);
5729 }
5730 #endif
5731 
5732 bool TypeAryPtr::empty(void) const {
5733   if (_ary->empty())       return true;
5734   // FIXME: Does this belong here? Or in the meet code itself?
5735   if (is_flat() && is_not_flat()) {
5736     return true;
5737   }
5738   return TypeOopPtr::empty();
5739 }
5740 
5741 //------------------------------add_offset-------------------------------------
5742 const TypePtr* TypeAryPtr::add_offset(intptr_t offset) const {
5743   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);
5744 }
5745 
5746 const TypeAryPtr* TypeAryPtr::with_offset(intptr_t offset) const {
5747   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);
5748 }
5749 
5750 const TypeAryPtr* TypeAryPtr::with_ary(const TypeAry* ary) const {
5751   return make(_ptr, _const_oop, ary, _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5752 }
5753 
5754 const TypeAryPtr* TypeAryPtr::remove_speculative() const {
5755   if (_speculative == nullptr) {
5756     return this;
5757   }
5758   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
5759   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);
5760 }
5761 
5762 const Type* TypeAryPtr::cleanup_speculative() const {
5763   if (speculative() == nullptr) {
5764     return this;
5765   }
5766   // Keep speculative part if it contains information about flat-/nullability
5767   const TypeAryPtr* spec_aryptr = speculative()->isa_aryptr();
5768   if (spec_aryptr != nullptr && !above_centerline(spec_aryptr->ptr()) &&
5769       (spec_aryptr->is_not_flat() || spec_aryptr->is_not_null_free())) {
5770     return this;
5771   }
5772   return TypeOopPtr::cleanup_speculative();
5773 }
5774 
5775 const TypePtr* TypeAryPtr::with_inline_depth(int depth) const {
5776   if (!UseInlineDepthForSpeculativeTypes) {
5777     return this;
5778   }
5779   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, depth, _is_autobox_cache);
5780 }
5781 
5782 const TypeAryPtr* TypeAryPtr::with_field_offset(int offset) const {
5783   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);
5784 }
5785 
5786 const TypePtr* TypeAryPtr::add_field_offset_and_offset(intptr_t offset) const {
5787   int adj = 0;
5788   if (is_flat() && klass_is_exact() && offset != Type::OffsetBot && offset != Type::OffsetTop) {
5789     if (_offset.get() != OffsetBot && _offset.get() != OffsetTop) {
5790       adj = _offset.get();
5791       offset += _offset.get();
5792     }
5793     uint header = arrayOopDesc::base_offset_in_bytes(T_FLAT_ELEMENT);
5794     if (_field_offset.get() != OffsetBot && _field_offset.get() != OffsetTop) {
5795       offset += _field_offset.get();
5796       if (_offset.get() == OffsetBot || _offset.get() == OffsetTop) {
5797         offset += header;
5798       }
5799     }
5800     if (elem()->make_oopptr()->is_inlinetypeptr() && (offset >= (intptr_t)header || offset < 0)) {
5801       // Try to get the field of the inline type array element we are pointing to
5802       ciInlineKlass* vk = elem()->inline_klass();
5803       int shift = flat_log_elem_size();
5804       int mask = (1 << shift) - 1;
5805       intptr_t field_offset = ((offset - header) & mask);
5806       ciField* field = vk->get_field_by_offset(field_offset + vk->payload_offset(), false);
5807       if (field != nullptr || field_offset == vk->null_marker_offset_in_payload()) {
5808         return with_field_offset(field_offset)->add_offset(offset - field_offset - adj);
5809       }
5810     }
5811   }
5812   return add_offset(offset - adj);
5813 }
5814 
5815 // Return offset incremented by field_offset for flat inline type arrays
5816 int TypeAryPtr::flat_offset() const {
5817   int offset = _offset.get();
5818   if (offset != Type::OffsetBot && offset != Type::OffsetTop &&
5819       _field_offset != Offset::bottom && _field_offset != Offset::top) {
5820     offset += _field_offset.get();
5821   }
5822   return offset;
5823 }
5824 
5825 const TypePtr* TypeAryPtr::with_instance_id(int instance_id) const {
5826   assert(is_known_instance(), "should be known");
5827   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth);
5828 }
5829 
5830 //=============================================================================
5831 
5832 
5833 //------------------------------hash-------------------------------------------
5834 // Type-specific hashing function.
5835 uint TypeNarrowPtr::hash(void) const {
5836   return _ptrtype->hash() + 7;
5837 }
5838 
5839 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
5840   return _ptrtype->singleton();
5841 }
5842 
5843 bool TypeNarrowPtr::empty(void) const {
5844   return _ptrtype->empty();
5845 }
5846 
5847 intptr_t TypeNarrowPtr::get_con() const {
5848   return _ptrtype->get_con();
5849 }
5850 
5851 bool TypeNarrowPtr::eq( const Type *t ) const {
5852   const TypeNarrowPtr* tc = isa_same_narrowptr(t);
5853   if (tc != nullptr) {
5854     if (_ptrtype->base() != tc->_ptrtype->base()) {
5855       return false;
5856     }
5857     return tc->_ptrtype->eq(_ptrtype);
5858   }
5859   return false;
5860 }
5861 
5862 const Type *TypeNarrowPtr::xdual() const {    // Compute dual right now.
5863   const TypePtr* odual = _ptrtype->dual()->is_ptr();
5864   return make_same_narrowptr(odual);
5865 }
5866 
5867 
5868 const Type *TypeNarrowPtr::filter_helper(const Type *kills, bool include_speculative) const {
5869   if (isa_same_narrowptr(kills)) {
5870     const Type* ft =_ptrtype->filter_helper(is_same_narrowptr(kills)->_ptrtype, include_speculative);
5871     if (ft->empty())
5872       return Type::TOP;           // Canonical empty value
5873     if (ft->isa_ptr()) {
5874       return make_hash_same_narrowptr(ft->isa_ptr());
5875     }
5876     return ft;
5877   } else if (kills->isa_ptr()) {
5878     const Type* ft = _ptrtype->join_helper(kills, include_speculative);
5879     if (ft->empty())
5880       return Type::TOP;           // Canonical empty value
5881     return ft;
5882   } else {
5883     return Type::TOP;
5884   }
5885 }
5886 
5887 //------------------------------xmeet------------------------------------------
5888 // Compute the MEET of two types.  It returns a new Type object.
5889 const Type *TypeNarrowPtr::xmeet( const Type *t ) const {
5890   // Perform a fast test for common case; meeting the same types together.
5891   if( this == t ) return this;  // Meeting same type-rep?
5892 
5893   if (t->base() == base()) {
5894     const Type* result = _ptrtype->xmeet(t->make_ptr());
5895     if (result->isa_ptr()) {
5896       return make_hash_same_narrowptr(result->is_ptr());
5897     }
5898     return result;
5899   }
5900 
5901   // Current "this->_base" is NarrowKlass or NarrowOop
5902   switch (t->base()) {          // switch on original type
5903 
5904   case Int:                     // Mixing ints & oops happens when javac
5905   case Long:                    // reuses local variables
5906   case HalfFloatTop:
5907   case HalfFloatCon:
5908   case HalfFloatBot:
5909   case FloatTop:
5910   case FloatCon:
5911   case FloatBot:
5912   case DoubleTop:
5913   case DoubleCon:
5914   case DoubleBot:
5915   case AnyPtr:
5916   case RawPtr:
5917   case OopPtr:
5918   case InstPtr:
5919   case AryPtr:
5920   case MetadataPtr:
5921   case KlassPtr:
5922   case InstKlassPtr:
5923   case AryKlassPtr:
5924   case NarrowOop:
5925   case NarrowKlass:

5926   case Bottom:                  // Ye Olde Default
5927     return Type::BOTTOM;
5928   case Top:
5929     return this;
5930 
5931   default:                      // All else is a mistake
5932     typerr(t);
5933 
5934   } // End of switch
5935 
5936   return this;
5937 }
5938 
5939 #ifndef PRODUCT
5940 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5941   _ptrtype->dump2(d, depth, st);
5942 }
5943 #endif
5944 
5945 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
5946 const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
5947 
5948 
5949 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
5950   return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();
5951 }
5952 
5953 const TypeNarrowOop* TypeNarrowOop::remove_speculative() const {
5954   return make(_ptrtype->remove_speculative()->is_ptr());
5955 }
5956 
5957 const Type* TypeNarrowOop::cleanup_speculative() const {
5958   return make(_ptrtype->cleanup_speculative()->is_ptr());
5959 }
5960 
5961 #ifndef PRODUCT
5962 void TypeNarrowOop::dump2( Dict & d, uint depth, outputStream *st ) const {
5963   st->print("narrowoop: ");
5964   TypeNarrowPtr::dump2(d, depth, st);
5965 }
5966 #endif
5967 
5968 const TypeNarrowKlass *TypeNarrowKlass::NULL_PTR;
5969 
5970 const TypeNarrowKlass* TypeNarrowKlass::make(const TypePtr* type) {
5971   return (const TypeNarrowKlass*)(new TypeNarrowKlass(type))->hashcons();
5972 }
5973 
5974 #ifndef PRODUCT
5975 void TypeNarrowKlass::dump2( Dict & d, uint depth, outputStream *st ) const {
5976   st->print("narrowklass: ");
5977   TypeNarrowPtr::dump2(d, depth, st);
5978 }
5979 #endif
5980 
5981 
5982 //------------------------------eq---------------------------------------------
5983 // Structural equality check for Type representations
5984 bool TypeMetadataPtr::eq( const Type *t ) const {
5985   const TypeMetadataPtr *a = (const TypeMetadataPtr*)t;
5986   ciMetadata* one = metadata();
5987   ciMetadata* two = a->metadata();
5988   if (one == nullptr || two == nullptr) {
5989     return (one == two) && TypePtr::eq(t);
5990   } else {
5991     return one->equals(two) && TypePtr::eq(t);
5992   }
5993 }
5994 
5995 //------------------------------hash-------------------------------------------
5996 // Type-specific hashing function.
5997 uint TypeMetadataPtr::hash(void) const {
5998   return
5999     (metadata() ? metadata()->hash() : 0) +
6000     TypePtr::hash();
6001 }
6002 
6003 //------------------------------singleton--------------------------------------
6004 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
6005 // constants
6006 bool TypeMetadataPtr::singleton(void) const {
6007   // detune optimizer to not generate constant metadata + constant offset as a constant!
6008   // TopPTR, Null, AnyNull, Constant are all singletons
6009   return (offset() == 0) && !below_centerline(_ptr);
6010 }
6011 
6012 //------------------------------add_offset-------------------------------------
6013 const TypePtr* TypeMetadataPtr::add_offset( intptr_t offset ) const {
6014   return make( _ptr, _metadata, xadd_offset(offset));
6015 }
6016 
6017 //-----------------------------filter------------------------------------------
6018 // Do not allow interface-vs.-noninterface joins to collapse to top.
6019 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
6020   const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
6021   if (ft == nullptr || ft->empty())
6022     return Type::TOP;           // Canonical empty value
6023   return ft;
6024 }
6025 
6026  //------------------------------get_con----------------------------------------
6027 intptr_t TypeMetadataPtr::get_con() const {
6028   assert( _ptr == Null || _ptr == Constant, "" );
6029   assert(offset() >= 0, "");
6030 
6031   if (offset() != 0) {
6032     // After being ported to the compiler interface, the compiler no longer
6033     // directly manipulates the addresses of oops.  Rather, it only has a pointer
6034     // to a handle at compile time.  This handle is embedded in the generated
6035     // code and dereferenced at the time the nmethod is made.  Until that time,
6036     // it is not reasonable to do arithmetic with the addresses of oops (we don't
6037     // have access to the addresses!).  This does not seem to currently happen,
6038     // but this assertion here is to help prevent its occurrence.
6039     tty->print_cr("Found oop constant with non-zero offset");
6040     ShouldNotReachHere();
6041   }
6042 
6043   return (intptr_t)metadata()->constant_encoding();
6044 }
6045 
6046 //------------------------------cast_to_ptr_type-------------------------------
6047 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
6048   if( ptr == _ptr ) return this;
6049   return make(ptr, metadata(), _offset);
6050 }
6051 
6052 //------------------------------meet-------------------------------------------
6053 // Compute the MEET of two types.  It returns a new Type object.
6054 const Type *TypeMetadataPtr::xmeet( const Type *t ) const {
6055   // Perform a fast test for common case; meeting the same types together.
6056   if( this == t ) return this;  // Meeting same type-rep?
6057 
6058   // Current "this->_base" is OopPtr
6059   switch (t->base()) {          // switch on original type
6060 
6061   case Int:                     // Mixing ints & oops happens when javac
6062   case Long:                    // reuses local variables
6063   case HalfFloatTop:
6064   case HalfFloatCon:
6065   case HalfFloatBot:
6066   case FloatTop:
6067   case FloatCon:
6068   case FloatBot:
6069   case DoubleTop:
6070   case DoubleCon:
6071   case DoubleBot:
6072   case NarrowOop:
6073   case NarrowKlass:
6074   case Bottom:                  // Ye Olde Default
6075     return Type::BOTTOM;
6076   case Top:
6077     return this;
6078 
6079   default:                      // All else is a mistake
6080     typerr(t);
6081 
6082   case AnyPtr: {
6083     // Found an AnyPtr type vs self-OopPtr type
6084     const TypePtr *tp = t->is_ptr();
6085     Offset offset = meet_offset(tp->offset());
6086     PTR ptr = meet_ptr(tp->ptr());
6087     switch (tp->ptr()) {
6088     case Null:
6089       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6090       // else fall through:
6091     case TopPTR:
6092     case AnyNull: {
6093       return make(ptr, _metadata, offset);
6094     }
6095     case BotPTR:
6096     case NotNull:
6097       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6098     default: typerr(t);
6099     }
6100   }
6101 
6102   case RawPtr:
6103   case KlassPtr:
6104   case InstKlassPtr:
6105   case AryKlassPtr:
6106   case OopPtr:
6107   case InstPtr:
6108   case AryPtr:
6109     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
6110 
6111   case MetadataPtr: {
6112     const TypeMetadataPtr *tp = t->is_metadataptr();
6113     Offset offset = meet_offset(tp->offset());
6114     PTR tptr = tp->ptr();
6115     PTR ptr = meet_ptr(tptr);
6116     ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
6117     if (tptr == TopPTR || _ptr == TopPTR ||
6118         metadata()->equals(tp->metadata())) {
6119       return make(ptr, md, offset);
6120     }
6121     // metadata is different
6122     if( ptr == Constant ) {  // Cannot be equal constants, so...
6123       if( tptr == Constant && _ptr != Constant)  return t;
6124       if( _ptr == Constant && tptr != Constant)  return this;
6125       ptr = NotNull;            // Fall down in lattice
6126     }
6127     return make(ptr, nullptr, offset);
6128     break;
6129   }
6130   } // End of switch
6131   return this;                  // Return the double constant
6132 }
6133 
6134 
6135 //------------------------------xdual------------------------------------------
6136 // Dual of a pure metadata pointer.
6137 const Type *TypeMetadataPtr::xdual() const {
6138   return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
6139 }
6140 
6141 //------------------------------dump2------------------------------------------
6142 #ifndef PRODUCT
6143 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
6144   st->print("metadataptr:%s", ptr_msg[_ptr]);
6145   if (metadata() != nullptr) {
6146     st->print(":" INTPTR_FORMAT, p2i(metadata()));
6147   }
6148   dump_offset(st);
6149 }
6150 #endif
6151 
6152 
6153 //=============================================================================
6154 // Convenience common pre-built type.
6155 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
6156 
6157 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, Offset offset):
6158   TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
6159 }
6160 
6161 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
6162   return make(Constant, m, Offset(0));
6163 }
6164 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
6165   return make(Constant, m, Offset(0));
6166 }
6167 
6168 //------------------------------make-------------------------------------------
6169 // Create a meta data constant
6170 const TypeMetadataPtr* TypeMetadataPtr::make(PTR ptr, ciMetadata* m, Offset offset) {
6171   assert(m == nullptr || !m->is_klass(), "wrong type");
6172   return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
6173 }
6174 
6175 
6176 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
6177   const Type* elem = _ary->_elem;
6178   bool xk = klass_is_exact();
6179   bool is_refined = false;
6180   if (elem->make_oopptr() != nullptr) {
6181     is_refined = true;
6182     elem = elem->make_oopptr()->as_klass_type(try_for_exact);
6183     if (elem->isa_aryklassptr()) {
6184       const TypeAryKlassPtr* elem_klass = elem->is_aryklassptr();
6185       if (elem_klass->is_refined_type()) {
6186         elem = elem_klass->cast_to_non_refined();
6187       }
6188     } else {
6189       const TypeInstKlassPtr* elem_klass = elem->is_instklassptr();
6190       if (try_for_exact && !xk && elem_klass->klass_is_exact() &&
6191           !elem_klass->exact_klass()->as_instance_klass()->can_be_inline_klass()) {
6192         xk = true;
6193       }
6194     }
6195   }
6196   return TypeAryKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, elem, klass(), Offset(0), is_not_flat(), is_not_null_free(), is_flat(), is_null_free(), is_atomic(), is_refined);
6197 }
6198 
6199 const TypeKlassPtr* TypeKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6200   if (klass->is_instance_klass()) {
6201     return TypeInstKlassPtr::make(klass, interface_handling);
6202   }
6203   return TypeAryKlassPtr::make(klass, interface_handling);
6204 }
6205 
6206 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, Offset offset)










6207   : TypePtr(t, ptr, offset), _klass(klass), _interfaces(interfaces) {
6208   assert(klass == nullptr || !klass->is_loaded() || (klass->is_instance_klass() && !klass->is_interface()) ||
6209          klass->is_type_array_klass() || klass->is_flat_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "no interface here");
6210 }
6211 
6212 // Is there a single ciKlass* that can represent that type?
6213 ciKlass* TypeKlassPtr::exact_klass_helper() const {
6214   assert(_klass->is_instance_klass() && !_klass->is_interface(), "No interface");
6215   if (_interfaces->empty()) {
6216     return _klass;
6217   }
6218   if (_klass != ciEnv::current()->Object_klass()) {
6219     if (_interfaces->eq(_klass->as_instance_klass())) {
6220       return _klass;
6221     }
6222     return nullptr;
6223   }
6224   return _interfaces->exact_klass();
6225 }
6226 
6227 //------------------------------eq---------------------------------------------
6228 // Structural equality check for Type representations
6229 bool TypeKlassPtr::eq(const Type *t) const {
6230   const TypeKlassPtr *p = t->is_klassptr();
6231   return
6232     _interfaces->eq(p->_interfaces) &&
6233     TypePtr::eq(p);
6234 }
6235 
6236 //------------------------------hash-------------------------------------------
6237 // Type-specific hashing function.
6238 uint TypeKlassPtr::hash(void) const {
6239   return TypePtr::hash() + _interfaces->hash();
6240 }
6241 
6242 //------------------------------singleton--------------------------------------
6243 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
6244 // constants
6245 bool TypeKlassPtr::singleton(void) const {
6246   // detune optimizer to not generate constant klass + constant offset as a constant!
6247   // TopPTR, Null, AnyNull, Constant are all singletons
6248   return (offset() == 0) && !below_centerline(_ptr);
6249 }
6250 
6251 // Do not allow interface-vs.-noninterface joins to collapse to top.
6252 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
6253   // logic here mirrors the one from TypeOopPtr::filter. See comments
6254   // there.
6255   const Type* ft = join_helper(kills, include_speculative);
6256 
6257   if (ft->empty()) {
6258     return Type::TOP;           // Canonical empty value
6259   }
6260 
6261   return ft;
6262 }
6263 
6264 const TypeInterfaces* TypeKlassPtr::meet_interfaces(const TypeKlassPtr* other) const {
6265   if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
6266     return _interfaces->union_with(other->_interfaces);
6267   } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
6268     return other->_interfaces;
6269   } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
6270     return _interfaces;
6271   }
6272   return _interfaces->intersection_with(other->_interfaces);
6273 }
6274 
6275 //------------------------------get_con----------------------------------------
6276 intptr_t TypeKlassPtr::get_con() const {
6277   assert( _ptr == Null || _ptr == Constant, "" );
6278   assert( offset() >= 0, "" );
6279 
6280   if (offset() != 0) {
6281     // After being ported to the compiler interface, the compiler no longer
6282     // directly manipulates the addresses of oops.  Rather, it only has a pointer
6283     // to a handle at compile time.  This handle is embedded in the generated
6284     // code and dereferenced at the time the nmethod is made.  Until that time,
6285     // it is not reasonable to do arithmetic with the addresses of oops (we don't
6286     // have access to the addresses!).  This does not seem to currently happen,
6287     // but this assertion here is to help prevent its occurrence.
6288     tty->print_cr("Found oop constant with non-zero offset");
6289     ShouldNotReachHere();
6290   }
6291 
6292   ciKlass* k = exact_klass();
6293 
6294   return (intptr_t)k->constant_encoding();
6295 }
6296 
6297 //=============================================================================
6298 // Convenience common pre-built types.
6299 
6300 // Not-null object klass or below
6301 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
6302 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
6303 
6304 bool TypeInstKlassPtr::eq(const Type *t) const {
6305   const TypeInstKlassPtr* p = t->is_instklassptr();
6306   return
6307     klass()->equals(p->klass()) &&
6308     _flat_in_array == p->_flat_in_array &&
6309     TypeKlassPtr::eq(p);
6310 }
6311 
6312 uint TypeInstKlassPtr::hash() const {
6313   return klass()->hash() + TypeKlassPtr::hash() + static_cast<uint>(_flat_in_array);
6314 }
6315 
6316 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, Offset offset, FlatInArray flat_in_array) {
6317   if (flat_in_array == Uninitialized) {
6318     flat_in_array = compute_flat_in_array(k->as_instance_klass(), ptr == Constant);
6319   }
6320   TypeInstKlassPtr *r =
6321     (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, interfaces, offset, flat_in_array))->hashcons();
6322 
6323   return r;
6324 }
6325 
6326 bool TypeInstKlassPtr::empty() const {
6327   if (_flat_in_array == TopFlat) {
6328     return true;
6329   }
6330   return TypeKlassPtr::empty();
6331 }
6332 
6333 //------------------------------add_offset-------------------------------------
6334 // Access internals of klass object
6335 const TypePtr *TypeInstKlassPtr::add_offset( intptr_t offset ) const {
6336   return make(_ptr, klass(), _interfaces, xadd_offset(offset), _flat_in_array);
6337 }
6338 
6339 const TypeInstKlassPtr* TypeInstKlassPtr::with_offset(intptr_t offset) const {
6340   return make(_ptr, klass(), _interfaces, Offset(offset), _flat_in_array);
6341 }
6342 
6343 //------------------------------cast_to_ptr_type-------------------------------
6344 const TypeInstKlassPtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
6345   assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
6346   if( ptr == _ptr ) return this;
6347   return make(ptr, _klass, _interfaces, _offset, _flat_in_array);
6348 }
6349 
6350 
6351 bool TypeInstKlassPtr::must_be_exact() const {
6352   if (!_klass->is_loaded())  return false;
6353   ciInstanceKlass* ik = _klass->as_instance_klass();
6354   if (ik->is_final())  return true;  // cannot clear xk
6355   return false;
6356 }
6357 
6358 //-----------------------------cast_to_exactness-------------------------------
6359 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6360   if (klass_is_exact == (_ptr == Constant)) return this;
6361   if (must_be_exact()) return this;
6362   ciKlass* k = klass();
6363   FlatInArray flat_in_array = compute_flat_in_array(k->as_instance_klass(), klass_is_exact);
6364   return make(klass_is_exact ? Constant : NotNull, k, _interfaces, _offset, flat_in_array);
6365 }
6366 
6367 
6368 //-----------------------------as_instance_type--------------------------------
6369 // Corresponding type for an instance of the given class.
6370 // It will be NotNull, and exact if and only if the klass type is exact.
6371 const TypeOopPtr* TypeInstKlassPtr::as_instance_type(bool klass_change) const {
6372   ciKlass* k = klass();
6373   bool xk = klass_is_exact();
6374   Compile* C = Compile::current();
6375   Dependencies* deps = C->dependencies();
6376   assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
6377   // Element is an instance
6378   bool klass_is_exact = false;
6379   const TypeInterfaces* interfaces = _interfaces;
6380   ciInstanceKlass* ik = k->as_instance_klass();
6381   if (k->is_loaded()) {
6382     // Try to set klass_is_exact.

6383     klass_is_exact = ik->is_final();
6384     if (!klass_is_exact && klass_change
6385         && deps != nullptr && UseUniqueSubclasses) {
6386       ciInstanceKlass* sub = ik->unique_concrete_subklass();
6387       if (sub != nullptr) {
6388         if (_interfaces->eq(sub)) {
6389           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6390           k = ik = sub;
6391           xk = sub->is_final();
6392         }
6393       }
6394     }
6395   }
6396 
6397   FlatInArray flat_in_array = compute_flat_in_array_if_unknown(ik, xk, _flat_in_array);
6398   return TypeInstPtr::make(TypePtr::BotPTR, k, interfaces, xk, nullptr, Offset(0), flat_in_array);
6399 }
6400 
6401 //------------------------------xmeet------------------------------------------
6402 // Compute the MEET of two types, return a new Type object.
6403 const Type    *TypeInstKlassPtr::xmeet( const Type *t ) const {
6404   // Perform a fast test for common case; meeting the same types together.
6405   if( this == t ) return this;  // Meeting same type-rep?
6406 
6407   // Current "this->_base" is Pointer
6408   switch (t->base()) {          // switch on original type
6409 
6410   case Int:                     // Mixing ints & oops happens when javac
6411   case Long:                    // reuses local variables
6412   case HalfFloatTop:
6413   case HalfFloatCon:
6414   case HalfFloatBot:
6415   case FloatTop:
6416   case FloatCon:
6417   case FloatBot:
6418   case DoubleTop:
6419   case DoubleCon:
6420   case DoubleBot:
6421   case NarrowOop:
6422   case NarrowKlass:
6423   case Bottom:                  // Ye Olde Default
6424     return Type::BOTTOM;
6425   case Top:
6426     return this;
6427 
6428   default:                      // All else is a mistake
6429     typerr(t);
6430 
6431   case AnyPtr: {                // Meeting to AnyPtrs
6432     // Found an AnyPtr type vs self-KlassPtr type
6433     const TypePtr *tp = t->is_ptr();
6434     Offset offset = meet_offset(tp->offset());
6435     PTR ptr = meet_ptr(tp->ptr());
6436     switch (tp->ptr()) {
6437     case TopPTR:
6438       return this;
6439     case Null:
6440       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6441     case AnyNull:
6442       return make(ptr, klass(), _interfaces, offset, _flat_in_array);
6443     case BotPTR:
6444     case NotNull:
6445       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6446     default: typerr(t);
6447     }
6448   }
6449 
6450   case RawPtr:
6451   case MetadataPtr:
6452   case OopPtr:
6453   case AryPtr:                  // Meet with AryPtr
6454   case InstPtr:                 // Meet with InstPtr
6455       return TypePtr::BOTTOM;
6456 
6457   //
6458   //             A-top         }
6459   //           /   |   \       }  Tops
6460   //       B-top A-any C-top   }
6461   //          | /  |  \ |      }  Any-nulls
6462   //       B-any   |   C-any   }
6463   //          |    |    |
6464   //       B-con A-con C-con   } constants; not comparable across classes
6465   //          |    |    |
6466   //       B-not   |   C-not   }
6467   //          | \  |  / |      }  not-nulls
6468   //       B-bot A-not C-bot   }
6469   //           \   |   /       }  Bottoms
6470   //             A-bot         }
6471   //
6472 
6473   case InstKlassPtr: {  // Meet two KlassPtr types
6474     const TypeInstKlassPtr *tkls = t->is_instklassptr();
6475     Offset  off     = meet_offset(tkls->offset());
6476     PTR  ptr     = meet_ptr(tkls->ptr());
6477     const TypeInterfaces* interfaces = meet_interfaces(tkls);
6478 
6479     ciKlass* res_klass = nullptr;
6480     bool res_xk = false;
6481     const FlatInArray flat_in_array = meet_flat_in_array(_flat_in_array, tkls->flat_in_array());
6482     switch (meet_instptr(ptr, interfaces, this, tkls, res_klass, res_xk)) {
6483       case UNLOADED:
6484         ShouldNotReachHere();
6485       case SUBTYPE:
6486       case NOT_SUBTYPE:
6487       case LCA:
6488       case QUICK: {
6489         assert(res_xk == (ptr == Constant), "");
6490         const Type* res = make(ptr, res_klass, interfaces, off, flat_in_array);
6491         return res;
6492       }
6493       default:
6494         ShouldNotReachHere();
6495     }
6496   } // End of case KlassPtr
6497   case AryKlassPtr: {                // All arrays inherit from Object class
6498     const TypeAryKlassPtr *tp = t->is_aryklassptr();
6499     Offset offset = meet_offset(tp->offset());
6500     PTR ptr = meet_ptr(tp->ptr());
6501     const TypeInterfaces* interfaces = meet_interfaces(tp);
6502     const TypeInterfaces* tp_interfaces = tp->_interfaces;
6503     const TypeInterfaces* this_interfaces = _interfaces;
6504 
6505     switch (ptr) {
6506     case TopPTR:
6507     case AnyNull:                // Fall 'down' to dual of object klass
6508       // For instances when a subclass meets a superclass we fall
6509       // below the centerline when the superclass is exact. We need to
6510       // do the same here.
6511       //
6512       // Flat in array: See explanation for meet with TypeInstPtr in TypeAryPtr::xmeet_helper().
6513       if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) &&
6514           !klass_is_exact() && !is_not_flat_in_array()) {
6515         return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset, tp->is_not_flat(), tp->is_not_null_free(), tp->is_flat(), tp->is_null_free(), tp->is_atomic(), tp->is_refined_type());
6516       } else {
6517         // cannot subclass, so the meet has to fall badly below the centerline
6518         ptr = NotNull;
6519         interfaces = _interfaces->intersection_with(tp->_interfaces);
6520         FlatInArray flat_in_array = meet_flat_in_array(_flat_in_array, NotFlat);
6521         return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, flat_in_array);
6522       }
6523     case Constant:
6524     case NotNull:
6525     case BotPTR: { // Fall down to object klass
6526       // LCA is object_klass, but if we subclass from the top we can do better
6527       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
6528         // If 'this' (InstPtr) is above the centerline and it is Object class
6529         // then we can subclass in the Java class hierarchy.
6530         // For instances when a subclass meets a superclass we fall
6531         // below the centerline when the superclass is exact. We need
6532         // to do the same here.
6533         //
6534         // Flat in array: See explanation for meet with TypeInstPtr in TypeAryPtr::xmeet_helper().
6535         if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) &&
6536             !klass_is_exact() && !is_not_flat_in_array()) {
6537           // that is, tp's array type is a subtype of my klass
6538           return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset, tp->is_not_flat(), tp->is_not_null_free(), tp->is_flat(), tp->is_null_free(), tp->is_atomic(), tp->is_refined_type());

6539         }
6540       }
6541       // The other case cannot happen, since I cannot be a subtype of an array.
6542       // The meet falls down to Object class below centerline.
6543       if( ptr == Constant )
6544         ptr = NotNull;
6545       interfaces = this_interfaces->intersection_with(tp_interfaces);
6546       FlatInArray flat_in_array = meet_flat_in_array(_flat_in_array, NotFlat);
6547       return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, flat_in_array);
6548     }
6549     default: typerr(t);
6550     }
6551   }
6552 
6553   } // End of switch
6554   return this;                  // Return the double constant
6555 }
6556 
6557 //------------------------------xdual------------------------------------------
6558 // Dual: compute field-by-field dual
6559 const Type* TypeInstKlassPtr::xdual() const {
6560   return new TypeInstKlassPtr(dual_ptr(), klass(), _interfaces, dual_offset(), dual_flat_in_array());
6561 }
6562 
6563 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) {
6564   static_assert(std::is_base_of<T2, T1>::value, "");
6565   if (!this_one->is_loaded() || !other->is_loaded()) {
6566     return false;
6567   }
6568   if (!this_one->is_instance_type(other)) {
6569     return false;
6570   }
6571 
6572   if (!other_exact) {
6573     return false;
6574   }
6575 
6576   if (other->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces->empty()) {
6577     return true;
6578   }
6579 
6580   return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);
6581 }
6582 
6583 bool TypeInstKlassPtr::might_be_an_array() const {
6584   if (!instance_klass()->is_java_lang_Object()) {
6585     // TypeInstKlassPtr can be an array only if it is java.lang.Object: the only supertype of array types.
6586     return false;
6587   }
6588   if (interfaces()->has_non_array_interface()) {
6589     // Arrays only implement Cloneable and Serializable. If we see any other interface, [this] cannot be an array.
6590     return false;
6591   }
6592   // Cannot prove it's not an array.
6593   return true;
6594 }
6595 
6596 bool TypeInstKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6597   return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
6598 }
6599 
6600 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_instance(const T1* this_one, const T2* other) {
6601   static_assert(std::is_base_of<T2, T1>::value, "");
6602   if (!this_one->is_loaded() || !other->is_loaded()) {
6603     return false;
6604   }
6605   if (!this_one->is_instance_type(other)) {
6606     return false;
6607   }
6608   return this_one->klass()->equals(other->klass()) && this_one->_interfaces->eq(other->_interfaces);
6609 }
6610 
6611 bool TypeInstKlassPtr::is_same_java_type_as_helper(const TypeKlassPtr* other) const {
6612   return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
6613 }
6614 
6615 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) {
6616   static_assert(std::is_base_of<T2, T1>::value, "");
6617   if (!this_one->is_loaded() || !other->is_loaded()) {
6618     return true;
6619   }
6620 
6621   if (this_one->is_array_type(other)) {
6622     return !this_exact && this_one->klass()->equals(ciEnv::current()->Object_klass())  && other->_interfaces->contains(this_one->_interfaces);
6623   }
6624 
6625   assert(this_one->is_instance_type(other), "unsupported");
6626 
6627   if (this_exact && other_exact) {
6628     return this_one->is_java_subtype_of(other);
6629   }
6630 
6631   if (!this_one->klass()->is_subtype_of(other->klass()) && !other->klass()->is_subtype_of(this_one->klass())) {
6632     return false;
6633   }
6634 
6635   if (this_exact) {
6636     return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);
6637   }
6638 
6639   return true;
6640 }
6641 
6642 bool TypeInstKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6643   return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
6644 }
6645 
6646 const TypeKlassPtr* TypeInstKlassPtr::try_improve() const {
6647   if (!UseUniqueSubclasses) {
6648     return this;
6649   }
6650   ciKlass* k = klass();
6651   Compile* C = Compile::current();
6652   Dependencies* deps = C->dependencies();
6653   assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");

6654   if (k->is_loaded()) {
6655     ciInstanceKlass* ik = k->as_instance_klass();
6656     if (deps != nullptr) {


6657       ciInstanceKlass* sub = ik->unique_concrete_subklass();
6658       if (sub != nullptr) {
6659         bool improve_to_exact = sub->is_final() && _ptr == NotNull;
6660         const TypeInstKlassPtr* improved = TypeInstKlassPtr::make(improve_to_exact ? Constant : _ptr, sub, _offset);
6661         if (improved->_interfaces->contains(_interfaces)) {
6662           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6663           return improved;


6664         }
6665       }
6666     }
6667   }
6668   return this;
6669 }
6670 
6671 bool TypeInstKlassPtr::can_be_inline_array() const {
6672   return _klass->equals(ciEnv::current()->Object_klass()) && TypeAryKlassPtr::_array_interfaces->contains(_interfaces);
6673 }
6674 
6675 #ifndef PRODUCT
6676 void TypeInstKlassPtr::dump2(Dict& d, uint depth, outputStream* st) const {
6677   st->print("instklassptr:");
6678   klass()->print_name_on(st);
6679   _interfaces->dump(st);
6680   st->print(":%s", ptr_msg[_ptr]);
6681   dump_offset(st);
6682   dump_flat_in_array(_flat_in_array, st);
6683 }
6684 #endif // PRODUCT
6685 
6686 bool TypeAryKlassPtr::can_be_inline_array() const {
6687   return _elem->isa_instklassptr() && _elem->is_instklassptr()->_klass->can_be_inline_klass();
6688 }
6689 
6690 bool TypeInstPtr::can_be_inline_array() const {
6691   return _klass->equals(ciEnv::current()->Object_klass()) && TypeAryPtr::_array_interfaces->contains(_interfaces);
6692 }
6693 
6694 bool TypeAryPtr::can_be_inline_array() const {
6695   return elem()->make_ptr() && elem()->make_ptr()->isa_instptr() && elem()->make_ptr()->is_instptr()->_klass->can_be_inline_klass();
6696 }
6697 
6698 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, Offset offset, bool not_flat, bool not_null_free, bool flat, bool null_free, bool atomic, bool refined_type) {
6699   return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset, not_flat, not_null_free, flat, null_free, atomic, refined_type))->hashcons();
6700 }
6701 
6702 const TypeAryKlassPtr* TypeAryKlassPtr::make(PTR ptr, ciKlass* k, Offset offset, InterfaceHandling interface_handling, bool not_flat, bool not_null_free, bool flat, bool null_free, bool atomic, bool refined_type) {
6703   const Type* etype;
6704   if (k->is_obj_array_klass()) {
6705     // Element is an object array. Recursively call ourself.
6706     ciKlass* eklass = k->as_obj_array_klass()->element_klass();
6707     etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6708     k = nullptr;
6709   } else if (k->is_type_array_klass()) {
6710     // Element is an typeArray
6711     etype = get_const_basic_type(k->as_type_array_klass()->element_type());

6712   } else {
6713     ShouldNotReachHere();

6714   }
6715 
6716   return TypeAryKlassPtr::make(ptr, etype, k, offset, not_flat, not_null_free, flat, null_free, atomic, refined_type);
6717 }
6718 
6719 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6720   ciArrayKlass* k = klass->as_array_klass();
6721   if (k->is_refined()) {
6722     return TypeAryKlassPtr::make(Constant, k, Offset(0), interface_handling, !k->is_flat_array_klass(), !k->is_elem_null_free(),
6723                                  k->is_flat_array_klass(), k->is_elem_null_free(), k->is_elem_atomic(), true);
6724   } else {
6725     // Use the default combination to canonicalize all non-refined klass pointers
6726     return TypeAryKlassPtr::make(Constant, k, Offset(0), interface_handling, true, true, false, false, true, false);
6727   }
6728 }
6729 
6730 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_non_refined() const {
6731   assert(is_refined_type(), "must be a refined type");
6732   PTR ptr = _ptr;
6733   // There can be multiple refined array types corresponding to a single unrefined type
6734   if (ptr == NotNull && elem()->is_klassptr()->klass_is_exact()) {
6735     ptr = Constant;
6736   }
6737   return make(ptr, elem(), nullptr, _offset, true, true, false, false, true, false);
6738 }
6739 
6740 // Get the (non-)refined array klass ptr
6741 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_refined_array_klass_ptr(bool refined) const {
6742   if ((refined == is_refined_type()) || !klass_is_exact() || !exact_klass()->is_obj_array_klass()) {
6743     return this;
6744   }
6745   ciArrayKlass* k = exact_klass()->as_array_klass();
6746   k = ciObjArrayKlass::make(k->element_klass(), refined);
6747   return make(k, trust_interfaces);
6748 }
6749 
6750 //------------------------------eq---------------------------------------------
6751 // Structural equality check for Type representations
6752 bool TypeAryKlassPtr::eq(const Type *t) const {
6753   const TypeAryKlassPtr *p = t->is_aryklassptr();
6754   return
6755     _elem == p->_elem &&  // Check array
6756     _flat == p->_flat &&
6757     _not_flat == p->_not_flat &&
6758     _null_free == p->_null_free &&
6759     _not_null_free == p->_not_null_free &&
6760     _atomic == p->_atomic &&
6761     _refined_type == p->_refined_type &&
6762     TypeKlassPtr::eq(p);  // Check sub-parts
6763 }
6764 
6765 //------------------------------hash-------------------------------------------
6766 // Type-specific hashing function.
6767 uint TypeAryKlassPtr::hash(void) const {
6768   return (uint)(uintptr_t)_elem + TypeKlassPtr::hash() + (uint)(_not_flat ? 43 : 0) +
6769       (uint)(_not_null_free ? 44 : 0) + (uint)(_flat ? 45 : 0) + (uint)(_null_free ? 46 : 0)  + (uint)(_atomic ? 47 : 0) + (uint)(_refined_type ? 48 : 0);
6770 }
6771 
6772 //----------------------compute_klass------------------------------------------
6773 // Compute the defining klass for this class
6774 ciKlass* TypeAryPtr::compute_klass() const {
6775   // Compute _klass based on element type.
6776   ciKlass* k_ary = nullptr;
6777   const TypeInstPtr *tinst;
6778   const TypeAryPtr *tary;
6779   const Type* el = elem();
6780   if (el->isa_narrowoop()) {
6781     el = el->make_ptr();
6782   }
6783 
6784   // Get element klass
6785   if ((tinst = el->isa_instptr()) != nullptr) {
6786     // Leave k_ary at nullptr.
6787   } else if ((tary = el->isa_aryptr()) != nullptr) {
6788     // Leave k_ary at nullptr.
6789   } else if ((el->base() == Type::Top) ||
6790              (el->base() == Type::Bottom)) {
6791     // element type of Bottom occurs from meet of basic type
6792     // and object; Top occurs when doing join on Bottom.
6793     // Leave k_ary at null.
6794   } else {
6795     assert(!el->isa_int(), "integral arrays must be pre-equipped with a class");
6796     // Compute array klass directly from basic type
6797     k_ary = ciTypeArrayKlass::make(el->basic_type());
6798   }
6799   return k_ary;
6800 }
6801 
6802 //------------------------------klass------------------------------------------
6803 // Return the defining klass for this class
6804 ciKlass* TypeAryPtr::klass() const {
6805   if( _klass ) return _klass;   // Return cached value, if possible
6806 
6807   // Oops, need to compute _klass and cache it
6808   ciKlass* k_ary = compute_klass();
6809 
6810   if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) {
6811     // The _klass field acts as a cache of the underlying
6812     // ciKlass for this array type.  In order to set the field,
6813     // we need to cast away const-ness.
6814     //
6815     // IMPORTANT NOTE: we *never* set the _klass field for the
6816     // type TypeAryPtr::OOPS.  This Type is shared between all
6817     // active compilations.  However, the ciKlass which represents
6818     // this Type is *not* shared between compilations, so caching
6819     // this value would result in fetching a dangling pointer.
6820     //
6821     // Recomputing the underlying ciKlass for each request is
6822     // a bit less efficient than caching, but calls to
6823     // TypeAryPtr::OOPS->klass() are not common enough to matter.
6824     ((TypeAryPtr*)this)->_klass = k_ary;
6825   }
6826   return k_ary;
6827 }
6828 
6829 // Is there a single ciKlass* that can represent that type?
6830 ciKlass* TypeAryPtr::exact_klass_helper() const {
6831   if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) {
6832     ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper();
6833     if (k == nullptr) {
6834       return nullptr;
6835     }
6836     if (k->is_array_klass() && k->as_array_klass()->is_refined()) {
6837       // We have no mechanism to create an array of refined arrays
6838       k = ciObjArrayKlass::make(k->as_array_klass()->element_klass(), false);
6839     }
6840     if (klass_is_exact()) {
6841       return ciObjArrayKlass::make(k, true, is_null_free(), is_atomic());
6842     } else {
6843       // We may reach here if called recursively, must be an unrefined type then
6844       return ciObjArrayKlass::make(k, false);
6845     }
6846   }
6847 
6848   return klass();
6849 }
6850 
6851 const Type* TypeAryPtr::base_element_type(int& dims) const {
6852   const Type* elem = this->elem();
6853   dims = 1;
6854   while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) {
6855     elem = elem->make_ptr()->is_aryptr()->elem();
6856     dims++;
6857   }
6858   return elem;
6859 }
6860 
6861 //------------------------------add_offset-------------------------------------
6862 // Access internals of klass object
6863 const TypePtr* TypeAryKlassPtr::add_offset(intptr_t offset) const {
6864   return make(_ptr, elem(), klass(), xadd_offset(offset), is_not_flat(), is_not_null_free(), _flat, _null_free, _atomic, _refined_type);
6865 }
6866 
6867 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const {
6868   return make(_ptr, elem(), klass(), Offset(offset), is_not_flat(), is_not_null_free(), _flat, _null_free, _atomic, _refined_type);
6869 }
6870 
6871 //------------------------------cast_to_ptr_type-------------------------------
6872 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6873   assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6874   if (ptr == _ptr) return this;
6875   return make(ptr, elem(), _klass, _offset, is_not_flat(), is_not_null_free(), _flat, _null_free, _atomic, _refined_type);
6876 }
6877 
6878 bool TypeAryKlassPtr::must_be_exact() const {
6879   assert(klass_is_exact(), "precondition");
6880   if (_elem == Type::BOTTOM || _elem == Type::TOP) {
6881     return false;
6882   }
6883   const TypeKlassPtr* elem = _elem->isa_klassptr();
6884   if (elem == nullptr) {
6885     // primitive arrays
6886     return true;
6887   }
6888 
6889   // refined types are final
6890   return _refined_type;
6891 }
6892 
6893 //-----------------------------cast_to_exactness-------------------------------
6894 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6895   if (klass_is_exact == this->klass_is_exact()) {
6896     return this;
6897   }
6898   if (!klass_is_exact && must_be_exact()) {
6899     return this;
6900   }
6901   const Type* elem = this->elem();
6902   if (elem->isa_klassptr() && !klass_is_exact) {
6903     elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
6904   }


6905 
6906   if (klass_is_exact) {
6907     // cast_to_exactness(true) really means get the LCA of all values represented by this
6908     // TypeAryKlassPtr. As a result, it must be an unrefined klass pointer.
6909     return make(Constant, elem, nullptr, _offset, true, true, false, false, true, false);
6910   } else {
6911     // cast_to_exactness(false) means get the TypeAryKlassPtr representing all values that subtype
6912     // this value
6913     bool not_inline = !_elem->isa_instklassptr() || !_elem->is_instklassptr()->instance_klass()->can_be_inline_klass();
6914     bool not_flat = !UseArrayFlattening || not_inline ||
6915                     (_elem->isa_instklassptr() && _elem->is_instklassptr()->instance_klass()->is_inlinetype() && !_elem->is_instklassptr()->instance_klass()->maybe_flat_in_array());
6916     bool not_null_free = not_inline;
6917     bool atomic = not_flat;
6918     return make(NotNull, elem, nullptr, _offset, not_flat, not_null_free, false, false, atomic, false);
6919   }
6920 }
6921 
6922 //-----------------------------as_instance_type--------------------------------
6923 // Corresponding type for an instance of the given class.
6924 // It will be NotNull, and exact if and only if the klass type is exact.
6925 const TypeOopPtr* TypeAryKlassPtr::as_instance_type(bool klass_change) const {
6926   ciKlass* k = klass();
6927   bool    xk = klass_is_exact();
6928   const Type* el = nullptr;
6929   if (elem()->isa_klassptr()) {
6930     el = elem()->is_klassptr()->as_instance_type(false)->cast_to_exactness(false);
6931     k = nullptr;
6932   } else {
6933     el = elem();
6934   }
6935   bool null_free = _null_free;
6936   if (null_free && el->isa_ptr()) {
6937     el = el->is_ptr()->join_speculative(TypePtr::NOTNULL);
6938   }
6939   return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS, false, is_flat(), is_not_flat(), is_not_null_free(), is_atomic()), k, xk, Offset(0));
6940 }
6941 
6942 
6943 //------------------------------xmeet------------------------------------------
6944 // Compute the MEET of two types, return a new Type object.
6945 const Type    *TypeAryKlassPtr::xmeet( const Type *t ) const {
6946   // Perform a fast test for common case; meeting the same types together.
6947   if( this == t ) return this;  // Meeting same type-rep?
6948 
6949   // Current "this->_base" is Pointer
6950   switch (t->base()) {          // switch on original type
6951 
6952   case Int:                     // Mixing ints & oops happens when javac
6953   case Long:                    // reuses local variables
6954   case HalfFloatTop:
6955   case HalfFloatCon:
6956   case HalfFloatBot:
6957   case FloatTop:
6958   case FloatCon:
6959   case FloatBot:
6960   case DoubleTop:
6961   case DoubleCon:
6962   case DoubleBot:
6963   case NarrowOop:
6964   case NarrowKlass:
6965   case Bottom:                  // Ye Olde Default
6966     return Type::BOTTOM;
6967   case Top:
6968     return this;
6969 
6970   default:                      // All else is a mistake
6971     typerr(t);
6972 
6973   case AnyPtr: {                // Meeting to AnyPtrs
6974     // Found an AnyPtr type vs self-KlassPtr type
6975     const TypePtr *tp = t->is_ptr();
6976     Offset offset = meet_offset(tp->offset());
6977     PTR ptr = meet_ptr(tp->ptr());
6978     switch (tp->ptr()) {
6979     case TopPTR:
6980       return this;
6981     case Null:
6982       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6983     case AnyNull:
6984       return make(ptr, _elem, klass(), offset, is_not_flat(), is_not_null_free(), is_flat(), is_null_free(), is_atomic(), is_refined_type());
6985     case BotPTR:
6986     case NotNull:
6987       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6988     default: typerr(t);
6989     }
6990   }
6991 
6992   case RawPtr:
6993   case MetadataPtr:
6994   case OopPtr:
6995   case AryPtr:                  // Meet with AryPtr
6996   case InstPtr:                 // Meet with InstPtr
6997     return TypePtr::BOTTOM;
6998 
6999   //
7000   //             A-top         }
7001   //           /   |   \       }  Tops
7002   //       B-top A-any C-top   }
7003   //          | /  |  \ |      }  Any-nulls
7004   //       B-any   |   C-any   }
7005   //          |    |    |
7006   //       B-con A-con C-con   } constants; not comparable across classes
7007   //          |    |    |
7008   //       B-not   |   C-not   }
7009   //          | \  |  / |      }  not-nulls
7010   //       B-bot A-not C-bot   }
7011   //           \   |   /       }  Bottoms
7012   //             A-bot         }
7013   //
7014 
7015   case AryKlassPtr: {  // Meet two KlassPtr types
7016     const TypeAryKlassPtr *tap = t->is_aryklassptr();
7017     Offset off = meet_offset(tap->offset());
7018     const Type* elem = _elem->meet(tap->_elem);

7019     PTR ptr = meet_ptr(tap->ptr());
7020     ciKlass* res_klass = nullptr;
7021     bool res_xk = false;
7022     bool res_flat = false;
7023     bool res_not_flat = false;
7024     bool res_not_null_free = false;
7025     bool res_atomic = false;
7026     MeetResult res = meet_aryptr(ptr, elem, this, tap,
7027                                  res_klass, res_xk, res_flat, res_not_flat, res_not_null_free, res_atomic);
7028     assert(res_xk == (ptr == Constant), "");
7029     bool flat = meet_flat(tap->_flat);
7030     bool null_free = meet_null_free(tap->_null_free);
7031     bool atomic = meet_atomic(tap->_atomic);
7032     bool refined_type = _refined_type && tap->_refined_type;
7033     if (res == NOT_SUBTYPE) {
7034       flat = false;
7035       null_free = false;
7036       atomic = false;
7037       refined_type = false;
7038     } else if (res == SUBTYPE) {
7039       if (above_centerline(tap->ptr()) && !above_centerline(this->ptr())) {
7040         flat = _flat;
7041         null_free = _null_free;
7042         atomic = _atomic;
7043         refined_type = _refined_type;
7044       } else if (above_centerline(this->ptr()) && !above_centerline(tap->ptr())) {
7045         flat = tap->_flat;
7046         null_free = tap->_null_free;
7047         atomic = tap->_atomic;
7048         refined_type = tap->_refined_type;
7049       } else if (above_centerline(this->ptr()) && above_centerline(tap->ptr())) {
7050         flat = _flat || tap->_flat;
7051         null_free = _null_free || tap->_null_free;
7052         atomic = _atomic || tap->_atomic;
7053         refined_type = _refined_type || tap->_refined_type;
7054       } else if (res_xk && _refined_type != tap->_refined_type) {
7055         // This can happen if the phi emitted by LibraryCallKit::load_default_refined_array_klass/load_non_refined_array_klass
7056         // is processed before the typeArray guard is folded. Both inputs are constant but the input corresponding to the
7057         // typeArray will go away. Don't constant fold it yet but wait for the control input to collapse.
7058         ptr = PTR::NotNull;
7059       }
7060     }
7061     return make(ptr, elem, res_klass, off, res_not_flat, res_not_null_free, flat, null_free, atomic, refined_type);
7062   } // End of case KlassPtr
7063   case InstKlassPtr: {
7064     const TypeInstKlassPtr *tp = t->is_instklassptr();
7065     Offset offset = meet_offset(tp->offset());
7066     PTR ptr = meet_ptr(tp->ptr());
7067     const TypeInterfaces* interfaces = meet_interfaces(tp);
7068     const TypeInterfaces* tp_interfaces = tp->_interfaces;
7069     const TypeInterfaces* this_interfaces = _interfaces;
7070 
7071     switch (ptr) {
7072     case TopPTR:
7073     case AnyNull:                // Fall 'down' to dual of object klass
7074       // For instances when a subclass meets a superclass we fall
7075       // below the centerline when the superclass is exact. We need to
7076       // do the same here.
7077       //
7078       // Flat in array: See explanation for meet with TypeInstPtr in TypeAryPtr::xmeet_helper().
7079       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
7080           !tp->klass_is_exact() && !tp->is_not_flat_in_array()) {
7081         return TypeAryKlassPtr::make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), is_flat(), is_null_free(), is_atomic(), is_refined_type());
7082       } else {
7083         // cannot subclass, so the meet has to fall badly below the centerline
7084         ptr = NotNull;
7085         interfaces = this_interfaces->intersection_with(tp->_interfaces);
7086         FlatInArray flat_in_array = meet_flat_in_array(NotFlat, tp->flat_in_array());
7087         return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, flat_in_array);
7088       }
7089     case Constant:
7090     case NotNull:
7091     case BotPTR: { // Fall down to object klass
7092       // LCA is object_klass, but if we subclass from the top we can do better
7093       if (above_centerline(tp->ptr())) {
7094         // If 'tp'  is above the centerline and it is Object class
7095         // then we can subclass in the Java class hierarchy.
7096         // For instances when a subclass meets a superclass we fall
7097         // below the centerline when the superclass is exact. We need
7098         // to do the same here.
7099         //
7100         // Flat in array: See explanation for meet with TypeInstPtr in TypeAryPtr::xmeet_helper().
7101         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
7102             !tp->klass_is_exact() && !tp->is_not_flat_in_array()) {
7103           // that is, my array type is a subtype of 'tp' klass
7104           return make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), is_flat(), is_null_free(), is_atomic(), is_refined_type());
7105         }
7106       }
7107       // The other case cannot happen, since t cannot be a subtype of an array.
7108       // The meet falls down to Object class below centerline.
7109       if (ptr == Constant)
7110         ptr = NotNull;
7111       interfaces = this_interfaces->intersection_with(tp_interfaces);
7112       FlatInArray flat_in_array = meet_flat_in_array(NotFlat, tp->flat_in_array());
7113       return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, tp->flat_in_array());
7114     }
7115     default: typerr(t);
7116     }
7117   }
7118 
7119   } // End of switch
7120   return this;                  // Return the double constant
7121 }
7122 
7123 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) {
7124   static_assert(std::is_base_of<T2, T1>::value, "");
7125 
7126   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
7127     return true;
7128   }
7129 
7130   int dummy;
7131   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
7132 
7133   if (!this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
7134     return false;
7135   }
7136 
7137   if (this_one->is_instance_type(other)) {
7138     return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces) &&
7139            other_exact;
7140   }
7141 
7142   assert(this_one->is_array_type(other), "");
7143   const T1* other_ary = this_one->is_array_type(other);
7144   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
7145   if (other_top_or_bottom) {
7146     return false;
7147   }
7148 
7149   const TypePtr* other_elem = other_ary->elem()->make_ptr();
7150   const TypePtr* this_elem = this_one->elem()->make_ptr();
7151   if (this_elem != nullptr && other_elem != nullptr) {
7152     if (other->is_null_free() && !this_one->is_null_free()) {
7153       return false; // A nullable array can't be a subtype of a null-free array
7154     }
7155     return this_one->is_reference_type(this_elem)->is_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
7156   }
7157   if (this_elem == nullptr && other_elem == nullptr) {
7158     return this_one->klass()->is_subtype_of(other->klass());
7159   }
7160   return false;
7161 }
7162 
7163 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
7164   return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
7165 }
7166 
7167 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other) {
7168   static_assert(std::is_base_of<T2, T1>::value, "");
7169 
7170   int dummy;
7171   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
7172 
7173   if (!this_one->is_array_type(other) ||
7174       !this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
7175     return false;
7176   }
7177   const T1* other_ary = this_one->is_array_type(other);
7178   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
7179 
7180   if (other_top_or_bottom) {
7181     return false;
7182   }
7183 
7184   const TypePtr* other_elem = other_ary->elem()->make_ptr();
7185   const TypePtr* this_elem = this_one->elem()->make_ptr();
7186   if (other_elem != nullptr && this_elem != nullptr) {
7187     return this_one->is_reference_type(this_elem)->is_same_java_type_as(this_one->is_reference_type(other_elem));
7188   }
7189   if (other_elem == nullptr && this_elem == nullptr) {
7190     return this_one->klass()->equals(other->klass());
7191   }
7192   return false;
7193 }
7194 
7195 bool TypeAryKlassPtr::is_same_java_type_as_helper(const TypeKlassPtr* other) const {
7196   return TypePtr::is_same_java_type_as_helper_for_array(this, other);
7197 }
7198 
7199 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) {
7200   static_assert(std::is_base_of<T2, T1>::value, "");
7201   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
7202     return true;
7203   }
7204   if (!this_one->is_loaded() || !other->is_loaded()) {
7205     return true;
7206   }
7207   if (this_one->is_instance_type(other)) {
7208     return other->klass()->equals(ciEnv::current()->Object_klass()) &&
7209            this_one->_interfaces->contains(other->_interfaces);
7210   }
7211 
7212   int dummy;
7213   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
7214   if (this_top_or_bottom) {
7215     return true;
7216   }
7217 
7218   assert(this_one->is_array_type(other), "");
7219 
7220   const T1* other_ary = this_one->is_array_type(other);
7221   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
7222   if (other_top_or_bottom) {
7223     return true;
7224   }
7225   if (this_exact && other_exact) {
7226     return this_one->is_java_subtype_of(other);
7227   }
7228 
7229   const TypePtr* this_elem = this_one->elem()->make_ptr();
7230   const TypePtr* other_elem = other_ary->elem()->make_ptr();
7231   if (other_elem != nullptr && this_elem != nullptr) {
7232     return this_one->is_reference_type(this_elem)->maybe_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
7233   }
7234   if (other_elem == nullptr && this_elem == nullptr) {
7235     return this_one->klass()->is_subtype_of(other->klass());
7236   }
7237   return false;
7238 }
7239 
7240 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
7241   return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
7242 }
7243 
7244 //------------------------------xdual------------------------------------------
7245 // Dual: compute field-by-field dual
7246 const Type    *TypeAryKlassPtr::xdual() const {
7247   return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset(), !is_not_flat(), !is_not_null_free(), dual_flat(), dual_null_free(), dual_atomic(), _refined_type);
7248 }
7249 
7250 // Is there a single ciKlass* that can represent that type?
7251 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
7252   if (elem()->isa_klassptr()) {
7253     ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
7254     if (k == nullptr) {
7255       return nullptr;
7256     }
7257     assert(!k->is_array_klass() || !k->as_array_klass()->is_refined(), "no mechanism to create an array of refined arrays %s", k->name()->as_utf8());
7258     k = ciArrayKlass::make(k, is_null_free(), is_atomic(), _refined_type);
7259     return k;
7260   }
7261 
7262   return klass();
7263 }
7264 
7265 ciKlass* TypeAryKlassPtr::klass() const {
7266   if (_klass != nullptr) {
7267     return _klass;
7268   }
7269   ciKlass* k = nullptr;
7270   if (elem()->isa_klassptr()) {
7271     // leave null
7272   } else if ((elem()->base() == Type::Top) ||
7273              (elem()->base() == Type::Bottom)) {
7274   } else {
7275     k = ciTypeArrayKlass::make(elem()->basic_type());
7276     ((TypeAryKlassPtr*)this)->_klass = k;
7277   }
7278   return k;
7279 }
7280 
7281 //------------------------------dump2------------------------------------------
7282 // Dump Klass Type
7283 #ifndef PRODUCT
7284 void TypeAryKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
7285   st->print("aryklassptr:[");
7286   _elem->dump2(d, depth, st);
7287   _interfaces->dump(st);
7288   st->print(":%s", ptr_msg[_ptr]);
7289   if (_flat) st->print(":flat");
7290   if (_null_free) st->print(":null free");
7291   if (_atomic) st->print(":atomic");
7292   if (_refined_type) st->print(":refined_type");
7293   if (Verbose) {
7294     if (_not_flat) st->print(":not flat");
7295     if (_not_null_free) st->print(":nullable");
7296   }
7297   dump_offset(st);
7298 }
7299 #endif
7300 
7301 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
7302   const Type* elem = this->elem();
7303   dims = 1;
7304   while (elem->isa_aryklassptr()) {
7305     elem = elem->is_aryklassptr()->elem();
7306     dims++;
7307   }
7308   return elem;
7309 }
7310 
7311 //=============================================================================
7312 // Convenience common pre-built types.
7313 
7314 //------------------------------make-------------------------------------------
7315 const TypeFunc *TypeFunc::make(const TypeTuple *domain_sig, const TypeTuple* domain_cc,
7316                                const TypeTuple* range_sig, const TypeTuple* range_cc,
7317                                bool scalarized_return) {
7318   return (TypeFunc*)(new TypeFunc(domain_sig, domain_cc, range_sig, range_cc, scalarized_return))->hashcons();
7319 }
7320 
7321 const TypeFunc *TypeFunc::make(const TypeTuple *domain, const TypeTuple *range) {
7322   return make(domain, domain, range, range);
7323 }
7324 
7325 //------------------------------osr_domain-----------------------------
7326 const TypeTuple* osr_domain() {
7327   const Type **fields = TypeTuple::fields(2);
7328   fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM;  // address of osr buffer
7329   return TypeTuple::make(TypeFunc::Parms+1, fields);
7330 }
7331 
7332 // Build a TypeFunc with both the Java-signature view ('sig') and the actual calling-
7333 // convention view ('cc') of inline types. In the signature, an inline type is a single
7334 // oop slot. In the scalarized calling convention, it is expanded to its field
7335 // values (plus null marker and optional oop to the heap buffer).
7336 // The 'is_call' argument distinguishes between the return signature of a method at calls
7337 // vs. at compilation of that method because at calls we return an additional null marker field.
7338 // For OSR and mismatching calls, we fall back to the non-scalarized argument view.
7339 const TypeFunc* TypeFunc::make(ciMethod* method, bool is_call, bool is_osr_compilation) {
7340   Compile* C = Compile::current();
7341   const TypeFunc* tf = nullptr;
7342   // Inline types are not passed/returned by reference, instead each field of
7343   // the inline type is passed/returned as an argument. We maintain two views of
7344   // the argument/return list here: one based on the signature (with an inline
7345   // type argument/return as a single slot), one based on the actual calling
7346   // convention (with an inline type argument/return as a list of its fields).
7347   bool has_scalar_args = method->has_scalarized_args() && !is_osr_compilation;
7348   // Fall back to the non-scalarized calling convention when compiling a call via a mismatching method
7349   if (is_call && method->mismatch()) {
7350     has_scalar_args = false;
7351   }
7352   ciSignature* sig = method->signature();
7353   bool has_scalar_ret = !method->is_native() && sig->return_type()->is_inlinetype() && sig->return_type()->as_inline_klass()->can_be_returned_as_fields();
7354   // Don't cache on scalarized return because the range depends on 'is_call'
7355   if (!is_osr_compilation && !has_scalar_ret) {
7356     tf = C->last_tf(method); // check cache
7357     if (tf != nullptr)  return tf;  // The hit rate here is almost 50%.
7358   }
7359   const TypeTuple* domain_sig = is_osr_compilation ? osr_domain() : TypeTuple::make_domain(method, ignore_interfaces, false);
7360   const TypeTuple* domain_cc = has_scalar_args ? TypeTuple::make_domain(method, ignore_interfaces, true) : domain_sig;
7361   const TypeTuple* range_sig = TypeTuple::make_range(sig, ignore_interfaces);
7362   const TypeTuple* range_cc = has_scalar_ret ? TypeTuple::make_range(sig, ignore_interfaces, true, is_call) : range_sig;
7363   tf = TypeFunc::make(domain_sig, domain_cc, range_sig, range_cc, has_scalar_ret);
7364   if (!is_osr_compilation && !has_scalar_ret) {
7365     C->set_last_tf(method, tf);  // fill cache
7366   }



7367   return tf;
7368 }
7369 
7370 //------------------------------meet-------------------------------------------
7371 // Compute the MEET of two types.  It returns a new Type object.
7372 const Type *TypeFunc::xmeet( const Type *t ) const {
7373   // Perform a fast test for common case; meeting the same types together.
7374   if( this == t ) return this;  // Meeting same type-rep?
7375 
7376   // Current "this->_base" is Func
7377   switch (t->base()) {          // switch on original type
7378 
7379   case Bottom:                  // Ye Olde Default
7380     return t;
7381 
7382   default:                      // All else is a mistake
7383     typerr(t);
7384 
7385   case Top:
7386     break;
7387   }
7388   return this;                  // Return the double constant
7389 }
7390 
7391 //------------------------------xdual------------------------------------------
7392 // Dual: compute field-by-field dual
7393 const Type *TypeFunc::xdual() const {
7394   return this;
7395 }
7396 
7397 //------------------------------eq---------------------------------------------
7398 // Structural equality check for Type representations
7399 bool TypeFunc::eq( const Type *t ) const {
7400   const TypeFunc *a = (const TypeFunc*)t;
7401   return _domain_sig == a->_domain_sig &&
7402     _domain_cc == a->_domain_cc &&
7403     _range_sig == a->_range_sig &&
7404     _range_cc == a->_range_cc &&
7405     _scalarized_return == a->_scalarized_return;
7406 }
7407 
7408 //------------------------------hash-------------------------------------------
7409 // Type-specific hashing function.
7410 uint TypeFunc::hash(void) const {
7411   return (uint)(intptr_t)_domain_sig + (uint)(intptr_t)_domain_cc + (uint)(intptr_t)_range_sig + (uint)(intptr_t)_range_cc + (uint)(intptr_t)_scalarized_return;
7412 }
7413 
7414 //------------------------------dump2------------------------------------------
7415 // Dump Function Type
7416 #ifndef PRODUCT
7417 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
7418   if( _range_sig->cnt() <= Parms )
7419     st->print("void");
7420   else {
7421     uint i;
7422     for (i = Parms; i < _range_sig->cnt()-1; i++) {
7423       _range_sig->field_at(i)->dump2(d,depth,st);
7424       st->print("/");
7425     }
7426     _range_sig->field_at(i)->dump2(d,depth,st);
7427   }
7428   st->print(" ");
7429   st->print("( ");
7430   if( !depth || d[this] ) {     // Check for recursive dump
7431     st->print("...)");
7432     return;
7433   }
7434   d.Insert((void*)this,(void*)this);    // Stop recursion
7435   if (Parms < _domain_sig->cnt())
7436     _domain_sig->field_at(Parms)->dump2(d,depth-1,st);
7437   for (uint i = Parms+1; i < _domain_sig->cnt(); i++) {
7438     st->print(", ");
7439     _domain_sig->field_at(i)->dump2(d,depth-1,st);
7440   }
7441   st->print(" )");
7442 }
7443 #endif
7444 
7445 //------------------------------singleton--------------------------------------
7446 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
7447 // constants (Ldi nodes).  Singletons are integer, float or double constants
7448 // or a single symbol.
7449 bool TypeFunc::singleton(void) const {
7450   return false;                 // Never a singleton
7451 }
7452 
7453 bool TypeFunc::empty(void) const {
7454   return false;                 // Never empty
7455 }
7456 
7457 
7458 BasicType TypeFunc::return_type() const{
7459   if (range_sig()->cnt() == TypeFunc::Parms) {
7460     return T_VOID;
7461   }
7462   return range_sig()->field_at(TypeFunc::Parms)->basic_type();
7463 }
--- EOF ---