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

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





2859 }
2860 
2861 //------------------------------dual_offset------------------------------------
2862 Type::Offset TypePtr::dual_offset() const {
2863   return _offset.dual();


2864 }
2865 
2866 //------------------------------xdual------------------------------------------
2867 // Dual: compute field-by-field dual
2868 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2869   BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2870 };
2871 
2872 const TypePtr::FlatInArray TypePtr::flat_in_array_dual[Uninitialized] = {
2873   /* TopFlat   -> */ MaybeFlat,
2874   /* Flat      -> */ NotFlat,
2875   /* NotFlat   -> */ Flat,
2876   /* MaybeFlat -> */ TopFlat
2877 };
2878 
2879 const char* const TypePtr::flat_in_array_msg[Uninitialized] = {
2880   "TOP flat in array", "flat in array", "not flat in array", "maybe flat in array"
2881 };
2882 
2883 const Type *TypePtr::xdual() const {
2884   return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
2885 }
2886 
2887 //------------------------------xadd_offset------------------------------------
2888 Type::Offset TypePtr::xadd_offset(intptr_t offset) const {
2889   return _offset.add(offset);











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






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

3732       if (this->isa_klassptr()) {
3733         // Perm objects don't use compressed references
3734       } else if (_offset == Offset::bottom || _offset == Offset::top) {
3735         // unsafe access
3736         _is_ptr_to_narrowoop = UseCompressedOops;
3737       } else {
3738         assert(this->isa_instptr(), "must be an instance ptr.");

3739         if (klass() == ciEnv::current()->Class_klass() &&
3740             (this->offset() == java_lang_Class::klass_offset() ||
3741              this->offset() == java_lang_Class::array_klass_offset())) {
3742           // Special hidden fields from the Class.
3743           assert(this->isa_instptr(), "must be an instance ptr.");
3744           _is_ptr_to_narrowoop = false;
3745         } else if (klass() == ciEnv::current()->Class_klass() &&
3746                    this->offset() >= InstanceMirrorKlass::offset_of_static_fields()) {
3747           // Static fields
3748           BasicType basic_elem_type = T_ILLEGAL;
3749           if (const_oop() != nullptr) {
3750             ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3751             basic_elem_type = k->get_field_type_by_offset(this->offset(), true);
3752           }
3753           if (basic_elem_type != T_ILLEGAL) {
3754             _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3755           } else {
3756             // unsafe access
3757             _is_ptr_to_narrowoop = UseCompressedOops;
3758           }
3759         } else {
3760           // Instance fields which contains a compressed oop references.
3761           ciInstanceKlass* ik = klass()->as_instance_klass();
3762           BasicType basic_elem_type = ik->get_field_type_by_offset(this->offset(), false);
3763           if (basic_elem_type != T_ILLEGAL) {
3764             _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3765           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3766             // Compile::find_alias_type() cast exactness on all types to verify
3767             // that it does not affect alias type.
3768             _is_ptr_to_narrowoop = UseCompressedOops;
3769           } else {
3770             // Type for the copy start in LibraryCallKit::inline_native_clone().
3771             _is_ptr_to_narrowoop = UseCompressedOops;
3772           }
3773         }
3774       }
3775     }
3776   }
3777 #endif // _LP64
3778 }
3779 
3780 //------------------------------make-------------------------------------------
3781 const TypeOopPtr *TypeOopPtr::make(PTR ptr, Offset offset, int instance_id,
3782                                    const TypePtr* speculative, int inline_depth) {
3783   assert(ptr != Constant, "no constant generic pointers");
3784   ciKlass*  k = Compile::current()->env()->Object_klass();
3785   bool      xk = false;
3786   ciObject* o = nullptr;
3787   const TypeInterfaces* interfaces = TypeInterfaces::make();
3788   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, interfaces, xk, o, offset, Offset::bottom, instance_id, speculative, inline_depth))->hashcons();
3789 }
3790 
3791 
3792 //------------------------------cast_to_ptr_type-------------------------------
3793 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3794   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3795   if( ptr == _ptr ) return this;
3796   return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3797 }
3798 
3799 //-----------------------------cast_to_instance_id----------------------------
3800 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3801   // There are no instances of a general oop.
3802   // Return self unchanged.
3803   return this;
3804 }
3805 
3806 //-----------------------------cast_to_exactness-------------------------------
3807 const TypeOopPtr* TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3808   // There is no such thing as an exact general oop.
3809   // Return self unchanged.
3810   return this;
3811 }
3812 

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

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

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

