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