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->with_speculative(speculative); }
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->with_speculative(speculative); }
4186     else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
4187       if (unloaded->ptr() == TypePtr::BotPTR)    { return TypeInstPtr::BOTTOM->with_speculative(speculative);  }
4188       else                                       { return TypeInstPtr::NOTNULL->with_speculative(speculative); }
4189     }
4190     else if (unloaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); }
4191 
4192     return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr()->with_speculative(speculative);
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->with_speculative(speculative);
4199   }
4200   return TypeInstPtr::BOTTOM->with_speculative(speculative);
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 TypeInstPtr* TypeInstPtr::with_speculative(const TypePtr* speculative) const {
4604   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _instance_id, speculative, _inline_depth);
4605 }
4606 
4607 const TypePtr* TypeInstPtr::with_inline_depth(int depth) const {
4608   if (!UseInlineDepthForSpeculativeTypes) {
4609     return this;
4610   }
4611   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth);
4612 }
4613 
4614 const TypePtr* TypeInstPtr::with_instance_id(int instance_id) const {
4615   assert(is_known_instance(), "should be known");
4616   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, instance_id, _speculative, _inline_depth);
4617 }
4618 
4619 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4620   bool xk = klass_is_exact();
4621   ciInstanceKlass* ik = klass()->as_instance_klass();
4622   if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final()) {
4623     if (_interfaces->eq(ik)) {
4624       Compile* C = Compile::current();
4625       Dependencies* deps = C->dependencies();
4626       deps->assert_leaf_type(ik);
4627       xk = true;
4628     }
4629   }
4630   return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), _interfaces, 0);
4631 }
4632 
4633 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) {
4634   static_assert(std::is_base_of<T2, T1>::value, "");
4635 
4636   if (!this_one->is_instance_type(other)) {
4637     return false;
4638   }
4639 
4640   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4641     return true;
4642   }
4643 
4644   return this_one->klass()->is_subtype_of(other->klass()) &&
4645          (!this_xk || this_one->_interfaces->contains(other->_interfaces));
4646 }
4647 
4648 
4649 bool TypeInstPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4650   return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4651 }
4652 
4653 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) {
4654   static_assert(std::is_base_of<T2, T1>::value, "");
4655   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4656     return true;
4657   }
4658 
4659   if (this_one->is_instance_type(other)) {
4660     return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces);
4661   }
4662 
4663   int dummy;
4664   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
4665   if (this_top_or_bottom) {
4666     return false;
4667   }
4668 
4669   const T1* other_ary = this_one->is_array_type(other);
4670   const TypePtr* other_elem = other_ary->elem()->make_ptr();
4671   const TypePtr* this_elem = this_one->elem()->make_ptr();
4672   if (other_elem != nullptr && this_elem != nullptr) {
4673     return this_one->is_reference_type(this_elem)->is_meet_subtype_of_helper(this_one->is_reference_type(other_elem), this_xk, other_xk);
4674   }
4675 
4676   if (other_elem == nullptr && this_elem == nullptr) {
4677     return this_one->klass()->is_subtype_of(other->klass());
4678   }
4679 
4680   return false;
4681 }
4682 
4683 bool TypeAryPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4684   return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4685 }
4686 
4687 bool TypeInstKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4688   return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4689 }
4690 
4691 bool TypeAryKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4692   return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4693 }
4694 
4695 //=============================================================================
4696 // Convenience common pre-built types.
4697 const TypeAryPtr *TypeAryPtr::RANGE;
4698 const TypeAryPtr *TypeAryPtr::OOPS;
4699 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
4700 const TypeAryPtr *TypeAryPtr::BYTES;
4701 const TypeAryPtr *TypeAryPtr::SHORTS;
4702 const TypeAryPtr *TypeAryPtr::CHARS;
4703 const TypeAryPtr *TypeAryPtr::INTS;
4704 const TypeAryPtr *TypeAryPtr::LONGS;
4705 const TypeAryPtr *TypeAryPtr::FLOATS;
4706 const TypeAryPtr *TypeAryPtr::DOUBLES;
4707 
4708 //------------------------------make-------------------------------------------
4709 const TypeAryPtr *TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4710                                    int instance_id, const TypePtr* speculative, int inline_depth) {
4711   assert(!(k == nullptr && ary->_elem->isa_int()),
4712          "integral arrays must be pre-equipped with a class");
4713   if (!xk)  xk = ary->ary_must_be_exact();
4714   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4715   if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4716       k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4717     k = nullptr;
4718   }
4719   return (TypeAryPtr*)(new TypeAryPtr(ptr, nullptr, ary, k, xk, offset, instance_id, false, speculative, inline_depth))->hashcons();
4720 }
4721 
4722 //------------------------------make-------------------------------------------
4723 const TypeAryPtr *TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4724                                    int instance_id, const TypePtr* speculative, int inline_depth,
4725                                    bool is_autobox_cache) {
4726   assert(!(k == nullptr && ary->_elem->isa_int()),
4727          "integral arrays must be pre-equipped with a class");
4728   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4729   if (!xk)  xk = (o != nullptr) || ary->ary_must_be_exact();
4730   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4731   if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4732       k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4733     k = nullptr;
4734   }
4735   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4736 }
4737 
4738 //------------------------------cast_to_ptr_type-------------------------------
4739 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4740   if( ptr == _ptr ) return this;
4741   return make(ptr, ptr == Constant ? const_oop() : nullptr, _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4742 }
4743 
4744 
4745 //-----------------------------cast_to_exactness-------------------------------
4746 const TypeAryPtr* TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4747   if( klass_is_exact == _klass_is_exact ) return this;
4748   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
4749   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
4750 }
4751 
4752 //-----------------------------cast_to_instance_id----------------------------
4753 const TypeAryPtr* TypeAryPtr::cast_to_instance_id(int instance_id) const {
4754   if( instance_id == _instance_id ) return this;
4755   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
4756 }
4757 
4758 
4759 //-----------------------------max_array_length-------------------------------
4760 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
4761 jint TypeAryPtr::max_array_length(BasicType etype) {
4762   if (!is_java_primitive(etype) && !::is_reference_type(etype)) {
4763     if (etype == T_NARROWOOP) {
4764       etype = T_OBJECT;
4765     } else if (etype == T_ILLEGAL) { // bottom[]
4766       etype = T_BYTE; // will produce conservatively high value
4767     } else {
4768       fatal("not an element type: %s", type2name(etype));
4769     }
4770   }
4771   return arrayOopDesc::max_array_length(etype);
4772 }
4773 
4774 //-----------------------------narrow_size_type-------------------------------
4775 // Narrow the given size type to the index range for the given array base type.
4776 // Return null if the resulting int type becomes empty.
4777 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const {
4778   jint hi = size->_hi;
4779   jint lo = size->_lo;
4780   jint min_lo = 0;
4781   jint max_hi = max_array_length(elem()->array_element_basic_type());
4782   //if (index_not_size)  --max_hi;     // type of a valid array index, FTR
4783   bool chg = false;
4784   if (lo < min_lo) {
4785     lo = min_lo;
4786     if (size->is_con()) {
4787       hi = lo;
4788     }
4789     chg = true;
4790   }
4791   if (hi > max_hi) {
4792     hi = max_hi;
4793     if (size->is_con()) {
4794       lo = hi;
4795     }
4796     chg = true;
4797   }
4798   // Negative length arrays will produce weird intermediate dead fast-path code
4799   if (lo > hi)
4800     return TypeInt::ZERO;
4801   if (!chg)
4802     return size;
4803   return TypeInt::make(lo, hi, Type::WidenMin);
4804 }
4805 
4806 //-------------------------------cast_to_size----------------------------------
4807 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4808   assert(new_size != nullptr, "");
4809   new_size = narrow_size_type(new_size);
4810   if (new_size == size())  return this;
4811   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
4812   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4813 }
4814 
4815 //------------------------------cast_to_stable---------------------------------
4816 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
4817   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
4818     return this;
4819 
4820   const Type* elem = this->elem();
4821   const TypePtr* elem_ptr = elem->make_ptr();
4822 
4823   if (stable_dimension > 1 && elem_ptr != nullptr && elem_ptr->isa_aryptr()) {
4824     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
4825     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
4826   }
4827 
4828   const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
4829 
4830   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4831 }
4832 
4833 //-----------------------------stable_dimension--------------------------------
4834 int TypeAryPtr::stable_dimension() const {
4835   if (!is_stable())  return 0;
4836   int dim = 1;
4837   const TypePtr* elem_ptr = elem()->make_ptr();
4838   if (elem_ptr != nullptr && elem_ptr->isa_aryptr())
4839     dim += elem_ptr->is_aryptr()->stable_dimension();
4840   return dim;
4841 }
4842 
4843 //----------------------cast_to_autobox_cache-----------------------------------
4844 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
4845   if (is_autobox_cache())  return this;
4846   const TypeOopPtr* etype = elem()->make_oopptr();
4847   if (etype == nullptr)  return this;
4848   // The pointers in the autobox arrays are always non-null.
4849   etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
4850   const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable());
4851   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
4852 }
4853 
4854 //------------------------------eq---------------------------------------------
4855 // Structural equality check for Type representations
4856 bool TypeAryPtr::eq( const Type *t ) const {
4857   const TypeAryPtr *p = t->is_aryptr();
4858   return
4859     _ary == p->_ary &&  // Check array
4860     TypeOopPtr::eq(p);  // Check sub-parts
4861 }
4862 
4863 //------------------------------hash-------------------------------------------
4864 // Type-specific hashing function.
4865 uint TypeAryPtr::hash(void) const {
4866   return (uint)(uintptr_t)_ary + TypeOopPtr::hash();
4867 }
4868 
4869 bool TypeAryPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4870   return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
4871 }
4872 
4873 bool TypeAryPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4874   return TypePtr::is_same_java_type_as_helper_for_array(this, other);
4875 }
4876 
4877 bool TypeAryPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4878   return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
4879 }
4880 //------------------------------meet-------------------------------------------
4881 // Compute the MEET of two types.  It returns a new Type object.
4882 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
4883   // Perform a fast test for common case; meeting the same types together.
4884   if( this == t ) return this;  // Meeting same type-rep?
4885   // Current "this->_base" is Pointer
4886   switch (t->base()) {          // switch on original type
4887 
4888   // Mixing ints & oops happens when javac reuses local variables
4889   case Int:
4890   case Long:
4891   case FloatTop:
4892   case FloatCon:
4893   case FloatBot:
4894   case DoubleTop:
4895   case DoubleCon:
4896   case DoubleBot:
4897   case NarrowOop:
4898   case NarrowKlass:
4899   case Bottom:                  // Ye Olde Default
4900     return Type::BOTTOM;
4901   case Top:
4902     return this;
4903 
4904   default:                      // All else is a mistake
4905     typerr(t);
4906 
4907   case OopPtr: {                // Meeting to OopPtrs
4908     // Found a OopPtr type vs self-AryPtr type
4909     const TypeOopPtr *tp = t->is_oopptr();
4910     int offset = meet_offset(tp->offset());
4911     PTR ptr = meet_ptr(tp->ptr());
4912     int depth = meet_inline_depth(tp->inline_depth());
4913     const TypePtr* speculative = xmeet_speculative(tp);
4914     switch (tp->ptr()) {
4915     case TopPTR:
4916     case AnyNull: {
4917       int instance_id = meet_instance_id(InstanceTop);
4918       return make(ptr, (ptr == Constant ? const_oop() : nullptr),
4919                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4920     }
4921     case BotPTR:
4922     case NotNull: {
4923       int instance_id = meet_instance_id(tp->instance_id());
4924       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4925     }
4926     default: ShouldNotReachHere();
4927     }
4928   }
4929 
4930   case AnyPtr: {                // Meeting two AnyPtrs
4931     // Found an AnyPtr type vs self-AryPtr type
4932     const TypePtr *tp = t->is_ptr();
4933     int offset = meet_offset(tp->offset());
4934     PTR ptr = meet_ptr(tp->ptr());
4935     const TypePtr* speculative = xmeet_speculative(tp);
4936     int depth = meet_inline_depth(tp->inline_depth());
4937     switch (tp->ptr()) {
4938     case TopPTR:
4939       return this;
4940     case BotPTR:
4941     case NotNull:
4942       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4943     case Null:
4944       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4945       // else fall through to AnyNull
4946     case AnyNull: {
4947       int instance_id = meet_instance_id(InstanceTop);
4948       return make(ptr, (ptr == Constant ? const_oop() : nullptr),
4949                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4950     }
4951     default: ShouldNotReachHere();
4952     }
4953   }
4954 
4955   case MetadataPtr:
4956   case KlassPtr:
4957   case InstKlassPtr:
4958   case AryKlassPtr:
4959   case RawPtr: return TypePtr::BOTTOM;
4960 
4961   case AryPtr: {                // Meeting 2 references?
4962     const TypeAryPtr *tap = t->is_aryptr();
4963     int off = meet_offset(tap->offset());
4964     const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
4965     PTR ptr = meet_ptr(tap->ptr());
4966     int instance_id = meet_instance_id(tap->instance_id());
4967     const TypePtr* speculative = xmeet_speculative(tap);
4968     int depth = meet_inline_depth(tap->inline_depth());
4969 
4970     ciKlass* res_klass = nullptr;
4971     bool res_xk = false;
4972     const Type* elem = tary->_elem;
4973     if (meet_aryptr(ptr, elem, this, tap, res_klass, res_xk) == NOT_SUBTYPE) {
4974       instance_id = InstanceBot;
4975     }
4976 
4977     ciObject* o = nullptr;             // Assume not constant when done
4978     ciObject* this_oop = const_oop();
4979     ciObject* tap_oop = tap->const_oop();
4980     if (ptr == Constant) {
4981       if (this_oop != nullptr && tap_oop != nullptr &&
4982           this_oop->equals(tap_oop)) {
4983         o = tap_oop;
4984       } else if (above_centerline(_ptr)) {
4985         o = tap_oop;
4986       } else if (above_centerline(tap->_ptr)) {
4987         o = this_oop;
4988       } else {
4989         ptr = NotNull;
4990       }
4991     }
4992     return make(ptr, o, TypeAry::make(elem, tary->_size, tary->_stable), res_klass, res_xk, off, instance_id, speculative, depth);
4993   }
4994 
4995   // All arrays inherit from Object class
4996   case InstPtr: {
4997     const TypeInstPtr *tp = t->is_instptr();
4998     int offset = meet_offset(tp->offset());
4999     PTR ptr = meet_ptr(tp->ptr());
5000     int instance_id = meet_instance_id(tp->instance_id());
5001     const TypePtr* speculative = xmeet_speculative(tp);
5002     int depth = meet_inline_depth(tp->inline_depth());
5003     const TypeInterfaces* interfaces = meet_interfaces(tp);
5004     const TypeInterfaces* tp_interfaces = tp->_interfaces;
5005     const TypeInterfaces* this_interfaces = _interfaces;
5006 
5007     switch (ptr) {
5008     case TopPTR:
5009     case AnyNull:                // Fall 'down' to dual of object klass
5010       // For instances when a subclass meets a superclass we fall
5011       // below the centerline when the superclass is exact. We need to
5012       // do the same here.
5013       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact()) {
5014         return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
5015       } else {
5016         // cannot subclass, so the meet has to fall badly below the centerline
5017         ptr = NotNull;
5018         instance_id = InstanceBot;
5019         interfaces = this_interfaces->intersection_with(tp_interfaces);
5020         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr,offset, instance_id, speculative, depth);
5021       }
5022     case Constant:
5023     case NotNull:
5024     case BotPTR:                // Fall down to object klass
5025       // LCA is object_klass, but if we subclass from the top we can do better
5026       if (above_centerline(tp->ptr())) {
5027         // If 'tp'  is above the centerline and it is Object class
5028         // then we can subclass in the Java class hierarchy.
5029         // For instances when a subclass meets a superclass we fall
5030         // below the centerline when the superclass is exact. We need
5031         // to do the same here.
5032         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact()) {
5033           // that is, my array type is a subtype of 'tp' klass
5034           return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5035                       _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
5036         }
5037       }
5038       // The other case cannot happen, since t cannot be a subtype of an array.
5039       // The meet falls down to Object class below centerline.
5040       if (ptr == Constant) {
5041          ptr = NotNull;
5042       }
5043       if (instance_id > 0) {
5044         instance_id = InstanceBot;
5045       }
5046       interfaces = this_interfaces->intersection_with(tp_interfaces);
5047       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset, instance_id, speculative, depth);
5048     default: typerr(t);
5049     }
5050   }
5051   }
5052   return this;                  // Lint noise
5053 }
5054 
5055 
5056 template<class T> TypePtr::MeetResult TypePtr::meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary,
5057                                                            const T* other_ary, ciKlass*& res_klass, bool& res_xk) {
5058   int dummy;
5059   bool this_top_or_bottom = (this_ary->base_element_type(dummy) == Type::TOP || this_ary->base_element_type(dummy) == Type::BOTTOM);
5060   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
5061   ciKlass* this_klass = this_ary->klass();
5062   ciKlass* other_klass = other_ary->klass();
5063   bool this_xk = this_ary->klass_is_exact();
5064   bool other_xk = other_ary->klass_is_exact();
5065   PTR this_ptr = this_ary->ptr();
5066   PTR other_ptr = other_ary->ptr();
5067   res_klass = nullptr;
5068   MeetResult result = SUBTYPE;
5069   if (elem->isa_int()) {
5070     // Integral array element types have irrelevant lattice relations.
5071     // It is the klass that determines array layout, not the element type.
5072     if (this_top_or_bottom)
5073       res_klass = other_klass;
5074     else if (other_top_or_bottom || other_klass == this_klass) {
5075       res_klass = this_klass;
5076     } else {
5077       // Something like byte[int+] meets char[int+].
5078       // This must fall to bottom, not (int[-128..65535])[int+].
5079       // instance_id = InstanceBot;
5080       elem = Type::BOTTOM;
5081       result = NOT_SUBTYPE;
5082       if (above_centerline(ptr) || ptr == Constant) {
5083         ptr = NotNull;
5084         res_xk = false;
5085         return NOT_SUBTYPE;
5086       }
5087     }
5088   } else {// Non integral arrays.
5089     // Must fall to bottom if exact klasses in upper lattice
5090     // are not equal or super klass is exact.
5091     if ((above_centerline(ptr) || ptr == Constant) && !this_ary->is_same_java_type_as(other_ary) &&
5092         // meet with top[] and bottom[] are processed further down:
5093         !this_top_or_bottom && !other_top_or_bottom &&
5094         // both are exact and not equal:
5095         ((other_xk && this_xk) ||
5096          // 'tap'  is exact and super or unrelated:
5097          (other_xk && !other_ary->is_meet_subtype_of(this_ary)) ||
5098          // 'this' is exact and super or unrelated:
5099          (this_xk && !this_ary->is_meet_subtype_of(other_ary)))) {
5100       if (above_centerline(ptr) || (elem->make_ptr() && above_centerline(elem->make_ptr()->_ptr))) {
5101         elem = Type::BOTTOM;
5102       }
5103       ptr = NotNull;
5104       res_xk = false;
5105       return NOT_SUBTYPE;
5106     }
5107   }
5108 
5109   res_xk = false;
5110   switch (other_ptr) {
5111     case AnyNull:
5112     case TopPTR:
5113       // Compute new klass on demand, do not use tap->_klass
5114       if (below_centerline(this_ptr)) {
5115         res_xk = this_xk;
5116       } else {
5117         res_xk = (other_xk || this_xk);
5118       }
5119       return result;
5120     case Constant: {
5121       if (this_ptr == Constant) {
5122         res_xk = true;
5123       } else if(above_centerline(this_ptr)) {
5124         res_xk = true;
5125       } else {
5126         // Only precise for identical arrays
5127         res_xk = this_xk && (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom));
5128       }
5129       return result;
5130     }
5131     case NotNull:
5132     case BotPTR:
5133       // Compute new klass on demand, do not use tap->_klass
5134       if (above_centerline(this_ptr)) {
5135         res_xk = other_xk;
5136       } else {
5137         res_xk = (other_xk && this_xk) &&
5138                  (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom)); // Only precise for identical arrays
5139       }
5140       return result;
5141     default:  {
5142       ShouldNotReachHere();
5143       return result;
5144     }
5145   }
5146   return result;
5147 }
5148 
5149 
5150 //------------------------------xdual------------------------------------------
5151 // Dual: compute field-by-field dual
5152 const Type *TypeAryPtr::xdual() const {
5153   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());
5154 }
5155 
5156 //------------------------------dump2------------------------------------------
5157 #ifndef PRODUCT
5158 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5159   _ary->dump2(d,depth,st);
5160   _interfaces->dump(st);
5161 
5162   switch( _ptr ) {
5163   case Constant:
5164     const_oop()->print(st);
5165     break;
5166   case BotPTR:
5167     if (!WizardMode && !Verbose) {
5168       if( _klass_is_exact ) st->print(":exact");
5169       break;
5170     }
5171   case TopPTR:
5172   case AnyNull:
5173   case NotNull:
5174     st->print(":%s", ptr_msg[_ptr]);
5175     if( _klass_is_exact ) st->print(":exact");
5176     break;
5177   default:
5178     break;
5179   }
5180 
5181   if( _offset != 0 ) {
5182     BasicType basic_elem_type = elem()->basic_type();
5183     int header_size = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5184     if( _offset == OffsetTop )       st->print("+undefined");
5185     else if( _offset == OffsetBot )  st->print("+any");
5186     else if( _offset < header_size ) st->print("+%d", _offset);
5187     else {
5188       if (basic_elem_type == T_ILLEGAL) {
5189         st->print("+any");
5190       } else {
5191         int elem_size = type2aelembytes(basic_elem_type);
5192         st->print("[%d]", (_offset - header_size)/elem_size);
5193       }
5194     }
5195   }
5196   st->print(" *");
5197   if (_instance_id == InstanceTop)
5198     st->print(",iid=top");
5199   else if (_instance_id != InstanceBot)
5200     st->print(",iid=%d",_instance_id);
5201 
5202   dump_inline_depth(st);
5203   dump_speculative(st);
5204 }
5205 #endif
5206 
5207 bool TypeAryPtr::empty(void) const {
5208   if (_ary->empty())       return true;
5209   return TypeOopPtr::empty();
5210 }
5211 
5212 //------------------------------add_offset-------------------------------------
5213 const TypePtr* TypeAryPtr::add_offset(intptr_t offset) const {
5214   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
5215 }
5216 
5217 const TypeAryPtr* TypeAryPtr::with_offset(intptr_t offset) const {
5218   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, offset, _instance_id, with_offset_speculative(offset), _inline_depth);
5219 }
5220 
5221 const TypeAryPtr* TypeAryPtr::with_ary(const TypeAry* ary) const {
5222   return make(_ptr, _const_oop, ary, _klass, _klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
5223 }
5224 
5225 const TypeAryPtr* TypeAryPtr::remove_speculative() const {
5226   if (_speculative == nullptr) {
5227     return this;
5228   }
5229   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
5230   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, nullptr, _inline_depth);
5231 }
5232 
5233 const TypePtr* TypeAryPtr::with_inline_depth(int depth) const {
5234   if (!UseInlineDepthForSpeculativeTypes) {
5235     return this;
5236   }
5237   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, _speculative, depth);
5238 }
5239 
5240 const TypePtr* TypeAryPtr::with_instance_id(int instance_id) const {
5241   assert(is_known_instance(), "should be known");
5242   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
5243 }
5244 
5245 //=============================================================================
5246 
5247 //------------------------------hash-------------------------------------------
5248 // Type-specific hashing function.
5249 uint TypeNarrowPtr::hash(void) const {
5250   return _ptrtype->hash() + 7;
5251 }
5252 
5253 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
5254   return _ptrtype->singleton();
5255 }
5256 
5257 bool TypeNarrowPtr::empty(void) const {
5258   return _ptrtype->empty();
5259 }
5260 
5261 intptr_t TypeNarrowPtr::get_con() const {
5262   return _ptrtype->get_con();
5263 }
5264 
5265 bool TypeNarrowPtr::eq( const Type *t ) const {
5266   const TypeNarrowPtr* tc = isa_same_narrowptr(t);
5267   if (tc != nullptr) {
5268     if (_ptrtype->base() != tc->_ptrtype->base()) {
5269       return false;
5270     }
5271     return tc->_ptrtype->eq(_ptrtype);
5272   }
5273   return false;
5274 }
5275 
5276 const Type *TypeNarrowPtr::xdual() const {    // Compute dual right now.
5277   const TypePtr* odual = _ptrtype->dual()->is_ptr();
5278   return make_same_narrowptr(odual);
5279 }
5280 
5281 
5282 const Type *TypeNarrowPtr::filter_helper(const Type *kills, bool include_speculative) const {
5283   if (isa_same_narrowptr(kills)) {
5284     const Type* ft =_ptrtype->filter_helper(is_same_narrowptr(kills)->_ptrtype, include_speculative);
5285     if (ft->empty())
5286       return Type::TOP;           // Canonical empty value
5287     if (ft->isa_ptr()) {
5288       return make_hash_same_narrowptr(ft->isa_ptr());
5289     }
5290     return ft;
5291   } else if (kills->isa_ptr()) {
5292     const Type* ft = _ptrtype->join_helper(kills, include_speculative);
5293     if (ft->empty())
5294       return Type::TOP;           // Canonical empty value
5295     return ft;
5296   } else {
5297     return Type::TOP;
5298   }
5299 }
5300 
5301 //------------------------------xmeet------------------------------------------
5302 // Compute the MEET of two types.  It returns a new Type object.
5303 const Type *TypeNarrowPtr::xmeet( const Type *t ) const {
5304   // Perform a fast test for common case; meeting the same types together.
5305   if( this == t ) return this;  // Meeting same type-rep?
5306 
5307   if (t->base() == base()) {
5308     const Type* result = _ptrtype->xmeet(t->make_ptr());
5309     if (result->isa_ptr()) {
5310       return make_hash_same_narrowptr(result->is_ptr());
5311     }
5312     return result;
5313   }
5314 
5315   // Current "this->_base" is NarrowKlass or NarrowOop
5316   switch (t->base()) {          // switch on original type
5317 
5318   case Int:                     // Mixing ints & oops happens when javac
5319   case Long:                    // reuses local variables
5320   case FloatTop:
5321   case FloatCon:
5322   case FloatBot:
5323   case DoubleTop:
5324   case DoubleCon:
5325   case DoubleBot:
5326   case AnyPtr:
5327   case RawPtr:
5328   case OopPtr:
5329   case InstPtr:
5330   case AryPtr:
5331   case MetadataPtr:
5332   case KlassPtr:
5333   case InstKlassPtr:
5334   case AryKlassPtr:
5335   case NarrowOop:
5336   case NarrowKlass:
5337 
5338   case Bottom:                  // Ye Olde Default
5339     return Type::BOTTOM;
5340   case Top:
5341     return this;
5342 
5343   default:                      // All else is a mistake
5344     typerr(t);
5345 
5346   } // End of switch
5347 
5348   return this;
5349 }
5350 
5351 #ifndef PRODUCT
5352 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5353   _ptrtype->dump2(d, depth, st);
5354 }
5355 #endif
5356 
5357 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
5358 const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
5359 
5360 
5361 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
5362   return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();
5363 }
5364 
5365 const TypeNarrowOop* TypeNarrowOop::remove_speculative() const {
5366   return make(_ptrtype->remove_speculative()->is_ptr());
5367 }
5368 
5369 const Type* TypeNarrowOop::cleanup_speculative() const {
5370   return make(_ptrtype->cleanup_speculative()->is_ptr());
5371 }
5372 
5373 #ifndef PRODUCT
5374 void TypeNarrowOop::dump2( Dict & d, uint depth, outputStream *st ) const {
5375   st->print("narrowoop: ");
5376   TypeNarrowPtr::dump2(d, depth, st);
5377 }
5378 #endif
5379 
5380 const TypeNarrowKlass *TypeNarrowKlass::NULL_PTR;
5381 
5382 const TypeNarrowKlass* TypeNarrowKlass::make(const TypePtr* type) {
5383   return (const TypeNarrowKlass*)(new TypeNarrowKlass(type))->hashcons();
5384 }
5385 
5386 #ifndef PRODUCT
5387 void TypeNarrowKlass::dump2( Dict & d, uint depth, outputStream *st ) const {
5388   st->print("narrowklass: ");
5389   TypeNarrowPtr::dump2(d, depth, st);
5390 }
5391 #endif
5392 
5393 
5394 //------------------------------eq---------------------------------------------
5395 // Structural equality check for Type representations
5396 bool TypeMetadataPtr::eq( const Type *t ) const {
5397   const TypeMetadataPtr *a = (const TypeMetadataPtr*)t;
5398   ciMetadata* one = metadata();
5399   ciMetadata* two = a->metadata();
5400   if (one == nullptr || two == nullptr) {
5401     return (one == two) && TypePtr::eq(t);
5402   } else {
5403     return one->equals(two) && TypePtr::eq(t);
5404   }
5405 }
5406 
5407 //------------------------------hash-------------------------------------------
5408 // Type-specific hashing function.
5409 uint TypeMetadataPtr::hash(void) const {
5410   return
5411     (metadata() ? metadata()->hash() : 0) +
5412     TypePtr::hash();
5413 }
5414 
5415 //------------------------------singleton--------------------------------------
5416 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5417 // constants
5418 bool TypeMetadataPtr::singleton(void) const {
5419   // detune optimizer to not generate constant metadata + constant offset as a constant!
5420   // TopPTR, Null, AnyNull, Constant are all singletons
5421   return (_offset == 0) && !below_centerline(_ptr);
5422 }
5423 
5424 //------------------------------add_offset-------------------------------------
5425 const TypePtr* TypeMetadataPtr::add_offset( intptr_t offset ) const {
5426   return make( _ptr, _metadata, xadd_offset(offset));
5427 }
5428 
5429 //-----------------------------filter------------------------------------------
5430 // Do not allow interface-vs.-noninterface joins to collapse to top.
5431 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
5432   const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
5433   if (ft == nullptr || ft->empty())
5434     return Type::TOP;           // Canonical empty value
5435   return ft;
5436 }
5437 
5438  //------------------------------get_con----------------------------------------
5439 intptr_t TypeMetadataPtr::get_con() const {
5440   assert( _ptr == Null || _ptr == Constant, "" );
5441   assert( _offset >= 0, "" );
5442 
5443   if (_offset != 0) {
5444     // After being ported to the compiler interface, the compiler no longer
5445     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5446     // to a handle at compile time.  This handle is embedded in the generated
5447     // code and dereferenced at the time the nmethod is made.  Until that time,
5448     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5449     // have access to the addresses!).  This does not seem to currently happen,
5450     // but this assertion here is to help prevent its occurrence.
5451     tty->print_cr("Found oop constant with non-zero offset");
5452     ShouldNotReachHere();
5453   }
5454 
5455   return (intptr_t)metadata()->constant_encoding();
5456 }
5457 
5458 //------------------------------cast_to_ptr_type-------------------------------
5459 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
5460   if( ptr == _ptr ) return this;
5461   return make(ptr, metadata(), _offset);
5462 }
5463 
5464 //------------------------------meet-------------------------------------------
5465 // Compute the MEET of two types.  It returns a new Type object.
5466 const Type *TypeMetadataPtr::xmeet( const Type *t ) const {
5467   // Perform a fast test for common case; meeting the same types together.
5468   if( this == t ) return this;  // Meeting same type-rep?
5469 
5470   // Current "this->_base" is OopPtr
5471   switch (t->base()) {          // switch on original type
5472 
5473   case Int:                     // Mixing ints & oops happens when javac
5474   case Long:                    // reuses local variables
5475   case FloatTop:
5476   case FloatCon:
5477   case FloatBot:
5478   case DoubleTop:
5479   case DoubleCon:
5480   case DoubleBot:
5481   case NarrowOop:
5482   case NarrowKlass:
5483   case Bottom:                  // Ye Olde Default
5484     return Type::BOTTOM;
5485   case Top:
5486     return this;
5487 
5488   default:                      // All else is a mistake
5489     typerr(t);
5490 
5491   case AnyPtr: {
5492     // Found an AnyPtr type vs self-OopPtr type
5493     const TypePtr *tp = t->is_ptr();
5494     int offset = meet_offset(tp->offset());
5495     PTR ptr = meet_ptr(tp->ptr());
5496     switch (tp->ptr()) {
5497     case Null:
5498       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5499       // else fall through:
5500     case TopPTR:
5501     case AnyNull: {
5502       return make(ptr, _metadata, offset);
5503     }
5504     case BotPTR:
5505     case NotNull:
5506       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5507     default: typerr(t);
5508     }
5509   }
5510 
5511   case RawPtr:
5512   case KlassPtr:
5513   case InstKlassPtr:
5514   case AryKlassPtr:
5515   case OopPtr:
5516   case InstPtr:
5517   case AryPtr:
5518     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
5519 
5520   case MetadataPtr: {
5521     const TypeMetadataPtr *tp = t->is_metadataptr();
5522     int offset = meet_offset(tp->offset());
5523     PTR tptr = tp->ptr();
5524     PTR ptr = meet_ptr(tptr);
5525     ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
5526     if (tptr == TopPTR || _ptr == TopPTR ||
5527         metadata()->equals(tp->metadata())) {
5528       return make(ptr, md, offset);
5529     }
5530     // metadata is different
5531     if( ptr == Constant ) {  // Cannot be equal constants, so...
5532       if( tptr == Constant && _ptr != Constant)  return t;
5533       if( _ptr == Constant && tptr != Constant)  return this;
5534       ptr = NotNull;            // Fall down in lattice
5535     }
5536     return make(ptr, nullptr, offset);
5537     break;
5538   }
5539   } // End of switch
5540   return this;                  // Return the double constant
5541 }
5542 
5543 
5544 //------------------------------xdual------------------------------------------
5545 // Dual of a pure metadata pointer.
5546 const Type *TypeMetadataPtr::xdual() const {
5547   return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
5548 }
5549 
5550 //------------------------------dump2------------------------------------------
5551 #ifndef PRODUCT
5552 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5553   st->print("metadataptr:%s", ptr_msg[_ptr]);
5554   if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata()));
5555   switch( _offset ) {
5556   case OffsetTop: st->print("+top"); break;
5557   case OffsetBot: st->print("+any"); break;
5558   case         0: break;
5559   default:        st->print("+%d",_offset); break;
5560   }
5561 }
5562 #endif
5563 
5564 
5565 //=============================================================================
5566 // Convenience common pre-built type.
5567 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
5568 
5569 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset):
5570   TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
5571 }
5572 
5573 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
5574   return make(Constant, m, 0);
5575 }
5576 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
5577   return make(Constant, m, 0);
5578 }
5579 
5580 //------------------------------make-------------------------------------------
5581 // Create a meta data constant
5582 const TypeMetadataPtr *TypeMetadataPtr::make(PTR ptr, ciMetadata* m, int offset) {
5583   assert(m == nullptr || !m->is_klass(), "wrong type");
5584   return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
5585 }
5586 
5587 
5588 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
5589   const Type* elem = _ary->_elem;
5590   bool xk = klass_is_exact();
5591   if (elem->make_oopptr() != nullptr) {
5592     elem = elem->make_oopptr()->as_klass_type(try_for_exact);
5593     if (elem->is_klassptr()->klass_is_exact()) {
5594       xk = true;
5595     }
5596   }
5597   return TypeAryKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, elem, klass(), 0);
5598 }
5599 
5600 const TypeKlassPtr* TypeKlassPtr::make(ciKlass *klass, InterfaceHandling interface_handling) {
5601   if (klass->is_instance_klass()) {
5602     return TypeInstKlassPtr::make(klass, interface_handling);
5603   }
5604   return TypeAryKlassPtr::make(klass, interface_handling);
5605 }
5606 
5607 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* klass, int offset, InterfaceHandling interface_handling) {
5608   if (klass->is_instance_klass()) {
5609     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
5610     return TypeInstKlassPtr::make(ptr, klass, interfaces, offset);
5611   }
5612   return TypeAryKlassPtr::make(ptr, klass, offset, interface_handling);
5613 }
5614 
5615 
5616 //------------------------------TypeKlassPtr-----------------------------------
5617 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, int offset)
5618   : TypePtr(t, ptr, offset), _klass(klass), _interfaces(interfaces) {
5619   assert(klass == nullptr || !klass->is_loaded() || (klass->is_instance_klass() && !klass->is_interface()) ||
5620          klass->is_type_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "no interface here");
5621 }
5622 
5623 // Is there a single ciKlass* that can represent that type?
5624 ciKlass* TypeKlassPtr::exact_klass_helper() const {
5625   assert(_klass->is_instance_klass() && !_klass->is_interface(), "No interface");
5626   if (_interfaces->empty()) {
5627     return _klass;
5628   }
5629   if (_klass != ciEnv::current()->Object_klass()) {
5630     if (_interfaces->eq(_klass->as_instance_klass())) {
5631       return _klass;
5632     }
5633     return nullptr;
5634   }
5635   return _interfaces->exact_klass();
5636 }
5637 
5638 //------------------------------eq---------------------------------------------
5639 // Structural equality check for Type representations
5640 bool TypeKlassPtr::eq(const Type *t) const {
5641   const TypeKlassPtr *p = t->is_klassptr();
5642   return
5643     _interfaces->eq(p->_interfaces) &&
5644     TypePtr::eq(p);
5645 }
5646 
5647 //------------------------------hash-------------------------------------------
5648 // Type-specific hashing function.
5649 uint TypeKlassPtr::hash(void) const {
5650   return TypePtr::hash() + _interfaces->hash();
5651 }
5652 
5653 //------------------------------singleton--------------------------------------
5654 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5655 // constants
5656 bool TypeKlassPtr::singleton(void) const {
5657   // detune optimizer to not generate constant klass + constant offset as a constant!
5658   // TopPTR, Null, AnyNull, Constant are all singletons
5659   return (_offset == 0) && !below_centerline(_ptr);
5660 }
5661 
5662 // Do not allow interface-vs.-noninterface joins to collapse to top.
5663 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
5664   // logic here mirrors the one from TypeOopPtr::filter. See comments
5665   // there.
5666   const Type* ft = join_helper(kills, include_speculative);
5667   const TypeKlassPtr* ftkp = ft->isa_instklassptr();
5668   const TypeKlassPtr* ktkp = kills->isa_instklassptr();
5669 
5670   if (ft->empty()) {
5671     return Type::TOP;           // Canonical empty value
5672   }
5673 
5674   return ft;
5675 }
5676 
5677 const TypeInterfaces* TypeKlassPtr::meet_interfaces(const TypeKlassPtr* other) const {
5678   if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
5679     return _interfaces->union_with(other->_interfaces);
5680   } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
5681     return other->_interfaces;
5682   } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
5683     return _interfaces;
5684   }
5685   return _interfaces->intersection_with(other->_interfaces);
5686 }
5687 
5688 //------------------------------get_con----------------------------------------
5689 intptr_t TypeKlassPtr::get_con() const {
5690   assert( _ptr == Null || _ptr == Constant, "" );
5691   assert( _offset >= 0, "" );
5692 
5693   if (_offset != 0) {
5694     // After being ported to the compiler interface, the compiler no longer
5695     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5696     // to a handle at compile time.  This handle is embedded in the generated
5697     // code and dereferenced at the time the nmethod is made.  Until that time,
5698     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5699     // have access to the addresses!).  This does not seem to currently happen,
5700     // but this assertion here is to help prevent its occurrence.
5701     tty->print_cr("Found oop constant with non-zero offset");
5702     ShouldNotReachHere();
5703   }
5704 
5705   ciKlass* k = exact_klass();
5706 
5707   return (intptr_t)k->constant_encoding();
5708 }
5709 
5710 //------------------------------dump2------------------------------------------
5711 // Dump Klass Type
5712 #ifndef PRODUCT
5713 void TypeKlassPtr::dump2(Dict & d, uint depth, outputStream *st) const {
5714   switch(_ptr) {
5715   case Constant:
5716     st->print("precise ");
5717   case NotNull:
5718     {
5719       const char *name = klass()->name()->as_utf8();
5720       if (name) {
5721         st->print("%s: " INTPTR_FORMAT, name, p2i(klass()));
5722       } else {
5723         ShouldNotReachHere();
5724       }
5725       _interfaces->dump(st);
5726     }
5727   case BotPTR:
5728     if (!WizardMode && !Verbose && _ptr != Constant) break;
5729   case TopPTR:
5730   case AnyNull:
5731     st->print(":%s", ptr_msg[_ptr]);
5732     if (_ptr == Constant) st->print(":exact");
5733     break;
5734   default:
5735     break;
5736   }
5737 
5738   if (_offset) {               // Dump offset, if any
5739     if (_offset == OffsetBot)      { st->print("+any"); }
5740     else if (_offset == OffsetTop) { st->print("+unknown"); }
5741     else                            { st->print("+%d", _offset); }
5742   }
5743 
5744   st->print(" *");
5745 }
5746 #endif
5747 
5748 //=============================================================================
5749 // Convenience common pre-built types.
5750 
5751 // Not-null object klass or below
5752 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
5753 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
5754 
5755 bool TypeInstKlassPtr::eq(const Type *t) const {
5756   const TypeKlassPtr *p = t->is_klassptr();
5757   return
5758     klass()->equals(p->klass()) &&
5759     TypeKlassPtr::eq(p);
5760 }
5761 
5762 uint TypeInstKlassPtr::hash(void) const {
5763   return klass()->hash() + TypeKlassPtr::hash();
5764 }
5765 
5766 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, int offset) {
5767   TypeInstKlassPtr *r =
5768     (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, interfaces, offset))->hashcons();
5769 
5770   return r;
5771 }
5772 
5773 //------------------------------add_offset-------------------------------------
5774 // Access internals of klass object
5775 const TypePtr* TypeInstKlassPtr::add_offset( intptr_t offset ) const {
5776   return make( _ptr, klass(), _interfaces, xadd_offset(offset) );
5777 }
5778 
5779 const TypeInstKlassPtr* TypeInstKlassPtr::with_offset(intptr_t offset) const {
5780   return make(_ptr, klass(), _interfaces, offset);
5781 }
5782 
5783 //------------------------------cast_to_ptr_type-------------------------------
5784 const TypeInstKlassPtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
5785   assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
5786   if( ptr == _ptr ) return this;
5787   return make(ptr, _klass, _interfaces, _offset);
5788 }
5789 
5790 
5791 bool TypeInstKlassPtr::must_be_exact() const {
5792   if (!_klass->is_loaded())  return false;
5793   ciInstanceKlass* ik = _klass->as_instance_klass();
5794   if (ik->is_final())  return true;  // cannot clear xk
5795   return false;
5796 }
5797 
5798 //-----------------------------cast_to_exactness-------------------------------
5799 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
5800   if (klass_is_exact == (_ptr == Constant)) return this;
5801   if (must_be_exact()) return this;
5802   ciKlass* k = klass();
5803   return make(klass_is_exact ? Constant : NotNull, k, _interfaces, _offset);
5804 }
5805 
5806 
5807 //-----------------------------as_instance_type--------------------------------
5808 // Corresponding type for an instance of the given class.
5809 // It will be NotNull, and exact if and only if the klass type is exact.
5810 const TypeOopPtr* TypeInstKlassPtr::as_instance_type(bool klass_change) const {
5811   ciKlass* k = klass();
5812   bool xk = klass_is_exact();
5813   Compile* C = Compile::current();
5814   Dependencies* deps = C->dependencies();
5815   assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
5816   // Element is an instance
5817   bool klass_is_exact = false;
5818   const TypeInterfaces* interfaces = _interfaces;
5819   if (k->is_loaded()) {
5820     // Try to set klass_is_exact.
5821     ciInstanceKlass* ik = k->as_instance_klass();
5822     klass_is_exact = ik->is_final();
5823     if (!klass_is_exact && klass_change
5824         && deps != nullptr && UseUniqueSubclasses) {
5825       ciInstanceKlass* sub = ik->unique_concrete_subklass();
5826       if (sub != nullptr) {
5827         if (_interfaces->eq(sub)) {
5828           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
5829           k = ik = sub;
5830           xk = sub->is_final();
5831         }
5832       }
5833     }
5834   }
5835   return TypeInstPtr::make(TypePtr::BotPTR, k, interfaces, xk, nullptr, 0);
5836 }
5837 
5838 //------------------------------xmeet------------------------------------------
5839 // Compute the MEET of two types, return a new Type object.
5840 const Type    *TypeInstKlassPtr::xmeet( const Type *t ) const {
5841   // Perform a fast test for common case; meeting the same types together.
5842   if( this == t ) return this;  // Meeting same type-rep?
5843 
5844   // Current "this->_base" is Pointer
5845   switch (t->base()) {          // switch on original type
5846 
5847   case Int:                     // Mixing ints & oops happens when javac
5848   case Long:                    // reuses local variables
5849   case FloatTop:
5850   case FloatCon:
5851   case FloatBot:
5852   case DoubleTop:
5853   case DoubleCon:
5854   case DoubleBot:
5855   case NarrowOop:
5856   case NarrowKlass:
5857   case Bottom:                  // Ye Olde Default
5858     return Type::BOTTOM;
5859   case Top:
5860     return this;
5861 
5862   default:                      // All else is a mistake
5863     typerr(t);
5864 
5865   case AnyPtr: {                // Meeting to AnyPtrs
5866     // Found an AnyPtr type vs self-KlassPtr type
5867     const TypePtr *tp = t->is_ptr();
5868     int offset = meet_offset(tp->offset());
5869     PTR ptr = meet_ptr(tp->ptr());
5870     switch (tp->ptr()) {
5871     case TopPTR:
5872       return this;
5873     case Null:
5874       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5875     case AnyNull:
5876       return make( ptr, klass(), _interfaces, offset );
5877     case BotPTR:
5878     case NotNull:
5879       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5880     default: typerr(t);
5881     }
5882   }
5883 
5884   case RawPtr:
5885   case MetadataPtr:
5886   case OopPtr:
5887   case AryPtr:                  // Meet with AryPtr
5888   case InstPtr:                 // Meet with InstPtr
5889     return TypePtr::BOTTOM;
5890 
5891   //
5892   //             A-top         }
5893   //           /   |   \       }  Tops
5894   //       B-top A-any C-top   }
5895   //          | /  |  \ |      }  Any-nulls
5896   //       B-any   |   C-any   }
5897   //          |    |    |
5898   //       B-con A-con C-con   } constants; not comparable across classes
5899   //          |    |    |
5900   //       B-not   |   C-not   }
5901   //          | \  |  / |      }  not-nulls
5902   //       B-bot A-not C-bot   }
5903   //           \   |   /       }  Bottoms
5904   //             A-bot         }
5905   //
5906 
5907   case InstKlassPtr: {  // Meet two KlassPtr types
5908     const TypeInstKlassPtr *tkls = t->is_instklassptr();
5909     int  off     = meet_offset(tkls->offset());
5910     PTR  ptr     = meet_ptr(tkls->ptr());
5911     const TypeInterfaces* interfaces = meet_interfaces(tkls);
5912 
5913     ciKlass* res_klass = nullptr;
5914     bool res_xk = false;
5915     switch(meet_instptr(ptr, interfaces, this, tkls, res_klass, res_xk)) {
5916       case UNLOADED:
5917         ShouldNotReachHere();
5918       case SUBTYPE:
5919       case NOT_SUBTYPE:
5920       case LCA:
5921       case QUICK: {
5922         assert(res_xk == (ptr == Constant), "");
5923         const Type* res = make(ptr, res_klass, interfaces, off);
5924         return res;
5925       }
5926       default:
5927         ShouldNotReachHere();
5928     }
5929   } // End of case KlassPtr
5930   case AryKlassPtr: {                // All arrays inherit from Object class
5931     const TypeAryKlassPtr *tp = t->is_aryklassptr();
5932     int offset = meet_offset(tp->offset());
5933     PTR ptr = meet_ptr(tp->ptr());
5934     const TypeInterfaces* interfaces = meet_interfaces(tp);
5935     const TypeInterfaces* tp_interfaces = tp->_interfaces;
5936     const TypeInterfaces* this_interfaces = _interfaces;
5937 
5938     switch (ptr) {
5939     case TopPTR:
5940     case AnyNull:                // Fall 'down' to dual of object klass
5941       // For instances when a subclass meets a superclass we fall
5942       // below the centerline when the superclass is exact. We need to
5943       // do the same here.
5944       if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
5945         return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset);
5946       } else {
5947         // cannot subclass, so the meet has to fall badly below the centerline
5948         ptr = NotNull;
5949         interfaces = _interfaces->intersection_with(tp->_interfaces);
5950         return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
5951       }
5952     case Constant:
5953     case NotNull:
5954     case BotPTR:                // Fall down to object klass
5955       // LCA is object_klass, but if we subclass from the top we can do better
5956       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
5957         // If 'this' (InstPtr) is above the centerline and it is Object class
5958         // then we can subclass in the Java class hierarchy.
5959         // For instances when a subclass meets a superclass we fall
5960         // below the centerline when the superclass is exact. We need
5961         // to do the same here.
5962         if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
5963           // that is, tp's array type is a subtype of my klass
5964           return TypeAryKlassPtr::make(ptr,
5965                                        tp->elem(), tp->klass(), offset);
5966         }
5967       }
5968       // The other case cannot happen, since I cannot be a subtype of an array.
5969       // The meet falls down to Object class below centerline.
5970       if( ptr == Constant )
5971          ptr = NotNull;
5972       interfaces = this_interfaces->intersection_with(tp_interfaces);
5973       return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
5974     default: typerr(t);
5975     }
5976   }
5977 
5978   } // End of switch
5979   return this;                  // Return the double constant
5980 }
5981 
5982 //------------------------------xdual------------------------------------------
5983 // Dual: compute field-by-field dual
5984 const Type    *TypeInstKlassPtr::xdual() const {
5985   return new TypeInstKlassPtr(dual_ptr(), klass(), _interfaces, dual_offset());
5986 }
5987 
5988 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) {
5989   static_assert(std::is_base_of<T2, T1>::value, "");
5990   if (!this_one->is_loaded() || !other->is_loaded()) {
5991     return false;
5992   }
5993   if (!this_one->is_instance_type(other)) {
5994     return false;
5995   }
5996 
5997   if (!other_exact) {
5998     return false;
5999   }
6000 
6001   if (other->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces->empty()) {
6002     return true;
6003   }
6004 
6005   return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);
6006 }
6007 
6008 bool TypeInstKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6009   return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
6010 }
6011 
6012 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_instance(const T1* this_one, const T2* other) {
6013   static_assert(std::is_base_of<T2, T1>::value, "");
6014   if (!this_one->is_loaded() || !other->is_loaded()) {
6015     return false;
6016   }
6017   if (!this_one->is_instance_type(other)) {
6018     return false;
6019   }
6020   return this_one->klass()->equals(other->klass()) && this_one->_interfaces->eq(other->_interfaces);
6021 }
6022 
6023 bool TypeInstKlassPtr::is_same_java_type_as_helper(const TypeKlassPtr* other) const {
6024   return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
6025 }
6026 
6027 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) {
6028   static_assert(std::is_base_of<T2, T1>::value, "");
6029   if (!this_one->is_loaded() || !other->is_loaded()) {
6030     return true;
6031   }
6032 
6033   if (this_one->is_array_type(other)) {
6034     return !this_exact && this_one->klass()->equals(ciEnv::current()->Object_klass())  && other->_interfaces->contains(this_one->_interfaces);
6035   }
6036 
6037   assert(this_one->is_instance_type(other), "unsupported");
6038 
6039   if (this_exact && other_exact) {
6040     return this_one->is_java_subtype_of(other);
6041   }
6042 
6043   if (!this_one->klass()->is_subtype_of(other->klass()) && !other->klass()->is_subtype_of(this_one->klass())) {
6044     return false;
6045   }
6046 
6047   if (this_exact) {
6048     return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);
6049   }
6050 
6051   return true;
6052 }
6053 
6054 bool TypeInstKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6055   return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
6056 }
6057 
6058 const TypeKlassPtr* TypeInstKlassPtr::try_improve() const {
6059   if (!UseUniqueSubclasses) {
6060     return this;
6061   }
6062   ciKlass* k = klass();
6063   Compile* C = Compile::current();
6064   Dependencies* deps = C->dependencies();
6065   assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
6066   const TypeInterfaces* interfaces = _interfaces;
6067   if (k->is_loaded()) {
6068     ciInstanceKlass* ik = k->as_instance_klass();
6069     bool klass_is_exact = ik->is_final();
6070     if (!klass_is_exact &&
6071         deps != nullptr) {
6072       ciInstanceKlass* sub = ik->unique_concrete_subklass();
6073       if (sub != nullptr) {
6074         if (_interfaces->eq(sub)) {
6075           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6076           k = ik = sub;
6077           klass_is_exact = sub->is_final();
6078           return TypeKlassPtr::make(klass_is_exact ? Constant : _ptr, k, _offset);
6079         }
6080       }
6081     }
6082   }
6083   return this;
6084 }
6085 
6086 
6087 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, int offset) {
6088   return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset))->hashcons();
6089 }
6090 
6091 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, ciKlass* k, int offset, InterfaceHandling interface_handling) {
6092   if (k->is_obj_array_klass()) {
6093     // Element is an object array. Recursively call ourself.
6094     ciKlass* eklass = k->as_obj_array_klass()->element_klass();
6095     const TypeKlassPtr *etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6096     return TypeAryKlassPtr::make(ptr, etype, nullptr, offset);
6097   } else if (k->is_type_array_klass()) {
6098     // Element is an typeArray
6099     const Type* etype = get_const_basic_type(k->as_type_array_klass()->element_type());
6100     return TypeAryKlassPtr::make(ptr, etype, k, offset);
6101   } else {
6102     ShouldNotReachHere();
6103     return nullptr;
6104   }
6105 }
6106 
6107 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6108   return TypeAryKlassPtr::make(Constant, klass, 0, interface_handling);
6109 }
6110 
6111 //------------------------------eq---------------------------------------------
6112 // Structural equality check for Type representations
6113 bool TypeAryKlassPtr::eq(const Type *t) const {
6114   const TypeAryKlassPtr *p = t->is_aryklassptr();
6115   return
6116     _elem == p->_elem &&  // Check array
6117     TypeKlassPtr::eq(p);  // Check sub-parts
6118 }
6119 
6120 //------------------------------hash-------------------------------------------
6121 // Type-specific hashing function.
6122 uint TypeAryKlassPtr::hash(void) const {
6123   return (uint)(uintptr_t)_elem + TypeKlassPtr::hash();
6124 }
6125 
6126 //----------------------compute_klass------------------------------------------
6127 // Compute the defining klass for this class
6128 ciKlass* TypeAryPtr::compute_klass() const {
6129   // Compute _klass based on element type.
6130   ciKlass* k_ary = nullptr;
6131   const TypeInstPtr *tinst;
6132   const TypeAryPtr *tary;
6133   const Type* el = elem();
6134   if (el->isa_narrowoop()) {
6135     el = el->make_ptr();
6136   }
6137 
6138   // Get element klass
6139   if ((tinst = el->isa_instptr()) != nullptr) {
6140     // Leave k_ary at null.
6141   } else if ((tary = el->isa_aryptr()) != nullptr) {
6142     // Leave k_ary at null.
6143   } else if ((el->base() == Type::Top) ||
6144              (el->base() == Type::Bottom)) {
6145     // element type of Bottom occurs from meet of basic type
6146     // and object; Top occurs when doing join on Bottom.
6147     // Leave k_ary at null.
6148   } else {
6149     assert(!el->isa_int(), "integral arrays must be pre-equipped with a class");
6150     // Compute array klass directly from basic type
6151     k_ary = ciTypeArrayKlass::make(el->basic_type());
6152   }
6153   return k_ary;
6154 }
6155 
6156 //------------------------------klass------------------------------------------
6157 // Return the defining klass for this class
6158 ciKlass* TypeAryPtr::klass() const {
6159   if( _klass ) return _klass;   // Return cached value, if possible
6160 
6161   // Oops, need to compute _klass and cache it
6162   ciKlass* k_ary = compute_klass();
6163 
6164   if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) {
6165     // The _klass field acts as a cache of the underlying
6166     // ciKlass for this array type.  In order to set the field,
6167     // we need to cast away const-ness.
6168     //
6169     // IMPORTANT NOTE: we *never* set the _klass field for the
6170     // type TypeAryPtr::OOPS.  This Type is shared between all
6171     // active compilations.  However, the ciKlass which represents
6172     // this Type is *not* shared between compilations, so caching
6173     // this value would result in fetching a dangling pointer.
6174     //
6175     // Recomputing the underlying ciKlass for each request is
6176     // a bit less efficient than caching, but calls to
6177     // TypeAryPtr::OOPS->klass() are not common enough to matter.
6178     ((TypeAryPtr*)this)->_klass = k_ary;
6179   }
6180   return k_ary;
6181 }
6182 
6183 // Is there a single ciKlass* that can represent that type?
6184 ciKlass* TypeAryPtr::exact_klass_helper() const {
6185   if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) {
6186     ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper();
6187     if (k == nullptr) {
6188       return nullptr;
6189     }
6190     k = ciObjArrayKlass::make(k);
6191     return k;
6192   }
6193 
6194   return klass();
6195 }
6196 
6197 const Type* TypeAryPtr::base_element_type(int& dims) const {
6198   const Type* elem = this->elem();
6199   dims = 1;
6200   while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) {
6201     elem = elem->make_ptr()->is_aryptr()->elem();
6202     dims++;
6203   }
6204   return elem;
6205 }
6206 
6207 //------------------------------add_offset-------------------------------------
6208 // Access internals of klass object
6209 const TypePtr* TypeAryKlassPtr::add_offset(intptr_t offset) const {
6210   return make(_ptr, elem(), klass(), xadd_offset(offset));
6211 }
6212 
6213 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const {
6214   return make(_ptr, elem(), klass(), offset);
6215 }
6216 
6217 //------------------------------cast_to_ptr_type-------------------------------
6218 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6219   assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6220   if (ptr == _ptr) return this;
6221   return make(ptr, elem(), _klass, _offset);
6222 }
6223 
6224 bool TypeAryKlassPtr::must_be_exact() const {
6225   if (_elem == Type::BOTTOM) return false;
6226   if (_elem == Type::TOP   ) return false;
6227   const TypeKlassPtr*  tk = _elem->isa_klassptr();
6228   if (!tk)             return true;   // a primitive type, like int
6229   return tk->must_be_exact();
6230 }
6231 
6232 
6233 //-----------------------------cast_to_exactness-------------------------------
6234 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6235   if (must_be_exact()) return this;  // cannot clear xk
6236   ciKlass* k = _klass;
6237   const Type* elem = this->elem();
6238   if (elem->isa_klassptr() && !klass_is_exact) {
6239     elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
6240   }
6241   return make(klass_is_exact ? Constant : NotNull, elem, k, _offset);
6242 }
6243 
6244 
6245 //-----------------------------as_instance_type--------------------------------
6246 // Corresponding type for an instance of the given class.
6247 // It will be NotNull, and exact if and only if the klass type is exact.
6248 const TypeOopPtr* TypeAryKlassPtr::as_instance_type(bool klass_change) const {
6249   ciKlass* k = klass();
6250   bool    xk = klass_is_exact();
6251   const Type* el = nullptr;
6252   if (elem()->isa_klassptr()) {
6253     el = elem()->is_klassptr()->as_instance_type(false)->cast_to_exactness(false);
6254     k = nullptr;
6255   } else {
6256     el = elem();
6257   }
6258   return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS), k, xk, 0);
6259 }
6260 
6261 
6262 //------------------------------xmeet------------------------------------------
6263 // Compute the MEET of two types, return a new Type object.
6264 const Type    *TypeAryKlassPtr::xmeet( const Type *t ) const {
6265   // Perform a fast test for common case; meeting the same types together.
6266   if( this == t ) return this;  // Meeting same type-rep?
6267 
6268   // Current "this->_base" is Pointer
6269   switch (t->base()) {          // switch on original type
6270 
6271   case Int:                     // Mixing ints & oops happens when javac
6272   case Long:                    // reuses local variables
6273   case FloatTop:
6274   case FloatCon:
6275   case FloatBot:
6276   case DoubleTop:
6277   case DoubleCon:
6278   case DoubleBot:
6279   case NarrowOop:
6280   case NarrowKlass:
6281   case Bottom:                  // Ye Olde Default
6282     return Type::BOTTOM;
6283   case Top:
6284     return this;
6285 
6286   default:                      // All else is a mistake
6287     typerr(t);
6288 
6289   case AnyPtr: {                // Meeting to AnyPtrs
6290     // Found an AnyPtr type vs self-KlassPtr type
6291     const TypePtr *tp = t->is_ptr();
6292     int offset = meet_offset(tp->offset());
6293     PTR ptr = meet_ptr(tp->ptr());
6294     switch (tp->ptr()) {
6295     case TopPTR:
6296       return this;
6297     case Null:
6298       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6299     case AnyNull:
6300       return make( ptr, _elem, klass(), offset );
6301     case BotPTR:
6302     case NotNull:
6303       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6304     default: typerr(t);
6305     }
6306   }
6307 
6308   case RawPtr:
6309   case MetadataPtr:
6310   case OopPtr:
6311   case AryPtr:                  // Meet with AryPtr
6312   case InstPtr:                 // Meet with InstPtr
6313     return TypePtr::BOTTOM;
6314 
6315   //
6316   //             A-top         }
6317   //           /   |   \       }  Tops
6318   //       B-top A-any C-top   }
6319   //          | /  |  \ |      }  Any-nulls
6320   //       B-any   |   C-any   }
6321   //          |    |    |
6322   //       B-con A-con C-con   } constants; not comparable across classes
6323   //          |    |    |
6324   //       B-not   |   C-not   }
6325   //          | \  |  / |      }  not-nulls
6326   //       B-bot A-not C-bot   }
6327   //           \   |   /       }  Bottoms
6328   //             A-bot         }
6329   //
6330 
6331   case AryKlassPtr: {  // Meet two KlassPtr types
6332     const TypeAryKlassPtr *tap = t->is_aryklassptr();
6333     int off = meet_offset(tap->offset());
6334     const Type* elem = _elem->meet(tap->_elem);
6335 
6336     PTR ptr = meet_ptr(tap->ptr());
6337     ciKlass* res_klass = nullptr;
6338     bool res_xk = false;
6339     meet_aryptr(ptr, elem, this, tap, res_klass, res_xk);
6340     assert(res_xk == (ptr == Constant), "");
6341     return make(ptr, elem, res_klass, off);
6342   } // End of case KlassPtr
6343   case InstKlassPtr: {
6344     const TypeInstKlassPtr *tp = t->is_instklassptr();
6345     int offset = meet_offset(tp->offset());
6346     PTR ptr = meet_ptr(tp->ptr());
6347     const TypeInterfaces* interfaces = meet_interfaces(tp);
6348     const TypeInterfaces* tp_interfaces = tp->_interfaces;
6349     const TypeInterfaces* this_interfaces = _interfaces;
6350 
6351     switch (ptr) {
6352     case TopPTR:
6353     case AnyNull:                // Fall 'down' to dual of object klass
6354       // For instances when a subclass meets a superclass we fall
6355       // below the centerline when the superclass is exact. We need to
6356       // do the same here.
6357       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
6358           !tp->klass_is_exact()) {
6359         return TypeAryKlassPtr::make(ptr, _elem, _klass, offset);
6360       } else {
6361         // cannot subclass, so the meet has to fall badly below the centerline
6362         ptr = NotNull;
6363         interfaces = this_interfaces->intersection_with(tp->_interfaces);
6364         return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
6365       }
6366     case Constant:
6367     case NotNull:
6368     case BotPTR:                // Fall down to object klass
6369       // LCA is object_klass, but if we subclass from the top we can do better
6370       if (above_centerline(tp->ptr())) {
6371         // If 'tp'  is above the centerline and it is Object class
6372         // then we can subclass in the Java class hierarchy.
6373         // For instances when a subclass meets a superclass we fall
6374         // below the centerline when the superclass is exact. We need
6375         // to do the same here.
6376         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
6377             !tp->klass_is_exact()) {
6378           // that is, my array type is a subtype of 'tp' klass
6379           return make(ptr, _elem, _klass, offset);
6380         }
6381       }
6382       // The other case cannot happen, since t cannot be a subtype of an array.
6383       // The meet falls down to Object class below centerline.
6384       if (ptr == Constant)
6385          ptr = NotNull;
6386       interfaces = this_interfaces->intersection_with(tp_interfaces);
6387       return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
6388     default: typerr(t);
6389     }
6390   }
6391 
6392   } // End of switch
6393   return this;                  // Return the double constant
6394 }
6395 
6396 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) {
6397   static_assert(std::is_base_of<T2, T1>::value, "");
6398 
6399   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
6400     return true;
6401   }
6402 
6403   int dummy;
6404   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6405 
6406   if (!this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
6407     return false;
6408   }
6409 
6410   if (this_one->is_instance_type(other)) {
6411     return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces) &&
6412            other_exact;
6413   }
6414 
6415   assert(this_one->is_array_type(other), "");
6416   const T1* other_ary = this_one->is_array_type(other);
6417   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
6418   if (other_top_or_bottom) {
6419     return false;
6420   }
6421 
6422   const TypePtr* other_elem = other_ary->elem()->make_ptr();
6423   const TypePtr* this_elem = this_one->elem()->make_ptr();
6424   if (this_elem != nullptr && other_elem != nullptr) {
6425     return this_one->is_reference_type(this_elem)->is_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6426   }
6427   if (this_elem == nullptr && other_elem == nullptr) {
6428     return this_one->klass()->is_subtype_of(other->klass());
6429   }
6430   return false;
6431 }
6432 
6433 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6434   return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6435 }
6436 
6437 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other) {
6438   static_assert(std::is_base_of<T2, T1>::value, "");
6439 
6440   int dummy;
6441   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6442 
6443   if (!this_one->is_array_type(other) ||
6444       !this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
6445     return false;
6446   }
6447   const T1* other_ary = this_one->is_array_type(other);
6448   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
6449 
6450   if (other_top_or_bottom) {
6451     return false;
6452   }
6453 
6454   const TypePtr* other_elem = other_ary->elem()->make_ptr();
6455   const TypePtr* this_elem = this_one->elem()->make_ptr();
6456   if (other_elem != nullptr && this_elem != nullptr) {
6457     return this_one->is_reference_type(this_elem)->is_same_java_type_as(this_one->is_reference_type(other_elem));
6458   }
6459   if (other_elem == nullptr && this_elem == nullptr) {
6460     return this_one->klass()->equals(other->klass());
6461   }
6462   return false;
6463 }
6464 
6465 bool TypeAryKlassPtr::is_same_java_type_as_helper(const TypeKlassPtr* other) const {
6466   return TypePtr::is_same_java_type_as_helper_for_array(this, other);
6467 }
6468 
6469 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) {
6470   static_assert(std::is_base_of<T2, T1>::value, "");
6471   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
6472     return true;
6473   }
6474   if (!this_one->is_loaded() || !other->is_loaded()) {
6475     return true;
6476   }
6477   if (this_one->is_instance_type(other)) {
6478     return other->klass()->equals(ciEnv::current()->Object_klass()) &&
6479            this_one->_interfaces->contains(other->_interfaces);
6480   }
6481 
6482   int dummy;
6483   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6484   if (this_top_or_bottom) {
6485     return true;
6486   }
6487 
6488   assert(this_one->is_array_type(other), "");
6489 
6490   const T1* other_ary = this_one->is_array_type(other);
6491   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
6492   if (other_top_or_bottom) {
6493     return true;
6494   }
6495   if (this_exact && other_exact) {
6496     return this_one->is_java_subtype_of(other);
6497   }
6498 
6499   const TypePtr* this_elem = this_one->elem()->make_ptr();
6500   const TypePtr* other_elem = other_ary->elem()->make_ptr();
6501   if (other_elem != nullptr && this_elem != nullptr) {
6502     return this_one->is_reference_type(this_elem)->maybe_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6503   }
6504   if (other_elem == nullptr && this_elem == nullptr) {
6505     return this_one->klass()->is_subtype_of(other->klass());
6506   }
6507   return false;
6508 }
6509 
6510 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6511   return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6512 }
6513 
6514 //------------------------------xdual------------------------------------------
6515 // Dual: compute field-by-field dual
6516 const Type    *TypeAryKlassPtr::xdual() const {
6517   return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset());
6518 }
6519 
6520 // Is there a single ciKlass* that can represent that type?
6521 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
6522   if (elem()->isa_klassptr()) {
6523     ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
6524     if (k == nullptr) {
6525       return nullptr;
6526     }
6527     k = ciObjArrayKlass::make(k);
6528     return k;
6529   }
6530 
6531   return klass();
6532 }
6533 
6534 ciKlass* TypeAryKlassPtr::klass() const {
6535   if (_klass != nullptr) {
6536     return _klass;
6537   }
6538   ciKlass* k = nullptr;
6539   if (elem()->isa_klassptr()) {
6540     // leave null
6541   } else if ((elem()->base() == Type::Top) ||
6542              (elem()->base() == Type::Bottom)) {
6543   } else {
6544     k = ciTypeArrayKlass::make(elem()->basic_type());
6545     ((TypeAryKlassPtr*)this)->_klass = k;
6546   }
6547   return k;
6548 }
6549 
6550 //------------------------------dump2------------------------------------------
6551 // Dump Klass Type
6552 #ifndef PRODUCT
6553 void TypeAryKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
6554   switch( _ptr ) {
6555   case Constant:
6556     st->print("precise ");
6557   case NotNull:
6558     {
6559       st->print("[");
6560       _elem->dump2(d, depth, st);
6561       _interfaces->dump(st);
6562       st->print(": ");
6563     }
6564   case BotPTR:
6565     if( !WizardMode && !Verbose && _ptr != Constant ) break;
6566   case TopPTR:
6567   case AnyNull:
6568     st->print(":%s", ptr_msg[_ptr]);
6569     if( _ptr == Constant ) st->print(":exact");
6570     break;
6571   default:
6572     break;
6573   }
6574 
6575   if( _offset ) {               // Dump offset, if any
6576     if( _offset == OffsetBot )      { st->print("+any"); }
6577     else if( _offset == OffsetTop ) { st->print("+unknown"); }
6578     else                            { st->print("+%d", _offset); }
6579   }
6580 
6581   st->print(" *");
6582 }
6583 #endif
6584 
6585 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
6586   const Type* elem = this->elem();
6587   dims = 1;
6588   while (elem->isa_aryklassptr()) {
6589     elem = elem->is_aryklassptr()->elem();
6590     dims++;
6591   }
6592   return elem;
6593 }
6594 
6595 //=============================================================================
6596 // Convenience common pre-built types.
6597 
6598 //------------------------------make-------------------------------------------
6599 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
6600   return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();
6601 }
6602 
6603 //------------------------------make-------------------------------------------
6604 const TypeFunc *TypeFunc::make(ciMethod* method) {
6605   Compile* C = Compile::current();
6606   const TypeFunc* tf = C->last_tf(method); // check cache
6607   if (tf != nullptr)  return tf;  // The hit rate here is almost 50%.
6608   const TypeTuple *domain;
6609   if (method->is_static()) {
6610     domain = TypeTuple::make_domain(nullptr, method->signature(), ignore_interfaces);
6611   } else {
6612     domain = TypeTuple::make_domain(method->holder(), method->signature(), ignore_interfaces);
6613   }
6614   const TypeTuple *range  = TypeTuple::make_range(method->signature(), ignore_interfaces);
6615   tf = TypeFunc::make(domain, range);
6616   C->set_last_tf(method, tf);  // fill cache
6617   return tf;
6618 }
6619 
6620 //------------------------------meet-------------------------------------------
6621 // Compute the MEET of two types.  It returns a new Type object.
6622 const Type *TypeFunc::xmeet( const Type *t ) const {
6623   // Perform a fast test for common case; meeting the same types together.
6624   if( this == t ) return this;  // Meeting same type-rep?
6625 
6626   // Current "this->_base" is Func
6627   switch (t->base()) {          // switch on original type
6628 
6629   case Bottom:                  // Ye Olde Default
6630     return t;
6631 
6632   default:                      // All else is a mistake
6633     typerr(t);
6634 
6635   case Top:
6636     break;
6637   }
6638   return this;                  // Return the double constant
6639 }
6640 
6641 //------------------------------xdual------------------------------------------
6642 // Dual: compute field-by-field dual
6643 const Type *TypeFunc::xdual() const {
6644   return this;
6645 }
6646 
6647 //------------------------------eq---------------------------------------------
6648 // Structural equality check for Type representations
6649 bool TypeFunc::eq( const Type *t ) const {
6650   const TypeFunc *a = (const TypeFunc*)t;
6651   return _domain == a->_domain &&
6652     _range == a->_range;
6653 }
6654 
6655 //------------------------------hash-------------------------------------------
6656 // Type-specific hashing function.
6657 uint TypeFunc::hash(void) const {
6658   return (uint)(uintptr_t)_domain + (uint)(uintptr_t)_range;
6659 }
6660 
6661 //------------------------------dump2------------------------------------------
6662 // Dump Function Type
6663 #ifndef PRODUCT
6664 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
6665   if( _range->cnt() <= Parms )
6666     st->print("void");
6667   else {
6668     uint i;
6669     for (i = Parms; i < _range->cnt()-1; i++) {
6670       _range->field_at(i)->dump2(d,depth,st);
6671       st->print("/");
6672     }
6673     _range->field_at(i)->dump2(d,depth,st);
6674   }
6675   st->print(" ");
6676   st->print("( ");
6677   if( !depth || d[this] ) {     // Check for recursive dump
6678     st->print("...)");
6679     return;
6680   }
6681   d.Insert((void*)this,(void*)this);    // Stop recursion
6682   if (Parms < _domain->cnt())
6683     _domain->field_at(Parms)->dump2(d,depth-1,st);
6684   for (uint i = Parms+1; i < _domain->cnt(); i++) {
6685     st->print(", ");
6686     _domain->field_at(i)->dump2(d,depth-1,st);
6687   }
6688   st->print(" )");
6689 }
6690 #endif
6691 
6692 //------------------------------singleton--------------------------------------
6693 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
6694 // constants (Ldi nodes).  Singletons are integer, float or double constants
6695 // or a single symbol.
6696 bool TypeFunc::singleton(void) const {
6697   return false;                 // Never a singleton
6698 }
6699 
6700 bool TypeFunc::empty(void) const {
6701   return false;                 // Never empty
6702 }
6703 
6704 
6705 BasicType TypeFunc::return_type() const{
6706   if (range()->cnt() == TypeFunc::Parms) {
6707     return T_VOID;
6708   }
6709   return range()->field_at(TypeFunc::Parms)->basic_type();
6710 }