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     _is_ptr_to_strict_final_field(false),
3579     _instance_id(instance_id) {
3580 #ifdef ASSERT
3581   if (klass() != nullptr && klass()->is_loaded()) {
3582     interfaces->verify_is_loaded();
3583   }
3584 #endif
3585   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3586       (offset.get() > 0) && xk && (k != nullptr) && k->is_instance_klass()) {
3587     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset.get());
3588     _is_ptr_to_strict_final_field = _is_ptr_to_boxed_value;
3589   }
3590 
3591   if (klass() != nullptr && klass()->is_instance_klass() && klass()->is_loaded() &&
3592       this->offset() != Type::OffsetBot && this->offset() != Type::OffsetTop) {
3593     ciField* field = klass()->as_instance_klass()->get_field_by_offset(this->offset(), false);
3594     if (field != nullptr && field->is_strict() && field->is_final()) {
3595       _is_ptr_to_strict_final_field = true;
3596     }
3597   }
3598 
3599 #ifdef _LP64
3600   if (this->offset() > 0 || this->offset() == Type::OffsetTop || this->offset() == Type::OffsetBot) {
3601     if (this->offset() == oopDesc::klass_offset_in_bytes()) {
3602       _is_ptr_to_narrowklass = UseCompressedClassPointers;
3603     } else if (klass() == nullptr) {
3604       // Array with unknown body type
3605       assert(this->isa_aryptr(), "only arrays without klass");
3606       _is_ptr_to_narrowoop = UseCompressedOops;
3607     } else if (UseCompressedOops && this->isa_aryptr() && this->offset() != arrayOopDesc::length_offset_in_bytes()) {
3608       if (klass()->is_obj_array_klass()) {
3609         _is_ptr_to_narrowoop = true;
3610       } else if (klass()->is_flat_array_klass() && field_offset != Offset::top && field_offset != Offset::bottom) {
3611         // Check if the field of the inline type array element contains oops
3612         ciInlineKlass* vk = klass()->as_flat_array_klass()->element_klass()->as_inline_klass();
3613         int foffset = field_offset.get() + vk->payload_offset();
3614         BasicType field_bt;
3615         ciField* field = vk->get_field_by_offset(foffset, false);
3616         if (field != nullptr) {
3617           field_bt = field->layout_type();
3618         } else {
3619           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);
3620           field_bt = T_BOOLEAN;
3621         }
3622         _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(field_bt);
3623       }
3624     } else if (klass()->is_instance_klass()) {

3625       if (this->isa_klassptr()) {
3626         // Perm objects don't use compressed references
3627       } else if (_offset == Offset::bottom || _offset == Offset::top) {
3628         // unsafe access
3629         _is_ptr_to_narrowoop = UseCompressedOops;
3630       } else {
3631         assert(this->isa_instptr(), "must be an instance ptr.");

3632         if (klass() == ciEnv::current()->Class_klass() &&
3633             (this->offset() == java_lang_Class::klass_offset() ||
3634              this->offset() == java_lang_Class::array_klass_offset())) {
3635           // Special hidden fields from the Class.
3636           assert(this->isa_instptr(), "must be an instance ptr.");
3637           _is_ptr_to_narrowoop = false;
3638         } else if (klass() == ciEnv::current()->Class_klass() &&
3639                    this->offset() >= InstanceMirrorKlass::offset_of_static_fields()) {
3640           // Static fields
3641           ciField* field = nullptr;
3642           if (const_oop() != nullptr) {
3643             ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3644             field = k->get_field_by_offset(this->offset(), true);
3645           }
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 {
3650             // unsafe access
3651             _is_ptr_to_narrowoop = UseCompressedOops;
3652           }
3653         } else {
3654           // Instance fields which contains a compressed oop references.
3655           ciInstanceKlass* ik = klass()->as_instance_klass();
3656           ciField* field = ik->get_field_by_offset(this->offset(), false);
3657           if (field != nullptr) {
3658             BasicType basic_elem_type = field->layout_type();
3659             _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3660           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3661             // Compile::find_alias_type() cast exactness on all types to verify
3662             // that it does not affect alias type.
3663             _is_ptr_to_narrowoop = UseCompressedOops;
3664           } else {
3665             // Type for the copy start in LibraryCallKit::inline_native_clone().
3666             _is_ptr_to_narrowoop = UseCompressedOops;
3667           }
3668         }
3669       }
3670     }
3671   }
3672 #endif // _LP64
3673 }
3674 
3675 //------------------------------make-------------------------------------------
3676 const TypeOopPtr *TypeOopPtr::make(PTR ptr, Offset offset, int instance_id,
3677                                    const TypePtr* speculative, int inline_depth) {
3678   assert(ptr != Constant, "no constant generic pointers");
3679   ciKlass*  k = Compile::current()->env()->Object_klass();
3680   bool      xk = false;
3681   ciObject* o = nullptr;
3682   const TypeInterfaces* interfaces = TypeInterfaces::make();
3683   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, interfaces, xk, o, offset, Offset::bottom, instance_id, speculative, inline_depth))->hashcons();
3684 }
3685 
3686 
3687 //------------------------------cast_to_ptr_type-------------------------------
3688 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3689   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3690   if( ptr == _ptr ) return this;
3691   return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3692 }
3693 
3694 //-----------------------------cast_to_instance_id----------------------------
3695 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3696   // There are no instances of a general oop.
3697   // Return self unchanged.
3698   return this;
3699 }
3700 
3701 //-----------------------------cast_to_exactness-------------------------------
3702 const TypeOopPtr* TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3703   // There is no such thing as an exact general oop.
3704   // Return self unchanged.
3705   return this;
3706 }
3707 

3708 //------------------------------as_klass_type----------------------------------
3709 // Return the klass type corresponding to this instance or array type.
3710 // It is the type that is loaded from an object of this type.
3711 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3712   ShouldNotReachHere();
3713   return nullptr;
3714 }
3715 
3716 //------------------------------meet-------------------------------------------
3717 // Compute the MEET of two types.  It returns a new Type object.
3718 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3719   // Perform a fast test for common case; meeting the same types together.
3720   if( this == t ) return this;  // Meeting same type-rep?
3721 
3722   // Current "this->_base" is OopPtr
3723   switch (t->base()) {          // switch on original type
3724 
3725   case Int:                     // Mixing ints & oops happens when javac
3726   case Long:                    // reuses local variables
3727   case HalfFloatTop:
3728   case HalfFloatCon:
3729   case HalfFloatBot:
3730   case FloatTop:
3731   case FloatCon:
3732   case FloatBot:
3733   case DoubleTop:
3734   case DoubleCon:
3735   case DoubleBot:
3736   case NarrowOop:
3737   case NarrowKlass:
3738   case Bottom:                  // Ye Olde Default
3739     return Type::BOTTOM;
3740   case Top:
3741     return this;
3742 
3743   default:                      // All else is a mistake
3744     typerr(t);
3745 
3746   case RawPtr:
3747   case MetadataPtr:
3748   case KlassPtr:
3749   case InstKlassPtr:
3750   case AryKlassPtr:
3751     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3752 
3753   case AnyPtr: {
3754     // Found an AnyPtr type vs self-OopPtr type
3755     const TypePtr *tp = t->is_ptr();
3756     Offset offset = meet_offset(tp->offset());
3757     PTR ptr = meet_ptr(tp->ptr());
3758     const TypePtr* speculative = xmeet_speculative(tp);
3759     int depth = meet_inline_depth(tp->inline_depth());
3760     switch (tp->ptr()) {
3761     case Null:
3762       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3763       // else fall through:
3764     case TopPTR:
3765     case AnyNull: {
3766       int instance_id = meet_instance_id(InstanceTop);
3767       return make(ptr, offset, instance_id, speculative, depth);
3768     }
3769     case BotPTR:
3770     case NotNull:
3771       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3772     default: typerr(t);
3773     }
3774   }
3775 
3776   case OopPtr: {                 // Meeting to other OopPtrs
3777     const TypeOopPtr *tp = t->is_oopptr();
3778     int instance_id = meet_instance_id(tp->instance_id());
3779     const TypePtr* speculative = xmeet_speculative(tp);
3780     int depth = meet_inline_depth(tp->inline_depth());
3781     return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3782   }
3783 
3784   case InstPtr:                  // For these, flip the call around to cut down
3785   case AryPtr:
3786     return t->xmeet(this);      // Call in reverse direction
3787 
3788   } // End of switch
3789   return this;                  // Return the double constant
3790 }
3791 
3792 
3793 //------------------------------xdual------------------------------------------
3794 // Dual of a pure heap pointer.  No relevant klass or oop information.
3795 const Type *TypeOopPtr::xdual() const {
3796   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3797   assert(const_oop() == nullptr,             "no constants here");
3798   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());
3799 }
3800 
3801 //--------------------------make_from_klass_common-----------------------------
3802 // Computes the element-type given a klass.
3803 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling) {
3804   if (klass->is_instance_klass() || klass->is_inlinetype()) {
3805     Compile* C = Compile::current();
3806     Dependencies* deps = C->dependencies();
3807     assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
3808     // Element is an instance
3809     bool klass_is_exact = false;
3810     if (klass->is_loaded()) {
3811       // Try to set klass_is_exact.
3812       ciInstanceKlass* ik = klass->as_instance_klass();
3813       klass_is_exact = ik->is_final();
3814       if (!klass_is_exact && klass_change
3815           && deps != nullptr && UseUniqueSubclasses) {
3816         ciInstanceKlass* sub = ik->unique_concrete_subklass();
3817         if (sub != nullptr) {
3818           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3819           klass = ik = sub;
3820           klass_is_exact = sub->is_final();
3821         }
3822       }
3823       if (!klass_is_exact && try_for_exact && deps != nullptr &&
3824           !ik->is_interface() && !ik->has_subklass()) {
3825         // Add a dependence; if concrete subclass added we need to recompile
3826         deps->assert_leaf_type(ik);
3827         klass_is_exact = true;
3828       }
3829     }
3830     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
3831     return TypeInstPtr::make(TypePtr::BotPTR, klass, interfaces, klass_is_exact, nullptr, Offset(0));
3832   } else if (klass->is_obj_array_klass()) {
3833     // Element is an object or inline type array. Recursively call ourself.
3834     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), /* klass_change= */ false, try_for_exact, interface_handling);
3835     // Determine null-free/flat properties
3836     const bool is_null_free = klass->as_array_klass()->is_elem_null_free();
3837     if (is_null_free) {
3838       etype = etype->join_speculative(NOTNULL)->is_oopptr();
3839     }
3840     const TypeOopPtr* exact_etype = etype;
3841     if (etype->can_be_inline_type()) {
3842       // Use exact type if element can be an inline type
3843       exact_etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), /* klass_change= */ true, /* try_for_exact= */ true, interface_handling);
3844     }
3845     bool not_inline = !exact_etype->can_be_inline_type();
3846     bool not_null_free = not_inline;
3847     bool not_flat = !UseArrayFlattening || not_inline || (exact_etype->is_inlinetypeptr() && !exact_etype->inline_klass()->maybe_flat_in_array());
3848     bool atomic = klass->as_array_klass()->is_elem_atomic();
3849     // Even though MyValue is final, [LMyValue is not exact because null-free [LMyValue is a subtype.
3850     bool xk = etype->klass_is_exact() && !etype->is_inlinetypeptr();
3851     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS, /* stable= */ false, /* flat= */ false, not_flat, not_null_free, atomic);
3852     // We used to pass NotNull in here, asserting that the sub-arrays
3853     // are all not-null.  This is not true in generally, as code can
3854     // slam nullptrs down in the subarrays.
3855     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, nullptr, xk, Offset(0));
3856     return arr;
3857   } else if (klass->is_type_array_klass()) {
3858     // Element is an typeArray
3859     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3860     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS,
3861                                         /* stable= */ false, /* flat= */ false, /* not_flat= */ true, /* not_null_free= */ true);
3862     // We used to pass NotNull in here, asserting that the array pointer
3863     // is not-null. That was not true in general.
3864     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
3865     return arr;
3866   } else if (klass->is_flat_array_klass()) {
3867     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass(), trust_interfaces);
3868     const bool is_null_free = klass->as_array_klass()->is_elem_null_free();
3869     if (is_null_free) {
3870       etype = etype->join_speculative(NOTNULL)->is_oopptr();
3871     }
3872     bool atomic = klass->as_array_klass()->is_elem_atomic();
3873     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS, /* stable= */ false, /* flat= */ true, /* not_flat= */ false, /* not_null_free= */ false, atomic);
3874     const bool exact = is_null_free; // Only exact if null-free because "null-free [LMyValue <: null-able [LMyValue".
3875     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, exact, Offset(0));
3876     return arr;
3877   } else {
3878     ShouldNotReachHere();
3879     return nullptr;
3880   }
3881 }
3882 
3883 //------------------------------make_from_constant-----------------------------
3884 // Make a java pointer from an oop constant
3885 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3886   assert(!o->is_null_object(), "null object not yet handled here.");
3887 
3888   const bool make_constant = require_constant || o->should_be_constant();
3889 
3890   ciKlass* klass = o->klass();
3891   if (klass->is_instance_klass() || klass->is_inlinetype()) {
3892     // Element is an instance or inline type
3893     if (make_constant) {
3894       return TypeInstPtr::make(o);
3895     } else {
3896       return TypeInstPtr::make(TypePtr::NotNull, klass, true, nullptr, Offset(0));
3897     }
3898   } else if (klass->is_obj_array_klass()) {
3899     // Element is an object array. Recursively call ourself.
3900     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass(), trust_interfaces);
3901     bool is_flat = o->as_array()->is_flat();
3902     bool is_null_free = o->as_array()->is_null_free();
3903     if (is_null_free) {
3904       etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3905     }
3906     bool is_atomic = o->as_array()->is_atomic();
3907     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()), /* stable= */ false, /* flat= */ false,
3908                                         /* not_flat= */ !is_flat, /* not_null_free= */ !is_null_free, /* atomic= */ is_atomic);
3909     // We used to pass NotNull in here, asserting that the sub-arrays
3910     // are all not-null.  This is not true in generally, as code can
3911     // slam nulls down in the subarrays.
3912     if (make_constant) {
3913       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3914     } else {
3915       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3916     }
3917   } else if (klass->is_type_array_klass()) {
3918     // Element is an typeArray
3919     const Type* etype = (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3920     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()), /* stable= */ false, /* flat= */ false,
3921                                         /* not_flat= */ true, /* not_null_free= */ true);
3922     // We used to pass NotNull in here, asserting that the array pointer
3923     // is not-null. That was not true in general.
3924     if (make_constant) {
3925       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3926     } else {
3927       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3928     }
3929   } else if (klass->is_flat_array_klass()) {
3930     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass(), trust_interfaces);
3931     bool is_null_free = o->as_array()->is_null_free();
3932     if (is_null_free) {
3933       etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3934     }
3935     bool is_atomic = o->as_array()->is_atomic();
3936     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()), /* stable= */ false, /* flat= */ true,
3937                                         /* not_flat= */ false, /* not_null_free= */ !is_null_free, /* atomic= */ is_atomic);
3938     // We used to pass NotNull in here, asserting that the sub-arrays
3939     // are all not-null.  This is not true in generally, as code can
3940     // slam nullptrs down in the subarrays.
3941     if (make_constant) {
3942       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3943     } else {
3944       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3945     }
3946   }
3947 
3948   fatal("unhandled object type");
3949   return nullptr;
3950 }
3951 
3952 //------------------------------get_con----------------------------------------
3953 intptr_t TypeOopPtr::get_con() const {
3954   assert( _ptr == Null || _ptr == Constant, "" );
3955   assert(offset() >= 0, "");
3956 
3957   if (offset() != 0) {
3958     // After being ported to the compiler interface, the compiler no longer
3959     // directly manipulates the addresses of oops.  Rather, it only has a pointer
3960     // to a handle at compile time.  This handle is embedded in the generated
3961     // code and dereferenced at the time the nmethod is made.  Until that time,
3962     // it is not reasonable to do arithmetic with the addresses of oops (we don't
3963     // have access to the addresses!).  This does not seem to currently happen,
3964     // but this assertion here is to help prevent its occurrence.
3965     tty->print_cr("Found oop constant with non-zero offset");
3966     ShouldNotReachHere();
3967   }
3968 
3969   return (intptr_t)const_oop()->constant_encoding();
3970 }
3971 
3972 
3973 //-----------------------------filter------------------------------------------
3974 // Do not allow interface-vs.-noninterface joins to collapse to top.
3975 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
3976 
3977   const Type* ft = join_helper(kills, include_speculative);
3978 
3979   if (ft->empty()) {
3980     return Type::TOP;           // Canonical empty value
3981   }
3982 
3983   return ft;
3984 }
3985 
3986 //------------------------------eq---------------------------------------------
3987 // Structural equality check for Type representations
3988 bool TypeOopPtr::eq( const Type *t ) const {
3989   const TypeOopPtr *a = (const TypeOopPtr*)t;
3990   if (_klass_is_exact != a->_klass_is_exact ||
3991       _instance_id != a->_instance_id)  return false;
3992   ciObject* one = const_oop();
3993   ciObject* two = a->const_oop();
3994   if (one == nullptr || two == nullptr) {
3995     return (one == two) && TypePtr::eq(t);
3996   } else {
3997     return one->equals(two) && TypePtr::eq(t);
3998   }
3999 }
4000 
4001 //------------------------------hash-------------------------------------------
4002 // Type-specific hashing function.
4003 uint TypeOopPtr::hash(void) const {
4004   return
4005     (uint)(const_oop() ? const_oop()->hash() : 0) +
4006     (uint)_klass_is_exact +
4007     (uint)_instance_id + TypePtr::hash();
4008 }
4009 
4010 //------------------------------dump2------------------------------------------
4011 #ifndef PRODUCT
4012 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4013   st->print("oopptr:%s", ptr_msg[_ptr]);
4014   if( _klass_is_exact ) st->print(":exact");
4015   if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
4016   _offset.dump2(st);