4671   const T* subtype = nullptr;
4672   bool subtype_exact = false;
4673   if (this_type->is_same_java_type_as(other_type)) {
4674     // Same klass
4675     subtype = this_type;
4676     subtype_exact = below_centerline(ptr) ? (this_xk && other_xk) : (this_xk || other_xk);
4677   } else if (!other_xk && this_type->is_meet_subtype_of(other_type)) {
4678     subtype = this_type;     // Pick subtyping class
4679     subtype_exact = this_xk;
4680   } else if (!this_xk && other_type->is_meet_subtype_of(this_type)) {
4681     subtype = other_type;    // Pick subtyping class
4682     subtype_exact = other_xk;
4683   }
4684 
4685   if (subtype != nullptr) {
4686     if (above_centerline(ptr)) {
4687       // Both types are empty.
4688       this_type = other_type = subtype;
4689       this_xk = other_xk = subtype_exact;
4690     } else if (above_centerline(this_ptr) && !above_centerline(other_ptr)) {
4691       // this_type is empty while other_type is not. Take other_type.
4692       this_type = other_type;
4693       this_xk = other_xk;
4694     } else if (above_centerline(other_ptr) && !above_centerline(this_ptr)) {
4695       // other_type is empty while this_type is not. Take this_type.
4696       other_type = this_type; // this is down; keep down man

4697     } else {
4698       // this_type and other_type are both non-empty.
4699       this_xk = subtype_exact;  // either they are equal, or we'll do an LCA
4700     }
4701   }
4702 
4703   // Check for classes now being equal
4704   if (this_type->is_same_java_type_as(other_type)) {
4705     // If the klasses are equal, the constants may still differ.  Fall to
4706     // NotNull if they do (neither constant is null; that is a special case
4707     // handled elsewhere).
4708     res_klass = this_type->klass();
4709     res_xk = this_xk;
4710     return SUBTYPE;
4711   } // Else classes are not equal
4712 
4713   // Since klasses are different, we require a LCA in the Java
4714   // class hierarchy - which means we have to fall to at least NotNull.
4715   if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4716     ptr = NotNull;
4717   }
4718 
4719   interfaces = this_interfaces->intersection_with(other_interfaces);
4720 
4721   // Now we find the LCA of Java classes
4722   ciKlass* k = this_klass->least_common_ancestor(other_klass);
4723 
4724   res_klass = k;
4725   res_xk = false;

