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