4017   if (_instance_id == InstanceTop)
4018     st->print(",iid=top");
4019   else if (_instance_id != InstanceBot)
4020     st->print(",iid=%d",_instance_id);
4021 
4022   dump_inline_depth(st);
4023   dump_speculative(st);
4024 }
4025 #endif
4026 
4027 //------------------------------singleton--------------------------------------
4028 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
4029 // constants
4030 bool TypeOopPtr::singleton(void) const {
4031   // detune optimizer to not generate constant oop + constant offset as a constant!
4032   // TopPTR, Null, AnyNull, Constant are all singletons
4033   return (offset() == 0) && !below_centerline(_ptr);
4034 }
4035 
4036 //------------------------------add_offset-------------------------------------
4037 const TypePtr* TypeOopPtr::add_offset(intptr_t offset) const {
4038   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
4039 }
4040 
4041 const TypeOopPtr* TypeOopPtr::with_offset(intptr_t offset) const {
4042   return make(_ptr, Offset(offset), _instance_id, with_offset_speculative(offset), _inline_depth);
4043 }
4044 
4045 /**
4046  * Return same type without a speculative part
4047  */
4048 const TypeOopPtr* TypeOopPtr::remove_speculative() const {
4049   if (_speculative == nullptr) {
4050     return this;
4051   }
4052   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4053   return make(_ptr, _offset, _instance_id, nullptr, _inline_depth);
4054 }
4055 
4056 /**
4057  * Return same type but drop speculative part if we know we won't use
4058  * it
4059  */
4060 const Type* TypeOopPtr::cleanup_speculative() const {
4061   // If the klass is exact and the ptr is not null then there's
4062   // nothing that the speculative type can help us with
4063   if (klass_is_exact() && !maybe_null()) {
4064     return remove_speculative();
4065   }
4066   return TypePtr::cleanup_speculative();
4067 }
4068 
4069 /**
4070  * Return same type but with a different inline depth (used for speculation)
4071  *
4072  * @param depth  depth to meet with
4073  */
4074 const TypePtr* TypeOopPtr::with_inline_depth(int depth) const {
4075   if (!UseInlineDepthForSpeculativeTypes) {
4076     return this;
4077   }
4078   return make(_ptr, _offset, _instance_id, _speculative, depth);
4079 }
4080 
4081 //------------------------------with_instance_id--------------------------------
4082 const TypePtr* TypeOopPtr::with_instance_id(int instance_id) const {
4083   assert(_instance_id != -1, "should be known");
4084   return make(_ptr, _offset, instance_id, _speculative, _inline_depth);
4085 }
4086 
4087 //------------------------------meet_instance_id--------------------------------
4088 int TypeOopPtr::meet_instance_id( int instance_id ) const {
4089   // Either is 'TOP' instance?  Return the other instance!
4090   if( _instance_id == InstanceTop ) return  instance_id;
4091   if(  instance_id == InstanceTop ) return _instance_id;
4092   // If either is different, return 'BOTTOM' instance
4093   if( _instance_id != instance_id ) return InstanceBot;
4094   return _instance_id;
4095 }
4096 
4097 //------------------------------dual_instance_id--------------------------------
4098 int TypeOopPtr::dual_instance_id( ) const {
4099   if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM
4100   if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP
4101   return _instance_id;              // Map everything else into self
4102 }
4103 
4104 
4105 const TypeInterfaces* TypeOopPtr::meet_interfaces(const TypeOopPtr* other) const {
4106   if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
4107     return _interfaces->union_with(other->_interfaces);
4108   } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
4109     return other->_interfaces;
4110   } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
4111     return _interfaces;
4112   }
4113   return _interfaces->intersection_with(other->_interfaces);
4114 }
4115 
4116 /**
4117  * Check whether new profiling would improve speculative type
4118  *
4119  * @param   exact_kls    class from profiling
4120  * @param   inline_depth inlining depth of profile point
4121  *
4122  * @return  true if type profile is valuable
4123  */
4124 bool TypeOopPtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
4125   // no way to improve an already exact type
4126   if (klass_is_exact()) {
4127     return false;
4128   }
4129   return TypePtr::would_improve_type(exact_kls, inline_depth);
4130 }
4131 
4132 //=============================================================================
4133 // Convenience common pre-built types.
4134 const TypeInstPtr *TypeInstPtr::NOTNULL;
4135 const TypeInstPtr *TypeInstPtr::BOTTOM;
4136 const TypeInstPtr *TypeInstPtr::MIRROR;
4137 const TypeInstPtr *TypeInstPtr::MARK;
4138 const TypeInstPtr *TypeInstPtr::KLASS;
4139 
4140 // Is there a single ciKlass* that can represent that type?
4141 ciKlass* TypeInstPtr::exact_klass_helper() const {
4142   if (_interfaces->empty()) {
4143     return _klass;
4144   }
4145   if (_klass != ciEnv::current()->Object_klass()) {
4146     if (_interfaces->eq(_klass->as_instance_klass())) {
4147       return _klass;
4148     }
4149     return nullptr;
4150   }
4151   return _interfaces->exact_klass();
4152 }
4153 
4154 //------------------------------TypeInstPtr-------------------------------------
4155 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset off,
4156                          bool flat_in_array, int instance_id, const TypePtr* speculative, int inline_depth)
4157   : TypeOopPtr(InstPtr, ptr, k, interfaces, xk, o, off, Offset::bottom, instance_id, speculative, inline_depth),
4158     _flat_in_array(flat_in_array) {
4159   assert(k == nullptr || !k->is_loaded() || !k->is_interface(), "no interface here");
4160   assert(k != nullptr &&
4161          (k->is_loaded() || o == nullptr),
4162          "cannot have constants with non-loaded klass");
4163   assert(!klass()->maybe_flat_in_array() || flat_in_array, "Should be flat in array");
4164   assert(!flat_in_array || can_be_inline_type(), "Only inline types can be flat in array");
4165 };
4166 
4167 //------------------------------make-------------------------------------------
4168 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
4169                                      ciKlass* k,
4170                                      const TypeInterfaces* interfaces,
4171                                      bool xk,
4172                                      ciObject* o,
4173                                      Offset offset,
4174                                      bool flat_in_array,
4175                                      int instance_id,
4176                                      const TypePtr* speculative,
4177                                      int inline_depth) {
4178   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
4179   // Either const_oop() is null or else ptr is Constant
4180   assert( (!o && ptr != Constant) || (o && ptr == Constant),
4181           "constant pointers must have a value supplied" );
4182   // Ptr is never Null
4183   assert( ptr != Null, "null pointers are not typed" );
4184 
4185   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4186   if (ptr == Constant) {
4187     // Note:  This case includes meta-object constants, such as methods.
4188     xk = true;
4189   } else if (k->is_loaded()) {
4190     ciInstanceKlass* ik = k->as_instance_klass();
4191     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
4192     assert(!ik->is_interface(), "no interface here");
4193     if (xk && ik->is_interface())  xk = false;  // no exact interface
4194   }
4195 
4196   // Check if this type is known to be flat in arrays
4197   flat_in_array = flat_in_array || k->maybe_flat_in_array();
4198 
4199   // Now hash this baby
4200   TypeInstPtr *result =
4201     (TypeInstPtr*)(new TypeInstPtr(ptr, k, interfaces, xk, o, offset, flat_in_array, instance_id, speculative, inline_depth))->hashcons();
4202 
4203   return result;
4204 }
4205 
4206 const TypeInterfaces* TypePtr::interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling) {
4207   if (k->is_instance_klass()) {
4208     if (k->is_loaded()) {
4209       if (k->is_interface() && interface_handling == ignore_interfaces) {
4210         assert(interface, "no interface expected");
4211         k = ciEnv::current()->Object_klass();
4212         const TypeInterfaces* interfaces = TypeInterfaces::make();
4213         return interfaces;
4214       }
4215       GrowableArray<ciInstanceKlass *>* k_interfaces = k->as_instance_klass()->transitive_interfaces();
4216       const TypeInterfaces* interfaces = TypeInterfaces::make(k_interfaces);
4217       if (k->is_interface()) {
4218         assert(interface, "no interface expected");
4219         k = ciEnv::current()->Object_klass();
4220       } else {
4221         assert(klass, "no instance klass expected");
4222       }
4223       return interfaces;
4224     }
4225     const TypeInterfaces* interfaces = TypeInterfaces::make();
4226     return interfaces;
4227   }
4228   assert(array, "no array expected");
4229   assert(k->is_array_klass(), "Not an array?");
4230   ciType* e = k->as_array_klass()->base_element_type();
4231   if (e->is_loaded() && e->is_instance_klass() && e->as_instance_klass()->is_interface()) {
4232     if (interface_handling == ignore_interfaces) {
4233       k = ciObjArrayKlass::make(ciEnv::current()->Object_klass(), k->as_array_klass()->dimension());
4234     }
4235   }
4236   return TypeAryPtr::_array_interfaces;
4237 }
4238 
4239 /**
4240  *  Create constant type for a constant boxed value
4241  */
4242 const Type* TypeInstPtr::get_const_boxed_value() const {
4243   assert(is_ptr_to_boxed_value(), "should be called only for boxed value");
4244   assert((const_oop() != nullptr), "should be called only for constant object");
4245   ciConstant constant = const_oop()->as_instance()->field_value_by_offset(offset());
4246   BasicType bt = constant.basic_type();
4247   switch (bt) {
4248     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
4249     case T_INT:      return TypeInt::make(constant.as_int());
4250     case T_CHAR:     return TypeInt::make(constant.as_char());
4251     case T_BYTE:     return TypeInt::make(constant.as_byte());
4252     case T_SHORT:    return TypeInt::make(constant.as_short());
4253     case T_FLOAT:    return TypeF::make(constant.as_float());
4254     case T_DOUBLE:   return TypeD::make(constant.as_double());
4255     case T_LONG:     return TypeLong::make(constant.as_long());
4256     default:         break;
4257   }
4258   fatal("Invalid boxed value type '%s'", type2name(bt));
4259   return nullptr;
4260 }
4261 
4262 //------------------------------cast_to_ptr_type-------------------------------
4263 const TypeInstPtr* TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
4264   if( ptr == _ptr ) return this;
4265   // Reconstruct _sig info here since not a problem with later lazy
4266   // construction, _sig will show up on demand.
4267   return make(ptr, klass(), _interfaces, klass_is_exact(), ptr == Constant ? const_oop() : nullptr, _offset, _flat_in_array, _instance_id, _speculative, _inline_depth);
4268 }
4269 
4270 
4271 //-----------------------------cast_to_exactness-------------------------------
4272 const TypeInstPtr* TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
4273   if( klass_is_exact == _klass_is_exact ) return this;
4274   if (!_klass->is_loaded())  return this;
4275   ciInstanceKlass* ik = _klass->as_instance_klass();
4276   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
4277   assert(!ik->is_interface(), "no interface here");
4278   return make(ptr(), klass(), _interfaces, klass_is_exact, const_oop(), _offset, _flat_in_array, _instance_id, _speculative, _inline_depth);
4279 }
4280 
4281 //-----------------------------cast_to_instance_id----------------------------
4282 const TypeInstPtr* TypeInstPtr::cast_to_instance_id(int instance_id) const {
4283   if( instance_id == _instance_id ) return this;
4284   return make(_ptr, klass(), _interfaces, _klass_is_exact, const_oop(), _offset, _flat_in_array, instance_id, _speculative, _inline_depth);
4285 }
4286 
4287 //------------------------------xmeet_unloaded---------------------------------
4288 // Compute the MEET of two InstPtrs when at least one is unloaded.
4289 // Assume classes are different since called after check for same name/class-loader
4290 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst, const TypeInterfaces* interfaces) const {
4291   Offset off = meet_offset(tinst->offset());
4292   PTR ptr = meet_ptr(tinst->ptr());
4293   int instance_id = meet_instance_id(tinst->instance_id());
4294   const TypePtr* speculative = xmeet_speculative(tinst);
4295   int depth = meet_inline_depth(tinst->inline_depth());
4296 
4297   const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
4298   const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
4299   if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
4300     //
4301     // Meet unloaded class with java/lang/Object
4302     //
4303     // Meet
4304     //          |                     Unloaded Class
4305     //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
4306     //  ===================================================================
4307     //   TOP    | ..........................Unloaded......................|
4308     //  AnyNull |  U-AN    |................Unloaded......................|
4309     // Constant | ... O-NN .................................. |   O-BOT   |
4310     //  NotNull | ... O-NN .................................. |   O-BOT   |
4311     //  BOTTOM  | ........................Object-BOTTOM ..................|
4312     //
4313     assert(loaded->ptr() != TypePtr::Null, "insanity check");
4314     //
4315     if (loaded->ptr() == TypePtr::TopPTR)        { return unloaded->with_speculative(speculative); }
4316     else if (loaded->ptr() == TypePtr::AnyNull)  { return make(ptr, unloaded->klass(), interfaces, false, nullptr, off, false, instance_id, speculative, depth); }
4317     else if (loaded->ptr() == TypePtr::BotPTR)   { return TypeInstPtr::BOTTOM->with_speculative(speculative); }
4318     else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
4319       if (unloaded->ptr() == TypePtr::BotPTR)    { return TypeInstPtr::BOTTOM->with_speculative(speculative);  }
4320       else                                       { return TypeInstPtr::NOTNULL->with_speculative(speculative); }
4321     }
4322     else if (unloaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); }
4323 
4324     return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr()->with_speculative(speculative);
4325   }
4326 
4327   // Both are unloaded, not the same class, not Object
4328   // Or meet unloaded with a different loaded class, not java/lang/Object
4329   if (ptr != TypePtr::BotPTR) {
4330     return TypeInstPtr::NOTNULL->with_speculative(speculative);
4331   }
4332   return TypeInstPtr::BOTTOM->with_speculative(speculative);
4333 }
4334 
4335 
4336 //------------------------------meet-------------------------------------------
4337 // Compute the MEET of two types.  It returns a new Type object.
4338 const Type *TypeInstPtr::xmeet_helper(const Type *t) const {
4339   // Perform a fast test for common case; meeting the same types together.
4340   if( this == t ) return this;  // Meeting same type-rep?
4341 
4342   // Current "this->_base" is Pointer
4343   switch (t->base()) {          // switch on original type
4344 
4345   case Int:                     // Mixing ints & oops happens when javac
4346   case Long:                    // reuses local variables
4347   case HalfFloatTop:
4348   case HalfFloatCon:
4349   case HalfFloatBot:
4350   case FloatTop:
4351   case FloatCon:
4352   case FloatBot:
4353   case DoubleTop:
4354   case DoubleCon:
4355   case DoubleBot:
4356   case NarrowOop:
4357   case NarrowKlass:
4358   case Bottom:                  // Ye Olde Default
4359     return Type::BOTTOM;
4360   case Top:
4361     return this;
4362 
4363   default:                      // All else is a mistake
4364     typerr(t);
4365 
4366   case MetadataPtr:
4367   case KlassPtr:
4368   case InstKlassPtr:
4369   case AryKlassPtr:
4370   case RawPtr: return TypePtr::BOTTOM;
4371 
4372   case AryPtr: {                // All arrays inherit from Object class
4373     // Call in reverse direction to avoid duplication
4374     return t->is_aryptr()->xmeet_helper(this);
4375   }
4376 
4377   case OopPtr: {                // Meeting to OopPtrs
4378     // Found a OopPtr type vs self-InstPtr type
4379     const TypeOopPtr *tp = t->is_oopptr();
4380     Offset offset = meet_offset(tp->offset());
4381     PTR ptr = meet_ptr(tp->ptr());
4382     switch (tp->ptr()) {
4383     case TopPTR:
4384     case AnyNull: {
4385       int instance_id = meet_instance_id(InstanceTop);
4386       const TypePtr* speculative = xmeet_speculative(tp);
4387       int depth = meet_inline_depth(tp->inline_depth());
4388       return make(ptr, klass(), _interfaces, klass_is_exact(),
4389                   (ptr == Constant ? const_oop() : nullptr), offset, flat_in_array(), instance_id, speculative, depth);
4390     }
4391     case NotNull:
4392     case BotPTR: {
4393       int instance_id = meet_instance_id(tp->instance_id());
4394       const TypePtr* speculative = xmeet_speculative(tp);
4395       int depth = meet_inline_depth(tp->inline_depth());
4396       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4397     }
4398     default: typerr(t);
4399     }
4400   }
4401 
4402   case AnyPtr: {                // Meeting to AnyPtrs
4403     // Found an AnyPtr type vs self-InstPtr type
4404     const TypePtr *tp = t->is_ptr();
4405     Offset offset = meet_offset(tp->offset());
4406     PTR ptr = meet_ptr(tp->ptr());
4407     int instance_id = meet_instance_id(InstanceTop);
4408     const TypePtr* speculative = xmeet_speculative(tp);
4409     int depth = meet_inline_depth(tp->inline_depth());
4410     switch (tp->ptr()) {
4411     case Null:
4412       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4413       // else fall through to AnyNull
4414     case TopPTR:
4415     case AnyNull: {
4416       return make(ptr, klass(), _interfaces, klass_is_exact(),
4417                   (ptr == Constant ? const_oop() : nullptr), offset, flat_in_array(), instance_id, speculative, depth);
4418     }
4419     case NotNull:
4420     case BotPTR:
4421       return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4422     default: typerr(t);
4423     }
4424   }
4425 
4426   /*
4427                  A-top         }
4428                /   |   \       }  Tops
4429            B-top A-any C-top   }
4430               | /  |  \ |      }  Any-nulls
4431            B-any   |   C-any   }
4432               |    |    |
4433            B-con A-con C-con   } constants; not comparable across classes
4434               |    |    |
4435            B-not   |   C-not   }
4436               | \  |  / |      }  not-nulls
4437            B-bot A-not C-bot   }
4438                \   |   /       }  Bottoms
4439                  A-bot         }
4440   */
4441 
4442   case InstPtr: {                // Meeting 2 Oops?
4443     // Found an InstPtr sub-type vs self-InstPtr type
4444     const TypeInstPtr *tinst = t->is_instptr();
4445     Offset off = meet_offset(tinst->offset());
4446     PTR ptr = meet_ptr(tinst->ptr());
4447     int instance_id = meet_instance_id(tinst->instance_id());
4448     const TypePtr* speculative = xmeet_speculative(tinst);
4449     int depth = meet_inline_depth(tinst->inline_depth());
4450     const TypeInterfaces* interfaces = meet_interfaces(tinst);
4451 
4452     ciKlass* tinst_klass = tinst->klass();
4453     ciKlass* this_klass  = klass();
4454 
4455     ciKlass* res_klass = nullptr;
4456     bool res_xk = false;
4457     bool res_flat_in_array = false;
4458     const Type* res;
4459     MeetResult kind = meet_instptr(ptr, interfaces, this, tinst, res_klass, res_xk, res_flat_in_array);
4460 
4461     if (kind == UNLOADED) {
4462       // One of these classes has not been loaded
4463       const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst, interfaces);
4464 #ifndef PRODUCT
4465       if (PrintOpto && Verbose) {
4466         tty->print("meet of unloaded classes resulted in: ");
4467         unloaded_meet->dump();
4468         tty->cr();
4469         tty->print("  this == ");
4470         dump();
4471         tty->cr();
4472         tty->print(" tinst == ");
4473         tinst->dump();
4474         tty->cr();
4475       }
4476 #endif
4477       res = unloaded_meet;
4478     } else {
4479       if (kind == NOT_SUBTYPE && instance_id > 0) {
4480         instance_id = InstanceBot;
4481       } else if (kind == LCA) {
4482         instance_id = InstanceBot;
4483       }
4484       ciObject* o = nullptr;             // Assume not constant when done
4485       ciObject* this_oop = const_oop();
4486       ciObject* tinst_oop = tinst->const_oop();
4487       if (ptr == Constant) {
4488         if (this_oop != nullptr && tinst_oop != nullptr &&
4489             this_oop->equals(tinst_oop))
4490           o = this_oop;
4491         else if (above_centerline(_ptr)) {
4492           assert(!tinst_klass->is_interface(), "");
4493           o = tinst_oop;
4494         } else if (above_centerline(tinst->_ptr)) {
4495           assert(!this_klass->is_interface(), "");
4496           o = this_oop;
4497         } else
4498           ptr = NotNull;
4499       }
4500       res = make(ptr, res_klass, interfaces, res_xk, o, off, res_flat_in_array, instance_id, speculative, depth);
4501     }
4502 
4503     return res;
4504 
4505   } // End of case InstPtr
4506 
4507   } // End of switch
4508   return this;                  // Return the double constant
4509 }
4510 
4511 template<class T> TypePtr::MeetResult TypePtr::meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type, const T* other_type,
4512                                                             ciKlass*& res_klass, bool& res_xk, bool& res_flat_in_array) {
4513   ciKlass* this_klass = this_type->klass();
4514   ciKlass* other_klass = other_type->klass();
4515   const bool this_flat_in_array = this_type->flat_in_array();
4516   const bool other_flat_in_array = other_type->flat_in_array();
4517   const bool this_not_flat_in_array = this_type->not_flat_in_array();
4518   const bool other_not_flat_in_array = other_type->not_flat_in_array();
4519 
4520   bool this_xk = this_type->klass_is_exact();
4521   bool other_xk = other_type->klass_is_exact();
4522   PTR this_ptr = this_type->ptr();
4523   PTR other_ptr = other_type->ptr();
4524   const TypeInterfaces* this_interfaces = this_type->interfaces();
4525   const TypeInterfaces* other_interfaces = other_type->interfaces();
4526   // Check for easy case; klasses are equal (and perhaps not loaded!)
4527   // If we have constants, then we created oops so classes are loaded
4528   // and we can handle the constants further down.  This case handles
4529   // both-not-loaded or both-loaded classes
4530   if (ptr != Constant && this_klass->equals(other_klass) && this_xk == other_xk && this_flat_in_array == other_flat_in_array) {
4531     res_klass = this_klass;
4532     res_xk = this_xk;
4533     res_flat_in_array = this_flat_in_array;
4534     return QUICK;
4535   }
4536 
4537   // Classes require inspection in the Java klass hierarchy.  Must be loaded.
4538   if (!other_klass->is_loaded() || !this_klass->is_loaded()) {
4539     return UNLOADED;
4540   }
4541 
4542   // !!! Here's how the symmetry requirement breaks down into invariants:
4543   // If we split one up & one down AND they subtype, take the down man.
4544   // If we split one up & one down AND they do NOT subtype, "fall hard".
4545   // If both are up and they subtype, take the subtype class.
4546   // If both are up and they do NOT subtype, "fall hard".
4547   // If both are down and they subtype, take the supertype class.
4548   // If both are down and they do NOT subtype, "fall hard".
4549   // Constants treated as down.
4550 
4551   // Now, reorder the above list; observe that both-down+subtype is also
4552   // "fall hard"; "fall hard" becomes the default case:
4553   // If we split one up & one down AND they subtype, take the down man.
4554   // If both are up and they subtype, take the subtype class.
4555 
4556   // If both are down and they subtype, "fall hard".
4557   // If both are down and they do NOT subtype, "fall hard".
4558   // If both are up and they do NOT subtype, "fall hard".
4559   // If we split one up & one down AND they do NOT subtype, "fall hard".
4560 
4561   // If a proper subtype is exact, and we return it, we return it exactly.
4562   // If a proper supertype is exact, there can be no subtyping relationship!
4563   // If both types are equal to the subtype, exactness is and-ed below the
4564   // centerline and or-ed above it.  (N.B. Constants are always exact.)
4565 
4566   // Flat in Array property _flat_in_array.
4567   // For simplicity, _flat_in_array is a boolean but we actually have a tri state:
4568   // - Flat in array       -> flat_in_array()
4569   // - Not flat in array   -> not_flat_in_array()
4570   // - Maybe flat in array -> !not_flat_in_array()
4571   //
4572   // Maybe we should convert _flat_in_array to a proper lattice with four elements at some point:
4573   //
4574   //                  Top
4575   //    Flat in Array     Not Flat in Array
4576   //          Maybe Flat in Array
4577   //
4578   // where
4579   //     Top = dual(maybe Flat In Array) = "Flat in Array AND Not Flat in Array"
4580   //
4581   // But for now we stick with the current model with _flat_in_array as a boolean.
4582   //
4583   // When meeting two InstPtr types, we want to have the following behavior:
4584   //
4585   // (FiA-M) Meet(this, other):
4586   //     'this' and 'other' are either the same klass OR sub klasses:
4587   //
4588   //                yes maybe no
4589   //           yes   y    m    m                      y = Flat in Array
4590   //         maybe   m    m    m                      n = Not Flat in Array
4591   //            no   m    m    n                      m = Maybe Flat in Array
4592   //
4593   //  Join(this, other):
4594   //     (FiA-J-Same) 'this' and 'other' are the SAME klass:
4595   //
4596   //                yes maybe no                      E = Empty set
4597   //           yes   y    y    E                      y = Flat in Array
4598   //         maybe   y    m    m                      n = Not Flat in Array
4599   //            no   E    m    n                      m = Maybe Flat in Array
4600   //
4601   //     (FiA-J-Sub) 'this' and 'other' are SUB klasses:
4602   //
4603   //               yes maybe no   -> Super Klass      E = Empty set
4604   //          yes   y    y    y                       y = Flat in Array
4605   //        maybe   y    m    m                       n = Not Flat in Array
4606   //           no   E    m    n                       m = Maybe Flat in Array
4607   //           |
4608   //           v
4609   //       Sub Klass
4610   //
4611   //     Note the difference when joining a super klass that is not flat in array with a sub klass that is compared to
4612   //     the same klass case. We will take over the flat in array property of the sub klass. This can be done because
4613   //     the super klass could be Object (i.e. not an inline type and thus not flat in array) while the sub klass is a
4614   //     value class which can be flat in array.
4615   //
4616   //     The empty set is only a possible result when matching 'ptr' above the center line (i.e. joining). In this case,
4617   //     we can "fall hard" by setting 'ptr' to NotNull such that when we take the dual of that meet above the center
4618   //     line, we get an empty set again.
4619   //
4620   //     Note: When changing to a separate lattice with _flat_in_array we may want to add TypeInst(Klass)Ptr::empty()
4621   //           that returns true when the meet result is FlatInArray::Top (i.e. dual(maybe flat in array)).
4622 
4623   const T* subtype = nullptr;
4624   bool subtype_exact = false;
4625   bool flat_in_array = false;
4626   bool is_empty = false;
4627   if (this_type->is_same_java_type_as(other_type)) {
4628     // Same klass
4629     subtype = this_type;
4630     subtype_exact = below_centerline(ptr) ? (this_xk && other_xk) : (this_xk || other_xk);
4631     if (above_centerline(ptr)) {
4632       // Case (FiA-J-Same)
4633       // One is flat in array and the other not? Result is empty/"fall hard".
4634       is_empty = (this_flat_in_array && other_not_flat_in_array) || (this_not_flat_in_array && other_flat_in_array);
4635     }
4636   } else if (!other_xk && is_meet_subtype_of(this_type, other_type)) {
4637     subtype = this_type;     // Pick subtyping class
4638     subtype_exact = this_xk;
4639     if (above_centerline(ptr)) {
4640       // Case (FiA-J-Sub)
4641       is_empty = this_not_flat_in_array && other_flat_in_array;
4642       if (!is_empty) {
4643         bool other_flat_this_maybe_flat = other_flat_in_array && (!this_flat_in_array && !this_not_flat_in_array);
4644         flat_in_array = this_flat_in_array || other_flat_this_maybe_flat;
4645       }
4646     }
4647   } else if (!this_xk && is_meet_subtype_of(other_type, this_type)) {
4648     subtype = other_type;    // Pick subtyping class
4649     subtype_exact = other_xk;
4650     if (above_centerline(ptr)) {
4651       // Case (FiA-J-Sub)
4652       is_empty = this_flat_in_array && other_not_flat_in_array;
4653       if (!is_empty) {
4654         bool this_flat_other_maybe_flat = this_flat_in_array && (!other_flat_in_array && !other_not_flat_in_array);
4655         flat_in_array = other_flat_in_array || this_flat_other_maybe_flat;
4656       }
4657     }
4658   }
4659 
4660 
4661   if (subtype && !is_empty) {
4662     if (above_centerline(ptr)) {
4663       // Both types are empty.
4664       this_type = other_type = subtype;
4665       this_xk = other_xk = subtype_exact;
4666       // Case (FiA-J-Sub)
4667       bool other_flat_this_maybe_flat = other_flat_in_array && (!this_flat_in_array && !this_not_flat_in_array);
4668       flat_in_array = this_flat_in_array || other_flat_this_maybe_flat;
4669       // One is flat in array and the other not? Result is empty/"fall hard".
4670       is_empty = (this_flat_in_array && other_not_flat_in_array) || (this_not_flat_in_array && other_flat_in_array);
4671     } else if (above_centerline(this_ptr) && !above_centerline(other_ptr)) {
4672       // this_type is empty while other_type is not. Take other_type.
4673       this_type = other_type;
4674       this_xk = other_xk;
4675       flat_in_array = other_flat_in_array;
4676     } else if (above_centerline(other_ptr) && !above_centerline(this_ptr)) {
4677       // other_type is empty while this_type is not. Take this_type.
4678       other_type = this_type; // this is down; keep down man
4679       flat_in_array = this_flat_in_array;
4680     } else {
4681       // this_type and other_type are both non-empty.
4682       this_xk = subtype_exact;  // either they are equal, or we'll do an LCA
4683       // Case (FiA-M)
4684       // Meeting two types below the center line: Only flat in array if both are.
4685       flat_in_array = this_flat_in_array && other_flat_in_array;
4686     }
4687   }
4688 
4689   // Check for classes now being equal
4690   if (this_type->is_same_java_type_as(other_type) && !is_empty) {
4691     // If the klasses are equal, the constants may still differ.  Fall to
4692     // NotNull if they do (neither constant is null; that is a special case
4693     // handled elsewhere).
4694     res_klass = this_type->klass();
4695     res_xk = this_xk;
4696     res_flat_in_array = flat_in_array;
4697     return SUBTYPE;
4698   } // Else classes are not equal
4699 
4700   // Since klasses are different, we require a LCA in the Java
4701   // class hierarchy - which means we have to fall to at least NotNull.
4702   if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4703     ptr = NotNull;
4704   }
4705 
4706   interfaces = this_interfaces->intersection_with(other_interfaces);
4707 
4708   // Now we find the LCA of Java classes
4709   ciKlass* k = this_klass->least_common_ancestor(other_klass);
4710 
4711   res_klass = k;
4712   res_xk = false;
4713   res_flat_in_array = this_flat_in_array && other_flat_in_array;
4714 
4715   return LCA;
4716 }
4717 
4718 template<class T> bool TypePtr::is_meet_subtype_of(const T* sub_type, const T* super_type) {
4719   return sub_type->is_meet_subtype_of(super_type) && !(super_type->flat_in_array() && sub_type->not_flat_in_array());
4720 }
4721 
4722 //------------------------java_mirror_type--------------------------------------
4723 ciType* TypeInstPtr::java_mirror_type() const {
4724   // must be a singleton type
4725   if( const_oop() == nullptr )  return nullptr;
4726 
4727   // must be of type java.lang.Class
4728   if( klass() != ciEnv::current()->Class_klass() )  return nullptr;

4729   return const_oop()->as_instance()->java_mirror_type();
4730 }
4731 
4732 
4733 //------------------------------xdual------------------------------------------
4734 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
4735 // inheritance mechanism.
4736 const Type *TypeInstPtr::xdual() const {
4737   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());
4738 }
4739 
4740 //------------------------------eq---------------------------------------------
4741 // Structural equality check for Type representations
4742 bool TypeInstPtr::eq( const Type *t ) const {
4743   const TypeInstPtr *p = t->is_instptr();
4744   return
4745     klass()->equals(p->klass()) &&
4746     flat_in_array() == p->flat_in_array() &&
4747     _interfaces->eq(p->_interfaces) &&
4748     TypeOopPtr::eq(p);          // Check sub-type stuff
4749 }
4750 
4751 //------------------------------hash-------------------------------------------
4752 // Type-specific hashing function.
4753 uint TypeInstPtr::hash(void) const {
4754   return klass()->hash() + TypeOopPtr::hash() + _interfaces->hash() + (uint)flat_in_array();
4755 }
4756 
4757 bool TypeInstPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4758   return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4759 }
4760 
4761 
4762 bool TypeInstPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4763   return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
4764 }
4765 
4766 bool TypeInstPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4767   return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4768 }
4769 
4770 
4771 //------------------------------dump2------------------------------------------
4772 // Dump oop Type
4773 #ifndef PRODUCT
4774 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {
4775   // Print the name of the klass.
4776   klass()->print_name_on(st);
4777   _interfaces->dump(st);
4778 
4779   switch( _ptr ) {
4780   case Constant:
4781     if (WizardMode || Verbose) {
4782       ResourceMark rm;
4783       stringStream ss;
4784 
4785       st->print(" ");
4786       const_oop()->print_oop(&ss);
4787       // 'const_oop->print_oop()' may emit newlines('\n') into ss.
4788       // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4789       char* buf = ss.as_string(/* c_heap= */false);
4790       StringUtils::replace_no_expand(buf, "\n", "");
4791       st->print_raw(buf);
4792     }
4793   case BotPTR:
4794     if (!WizardMode && !Verbose) {
4795       if( _klass_is_exact ) st->print(":exact");
4796       break;
4797     }
4798   case TopPTR:
4799   case AnyNull:
4800   case NotNull:
4801     st->print(":%s", ptr_msg[_ptr]);
4802     if( _klass_is_exact ) st->print(":exact");
4803     break;
4804   default:
4805     break;
4806   }
4807 
4808   _offset.dump2(st);




4809 
4810   st->print(" *");
4811 
4812   if (flat_in_array() && !klass()->is_inlinetype()) {
4813     st->print(" (flat in array)");
4814   }
4815 
4816   if (_instance_id == InstanceTop)
4817     st->print(",iid=top");
4818   else if (_instance_id != InstanceBot)
4819     st->print(",iid=%d",_instance_id);
4820 
4821   dump_inline_depth(st);
4822   dump_speculative(st);
4823 }
4824 #endif
4825 
4826 //------------------------------add_offset-------------------------------------
4827 const TypePtr* TypeInstPtr::add_offset(intptr_t offset) const {
4828   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), xadd_offset(offset), flat_in_array(),
4829               _instance_id, add_offset_speculative(offset), _inline_depth);
4830 }
4831 
4832 const TypeInstPtr* TypeInstPtr::with_offset(intptr_t offset) const {
4833   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), Offset(offset), flat_in_array(),
4834               _instance_id, with_offset_speculative(offset), _inline_depth);
4835 }
4836 
4837 const TypeInstPtr* TypeInstPtr::remove_speculative() const {
4838   if (_speculative == nullptr) {
4839     return this;
4840   }
4841   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4842   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, flat_in_array(),
4843               _instance_id, nullptr, _inline_depth);
4844 }
4845 
4846 const TypeInstPtr* TypeInstPtr::with_speculative(const TypePtr* speculative) const {
4847   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, flat_in_array(), _instance_id, speculative, _inline_depth);
4848 }
4849 
4850 const TypePtr* TypeInstPtr::with_inline_depth(int depth) const {
4851   if (!UseInlineDepthForSpeculativeTypes) {
4852     return this;
4853   }
4854   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, flat_in_array(), _instance_id, _speculative, depth);
4855 }
4856 
4857 const TypePtr* TypeInstPtr::with_instance_id(int instance_id) const {
4858   assert(is_known_instance(), "should be known");
4859   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, flat_in_array(), instance_id, _speculative, _inline_depth);
4860 }
4861 
4862 const TypeInstPtr *TypeInstPtr::cast_to_flat_in_array() const {
4863   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, true, _instance_id, _speculative, _inline_depth);
4864 }
4865 
4866 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4867   bool xk = klass_is_exact();
4868   ciInstanceKlass* ik = klass()->as_instance_klass();
4869   if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final()) {
4870     if (_interfaces->eq(ik)) {
4871       Compile* C = Compile::current();
4872       Dependencies* deps = C->dependencies();
4873       deps->assert_leaf_type(ik);
4874       xk = true;
4875     }
4876   }
4877   return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), _interfaces, Offset(0), flat_in_array());
4878 }
4879 
4880 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) {
4881   static_assert(std::is_base_of<T2, T1>::value, "");
4882 
4883   if (!this_one->is_instance_type(other)) {
4884     return false;
4885   }
4886 
4887   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4888     return true;
4889   }
4890 
4891   return this_one->klass()->is_subtype_of(other->klass()) &&
4892          (!this_xk || this_one->_interfaces->contains(other->_interfaces));
4893 }
4894 
4895 
4896 bool TypeInstPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4897   return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4898 }
4899 
4900 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) {
4901   static_assert(std::is_base_of<T2, T1>::value, "");
4902   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4903     return true;
4904   }
4905 
4906   if (this_one->is_instance_type(other)) {
4907     return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces);
4908   }
4909 
4910   int dummy;
4911   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
4912   if (this_top_or_bottom) {
4913     return false;
4914   }
4915 
4916   const T1* other_ary = this_one->is_array_type(other);
4917   const TypePtr* other_elem = other_ary->elem()->make_ptr();
4918   const TypePtr* this_elem = this_one->elem()->make_ptr();
4919   if (other_elem != nullptr && this_elem != nullptr) {
4920     return this_one->is_reference_type(this_elem)->is_meet_subtype_of_helper(this_one->is_reference_type(other_elem), this_xk, other_xk);
4921   }

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