4726   return LCA;
4727 }
4728 
4729 //                Top-Flat    Flat        Not-Flat    Maybe-Flat
4730 // -------------------------------------------------------------
4731 //    Top-Flat    Top-Flat    Flat        Not-Flat    Maybe-Flat
4732 //        Flat    Flat        Flat        Maybe-Flat  Maybe-Flat
4733 //    Not-Flat    Not-Flat    Maybe-Flat  Not-Flat    Maybe-Flat
4734 //  Maybe-Flat    Maybe-Flat  Maybe-Flat  Maybe-Flat  Maybe-flat
4735 TypePtr::FlatInArray TypePtr::meet_flat_in_array(const FlatInArray left, const FlatInArray right) {
4736   if (left == TopFlat) {
4737     return right;
4738   }
4739   if (right == TopFlat) {
4740     return left;
4741   }
4742   if (left == MaybeFlat || right == MaybeFlat) {
4743     return MaybeFlat;
4744   }
4745 
4746   switch (left) {
4747     case Flat:
4748       if (right == Flat) {
4749         return Flat;
4750       }
4751       return MaybeFlat;
4752     case NotFlat:
4753       if (right == NotFlat) {
4754         return NotFlat;
4755       }
4756       return MaybeFlat;
4757     default:
4758       ShouldNotReachHere();
4759       return Uninitialized;
4760   }
4761 }
4762 
4763 //------------------------java_mirror_type--------------------------------------
4764 ciType* TypeInstPtr::java_mirror_type() const {
4765   // must be a singleton type
4766   if( const_oop() == nullptr )  return nullptr;
4767 
4768   // must be of type java.lang.Class
4769   if( klass() != ciEnv::current()->Class_klass() )  return nullptr;

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

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

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










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

6343     klass_is_exact = ik->is_final();
6344     if (!klass_is_exact && klass_change
6345         && deps != nullptr && UseUniqueSubclasses) {
6346       ciInstanceKlass* sub = ik->unique_concrete_subklass();
6347       if (sub != nullptr) {
6348         if (_interfaces->eq(sub)) {
6349           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6350           k = ik = sub;
6351           xk = sub->is_final();
6352         }
6353       }
6354     }
6355   }
6356 
6357   FlatInArray flat_in_array = compute_flat_in_array_if_unknown(ik, xk, _flat_in_array);
6358   return TypeInstPtr::make(TypePtr::BotPTR, k, interfaces, xk, nullptr, Offset(0), flat_in_array);
6359 }
6360 
6361 //------------------------------xmeet------------------------------------------
6362 // Compute the MEET of two types, return a new Type object.
6363 const Type    *TypeInstKlassPtr::xmeet( const Type *t ) const {
6364   // Perform a fast test for common case; meeting the same types together.
6365   if( this == t ) return this;  // Meeting same type-rep?
6366 
6367   // Current "this->_base" is Pointer
6368   switch (t->base()) {          // switch on original type
6369 
6370   case Int:                     // Mixing ints & oops happens when javac
6371   case Long:                    // reuses local variables
6372   case HalfFloatTop:
6373   case HalfFloatCon:
6374   case HalfFloatBot:
6375   case FloatTop:
6376   case FloatCon:
6377   case FloatBot:
6378   case DoubleTop:
6379   case DoubleCon:
6380   case DoubleBot:
6381   case NarrowOop:
6382   case NarrowKlass:
6383   case Bottom:                  // Ye Olde Default
6384     return Type::BOTTOM;
6385   case Top:
6386     return this;
6387 
6388   default:                      // All else is a mistake
6389     typerr(t);
6390 
6391   case AnyPtr: {                // Meeting to AnyPtrs
6392     // Found an AnyPtr type vs self-KlassPtr type
6393     const TypePtr *tp = t->is_ptr();
6394     Offset offset = meet_offset(tp->offset());
6395     PTR ptr = meet_ptr(tp->ptr());
6396     switch (tp->ptr()) {
6397     case TopPTR:
6398       return this;
6399     case Null:
6400       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6401     case AnyNull:
6402       return make(ptr, klass(), _interfaces, offset, _flat_in_array);
6403     case BotPTR:
6404     case NotNull:
6405       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6406     default: typerr(t);
6407     }
6408   }
6409 
6410   case RawPtr:
6411   case MetadataPtr:
6412   case OopPtr:
6413   case AryPtr:                  // Meet with AryPtr
6414   case InstPtr:                 // Meet with InstPtr
6415       return TypePtr::BOTTOM;
6416 
6417   //
6418   //             A-top         }
6419   //           /   |   \       }  Tops
6420   //       B-top A-any C-top   }
6421   //          | /  |  \ |      }  Any-nulls
6422   //       B-any   |   C-any   }
6423   //          |    |    |
6424   //       B-con A-con C-con   } constants; not comparable across classes
6425   //          |    |    |
6426   //       B-not   |   C-not   }
6427   //          | \  |  / |      }  not-nulls
6428   //       B-bot A-not C-bot   }
6429   //           \   |   /       }  Bottoms
6430   //             A-bot         }
6431   //
6432 
6433   case InstKlassPtr: {  // Meet two KlassPtr types
6434     const TypeInstKlassPtr *tkls = t->is_instklassptr();
6435     Offset  off     = meet_offset(tkls->offset());
6436     PTR  ptr     = meet_ptr(tkls->ptr());
6437     const TypeInterfaces* interfaces = meet_interfaces(tkls);
6438 
6439     ciKlass* res_klass = nullptr;
6440     bool res_xk = false;
6441     const FlatInArray flat_in_array = meet_flat_in_array(_flat_in_array, tkls->flat_in_array());
6442     switch (meet_instptr(ptr, interfaces, this, tkls, res_klass, res_xk)) {
6443       case UNLOADED:
6444         ShouldNotReachHere();
6445       case SUBTYPE:
6446       case NOT_SUBTYPE:
6447       case LCA:
6448       case QUICK: {
6449         assert(res_xk == (ptr == Constant), "");
6450         const Type* res = make(ptr, res_klass, interfaces, off, flat_in_array);
6451         return res;
6452       }
6453       default:
6454         ShouldNotReachHere();
6455     }
6456   } // End of case KlassPtr
6457   case AryKlassPtr: {                // All arrays inherit from Object class
6458     const TypeAryKlassPtr *tp = t->is_aryklassptr();
6459     Offset offset = meet_offset(tp->offset());
6460     PTR ptr = meet_ptr(tp->ptr());
6461     const TypeInterfaces* interfaces = meet_interfaces(tp);
6462     const TypeInterfaces* tp_interfaces = tp->_interfaces;
6463     const TypeInterfaces* this_interfaces = _interfaces;
6464 
6465     switch (ptr) {
6466     case TopPTR:
6467     case AnyNull:                // Fall 'down' to dual of object klass
6468       // For instances when a subclass meets a superclass we fall
6469       // below the centerline when the superclass is exact. We need to
6470       // do the same here.
6471       //
6472       // Flat in array: See explanation for meet with TypeInstPtr in TypeAryPtr::xmeet_helper().
6473       if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) &&
6474           !klass_is_exact() && !is_not_flat_in_array()) {
6475         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());
6476       } else {
6477         // cannot subclass, so the meet has to fall badly below the centerline
6478         ptr = NotNull;
6479         interfaces = _interfaces->intersection_with(tp->_interfaces);
6480         FlatInArray flat_in_array = meet_flat_in_array(_flat_in_array, NotFlat);
6481         return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, flat_in_array);
6482       }
6483     case Constant:
6484     case NotNull:
6485     case BotPTR: { // Fall down to object klass
6486       // LCA is object_klass, but if we subclass from the top we can do better
6487       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
6488         // If 'this' (InstPtr) is above the centerline and it is Object class
6489         // then we can subclass in the Java class hierarchy.
6490         // For instances when a subclass meets a superclass we fall
6491         // below the centerline when the superclass is exact. We need
6492         // to do the same here.
6493         //
6494         // Flat in array: See explanation for meet with TypeInstPtr in TypeAryPtr::xmeet_helper().
6495         if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) &&
6496             !klass_is_exact() && !is_not_flat_in_array()) {
6497           // that is, tp's array type is a subtype of my klass
6498           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());

