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