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