6499         }
6500       }
6501       // The other case cannot happen, since I cannot be a subtype of an array.
6502       // The meet falls down to Object class below centerline.
6503       if( ptr == Constant )
6504         ptr = NotNull;
6505       interfaces = this_interfaces->intersection_with(tp_interfaces);
6506       FlatInArray flat_in_array = meet_flat_in_array(_flat_in_array, NotFlat);
6507       return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, flat_in_array);
6508     }
6509     default: typerr(t);
6510     }
6511   }
6512 
6513   } // End of switch
6514   return this;                  // Return the double constant
6515 }
6516 
6517 //------------------------------xdual------------------------------------------
6518 // Dual: compute field-by-field dual
6519 const Type* TypeInstKlassPtr::xdual() const {
6520   return new TypeInstKlassPtr(dual_ptr(), klass(), _interfaces, dual_offset(), dual_flat_in_array());
6521 }
6522 
6523 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) {
6524   static_assert(std::is_base_of<T2, T1>::value, "");
6525   if (!this_one->is_loaded() || !other->is_loaded()) {
6526     return false;
6527   }
6528   if (!this_one->is_instance_type(other)) {
6529     return false;
6530   }
6531 
6532   if (!other_exact) {
6533     return false;
6534   }
6535 
6536   if (other->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces->empty()) {
6537     return true;
6538   }
6539 
6540   return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);
6541 }
6542 
6543 bool TypeInstKlassPtr::might_be_an_array() const {
6544   if (!instance_klass()->is_java_lang_Object()) {
6545     // TypeInstKlassPtr can be an array only if it is java.lang.Object: the only supertype of array types.
6546     return false;
6547   }
6548   if (interfaces()->has_non_array_interface()) {
6549     // Arrays only implement Cloneable and Serializable. If we see any other interface, [this] cannot be an array.
6550     return false;
6551   }
6552   // Cannot prove it's not an array.
6553   return true;
6554 }
6555 
6556 bool TypeInstKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6557   return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
6558 }
6559 
6560 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_instance(const T1* this_one, const T2* other) {
6561   static_assert(std::is_base_of<T2, T1>::value, "");
6562   if (!this_one->is_loaded() || !other->is_loaded()) {
6563     return false;
6564   }
6565   if (!this_one->is_instance_type(other)) {
6566     return false;
6567   }
6568   return this_one->klass()->equals(other->klass()) && this_one->_interfaces->eq(other->_interfaces);
6569 }
6570 
6571 bool TypeInstKlassPtr::is_same_java_type_as_helper(const TypeKlassPtr* other) const {
6572   return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
6573 }
6574 
6575 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) {
6576   static_assert(std::is_base_of<T2, T1>::value, "");
6577   if (!this_one->is_loaded() || !other->is_loaded()) {
6578     return true;
6579   }
6580 
6581   if (this_one->is_array_type(other)) {
6582     return !this_exact && this_one->klass()->equals(ciEnv::current()->Object_klass())  && other->_interfaces->contains(this_one->_interfaces);
6583   }
6584 
6585   assert(this_one->is_instance_type(other), "unsupported");
6586 
6587   if (this_exact && other_exact) {
6588     return this_one->is_java_subtype_of(other);
6589   }
6590 
6591   if (!this_one->klass()->is_subtype_of(other->klass()) && !other->klass()->is_subtype_of(this_one->klass())) {
6592     return false;
6593   }
6594 
6595   if (this_exact) {
6596     return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);
6597   }
6598 
6599   return true;
6600 }
6601 
6602 bool TypeInstKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6603   return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
6604 }
6605 
6606 const TypeKlassPtr* TypeInstKlassPtr::try_improve() const {
6607   if (!UseUniqueSubclasses) {
6608     return this;
6609   }
6610   ciKlass* k = klass();
6611   Compile* C = Compile::current();
6612   Dependencies* deps = C->dependencies();
6613   assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");

6614   if (k->is_loaded()) {
6615     ciInstanceKlass* ik = k->as_instance_klass();
6616     if (deps != nullptr) {


6617       ciInstanceKlass* sub = ik->unique_concrete_subklass();
6618       if (sub != nullptr) {
6619         bool improve_to_exact = sub->is_final() && _ptr == NotNull;
6620         const TypeInstKlassPtr* improved = TypeInstKlassPtr::make(improve_to_exact ? Constant : _ptr, sub, _offset);
6621         if (improved->_interfaces->contains(_interfaces)) {
6622           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6623           return improved;


6624         }
6625       }
6626     }
6627   }
6628   return this;
6629 }
6630 
6631 bool TypeInstKlassPtr::can_be_inline_array() const {
6632   return _klass->equals(ciEnv::current()->Object_klass()) && TypeAryKlassPtr::_array_interfaces->contains(_interfaces);
6633 }
6634 
6635 #ifndef PRODUCT
6636 void TypeInstKlassPtr::dump2(Dict& d, uint depth, outputStream* st) const {
6637   st->print("instklassptr:");
6638   klass()->print_name_on(st);
6639   _interfaces->dump(st);
6640   st->print(":%s", ptr_msg[_ptr]);
6641   dump_offset(st);
6642   dump_flat_in_array(_flat_in_array, st);
6643 }
6644 #endif // PRODUCT
6645 
6646 bool TypeAryKlassPtr::can_be_inline_array() const {
6647   return _elem->isa_instklassptr() && _elem->is_instklassptr()->_klass->can_be_inline_klass();
6648 }
6649 
6650 bool TypeInstPtr::can_be_inline_array() const {
6651   return _klass->equals(ciEnv::current()->Object_klass()) && TypeAryPtr::_array_interfaces->contains(_interfaces);
6652 }
6653 
6654 bool TypeAryPtr::can_be_inline_array() const {
6655   return elem()->make_ptr() && elem()->make_ptr()->isa_instptr() && elem()->make_ptr()->is_instptr()->_klass->can_be_inline_klass();
6656 }
6657 
6658 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) {
6659   return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset, not_flat, not_null_free, flat, null_free, atomic, refined_type))->hashcons();
6660 }
6661 
6662 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) {
6663   const Type* etype;
6664   if (k->is_obj_array_klass()) {
6665     // Element is an object array. Recursively call ourself.
6666     ciKlass* eklass = k->as_obj_array_klass()->element_klass();
6667     etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6668     k = nullptr;
6669   } else if (k->is_type_array_klass()) {
6670     // Element is an typeArray
6671     etype = get_const_basic_type(k->as_type_array_klass()->element_type());

6672   } else {
6673     ShouldNotReachHere();

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


6865 
6866   if (klass_is_exact) {
6867     // cast_to_exactness(true) really means get the LCA of all values represented by this
6868     // TypeAryKlassPtr. As a result, it must be an unrefined klass pointer.
6869     return make(Constant, elem, nullptr, _offset, true, true, false, false, true, false);
6870   } else {
6871     // cast_to_exactness(false) means get the TypeAryKlassPtr representing all values that subtype
6872     // this value
6873     bool not_inline = !_elem->isa_instklassptr() || !_elem->is_instklassptr()->instance_klass()->can_be_inline_klass();
6874     bool not_flat = !UseArrayFlattening || not_inline ||
6875                     (_elem->isa_instklassptr() && _elem->is_instklassptr()->instance_klass()->is_inlinetype() && !_elem->is_instklassptr()->instance_klass()->maybe_flat_in_array());
6876     bool not_null_free = not_inline;
6877     bool atomic = not_flat;
6878     return make(NotNull, elem, nullptr, _offset, not_flat, not_null_free, false, false, atomic, false);
6879   }
6880 }
6881 
6882 //-----------------------------as_instance_type--------------------------------
6883 // Corresponding type for an instance of the given class.
6884 // It will be NotNull, and exact if and only if the klass type is exact.
6885 const TypeOopPtr* TypeAryKlassPtr::as_instance_type(bool klass_change) const {
6886   ciKlass* k = klass();
6887   bool    xk = klass_is_exact();
6888   const Type* el = nullptr;
6889   if (elem()->isa_klassptr()) {
6890     el = elem()->is_klassptr()->as_instance_type(false)->cast_to_exactness(false);
6891     k = nullptr;
6892   } else {
6893     el = elem();
6894   }
6895   bool null_free = _null_free;
6896   if (null_free && el->isa_ptr()) {
6897     el = el->is_ptr()->join_speculative(TypePtr::NOTNULL);
6898   }
6899   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));
6900 }
6901 
6902 
6903 //------------------------------xmeet------------------------------------------
6904 // Compute the MEET of two types, return a new Type object.
6905 const Type    *TypeAryKlassPtr::xmeet( const Type *t ) const {
6906   // Perform a fast test for common case; meeting the same types together.
6907   if( this == t ) return this;  // Meeting same type-rep?
6908 
6909   // Current "this->_base" is Pointer
6910   switch (t->base()) {          // switch on original type
6911 
6912   case Int:                     // Mixing ints & oops happens when javac
6913   case Long:                    // reuses local variables
6914   case HalfFloatTop:
6915   case HalfFloatCon:
6916   case HalfFloatBot:
6917   case FloatTop:
6918   case FloatCon:
6919   case FloatBot:
6920   case DoubleTop:
6921   case DoubleCon:
6922   case DoubleBot:
6923   case NarrowOop:
6924   case NarrowKlass:
6925   case Bottom:                  // Ye Olde Default
6926     return Type::BOTTOM;
6927   case Top:
6928     return this;
6929 
6930   default:                      // All else is a mistake
6931     typerr(t);
6932 
6933   case AnyPtr: {                // Meeting to AnyPtrs
6934     // Found an AnyPtr type vs self-KlassPtr type
6935     const TypePtr *tp = t->is_ptr();
6936     Offset offset = meet_offset(tp->offset());
6937     PTR ptr = meet_ptr(tp->ptr());
6938     switch (tp->ptr()) {
6939     case TopPTR:
6940       return this;
6941     case Null:
6942       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6943     case AnyNull:
6944       return make(ptr, _elem, klass(), offset, is_not_flat(), is_not_null_free(), is_flat(), is_null_free(), is_atomic(), is_refined_type());
6945     case BotPTR:
6946     case NotNull:
6947       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6948     default: typerr(t);
6949     }
6950   }
6951 
6952   case RawPtr:
6953   case MetadataPtr:
6954   case OopPtr:
6955   case AryPtr:                  // Meet with AryPtr
6956   case InstPtr:                 // Meet with InstPtr
6957     return TypePtr::BOTTOM;
6958 
6959   //
6960   //             A-top         }
6961   //           /   |   \       }  Tops
6962   //       B-top A-any C-top   }
6963   //          | /  |  \ |      }  Any-nulls
6964   //       B-any   |   C-any   }
6965   //          |    |    |
6966   //       B-con A-con C-con   } constants; not comparable across classes
6967   //          |    |    |
6968   //       B-not   |   C-not   }
6969   //          | \  |  / |      }  not-nulls
6970   //       B-bot A-not C-bot   }
6971   //           \   |   /       }  Bottoms
6972   //             A-bot         }
6973   //
6974 
6975   case AryKlassPtr: {  // Meet two KlassPtr types
6976     const TypeAryKlassPtr *tap = t->is_aryklassptr();
6977     Offset off = meet_offset(tap->offset());
6978     const Type* elem = _elem->meet(tap->_elem);

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



7319   return tf;
7320 }
7321 
7322 //------------------------------meet-------------------------------------------
7323 // Compute the MEET of two types.  It returns a new Type object.
7324 const Type *TypeFunc::xmeet( const Type *t ) const {
7325   // Perform a fast test for common case; meeting the same types together.
7326   if( this == t ) return this;  // Meeting same type-rep?
7327 
7328   // Current "this->_base" is Func
7329   switch (t->base()) {          // switch on original type
7330 
7331   case Bottom:                  // Ye Olde Default
7332     return t;
7333 
7334   default:                      // All else is a mistake
7335     typerr(t);
7336 
7337   case Top:
7338     break;
7339   }
7340   return this;                  // Return the double constant
7341 }
7342 
7343 //------------------------------xdual------------------------------------------
7344 // Dual: compute field-by-field dual
7345 const Type *TypeFunc::xdual() const {
7346   return this;
7347 }
7348 
7349 //------------------------------eq---------------------------------------------
7350 // Structural equality check for Type representations
7351 bool TypeFunc::eq( const Type *t ) const {
7352   const TypeFunc *a = (const TypeFunc*)t;
7353   return _domain_sig == a->_domain_sig &&
7354     _domain_cc == a->_domain_cc &&
7355     _range_sig == a->_range_sig &&
7356     _range_cc == a->_range_cc;
7357 }
7358 
7359 //------------------------------hash-------------------------------------------
7360 // Type-specific hashing function.
7361 uint TypeFunc::hash(void) const {
7362   return (uint)(intptr_t)_domain_sig + (uint)(intptr_t)_domain_cc + (uint)(intptr_t)_range_sig + (uint)(intptr_t)_range_cc;
7363 }
7364 
7365 //------------------------------dump2------------------------------------------
7366 // Dump Function Type
7367 #ifndef PRODUCT
7368 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
7369   if( _range_sig->cnt() <= Parms )
7370     st->print("void");
7371   else {
7372     uint i;
7373     for (i = Parms; i < _range_sig->cnt()-1; i++) {
7374       _range_sig->field_at(i)->dump2(d,depth,st);
7375       st->print("/");
7376     }
7377     _range_sig->field_at(i)->dump2(d,depth,st);
7378   }
7379   st->print(" ");
7380   st->print("( ");
7381   if( !depth || d[this] ) {     // Check for recursive dump
7382     st->print("...)");
7383     return;
7384   }
7385   d.Insert((void*)this,(void*)this);    // Stop recursion
7386   if (Parms < _domain_sig->cnt())
7387     _domain_sig->field_at(Parms)->dump2(d,depth-1,st);
7388   for (uint i = Parms+1; i < _domain_sig->cnt(); i++) {
7389     st->print(", ");
7390     _domain_sig->field_at(i)->dump2(d,depth-1,st);
7391   }
7392   st->print(" )");
7393 }
7394 #endif
7395 
7396 //------------------------------singleton--------------------------------------
7397 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
7398 // constants (Ldi nodes).  Singletons are integer, float or double constants
7399 // or a single symbol.
7400 bool TypeFunc::singleton(void) const {
7401   return false;                 // Never a singleton
7402 }
7403 
7404 bool TypeFunc::empty(void) const {
7405   return false;                 // Never empty
7406 }
7407 
7408 
7409 BasicType TypeFunc::return_type() const{
7410   if (range_sig()->cnt() == TypeFunc::Parms) {
7411     return T_VOID;
7412   }
7413   return range_sig()->field_at(TypeFunc::Parms)->basic_type();
7414 }
--- EOF ---