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