5809   case Bottom:                  // Ye Olde Default
5810     return Type::BOTTOM;
5811   case Top:
5812     return this;
5813 
5814   default:                      // All else is a mistake
5815     typerr(t);
5816 
5817   } // End of switch
5818 
5819   return this;
5820 }
5821 
5822 #ifndef PRODUCT
5823 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5824   _ptrtype->dump2(d, depth, st);
5825 }
5826 #endif
5827 
5828 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
5829 const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
5830 
5831 
5832 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
5833   return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();
5834 }
5835 
5836 const TypeNarrowOop* TypeNarrowOop::remove_speculative() const {
5837   return make(_ptrtype->remove_speculative()->is_ptr());
5838 }
5839 
5840 const Type* TypeNarrowOop::cleanup_speculative() const {
5841   return make(_ptrtype->cleanup_speculative()->is_ptr());
5842 }
5843 
5844 #ifndef PRODUCT
5845 void TypeNarrowOop::dump2( Dict & d, uint depth, outputStream *st ) const {
5846   st->print("narrowoop: ");
5847   TypeNarrowPtr::dump2(d, depth, st);
5848 }
5849 #endif
5850 
5851 const TypeNarrowKlass *TypeNarrowKlass::NULL_PTR;
5852 
5853 const TypeNarrowKlass* TypeNarrowKlass::make(const TypePtr* type) {
5854   return (const TypeNarrowKlass*)(new TypeNarrowKlass(type))->hashcons();
5855 }
5856 
5857 #ifndef PRODUCT
5858 void TypeNarrowKlass::dump2( Dict & d, uint depth, outputStream *st ) const {
5859   st->print("narrowklass: ");
5860   TypeNarrowPtr::dump2(d, depth, st);
5861 }
5862 #endif
5863 
5864 
5865 //------------------------------eq---------------------------------------------
5866 // Structural equality check for Type representations
5867 bool TypeMetadataPtr::eq( const Type *t ) const {
5868   const TypeMetadataPtr *a = (const TypeMetadataPtr*)t;
5869   ciMetadata* one = metadata();
5870   ciMetadata* two = a->metadata();
5871   if (one == nullptr || two == nullptr) {
5872     return (one == two) && TypePtr::eq(t);
5873   } else {
5874     return one->equals(two) && TypePtr::eq(t);
5875   }
5876 }
5877 
5878 //------------------------------hash-------------------------------------------
5879 // Type-specific hashing function.
5880 uint TypeMetadataPtr::hash(void) const {
5881   return
5882     (metadata() ? metadata()->hash() : 0) +
5883     TypePtr::hash();
5884 }
5885 
5886 //------------------------------singleton--------------------------------------
5887 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5888 // constants
5889 bool TypeMetadataPtr::singleton(void) const {
5890   // detune optimizer to not generate constant metadata + constant offset as a constant!
5891   // TopPTR, Null, AnyNull, Constant are all singletons
5892   return (offset() == 0) && !below_centerline(_ptr);
5893 }
5894 
5895 //------------------------------add_offset-------------------------------------
5896 const TypePtr* TypeMetadataPtr::add_offset( intptr_t offset ) const {
5897   return make( _ptr, _metadata, xadd_offset(offset));
5898 }
5899 
5900 //-----------------------------filter------------------------------------------
5901 // Do not allow interface-vs.-noninterface joins to collapse to top.
5902 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
5903   const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
5904   if (ft == nullptr || ft->empty())
5905     return Type::TOP;           // Canonical empty value
5906   return ft;
5907 }
5908 
5909  //------------------------------get_con----------------------------------------
5910 intptr_t TypeMetadataPtr::get_con() const {
5911   assert( _ptr == Null || _ptr == Constant, "" );
5912   assert(offset() >= 0, "");
5913 
5914   if (offset() != 0) {
5915     // After being ported to the compiler interface, the compiler no longer
5916     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5917     // to a handle at compile time.  This handle is embedded in the generated
5918     // code and dereferenced at the time the nmethod is made.  Until that time,
5919     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5920     // have access to the addresses!).  This does not seem to currently happen,
5921     // but this assertion here is to help prevent its occurrence.
5922     tty->print_cr("Found oop constant with non-zero offset");
5923     ShouldNotReachHere();
5924   }
5925 
5926   return (intptr_t)metadata()->constant_encoding();
5927 }
5928 
5929 //------------------------------cast_to_ptr_type-------------------------------
5930 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
5931   if( ptr == _ptr ) return this;
5932   return make(ptr, metadata(), _offset);
5933 }
5934 
5935 //------------------------------meet-------------------------------------------
5936 // Compute the MEET of two types.  It returns a new Type object.
5937 const Type *TypeMetadataPtr::xmeet( const Type *t ) const {
5938   // Perform a fast test for common case; meeting the same types together.
5939   if( this == t ) return this;  // Meeting same type-rep?
5940 
5941   // Current "this->_base" is OopPtr
5942   switch (t->base()) {          // switch on original type
5943 
5944   case Int:                     // Mixing ints & oops happens when javac
5945   case Long:                    // reuses local variables
5946   case HalfFloatTop:
5947   case HalfFloatCon:
5948   case HalfFloatBot:
5949   case FloatTop:
5950   case FloatCon:
5951   case FloatBot:
5952   case DoubleTop:
5953   case DoubleCon:
5954   case DoubleBot:
5955   case NarrowOop:
5956   case NarrowKlass:
5957   case Bottom:                  // Ye Olde Default
5958     return Type::BOTTOM;
5959   case Top:
5960     return this;
5961 
5962   default:                      // All else is a mistake
5963     typerr(t);
5964 
5965   case AnyPtr: {
5966     // Found an AnyPtr type vs self-OopPtr type
5967     const TypePtr *tp = t->is_ptr();
5968     Offset offset = meet_offset(tp->offset());
5969     PTR ptr = meet_ptr(tp->ptr());
5970     switch (tp->ptr()) {
5971     case Null:
5972       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5973       // else fall through:
5974     case TopPTR:
5975     case AnyNull: {
5976       return make(ptr, _metadata, offset);
5977     }
5978     case BotPTR:
5979     case NotNull:
5980       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5981     default: typerr(t);
5982     }
5983   }
5984 
5985   case RawPtr:
5986   case KlassPtr:
5987   case InstKlassPtr:
5988   case AryKlassPtr:
5989   case OopPtr:
5990   case InstPtr:
5991   case AryPtr:
5992     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
5993 
5994   case MetadataPtr: {
5995     const TypeMetadataPtr *tp = t->is_metadataptr();
5996     Offset offset = meet_offset(tp->offset());
5997     PTR tptr = tp->ptr();
5998     PTR ptr = meet_ptr(tptr);
5999     ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
6000     if (tptr == TopPTR || _ptr == TopPTR ||
6001         metadata()->equals(tp->metadata())) {
6002       return make(ptr, md, offset);
6003     }
6004     // metadata is different
6005     if( ptr == Constant ) {  // Cannot be equal constants, so...
6006       if( tptr == Constant && _ptr != Constant)  return t;
6007       if( _ptr == Constant && tptr != Constant)  return this;
6008       ptr = NotNull;            // Fall down in lattice
6009     }
6010     return make(ptr, nullptr, offset);
6011     break;
6012   }
6013   } // End of switch
6014   return this;                  // Return the double constant
6015 }
6016 
6017 
6018 //------------------------------xdual------------------------------------------
6019 // Dual of a pure metadata pointer.
6020 const Type *TypeMetadataPtr::xdual() const {
6021   return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
6022 }
6023 
6024 //------------------------------dump2------------------------------------------
6025 #ifndef PRODUCT
6026 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
6027   st->print("metadataptr:%s", ptr_msg[_ptr]);
6028   if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata()));
6029   switch (offset()) {
6030   case OffsetTop: st->print("+top"); break;
6031   case OffsetBot: st->print("+any"); break;
6032   case         0: break;
6033   default:        st->print("+%d",offset()); break;
6034   }
6035 }
6036 #endif
6037 
6038 
6039 //=============================================================================
6040 // Convenience common pre-built type.
6041 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
6042 
6043 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, Offset offset):
6044   TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
6045 }
6046 
6047 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
6048   return make(Constant, m, Offset(0));
6049 }
6050 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
6051   return make(Constant, m, Offset(0));
6052 }
6053 
6054 //------------------------------make-------------------------------------------
6055 // Create a meta data constant
6056 const TypeMetadataPtr* TypeMetadataPtr::make(PTR ptr, ciMetadata* m, Offset offset) {
6057   assert(m == nullptr || !m->is_klass(), "wrong type");
6058   return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
6059 }
6060 
6061 
6062 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
6063   const Type* elem = _ary->_elem;
6064   bool xk = klass_is_exact();
6065   if (elem->make_oopptr() != nullptr) {
6066     elem = elem->make_oopptr()->as_klass_type(try_for_exact);
6067     if (elem->is_klassptr()->klass_is_exact() &&
6068         // Even though MyValue is final, [LMyValue is only exact if the array
6069         // is (not) null-free due to null-free [LMyValue <: null-able [LMyValue.
6070         // TODO 8350865 If we know that the array can't be null-free, it's allowed to be exact, right?
6071         // If so, we should add '|| is_not_null_free()'
6072         (is_null_free() || !_ary->_elem->make_oopptr()->is_inlinetypeptr())) {
6073       xk = true;
6074     }
6075   }
6076   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());
6077 }
6078 
6079 const TypeKlassPtr* TypeKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6080   if (klass->is_instance_klass()) {
6081     return TypeInstKlassPtr::make(klass, interface_handling);
6082   }
6083   return TypeAryKlassPtr::make(klass, interface_handling);
6084 }
6085 
6086 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* klass, Offset offset, InterfaceHandling interface_handling) {
6087   if (klass->is_instance_klass()) {
6088     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
6089     return TypeInstKlassPtr::make(ptr, klass, interfaces, offset);
6090   }
6091   return TypeAryKlassPtr::make(ptr, klass, offset, interface_handling);
6092 }
6093 
6094 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, Offset offset)


