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