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