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