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