6095   : TypePtr(t, ptr, offset), _klass(klass), _interfaces(interfaces) {
6096   assert(klass == nullptr || !klass->is_loaded() || (klass->is_instance_klass() && !klass->is_interface()) ||
6097          klass->is_type_array_klass() || klass->is_flat_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "no interface here");
6098 }
6099 
6100 // Is there a single ciKlass* that can represent that type?
6101 ciKlass* TypeKlassPtr::exact_klass_helper() const {
6102   assert(_klass->is_instance_klass() && !_klass->is_interface(), "No interface");
6103   if (_interfaces->empty()) {
6104     return _klass;
6105   }
6106   if (_klass != ciEnv::current()->Object_klass()) {
6107     if (_interfaces->eq(_klass->as_instance_klass())) {
6108       return _klass;
6109     }
6110     return nullptr;
6111   }
6112   return _interfaces->exact_klass();
6113 }
6114 
6115 //------------------------------eq---------------------------------------------
6116 // Structural equality check for Type representations
6117 bool TypeKlassPtr::eq(const Type *t) const {
6118   const TypeKlassPtr *p = t->is_klassptr();
6119   return
6120     _interfaces->eq(p->_interfaces) &&
6121     TypePtr::eq(p);
6122 }
6123 
6124 //------------------------------hash-------------------------------------------
6125 // Type-specific hashing function.
6126 uint TypeKlassPtr::hash(void) const {
6127   return TypePtr::hash() + _interfaces->hash();
6128 }
6129 
6130 //------------------------------singleton--------------------------------------
6131 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
6132 // constants
6133 bool TypeKlassPtr::singleton(void) const {
6134   // detune optimizer to not generate constant klass + constant offset as a constant!
6135   // TopPTR, Null, AnyNull, Constant are all singletons
6136   return (offset() == 0) && !below_centerline(_ptr);
6137 }
6138 
6139 // Do not allow interface-vs.-noninterface joins to collapse to top.
6140 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
6141   // logic here mirrors the one from TypeOopPtr::filter. See comments
6142   // there.
6143   const Type* ft = join_helper(kills, include_speculative);
6144 
6145   if (ft->empty()) {
6146     return Type::TOP;           // Canonical empty value
6147   }
6148 
6149   return ft;
6150 }
6151 
6152 const TypeInterfaces* TypeKlassPtr::meet_interfaces(const TypeKlassPtr* other) const {
6153   if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
6154     return _interfaces->union_with(other->_interfaces);
6155   } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
6156     return other->_interfaces;
6157   } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
6158     return _interfaces;
6159   }
6160   return _interfaces->intersection_with(other->_interfaces);
6161 }
6162 
6163 //------------------------------get_con----------------------------------------
6164 intptr_t TypeKlassPtr::get_con() const {
6165   assert( _ptr == Null || _ptr == Constant, "" );
6166   assert( offset() >= 0, "" );
6167 
6168   if (offset() != 0) {
6169     // After being ported to the compiler interface, the compiler no longer
6170     // directly manipulates the addresses of oops.  Rather, it only has a pointer
6171     // to a handle at compile time.  This handle is embedded in the generated
6172     // code and dereferenced at the time the nmethod is made.  Until that time,
6173     // it is not reasonable to do arithmetic with the addresses of oops (we don't
6174     // have access to the addresses!).  This does not seem to currently happen,
6175     // but this assertion here is to help prevent its occurrence.
6176     tty->print_cr("Found oop constant with non-zero offset");
6177     ShouldNotReachHere();
6178   }
6179 
6180   ciKlass* k = exact_klass();
6181 
6182   return (intptr_t)k->constant_encoding();
6183 }
6184 
6185 //------------------------------dump2------------------------------------------
6186 // Dump Klass Type
6187 #ifndef PRODUCT
6188 void TypeKlassPtr::dump2(Dict & d, uint depth, outputStream *st) const {
6189   switch(_ptr) {
6190   case Constant:
6191     st->print("precise ");
6192   case NotNull:
6193     {
6194       const char *name = klass()->name()->as_utf8();
6195       if (name) {
6196         st->print("%s: " INTPTR_FORMAT, name, p2i(klass()));
6197       } else {
6198         ShouldNotReachHere();
6199       }
6200       _interfaces->dump(st);
6201     }
6202   case BotPTR:
6203     if (!WizardMode && !Verbose && _ptr != Constant) break;
6204   case TopPTR:
6205   case AnyNull:
6206     st->print(":%s", ptr_msg[_ptr]);
6207     if (_ptr == Constant) st->print(":exact");
6208     break;
6209   default:
6210     break;
6211   }
6212   if (Verbose) {
6213     if (isa_instklassptr() && is_instklassptr()->flat_in_array()) st->print(":flat in array");



6214   }
6215   _offset.dump2(st);
6216   st->print(" *");
6217 
6218   if (flat_in_array() && !klass()->is_inlinetype()) {
6219     st->print(" (flat in array)");
6220   }
6221 }
6222 #endif
6223 
6224 //=============================================================================
6225 // Convenience common pre-built types.
6226 
6227 // Not-null object klass or below
6228 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
6229 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
6230 
6231 bool TypeInstKlassPtr::eq(const Type *t) const {
6232   const TypeKlassPtr *p = t->is_klassptr();
6233   return
6234     klass()->equals(p->klass()) &&
6235     flat_in_array() == p->flat_in_array() &&
6236     TypeKlassPtr::eq(p);
6237 }
6238 
6239 uint TypeInstKlassPtr::hash(void) const {
6240   return klass()->hash() + TypeKlassPtr::hash() + (uint)flat_in_array();
6241 }
6242 
6243 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, Offset offset, bool flat_in_array) {
6244   flat_in_array = flat_in_array || k->maybe_flat_in_array();
6245 
6246   TypeInstKlassPtr *r =
6247     (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, interfaces, offset, flat_in_array))->hashcons();
6248 
6249   return r;
6250 }
6251 
6252 //------------------------------add_offset-------------------------------------
6253 // Access internals of klass object
6254 const TypePtr *TypeInstKlassPtr::add_offset( intptr_t offset ) const {
6255   return make(_ptr, klass(), _interfaces, xadd_offset(offset), flat_in_array());
6256 }
6257 
6258 const TypeInstKlassPtr* TypeInstKlassPtr::with_offset(intptr_t offset) const {
6259   return make(_ptr, klass(), _interfaces, Offset(offset), flat_in_array());
6260 }
6261 
6262 //------------------------------cast_to_ptr_type-------------------------------
6263 const TypeInstKlassPtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
6264   assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
6265   if( ptr == _ptr ) return this;
6266   return make(ptr, _klass, _interfaces, _offset, flat_in_array());
6267 }
6268 
6269 
6270 bool TypeInstKlassPtr::must_be_exact() const {
6271   if (!_klass->is_loaded())  return false;
6272   ciInstanceKlass* ik = _klass->as_instance_klass();
6273   if (ik->is_final())  return true;  // cannot clear xk
6274   return false;
6275 }
6276 
6277 //-----------------------------cast_to_exactness-------------------------------
6278 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6279   if (klass_is_exact == (_ptr == Constant)) return this;
6280   if (must_be_exact()) return this;
6281   ciKlass* k = klass();
6282   return make(klass_is_exact ? Constant : NotNull, k, _interfaces, _offset, flat_in_array());
6283 }
6284 
6285 
6286 //-----------------------------as_instance_type--------------------------------
6287 // Corresponding type for an instance of the given class.
6288 // It will be NotNull, and exact if and only if the klass type is exact.
6289 const TypeOopPtr* TypeInstKlassPtr::as_instance_type(bool klass_change) const {
6290   ciKlass* k = klass();
6291   bool xk = klass_is_exact();
6292   Compile* C = Compile::current();
6293   Dependencies* deps = C->dependencies();
6294   assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
6295   // Element is an instance
6296   bool klass_is_exact = false;
6297   const TypeInterfaces* interfaces = _interfaces;
6298   if (k->is_loaded()) {
6299     // Try to set klass_is_exact.
6300     ciInstanceKlass* ik = k->as_instance_klass();
6301     klass_is_exact = ik->is_final();
6302     if (!klass_is_exact && klass_change
6303         && deps != nullptr && UseUniqueSubclasses) {
6304       ciInstanceKlass* sub = ik->unique_concrete_subklass();
6305       if (sub != nullptr) {
6306         if (_interfaces->eq(sub)) {
6307           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6308           k = ik = sub;
6309           xk = sub->is_final();
6310         }
6311       }
6312     }
6313   }
6314   return TypeInstPtr::make(TypePtr::BotPTR, k, interfaces, xk, nullptr, Offset(0), flat_in_array() && !klass()->is_inlinetype());
6315 }
6316 
6317 //------------------------------xmeet------------------------------------------
6318 // Compute the MEET of two types, return a new Type object.
6319 const Type    *TypeInstKlassPtr::xmeet( const Type *t ) const {
6320   // Perform a fast test for common case; meeting the same types together.
6321   if( this == t ) return this;  // Meeting same type-rep?
6322 
6323   // Current "this->_base" is Pointer
6324   switch (t->base()) {          // switch on original type
6325 
6326   case Int:                     // Mixing ints & oops happens when javac
6327   case Long:                    // reuses local variables
6328   case HalfFloatTop:
6329   case HalfFloatCon:
6330   case HalfFloatBot:
6331   case FloatTop:
6332   case FloatCon:
6333   case FloatBot:
6334   case DoubleTop:
6335   case DoubleCon:
6336   case DoubleBot:
6337   case NarrowOop:
6338   case NarrowKlass:
6339   case Bottom:                  // Ye Olde Default
6340     return Type::BOTTOM;
6341   case Top:
6342     return this;
6343 
6344   default:                      // All else is a mistake
6345     typerr(t);
6346 
6347   case AnyPtr: {                // Meeting to AnyPtrs
6348     // Found an AnyPtr type vs self-KlassPtr type
6349     const TypePtr *tp = t->is_ptr();
6350     Offset offset = meet_offset(tp->offset());
6351     PTR ptr = meet_ptr(tp->ptr());
6352     switch (tp->ptr()) {
6353     case TopPTR:
6354       return this;
6355     case Null:
6356       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6357     case AnyNull:
6358       return make(ptr, klass(), _interfaces, offset, flat_in_array());
6359     case BotPTR:
6360     case NotNull:
6361       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6362     default: typerr(t);
6363     }
6364   }
6365 
6366   case RawPtr:
6367   case MetadataPtr:
6368   case OopPtr:
6369   case AryPtr:                  // Meet with AryPtr
6370   case InstPtr:                 // Meet with InstPtr
6371       return TypePtr::BOTTOM;
6372 
6373   //
6374   //             A-top         }
6375   //           /   |   \       }  Tops
6376   //       B-top A-any C-top   }
6377   //          | /  |  \ |      }  Any-nulls
6378   //       B-any   |   C-any   }
6379   //          |    |    |
6380   //       B-con A-con C-con   } constants; not comparable across classes
6381   //          |    |    |
6382   //       B-not   |   C-not   }
6383   //          | \  |  / |      }  not-nulls
6384   //       B-bot A-not C-bot   }
6385   //           \   |   /       }  Bottoms
6386   //             A-bot         }
6387   //
6388 
6389   case InstKlassPtr: {  // Meet two KlassPtr types
6390     const TypeInstKlassPtr *tkls = t->is_instklassptr();
6391     Offset  off     = meet_offset(tkls->offset());
6392     PTR  ptr     = meet_ptr(tkls->ptr());
6393     const TypeInterfaces* interfaces = meet_interfaces(tkls);
6394 
6395     ciKlass* res_klass = nullptr;
6396     bool res_xk = false;
6397     bool res_flat_in_array = false;
6398     switch(meet_instptr(ptr, interfaces, this, tkls, res_klass, res_xk, res_flat_in_array)) {
6399       case UNLOADED:
6400         ShouldNotReachHere();
6401       case SUBTYPE:
6402       case NOT_SUBTYPE:
6403       case LCA:
6404       case QUICK: {
6405         assert(res_xk == (ptr == Constant), "");
6406         const Type* res = make(ptr, res_klass, interfaces, off, res_flat_in_array);
6407         return res;
6408       }
6409       default:
6410         ShouldNotReachHere();
6411     }
6412   } // End of case KlassPtr
6413   case AryKlassPtr: {                // All arrays inherit from Object class
6414     const TypeAryKlassPtr *tp = t->is_aryklassptr();
6415     Offset offset = meet_offset(tp->offset());
6416     PTR ptr = meet_ptr(tp->ptr());
6417     const TypeInterfaces* interfaces = meet_interfaces(tp);
6418     const TypeInterfaces* tp_interfaces = tp->_interfaces;
6419     const TypeInterfaces* this_interfaces = _interfaces;
6420 
6421     switch (ptr) {
6422     case TopPTR:
6423     case AnyNull:                // Fall 'down' to dual of object klass
6424       // For instances when a subclass meets a superclass we fall
6425       // below the centerline when the superclass is exact. We need to
6426       // do the same here.
6427       if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
6428         return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset, tp->is_not_flat(), tp->is_not_null_free(), tp->is_flat(), tp->is_null_free(), tp->is_atomic(), tp->is_refined_type());
6429       } else {
6430         // cannot subclass, so the meet has to fall badly below the centerline
6431         ptr = NotNull;
6432         interfaces = _interfaces->intersection_with(tp->_interfaces);
6433         return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
6434       }
6435     case Constant:
6436     case NotNull:
6437     case BotPTR:                // Fall down to object klass
6438       // LCA is object_klass, but if we subclass from the top we can do better
6439       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
6440         // If 'this' (InstPtr) is above the centerline and it is Object class
6441         // then we can subclass in the Java class hierarchy.
6442         // For instances when a subclass meets a superclass we fall
6443         // below the centerline when the superclass is exact. We need
6444         // to do the same here.
6445         if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
6446           // that is, tp's array type is a subtype of my klass
6447           return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset, tp->is_not_flat(), tp->is_not_null_free(), tp->is_flat(), tp->is_null_free(), tp->is_atomic(), tp->is_refined_type());

6448         }
6449       }
6450       // The other case cannot happen, since I cannot be a subtype of an array.
6451       // The meet falls down to Object class below centerline.
6452       if( ptr == Constant )
6453          ptr = NotNull;
6454       interfaces = this_interfaces->intersection_with(tp_interfaces);
6455       return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
6456     default: typerr(t);
6457     }
6458   }
6459 
6460   } // End of switch
6461   return this;                  // Return the double constant
6462 }
6463 
6464 //------------------------------xdual------------------------------------------
6465 // Dual: compute field-by-field dual
6466 const Type    *TypeInstKlassPtr::xdual() const {
6467   return new TypeInstKlassPtr(dual_ptr(), klass(), _interfaces, dual_offset(), flat_in_array());
6468 }
6469 
6470 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) {
6471   static_assert(std::is_base_of<T2, T1>::value, "");
6472   if (!this_one->is_loaded() || !other->is_loaded()) {
6473     return false;
6474   }
6475   if (!this_one->is_instance_type(other)) {
6476     return false;
6477   }
6478 
6479   if (!other_exact) {
6480     return false;
6481   }
6482 
6483   if (other->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces->empty()) {
6484     return true;
6485   }
6486 
6487   return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);
6488 }
6489 
6490 bool TypeInstKlassPtr::might_be_an_array() const {
6491   if (!instance_klass()->is_java_lang_Object()) {
6492     // TypeInstKlassPtr can be an array only if it is java.lang.Object: the only supertype of array types.
6493     return false;
6494   }
6495   if (interfaces()->has_non_array_interface()) {
6496     // Arrays only implement Cloneable and Serializable. If we see any other interface, [this] cannot be an array.
6497     return false;
6498   }
6499   // Cannot prove it's not an array.
6500   return true;
6501 }
6502 
6503 bool TypeInstKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6504   return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
6505 }
6506 
6507 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_instance(const T1* this_one, const T2* other) {
6508   static_assert(std::is_base_of<T2, T1>::value, "");
6509   if (!this_one->is_loaded() || !other->is_loaded()) {
6510     return false;
6511   }
6512   if (!this_one->is_instance_type(other)) {
6513     return false;
6514   }
6515   return this_one->klass()->equals(other->klass()) && this_one->_interfaces->eq(other->_interfaces);
6516 }
6517 
6518 bool TypeInstKlassPtr::is_same_java_type_as_helper(const TypeKlassPtr* other) const {
6519   return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
6520 }
6521 
6522 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) {
6523   static_assert(std::is_base_of<T2, T1>::value, "");
6524   if (!this_one->is_loaded() || !other->is_loaded()) {
6525     return true;
6526   }
6527 
6528   if (this_one->is_array_type(other)) {
6529     return !this_exact && this_one->klass()->equals(ciEnv::current()->Object_klass())  && other->_interfaces->contains(this_one->_interfaces);
6530   }
6531 
6532   assert(this_one->is_instance_type(other), "unsupported");
6533 
6534   if (this_exact && other_exact) {
6535     return this_one->is_java_subtype_of(other);
6536   }
6537 
6538   if (!this_one->klass()->is_subtype_of(other->klass()) && !other->klass()->is_subtype_of(this_one->klass())) {
6539     return false;
6540   }
6541 
6542   if (this_exact) {
6543     return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);
6544   }
6545 
6546   return true;
6547 }
6548 
6549 bool TypeInstKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6550   return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
6551 }
6552 
6553 const TypeKlassPtr* TypeInstKlassPtr::try_improve() const {
6554   if (!UseUniqueSubclasses) {
6555     return this;
6556   }
6557   ciKlass* k = klass();
6558   Compile* C = Compile::current();
6559   Dependencies* deps = C->dependencies();
6560   assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
6561   const TypeInterfaces* interfaces = _interfaces;
6562   if (k->is_loaded()) {
6563     ciInstanceKlass* ik = k->as_instance_klass();
6564     bool klass_is_exact = ik->is_final();
6565     if (!klass_is_exact &&
6566         deps != nullptr) {
6567       ciInstanceKlass* sub = ik->unique_concrete_subklass();
6568       if (sub != nullptr) {
6569         if (_interfaces->eq(sub)) {
6570           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6571           k = ik = sub;
6572           klass_is_exact = sub->is_final();
6573           return TypeKlassPtr::make(klass_is_exact ? Constant : _ptr, k, _offset);
6574         }
6575       }
6576     }
6577   }
6578   return this;
6579 }
6580 
6581 bool TypeInstKlassPtr::can_be_inline_array() const {
6582   return _klass->equals(ciEnv::current()->Object_klass()) && TypeAryKlassPtr::_array_interfaces->contains(_interfaces);
6583 }
6584 
6585 bool TypeAryKlassPtr::can_be_inline_array() const {
6586   return _elem->isa_instklassptr() && _elem->is_instklassptr()->_klass->can_be_inline_klass();
6587 }
6588 
6589 bool TypeInstPtr::can_be_inline_array() const {
6590   return _klass->equals(ciEnv::current()->Object_klass()) && TypeAryPtr::_array_interfaces->contains(_interfaces);
6591 }
6592 
6593 bool TypeAryPtr::can_be_inline_array() const {
6594   return elem()->make_ptr() && elem()->make_ptr()->isa_instptr() && elem()->make_ptr()->is_instptr()->_klass->can_be_inline_klass();
6595 }
6596 
6597 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, Offset offset, bool not_flat, bool not_null_free, bool flat, bool null_free, bool atomic, bool refined_type) {
6598   return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset, not_flat, not_null_free, flat, null_free, atomic, refined_type))->hashcons();
6599 }
6600 
6601 const TypeAryKlassPtr* TypeAryKlassPtr::make(PTR ptr, ciKlass* k, Offset offset, InterfaceHandling interface_handling, bool not_flat, bool not_null_free, bool flat, bool null_free, bool atomic, bool refined_type) {
6602   if (k->is_obj_array_klass()) {
6603     // Element is an object array. Recursively call ourself.
6604     ciKlass* eklass = k->as_obj_array_klass()->element_klass();
6605     const TypeKlassPtr* etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6606     return TypeAryKlassPtr::make(ptr, etype, nullptr, offset, not_flat, not_null_free, flat, null_free, atomic, refined_type);
6607   } else if (k->is_type_array_klass()) {
6608     // Element is an typeArray
6609     const Type* etype = get_const_basic_type(k->as_type_array_klass()->element_type());
6610     return TypeAryKlassPtr::make(ptr, etype, k, offset, not_flat, not_null_free, flat, null_free, atomic);
6611   } else if (k->is_flat_array_klass()) {
6612     ciKlass* eklass = k->as_flat_array_klass()->element_klass();
6613     const TypeKlassPtr* etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6614     return TypeAryKlassPtr::make(ptr, etype, k, offset, not_flat, not_null_free, flat, null_free, atomic, refined_type);
6615   } else {
6616     ShouldNotReachHere();
6617     return nullptr;
6618   }
6619 }
6620 
6621 const TypeAryKlassPtr* TypeAryKlassPtr::make(PTR ptr, ciKlass* k, Offset offset, InterfaceHandling interface_handling, bool refined_type) {
6622   bool flat = k->is_flat_array_klass();
6623   bool null_free = k->as_array_klass()->is_elem_null_free();
6624   bool atomic = k->as_array_klass()->is_elem_atomic();
6625 
6626   bool not_inline = k->is_type_array_klass() || !k->as_array_klass()->element_klass()->can_be_inline_klass(false);
6627   bool not_null_free = (ptr == Constant) ? !null_free : not_inline;
6628   bool not_flat = (ptr == Constant) ? !flat : (!UseArrayFlattening || not_inline ||
6629                    (k->as_array_klass()->element_klass() != nullptr &&
6630                     k->as_array_klass()->element_klass()->is_inlinetype() &&
6631                    !k->as_array_klass()->element_klass()->maybe_flat_in_array()));
6632 
6633   return TypeAryKlassPtr::make(ptr, k, offset, interface_handling, not_flat, not_null_free, flat, null_free, atomic, refined_type);
6634 }
6635 
6636 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling, bool refined_type) {
6637   return TypeAryKlassPtr::make(Constant, klass, Offset(0), interface_handling, refined_type);
6638 }
6639 
6640 // Get the (non-)refined array klass ptr
6641 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_refined_array_klass_ptr(bool refined) const {
6642   if ((refined == is_refined_type()) || !klass_is_exact() || (!exact_klass()->is_obj_array_klass() && !exact_klass()->is_flat_array_klass())) {
6643     return this;
6644   }
6645   ciKlass* eklass = elem()->is_klassptr()->exact_klass_helper();
6646   if (elem()->isa_aryklassptr()) {
6647     eklass = exact_klass()->as_obj_array_klass()->element_klass();
6648   }
6649   ciKlass* array_klass = ciArrayKlass::make(eklass, eklass->is_inlinetype() ? is_null_free() : false, eklass->is_inlinetype() ? is_atomic() : true, refined);
6650   return make(_ptr, array_klass, Offset(0), trust_interfaces, refined);
6651 }
6652 
6653 //------------------------------eq---------------------------------------------
6654 // Structural equality check for Type representations
6655 bool TypeAryKlassPtr::eq(const Type *t) const {
6656   const TypeAryKlassPtr *p = t->is_aryklassptr();
6657   return
6658     _elem == p->_elem &&  // Check array
6659     _flat == p->_flat &&
6660     _not_flat == p->_not_flat &&
6661     _null_free == p->_null_free &&
6662     _not_null_free == p->_not_null_free &&
6663     _atomic == p->_atomic &&
6664     _refined_type == p->_refined_type &&
6665     TypeKlassPtr::eq(p);  // Check sub-parts
6666 }
6667 
6668 //------------------------------hash-------------------------------------------
6669 // Type-specific hashing function.
6670 uint TypeAryKlassPtr::hash(void) const {
6671   return (uint)(uintptr_t)_elem + TypeKlassPtr::hash() + (uint)(_not_flat ? 43 : 0) +
6672       (uint)(_not_null_free ? 44 : 0) + (uint)(_flat ? 45 : 0) + (uint)(_null_free ? 46 : 0)  + (uint)(_atomic ? 47 : 0) + (uint)(_refined_type ? 48 : 0);
6673 }
6674 
6675 //----------------------compute_klass------------------------------------------
6676 // Compute the defining klass for this class
6677 ciKlass* TypeAryPtr::compute_klass() const {
6678   // Compute _klass based on element type.
6679   ciKlass* k_ary = nullptr;
6680   const TypeInstPtr *tinst;
6681   const TypeAryPtr *tary;
6682   const Type* el = elem();
6683   if (el->isa_narrowoop()) {
6684     el = el->make_ptr();
6685   }
6686 
6687   // Get element klass
6688   if (is_flat() && el->is_inlinetypeptr()) {
6689     // Klass is required by TypeAryPtr::flat_layout_helper() and others
6690     if (el->inline_klass() != nullptr) {
6691       // TODO 8350865 We assume atomic if the atomic layout is available, use is_atomic() here
6692       bool atomic = is_null_free() ? el->inline_klass()->has_atomic_layout() : el->inline_klass()->has_nullable_atomic_layout();
6693       k_ary = ciArrayKlass::make(el->inline_klass(), is_null_free(), atomic, true);
6694     }
6695   } else if ((tinst = el->isa_instptr()) != nullptr) {
6696     // Leave k_ary at nullptr.
6697   } else if ((tary = el->isa_aryptr()) != nullptr) {
6698     // Leave k_ary at nullptr.
6699   } else if ((el->base() == Type::Top) ||
6700              (el->base() == Type::Bottom)) {
6701     // element type of Bottom occurs from meet of basic type
6702     // and object; Top occurs when doing join on Bottom.
6703     // Leave k_ary at null.
6704   } else {
6705     assert(!el->isa_int(), "integral arrays must be pre-equipped with a class");
6706     // Compute array klass directly from basic type
6707     k_ary = ciTypeArrayKlass::make(el->basic_type());
6708   }
6709   return k_ary;
6710 }
6711 
6712 //------------------------------klass------------------------------------------
6713 // Return the defining klass for this class
6714 ciKlass* TypeAryPtr::klass() const {
6715   if( _klass ) return _klass;   // Return cached value, if possible
6716 
6717   // Oops, need to compute _klass and cache it
6718   ciKlass* k_ary = compute_klass();
6719 
6720   if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) {
6721     // The _klass field acts as a cache of the underlying
6722     // ciKlass for this array type.  In order to set the field,
6723     // we need to cast away const-ness.
6724     //
6725     // IMPORTANT NOTE: we *never* set the _klass field for the
6726     // type TypeAryPtr::OOPS.  This Type is shared between all
6727     // active compilations.  However, the ciKlass which represents
6728     // this Type is *not* shared between compilations, so caching
6729     // this value would result in fetching a dangling pointer.
6730     //
6731     // Recomputing the underlying ciKlass for each request is
6732     // a bit less efficient than caching, but calls to
6733     // TypeAryPtr::OOPS->klass() are not common enough to matter.
6734     ((TypeAryPtr*)this)->_klass = k_ary;
6735   }
6736   return k_ary;
6737 }
6738 
6739 // Is there a single ciKlass* that can represent that type?
6740 ciKlass* TypeAryPtr::exact_klass_helper() const {
6741   if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) {
6742     ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper();
6743     if (k == nullptr) {
6744       return nullptr;
6745     }
6746     k = ciArrayKlass::make(k, is_null_free(), is_atomic(), is_flat() || is_null_free());
6747     return k;
6748   }
6749 
6750   return klass();
6751 }
6752 
6753 const Type* TypeAryPtr::base_element_type(int& dims) const {
6754   const Type* elem = this->elem();
6755   dims = 1;
6756   while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) {
6757     elem = elem->make_ptr()->is_aryptr()->elem();
6758     dims++;
6759   }
6760   return elem;
6761 }
6762 
6763 //------------------------------add_offset-------------------------------------
6764 // Access internals of klass object
6765 const TypePtr* TypeAryKlassPtr::add_offset(intptr_t offset) const {
6766   return make(_ptr, elem(), klass(), xadd_offset(offset), is_not_flat(), is_not_null_free(), _flat, _null_free, _atomic, _refined_type);
6767 }
6768 
6769 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const {
6770   return make(_ptr, elem(), klass(), Offset(offset), is_not_flat(), is_not_null_free(), _flat, _null_free, _atomic, _refined_type);
6771 }
6772 
6773 //------------------------------cast_to_ptr_type-------------------------------
6774 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6775   assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6776   if (ptr == _ptr) return this;
6777   return make(ptr, elem(), _klass, _offset, is_not_flat(), is_not_null_free(), _flat, _null_free, _atomic, _refined_type);
6778 }
6779 
6780 bool TypeAryKlassPtr::must_be_exact() const {
6781   if (_elem == Type::BOTTOM) return false;
6782   if (_elem == Type::TOP   ) return false;
6783   const TypeKlassPtr*  tk = _elem->isa_klassptr();
6784   if (!tk)             return true;   // a primitive type, like int
6785   // Even though MyValue is final, [LMyValue is only exact if the array
6786   // is (not) null-free due to null-free [LMyValue <: null-able [LMyValue.
6787   // TODO 8350865 If we know that the array can't be null-free, it's allowed to be exact, right?
6788   // If so, we should add '&& !is_not_null_free()'
6789   if (tk->isa_instklassptr() && tk->klass()->is_inlinetype() && !is_null_free()) {
6790     return false;
6791   }
6792   return tk->must_be_exact();
6793 }
6794 
6795 
6796 //-----------------------------cast_to_exactness-------------------------------
6797 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6798   if (must_be_exact() && !klass_is_exact) return this;  // cannot clear xk
6799   if (klass_is_exact == this->klass_is_exact()) {
6800     return this;
6801   }
6802   ciKlass* k = _klass;
6803   const Type* elem = this->elem();
6804   if (elem->isa_klassptr() && !klass_is_exact) {
6805     elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
6806   }
6807   bool not_flat = is_not_flat();
6808   bool not_null_free = is_not_null_free();
6809   if (_elem->isa_klassptr()) {
6810     if (klass_is_exact || _elem->isa_aryklassptr()) {
6811       assert((!is_null_free() && !is_flat()) ||
6812              _elem->is_klassptr()->klass()->is_abstract() || _elem->is_klassptr()->klass()->is_java_lang_Object(),
6813              "null-free (or flat) concrete inline type arrays should always be exact");
6814       // An array can't be null-free (or flat) if the klass is exact
6815       not_null_free = true;
6816       not_flat = true;
6817     } else {
6818       // Klass is not exact (anymore), re-compute null-free/flat properties
6819       const TypeOopPtr* exact_etype = TypeOopPtr::make_from_klass_unique(_elem->is_instklassptr()->instance_klass());
6820       bool not_inline = !exact_etype->can_be_inline_type();
6821       not_null_free = not_inline;
6822       not_flat = !UseArrayFlattening || not_inline || (exact_etype->is_inlinetypeptr() && !exact_etype->inline_klass()->maybe_flat_in_array());
6823     }
6824   }
6825   return make(klass_is_exact ? Constant : NotNull, elem, k, _offset, not_flat, not_null_free, _flat, _null_free, _atomic, _refined_type);
6826 }
6827 

