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