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, nullptr, oopDesc::mark_offset_in_bytes());
 558   TypeInstPtr::KLASS   = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
 559                                            false, nullptr, 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 ] = nullptr;
 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(T_BOOLEAN, 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(BasicType elem_bt, uint length, bool is_mask) {
2495   if (is_mask) {
2496     return makemask(elem_bt, length);
2497   }
2498   assert(is_java_primitive(elem_bt), "only primitive types in vector");
2499   assert(Matcher::vector_size_supported(elem_bt, length), "length in range");
2500   int size = length * type2aelembytes(elem_bt);
2501   switch (Matcher::vector_ideal_reg(size)) {
2502   case Op_VecA:
2503     return (TypeVect*)(new TypeVectA(elem_bt, length))->hashcons();
2504   case Op_VecS:
2505     return (TypeVect*)(new TypeVectS(elem_bt, length))->hashcons();
2506   case Op_RegL:
2507   case Op_VecD:
2508   case Op_RegD:
2509     return (TypeVect*)(new TypeVectD(elem_bt, length))->hashcons();
2510   case Op_VecX:
2511     return (TypeVect*)(new TypeVectX(elem_bt, length))->hashcons();
2512   case Op_VecY:
2513     return (TypeVect*)(new TypeVectY(elem_bt, length))->hashcons();
2514   case Op_VecZ:
2515     return (TypeVect*)(new TypeVectZ(elem_bt, length))->hashcons();
2516   }
2517  ShouldNotReachHere();
2518   return nullptr;
2519 }
2520 
2521 const TypeVect* TypeVect::makemask(BasicType elem_bt, uint length) {
2522   if (Matcher::has_predicated_vectors() &&
2523       Matcher::match_rule_supported_vector_masked(Op_VectorLoadMask, length, elem_bt)) {
2524     return TypeVectMask::make(elem_bt, length);
2525   } else {
2526     return make(elem_bt, length);
2527   }
2528 }
2529 
2530 //------------------------------meet-------------------------------------------
2531 // Compute the MEET of two types. Since each TypeVect is the only instance of
2532 // its species, meeting often returns itself
2533 const Type* TypeVect::xmeet(const Type* t) const {
2534   // Perform a fast test for common case; meeting the same types together.
2535   if (this == t) {
2536     return this;
2537   }
2538 
2539   // Current "this->_base" is Vector
2540   switch (t->base()) {          // switch on original type
2541 
2542   case Bottom:                  // Ye Olde Default
2543     return t;
2544 
2545   default:                      // All else is a mistake
2546     typerr(t);
2547   case VectorMask:
2548   case VectorA:
2549   case VectorS:
2550   case VectorD:
2551   case VectorX:
2552   case VectorY:
2553   case VectorZ: {                // Meeting 2 vectors?
2554     const TypeVect* v = t->is_vect();
2555     assert(base() == v->base(), "");
2556     assert(length() == v->length(), "");
2557     assert(element_basic_type() == v->element_basic_type(), "");
2558     return this;
2559   }
2560   case Top:
2561     break;
2562   }
2563   return this;
2564 }
2565 
2566 //------------------------------xdual------------------------------------------
2567 // Since each TypeVect is the only instance of its species, it is self-dual
2568 const Type* TypeVect::xdual() const {
2569   return this;
2570 }
2571 
2572 //------------------------------eq---------------------------------------------
2573 // Structural equality check for Type representations
2574 bool TypeVect::eq(const Type* t) const {
2575   const TypeVect* v = t->is_vect();
2576   return (element_basic_type() == v->element_basic_type()) && (length() == v->length());
2577 }
2578 
2579 //------------------------------hash-------------------------------------------
2580 // Type-specific hashing function.
2581 uint TypeVect::hash(void) const {
2582   return (uint)base() + (uint)(uintptr_t)_elem_bt + (uint)(uintptr_t)_length;
2583 }
2584 
2585 //------------------------------singleton--------------------------------------
2586 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2587 // constants (Ldi nodes).  Vector is singleton if all elements are the same
2588 // constant value (when vector is created with Replicate code).
2589 bool TypeVect::singleton(void) const {
2590 // There is no Con node for vectors yet.
2591 //  return _elem->singleton();
2592   return false;
2593 }
2594 
2595 bool TypeVect::empty(void) const {
2596   return false;
2597 }
2598 
2599 //------------------------------dump2------------------------------------------
2600 #ifndef PRODUCT
2601 void TypeVect::dump2(Dict& d, uint depth, outputStream* st) const {
2602   switch (base()) {
2603   case VectorA:
2604     st->print("vectora"); break;
2605   case VectorS:
2606     st->print("vectors"); break;
2607   case VectorD:
2608     st->print("vectord"); break;
2609   case VectorX:
2610     st->print("vectorx"); break;
2611   case VectorY:
2612     st->print("vectory"); break;
2613   case VectorZ:
2614     st->print("vectorz"); break;
2615   case VectorMask:
2616     st->print("vectormask"); break;
2617   default:
2618     ShouldNotReachHere();
2619   }
2620   st->print("<%c,%u>", type2char(element_basic_type()), length());
2621 }
2622 #endif
2623 
2624 const TypeVectMask* TypeVectMask::make(const BasicType elem_bt, uint length) {
2625   return (TypeVectMask*) (new TypeVectMask(elem_bt, length))->hashcons();
2626 }
2627 
2628 //=============================================================================
2629 // Convenience common pre-built types.
2630 const TypePtr *TypePtr::NULL_PTR;
2631 const TypePtr *TypePtr::NOTNULL;
2632 const TypePtr *TypePtr::BOTTOM;
2633 
2634 //------------------------------meet-------------------------------------------
2635 // Meet over the PTR enum
2636 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2637   //              TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,
2638   { /* Top     */ TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,},
2639   { /* AnyNull */ AnyNull,   AnyNull,   Constant, BotPTR, NotNull, BotPTR,},
2640   { /* Constant*/ Constant,  Constant,  Constant, BotPTR, NotNull, BotPTR,},
2641   { /* Null    */ Null,      BotPTR,    BotPTR,   Null,   BotPTR,  BotPTR,},
2642   { /* NotNull */ NotNull,   NotNull,   NotNull,  BotPTR, NotNull, BotPTR,},
2643   { /* BotPTR  */ BotPTR,    BotPTR,    BotPTR,   BotPTR, BotPTR,  BotPTR,}
2644 };
2645 
2646 //------------------------------make-------------------------------------------
2647 const TypePtr *TypePtr::make(TYPES t, enum PTR ptr, int offset, const TypePtr* speculative, int inline_depth) {
2648   return (TypePtr*)(new TypePtr(t,ptr,offset, speculative, inline_depth))->hashcons();
2649 }
2650 
2651 //------------------------------cast_to_ptr_type-------------------------------
2652 const TypePtr* TypePtr::cast_to_ptr_type(PTR ptr) const {
2653   assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2654   if( ptr == _ptr ) return this;
2655   return make(_base, ptr, _offset, _speculative, _inline_depth);
2656 }
2657 
2658 //------------------------------get_con----------------------------------------
2659 intptr_t TypePtr::get_con() const {
2660   assert( _ptr == Null, "" );
2661   return _offset;
2662 }
2663 
2664 //------------------------------meet-------------------------------------------
2665 // Compute the MEET of two types.  It returns a new Type object.
2666 const Type *TypePtr::xmeet(const Type *t) const {
2667   const Type* res = xmeet_helper(t);
2668   if (res->isa_ptr() == nullptr) {
2669     return res;
2670   }
2671 
2672   const TypePtr* res_ptr = res->is_ptr();
2673   if (res_ptr->speculative() != nullptr) {
2674     // type->speculative() is null means that speculation is no better
2675     // than type, i.e. type->speculative() == type. So there are 2
2676     // ways to represent the fact that we have no useful speculative
2677     // data and we should use a single one to be able to test for
2678     // equality between types. Check whether type->speculative() ==
2679     // type and set speculative to null if it is the case.
2680     if (res_ptr->remove_speculative() == res_ptr->speculative()) {
2681       return res_ptr->remove_speculative();
2682     }
2683   }
2684 
2685   return res;
2686 }
2687 
2688 const Type *TypePtr::xmeet_helper(const Type *t) const {
2689   // Perform a fast test for common case; meeting the same types together.
2690   if( this == t ) return this;  // Meeting same type-rep?
2691 
2692   // Current "this->_base" is AnyPtr
2693   switch (t->base()) {          // switch on original type
2694   case Int:                     // Mixing ints & oops happens when javac
2695   case Long:                    // reuses local variables
2696   case FloatTop:
2697   case FloatCon:
2698   case FloatBot:
2699   case DoubleTop:
2700   case DoubleCon:
2701   case DoubleBot:
2702   case NarrowOop:
2703   case NarrowKlass:
2704   case Bottom:                  // Ye Olde Default
2705     return Type::BOTTOM;
2706   case Top:
2707     return this;
2708 
2709   case AnyPtr: {                // Meeting to AnyPtrs
2710     const TypePtr *tp = t->is_ptr();
2711     const TypePtr* speculative = xmeet_speculative(tp);
2712     int depth = meet_inline_depth(tp->inline_depth());
2713     return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2714   }
2715   case RawPtr:                  // For these, flip the call around to cut down
2716   case OopPtr:
2717   case InstPtr:                 // on the cases I have to handle.
2718   case AryPtr:
2719   case MetadataPtr:
2720   case KlassPtr:
2721   case InstKlassPtr:
2722   case AryKlassPtr:
2723     return t->xmeet(this);      // Call in reverse direction
2724   default:                      // All else is a mistake
2725     typerr(t);
2726 
2727   }
2728   return this;
2729 }
2730 
2731 //------------------------------meet_offset------------------------------------
2732 int TypePtr::meet_offset( int offset ) const {
2733   // Either is 'TOP' offset?  Return the other offset!
2734   if( _offset == OffsetTop ) return offset;
2735   if( offset == OffsetTop ) return _offset;
2736   // If either is different, return 'BOTTOM' offset
2737   if( _offset != offset ) return OffsetBot;
2738   return _offset;
2739 }
2740 
2741 //------------------------------dual_offset------------------------------------
2742 int TypePtr::dual_offset( ) const {
2743   if( _offset == OffsetTop ) return OffsetBot;// Map 'TOP' into 'BOTTOM'
2744   if( _offset == OffsetBot ) return OffsetTop;// Map 'BOTTOM' into 'TOP'
2745   return _offset;               // Map everything else into self
2746 }
2747 
2748 //------------------------------xdual------------------------------------------
2749 // Dual: compute field-by-field dual
2750 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2751   BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2752 };
2753 const Type *TypePtr::xdual() const {
2754   return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
2755 }
2756 
2757 //------------------------------xadd_offset------------------------------------
2758 int TypePtr::xadd_offset( intptr_t offset ) const {
2759   // Adding to 'TOP' offset?  Return 'TOP'!
2760   if( _offset == OffsetTop || offset == OffsetTop ) return OffsetTop;
2761   // Adding to 'BOTTOM' offset?  Return 'BOTTOM'!
2762   if( _offset == OffsetBot || offset == OffsetBot ) return OffsetBot;
2763   // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
2764   offset += (intptr_t)_offset;
2765   if (offset != (int)offset || offset == OffsetTop) return OffsetBot;
2766 
2767   // assert( _offset >= 0 && _offset+offset >= 0, "" );
2768   // It is possible to construct a negative offset during PhaseCCP
2769 
2770   return (int)offset;        // Sum valid offsets
2771 }
2772 
2773 //------------------------------add_offset-------------------------------------
2774 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2775   return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth);
2776 }
2777 
2778 const TypePtr *TypePtr::with_offset(intptr_t offset) const {
2779   return make(AnyPtr, _ptr, offset, _speculative, _inline_depth);
2780 }
2781 
2782 //------------------------------eq---------------------------------------------
2783 // Structural equality check for Type representations
2784 bool TypePtr::eq( const Type *t ) const {
2785   const TypePtr *a = (const TypePtr*)t;
2786   return _ptr == a->ptr() && _offset == a->offset() && eq_speculative(a) && _inline_depth == a->_inline_depth;
2787 }
2788 
2789 //------------------------------hash-------------------------------------------
2790 // Type-specific hashing function.
2791 uint TypePtr::hash(void) const {
2792   return (uint)_ptr + (uint)_offset + (uint)hash_speculative() + (uint)_inline_depth;
2793 }
2794 
2795 /**
2796  * Return same type without a speculative part
2797  */
2798 const TypePtr* TypePtr::remove_speculative() const {
2799   if (_speculative == nullptr) {
2800     return this;
2801   }
2802   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2803   return make(AnyPtr, _ptr, _offset, nullptr, _inline_depth);
2804 }
2805 
2806 /**
2807  * Return same type but drop speculative part if we know we won't use
2808  * it
2809  */
2810 const Type* TypePtr::cleanup_speculative() const {
2811   if (speculative() == nullptr) {
2812     return this;
2813   }
2814   const Type* no_spec = remove_speculative();
2815   // If this is NULL_PTR then we don't need the speculative type
2816   // (with_inline_depth in case the current type inline depth is
2817   // InlineDepthTop)
2818   if (no_spec == NULL_PTR->with_inline_depth(inline_depth())) {
2819     return no_spec;
2820   }
2821   if (above_centerline(speculative()->ptr())) {
2822     return no_spec;
2823   }
2824   const TypeOopPtr* spec_oopptr = speculative()->isa_oopptr();
2825   // If the speculative may be null and is an inexact klass then it
2826   // doesn't help
2827   if (speculative() != TypePtr::NULL_PTR && speculative()->maybe_null() &&
2828       (spec_oopptr == nullptr || !spec_oopptr->klass_is_exact())) {
2829     return no_spec;
2830   }
2831   return this;
2832 }
2833 
2834 /**
2835  * dual of the speculative part of the type
2836  */
2837 const TypePtr* TypePtr::dual_speculative() const {
2838   if (_speculative == nullptr) {
2839     return nullptr;
2840   }
2841   return _speculative->dual()->is_ptr();
2842 }
2843 
2844 /**
2845  * meet of the speculative parts of 2 types
2846  *
2847  * @param other  type to meet with
2848  */
2849 const TypePtr* TypePtr::xmeet_speculative(const TypePtr* other) const {
2850   bool this_has_spec = (_speculative != nullptr);
2851   bool other_has_spec = (other->speculative() != nullptr);
2852 
2853   if (!this_has_spec && !other_has_spec) {
2854     return nullptr;
2855   }
2856 
2857   // If we are at a point where control flow meets and one branch has
2858   // a speculative type and the other has not, we meet the speculative
2859   // type of one branch with the actual type of the other. If the
2860   // actual type is exact and the speculative is as well, then the
2861   // result is a speculative type which is exact and we can continue
2862   // speculation further.
2863   const TypePtr* this_spec = _speculative;
2864   const TypePtr* other_spec = other->speculative();
2865 
2866   if (!this_has_spec) {
2867     this_spec = this;
2868   }
2869 
2870   if (!other_has_spec) {
2871     other_spec = other;
2872   }
2873 
2874   return this_spec->meet(other_spec)->is_ptr();
2875 }
2876 
2877 /**
2878  * dual of the inline depth for this type (used for speculation)
2879  */
2880 int TypePtr::dual_inline_depth() const {
2881   return -inline_depth();
2882 }
2883 
2884 /**
2885  * meet of 2 inline depths (used for speculation)
2886  *
2887  * @param depth  depth to meet with
2888  */
2889 int TypePtr::meet_inline_depth(int depth) const {
2890   return MAX2(inline_depth(), depth);
2891 }
2892 
2893 /**
2894  * Are the speculative parts of 2 types equal?
2895  *
2896  * @param other  type to compare this one to
2897  */
2898 bool TypePtr::eq_speculative(const TypePtr* other) const {
2899   if (_speculative == nullptr || other->speculative() == nullptr) {
2900     return _speculative == other->speculative();
2901   }
2902 
2903   if (_speculative->base() != other->speculative()->base()) {
2904     return false;
2905   }
2906 
2907   return _speculative->eq(other->speculative());
2908 }
2909 
2910 /**
2911  * Hash of the speculative part of the type
2912  */
2913 int TypePtr::hash_speculative() const {
2914   if (_speculative == nullptr) {
2915     return 0;
2916   }
2917 
2918   return _speculative->hash();
2919 }
2920 
2921 /**
2922  * add offset to the speculative part of the type
2923  *
2924  * @param offset  offset to add
2925  */
2926 const TypePtr* TypePtr::add_offset_speculative(intptr_t offset) const {
2927   if (_speculative == nullptr) {
2928     return nullptr;
2929   }
2930   return _speculative->add_offset(offset)->is_ptr();
2931 }
2932 
2933 const TypePtr* TypePtr::with_offset_speculative(intptr_t offset) const {
2934   if (_speculative == nullptr) {
2935     return nullptr;
2936   }
2937   return _speculative->with_offset(offset)->is_ptr();
2938 }
2939 
2940 /**
2941  * return exact klass from the speculative type if there's one
2942  */
2943 ciKlass* TypePtr::speculative_type() const {
2944   if (_speculative != nullptr && _speculative->isa_oopptr()) {
2945     const TypeOopPtr* speculative = _speculative->join(this)->is_oopptr();
2946     if (speculative->klass_is_exact()) {
2947       return speculative->exact_klass();
2948     }
2949   }
2950   return nullptr;
2951 }
2952 
2953 /**
2954  * return true if speculative type may be null
2955  */
2956 bool TypePtr::speculative_maybe_null() const {
2957   if (_speculative != nullptr) {
2958     const TypePtr* speculative = _speculative->join(this)->is_ptr();
2959     return speculative->maybe_null();
2960   }
2961   return true;
2962 }
2963 
2964 bool TypePtr::speculative_always_null() const {
2965   if (_speculative != nullptr) {
2966     const TypePtr* speculative = _speculative->join(this)->is_ptr();
2967     return speculative == TypePtr::NULL_PTR;
2968   }
2969   return false;
2970 }
2971 
2972 /**
2973  * Same as TypePtr::speculative_type() but return the klass only if
2974  * the speculative tells us is not null
2975  */
2976 ciKlass* TypePtr::speculative_type_not_null() const {
2977   if (speculative_maybe_null()) {
2978     return nullptr;
2979   }
2980   return speculative_type();
2981 }
2982 
2983 /**
2984  * Check whether new profiling would improve speculative type
2985  *
2986  * @param   exact_kls    class from profiling
2987  * @param   inline_depth inlining depth of profile point
2988  *
2989  * @return  true if type profile is valuable
2990  */
2991 bool TypePtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
2992   // no profiling?
2993   if (exact_kls == nullptr) {
2994     return false;
2995   }
2996   if (speculative() == TypePtr::NULL_PTR) {
2997     return false;
2998   }
2999   // no speculative type or non exact speculative type?
3000   if (speculative_type() == nullptr) {
3001     return true;
3002   }
3003   // If the node already has an exact speculative type keep it,
3004   // unless it was provided by profiling that is at a deeper
3005   // inlining level. Profiling at a higher inlining depth is
3006   // expected to be less accurate.
3007   if (_speculative->inline_depth() == InlineDepthBottom) {
3008     return false;
3009   }
3010   assert(_speculative->inline_depth() != InlineDepthTop, "can't do the comparison");
3011   return inline_depth < _speculative->inline_depth();
3012 }
3013 
3014 /**
3015  * Check whether new profiling would improve ptr (= tells us it is non
3016  * null)
3017  *
3018  * @param   ptr_kind always null or not null?
3019  *
3020  * @return  true if ptr profile is valuable
3021  */
3022 bool TypePtr::would_improve_ptr(ProfilePtrKind ptr_kind) const {
3023   // profiling doesn't tell us anything useful
3024   if (ptr_kind != ProfileAlwaysNull && ptr_kind != ProfileNeverNull) {
3025     return false;
3026   }
3027   // We already know this is not null
3028   if (!this->maybe_null()) {
3029     return false;
3030   }
3031   // We already know the speculative type cannot be null
3032   if (!speculative_maybe_null()) {
3033     return false;
3034   }
3035   // We already know this is always null
3036   if (this == TypePtr::NULL_PTR) {
3037     return false;
3038   }
3039   // We already know the speculative type is always null
3040   if (speculative_always_null()) {
3041     return false;
3042   }
3043   if (ptr_kind == ProfileAlwaysNull && speculative() != nullptr && speculative()->isa_oopptr()) {
3044     return false;
3045   }
3046   return true;
3047 }
3048 
3049 //------------------------------dump2------------------------------------------
3050 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
3051   "TopPTR","AnyNull","Constant","null","NotNull","BotPTR"
3052 };
3053 
3054 #ifndef PRODUCT
3055 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3056   if( _ptr == Null ) st->print("null");
3057   else st->print("%s *", ptr_msg[_ptr]);
3058   if( _offset == OffsetTop ) st->print("+top");
3059   else if( _offset == OffsetBot ) st->print("+bot");
3060   else if( _offset ) st->print("+%d", _offset);
3061   dump_inline_depth(st);
3062   dump_speculative(st);
3063 }
3064 
3065 /**
3066  *dump the speculative part of the type
3067  */
3068 void TypePtr::dump_speculative(outputStream *st) const {
3069   if (_speculative != nullptr) {
3070     st->print(" (speculative=");
3071     _speculative->dump_on(st);
3072     st->print(")");
3073   }
3074 }
3075 
3076 /**
3077  *dump the inline depth of the type
3078  */
3079 void TypePtr::dump_inline_depth(outputStream *st) const {
3080   if (_inline_depth != InlineDepthBottom) {
3081     if (_inline_depth == InlineDepthTop) {
3082       st->print(" (inline_depth=InlineDepthTop)");
3083     } else {
3084       st->print(" (inline_depth=%d)", _inline_depth);
3085     }
3086   }
3087 }
3088 #endif
3089 
3090 //------------------------------singleton--------------------------------------
3091 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3092 // constants
3093 bool TypePtr::singleton(void) const {
3094   // TopPTR, Null, AnyNull, Constant are all singletons
3095   return (_offset != OffsetBot) && !below_centerline(_ptr);
3096 }
3097 
3098 bool TypePtr::empty(void) const {
3099   return (_offset == OffsetTop) || above_centerline(_ptr);
3100 }
3101 
3102 //=============================================================================
3103 // Convenience common pre-built types.
3104 const TypeRawPtr *TypeRawPtr::BOTTOM;
3105 const TypeRawPtr *TypeRawPtr::NOTNULL;
3106 
3107 //------------------------------make-------------------------------------------
3108 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
3109   assert( ptr != Constant, "what is the constant?" );
3110   assert( ptr != Null, "Use TypePtr for null" );
3111   return (TypeRawPtr*)(new TypeRawPtr(ptr,nullptr))->hashcons();
3112 }
3113 
3114 const TypeRawPtr *TypeRawPtr::make(address bits) {
3115   assert(bits != nullptr, "Use TypePtr for null");
3116   return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
3117 }
3118 
3119 //------------------------------cast_to_ptr_type-------------------------------
3120 const TypeRawPtr* TypeRawPtr::cast_to_ptr_type(PTR ptr) const {
3121   assert( ptr != Constant, "what is the constant?" );
3122   assert( ptr != Null, "Use TypePtr for null" );
3123   assert( _bits == nullptr, "Why cast a constant address?");
3124   if( ptr == _ptr ) return this;
3125   return make(ptr);
3126 }
3127 
3128 //------------------------------get_con----------------------------------------
3129 intptr_t TypeRawPtr::get_con() const {
3130   assert( _ptr == Null || _ptr == Constant, "" );
3131   return (intptr_t)_bits;
3132 }
3133 
3134 //------------------------------meet-------------------------------------------
3135 // Compute the MEET of two types.  It returns a new Type object.
3136 const Type *TypeRawPtr::xmeet( const Type *t ) const {
3137   // Perform a fast test for common case; meeting the same types together.
3138   if( this == t ) return this;  // Meeting same type-rep?
3139 
3140   // Current "this->_base" is RawPtr
3141   switch( t->base() ) {         // switch on original type
3142   case Bottom:                  // Ye Olde Default
3143     return t;
3144   case Top:
3145     return this;
3146   case AnyPtr:                  // Meeting to AnyPtrs
3147     break;
3148   case RawPtr: {                // might be top, bot, any/not or constant
3149     enum PTR tptr = t->is_ptr()->ptr();
3150     enum PTR ptr = meet_ptr( tptr );
3151     if( ptr == Constant ) {     // Cannot be equal constants, so...
3152       if( tptr == Constant && _ptr != Constant)  return t;
3153       if( _ptr == Constant && tptr != Constant)  return this;
3154       ptr = NotNull;            // Fall down in lattice
3155     }
3156     return make( ptr );
3157   }
3158 
3159   case OopPtr:
3160   case InstPtr:
3161   case AryPtr:
3162   case MetadataPtr:
3163   case KlassPtr:
3164   case InstKlassPtr:
3165   case AryKlassPtr:
3166     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3167   default:                      // All else is a mistake
3168     typerr(t);
3169   }
3170 
3171   // Found an AnyPtr type vs self-RawPtr type
3172   const TypePtr *tp = t->is_ptr();
3173   switch (tp->ptr()) {
3174   case TypePtr::TopPTR:  return this;
3175   case TypePtr::BotPTR:  return t;
3176   case TypePtr::Null:
3177     if( _ptr == TypePtr::TopPTR ) return t;
3178     return TypeRawPtr::BOTTOM;
3179   case TypePtr::NotNull: return TypePtr::make(AnyPtr, meet_ptr(TypePtr::NotNull), tp->meet_offset(0), tp->speculative(), tp->inline_depth());
3180   case TypePtr::AnyNull:
3181     if( _ptr == TypePtr::Constant) return this;
3182     return make( meet_ptr(TypePtr::AnyNull) );
3183   default: ShouldNotReachHere();
3184   }
3185   return this;
3186 }
3187 
3188 //------------------------------xdual------------------------------------------
3189 // Dual: compute field-by-field dual
3190 const Type *TypeRawPtr::xdual() const {
3191   return new TypeRawPtr( dual_ptr(), _bits );
3192 }
3193 
3194 //------------------------------add_offset-------------------------------------
3195 const TypePtr* TypeRawPtr::add_offset(intptr_t offset) const {
3196   if( offset == OffsetTop ) return BOTTOM; // Undefined offset-> undefined pointer
3197   if( offset == OffsetBot ) return BOTTOM; // Unknown offset-> unknown pointer
3198   if( offset == 0 ) return this; // No change
3199   switch (_ptr) {
3200   case TypePtr::TopPTR:
3201   case TypePtr::BotPTR:
3202   case TypePtr::NotNull:
3203     return this;
3204   case TypePtr::Constant: {
3205     uintptr_t bits = (uintptr_t)_bits;
3206     uintptr_t sum = bits + offset;
3207     if (( offset < 0 )
3208         ? ( sum > bits )        // Underflow?
3209         : ( sum < bits )) {     // Overflow?
3210       return BOTTOM;
3211     } else if ( sum == 0 ) {
3212       return TypePtr::NULL_PTR;
3213     } else {
3214       return make( (address)sum );
3215     }
3216   }
3217   default:  ShouldNotReachHere();
3218   }
3219 }
3220 
3221 //------------------------------eq---------------------------------------------
3222 // Structural equality check for Type representations
3223 bool TypeRawPtr::eq( const Type *t ) const {
3224   const TypeRawPtr *a = (const TypeRawPtr*)t;
3225   return _bits == a->_bits && TypePtr::eq(t);
3226 }
3227 
3228 //------------------------------hash-------------------------------------------
3229 // Type-specific hashing function.
3230 uint TypeRawPtr::hash(void) const {
3231   return (uint)(uintptr_t)_bits + (uint)TypePtr::hash();
3232 }
3233 
3234 //------------------------------dump2------------------------------------------
3235 #ifndef PRODUCT
3236 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3237   if( _ptr == Constant )
3238     st->print(INTPTR_FORMAT, p2i(_bits));
3239   else
3240     st->print("rawptr:%s", ptr_msg[_ptr]);
3241 }
3242 #endif
3243 
3244 //=============================================================================
3245 // Convenience common pre-built type.
3246 const TypeOopPtr *TypeOopPtr::BOTTOM;
3247 
3248 TypeInterfaces::TypeInterfaces(ciInstanceKlass** interfaces_base, int nb_interfaces)
3249         : Type(Interfaces), _interfaces(interfaces_base, nb_interfaces),
3250           _hash(0), _exact_klass(nullptr) {
3251   _interfaces.sort(compare);
3252   initialize();
3253 }
3254 
3255 const TypeInterfaces* TypeInterfaces::make(GrowableArray<ciInstanceKlass*>* interfaces) {
3256   // hashcons() can only delete the last thing that was allocated: to
3257   // make sure all memory for the newly created TypeInterfaces can be
3258   // freed if an identical one exists, allocate space for the array of
3259   // interfaces right after the TypeInterfaces object so that they
3260   // form a contiguous piece of memory.
3261   int nb_interfaces = interfaces == nullptr ? 0 : interfaces->length();
3262   size_t total_size = sizeof(TypeInterfaces) + nb_interfaces * sizeof(ciInstanceKlass*);
3263 
3264   void* allocated_mem = operator new(total_size);
3265   ciInstanceKlass** interfaces_base = (ciInstanceKlass**)((char*)allocated_mem + sizeof(TypeInterfaces));
3266   for (int i = 0; i < nb_interfaces; ++i) {
3267     interfaces_base[i] = interfaces->at(i);
3268   }
3269   TypeInterfaces* result = ::new (allocated_mem) TypeInterfaces(interfaces_base, nb_interfaces);
3270   return (const TypeInterfaces*)result->hashcons();
3271 }
3272 
3273 void TypeInterfaces::initialize() {
3274   compute_hash();
3275   compute_exact_klass();
3276   DEBUG_ONLY(_initialized = true;)
3277 }
3278 
3279 int TypeInterfaces::compare(ciInstanceKlass* const& k1, ciInstanceKlass* const& k2) {
3280   if ((intptr_t)k1 < (intptr_t)k2) {
3281     return -1;
3282   } else if ((intptr_t)k1 > (intptr_t)k2) {
3283     return 1;
3284   }
3285   return 0;
3286 }
3287 
3288 int TypeInterfaces::compare(ciInstanceKlass** k1, ciInstanceKlass** k2) {
3289   return compare(*k1, *k2);
3290 }
3291 
3292 bool TypeInterfaces::eq(const Type* t) const {
3293   const TypeInterfaces* other = (const TypeInterfaces*)t;
3294   if (_interfaces.length() != other->_interfaces.length()) {
3295     return false;
3296   }
3297   for (int i = 0; i < _interfaces.length(); i++) {
3298     ciKlass* k1 = _interfaces.at(i);
3299     ciKlass* k2 = other->_interfaces.at(i);
3300     if (!k1->equals(k2)) {
3301       return false;
3302     }
3303   }
3304   return true;
3305 }
3306 
3307 bool TypeInterfaces::eq(ciInstanceKlass* k) const {
3308   assert(k->is_loaded(), "should be loaded");
3309   GrowableArray<ciInstanceKlass *>* interfaces = k->transitive_interfaces();
3310   if (_interfaces.length() != interfaces->length()) {
3311     return false;
3312   }
3313   for (int i = 0; i < interfaces->length(); i++) {
3314     bool found = false;
3315     _interfaces.find_sorted<ciInstanceKlass*, compare>(interfaces->at(i), found);
3316     if (!found) {
3317       return false;
3318     }
3319   }
3320   return true;
3321 }
3322 
3323 
3324 uint TypeInterfaces::hash() const {
3325   assert(_initialized, "must be");
3326   return _hash;
3327 }
3328 
3329 const Type* TypeInterfaces::xdual() const {
3330   return this;
3331 }
3332 
3333 void TypeInterfaces::compute_hash() {
3334   uint hash = 0;
3335   for (int i = 0; i < _interfaces.length(); i++) {
3336     ciKlass* k = _interfaces.at(i);
3337     hash += k->hash();
3338   }
3339   _hash = hash;
3340 }
3341 
3342 static int compare_interfaces(ciInstanceKlass** k1, ciInstanceKlass** k2) {
3343   return (int)((*k1)->ident() - (*k2)->ident());
3344 }
3345 
3346 void TypeInterfaces::dump(outputStream* st) const {
3347   if (_interfaces.length() == 0) {
3348     return;
3349   }
3350   ResourceMark rm;
3351   st->print(" (");
3352   GrowableArray<ciInstanceKlass*> interfaces;
3353   interfaces.appendAll(&_interfaces);
3354   // Sort the interfaces so they are listed in the same order from one run to the other of the same compilation
3355   interfaces.sort(compare_interfaces);
3356   for (int i = 0; i < interfaces.length(); i++) {
3357     if (i > 0) {
3358       st->print(",");
3359     }
3360     ciKlass* k = interfaces.at(i);
3361     k->print_name_on(st);
3362   }
3363   st->print(")");
3364 }
3365 
3366 #ifdef ASSERT
3367 void TypeInterfaces::verify() const {
3368   for (int i = 1; i < _interfaces.length(); i++) {
3369     ciInstanceKlass* k1 = _interfaces.at(i-1);
3370     ciInstanceKlass* k2 = _interfaces.at(i);
3371     assert(compare(k2, k1) > 0, "should be ordered");
3372     assert(k1 != k2, "no duplicate");
3373   }
3374 }
3375 #endif
3376 
3377 const TypeInterfaces* TypeInterfaces::union_with(const TypeInterfaces* other) const {
3378   GrowableArray<ciInstanceKlass*> result_list;
3379   int i = 0;
3380   int j = 0;
3381   while (i < _interfaces.length() || j < other->_interfaces.length()) {
3382     while (i < _interfaces.length() &&
3383            (j >= other->_interfaces.length() ||
3384             compare(_interfaces.at(i), other->_interfaces.at(j)) < 0)) {
3385       result_list.push(_interfaces.at(i));
3386       i++;
3387     }
3388     while (j < other->_interfaces.length() &&
3389            (i >= _interfaces.length() ||
3390             compare(other->_interfaces.at(j), _interfaces.at(i)) < 0)) {
3391       result_list.push(other->_interfaces.at(j));
3392       j++;
3393     }
3394     if (i < _interfaces.length() &&
3395         j < other->_interfaces.length() &&
3396         _interfaces.at(i) == other->_interfaces.at(j)) {
3397       result_list.push(_interfaces.at(i));
3398       i++;
3399       j++;
3400     }
3401   }
3402   const TypeInterfaces* result = TypeInterfaces::make(&result_list);
3403 #ifdef ASSERT
3404   result->verify();
3405   for (int i = 0; i < _interfaces.length(); i++) {
3406     assert(result->_interfaces.contains(_interfaces.at(i)), "missing");
3407   }
3408   for (int i = 0; i < other->_interfaces.length(); i++) {
3409     assert(result->_interfaces.contains(other->_interfaces.at(i)), "missing");
3410   }
3411   for (int i = 0; i < result->_interfaces.length(); i++) {
3412     assert(_interfaces.contains(result->_interfaces.at(i)) || other->_interfaces.contains(result->_interfaces.at(i)), "missing");
3413   }
3414 #endif
3415   return result;
3416 }
3417 
3418 const TypeInterfaces* TypeInterfaces::intersection_with(const TypeInterfaces* other) const {
3419   GrowableArray<ciInstanceKlass*> result_list;
3420   int i = 0;
3421   int j = 0;
3422   while (i < _interfaces.length() || j < other->_interfaces.length()) {
3423     while (i < _interfaces.length() &&
3424            (j >= other->_interfaces.length() ||
3425             compare(_interfaces.at(i), other->_interfaces.at(j)) < 0)) {
3426       i++;
3427     }
3428     while (j < other->_interfaces.length() &&
3429            (i >= _interfaces.length() ||
3430             compare(other->_interfaces.at(j), _interfaces.at(i)) < 0)) {
3431       j++;
3432     }
3433     if (i < _interfaces.length() &&
3434         j < other->_interfaces.length() &&
3435         _interfaces.at(i) == other->_interfaces.at(j)) {
3436       result_list.push(_interfaces.at(i));
3437       i++;
3438       j++;
3439     }
3440   }
3441   const TypeInterfaces* result = TypeInterfaces::make(&result_list);
3442 #ifdef ASSERT
3443   result->verify();
3444   for (int i = 0; i < _interfaces.length(); i++) {
3445     assert(!other->_interfaces.contains(_interfaces.at(i)) || result->_interfaces.contains(_interfaces.at(i)), "missing");
3446   }
3447   for (int i = 0; i < other->_interfaces.length(); i++) {
3448     assert(!_interfaces.contains(other->_interfaces.at(i)) || result->_interfaces.contains(other->_interfaces.at(i)), "missing");
3449   }
3450   for (int i = 0; i < result->_interfaces.length(); i++) {
3451     assert(_interfaces.contains(result->_interfaces.at(i)) && other->_interfaces.contains(result->_interfaces.at(i)), "missing");
3452   }
3453 #endif
3454   return result;
3455 }
3456 
3457 // Is there a single ciKlass* that can represent the interface set?
3458 ciInstanceKlass* TypeInterfaces::exact_klass() const {
3459   assert(_initialized, "must be");
3460   return _exact_klass;
3461 }
3462 
3463 void TypeInterfaces::compute_exact_klass() {
3464   if (_interfaces.length() == 0) {
3465     _exact_klass = nullptr;
3466     return;
3467   }
3468   ciInstanceKlass* res = nullptr;
3469   for (int i = 0; i < _interfaces.length(); i++) {
3470     ciInstanceKlass* interface = _interfaces.at(i);
3471     if (eq(interface)) {
3472       assert(res == nullptr, "");
3473       res = interface;
3474     }
3475   }
3476   _exact_klass = res;
3477 }
3478 
3479 #ifdef ASSERT
3480 void TypeInterfaces::verify_is_loaded() const {
3481   for (int i = 0; i < _interfaces.length(); i++) {
3482     ciKlass* interface = _interfaces.at(i);
3483     assert(interface->is_loaded(), "Interface not loaded");
3484   }
3485 }
3486 #endif
3487 
3488 // Can't be implemented because there's no way to know if the type is above or below the center line.
3489 const Type* TypeInterfaces::xmeet(const Type* t) const {
3490   ShouldNotReachHere();
3491   return Type::xmeet(t);
3492 }
3493 
3494 bool TypeInterfaces::singleton(void) const {
3495   ShouldNotReachHere();
3496   return Type::singleton();
3497 }
3498 
3499 //------------------------------TypeOopPtr-------------------------------------
3500 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int offset,
3501                        int instance_id, const TypePtr* speculative, int inline_depth)
3502   : TypePtr(t, ptr, offset, speculative, inline_depth),
3503     _const_oop(o), _klass(k),
3504     _interfaces(interfaces),
3505     _klass_is_exact(xk),
3506     _is_ptr_to_narrowoop(false),
3507     _is_ptr_to_narrowklass(false),
3508     _is_ptr_to_boxed_value(false),
3509     _instance_id(instance_id) {
3510 #ifdef ASSERT
3511   if (klass() != nullptr && klass()->is_loaded()) {
3512     interfaces->verify_is_loaded();
3513   }
3514 #endif
3515   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3516       (offset > 0) && xk && (k != nullptr) && k->is_instance_klass()) {
3517     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset);
3518   }
3519 #ifdef _LP64
3520   if (_offset > 0 || _offset == Type::OffsetTop || _offset == Type::OffsetBot) {
3521     if (_offset == oopDesc::klass_offset_in_bytes()) {
3522       _is_ptr_to_narrowklass = UseCompressedClassPointers;
3523     } else if (klass() == nullptr) {
3524       // Array with unknown body type
3525       assert(this->isa_aryptr(), "only arrays without klass");
3526       _is_ptr_to_narrowoop = UseCompressedOops;
3527     } else if (this->isa_aryptr()) {
3528       _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() &&
3529                              _offset != arrayOopDesc::length_offset_in_bytes());
3530     } else if (klass()->is_instance_klass()) {
3531       ciInstanceKlass* ik = klass()->as_instance_klass();
3532       if (this->isa_klassptr()) {
3533         // Perm objects don't use compressed references
3534       } else if (_offset == OffsetBot || _offset == OffsetTop) {
3535         // unsafe access
3536         _is_ptr_to_narrowoop = UseCompressedOops;
3537       } else {
3538         assert(this->isa_instptr(), "must be an instance ptr.");
3539 
3540         if (klass() == ciEnv::current()->Class_klass() &&
3541             (_offset == java_lang_Class::klass_offset() ||
3542              _offset == java_lang_Class::array_klass_offset())) {
3543           // Special hidden fields from the Class.
3544           assert(this->isa_instptr(), "must be an instance ptr.");
3545           _is_ptr_to_narrowoop = false;
3546         } else if (klass() == ciEnv::current()->Class_klass() &&
3547                    _offset >= InstanceMirrorKlass::offset_of_static_fields()) {
3548           // Static fields
3549           ciField* field = nullptr;
3550           if (const_oop() != nullptr) {
3551             ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3552             field = k->get_field_by_offset(_offset, true);
3553           }
3554           if (field != nullptr) {
3555             BasicType basic_elem_type = field->layout_type();
3556             _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3557           } else {
3558             // unsafe access
3559             _is_ptr_to_narrowoop = UseCompressedOops;
3560           }
3561         } else {
3562           // Instance fields which contains a compressed oop references.
3563           ciField* field = ik->get_field_by_offset(_offset, false);
3564           if (field != nullptr) {
3565             BasicType basic_elem_type = field->layout_type();
3566             _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3567           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3568             // Compile::find_alias_type() cast exactness on all types to verify
3569             // that it does not affect alias type.
3570             _is_ptr_to_narrowoop = UseCompressedOops;
3571           } else {
3572             // Type for the copy start in LibraryCallKit::inline_native_clone().
3573             _is_ptr_to_narrowoop = UseCompressedOops;
3574           }
3575         }
3576       }
3577     }
3578   }
3579 #endif
3580 }
3581 
3582 //------------------------------make-------------------------------------------
3583 const TypeOopPtr *TypeOopPtr::make(PTR ptr, int offset, int instance_id,
3584                                      const TypePtr* speculative, int inline_depth) {
3585   assert(ptr != Constant, "no constant generic pointers");
3586   ciKlass*  k = Compile::current()->env()->Object_klass();
3587   bool      xk = false;
3588   ciObject* o = nullptr;
3589   const TypeInterfaces* interfaces = TypeInterfaces::make();
3590   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, interfaces, xk, o, offset, instance_id, speculative, inline_depth))->hashcons();
3591 }
3592 
3593 
3594 //------------------------------cast_to_ptr_type-------------------------------
3595 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3596   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3597   if( ptr == _ptr ) return this;
3598   return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3599 }
3600 
3601 //-----------------------------cast_to_instance_id----------------------------
3602 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3603   // There are no instances of a general oop.
3604   // Return self unchanged.
3605   return this;
3606 }
3607 
3608 //-----------------------------cast_to_exactness-------------------------------
3609 const TypeOopPtr* TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3610   // There is no such thing as an exact general oop.
3611   // Return self unchanged.
3612   return this;
3613 }
3614 
3615 
3616 //------------------------------as_klass_type----------------------------------
3617 // Return the klass type corresponding to this instance or array type.
3618 // It is the type that is loaded from an object of this type.
3619 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3620   ShouldNotReachHere();
3621   return nullptr;
3622 }
3623 
3624 //------------------------------meet-------------------------------------------
3625 // Compute the MEET of two types.  It returns a new Type object.
3626 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3627   // Perform a fast test for common case; meeting the same types together.
3628   if( this == t ) return this;  // Meeting same type-rep?
3629 
3630   // Current "this->_base" is OopPtr
3631   switch (t->base()) {          // switch on original type
3632 
3633   case Int:                     // Mixing ints & oops happens when javac
3634   case Long:                    // reuses local variables
3635   case FloatTop:
3636   case FloatCon:
3637   case FloatBot:
3638   case DoubleTop:
3639   case DoubleCon:
3640   case DoubleBot:
3641   case NarrowOop:
3642   case NarrowKlass:
3643   case Bottom:                  // Ye Olde Default
3644     return Type::BOTTOM;
3645   case Top:
3646     return this;
3647 
3648   default:                      // All else is a mistake
3649     typerr(t);
3650 
3651   case RawPtr:
3652   case MetadataPtr:
3653   case KlassPtr:
3654   case InstKlassPtr:
3655   case AryKlassPtr:
3656     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3657 
3658   case AnyPtr: {
3659     // Found an AnyPtr type vs self-OopPtr type
3660     const TypePtr *tp = t->is_ptr();
3661     int offset = meet_offset(tp->offset());
3662     PTR ptr = meet_ptr(tp->ptr());
3663     const TypePtr* speculative = xmeet_speculative(tp);
3664     int depth = meet_inline_depth(tp->inline_depth());
3665     switch (tp->ptr()) {
3666     case Null:
3667       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3668       // else fall through:
3669     case TopPTR:
3670     case AnyNull: {
3671       int instance_id = meet_instance_id(InstanceTop);
3672       return make(ptr, offset, instance_id, speculative, depth);
3673     }
3674     case BotPTR:
3675     case NotNull:
3676       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3677     default: typerr(t);
3678     }
3679   }
3680 
3681   case OopPtr: {                 // Meeting to other OopPtrs
3682     const TypeOopPtr *tp = t->is_oopptr();
3683     int instance_id = meet_instance_id(tp->instance_id());
3684     const TypePtr* speculative = xmeet_speculative(tp);
3685     int depth = meet_inline_depth(tp->inline_depth());
3686     return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3687   }
3688 
3689   case InstPtr:                  // For these, flip the call around to cut down
3690   case AryPtr:
3691     return t->xmeet(this);      // Call in reverse direction
3692 
3693   } // End of switch
3694   return this;                  // Return the double constant
3695 }
3696 
3697 
3698 //------------------------------xdual------------------------------------------
3699 // Dual of a pure heap pointer.  No relevant klass or oop information.
3700 const Type *TypeOopPtr::xdual() const {
3701   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3702   assert(const_oop() == nullptr,             "no constants here");
3703   return new TypeOopPtr(_base, dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
3704 }
3705 
3706 //--------------------------make_from_klass_common-----------------------------
3707 // Computes the element-type given a klass.
3708 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling) {
3709   if (klass->is_instance_klass()) {
3710     Compile* C = Compile::current();
3711     Dependencies* deps = C->dependencies();
3712     assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
3713     // Element is an instance
3714     bool klass_is_exact = false;
3715     if (klass->is_loaded()) {
3716       // Try to set klass_is_exact.
3717       ciInstanceKlass* ik = klass->as_instance_klass();
3718       klass_is_exact = ik->is_final();
3719       if (!klass_is_exact && klass_change
3720           && deps != nullptr && UseUniqueSubclasses) {
3721         ciInstanceKlass* sub = ik->unique_concrete_subklass();
3722         if (sub != nullptr) {
3723           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3724           klass = ik = sub;
3725           klass_is_exact = sub->is_final();
3726         }
3727       }
3728       if (!klass_is_exact && try_for_exact && deps != nullptr &&
3729           !ik->is_interface() && !ik->has_subklass()) {
3730         // Add a dependence; if concrete subclass added we need to recompile
3731         deps->assert_leaf_type(ik);
3732         klass_is_exact = true;
3733       }
3734     }
3735     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
3736     return TypeInstPtr::make(TypePtr::BotPTR, klass, interfaces, klass_is_exact, nullptr, 0);
3737   } else if (klass->is_obj_array_klass()) {
3738     // Element is an object array. Recursively call ourself.
3739     ciKlass* eklass = klass->as_obj_array_klass()->element_klass();
3740     const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(eklass, false, try_for_exact, interface_handling);
3741     bool xk = etype->klass_is_exact();
3742     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3743     // We used to pass NotNull in here, asserting that the sub-arrays
3744     // are all not-null.  This is not true in generally, as code can
3745     // slam nulls down in the subarrays.
3746     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, nullptr, xk, 0);
3747     return arr;
3748   } else if (klass->is_type_array_klass()) {
3749     // Element is an typeArray
3750     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3751     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3752     // We used to pass NotNull in here, asserting that the array pointer
3753     // is not-null. That was not true in general.
3754     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, 0);
3755     return arr;
3756   } else {
3757     ShouldNotReachHere();
3758     return nullptr;
3759   }
3760 }
3761 
3762 //------------------------------make_from_constant-----------------------------
3763 // Make a java pointer from an oop constant
3764 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3765   assert(!o->is_null_object(), "null object not yet handled here.");
3766 
3767   const bool make_constant = require_constant || o->should_be_constant();
3768 
3769   ciKlass* klass = o->klass();
3770   if (klass->is_instance_klass()) {
3771     // Element is an instance
3772     if (make_constant) {
3773       return TypeInstPtr::make(o);
3774     } else {
3775       return TypeInstPtr::make(TypePtr::NotNull, klass, true, nullptr, 0);
3776     }
3777   } else if (klass->is_obj_array_klass()) {
3778     // Element is an object array. Recursively call ourself.
3779     const TypeOopPtr *etype =
3780       TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass(), trust_interfaces);
3781     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3782     // We used to pass NotNull in here, asserting that the sub-arrays
3783     // are all not-null.  This is not true in generally, as code can
3784     // slam nulls down in the subarrays.
3785     if (make_constant) {
3786       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3787     } else {
3788       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
3789     }
3790   } else if (klass->is_type_array_klass()) {
3791     // Element is an typeArray
3792     const Type* etype =
3793       (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3794     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3795     // We used to pass NotNull in here, asserting that the array pointer
3796     // is not-null. That was not true in general.
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   }
3803 
3804   fatal("unhandled object type");
3805   return nullptr;
3806 }
3807 
3808 //------------------------------get_con----------------------------------------
3809 intptr_t TypeOopPtr::get_con() const {
3810   assert( _ptr == Null || _ptr == Constant, "" );
3811   assert( _offset >= 0, "" );
3812 
3813   if (_offset != 0) {
3814     // After being ported to the compiler interface, the compiler no longer
3815     // directly manipulates the addresses of oops.  Rather, it only has a pointer
3816     // to a handle at compile time.  This handle is embedded in the generated
3817     // code and dereferenced at the time the nmethod is made.  Until that time,
3818     // it is not reasonable to do arithmetic with the addresses of oops (we don't
3819     // have access to the addresses!).  This does not seem to currently happen,
3820     // but this assertion here is to help prevent its occurrence.
3821     tty->print_cr("Found oop constant with non-zero offset");
3822     ShouldNotReachHere();
3823   }
3824 
3825   return (intptr_t)const_oop()->constant_encoding();
3826 }
3827 
3828 
3829 //-----------------------------filter------------------------------------------
3830 // Do not allow interface-vs.-noninterface joins to collapse to top.
3831 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
3832 
3833   const Type* ft = join_helper(kills, include_speculative);
3834   const TypeInstPtr* ftip = ft->isa_instptr();
3835   const TypeInstPtr* ktip = kills->isa_instptr();
3836 
3837   if (ft->empty()) {
3838     return Type::TOP;           // Canonical empty value
3839   }
3840 
3841   return ft;
3842 }
3843 
3844 //------------------------------eq---------------------------------------------
3845 // Structural equality check for Type representations
3846 bool TypeOopPtr::eq( const Type *t ) const {
3847   const TypeOopPtr *a = (const TypeOopPtr*)t;
3848   if (_klass_is_exact != a->_klass_is_exact ||
3849       _instance_id != a->_instance_id)  return false;
3850   ciObject* one = const_oop();
3851   ciObject* two = a->const_oop();
3852   if (one == nullptr || two == nullptr) {
3853     return (one == two) && TypePtr::eq(t);
3854   } else {
3855     return one->equals(two) && TypePtr::eq(t);
3856   }
3857 }
3858 
3859 //------------------------------hash-------------------------------------------
3860 // Type-specific hashing function.
3861 uint TypeOopPtr::hash(void) const {
3862   return
3863     (uint)(const_oop() ? const_oop()->hash() : 0) +
3864     (uint)_klass_is_exact +
3865     (uint)_instance_id + TypePtr::hash();
3866 }
3867 
3868 //------------------------------dump2------------------------------------------
3869 #ifndef PRODUCT
3870 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3871   st->print("oopptr:%s", ptr_msg[_ptr]);
3872   if( _klass_is_exact ) st->print(":exact");
3873   if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
3874   switch( _offset ) {
3875   case OffsetTop: st->print("+top"); break;
3876   case OffsetBot: st->print("+any"); break;
3877   case         0: break;
3878   default:        st->print("+%d",_offset); break;
3879   }
3880   if (_instance_id == InstanceTop)
3881     st->print(",iid=top");
3882   else if (_instance_id != InstanceBot)
3883     st->print(",iid=%d",_instance_id);
3884 
3885   dump_inline_depth(st);
3886   dump_speculative(st);
3887 }
3888 #endif
3889 
3890 //------------------------------singleton--------------------------------------
3891 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3892 // constants
3893 bool TypeOopPtr::singleton(void) const {
3894   // detune optimizer to not generate constant oop + constant offset as a constant!
3895   // TopPTR, Null, AnyNull, Constant are all singletons
3896   return (_offset == 0) && !below_centerline(_ptr);
3897 }
3898 
3899 //------------------------------add_offset-------------------------------------
3900 const TypePtr* TypeOopPtr::add_offset(intptr_t offset) const {
3901   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
3902 }
3903 
3904 const TypeOopPtr* TypeOopPtr::with_offset(intptr_t offset) const {
3905   return make(_ptr, offset, _instance_id, with_offset_speculative(offset), _inline_depth);
3906 }
3907 
3908 /**
3909  * Return same type without a speculative part
3910  */
3911 const TypeOopPtr* TypeOopPtr::remove_speculative() const {
3912   if (_speculative == nullptr) {
3913     return this;
3914   }
3915   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
3916   return make(_ptr, _offset, _instance_id, nullptr, _inline_depth);
3917 }
3918 
3919 /**
3920  * Return same type but drop speculative part if we know we won't use
3921  * it
3922  */
3923 const Type* TypeOopPtr::cleanup_speculative() const {
3924   // If the klass is exact and the ptr is not null then there's
3925   // nothing that the speculative type can help us with
3926   if (klass_is_exact() && !maybe_null()) {
3927     return remove_speculative();
3928   }
3929   return TypePtr::cleanup_speculative();
3930 }
3931 
3932 /**
3933  * Return same type but with a different inline depth (used for speculation)
3934  *
3935  * @param depth  depth to meet with
3936  */
3937 const TypePtr* TypeOopPtr::with_inline_depth(int depth) const {
3938   if (!UseInlineDepthForSpeculativeTypes) {
3939     return this;
3940   }
3941   return make(_ptr, _offset, _instance_id, _speculative, depth);
3942 }
3943 
3944 //------------------------------with_instance_id--------------------------------
3945 const TypePtr* TypeOopPtr::with_instance_id(int instance_id) const {
3946   assert(_instance_id != -1, "should be known");
3947   return make(_ptr, _offset, instance_id, _speculative, _inline_depth);
3948 }
3949 
3950 //------------------------------meet_instance_id--------------------------------
3951 int TypeOopPtr::meet_instance_id( int instance_id ) const {
3952   // Either is 'TOP' instance?  Return the other instance!
3953   if( _instance_id == InstanceTop ) return  instance_id;
3954   if(  instance_id == InstanceTop ) return _instance_id;
3955   // If either is different, return 'BOTTOM' instance
3956   if( _instance_id != instance_id ) return InstanceBot;
3957   return _instance_id;
3958 }
3959 
3960 //------------------------------dual_instance_id--------------------------------
3961 int TypeOopPtr::dual_instance_id( ) const {
3962   if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM
3963   if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP
3964   return _instance_id;              // Map everything else into self
3965 }
3966 
3967 
3968 const TypeInterfaces* TypeOopPtr::meet_interfaces(const TypeOopPtr* other) const {
3969   if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
3970     return _interfaces->union_with(other->_interfaces);
3971   } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
3972     return other->_interfaces;
3973   } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
3974     return _interfaces;
3975   }
3976   return _interfaces->intersection_with(other->_interfaces);
3977 }
3978 
3979 /**
3980  * Check whether new profiling would improve speculative type
3981  *
3982  * @param   exact_kls    class from profiling
3983  * @param   inline_depth inlining depth of profile point
3984  *
3985  * @return  true if type profile is valuable
3986  */
3987 bool TypeOopPtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
3988   // no way to improve an already exact type
3989   if (klass_is_exact()) {
3990     return false;
3991   }
3992   return TypePtr::would_improve_type(exact_kls, inline_depth);
3993 }
3994 
3995 //=============================================================================
3996 // Convenience common pre-built types.
3997 const TypeInstPtr *TypeInstPtr::NOTNULL;
3998 const TypeInstPtr *TypeInstPtr::BOTTOM;
3999 const TypeInstPtr *TypeInstPtr::MIRROR;
4000 const TypeInstPtr *TypeInstPtr::MARK;
4001 const TypeInstPtr *TypeInstPtr::KLASS;
4002 
4003 // Is there a single ciKlass* that can represent that type?
4004 ciKlass* TypeInstPtr::exact_klass_helper() const {
4005   if (_interfaces->empty()) {
4006     return _klass;
4007   }
4008   if (_klass != ciEnv::current()->Object_klass()) {
4009     if (_interfaces->eq(_klass->as_instance_klass())) {
4010       return _klass;
4011     }
4012     return nullptr;
4013   }
4014   return _interfaces->exact_klass();
4015 }
4016 
4017 //------------------------------TypeInstPtr-------------------------------------
4018 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int off,
4019                          int instance_id, const TypePtr* speculative, int inline_depth)
4020   : TypeOopPtr(InstPtr, ptr, k, interfaces, xk, o, off, instance_id, speculative, inline_depth) {
4021   assert(k == nullptr || !k->is_loaded() || !k->is_interface(), "no interface here");
4022   assert(k != nullptr &&
4023          (k->is_loaded() || o == nullptr),
4024          "cannot have constants with non-loaded klass");
4025 };
4026 
4027 //------------------------------make-------------------------------------------
4028 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
4029                                      ciKlass* k,
4030                                      const TypeInterfaces* interfaces,
4031                                      bool xk,
4032                                      ciObject* o,
4033                                      int offset,
4034                                      int instance_id,
4035                                      const TypePtr* speculative,
4036                                      int inline_depth) {
4037   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
4038   // Either const_oop() is null or else ptr is Constant
4039   assert( (!o && ptr != Constant) || (o && ptr == Constant),
4040           "constant pointers must have a value supplied" );
4041   // Ptr is never Null
4042   assert( ptr != Null, "null pointers are not typed" );
4043 
4044   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4045   if (ptr == Constant) {
4046     // Note:  This case includes meta-object constants, such as methods.
4047     xk = true;
4048   } else if (k->is_loaded()) {
4049     ciInstanceKlass* ik = k->as_instance_klass();
4050     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
4051     assert(!ik->is_interface(), "no interface here");
4052     if (xk && ik->is_interface())  xk = false;  // no exact interface
4053   }
4054 
4055   // Now hash this baby
4056   TypeInstPtr *result =
4057     (TypeInstPtr*)(new TypeInstPtr(ptr, k, interfaces, xk, o ,offset, instance_id, speculative, inline_depth))->hashcons();
4058 
4059   return result;
4060 }
4061 
4062 const TypeInterfaces* TypePtr::interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling) {
4063   if (k->is_instance_klass()) {
4064     if (k->is_loaded()) {
4065       if (k->is_interface() && interface_handling == ignore_interfaces) {
4066         assert(interface, "no interface expected");
4067         k = ciEnv::current()->Object_klass();
4068         const TypeInterfaces* interfaces = TypeInterfaces::make();
4069         return interfaces;
4070       }
4071       GrowableArray<ciInstanceKlass *>* k_interfaces = k->as_instance_klass()->transitive_interfaces();
4072       const TypeInterfaces* interfaces = TypeInterfaces::make(k_interfaces);
4073       if (k->is_interface()) {
4074         assert(interface, "no interface expected");
4075         k = ciEnv::current()->Object_klass();
4076       } else {
4077         assert(klass, "no instance klass expected");
4078       }
4079       return interfaces;
4080     }
4081     const TypeInterfaces* interfaces = TypeInterfaces::make();
4082     return interfaces;
4083   }
4084   assert(array, "no array expected");
4085   assert(k->is_array_klass(), "Not an array?");
4086   ciType* e = k->as_array_klass()->base_element_type();
4087   if (e->is_loaded() && e->is_instance_klass() && e->as_instance_klass()->is_interface()) {
4088     if (interface_handling == ignore_interfaces) {
4089       k = ciObjArrayKlass::make(ciEnv::current()->Object_klass(), k->as_array_klass()->dimension());
4090     }
4091   }
4092   return TypeAryPtr::_array_interfaces;
4093 }
4094 
4095 /**
4096  *  Create constant type for a constant boxed value
4097  */
4098 const Type* TypeInstPtr::get_const_boxed_value() const {
4099   assert(is_ptr_to_boxed_value(), "should be called only for boxed value");
4100   assert((const_oop() != nullptr), "should be called only for constant object");
4101   ciConstant constant = const_oop()->as_instance()->field_value_by_offset(offset());
4102   BasicType bt = constant.basic_type();
4103   switch (bt) {
4104     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
4105     case T_INT:      return TypeInt::make(constant.as_int());
4106     case T_CHAR:     return TypeInt::make(constant.as_char());
4107     case T_BYTE:     return TypeInt::make(constant.as_byte());
4108     case T_SHORT:    return TypeInt::make(constant.as_short());
4109     case T_FLOAT:    return TypeF::make(constant.as_float());
4110     case T_DOUBLE:   return TypeD::make(constant.as_double());
4111     case T_LONG:     return TypeLong::make(constant.as_long());
4112     default:         break;
4113   }
4114   fatal("Invalid boxed value type '%s'", type2name(bt));
4115   return nullptr;
4116 }
4117 
4118 //------------------------------cast_to_ptr_type-------------------------------
4119 const TypeInstPtr* TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
4120   if( ptr == _ptr ) return this;
4121   // Reconstruct _sig info here since not a problem with later lazy
4122   // construction, _sig will show up on demand.
4123   return make(ptr, klass(), _interfaces, klass_is_exact(), ptr == Constant ? const_oop() : nullptr, _offset, _instance_id, _speculative, _inline_depth);
4124 }
4125 
4126 
4127 //-----------------------------cast_to_exactness-------------------------------
4128 const TypeInstPtr* TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
4129   if( klass_is_exact == _klass_is_exact ) return this;
4130   if (!_klass->is_loaded())  return this;
4131   ciInstanceKlass* ik = _klass->as_instance_klass();
4132   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
4133   assert(!ik->is_interface(), "no interface here");
4134   return make(ptr(), klass(), _interfaces, klass_is_exact, const_oop(), _offset, _instance_id, _speculative, _inline_depth);
4135 }
4136 
4137 //-----------------------------cast_to_instance_id----------------------------
4138 const TypeInstPtr* TypeInstPtr::cast_to_instance_id(int instance_id) const {
4139   if( instance_id == _instance_id ) return this;
4140   return make(_ptr, klass(),  _interfaces, _klass_is_exact, const_oop(), _offset, instance_id, _speculative, _inline_depth);
4141 }
4142 
4143 //------------------------------xmeet_unloaded---------------------------------
4144 // Compute the MEET of two InstPtrs when at least one is unloaded.
4145 // Assume classes are different since called after check for same name/class-loader
4146 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst, const TypeInterfaces* interfaces) const {
4147   int off = meet_offset(tinst->offset());
4148   PTR ptr = meet_ptr(tinst->ptr());
4149   int instance_id = meet_instance_id(tinst->instance_id());
4150   const TypePtr* speculative = xmeet_speculative(tinst);
4151   int depth = meet_inline_depth(tinst->inline_depth());
4152 
4153   const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
4154   const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
4155   if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
4156     //
4157     // Meet unloaded class with java/lang/Object
4158     //
4159     // Meet
4160     //          |                     Unloaded Class
4161     //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
4162     //  ===================================================================
4163     //   TOP    | ..........................Unloaded......................|
4164     //  AnyNull |  U-AN    |................Unloaded......................|
4165     // Constant | ... O-NN .................................. |   O-BOT   |
4166     //  NotNull | ... O-NN .................................. |   O-BOT   |
4167     //  BOTTOM  | ........................Object-BOTTOM ..................|
4168     //
4169     assert(loaded->ptr() != TypePtr::Null, "insanity check");
4170     //
4171     if (loaded->ptr() == TypePtr::TopPTR)        { return unloaded->with_speculative(speculative); }
4172     else if (loaded->ptr() == TypePtr::AnyNull)  { return make(ptr, unloaded->klass(), interfaces, false, nullptr, off, instance_id, speculative, depth); }
4173     else if (loaded->ptr() == TypePtr::BotPTR)   { return TypeInstPtr::BOTTOM->with_speculative(speculative); }
4174     else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
4175       if (unloaded->ptr() == TypePtr::BotPTR)    { return TypeInstPtr::BOTTOM->with_speculative(speculative);  }
4176       else                                       { return TypeInstPtr::NOTNULL->with_speculative(speculative); }
4177     }
4178     else if (unloaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); }
4179 
4180     return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr()->with_speculative(speculative);
4181   }
4182 
4183   // Both are unloaded, not the same class, not Object
4184   // Or meet unloaded with a different loaded class, not java/lang/Object
4185   if (ptr != TypePtr::BotPTR) {
4186     return TypeInstPtr::NOTNULL->with_speculative(speculative);
4187   }
4188   return TypeInstPtr::BOTTOM->with_speculative(speculative);
4189 }
4190 
4191 
4192 //------------------------------meet-------------------------------------------
4193 // Compute the MEET of two types.  It returns a new Type object.
4194 const Type *TypeInstPtr::xmeet_helper(const Type *t) const {
4195   // Perform a fast test for common case; meeting the same types together.
4196   if( this == t ) return this;  // Meeting same type-rep?
4197 
4198   // Current "this->_base" is Pointer
4199   switch (t->base()) {          // switch on original type
4200 
4201   case Int:                     // Mixing ints & oops happens when javac
4202   case Long:                    // reuses local variables
4203   case FloatTop:
4204   case FloatCon:
4205   case FloatBot:
4206   case DoubleTop:
4207   case DoubleCon:
4208   case DoubleBot:
4209   case NarrowOop:
4210   case NarrowKlass:
4211   case Bottom:                  // Ye Olde Default
4212     return Type::BOTTOM;
4213   case Top:
4214     return this;
4215 
4216   default:                      // All else is a mistake
4217     typerr(t);
4218 
4219   case MetadataPtr:
4220   case KlassPtr:
4221   case InstKlassPtr:
4222   case AryKlassPtr:
4223   case RawPtr: return TypePtr::BOTTOM;
4224 
4225   case AryPtr: {                // All arrays inherit from Object class
4226     // Call in reverse direction to avoid duplication
4227     return t->is_aryptr()->xmeet_helper(this);
4228   }
4229 
4230   case OopPtr: {                // Meeting to OopPtrs
4231     // Found a OopPtr type vs self-InstPtr type
4232     const TypeOopPtr *tp = t->is_oopptr();
4233     int offset = meet_offset(tp->offset());
4234     PTR ptr = meet_ptr(tp->ptr());
4235     switch (tp->ptr()) {
4236     case TopPTR:
4237     case AnyNull: {
4238       int instance_id = meet_instance_id(InstanceTop);
4239       const TypePtr* speculative = xmeet_speculative(tp);
4240       int depth = meet_inline_depth(tp->inline_depth());
4241       return make(ptr, klass(), _interfaces, klass_is_exact(),
4242                   (ptr == Constant ? const_oop() : nullptr), offset, instance_id, speculative, depth);
4243     }
4244     case NotNull:
4245     case BotPTR: {
4246       int instance_id = meet_instance_id(tp->instance_id());
4247       const TypePtr* speculative = xmeet_speculative(tp);
4248       int depth = meet_inline_depth(tp->inline_depth());
4249       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4250     }
4251     default: typerr(t);
4252     }
4253   }
4254 
4255   case AnyPtr: {                // Meeting to AnyPtrs
4256     // Found an AnyPtr type vs self-InstPtr type
4257     const TypePtr *tp = t->is_ptr();
4258     int offset = meet_offset(tp->offset());
4259     PTR ptr = meet_ptr(tp->ptr());
4260     int instance_id = meet_instance_id(InstanceTop);
4261     const TypePtr* speculative = xmeet_speculative(tp);
4262     int depth = meet_inline_depth(tp->inline_depth());
4263     switch (tp->ptr()) {
4264     case Null:
4265       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4266       // else fall through to AnyNull
4267     case TopPTR:
4268     case AnyNull: {
4269       return make(ptr, klass(), _interfaces, klass_is_exact(),
4270                   (ptr == Constant ? const_oop() : nullptr), offset, instance_id, speculative, depth);
4271     }
4272     case NotNull:
4273     case BotPTR:
4274       return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4275     default: typerr(t);
4276     }
4277   }
4278 
4279   /*
4280                  A-top         }
4281                /   |   \       }  Tops
4282            B-top A-any C-top   }
4283               | /  |  \ |      }  Any-nulls
4284            B-any   |   C-any   }
4285               |    |    |
4286            B-con A-con C-con   } constants; not comparable across classes
4287               |    |    |
4288            B-not   |   C-not   }
4289               | \  |  / |      }  not-nulls
4290            B-bot A-not C-bot   }
4291                \   |   /       }  Bottoms
4292                  A-bot         }
4293   */
4294 
4295   case InstPtr: {                // Meeting 2 Oops?
4296     // Found an InstPtr sub-type vs self-InstPtr type
4297     const TypeInstPtr *tinst = t->is_instptr();
4298     int off = meet_offset(tinst->offset());
4299     PTR ptr = meet_ptr(tinst->ptr());
4300     int instance_id = meet_instance_id(tinst->instance_id());
4301     const TypePtr* speculative = xmeet_speculative(tinst);
4302     int depth = meet_inline_depth(tinst->inline_depth());
4303     const TypeInterfaces* interfaces = meet_interfaces(tinst);
4304 
4305     ciKlass* tinst_klass = tinst->klass();
4306     ciKlass* this_klass  = klass();
4307 
4308     ciKlass* res_klass = nullptr;
4309     bool res_xk = false;
4310     const Type* res;
4311     MeetResult kind = meet_instptr(ptr, interfaces, this, tinst, res_klass, res_xk);
4312 
4313     if (kind == UNLOADED) {
4314       // One of these classes has not been loaded
4315       const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst, interfaces);
4316 #ifndef PRODUCT
4317       if (PrintOpto && Verbose) {
4318         tty->print("meet of unloaded classes resulted in: ");
4319         unloaded_meet->dump();
4320         tty->cr();
4321         tty->print("  this == ");
4322         dump();
4323         tty->cr();
4324         tty->print(" tinst == ");
4325         tinst->dump();
4326         tty->cr();
4327       }
4328 #endif
4329       res = unloaded_meet;
4330     } else {
4331       if (kind == NOT_SUBTYPE && instance_id > 0) {
4332         instance_id = InstanceBot;
4333       } else if (kind == LCA) {
4334         instance_id = InstanceBot;
4335       }
4336       ciObject* o = nullptr;             // Assume not constant when done
4337       ciObject* this_oop = const_oop();
4338       ciObject* tinst_oop = tinst->const_oop();
4339       if (ptr == Constant) {
4340         if (this_oop != nullptr && tinst_oop != nullptr &&
4341             this_oop->equals(tinst_oop))
4342           o = this_oop;
4343         else if (above_centerline(_ptr)) {
4344           assert(!tinst_klass->is_interface(), "");
4345           o = tinst_oop;
4346         } else if (above_centerline(tinst->_ptr)) {
4347           assert(!this_klass->is_interface(), "");
4348           o = this_oop;
4349         } else
4350           ptr = NotNull;
4351       }
4352       res = make(ptr, res_klass, interfaces, res_xk, o, off, instance_id, speculative, depth);
4353     }
4354 
4355     return res;
4356 
4357   } // End of case InstPtr
4358 
4359   } // End of switch
4360   return this;                  // Return the double constant
4361 }
4362 
4363 template<class T> TypePtr::MeetResult TypePtr::meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type, const T* other_type,
4364                                                             ciKlass*& res_klass, bool& res_xk) {
4365   ciKlass* this_klass = this_type->klass();
4366   ciKlass* other_klass = other_type->klass();
4367   bool this_xk = this_type->klass_is_exact();
4368   bool other_xk = other_type->klass_is_exact();
4369   PTR this_ptr = this_type->ptr();
4370   PTR other_ptr = other_type->ptr();
4371   const TypeInterfaces* this_interfaces = this_type->interfaces();
4372   const TypeInterfaces* other_interfaces = other_type->interfaces();
4373   // Check for easy case; klasses are equal (and perhaps not loaded!)
4374   // If we have constants, then we created oops so classes are loaded
4375   // and we can handle the constants further down.  This case handles
4376   // both-not-loaded or both-loaded classes
4377   if (ptr != Constant && this_klass->equals(other_klass) && this_xk == other_xk) {
4378     res_klass = this_klass;
4379     res_xk = this_xk;
4380     return QUICK;
4381   }
4382 
4383   // Classes require inspection in the Java klass hierarchy.  Must be loaded.
4384   if (!other_klass->is_loaded() || !this_klass->is_loaded()) {
4385     return UNLOADED;
4386   }
4387 
4388   // !!! Here's how the symmetry requirement breaks down into invariants:
4389   // If we split one up & one down AND they subtype, take the down man.
4390   // If we split one up & one down AND they do NOT subtype, "fall hard".
4391   // If both are up and they subtype, take the subtype class.
4392   // If both are up and they do NOT subtype, "fall hard".
4393   // If both are down and they subtype, take the supertype class.
4394   // If both are down and they do NOT subtype, "fall hard".
4395   // Constants treated as down.
4396 
4397   // Now, reorder the above list; observe that both-down+subtype is also
4398   // "fall hard"; "fall hard" becomes the default case:
4399   // If we split one up & one down AND they subtype, take the down man.
4400   // If both are up and they subtype, take the subtype class.
4401 
4402   // If both are down and they subtype, "fall hard".
4403   // If both are down and they do NOT subtype, "fall hard".
4404   // If both are up and they do NOT subtype, "fall hard".
4405   // If we split one up & one down AND they do NOT subtype, "fall hard".
4406 
4407   // If a proper subtype is exact, and we return it, we return it exactly.
4408   // If a proper supertype is exact, there can be no subtyping relationship!
4409   // If both types are equal to the subtype, exactness is and-ed below the
4410   // centerline and or-ed above it.  (N.B. Constants are always exact.)
4411 
4412   // Check for subtyping:
4413   const T* subtype = nullptr;
4414   bool subtype_exact = false;
4415   if (this_type->is_same_java_type_as(other_type)) {
4416     subtype = this_type;
4417     subtype_exact = below_centerline(ptr) ? (this_xk && other_xk) : (this_xk || other_xk);
4418   } else if (!other_xk && this_type->is_meet_subtype_of(other_type)) {
4419     subtype = this_type;     // Pick subtyping class
4420     subtype_exact = this_xk;
4421   } else if(!this_xk && other_type->is_meet_subtype_of(this_type)) {
4422     subtype = other_type;    // Pick subtyping class
4423     subtype_exact = other_xk;
4424   }
4425 
4426   if (subtype) {
4427     if (above_centerline(ptr)) { // both are up?
4428       this_type = other_type = subtype;
4429       this_xk = other_xk = subtype_exact;
4430     } else if (above_centerline(this_ptr) && !above_centerline(other_ptr)) {
4431       this_type = other_type; // tinst is down; keep down man
4432       this_xk = other_xk;
4433     } else if (above_centerline(other_ptr) && !above_centerline(this_ptr)) {
4434       other_type = this_type; // this is down; keep down man
4435       other_xk = this_xk;
4436     } else {
4437       this_xk = subtype_exact;  // either they are equal, or we'll do an LCA
4438     }
4439   }
4440 
4441   // Check for classes now being equal
4442   if (this_type->is_same_java_type_as(other_type)) {
4443     // If the klasses are equal, the constants may still differ.  Fall to
4444     // NotNull if they do (neither constant is null; that is a special case
4445     // handled elsewhere).
4446     res_klass = this_type->klass();
4447     res_xk = this_xk;
4448     return SUBTYPE;
4449   } // Else classes are not equal
4450 
4451   // Since klasses are different, we require a LCA in the Java
4452   // class hierarchy - which means we have to fall to at least NotNull.
4453   if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4454     ptr = NotNull;
4455   }
4456 
4457   interfaces = this_interfaces->intersection_with(other_interfaces);
4458 
4459   // Now we find the LCA of Java classes
4460   ciKlass* k = this_klass->least_common_ancestor(other_klass);
4461 
4462   res_klass = k;
4463   res_xk = false;
4464 
4465   return LCA;
4466 }
4467 
4468 //------------------------java_mirror_type--------------------------------------
4469 ciType* TypeInstPtr::java_mirror_type() const {
4470   // must be a singleton type
4471   if( const_oop() == nullptr )  return nullptr;
4472 
4473   // must be of type java.lang.Class
4474   if( klass() != ciEnv::current()->Class_klass() )  return nullptr;
4475 
4476   return const_oop()->as_instance()->java_mirror_type();
4477 }
4478 
4479 
4480 //------------------------------xdual------------------------------------------
4481 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
4482 // inheritance mechanism.
4483 const Type *TypeInstPtr::xdual() const {
4484   return new TypeInstPtr(dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4485 }
4486 
4487 //------------------------------eq---------------------------------------------
4488 // Structural equality check for Type representations
4489 bool TypeInstPtr::eq( const Type *t ) const {
4490   const TypeInstPtr *p = t->is_instptr();
4491   return
4492     klass()->equals(p->klass()) &&
4493     _interfaces->eq(p->_interfaces) &&
4494     TypeOopPtr::eq(p);          // Check sub-type stuff
4495 }
4496 
4497 //------------------------------hash-------------------------------------------
4498 // Type-specific hashing function.
4499 uint TypeInstPtr::hash(void) const {
4500   return klass()->hash() + TypeOopPtr::hash() + _interfaces->hash();
4501 }
4502 
4503 bool TypeInstPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4504   return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4505 }
4506 
4507 
4508 bool TypeInstPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4509   return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
4510 }
4511 
4512 bool TypeInstPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4513   return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4514 }
4515 
4516 
4517 //------------------------------dump2------------------------------------------
4518 // Dump oop Type
4519 #ifndef PRODUCT
4520 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {
4521   // Print the name of the klass.
4522   klass()->print_name_on(st);
4523   _interfaces->dump(st);
4524 
4525   switch( _ptr ) {
4526   case Constant:
4527     if (WizardMode || Verbose) {
4528       ResourceMark rm;
4529       stringStream ss;
4530 
4531       st->print(" ");
4532       const_oop()->print_oop(&ss);
4533       // 'const_oop->print_oop()' may emit newlines('\n') into ss.
4534       // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4535       char* buf = ss.as_string(/* c_heap= */false);
4536       StringUtils::replace_no_expand(buf, "\n", "");
4537       st->print_raw(buf);
4538     }
4539   case BotPTR:
4540     if (!WizardMode && !Verbose) {
4541       if( _klass_is_exact ) st->print(":exact");
4542       break;
4543     }
4544   case TopPTR:
4545   case AnyNull:
4546   case NotNull:
4547     st->print(":%s", ptr_msg[_ptr]);
4548     if( _klass_is_exact ) st->print(":exact");
4549     break;
4550   default:
4551     break;
4552   }
4553 
4554   if( _offset ) {               // Dump offset, if any
4555     if( _offset == OffsetBot )      st->print("+any");
4556     else if( _offset == OffsetTop ) st->print("+unknown");
4557     else st->print("+%d", _offset);
4558   }
4559 
4560   st->print(" *");
4561   if (_instance_id == InstanceTop)
4562     st->print(",iid=top");
4563   else if (_instance_id != InstanceBot)
4564     st->print(",iid=%d",_instance_id);
4565 
4566   dump_inline_depth(st);
4567   dump_speculative(st);
4568 }
4569 #endif
4570 
4571 //------------------------------add_offset-------------------------------------
4572 const TypePtr* TypeInstPtr::add_offset(intptr_t offset) const {
4573   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), xadd_offset(offset),
4574               _instance_id, add_offset_speculative(offset), _inline_depth);
4575 }
4576 
4577 const TypeInstPtr* TypeInstPtr::with_offset(intptr_t offset) const {
4578   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), offset,
4579               _instance_id, with_offset_speculative(offset), _inline_depth);
4580 }
4581 
4582 const TypeInstPtr* TypeInstPtr::remove_speculative() const {
4583   if (_speculative == nullptr) {
4584     return this;
4585   }
4586   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4587   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset,
4588               _instance_id, nullptr, _inline_depth);
4589 }
4590 
4591 const TypeInstPtr* TypeInstPtr::with_speculative(const TypePtr* speculative) const {
4592   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _instance_id, speculative, _inline_depth);
4593 }
4594 
4595 const TypePtr* TypeInstPtr::with_inline_depth(int depth) const {
4596   if (!UseInlineDepthForSpeculativeTypes) {
4597     return this;
4598   }
4599   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth);
4600 }
4601 
4602 const TypePtr* TypeInstPtr::with_instance_id(int instance_id) const {
4603   assert(is_known_instance(), "should be known");
4604   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, instance_id, _speculative, _inline_depth);
4605 }
4606 
4607 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4608   bool xk = klass_is_exact();
4609   ciInstanceKlass* ik = klass()->as_instance_klass();
4610   if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final()) {
4611     if (_interfaces->eq(ik)) {
4612       Compile* C = Compile::current();
4613       Dependencies* deps = C->dependencies();
4614       deps->assert_leaf_type(ik);
4615       xk = true;
4616     }
4617   }
4618   return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), _interfaces, 0);
4619 }
4620 
4621 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) {
4622   static_assert(std::is_base_of<T2, T1>::value, "");
4623 
4624   if (!this_one->is_instance_type(other)) {
4625     return false;
4626   }
4627 
4628   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4629     return true;
4630   }
4631 
4632   return this_one->klass()->is_subtype_of(other->klass()) &&
4633          (!this_xk || this_one->_interfaces->contains(other->_interfaces));
4634 }
4635 
4636 
4637 bool TypeInstPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4638   return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4639 }
4640 
4641 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) {
4642   static_assert(std::is_base_of<T2, T1>::value, "");
4643   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4644     return true;
4645   }
4646 
4647   if (this_one->is_instance_type(other)) {
4648     return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces);
4649   }
4650 
4651   int dummy;
4652   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
4653   if (this_top_or_bottom) {
4654     return false;
4655   }
4656 
4657   const T1* other_ary = this_one->is_array_type(other);
4658   const TypePtr* other_elem = other_ary->elem()->make_ptr();
4659   const TypePtr* this_elem = this_one->elem()->make_ptr();
4660   if (other_elem != nullptr && this_elem != nullptr) {
4661     return this_one->is_reference_type(this_elem)->is_meet_subtype_of_helper(this_one->is_reference_type(other_elem), this_xk, other_xk);
4662   }
4663 
4664   if (other_elem == nullptr && this_elem == nullptr) {
4665     return this_one->klass()->is_subtype_of(other->klass());
4666   }
4667 
4668   return false;
4669 }
4670 
4671 bool TypeAryPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4672   return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4673 }
4674 
4675 bool TypeInstKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4676   return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4677 }
4678 
4679 bool TypeAryKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4680   return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4681 }
4682 
4683 //=============================================================================
4684 // Convenience common pre-built types.
4685 const TypeAryPtr *TypeAryPtr::RANGE;
4686 const TypeAryPtr *TypeAryPtr::OOPS;
4687 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
4688 const TypeAryPtr *TypeAryPtr::BYTES;
4689 const TypeAryPtr *TypeAryPtr::SHORTS;
4690 const TypeAryPtr *TypeAryPtr::CHARS;
4691 const TypeAryPtr *TypeAryPtr::INTS;
4692 const TypeAryPtr *TypeAryPtr::LONGS;
4693 const TypeAryPtr *TypeAryPtr::FLOATS;
4694 const TypeAryPtr *TypeAryPtr::DOUBLES;
4695 
4696 //------------------------------make-------------------------------------------
4697 const TypeAryPtr *TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4698                                    int instance_id, const TypePtr* speculative, int inline_depth) {
4699   assert(!(k == nullptr && ary->_elem->isa_int()),
4700          "integral arrays must be pre-equipped with a class");
4701   if (!xk)  xk = ary->ary_must_be_exact();
4702   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4703   if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4704       k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4705     k = nullptr;
4706   }
4707   return (TypeAryPtr*)(new TypeAryPtr(ptr, nullptr, ary, k, xk, offset, instance_id, false, speculative, inline_depth))->hashcons();
4708 }
4709 
4710 //------------------------------make-------------------------------------------
4711 const TypeAryPtr *TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4712                                    int instance_id, const TypePtr* speculative, int inline_depth,
4713                                    bool is_autobox_cache) {
4714   assert(!(k == nullptr && ary->_elem->isa_int()),
4715          "integral arrays must be pre-equipped with a class");
4716   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4717   if (!xk)  xk = (o != nullptr) || ary->ary_must_be_exact();
4718   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4719   if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4720       k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4721     k = nullptr;
4722   }
4723   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4724 }
4725 
4726 //------------------------------cast_to_ptr_type-------------------------------
4727 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4728   if( ptr == _ptr ) return this;
4729   return make(ptr, ptr == Constant ? const_oop() : nullptr, _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4730 }
4731 
4732 
4733 //-----------------------------cast_to_exactness-------------------------------
4734 const TypeAryPtr* TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4735   if( klass_is_exact == _klass_is_exact ) return this;
4736   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
4737   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
4738 }
4739 
4740 //-----------------------------cast_to_instance_id----------------------------
4741 const TypeAryPtr* TypeAryPtr::cast_to_instance_id(int instance_id) const {
4742   if( instance_id == _instance_id ) return this;
4743   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
4744 }
4745 
4746 
4747 //-----------------------------max_array_length-------------------------------
4748 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
4749 jint TypeAryPtr::max_array_length(BasicType etype) {
4750   if (!is_java_primitive(etype) && !::is_reference_type(etype)) {
4751     if (etype == T_NARROWOOP) {
4752       etype = T_OBJECT;
4753     } else if (etype == T_ILLEGAL) { // bottom[]
4754       etype = T_BYTE; // will produce conservatively high value
4755     } else {
4756       fatal("not an element type: %s", type2name(etype));
4757     }
4758   }
4759   return arrayOopDesc::max_array_length(etype);
4760 }
4761 
4762 //-----------------------------narrow_size_type-------------------------------
4763 // Narrow the given size type to the index range for the given array base type.
4764 // Return null if the resulting int type becomes empty.
4765 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const {
4766   jint hi = size->_hi;
4767   jint lo = size->_lo;
4768   jint min_lo = 0;
4769   jint max_hi = max_array_length(elem()->array_element_basic_type());
4770   //if (index_not_size)  --max_hi;     // type of a valid array index, FTR
4771   bool chg = false;
4772   if (lo < min_lo) {
4773     lo = min_lo;
4774     if (size->is_con()) {
4775       hi = lo;
4776     }
4777     chg = true;
4778   }
4779   if (hi > max_hi) {
4780     hi = max_hi;
4781     if (size->is_con()) {
4782       lo = hi;
4783     }
4784     chg = true;
4785   }
4786   // Negative length arrays will produce weird intermediate dead fast-path code
4787   if (lo > hi)
4788     return TypeInt::ZERO;
4789   if (!chg)
4790     return size;
4791   return TypeInt::make(lo, hi, Type::WidenMin);
4792 }
4793 
4794 //-------------------------------cast_to_size----------------------------------
4795 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4796   assert(new_size != nullptr, "");
4797   new_size = narrow_size_type(new_size);
4798   if (new_size == size())  return this;
4799   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
4800   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4801 }
4802 
4803 //------------------------------cast_to_stable---------------------------------
4804 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
4805   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
4806     return this;
4807 
4808   const Type* elem = this->elem();
4809   const TypePtr* elem_ptr = elem->make_ptr();
4810 
4811   if (stable_dimension > 1 && elem_ptr != nullptr && elem_ptr->isa_aryptr()) {
4812     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
4813     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
4814   }
4815 
4816   const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
4817 
4818   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4819 }
4820 
4821 //-----------------------------stable_dimension--------------------------------
4822 int TypeAryPtr::stable_dimension() const {
4823   if (!is_stable())  return 0;
4824   int dim = 1;
4825   const TypePtr* elem_ptr = elem()->make_ptr();
4826   if (elem_ptr != nullptr && elem_ptr->isa_aryptr())
4827     dim += elem_ptr->is_aryptr()->stable_dimension();
4828   return dim;
4829 }
4830 
4831 //----------------------cast_to_autobox_cache-----------------------------------
4832 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
4833   if (is_autobox_cache())  return this;
4834   const TypeOopPtr* etype = elem()->make_oopptr();
4835   if (etype == nullptr)  return this;
4836   // The pointers in the autobox arrays are always non-null.
4837   etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
4838   const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable());
4839   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
4840 }
4841 
4842 //------------------------------eq---------------------------------------------
4843 // Structural equality check for Type representations
4844 bool TypeAryPtr::eq( const Type *t ) const {
4845   const TypeAryPtr *p = t->is_aryptr();
4846   return
4847     _ary == p->_ary &&  // Check array
4848     TypeOopPtr::eq(p);  // Check sub-parts
4849 }
4850 
4851 //------------------------------hash-------------------------------------------
4852 // Type-specific hashing function.
4853 uint TypeAryPtr::hash(void) const {
4854   return (uint)(uintptr_t)_ary + TypeOopPtr::hash();
4855 }
4856 
4857 bool TypeAryPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4858   return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
4859 }
4860 
4861 bool TypeAryPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4862   return TypePtr::is_same_java_type_as_helper_for_array(this, other);
4863 }
4864 
4865 bool TypeAryPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4866   return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
4867 }
4868 //------------------------------meet-------------------------------------------
4869 // Compute the MEET of two types.  It returns a new Type object.
4870 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
4871   // Perform a fast test for common case; meeting the same types together.
4872   if( this == t ) return this;  // Meeting same type-rep?
4873   // Current "this->_base" is Pointer
4874   switch (t->base()) {          // switch on original type
4875 
4876   // Mixing ints & oops happens when javac reuses local variables
4877   case Int:
4878   case Long:
4879   case FloatTop:
4880   case FloatCon:
4881   case FloatBot:
4882   case DoubleTop:
4883   case DoubleCon:
4884   case DoubleBot:
4885   case NarrowOop:
4886   case NarrowKlass:
4887   case Bottom:                  // Ye Olde Default
4888     return Type::BOTTOM;
4889   case Top:
4890     return this;
4891 
4892   default:                      // All else is a mistake
4893     typerr(t);
4894 
4895   case OopPtr: {                // Meeting to OopPtrs
4896     // Found a OopPtr type vs self-AryPtr type
4897     const TypeOopPtr *tp = t->is_oopptr();
4898     int offset = meet_offset(tp->offset());
4899     PTR ptr = meet_ptr(tp->ptr());
4900     int depth = meet_inline_depth(tp->inline_depth());
4901     const TypePtr* speculative = xmeet_speculative(tp);
4902     switch (tp->ptr()) {
4903     case TopPTR:
4904     case AnyNull: {
4905       int instance_id = meet_instance_id(InstanceTop);
4906       return make(ptr, (ptr == Constant ? const_oop() : nullptr),
4907                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4908     }
4909     case BotPTR:
4910     case NotNull: {
4911       int instance_id = meet_instance_id(tp->instance_id());
4912       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4913     }
4914     default: ShouldNotReachHere();
4915     }
4916   }
4917 
4918   case AnyPtr: {                // Meeting two AnyPtrs
4919     // Found an AnyPtr type vs self-AryPtr type
4920     const TypePtr *tp = t->is_ptr();
4921     int offset = meet_offset(tp->offset());
4922     PTR ptr = meet_ptr(tp->ptr());
4923     const TypePtr* speculative = xmeet_speculative(tp);
4924     int depth = meet_inline_depth(tp->inline_depth());
4925     switch (tp->ptr()) {
4926     case TopPTR:
4927       return this;
4928     case BotPTR:
4929     case NotNull:
4930       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4931     case Null:
4932       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4933       // else fall through to AnyNull
4934     case AnyNull: {
4935       int instance_id = meet_instance_id(InstanceTop);
4936       return make(ptr, (ptr == Constant ? const_oop() : nullptr),
4937                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4938     }
4939     default: ShouldNotReachHere();
4940     }
4941   }
4942 
4943   case MetadataPtr:
4944   case KlassPtr:
4945   case InstKlassPtr:
4946   case AryKlassPtr:
4947   case RawPtr: return TypePtr::BOTTOM;
4948 
4949   case AryPtr: {                // Meeting 2 references?
4950     const TypeAryPtr *tap = t->is_aryptr();
4951     int off = meet_offset(tap->offset());
4952     const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
4953     PTR ptr = meet_ptr(tap->ptr());
4954     int instance_id = meet_instance_id(tap->instance_id());
4955     const TypePtr* speculative = xmeet_speculative(tap);
4956     int depth = meet_inline_depth(tap->inline_depth());
4957 
4958     ciKlass* res_klass = nullptr;
4959     bool res_xk = false;
4960     const Type* elem = tary->_elem;
4961     if (meet_aryptr(ptr, elem, this, tap, res_klass, res_xk) == NOT_SUBTYPE) {
4962       instance_id = InstanceBot;
4963     }
4964 
4965     ciObject* o = nullptr;             // Assume not constant when done
4966     ciObject* this_oop = const_oop();
4967     ciObject* tap_oop = tap->const_oop();
4968     if (ptr == Constant) {
4969       if (this_oop != nullptr && tap_oop != nullptr &&
4970           this_oop->equals(tap_oop)) {
4971         o = tap_oop;
4972       } else if (above_centerline(_ptr)) {
4973         o = tap_oop;
4974       } else if (above_centerline(tap->_ptr)) {
4975         o = this_oop;
4976       } else {
4977         ptr = NotNull;
4978       }
4979     }
4980     return make(ptr, o, TypeAry::make(elem, tary->_size, tary->_stable), res_klass, res_xk, off, instance_id, speculative, depth);
4981   }
4982 
4983   // All arrays inherit from Object class
4984   case InstPtr: {
4985     const TypeInstPtr *tp = t->is_instptr();
4986     int offset = meet_offset(tp->offset());
4987     PTR ptr = meet_ptr(tp->ptr());
4988     int instance_id = meet_instance_id(tp->instance_id());
4989     const TypePtr* speculative = xmeet_speculative(tp);
4990     int depth = meet_inline_depth(tp->inline_depth());
4991     const TypeInterfaces* interfaces = meet_interfaces(tp);
4992     const TypeInterfaces* tp_interfaces = tp->_interfaces;
4993     const TypeInterfaces* this_interfaces = _interfaces;
4994 
4995     switch (ptr) {
4996     case TopPTR:
4997     case AnyNull:                // Fall 'down' to dual of object klass
4998       // For instances when a subclass meets a superclass we fall
4999       // below the centerline when the superclass is exact. We need to
5000       // do the same here.
5001       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact()) {
5002         return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
5003       } else {
5004         // cannot subclass, so the meet has to fall badly below the centerline
5005         ptr = NotNull;
5006         instance_id = InstanceBot;
5007         interfaces = this_interfaces->intersection_with(tp_interfaces);
5008         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr,offset, instance_id, speculative, depth);
5009       }
5010     case Constant:
5011     case NotNull:
5012     case BotPTR:                // Fall down to object klass
5013       // LCA is object_klass, but if we subclass from the top we can do better
5014       if (above_centerline(tp->ptr())) {
5015         // If 'tp'  is above the centerline and it is Object class
5016         // then we can subclass in the Java class hierarchy.
5017         // For instances when a subclass meets a superclass we fall
5018         // below the centerline when the superclass is exact. We need
5019         // to do the same here.
5020         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact()) {
5021           // that is, my array type is a subtype of 'tp' klass
5022           return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5023                       _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
5024         }
5025       }
5026       // The other case cannot happen, since t cannot be a subtype of an array.
5027       // The meet falls down to Object class below centerline.
5028       if (ptr == Constant) {
5029          ptr = NotNull;
5030       }
5031       if (instance_id > 0) {
5032         instance_id = InstanceBot;
5033       }
5034       interfaces = this_interfaces->intersection_with(tp_interfaces);
5035       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset, instance_id, speculative, depth);
5036     default: typerr(t);
5037     }
5038   }
5039   }
5040   return this;                  // Lint noise
5041 }
5042 
5043 
5044 template<class T> TypePtr::MeetResult TypePtr::meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary,
5045                                                            const T* other_ary, ciKlass*& res_klass, bool& res_xk) {
5046   int dummy;
5047   bool this_top_or_bottom = (this_ary->base_element_type(dummy) == Type::TOP || this_ary->base_element_type(dummy) == Type::BOTTOM);
5048   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
5049   ciKlass* this_klass = this_ary->klass();
5050   ciKlass* other_klass = other_ary->klass();
5051   bool this_xk = this_ary->klass_is_exact();
5052   bool other_xk = other_ary->klass_is_exact();
5053   PTR this_ptr = this_ary->ptr();
5054   PTR other_ptr = other_ary->ptr();
5055   res_klass = nullptr;
5056   MeetResult result = SUBTYPE;
5057   if (elem->isa_int()) {
5058     // Integral array element types have irrelevant lattice relations.
5059     // It is the klass that determines array layout, not the element type.
5060     if (this_top_or_bottom)
5061       res_klass = other_klass;
5062     else if (other_top_or_bottom || other_klass == this_klass) {
5063       res_klass = this_klass;
5064     } else {
5065       // Something like byte[int+] meets char[int+].
5066       // This must fall to bottom, not (int[-128..65535])[int+].
5067       // instance_id = InstanceBot;
5068       elem = Type::BOTTOM;
5069       result = NOT_SUBTYPE;
5070       if (above_centerline(ptr) || ptr == Constant) {
5071         ptr = NotNull;
5072         res_xk = false;
5073         return NOT_SUBTYPE;
5074       }
5075     }
5076   } else {// Non integral arrays.
5077     // Must fall to bottom if exact klasses in upper lattice
5078     // are not equal or super klass is exact.
5079     if ((above_centerline(ptr) || ptr == Constant) && !this_ary->is_same_java_type_as(other_ary) &&
5080         // meet with top[] and bottom[] are processed further down:
5081         !this_top_or_bottom && !other_top_or_bottom &&
5082         // both are exact and not equal:
5083         ((other_xk && this_xk) ||
5084          // 'tap'  is exact and super or unrelated:
5085          (other_xk && !other_ary->is_meet_subtype_of(this_ary)) ||
5086          // 'this' is exact and super or unrelated:
5087          (this_xk && !this_ary->is_meet_subtype_of(other_ary)))) {
5088       if (above_centerline(ptr) || (elem->make_ptr() && above_centerline(elem->make_ptr()->_ptr))) {
5089         elem = Type::BOTTOM;
5090       }
5091       ptr = NotNull;
5092       res_xk = false;
5093       return NOT_SUBTYPE;
5094     }
5095   }
5096 
5097   res_xk = false;
5098   switch (other_ptr) {
5099     case AnyNull:
5100     case TopPTR:
5101       // Compute new klass on demand, do not use tap->_klass
5102       if (below_centerline(this_ptr)) {
5103         res_xk = this_xk;
5104       } else {
5105         res_xk = (other_xk || this_xk);
5106       }
5107       return result;
5108     case Constant: {
5109       if (this_ptr == Constant) {
5110         res_xk = true;
5111       } else if(above_centerline(this_ptr)) {
5112         res_xk = true;
5113       } else {
5114         // Only precise for identical arrays
5115         res_xk = this_xk && (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom));
5116       }
5117       return result;
5118     }
5119     case NotNull:
5120     case BotPTR:
5121       // Compute new klass on demand, do not use tap->_klass
5122       if (above_centerline(this_ptr)) {
5123         res_xk = other_xk;
5124       } else {
5125         res_xk = (other_xk && this_xk) &&
5126                  (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom)); // Only precise for identical arrays
5127       }
5128       return result;
5129     default:  {
5130       ShouldNotReachHere();
5131       return result;
5132     }
5133   }
5134   return result;
5135 }
5136 
5137 
5138 //------------------------------xdual------------------------------------------
5139 // Dual: compute field-by-field dual
5140 const Type *TypeAryPtr::xdual() const {
5141   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());
5142 }
5143 
5144 //------------------------------dump2------------------------------------------
5145 #ifndef PRODUCT
5146 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5147   _ary->dump2(d,depth,st);
5148   _interfaces->dump(st);
5149 
5150   switch( _ptr ) {
5151   case Constant:
5152     const_oop()->print(st);
5153     break;
5154   case BotPTR:
5155     if (!WizardMode && !Verbose) {
5156       if( _klass_is_exact ) st->print(":exact");
5157       break;
5158     }
5159   case TopPTR:
5160   case AnyNull:
5161   case NotNull:
5162     st->print(":%s", ptr_msg[_ptr]);
5163     if( _klass_is_exact ) st->print(":exact");
5164     break;
5165   default:
5166     break;
5167   }
5168 
5169   if( _offset != 0 ) {
5170     BasicType basic_elem_type = elem()->basic_type();
5171     int header_size = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5172     if( _offset == OffsetTop )       st->print("+undefined");
5173     else if( _offset == OffsetBot )  st->print("+any");
5174     else if( _offset < header_size ) st->print("+%d", _offset);
5175     else {
5176       if (basic_elem_type == T_ILLEGAL) {
5177         st->print("+any");
5178       } else {
5179         int elem_size = type2aelembytes(basic_elem_type);
5180         st->print("[%d]", (_offset - header_size)/elem_size);
5181       }
5182     }
5183   }
5184   st->print(" *");
5185   if (_instance_id == InstanceTop)
5186     st->print(",iid=top");
5187   else if (_instance_id != InstanceBot)
5188     st->print(",iid=%d",_instance_id);
5189 
5190   dump_inline_depth(st);
5191   dump_speculative(st);
5192 }
5193 #endif
5194 
5195 bool TypeAryPtr::empty(void) const {
5196   if (_ary->empty())       return true;
5197   return TypeOopPtr::empty();
5198 }
5199 
5200 //------------------------------add_offset-------------------------------------
5201 const TypePtr* TypeAryPtr::add_offset(intptr_t offset) const {
5202   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
5203 }
5204 
5205 const TypeAryPtr* TypeAryPtr::with_offset(intptr_t offset) const {
5206   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, offset, _instance_id, with_offset_speculative(offset), _inline_depth);
5207 }
5208 
5209 const TypeAryPtr* TypeAryPtr::with_ary(const TypeAry* ary) const {
5210   return make(_ptr, _const_oop, ary, _klass, _klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
5211 }
5212 
5213 const TypeAryPtr* TypeAryPtr::remove_speculative() const {
5214   if (_speculative == nullptr) {
5215     return this;
5216   }
5217   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
5218   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, nullptr, _inline_depth);
5219 }
5220 
5221 const TypePtr* TypeAryPtr::with_inline_depth(int depth) const {
5222   if (!UseInlineDepthForSpeculativeTypes) {
5223     return this;
5224   }
5225   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, _speculative, depth);
5226 }
5227 
5228 const TypePtr* TypeAryPtr::with_instance_id(int instance_id) const {
5229   assert(is_known_instance(), "should be known");
5230   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
5231 }
5232 
5233 //=============================================================================
5234 
5235 //------------------------------hash-------------------------------------------
5236 // Type-specific hashing function.
5237 uint TypeNarrowPtr::hash(void) const {
5238   return _ptrtype->hash() + 7;
5239 }
5240 
5241 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
5242   return _ptrtype->singleton();
5243 }
5244 
5245 bool TypeNarrowPtr::empty(void) const {
5246   return _ptrtype->empty();
5247 }
5248 
5249 intptr_t TypeNarrowPtr::get_con() const {
5250   return _ptrtype->get_con();
5251 }
5252 
5253 bool TypeNarrowPtr::eq( const Type *t ) const {
5254   const TypeNarrowPtr* tc = isa_same_narrowptr(t);
5255   if (tc != nullptr) {
5256     if (_ptrtype->base() != tc->_ptrtype->base()) {
5257       return false;
5258     }
5259     return tc->_ptrtype->eq(_ptrtype);
5260   }
5261   return false;
5262 }
5263 
5264 const Type *TypeNarrowPtr::xdual() const {    // Compute dual right now.
5265   const TypePtr* odual = _ptrtype->dual()->is_ptr();
5266   return make_same_narrowptr(odual);
5267 }
5268 
5269 
5270 const Type *TypeNarrowPtr::filter_helper(const Type *kills, bool include_speculative) const {
5271   if (isa_same_narrowptr(kills)) {
5272     const Type* ft =_ptrtype->filter_helper(is_same_narrowptr(kills)->_ptrtype, include_speculative);
5273     if (ft->empty())
5274       return Type::TOP;           // Canonical empty value
5275     if (ft->isa_ptr()) {
5276       return make_hash_same_narrowptr(ft->isa_ptr());
5277     }
5278     return ft;
5279   } else if (kills->isa_ptr()) {
5280     const Type* ft = _ptrtype->join_helper(kills, include_speculative);
5281     if (ft->empty())
5282       return Type::TOP;           // Canonical empty value
5283     return ft;
5284   } else {
5285     return Type::TOP;
5286   }
5287 }
5288 
5289 //------------------------------xmeet------------------------------------------
5290 // Compute the MEET of two types.  It returns a new Type object.
5291 const Type *TypeNarrowPtr::xmeet( const Type *t ) const {
5292   // Perform a fast test for common case; meeting the same types together.
5293   if( this == t ) return this;  // Meeting same type-rep?
5294 
5295   if (t->base() == base()) {
5296     const Type* result = _ptrtype->xmeet(t->make_ptr());
5297     if (result->isa_ptr()) {
5298       return make_hash_same_narrowptr(result->is_ptr());
5299     }
5300     return result;
5301   }
5302 
5303   // Current "this->_base" is NarrowKlass or NarrowOop
5304   switch (t->base()) {          // switch on original type
5305 
5306   case Int:                     // Mixing ints & oops happens when javac
5307   case Long:                    // reuses local variables
5308   case FloatTop:
5309   case FloatCon:
5310   case FloatBot:
5311   case DoubleTop:
5312   case DoubleCon:
5313   case DoubleBot:
5314   case AnyPtr:
5315   case RawPtr:
5316   case OopPtr:
5317   case InstPtr:
5318   case AryPtr:
5319   case MetadataPtr:
5320   case KlassPtr:
5321   case InstKlassPtr:
5322   case AryKlassPtr:
5323   case NarrowOop:
5324   case NarrowKlass:
5325 
5326   case Bottom:                  // Ye Olde Default
5327     return Type::BOTTOM;
5328   case Top:
5329     return this;
5330 
5331   default:                      // All else is a mistake
5332     typerr(t);
5333 
5334   } // End of switch
5335 
5336   return this;
5337 }
5338 
5339 #ifndef PRODUCT
5340 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5341   _ptrtype->dump2(d, depth, st);
5342 }
5343 #endif
5344 
5345 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
5346 const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
5347 
5348 
5349 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
5350   return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();
5351 }
5352 
5353 const TypeNarrowOop* TypeNarrowOop::remove_speculative() const {
5354   return make(_ptrtype->remove_speculative()->is_ptr());
5355 }
5356 
5357 const Type* TypeNarrowOop::cleanup_speculative() const {
5358   return make(_ptrtype->cleanup_speculative()->is_ptr());
5359 }
5360 
5361 #ifndef PRODUCT
5362 void TypeNarrowOop::dump2( Dict & d, uint depth, outputStream *st ) const {
5363   st->print("narrowoop: ");
5364   TypeNarrowPtr::dump2(d, depth, st);
5365 }
5366 #endif
5367 
5368 const TypeNarrowKlass *TypeNarrowKlass::NULL_PTR;
5369 
5370 const TypeNarrowKlass* TypeNarrowKlass::make(const TypePtr* type) {
5371   return (const TypeNarrowKlass*)(new TypeNarrowKlass(type))->hashcons();
5372 }
5373 
5374 #ifndef PRODUCT
5375 void TypeNarrowKlass::dump2( Dict & d, uint depth, outputStream *st ) const {
5376   st->print("narrowklass: ");
5377   TypeNarrowPtr::dump2(d, depth, st);
5378 }
5379 #endif
5380 
5381 
5382 //------------------------------eq---------------------------------------------
5383 // Structural equality check for Type representations
5384 bool TypeMetadataPtr::eq( const Type *t ) const {
5385   const TypeMetadataPtr *a = (const TypeMetadataPtr*)t;
5386   ciMetadata* one = metadata();
5387   ciMetadata* two = a->metadata();
5388   if (one == nullptr || two == nullptr) {
5389     return (one == two) && TypePtr::eq(t);
5390   } else {
5391     return one->equals(two) && TypePtr::eq(t);
5392   }
5393 }
5394 
5395 //------------------------------hash-------------------------------------------
5396 // Type-specific hashing function.
5397 uint TypeMetadataPtr::hash(void) const {
5398   return
5399     (metadata() ? metadata()->hash() : 0) +
5400     TypePtr::hash();
5401 }
5402 
5403 //------------------------------singleton--------------------------------------
5404 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5405 // constants
5406 bool TypeMetadataPtr::singleton(void) const {
5407   // detune optimizer to not generate constant metadata + constant offset as a constant!
5408   // TopPTR, Null, AnyNull, Constant are all singletons
5409   return (_offset == 0) && !below_centerline(_ptr);
5410 }
5411 
5412 //------------------------------add_offset-------------------------------------
5413 const TypePtr* TypeMetadataPtr::add_offset( intptr_t offset ) const {
5414   return make( _ptr, _metadata, xadd_offset(offset));
5415 }
5416 
5417 //-----------------------------filter------------------------------------------
5418 // Do not allow interface-vs.-noninterface joins to collapse to top.
5419 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
5420   const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
5421   if (ft == nullptr || ft->empty())
5422     return Type::TOP;           // Canonical empty value
5423   return ft;
5424 }
5425 
5426  //------------------------------get_con----------------------------------------
5427 intptr_t TypeMetadataPtr::get_con() const {
5428   assert( _ptr == Null || _ptr == Constant, "" );
5429   assert( _offset >= 0, "" );
5430 
5431   if (_offset != 0) {
5432     // After being ported to the compiler interface, the compiler no longer
5433     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5434     // to a handle at compile time.  This handle is embedded in the generated
5435     // code and dereferenced at the time the nmethod is made.  Until that time,
5436     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5437     // have access to the addresses!).  This does not seem to currently happen,
5438     // but this assertion here is to help prevent its occurrence.
5439     tty->print_cr("Found oop constant with non-zero offset");
5440     ShouldNotReachHere();
5441   }
5442 
5443   return (intptr_t)metadata()->constant_encoding();
5444 }
5445 
5446 //------------------------------cast_to_ptr_type-------------------------------
5447 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
5448   if( ptr == _ptr ) return this;
5449   return make(ptr, metadata(), _offset);
5450 }
5451 
5452 //------------------------------meet-------------------------------------------
5453 // Compute the MEET of two types.  It returns a new Type object.
5454 const Type *TypeMetadataPtr::xmeet( const Type *t ) const {
5455   // Perform a fast test for common case; meeting the same types together.
5456   if( this == t ) return this;  // Meeting same type-rep?
5457 
5458   // Current "this->_base" is OopPtr
5459   switch (t->base()) {          // switch on original type
5460 
5461   case Int:                     // Mixing ints & oops happens when javac
5462   case Long:                    // reuses local variables
5463   case FloatTop:
5464   case FloatCon:
5465   case FloatBot:
5466   case DoubleTop:
5467   case DoubleCon:
5468   case DoubleBot:
5469   case NarrowOop:
5470   case NarrowKlass:
5471   case Bottom:                  // Ye Olde Default
5472     return Type::BOTTOM;
5473   case Top:
5474     return this;
5475 
5476   default:                      // All else is a mistake
5477     typerr(t);
5478 
5479   case AnyPtr: {
5480     // Found an AnyPtr type vs self-OopPtr type
5481     const TypePtr *tp = t->is_ptr();
5482     int offset = meet_offset(tp->offset());
5483     PTR ptr = meet_ptr(tp->ptr());
5484     switch (tp->ptr()) {
5485     case Null:
5486       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5487       // else fall through:
5488     case TopPTR:
5489     case AnyNull: {
5490       return make(ptr, _metadata, offset);
5491     }
5492     case BotPTR:
5493     case NotNull:
5494       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5495     default: typerr(t);
5496     }
5497   }
5498 
5499   case RawPtr:
5500   case KlassPtr:
5501   case InstKlassPtr:
5502   case AryKlassPtr:
5503   case OopPtr:
5504   case InstPtr:
5505   case AryPtr:
5506     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
5507 
5508   case MetadataPtr: {
5509     const TypeMetadataPtr *tp = t->is_metadataptr();
5510     int offset = meet_offset(tp->offset());
5511     PTR tptr = tp->ptr();
5512     PTR ptr = meet_ptr(tptr);
5513     ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
5514     if (tptr == TopPTR || _ptr == TopPTR ||
5515         metadata()->equals(tp->metadata())) {
5516       return make(ptr, md, offset);
5517     }
5518     // metadata is different
5519     if( ptr == Constant ) {  // Cannot be equal constants, so...
5520       if( tptr == Constant && _ptr != Constant)  return t;
5521       if( _ptr == Constant && tptr != Constant)  return this;
5522       ptr = NotNull;            // Fall down in lattice
5523     }
5524     return make(ptr, nullptr, offset);
5525     break;
5526   }
5527   } // End of switch
5528   return this;                  // Return the double constant
5529 }
5530 
5531 
5532 //------------------------------xdual------------------------------------------
5533 // Dual of a pure metadata pointer.
5534 const Type *TypeMetadataPtr::xdual() const {
5535   return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
5536 }
5537 
5538 //------------------------------dump2------------------------------------------
5539 #ifndef PRODUCT
5540 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5541   st->print("metadataptr:%s", ptr_msg[_ptr]);
5542   if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata()));
5543   switch( _offset ) {
5544   case OffsetTop: st->print("+top"); break;
5545   case OffsetBot: st->print("+any"); break;
5546   case         0: break;
5547   default:        st->print("+%d",_offset); break;
5548   }
5549 }
5550 #endif
5551 
5552 
5553 //=============================================================================
5554 // Convenience common pre-built type.
5555 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
5556 
5557 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset):
5558   TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
5559 }
5560 
5561 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
5562   return make(Constant, m, 0);
5563 }
5564 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
5565   return make(Constant, m, 0);
5566 }
5567 
5568 //------------------------------make-------------------------------------------
5569 // Create a meta data constant
5570 const TypeMetadataPtr *TypeMetadataPtr::make(PTR ptr, ciMetadata* m, int offset) {
5571   assert(m == nullptr || !m->is_klass(), "wrong type");
5572   return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
5573 }
5574 
5575 
5576 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
5577   const Type* elem = _ary->_elem;
5578   bool xk = klass_is_exact();
5579   if (elem->make_oopptr() != nullptr) {
5580     elem = elem->make_oopptr()->as_klass_type(try_for_exact);
5581     if (elem->is_klassptr()->klass_is_exact()) {
5582       xk = true;
5583     }
5584   }
5585   return TypeAryKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, elem, klass(), 0);
5586 }
5587 
5588 const TypeKlassPtr* TypeKlassPtr::make(ciKlass *klass, InterfaceHandling interface_handling) {
5589   if (klass->is_instance_klass()) {
5590     return TypeInstKlassPtr::make(klass, interface_handling);
5591   }
5592   return TypeAryKlassPtr::make(klass, interface_handling);
5593 }
5594 
5595 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* klass, int offset, InterfaceHandling interface_handling) {
5596   if (klass->is_instance_klass()) {
5597     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
5598     return TypeInstKlassPtr::make(ptr, klass, interfaces, offset);
5599   }
5600   return TypeAryKlassPtr::make(ptr, klass, offset, interface_handling);
5601 }
5602 
5603 
5604 //------------------------------TypeKlassPtr-----------------------------------
5605 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, int offset)
5606   : TypePtr(t, ptr, offset), _klass(klass), _interfaces(interfaces) {
5607   assert(klass == nullptr || !klass->is_loaded() || (klass->is_instance_klass() && !klass->is_interface()) ||
5608          klass->is_type_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "no interface here");
5609 }
5610 
5611 // Is there a single ciKlass* that can represent that type?
5612 ciKlass* TypeKlassPtr::exact_klass_helper() const {
5613   assert(_klass->is_instance_klass() && !_klass->is_interface(), "No interface");
5614   if (_interfaces->empty()) {
5615     return _klass;
5616   }
5617   if (_klass != ciEnv::current()->Object_klass()) {
5618     if (_interfaces->eq(_klass->as_instance_klass())) {
5619       return _klass;
5620     }
5621     return nullptr;
5622   }
5623   return _interfaces->exact_klass();
5624 }
5625 
5626 //------------------------------eq---------------------------------------------
5627 // Structural equality check for Type representations
5628 bool TypeKlassPtr::eq(const Type *t) const {
5629   const TypeKlassPtr *p = t->is_klassptr();
5630   return
5631     _interfaces->eq(p->_interfaces) &&
5632     TypePtr::eq(p);
5633 }
5634 
5635 //------------------------------hash-------------------------------------------
5636 // Type-specific hashing function.
5637 uint TypeKlassPtr::hash(void) const {
5638   return TypePtr::hash() + _interfaces->hash();
5639 }
5640 
5641 //------------------------------singleton--------------------------------------
5642 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5643 // constants
5644 bool TypeKlassPtr::singleton(void) const {
5645   // detune optimizer to not generate constant klass + constant offset as a constant!
5646   // TopPTR, Null, AnyNull, Constant are all singletons
5647   return (_offset == 0) && !below_centerline(_ptr);
5648 }
5649 
5650 // Do not allow interface-vs.-noninterface joins to collapse to top.
5651 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
5652   // logic here mirrors the one from TypeOopPtr::filter. See comments
5653   // there.
5654   const Type* ft = join_helper(kills, include_speculative);
5655   const TypeKlassPtr* ftkp = ft->isa_instklassptr();
5656   const TypeKlassPtr* ktkp = kills->isa_instklassptr();
5657 
5658   if (ft->empty()) {
5659     return Type::TOP;           // Canonical empty value
5660   }
5661 
5662   return ft;
5663 }
5664 
5665 const TypeInterfaces* TypeKlassPtr::meet_interfaces(const TypeKlassPtr* other) const {
5666   if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
5667     return _interfaces->union_with(other->_interfaces);
5668   } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
5669     return other->_interfaces;
5670   } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
5671     return _interfaces;
5672   }
5673   return _interfaces->intersection_with(other->_interfaces);
5674 }
5675 
5676 //------------------------------get_con----------------------------------------
5677 intptr_t TypeKlassPtr::get_con() const {
5678   assert( _ptr == Null || _ptr == Constant, "" );
5679   assert( _offset >= 0, "" );
5680 
5681   if (_offset != 0) {
5682     // After being ported to the compiler interface, the compiler no longer
5683     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5684     // to a handle at compile time.  This handle is embedded in the generated
5685     // code and dereferenced at the time the nmethod is made.  Until that time,
5686     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5687     // have access to the addresses!).  This does not seem to currently happen,
5688     // but this assertion here is to help prevent its occurrence.
5689     tty->print_cr("Found oop constant with non-zero offset");
5690     ShouldNotReachHere();
5691   }
5692 
5693   ciKlass* k = exact_klass();
5694 
5695   return (intptr_t)k->constant_encoding();
5696 }
5697 
5698 //------------------------------dump2------------------------------------------
5699 // Dump Klass Type
5700 #ifndef PRODUCT
5701 void TypeKlassPtr::dump2(Dict & d, uint depth, outputStream *st) const {
5702   switch(_ptr) {
5703   case Constant:
5704     st->print("precise ");
5705   case NotNull:
5706     {
5707       const char *name = klass()->name()->as_utf8();
5708       if (name) {
5709         st->print("%s: " INTPTR_FORMAT, name, p2i(klass()));
5710       } else {
5711         ShouldNotReachHere();
5712       }
5713       _interfaces->dump(st);
5714     }
5715   case BotPTR:
5716     if (!WizardMode && !Verbose && _ptr != Constant) break;
5717   case TopPTR:
5718   case AnyNull:
5719     st->print(":%s", ptr_msg[_ptr]);
5720     if (_ptr == Constant) st->print(":exact");
5721     break;
5722   default:
5723     break;
5724   }
5725 
5726   if (_offset) {               // Dump offset, if any
5727     if (_offset == OffsetBot)      { st->print("+any"); }
5728     else if (_offset == OffsetTop) { st->print("+unknown"); }
5729     else                            { st->print("+%d", _offset); }
5730   }
5731 
5732   st->print(" *");
5733 }
5734 #endif
5735 
5736 //=============================================================================
5737 // Convenience common pre-built types.
5738 
5739 // Not-null object klass or below
5740 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
5741 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
5742 
5743 bool TypeInstKlassPtr::eq(const Type *t) const {
5744   const TypeKlassPtr *p = t->is_klassptr();
5745   return
5746     klass()->equals(p->klass()) &&
5747     TypeKlassPtr::eq(p);
5748 }
5749 
5750 uint TypeInstKlassPtr::hash(void) const {
5751   return klass()->hash() + TypeKlassPtr::hash();
5752 }
5753 
5754 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, int offset) {
5755   TypeInstKlassPtr *r =
5756     (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, interfaces, offset))->hashcons();
5757 
5758   return r;
5759 }
5760 
5761 //------------------------------add_offset-------------------------------------
5762 // Access internals of klass object
5763 const TypePtr* TypeInstKlassPtr::add_offset( intptr_t offset ) const {
5764   return make( _ptr, klass(), _interfaces, xadd_offset(offset) );
5765 }
5766 
5767 const TypeInstKlassPtr* TypeInstKlassPtr::with_offset(intptr_t offset) const {
5768   return make(_ptr, klass(), _interfaces, offset);
5769 }
5770 
5771 //------------------------------cast_to_ptr_type-------------------------------
5772 const TypeInstKlassPtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
5773   assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
5774   if( ptr == _ptr ) return this;
5775   return make(ptr, _klass, _interfaces, _offset);
5776 }
5777 
5778 
5779 bool TypeInstKlassPtr::must_be_exact() const {
5780   if (!_klass->is_loaded())  return false;
5781   ciInstanceKlass* ik = _klass->as_instance_klass();
5782   if (ik->is_final())  return true;  // cannot clear xk
5783   return false;
5784 }
5785 
5786 //-----------------------------cast_to_exactness-------------------------------
5787 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
5788   if (klass_is_exact == (_ptr == Constant)) return this;
5789   if (must_be_exact()) return this;
5790   ciKlass* k = klass();
5791   return make(klass_is_exact ? Constant : NotNull, k, _interfaces, _offset);
5792 }
5793 
5794 
5795 //-----------------------------as_instance_type--------------------------------
5796 // Corresponding type for an instance of the given class.
5797 // It will be NotNull, and exact if and only if the klass type is exact.
5798 const TypeOopPtr* TypeInstKlassPtr::as_instance_type(bool klass_change) const {
5799   ciKlass* k = klass();
5800   bool xk = klass_is_exact();
5801   Compile* C = Compile::current();
5802   Dependencies* deps = C->dependencies();
5803   assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
5804   // Element is an instance
5805   bool klass_is_exact = false;
5806   const TypeInterfaces* interfaces = _interfaces;
5807   if (k->is_loaded()) {
5808     // Try to set klass_is_exact.
5809     ciInstanceKlass* ik = k->as_instance_klass();
5810     klass_is_exact = ik->is_final();
5811     if (!klass_is_exact && klass_change
5812         && deps != nullptr && UseUniqueSubclasses) {
5813       ciInstanceKlass* sub = ik->unique_concrete_subklass();
5814       if (sub != nullptr) {
5815         if (_interfaces->eq(sub)) {
5816           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
5817           k = ik = sub;
5818           xk = sub->is_final();
5819         }
5820       }
5821     }
5822   }
5823   return TypeInstPtr::make(TypePtr::BotPTR, k, interfaces, xk, nullptr, 0);
5824 }
5825 
5826 //------------------------------xmeet------------------------------------------
5827 // Compute the MEET of two types, return a new Type object.
5828 const Type    *TypeInstKlassPtr::xmeet( const Type *t ) const {
5829   // Perform a fast test for common case; meeting the same types together.
5830   if( this == t ) return this;  // Meeting same type-rep?
5831 
5832   // Current "this->_base" is Pointer
5833   switch (t->base()) {          // switch on original type
5834 
5835   case Int:                     // Mixing ints & oops happens when javac
5836   case Long:                    // reuses local variables
5837   case FloatTop:
5838   case FloatCon:
5839   case FloatBot:
5840   case DoubleTop:
5841   case DoubleCon:
5842   case DoubleBot:
5843   case NarrowOop:
5844   case NarrowKlass:
5845   case Bottom:                  // Ye Olde Default
5846     return Type::BOTTOM;
5847   case Top:
5848     return this;
5849 
5850   default:                      // All else is a mistake
5851     typerr(t);
5852 
5853   case AnyPtr: {                // Meeting to AnyPtrs
5854     // Found an AnyPtr type vs self-KlassPtr type
5855     const TypePtr *tp = t->is_ptr();
5856     int offset = meet_offset(tp->offset());
5857     PTR ptr = meet_ptr(tp->ptr());
5858     switch (tp->ptr()) {
5859     case TopPTR:
5860       return this;
5861     case Null:
5862       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5863     case AnyNull:
5864       return make( ptr, klass(), _interfaces, offset );
5865     case BotPTR:
5866     case NotNull:
5867       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5868     default: typerr(t);
5869     }
5870   }
5871 
5872   case RawPtr:
5873   case MetadataPtr:
5874   case OopPtr:
5875   case AryPtr:                  // Meet with AryPtr
5876   case InstPtr:                 // Meet with InstPtr
5877     return TypePtr::BOTTOM;
5878 
5879   //
5880   //             A-top         }
5881   //           /   |   \       }  Tops
5882   //       B-top A-any C-top   }
5883   //          | /  |  \ |      }  Any-nulls
5884   //       B-any   |   C-any   }
5885   //          |    |    |
5886   //       B-con A-con C-con   } constants; not comparable across classes
5887   //          |    |    |
5888   //       B-not   |   C-not   }
5889   //          | \  |  / |      }  not-nulls
5890   //       B-bot A-not C-bot   }
5891   //           \   |   /       }  Bottoms
5892   //             A-bot         }
5893   //
5894 
5895   case InstKlassPtr: {  // Meet two KlassPtr types
5896     const TypeInstKlassPtr *tkls = t->is_instklassptr();
5897     int  off     = meet_offset(tkls->offset());
5898     PTR  ptr     = meet_ptr(tkls->ptr());
5899     const TypeInterfaces* interfaces = meet_interfaces(tkls);
5900 
5901     ciKlass* res_klass = nullptr;
5902     bool res_xk = false;
5903     switch(meet_instptr(ptr, interfaces, this, tkls, res_klass, res_xk)) {
5904       case UNLOADED:
5905         ShouldNotReachHere();
5906       case SUBTYPE:
5907       case NOT_SUBTYPE:
5908       case LCA:
5909       case QUICK: {
5910         assert(res_xk == (ptr == Constant), "");
5911         const Type* res = make(ptr, res_klass, interfaces, off);
5912         return res;
5913       }
5914       default:
5915         ShouldNotReachHere();
5916     }
5917   } // End of case KlassPtr
5918   case AryKlassPtr: {                // All arrays inherit from Object class
5919     const TypeAryKlassPtr *tp = t->is_aryklassptr();
5920     int offset = meet_offset(tp->offset());
5921     PTR ptr = meet_ptr(tp->ptr());
5922     const TypeInterfaces* interfaces = meet_interfaces(tp);
5923     const TypeInterfaces* tp_interfaces = tp->_interfaces;
5924     const TypeInterfaces* this_interfaces = _interfaces;
5925 
5926     switch (ptr) {
5927     case TopPTR:
5928     case AnyNull:                // Fall 'down' to dual of object klass
5929       // For instances when a subclass meets a superclass we fall
5930       // below the centerline when the superclass is exact. We need to
5931       // do the same here.
5932       if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
5933         return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset);
5934       } else {
5935         // cannot subclass, so the meet has to fall badly below the centerline
5936         ptr = NotNull;
5937         interfaces = _interfaces->intersection_with(tp->_interfaces);
5938         return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
5939       }
5940     case Constant:
5941     case NotNull:
5942     case BotPTR:                // Fall down to object klass
5943       // LCA is object_klass, but if we subclass from the top we can do better
5944       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
5945         // If 'this' (InstPtr) is above the centerline and it is Object class
5946         // then we can subclass in the Java class hierarchy.
5947         // For instances when a subclass meets a superclass we fall
5948         // below the centerline when the superclass is exact. We need
5949         // to do the same here.
5950         if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
5951           // that is, tp's array type is a subtype of my klass
5952           return TypeAryKlassPtr::make(ptr,
5953                                        tp->elem(), tp->klass(), offset);
5954         }
5955       }
5956       // The other case cannot happen, since I cannot be a subtype of an array.
5957       // The meet falls down to Object class below centerline.
5958       if( ptr == Constant )
5959          ptr = NotNull;
5960       interfaces = this_interfaces->intersection_with(tp_interfaces);
5961       return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
5962     default: typerr(t);
5963     }
5964   }
5965 
5966   } // End of switch
5967   return this;                  // Return the double constant
5968 }
5969 
5970 //------------------------------xdual------------------------------------------
5971 // Dual: compute field-by-field dual
5972 const Type    *TypeInstKlassPtr::xdual() const {
5973   return new TypeInstKlassPtr(dual_ptr(), klass(), _interfaces, dual_offset());
5974 }
5975 
5976 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) {
5977   static_assert(std::is_base_of<T2, T1>::value, "");
5978   if (!this_one->is_loaded() || !other->is_loaded()) {
5979     return false;
5980   }
5981   if (!this_one->is_instance_type(other)) {
5982     return false;
5983   }
5984 
5985   if (!other_exact) {
5986     return false;
5987   }
5988 
5989   if (other->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces->empty()) {
5990     return true;
5991   }
5992 
5993   return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);
5994 }
5995 
5996 bool TypeInstKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
5997   return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
5998 }
5999 
6000 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_instance(const T1* this_one, const T2* other) {
6001   static_assert(std::is_base_of<T2, T1>::value, "");
6002   if (!this_one->is_loaded() || !other->is_loaded()) {
6003     return false;
6004   }
6005   if (!this_one->is_instance_type(other)) {
6006     return false;
6007   }
6008   return this_one->klass()->equals(other->klass()) && this_one->_interfaces->eq(other->_interfaces);
6009 }
6010 
6011 bool TypeInstKlassPtr::is_same_java_type_as_helper(const TypeKlassPtr* other) const {
6012   return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
6013 }
6014 
6015 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) {
6016   static_assert(std::is_base_of<T2, T1>::value, "");
6017   if (!this_one->is_loaded() || !other->is_loaded()) {
6018     return true;
6019   }
6020 
6021   if (this_one->is_array_type(other)) {
6022     return !this_exact && this_one->klass()->equals(ciEnv::current()->Object_klass())  && other->_interfaces->contains(this_one->_interfaces);
6023   }
6024 
6025   assert(this_one->is_instance_type(other), "unsupported");
6026 
6027   if (this_exact && other_exact) {
6028     return this_one->is_java_subtype_of(other);
6029   }
6030 
6031   if (!this_one->klass()->is_subtype_of(other->klass()) && !other->klass()->is_subtype_of(this_one->klass())) {
6032     return false;
6033   }
6034 
6035   if (this_exact) {
6036     return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);
6037   }
6038 
6039   return true;
6040 }
6041 
6042 bool TypeInstKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6043   return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
6044 }
6045 
6046 const TypeKlassPtr* TypeInstKlassPtr::try_improve() const {
6047   if (!UseUniqueSubclasses) {
6048     return this;
6049   }
6050   ciKlass* k = klass();
6051   Compile* C = Compile::current();
6052   Dependencies* deps = C->dependencies();
6053   assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
6054   const TypeInterfaces* interfaces = _interfaces;
6055   if (k->is_loaded()) {
6056     ciInstanceKlass* ik = k->as_instance_klass();
6057     bool klass_is_exact = ik->is_final();
6058     if (!klass_is_exact &&
6059         deps != nullptr) {
6060       ciInstanceKlass* sub = ik->unique_concrete_subklass();
6061       if (sub != nullptr) {
6062         if (_interfaces->eq(sub)) {
6063           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6064           k = ik = sub;
6065           klass_is_exact = sub->is_final();
6066           return TypeKlassPtr::make(klass_is_exact ? Constant : _ptr, k, _offset);
6067         }
6068       }
6069     }
6070   }
6071   return this;
6072 }
6073 
6074 
6075 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, int offset) {
6076   return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset))->hashcons();
6077 }
6078 
6079 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, ciKlass* k, int offset, InterfaceHandling interface_handling) {
6080   if (k->is_obj_array_klass()) {
6081     // Element is an object array. Recursively call ourself.
6082     ciKlass* eklass = k->as_obj_array_klass()->element_klass();
6083     const TypeKlassPtr *etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6084     return TypeAryKlassPtr::make(ptr, etype, nullptr, offset);
6085   } else if (k->is_type_array_klass()) {
6086     // Element is an typeArray
6087     const Type* etype = get_const_basic_type(k->as_type_array_klass()->element_type());
6088     return TypeAryKlassPtr::make(ptr, etype, k, offset);
6089   } else {
6090     ShouldNotReachHere();
6091     return nullptr;
6092   }
6093 }
6094 
6095 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6096   return TypeAryKlassPtr::make(Constant, klass, 0, interface_handling);
6097 }
6098 
6099 //------------------------------eq---------------------------------------------
6100 // Structural equality check for Type representations
6101 bool TypeAryKlassPtr::eq(const Type *t) const {
6102   const TypeAryKlassPtr *p = t->is_aryklassptr();
6103   return
6104     _elem == p->_elem &&  // Check array
6105     TypeKlassPtr::eq(p);  // Check sub-parts
6106 }
6107 
6108 //------------------------------hash-------------------------------------------
6109 // Type-specific hashing function.
6110 uint TypeAryKlassPtr::hash(void) const {
6111   return (uint)(uintptr_t)_elem + TypeKlassPtr::hash();
6112 }
6113 
6114 //----------------------compute_klass------------------------------------------
6115 // Compute the defining klass for this class
6116 ciKlass* TypeAryPtr::compute_klass() const {
6117   // Compute _klass based on element type.
6118   ciKlass* k_ary = nullptr;
6119   const TypeInstPtr *tinst;
6120   const TypeAryPtr *tary;
6121   const Type* el = elem();
6122   if (el->isa_narrowoop()) {
6123     el = el->make_ptr();
6124   }
6125 
6126   // Get element klass
6127   if ((tinst = el->isa_instptr()) != nullptr) {
6128     // Leave k_ary at null.
6129   } else if ((tary = el->isa_aryptr()) != nullptr) {
6130     // Leave k_ary at null.
6131   } else if ((el->base() == Type::Top) ||
6132              (el->base() == Type::Bottom)) {
6133     // element type of Bottom occurs from meet of basic type
6134     // and object; Top occurs when doing join on Bottom.
6135     // Leave k_ary at null.
6136   } else {
6137     assert(!el->isa_int(), "integral arrays must be pre-equipped with a class");
6138     // Compute array klass directly from basic type
6139     k_ary = ciTypeArrayKlass::make(el->basic_type());
6140   }
6141   return k_ary;
6142 }
6143 
6144 //------------------------------klass------------------------------------------
6145 // Return the defining klass for this class
6146 ciKlass* TypeAryPtr::klass() const {
6147   if( _klass ) return _klass;   // Return cached value, if possible
6148 
6149   // Oops, need to compute _klass and cache it
6150   ciKlass* k_ary = compute_klass();
6151 
6152   if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) {
6153     // The _klass field acts as a cache of the underlying
6154     // ciKlass for this array type.  In order to set the field,
6155     // we need to cast away const-ness.
6156     //
6157     // IMPORTANT NOTE: we *never* set the _klass field for the
6158     // type TypeAryPtr::OOPS.  This Type is shared between all
6159     // active compilations.  However, the ciKlass which represents
6160     // this Type is *not* shared between compilations, so caching
6161     // this value would result in fetching a dangling pointer.
6162     //
6163     // Recomputing the underlying ciKlass for each request is
6164     // a bit less efficient than caching, but calls to
6165     // TypeAryPtr::OOPS->klass() are not common enough to matter.
6166     ((TypeAryPtr*)this)->_klass = k_ary;
6167   }
6168   return k_ary;
6169 }
6170 
6171 // Is there a single ciKlass* that can represent that type?
6172 ciKlass* TypeAryPtr::exact_klass_helper() const {
6173   if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) {
6174     ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper();
6175     if (k == nullptr) {
6176       return nullptr;
6177     }
6178     k = ciObjArrayKlass::make(k);
6179     return k;
6180   }
6181 
6182   return klass();
6183 }
6184 
6185 const Type* TypeAryPtr::base_element_type(int& dims) const {
6186   const Type* elem = this->elem();
6187   dims = 1;
6188   while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) {
6189     elem = elem->make_ptr()->is_aryptr()->elem();
6190     dims++;
6191   }
6192   return elem;
6193 }
6194 
6195 //------------------------------add_offset-------------------------------------
6196 // Access internals of klass object
6197 const TypePtr* TypeAryKlassPtr::add_offset(intptr_t offset) const {
6198   return make(_ptr, elem(), klass(), xadd_offset(offset));
6199 }
6200 
6201 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const {
6202   return make(_ptr, elem(), klass(), offset);
6203 }
6204 
6205 //------------------------------cast_to_ptr_type-------------------------------
6206 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6207   assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6208   if (ptr == _ptr) return this;
6209   return make(ptr, elem(), _klass, _offset);
6210 }
6211 
6212 bool TypeAryKlassPtr::must_be_exact() const {
6213   if (_elem == Type::BOTTOM) return false;
6214   if (_elem == Type::TOP   ) return false;
6215   const TypeKlassPtr*  tk = _elem->isa_klassptr();
6216   if (!tk)             return true;   // a primitive type, like int
6217   return tk->must_be_exact();
6218 }
6219 
6220 
6221 //-----------------------------cast_to_exactness-------------------------------
6222 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6223   if (must_be_exact()) return this;  // cannot clear xk
6224   ciKlass* k = _klass;
6225   const Type* elem = this->elem();
6226   if (elem->isa_klassptr() && !klass_is_exact) {
6227     elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
6228   }
6229   return make(klass_is_exact ? Constant : NotNull, elem, k, _offset);
6230 }
6231 
6232 
6233 //-----------------------------as_instance_type--------------------------------
6234 // Corresponding type for an instance of the given class.
6235 // It will be NotNull, and exact if and only if the klass type is exact.
6236 const TypeOopPtr* TypeAryKlassPtr::as_instance_type(bool klass_change) const {
6237   ciKlass* k = klass();
6238   bool    xk = klass_is_exact();
6239   const Type* el = nullptr;
6240   if (elem()->isa_klassptr()) {
6241     el = elem()->is_klassptr()->as_instance_type(false)->cast_to_exactness(false);
6242     k = nullptr;
6243   } else {
6244     el = elem();
6245   }
6246   return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS), k, xk, 0);
6247 }
6248 
6249 
6250 //------------------------------xmeet------------------------------------------
6251 // Compute the MEET of two types, return a new Type object.
6252 const Type    *TypeAryKlassPtr::xmeet( const Type *t ) const {
6253   // Perform a fast test for common case; meeting the same types together.
6254   if( this == t ) return this;  // Meeting same type-rep?
6255 
6256   // Current "this->_base" is Pointer
6257   switch (t->base()) {          // switch on original type
6258 
6259   case Int:                     // Mixing ints & oops happens when javac
6260   case Long:                    // reuses local variables
6261   case FloatTop:
6262   case FloatCon:
6263   case FloatBot:
6264   case DoubleTop:
6265   case DoubleCon:
6266   case DoubleBot:
6267   case NarrowOop:
6268   case NarrowKlass:
6269   case Bottom:                  // Ye Olde Default
6270     return Type::BOTTOM;
6271   case Top:
6272     return this;
6273 
6274   default:                      // All else is a mistake
6275     typerr(t);
6276 
6277   case AnyPtr: {                // Meeting to AnyPtrs
6278     // Found an AnyPtr type vs self-KlassPtr type
6279     const TypePtr *tp = t->is_ptr();
6280     int offset = meet_offset(tp->offset());
6281     PTR ptr = meet_ptr(tp->ptr());
6282     switch (tp->ptr()) {
6283     case TopPTR:
6284       return this;
6285     case Null:
6286       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6287     case AnyNull:
6288       return make( ptr, _elem, klass(), offset );
6289     case BotPTR:
6290     case NotNull:
6291       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6292     default: typerr(t);
6293     }
6294   }
6295 
6296   case RawPtr:
6297   case MetadataPtr:
6298   case OopPtr:
6299   case AryPtr:                  // Meet with AryPtr
6300   case InstPtr:                 // Meet with InstPtr
6301     return TypePtr::BOTTOM;
6302 
6303   //
6304   //             A-top         }
6305   //           /   |   \       }  Tops
6306   //       B-top A-any C-top   }
6307   //          | /  |  \ |      }  Any-nulls
6308   //       B-any   |   C-any   }
6309   //          |    |    |
6310   //       B-con A-con C-con   } constants; not comparable across classes
6311   //          |    |    |
6312   //       B-not   |   C-not   }
6313   //          | \  |  / |      }  not-nulls
6314   //       B-bot A-not C-bot   }
6315   //           \   |   /       }  Bottoms
6316   //             A-bot         }
6317   //
6318 
6319   case AryKlassPtr: {  // Meet two KlassPtr types
6320     const TypeAryKlassPtr *tap = t->is_aryklassptr();
6321     int off = meet_offset(tap->offset());
6322     const Type* elem = _elem->meet(tap->_elem);
6323 
6324     PTR ptr = meet_ptr(tap->ptr());
6325     ciKlass* res_klass = nullptr;
6326     bool res_xk = false;
6327     meet_aryptr(ptr, elem, this, tap, res_klass, res_xk);
6328     assert(res_xk == (ptr == Constant), "");
6329     return make(ptr, elem, res_klass, off);
6330   } // End of case KlassPtr
6331   case InstKlassPtr: {
6332     const TypeInstKlassPtr *tp = t->is_instklassptr();
6333     int offset = meet_offset(tp->offset());
6334     PTR ptr = meet_ptr(tp->ptr());
6335     const TypeInterfaces* interfaces = meet_interfaces(tp);
6336     const TypeInterfaces* tp_interfaces = tp->_interfaces;
6337     const TypeInterfaces* this_interfaces = _interfaces;
6338 
6339     switch (ptr) {
6340     case TopPTR:
6341     case AnyNull:                // Fall 'down' to dual of object klass
6342       // For instances when a subclass meets a superclass we fall
6343       // below the centerline when the superclass is exact. We need to
6344       // do the same here.
6345       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
6346           !tp->klass_is_exact()) {
6347         return TypeAryKlassPtr::make(ptr, _elem, _klass, offset);
6348       } else {
6349         // cannot subclass, so the meet has to fall badly below the centerline
6350         ptr = NotNull;
6351         interfaces = this_interfaces->intersection_with(tp->_interfaces);
6352         return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
6353       }
6354     case Constant:
6355     case NotNull:
6356     case BotPTR:                // Fall down to object klass
6357       // LCA is object_klass, but if we subclass from the top we can do better
6358       if (above_centerline(tp->ptr())) {
6359         // If 'tp'  is above the centerline and it is Object class
6360         // then we can subclass in the Java class hierarchy.
6361         // For instances when a subclass meets a superclass we fall
6362         // below the centerline when the superclass is exact. We need
6363         // to do the same here.
6364         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
6365             !tp->klass_is_exact()) {
6366           // that is, my array type is a subtype of 'tp' klass
6367           return make(ptr, _elem, _klass, offset);
6368         }
6369       }
6370       // The other case cannot happen, since t cannot be a subtype of an array.
6371       // The meet falls down to Object class below centerline.
6372       if (ptr == Constant)
6373          ptr = NotNull;
6374       interfaces = this_interfaces->intersection_with(tp_interfaces);
6375       return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
6376     default: typerr(t);
6377     }
6378   }
6379 
6380   } // End of switch
6381   return this;                  // Return the double constant
6382 }
6383 
6384 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) {
6385   static_assert(std::is_base_of<T2, T1>::value, "");
6386 
6387   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
6388     return true;
6389   }
6390 
6391   int dummy;
6392   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6393 
6394   if (!this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
6395     return false;
6396   }
6397 
6398   if (this_one->is_instance_type(other)) {
6399     return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces) &&
6400            other_exact;
6401   }
6402 
6403   assert(this_one->is_array_type(other), "");
6404   const T1* other_ary = this_one->is_array_type(other);
6405   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
6406   if (other_top_or_bottom) {
6407     return false;
6408   }
6409 
6410   const TypePtr* other_elem = other_ary->elem()->make_ptr();
6411   const TypePtr* this_elem = this_one->elem()->make_ptr();
6412   if (this_elem != nullptr && other_elem != nullptr) {
6413     return this_one->is_reference_type(this_elem)->is_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6414   }
6415   if (this_elem == nullptr && other_elem == nullptr) {
6416     return this_one->klass()->is_subtype_of(other->klass());
6417   }
6418   return false;
6419 }
6420 
6421 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6422   return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6423 }
6424 
6425 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other) {
6426   static_assert(std::is_base_of<T2, T1>::value, "");
6427 
6428   int dummy;
6429   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6430 
6431   if (!this_one->is_array_type(other) ||
6432       !this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
6433     return false;
6434   }
6435   const T1* other_ary = this_one->is_array_type(other);
6436   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
6437 
6438   if (other_top_or_bottom) {
6439     return false;
6440   }
6441 
6442   const TypePtr* other_elem = other_ary->elem()->make_ptr();
6443   const TypePtr* this_elem = this_one->elem()->make_ptr();
6444   if (other_elem != nullptr && this_elem != nullptr) {
6445     return this_one->is_reference_type(this_elem)->is_same_java_type_as(this_one->is_reference_type(other_elem));
6446   }
6447   if (other_elem == nullptr && this_elem == nullptr) {
6448     return this_one->klass()->equals(other->klass());
6449   }
6450   return false;
6451 }
6452 
6453 bool TypeAryKlassPtr::is_same_java_type_as_helper(const TypeKlassPtr* other) const {
6454   return TypePtr::is_same_java_type_as_helper_for_array(this, other);
6455 }
6456 
6457 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) {
6458   static_assert(std::is_base_of<T2, T1>::value, "");
6459   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
6460     return true;
6461   }
6462   if (!this_one->is_loaded() || !other->is_loaded()) {
6463     return true;
6464   }
6465   if (this_one->is_instance_type(other)) {
6466     return other->klass()->equals(ciEnv::current()->Object_klass()) &&
6467            this_one->_interfaces->contains(other->_interfaces);
6468   }
6469 
6470   int dummy;
6471   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6472   if (this_top_or_bottom) {
6473     return true;
6474   }
6475 
6476   assert(this_one->is_array_type(other), "");
6477 
6478   const T1* other_ary = this_one->is_array_type(other);
6479   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
6480   if (other_top_or_bottom) {
6481     return true;
6482   }
6483   if (this_exact && other_exact) {
6484     return this_one->is_java_subtype_of(other);
6485   }
6486 
6487   const TypePtr* this_elem = this_one->elem()->make_ptr();
6488   const TypePtr* other_elem = other_ary->elem()->make_ptr();
6489   if (other_elem != nullptr && this_elem != nullptr) {
6490     return this_one->is_reference_type(this_elem)->maybe_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6491   }
6492   if (other_elem == nullptr && this_elem == nullptr) {
6493     return this_one->klass()->is_subtype_of(other->klass());
6494   }
6495   return false;
6496 }
6497 
6498 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6499   return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6500 }
6501 
6502 //------------------------------xdual------------------------------------------
6503 // Dual: compute field-by-field dual
6504 const Type    *TypeAryKlassPtr::xdual() const {
6505   return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset());
6506 }
6507 
6508 // Is there a single ciKlass* that can represent that type?
6509 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
6510   if (elem()->isa_klassptr()) {
6511     ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
6512     if (k == nullptr) {
6513       return nullptr;
6514     }
6515     k = ciObjArrayKlass::make(k);
6516     return k;
6517   }
6518 
6519   return klass();
6520 }
6521 
6522 ciKlass* TypeAryKlassPtr::klass() const {
6523   if (_klass != nullptr) {
6524     return _klass;
6525   }
6526   ciKlass* k = nullptr;
6527   if (elem()->isa_klassptr()) {
6528     // leave null
6529   } else if ((elem()->base() == Type::Top) ||
6530              (elem()->base() == Type::Bottom)) {
6531   } else {
6532     k = ciTypeArrayKlass::make(elem()->basic_type());
6533     ((TypeAryKlassPtr*)this)->_klass = k;
6534   }
6535   return k;
6536 }
6537 
6538 //------------------------------dump2------------------------------------------
6539 // Dump Klass Type
6540 #ifndef PRODUCT
6541 void TypeAryKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
6542   switch( _ptr ) {
6543   case Constant:
6544     st->print("precise ");
6545   case NotNull:
6546     {
6547       st->print("[");
6548       _elem->dump2(d, depth, st);
6549       _interfaces->dump(st);
6550       st->print(": ");
6551     }
6552   case BotPTR:
6553     if( !WizardMode && !Verbose && _ptr != Constant ) break;
6554   case TopPTR:
6555   case AnyNull:
6556     st->print(":%s", ptr_msg[_ptr]);
6557     if( _ptr == Constant ) st->print(":exact");
6558     break;
6559   default:
6560     break;
6561   }
6562 
6563   if( _offset ) {               // Dump offset, if any
6564     if( _offset == OffsetBot )      { st->print("+any"); }
6565     else if( _offset == OffsetTop ) { st->print("+unknown"); }
6566     else                            { st->print("+%d", _offset); }
6567   }
6568 
6569   st->print(" *");
6570 }
6571 #endif
6572 
6573 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
6574   const Type* elem = this->elem();
6575   dims = 1;
6576   while (elem->isa_aryklassptr()) {
6577     elem = elem->is_aryklassptr()->elem();
6578     dims++;
6579   }
6580   return elem;
6581 }
6582 
6583 //=============================================================================
6584 // Convenience common pre-built types.
6585 
6586 //------------------------------make-------------------------------------------
6587 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
6588   return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();
6589 }
6590 
6591 //------------------------------make-------------------------------------------
6592 const TypeFunc *TypeFunc::make(ciMethod* method) {
6593   Compile* C = Compile::current();
6594   const TypeFunc* tf = C->last_tf(method); // check cache
6595   if (tf != nullptr)  return tf;  // The hit rate here is almost 50%.
6596   const TypeTuple *domain;
6597   if (method->is_static()) {
6598     domain = TypeTuple::make_domain(nullptr, method->signature(), ignore_interfaces);
6599   } else {
6600     domain = TypeTuple::make_domain(method->holder(), method->signature(), ignore_interfaces);
6601   }
6602   const TypeTuple *range  = TypeTuple::make_range(method->signature(), ignore_interfaces);
6603   tf = TypeFunc::make(domain, range);
6604   C->set_last_tf(method, tf);  // fill cache
6605   return tf;
6606 }
6607 
6608 //------------------------------meet-------------------------------------------
6609 // Compute the MEET of two types.  It returns a new Type object.
6610 const Type *TypeFunc::xmeet( const Type *t ) const {
6611   // Perform a fast test for common case; meeting the same types together.
6612   if( this == t ) return this;  // Meeting same type-rep?
6613 
6614   // Current "this->_base" is Func
6615   switch (t->base()) {          // switch on original type
6616 
6617   case Bottom:                  // Ye Olde Default
6618     return t;
6619 
6620   default:                      // All else is a mistake
6621     typerr(t);
6622 
6623   case Top:
6624     break;
6625   }
6626   return this;                  // Return the double constant
6627 }
6628 
6629 //------------------------------xdual------------------------------------------
6630 // Dual: compute field-by-field dual
6631 const Type *TypeFunc::xdual() const {
6632   return this;
6633 }
6634 
6635 //------------------------------eq---------------------------------------------
6636 // Structural equality check for Type representations
6637 bool TypeFunc::eq( const Type *t ) const {
6638   const TypeFunc *a = (const TypeFunc*)t;
6639   return _domain == a->_domain &&
6640     _range == a->_range;
6641 }
6642 
6643 //------------------------------hash-------------------------------------------
6644 // Type-specific hashing function.
6645 uint TypeFunc::hash(void) const {
6646   return (uint)(uintptr_t)_domain + (uint)(uintptr_t)_range;
6647 }
6648 
6649 //------------------------------dump2------------------------------------------
6650 // Dump Function Type
6651 #ifndef PRODUCT
6652 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
6653   if( _range->cnt() <= Parms )
6654     st->print("void");
6655   else {
6656     uint i;
6657     for (i = Parms; i < _range->cnt()-1; i++) {
6658       _range->field_at(i)->dump2(d,depth,st);
6659       st->print("/");
6660     }
6661     _range->field_at(i)->dump2(d,depth,st);
6662   }
6663   st->print(" ");
6664   st->print("( ");
6665   if( !depth || d[this] ) {     // Check for recursive dump
6666     st->print("...)");
6667     return;
6668   }
6669   d.Insert((void*)this,(void*)this);    // Stop recursion
6670   if (Parms < _domain->cnt())
6671     _domain->field_at(Parms)->dump2(d,depth-1,st);
6672   for (uint i = Parms+1; i < _domain->cnt(); i++) {
6673     st->print(", ");
6674     _domain->field_at(i)->dump2(d,depth-1,st);
6675   }
6676   st->print(" )");
6677 }
6678 #endif
6679 
6680 //------------------------------singleton--------------------------------------
6681 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
6682 // constants (Ldi nodes).  Singletons are integer, float or double constants
6683 // or a single symbol.
6684 bool TypeFunc::singleton(void) const {
6685   return false;                 // Never a singleton
6686 }
6687 
6688 bool TypeFunc::empty(void) const {
6689   return false;                 // Never empty
6690 }
6691 
6692 
6693 BasicType TypeFunc::return_type() const{
6694   if (range()->cnt() == TypeFunc::Parms) {
6695     return T_VOID;
6696   }
6697   return range()->field_at(TypeFunc::Parms)->basic_type();
6698 }