6828 //-----------------------------as_instance_type--------------------------------
6829 // Corresponding type for an instance of the given class.
6830 // It will be NotNull, and exact if and only if the klass type is exact.
6831 const TypeOopPtr* TypeAryKlassPtr::as_instance_type(bool klass_change) const {
6832   ciKlass* k = klass();
6833   bool    xk = klass_is_exact();
6834   const Type* el = nullptr;
6835   if (elem()->isa_klassptr()) {
6836     el = elem()->is_klassptr()->as_instance_type(false)->cast_to_exactness(false);
6837     k = nullptr;
6838   } else {
6839     el = elem();
6840   }
6841   bool null_free = _null_free;
6842   if (null_free && el->isa_ptr()) {
6843     el = el->is_ptr()->join_speculative(TypePtr::NOTNULL);
6844   }
6845   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));
6846 }
6847 
6848 
6849 //------------------------------xmeet------------------------------------------
6850 // Compute the MEET of two types, return a new Type object.
6851 const Type    *TypeAryKlassPtr::xmeet( const Type *t ) const {
6852   // Perform a fast test for common case; meeting the same types together.
6853   if( this == t ) return this;  // Meeting same type-rep?
6854 
6855   // Current "this->_base" is Pointer
6856   switch (t->base()) {          // switch on original type
6857 
6858   case Int:                     // Mixing ints & oops happens when javac
6859   case Long:                    // reuses local variables
6860   case HalfFloatTop:
6861   case HalfFloatCon:
6862   case HalfFloatBot:
6863   case FloatTop:
6864   case FloatCon:
6865   case FloatBot:
6866   case DoubleTop:
6867   case DoubleCon:
6868   case DoubleBot:
6869   case NarrowOop:
6870   case NarrowKlass:
6871   case Bottom:                  // Ye Olde Default
6872     return Type::BOTTOM;
6873   case Top:
6874     return this;
6875 
6876   default:                      // All else is a mistake
6877     typerr(t);
6878 
6879   case AnyPtr: {                // Meeting to AnyPtrs
6880     // Found an AnyPtr type vs self-KlassPtr type
6881     const TypePtr *tp = t->is_ptr();
6882     Offset offset = meet_offset(tp->offset());
6883     PTR ptr = meet_ptr(tp->ptr());
6884     switch (tp->ptr()) {
6885     case TopPTR:
6886       return this;
6887     case Null:
6888       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6889     case AnyNull:
6890       return make(ptr, _elem, klass(), offset, is_not_flat(), is_not_null_free(), is_flat(), is_null_free(), is_atomic(), is_refined_type());
6891     case BotPTR:
6892     case NotNull:
6893       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6894     default: typerr(t);
6895     }
6896   }
6897 
6898   case RawPtr:
6899   case MetadataPtr:
6900   case OopPtr:
6901   case AryPtr:                  // Meet with AryPtr
6902   case InstPtr:                 // Meet with InstPtr
6903     return TypePtr::BOTTOM;
6904 
6905   //
6906   //             A-top         }
6907   //           /   |   \       }  Tops
6908   //       B-top A-any C-top   }
6909   //          | /  |  \ |      }  Any-nulls
6910   //       B-any   |   C-any   }
6911   //          |    |    |
6912   //       B-con A-con C-con   } constants; not comparable across classes
6913   //          |    |    |
6914   //       B-not   |   C-not   }
6915   //          | \  |  / |      }  not-nulls
6916   //       B-bot A-not C-bot   }
6917   //           \   |   /       }  Bottoms
6918   //             A-bot         }
6919   //
6920 
6921   case AryKlassPtr: {  // Meet two KlassPtr types
6922     const TypeAryKlassPtr *tap = t->is_aryklassptr();
6923     Offset off = meet_offset(tap->offset());
6924     const Type* elem = _elem->meet(tap->_elem);

6925     PTR ptr = meet_ptr(tap->ptr());
6926     ciKlass* res_klass = nullptr;
6927     bool res_xk = false;
6928     bool res_flat = false;
6929     bool res_not_flat = false;
6930     bool res_not_null_free = false;
6931     bool res_atomic = false;
6932     MeetResult res = meet_aryptr(ptr, elem, this, tap,
6933                                  res_klass, res_xk, res_flat, res_not_flat, res_not_null_free, res_atomic);
6934     assert(res_xk == (ptr == Constant), "");
6935     bool flat = meet_flat(tap->_flat);
6936     bool null_free = meet_null_free(tap->_null_free);
6937     bool atomic = meet_atomic(tap->_atomic);
6938     bool refined_type = _refined_type && tap->_refined_type;
6939     if (res == NOT_SUBTYPE) {
6940       flat = false;
6941       null_free = false;
6942       atomic = false;
6943       refined_type = false;
6944     } else if (res == SUBTYPE) {
6945       if (above_centerline(tap->ptr()) && !above_centerline(this->ptr())) {
6946         flat = _flat;
6947         null_free = _null_free;
6948         atomic = _atomic;
6949         refined_type = _refined_type;
6950       } else if (above_centerline(this->ptr()) && !above_centerline(tap->ptr())) {
6951         flat = tap->_flat;
6952         null_free = tap->_null_free;
6953         atomic = tap->_atomic;
6954         refined_type = tap->_refined_type;
6955       } else if (above_centerline(this->ptr()) && above_centerline(tap->ptr())) {
6956         flat = _flat || tap->_flat;
6957         null_free = _null_free || tap->_null_free;
6958         atomic = _atomic || tap->_atomic;
6959         refined_type = _refined_type || tap->_refined_type;
6960       } else if (res_xk && _refined_type != tap->_refined_type) {
6961         // This can happen if the phi emitted by LibraryCallKit::load_default_refined_array_klass/load_non_refined_array_klass
6962         // is processed before the typeArray guard is folded. Both inputs are constant but the input corresponding to the
6963         // typeArray will go away. Don't constant fold it yet but wait for the control input to collapse.
6964         ptr = PTR::NotNull;
6965       }
6966     }
6967     return make(ptr, elem, res_klass, off, res_not_flat, res_not_null_free, flat, null_free, atomic, refined_type);
6968   } // End of case KlassPtr
6969   case InstKlassPtr: {
6970     const TypeInstKlassPtr *tp = t->is_instklassptr();
6971     Offset offset = meet_offset(tp->offset());
6972     PTR ptr = meet_ptr(tp->ptr());
6973     const TypeInterfaces* interfaces = meet_interfaces(tp);
6974     const TypeInterfaces* tp_interfaces = tp->_interfaces;
6975     const TypeInterfaces* this_interfaces = _interfaces;
6976 
6977     switch (ptr) {
6978     case TopPTR:
6979     case AnyNull:                // Fall 'down' to dual of object klass
6980       // For instances when a subclass meets a superclass we fall
6981       // below the centerline when the superclass is exact. We need to
6982       // do the same here.
6983       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
6984           !tp->klass_is_exact()) {
6985         return TypeAryKlassPtr::make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), is_flat(), is_null_free(), is_atomic(), is_refined_type());
6986       } else {
6987         // cannot subclass, so the meet has to fall badly below the centerline
6988         ptr = NotNull;
6989         interfaces = this_interfaces->intersection_with(tp->_interfaces);
6990         return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
6991       }
6992     case Constant:
6993     case NotNull:
6994     case BotPTR:                // Fall down to object klass
6995       // LCA is object_klass, but if we subclass from the top we can do better
6996       if (above_centerline(tp->ptr())) {
6997         // If 'tp'  is above the centerline and it is Object class
6998         // then we can subclass in the Java class hierarchy.
6999         // For instances when a subclass meets a superclass we fall
7000         // below the centerline when the superclass is exact. We need
7001         // to do the same here.
7002         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
7003             !tp->klass_is_exact()) {
7004           // that is, my array type is a subtype of 'tp' klass
7005           return make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), is_flat(), is_null_free(), is_atomic(), is_refined_type());
7006         }
7007       }
7008       // The other case cannot happen, since t cannot be a subtype of an array.
7009       // The meet falls down to Object class below centerline.
7010       if (ptr == Constant)
7011          ptr = NotNull;
7012       interfaces = this_interfaces->intersection_with(tp_interfaces);
7013       return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
7014     default: typerr(t);
7015     }
7016   }
7017 
7018   } // End of switch
7019   return this;                  // Return the double constant
7020 }
7021 
7022 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) {
7023   static_assert(std::is_base_of<T2, T1>::value, "");
7024 
7025   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
7026     return true;
7027   }
7028 
7029   int dummy;
7030   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
7031 
7032   if (!this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
7033     return false;
7034   }
7035 
7036   if (this_one->is_instance_type(other)) {
7037     return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces) &&
7038            other_exact;
7039   }
7040 
7041   assert(this_one->is_array_type(other), "");
7042   const T1* other_ary = this_one->is_array_type(other);
7043   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
7044   if (other_top_or_bottom) {
7045     return false;
7046   }
7047 
7048   const TypePtr* other_elem = other_ary->elem()->make_ptr();
7049   const TypePtr* this_elem = this_one->elem()->make_ptr();
7050   if (this_elem != nullptr && other_elem != nullptr) {
7051     if (other->is_null_free() && !this_one->is_null_free()) {
7052       return false; // A nullable array can't be a subtype of a null-free array
7053     }
7054     return this_one->is_reference_type(this_elem)->is_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
7055   }
7056   if (this_elem == nullptr && other_elem == nullptr) {
7057     return this_one->klass()->is_subtype_of(other->klass());
7058   }
7059   return false;
7060 }
7061 
7062 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
7063   return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
7064 }
7065 
7066 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other) {
7067   static_assert(std::is_base_of<T2, T1>::value, "");
7068 
7069   int dummy;
7070   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
7071 
7072   if (!this_one->is_array_type(other) ||
7073       !this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
7074     return false;
7075   }
7076   const T1* other_ary = this_one->is_array_type(other);
7077   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
7078 
7079   if (other_top_or_bottom) {
7080     return false;
7081   }
7082 
7083   const TypePtr* other_elem = other_ary->elem()->make_ptr();
7084   const TypePtr* this_elem = this_one->elem()->make_ptr();
7085   if (other_elem != nullptr && this_elem != nullptr) {
7086     return this_one->is_reference_type(this_elem)->is_same_java_type_as(this_one->is_reference_type(other_elem));
7087   }
7088   if (other_elem == nullptr && this_elem == nullptr) {
7089     return this_one->klass()->equals(other->klass());
7090   }
7091   return false;
7092 }
7093 
7094 bool TypeAryKlassPtr::is_same_java_type_as_helper(const TypeKlassPtr* other) const {
7095   return TypePtr::is_same_java_type_as_helper_for_array(this, other);
7096 }
7097 
7098 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) {
7099   static_assert(std::is_base_of<T2, T1>::value, "");
7100   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
7101     return true;
7102   }
7103   if (!this_one->is_loaded() || !other->is_loaded()) {
7104     return true;
7105   }
7106   if (this_one->is_instance_type(other)) {
7107     return other->klass()->equals(ciEnv::current()->Object_klass()) &&
7108            this_one->_interfaces->contains(other->_interfaces);
7109   }
7110 
7111   int dummy;
7112   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
7113   if (this_top_or_bottom) {
7114     return true;
7115   }
7116 
7117   assert(this_one->is_array_type(other), "");
7118 
7119   const T1* other_ary = this_one->is_array_type(other);
7120   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
7121   if (other_top_or_bottom) {
7122     return true;
7123   }
7124   if (this_exact && other_exact) {
7125     return this_one->is_java_subtype_of(other);
7126   }
7127 
7128   const TypePtr* this_elem = this_one->elem()->make_ptr();
7129   const TypePtr* other_elem = other_ary->elem()->make_ptr();
7130   if (other_elem != nullptr && this_elem != nullptr) {
7131     return this_one->is_reference_type(this_elem)->maybe_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
7132   }
7133   if (other_elem == nullptr && this_elem == nullptr) {
7134     return this_one->klass()->is_subtype_of(other->klass());
7135   }
7136   return false;
7137 }
7138 
7139 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
7140   return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
7141 }
7142 
7143 //------------------------------xdual------------------------------------------
7144 // Dual: compute field-by-field dual
7145 const Type    *TypeAryKlassPtr::xdual() const {
7146   return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset(), !is_not_flat(), !is_not_null_free(), dual_flat(), dual_null_free(), dual_atomic(), _refined_type);
7147 }
7148 
7149 // Is there a single ciKlass* that can represent that type?
7150 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
7151   if (elem()->isa_klassptr()) {
7152     ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
7153     if (k == nullptr) {
7154       return nullptr;
7155     }
7156     k = ciArrayKlass::make(k, k->is_inlinetype() ? is_null_free() : false, k->is_inlinetype() ? is_atomic() : true, _refined_type);
7157     return k;
7158   }
7159 
7160   return klass();
7161 }
7162 
7163 ciKlass* TypeAryKlassPtr::klass() const {
7164   if (_klass != nullptr) {
7165     return _klass;
7166   }
7167   ciKlass* k = nullptr;
7168   if (elem()->isa_klassptr()) {
7169     // leave null
7170   } else if ((elem()->base() == Type::Top) ||
7171              (elem()->base() == Type::Bottom)) {
7172   } else {
7173     k = ciTypeArrayKlass::make(elem()->basic_type());
7174     ((TypeAryKlassPtr*)this)->_klass = k;
7175   }
7176   return k;
7177 }
7178 
7179 //------------------------------dump2------------------------------------------
7180 // Dump Klass Type
7181 #ifndef PRODUCT
7182 void TypeAryKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
7183   switch( _ptr ) {
7184   case Constant:
7185     st->print("precise ");
7186   case NotNull:
7187     {
7188       st->print("[");
7189       _elem->dump2(d, depth, st);
7190       _interfaces->dump(st);
7191       st->print(": ");
7192     }
7193   case BotPTR:
7194     if( !WizardMode && !Verbose && _ptr != Constant ) break;
7195   case TopPTR:
7196   case AnyNull:
7197     st->print(":%s", ptr_msg[_ptr]);
7198     if( _ptr == Constant ) st->print(":exact");
7199     break;
7200   default:
7201     break;
7202   }
7203   if (_flat) st->print(":flat");
7204   if (_null_free) st->print(":null free");
7205   if (_atomic) st->print(":atomic");
7206   if (_refined_type) st->print(":refined_type");
7207   if (Verbose) {
7208     if (_not_flat) st->print(":not flat");
7209     if (_not_null_free) st->print(":nullable");
7210   }
7211 
7212   _offset.dump2(st);
7213 
7214   st->print(" *");
7215 }
7216 #endif
7217 
7218 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
7219   const Type* elem = this->elem();
7220   dims = 1;
7221   while (elem->isa_aryklassptr()) {
7222     elem = elem->is_aryklassptr()->elem();
7223     dims++;
7224   }
7225   return elem;
7226 }
7227 
7228 //=============================================================================
7229 // Convenience common pre-built types.
7230 
7231 //------------------------------make-------------------------------------------
7232 const TypeFunc *TypeFunc::make(const TypeTuple *domain_sig, const TypeTuple* domain_cc,
7233                                const TypeTuple *range_sig, const TypeTuple *range_cc) {
7234   return (TypeFunc*)(new TypeFunc(domain_sig, domain_cc, range_sig, range_cc))->hashcons();
7235 }
7236 
7237 const TypeFunc *TypeFunc::make(const TypeTuple *domain, const TypeTuple *range) {
7238   return make(domain, domain, range, range);
7239 }
7240 
7241 //------------------------------osr_domain-----------------------------
7242 const TypeTuple* osr_domain() {
7243   const Type **fields = TypeTuple::fields(2);
7244   fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM;  // address of osr buffer
7245   return TypeTuple::make(TypeFunc::Parms+1, fields);
7246 }
7247 
7248 //------------------------------make-------------------------------------------
7249 const TypeFunc* TypeFunc::make(ciMethod* method, bool is_osr_compilation) {
7250   Compile* C = Compile::current();
7251   const TypeFunc* tf = nullptr;
7252   if (!is_osr_compilation) {
7253     tf = C->last_tf(method); // check cache
7254     if (tf != nullptr)  return tf;  // The hit rate here is almost 50%.
7255   }
7256   // Inline types are not passed/returned by reference, instead each field of
7257   // the inline type is passed/returned as an argument. We maintain two views of
7258   // the argument/return list here: one based on the signature (with an inline
7259   // type argument/return as a single slot), one based on the actual calling
7260   // convention (with an inline type argument/return as a list of its fields).
7261   bool has_scalar_args = method->has_scalarized_args() && !is_osr_compilation;
7262   // Fall back to the non-scalarized calling convention when compiling a call via a mismatching method
7263   if (method != C->method() && method->get_Method()->mismatch()) {
7264     has_scalar_args = false;
7265   }
7266   const TypeTuple* domain_sig = is_osr_compilation ? osr_domain() : TypeTuple::make_domain(method, ignore_interfaces, false);
7267   const TypeTuple* domain_cc = has_scalar_args ? TypeTuple::make_domain(method, ignore_interfaces, true) : domain_sig;
7268   ciSignature* sig = method->signature();
7269   bool has_scalar_ret = !method->is_native() && sig->return_type()->is_inlinetype() && sig->return_type()->as_inline_klass()->can_be_returned_as_fields();
7270   const TypeTuple* range_sig = TypeTuple::make_range(sig, ignore_interfaces, false);
7271   const TypeTuple* range_cc = has_scalar_ret ? TypeTuple::make_range(sig, ignore_interfaces, true) : range_sig;
7272   tf = TypeFunc::make(domain_sig, domain_cc, range_sig, range_cc);
7273   if (!is_osr_compilation) {
7274     C->set_last_tf(method, tf);  // fill cache
7275   }



7276   return tf;
7277 }
7278 
7279 //------------------------------meet-------------------------------------------
7280 // Compute the MEET of two types.  It returns a new Type object.
7281 const Type *TypeFunc::xmeet( const Type *t ) const {
7282   // Perform a fast test for common case; meeting the same types together.
7283   if( this == t ) return this;  // Meeting same type-rep?
7284 
7285   // Current "this->_base" is Func
7286   switch (t->base()) {          // switch on original type
7287 
7288   case Bottom:                  // Ye Olde Default
7289     return t;
7290 
7291   default:                      // All else is a mistake
7292     typerr(t);
7293 
7294   case Top:
7295     break;
7296   }
7297   return this;                  // Return the double constant
7298 }
7299 
7300 //------------------------------xdual------------------------------------------
7301 // Dual: compute field-by-field dual
7302 const Type *TypeFunc::xdual() const {
7303   return this;
7304 }
7305 
7306 //------------------------------eq---------------------------------------------
7307 // Structural equality check for Type representations
7308 bool TypeFunc::eq( const Type *t ) const {
7309   const TypeFunc *a = (const TypeFunc*)t;
7310   return _domain_sig == a->_domain_sig &&
7311     _domain_cc == a->_domain_cc &&
7312     _range_sig == a->_range_sig &&
7313     _range_cc == a->_range_cc;
7314 }
7315 
7316 //------------------------------hash-------------------------------------------
7317 // Type-specific hashing function.
7318 uint TypeFunc::hash(void) const {
7319   return (uint)(intptr_t)_domain_sig + (uint)(intptr_t)_domain_cc + (uint)(intptr_t)_range_sig + (uint)(intptr_t)_range_cc;
7320 }
7321 
7322 //------------------------------dump2------------------------------------------
7323 // Dump Function Type
7324 #ifndef PRODUCT
7325 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
7326   if( _range_sig->cnt() <= Parms )
7327     st->print("void");
7328   else {
7329     uint i;
7330     for (i = Parms; i < _range_sig->cnt()-1; i++) {
7331       _range_sig->field_at(i)->dump2(d,depth,st);
7332       st->print("/");
7333     }
7334     _range_sig->field_at(i)->dump2(d,depth,st);
7335   }
7336   st->print(" ");
7337   st->print("( ");
7338   if( !depth || d[this] ) {     // Check for recursive dump
7339     st->print("...)");
7340     return;
7341   }
7342   d.Insert((void*)this,(void*)this);    // Stop recursion
7343   if (Parms < _domain_sig->cnt())
7344     _domain_sig->field_at(Parms)->dump2(d,depth-1,st);
7345   for (uint i = Parms+1; i < _domain_sig->cnt(); i++) {
7346     st->print(", ");
7347     _domain_sig->field_at(i)->dump2(d,depth-1,st);
7348   }
7349   st->print(" )");
7350 }
7351 #endif
7352 
7353 //------------------------------singleton--------------------------------------
7354 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
7355 // constants (Ldi nodes).  Singletons are integer, float or double constants
7356 // or a single symbol.
7357 bool TypeFunc::singleton(void) const {
7358   return false;                 // Never a singleton
7359 }
7360 
7361 bool TypeFunc::empty(void) const {
7362   return false;                 // Never empty
7363 }
7364 
7365 
7366 BasicType TypeFunc::return_type() const{
7367   if (range_sig()->cnt() == TypeFunc::Parms) {
7368     return T_VOID;
7369   }
7370   return range_sig()->field_at(TypeFunc::Parms)->basic_type();
7371 }
--- EOF ---