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->with_speculative(speculative); }
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->with_speculative(speculative); }
4179     else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
4180       if (unloaded->ptr() == TypePtr::BotPTR)    { return TypeInstPtr::BOTTOM->with_speculative(speculative);  }
4181       else                                       { return TypeInstPtr::NOTNULL->with_speculative(speculative); }
4182     }
4183     else if (unloaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); }
4184 
4185     return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr()->with_speculative(speculative);
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->with_speculative(speculative);
4192   }
4193   return TypeInstPtr::BOTTOM->with_speculative(speculative);
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 TypeInstPtr* TypeInstPtr::with_speculative(const TypePtr* speculative) const {
4597   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _instance_id, speculative, _inline_depth);
4598 }
4599 
4600 const TypePtr* TypeInstPtr::with_inline_depth(int depth) const {
4601   if (!UseInlineDepthForSpeculativeTypes) {
4602     return this;
4603   }
4604   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth);
4605 }
4606 
4607 const TypePtr* TypeInstPtr::with_instance_id(int instance_id) const {
4608   assert(is_known_instance(), "should be known");
4609   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, instance_id, _speculative, _inline_depth);
4610 }
4611 
4612 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4613   bool xk = klass_is_exact();
4614   ciInstanceKlass* ik = klass()->as_instance_klass();
4615   if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final()) {
4616     if (_interfaces->eq(ik)) {
4617       Compile* C = Compile::current();
4618       Dependencies* deps = C->dependencies();
4619       deps->assert_leaf_type(ik);
4620       xk = true;
4621     }
4622   }
4623   return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), _interfaces, 0);
4624 }
4625 
4626 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) {
4627   static_assert(std::is_base_of<T2, T1>::value, "");
4628 
4629   if (!this_one->is_instance_type(other)) {
4630     return false;
4631   }
4632 
4633   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4634     return true;
4635   }
4636 
4637   return this_one->klass()->is_subtype_of(other->klass()) &&
4638          (!this_xk || this_one->_interfaces->contains(other->_interfaces));
4639 }
4640 
4641 
4642 bool TypeInstPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4643   return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4644 }
4645 
4646 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) {
4647   static_assert(std::is_base_of<T2, T1>::value, "");
4648   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4649     return true;
4650   }
4651 
4652   if (this_one->is_instance_type(other)) {
4653     return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces);
4654   }
4655 
4656   int dummy;
4657   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
4658   if (this_top_or_bottom) {
4659     return false;
4660   }
4661 
4662   const T1* other_ary = this_one->is_array_type(other);
4663   const TypePtr* other_elem = other_ary->elem()->make_ptr();
4664   const TypePtr* this_elem = this_one->elem()->make_ptr();
4665   if (other_elem != nullptr && this_elem != nullptr) {
4666     return this_one->is_reference_type(this_elem)->is_meet_subtype_of_helper(this_one->is_reference_type(other_elem), this_xk, other_xk);
4667   }
4668 
4669   if (other_elem == nullptr && this_elem == nullptr) {
4670     return this_one->klass()->is_subtype_of(other->klass());
4671   }
4672 
4673   return false;
4674 }
4675 
4676 bool TypeAryPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4677   return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4678 }
4679 
4680 bool TypeInstKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4681   return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4682 }
4683 
4684 bool TypeAryKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4685   return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4686 }
4687 
4688 //=============================================================================
4689 // Convenience common pre-built types.
4690 const TypeAryPtr *TypeAryPtr::RANGE;
4691 const TypeAryPtr *TypeAryPtr::OOPS;
4692 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
4693 const TypeAryPtr *TypeAryPtr::BYTES;
4694 const TypeAryPtr *TypeAryPtr::SHORTS;
4695 const TypeAryPtr *TypeAryPtr::CHARS;
4696 const TypeAryPtr *TypeAryPtr::INTS;
4697 const TypeAryPtr *TypeAryPtr::LONGS;
4698 const TypeAryPtr *TypeAryPtr::FLOATS;
4699 const TypeAryPtr *TypeAryPtr::DOUBLES;
4700 
4701 //------------------------------make-------------------------------------------
4702 const TypeAryPtr *TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4703                                    int instance_id, const TypePtr* speculative, int inline_depth) {
4704   assert(!(k == nullptr && ary->_elem->isa_int()),
4705          "integral arrays must be pre-equipped with a class");
4706   if (!xk)  xk = ary->ary_must_be_exact();
4707   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4708   if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4709       k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4710     k = nullptr;
4711   }
4712   return (TypeAryPtr*)(new TypeAryPtr(ptr, nullptr, ary, k, xk, offset, instance_id, false, speculative, inline_depth))->hashcons();
4713 }
4714 
4715 //------------------------------make-------------------------------------------
4716 const TypeAryPtr *TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4717                                    int instance_id, const TypePtr* speculative, int inline_depth,
4718                                    bool is_autobox_cache) {
4719   assert(!(k == nullptr && ary->_elem->isa_int()),
4720          "integral arrays must be pre-equipped with a class");
4721   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4722   if (!xk)  xk = (o != nullptr) || ary->ary_must_be_exact();
4723   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4724   if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4725       k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4726     k = nullptr;
4727   }
4728   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4729 }
4730 
4731 //------------------------------cast_to_ptr_type-------------------------------
4732 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4733   if( ptr == _ptr ) return this;
4734   return make(ptr, ptr == Constant ? const_oop() : nullptr, _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4735 }
4736 
4737 
4738 //-----------------------------cast_to_exactness-------------------------------
4739 const TypeAryPtr* TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4740   if( klass_is_exact == _klass_is_exact ) return this;
4741   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
4742   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
4743 }
4744 
4745 //-----------------------------cast_to_instance_id----------------------------
4746 const TypeAryPtr* TypeAryPtr::cast_to_instance_id(int instance_id) const {
4747   if( instance_id == _instance_id ) return this;
4748   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
4749 }
4750 
4751 
4752 //-----------------------------max_array_length-------------------------------
4753 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
4754 jint TypeAryPtr::max_array_length(BasicType etype) {
4755   if (!is_java_primitive(etype) && !::is_reference_type(etype)) {
4756     if (etype == T_NARROWOOP) {
4757       etype = T_OBJECT;
4758     } else if (etype == T_ILLEGAL) { // bottom[]
4759       etype = T_BYTE; // will produce conservatively high value
4760     } else {
4761       fatal("not an element type: %s", type2name(etype));
4762     }
4763   }
4764   return arrayOopDesc::max_array_length(etype);
4765 }
4766 
4767 //-----------------------------narrow_size_type-------------------------------
4768 // Narrow the given size type to the index range for the given array base type.
4769 // Return null if the resulting int type becomes empty.
4770 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const {
4771   jint hi = size->_hi;
4772   jint lo = size->_lo;
4773   jint min_lo = 0;
4774   jint max_hi = max_array_length(elem()->array_element_basic_type());
4775   //if (index_not_size)  --max_hi;     // type of a valid array index, FTR
4776   bool chg = false;
4777   if (lo < min_lo) {
4778     lo = min_lo;
4779     if (size->is_con()) {
4780       hi = lo;
4781     }
4782     chg = true;
4783   }
4784   if (hi > max_hi) {
4785     hi = max_hi;
4786     if (size->is_con()) {
4787       lo = hi;
4788     }
4789     chg = true;
4790   }
4791   // Negative length arrays will produce weird intermediate dead fast-path code
4792   if (lo > hi)
4793     return TypeInt::ZERO;
4794   if (!chg)
4795     return size;
4796   return TypeInt::make(lo, hi, Type::WidenMin);
4797 }
4798 
4799 //-------------------------------cast_to_size----------------------------------
4800 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4801   assert(new_size != nullptr, "");
4802   new_size = narrow_size_type(new_size);
4803   if (new_size == size())  return this;
4804   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
4805   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4806 }
4807 
4808 //------------------------------cast_to_stable---------------------------------
4809 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
4810   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
4811     return this;
4812 
4813   const Type* elem = this->elem();
4814   const TypePtr* elem_ptr = elem->make_ptr();
4815 
4816   if (stable_dimension > 1 && elem_ptr != nullptr && elem_ptr->isa_aryptr()) {
4817     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
4818     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
4819   }
4820 
4821   const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
4822 
4823   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4824 }
4825 
4826 //-----------------------------stable_dimension--------------------------------
4827 int TypeAryPtr::stable_dimension() const {
4828   if (!is_stable())  return 0;
4829   int dim = 1;
4830   const TypePtr* elem_ptr = elem()->make_ptr();
4831   if (elem_ptr != nullptr && elem_ptr->isa_aryptr())
4832     dim += elem_ptr->is_aryptr()->stable_dimension();
4833   return dim;
4834 }
4835 
4836 //----------------------cast_to_autobox_cache-----------------------------------
4837 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
4838   if (is_autobox_cache())  return this;
4839   const TypeOopPtr* etype = elem()->make_oopptr();
4840   if (etype == nullptr)  return this;
4841   // The pointers in the autobox arrays are always non-null.
4842   etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
4843   const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable());
4844   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
4845 }
4846 
4847 //------------------------------eq---------------------------------------------
4848 // Structural equality check for Type representations
4849 bool TypeAryPtr::eq( const Type *t ) const {
4850   const TypeAryPtr *p = t->is_aryptr();
4851   return
4852     _ary == p->_ary &&  // Check array
4853     TypeOopPtr::eq(p);  // Check sub-parts
4854 }
4855 
4856 //------------------------------hash-------------------------------------------
4857 // Type-specific hashing function.
4858 uint TypeAryPtr::hash(void) const {
4859   return (uint)(uintptr_t)_ary + TypeOopPtr::hash();
4860 }
4861 
4862 bool TypeAryPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4863   return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
4864 }
4865 
4866 bool TypeAryPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4867   return TypePtr::is_same_java_type_as_helper_for_array(this, other);
4868 }
4869 
4870 bool TypeAryPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4871   return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
4872 }
4873 //------------------------------meet-------------------------------------------
4874 // Compute the MEET of two types.  It returns a new Type object.
4875 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
4876   // Perform a fast test for common case; meeting the same types together.
4877   if( this == t ) return this;  // Meeting same type-rep?
4878   // Current "this->_base" is Pointer
4879   switch (t->base()) {          // switch on original type
4880 
4881   // Mixing ints & oops happens when javac reuses local variables
4882   case Int:
4883   case Long:
4884   case FloatTop:
4885   case FloatCon:
4886   case FloatBot:
4887   case DoubleTop:
4888   case DoubleCon:
4889   case DoubleBot:
4890   case NarrowOop:
4891   case NarrowKlass:
4892   case Bottom:                  // Ye Olde Default
4893     return Type::BOTTOM;
4894   case Top:
4895     return this;
4896 
4897   default:                      // All else is a mistake
4898     typerr(t);
4899 
4900   case OopPtr: {                // Meeting to OopPtrs
4901     // Found a OopPtr type vs self-AryPtr type
4902     const TypeOopPtr *tp = t->is_oopptr();
4903     int offset = meet_offset(tp->offset());
4904     PTR ptr = meet_ptr(tp->ptr());
4905     int depth = meet_inline_depth(tp->inline_depth());
4906     const TypePtr* speculative = xmeet_speculative(tp);
4907     switch (tp->ptr()) {
4908     case TopPTR:
4909     case AnyNull: {
4910       int instance_id = meet_instance_id(InstanceTop);
4911       return make(ptr, (ptr == Constant ? const_oop() : nullptr),
4912                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4913     }
4914     case BotPTR:
4915     case NotNull: {
4916       int instance_id = meet_instance_id(tp->instance_id());
4917       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4918     }
4919     default: ShouldNotReachHere();
4920     }
4921   }
4922 
4923   case AnyPtr: {                // Meeting two AnyPtrs
4924     // Found an AnyPtr type vs self-AryPtr type
4925     const TypePtr *tp = t->is_ptr();
4926     int offset = meet_offset(tp->offset());
4927     PTR ptr = meet_ptr(tp->ptr());
4928     const TypePtr* speculative = xmeet_speculative(tp);
4929     int depth = meet_inline_depth(tp->inline_depth());
4930     switch (tp->ptr()) {
4931     case TopPTR:
4932       return this;
4933     case BotPTR:
4934     case NotNull:
4935       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4936     case Null:
4937       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4938       // else fall through to AnyNull
4939     case AnyNull: {
4940       int instance_id = meet_instance_id(InstanceTop);
4941       return make(ptr, (ptr == Constant ? const_oop() : nullptr),
4942                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4943     }
4944     default: ShouldNotReachHere();
4945     }
4946   }
4947 
4948   case MetadataPtr:
4949   case KlassPtr:
4950   case InstKlassPtr:
4951   case AryKlassPtr:
4952   case RawPtr: return TypePtr::BOTTOM;
4953 
4954   case AryPtr: {                // Meeting 2 references?
4955     const TypeAryPtr *tap = t->is_aryptr();
4956     int off = meet_offset(tap->offset());
4957     const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
4958     PTR ptr = meet_ptr(tap->ptr());
4959     int instance_id = meet_instance_id(tap->instance_id());
4960     const TypePtr* speculative = xmeet_speculative(tap);
4961     int depth = meet_inline_depth(tap->inline_depth());
4962 
4963     ciKlass* res_klass = nullptr;
4964     bool res_xk = false;
4965     const Type* elem = tary->_elem;
4966     if (meet_aryptr(ptr, elem, this, tap, res_klass, res_xk) == NOT_SUBTYPE) {
4967       instance_id = InstanceBot;
4968     }
4969 
4970     ciObject* o = nullptr;             // Assume not constant when done
4971     ciObject* this_oop = const_oop();
4972     ciObject* tap_oop = tap->const_oop();
4973     if (ptr == Constant) {
4974       if (this_oop != nullptr && tap_oop != nullptr &&
4975           this_oop->equals(tap_oop)) {
4976         o = tap_oop;
4977       } else if (above_centerline(_ptr)) {
4978         o = tap_oop;
4979       } else if (above_centerline(tap->_ptr)) {
4980         o = this_oop;
4981       } else {
4982         ptr = NotNull;
4983       }
4984     }
4985     return make(ptr, o, TypeAry::make(elem, tary->_size, tary->_stable), res_klass, res_xk, off, instance_id, speculative, depth);
4986   }
4987 
4988   // All arrays inherit from Object class
4989   case InstPtr: {
4990     const TypeInstPtr *tp = t->is_instptr();
4991     int offset = meet_offset(tp->offset());
4992     PTR ptr = meet_ptr(tp->ptr());
4993     int instance_id = meet_instance_id(tp->instance_id());
4994     const TypePtr* speculative = xmeet_speculative(tp);
4995     int depth = meet_inline_depth(tp->inline_depth());
4996     const TypeInterfaces* interfaces = meet_interfaces(tp);
4997     const TypeInterfaces* tp_interfaces = tp->_interfaces;
4998     const TypeInterfaces* this_interfaces = _interfaces;
4999 
5000     switch (ptr) {
5001     case TopPTR:
5002     case AnyNull:                // Fall 'down' to dual of object klass
5003       // For instances when a subclass meets a superclass we fall
5004       // below the centerline when the superclass is exact. We need to
5005       // do the same here.
5006       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact()) {
5007         return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
5008       } else {
5009         // cannot subclass, so the meet has to fall badly below the centerline
5010         ptr = NotNull;
5011         instance_id = InstanceBot;
5012         interfaces = this_interfaces->intersection_with(tp_interfaces);
5013         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr,offset, instance_id, speculative, depth);
5014       }
5015     case Constant:
5016     case NotNull:
5017     case BotPTR:                // Fall down to object klass
5018       // LCA is object_klass, but if we subclass from the top we can do better
5019       if (above_centerline(tp->ptr())) {
5020         // If 'tp'  is above the centerline and it is Object class
5021         // then we can subclass in the Java class hierarchy.
5022         // For instances when a subclass meets a superclass we fall
5023         // below the centerline when the superclass is exact. We need
5024         // to do the same here.
5025         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact()) {
5026           // that is, my array type is a subtype of 'tp' klass
5027           return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5028                       _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
5029         }
5030       }
5031       // The other case cannot happen, since t cannot be a subtype of an array.
5032       // The meet falls down to Object class below centerline.
5033       if (ptr == Constant) {
5034          ptr = NotNull;
5035       }
5036       if (instance_id > 0) {
5037         instance_id = InstanceBot;
5038       }
5039       interfaces = this_interfaces->intersection_with(tp_interfaces);
5040       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset, instance_id, speculative, depth);
5041     default: typerr(t);
5042     }
5043   }
5044   }
5045   return this;                  // Lint noise
5046 }
5047 
5048 
5049 template<class T> TypePtr::MeetResult TypePtr::meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary,
5050                                                            const T* other_ary, ciKlass*& res_klass, bool& res_xk) {
5051   int dummy;
5052   bool this_top_or_bottom = (this_ary->base_element_type(dummy) == Type::TOP || this_ary->base_element_type(dummy) == Type::BOTTOM);
5053   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
5054   ciKlass* this_klass = this_ary->klass();
5055   ciKlass* other_klass = other_ary->klass();
5056   bool this_xk = this_ary->klass_is_exact();
5057   bool other_xk = other_ary->klass_is_exact();
5058   PTR this_ptr = this_ary->ptr();
5059   PTR other_ptr = other_ary->ptr();
5060   res_klass = nullptr;
5061   MeetResult result = SUBTYPE;
5062   if (elem->isa_int()) {
5063     // Integral array element types have irrelevant lattice relations.
5064     // It is the klass that determines array layout, not the element type.
5065     if (this_top_or_bottom)
5066       res_klass = other_klass;
5067     else if (other_top_or_bottom || other_klass == this_klass) {
5068       res_klass = this_klass;
5069     } else {
5070       // Something like byte[int+] meets char[int+].
5071       // This must fall to bottom, not (int[-128..65535])[int+].
5072       // instance_id = InstanceBot;
5073       elem = Type::BOTTOM;
5074       result = NOT_SUBTYPE;
5075       if (above_centerline(ptr) || ptr == Constant) {
5076         ptr = NotNull;
5077         res_xk = false;
5078         return NOT_SUBTYPE;
5079       }
5080     }
5081   } else {// Non integral arrays.
5082     // Must fall to bottom if exact klasses in upper lattice
5083     // are not equal or super klass is exact.
5084     if ((above_centerline(ptr) || ptr == Constant) && !this_ary->is_same_java_type_as(other_ary) &&
5085         // meet with top[] and bottom[] are processed further down:
5086         !this_top_or_bottom && !other_top_or_bottom &&
5087         // both are exact and not equal:
5088         ((other_xk && this_xk) ||
5089          // 'tap'  is exact and super or unrelated:
5090          (other_xk && !other_ary->is_meet_subtype_of(this_ary)) ||
5091          // 'this' is exact and super or unrelated:
5092          (this_xk && !this_ary->is_meet_subtype_of(other_ary)))) {
5093       if (above_centerline(ptr) || (elem->make_ptr() && above_centerline(elem->make_ptr()->_ptr))) {
5094         elem = Type::BOTTOM;
5095       }
5096       ptr = NotNull;
5097       res_xk = false;
5098       return NOT_SUBTYPE;
5099     }
5100   }
5101 
5102   res_xk = false;
5103   switch (other_ptr) {
5104     case AnyNull:
5105     case TopPTR:
5106       // Compute new klass on demand, do not use tap->_klass
5107       if (below_centerline(this_ptr)) {
5108         res_xk = this_xk;
5109       } else {
5110         res_xk = (other_xk || this_xk);
5111       }
5112       return result;
5113     case Constant: {
5114       if (this_ptr == Constant) {
5115         res_xk = true;
5116       } else if(above_centerline(this_ptr)) {
5117         res_xk = true;
5118       } else {
5119         // Only precise for identical arrays
5120         res_xk = this_xk && (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom));
5121       }
5122       return result;
5123     }
5124     case NotNull:
5125     case BotPTR:
5126       // Compute new klass on demand, do not use tap->_klass
5127       if (above_centerline(this_ptr)) {
5128         res_xk = other_xk;
5129       } else {
5130         res_xk = (other_xk && this_xk) &&
5131                  (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom)); // Only precise for identical arrays
5132       }
5133       return result;
5134     default:  {
5135       ShouldNotReachHere();
5136       return result;
5137     }
5138   }
5139   return result;
5140 }
5141 
5142 
5143 //------------------------------xdual------------------------------------------
5144 // Dual: compute field-by-field dual
5145 const Type *TypeAryPtr::xdual() const {
5146   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());
5147 }
5148 
5149 //------------------------------dump2------------------------------------------
5150 #ifndef PRODUCT
5151 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5152   _ary->dump2(d,depth,st);
5153   _interfaces->dump(st);
5154 
5155   switch( _ptr ) {
5156   case Constant:
5157     const_oop()->print(st);
5158     break;
5159   case BotPTR:
5160     if (!WizardMode && !Verbose) {
5161       if( _klass_is_exact ) st->print(":exact");
5162       break;
5163     }
5164   case TopPTR:
5165   case AnyNull:
5166   case NotNull:
5167     st->print(":%s", ptr_msg[_ptr]);
5168     if( _klass_is_exact ) st->print(":exact");
5169     break;
5170   default:
5171     break;
5172   }
5173 
5174   if( _offset != 0 ) {
5175     BasicType basic_elem_type = elem()->basic_type();
5176     int header_size = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5177     if( _offset == OffsetTop )       st->print("+undefined");
5178     else if( _offset == OffsetBot )  st->print("+any");
5179     else if( _offset < header_size ) st->print("+%d", _offset);
5180     else {
5181       if (basic_elem_type == T_ILLEGAL) {
5182         st->print("+any");
5183       } else {
5184         int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5185         int elem_size = type2aelembytes(basic_elem_type);
5186         st->print("[%d]", (_offset - array_base)/elem_size);
5187       }
5188     }
5189   }
5190   st->print(" *");
5191   if (_instance_id == InstanceTop)
5192     st->print(",iid=top");
5193   else if (_instance_id != InstanceBot)
5194     st->print(",iid=%d",_instance_id);
5195 
5196   dump_inline_depth(st);
5197   dump_speculative(st);
5198 }
5199 #endif
5200 
5201 bool TypeAryPtr::empty(void) const {
5202   if (_ary->empty())       return true;
5203   return TypeOopPtr::empty();
5204 }
5205 
5206 //------------------------------add_offset-------------------------------------
5207 const TypePtr* TypeAryPtr::add_offset(intptr_t offset) const {
5208   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
5209 }
5210 
5211 const TypeAryPtr* TypeAryPtr::with_offset(intptr_t offset) const {
5212   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, offset, _instance_id, with_offset_speculative(offset), _inline_depth);
5213 }
5214 
5215 const TypeAryPtr* TypeAryPtr::with_ary(const TypeAry* ary) const {
5216   return make(_ptr, _const_oop, ary, _klass, _klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
5217 }
5218 
5219 const TypeAryPtr* TypeAryPtr::remove_speculative() const {
5220   if (_speculative == nullptr) {
5221     return this;
5222   }
5223   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
5224   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, nullptr, _inline_depth);
5225 }
5226 
5227 const TypePtr* TypeAryPtr::with_inline_depth(int depth) const {
5228   if (!UseInlineDepthForSpeculativeTypes) {
5229     return this;
5230   }
5231   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, _speculative, depth);
5232 }
5233 
5234 const TypePtr* TypeAryPtr::with_instance_id(int instance_id) const {
5235   assert(is_known_instance(), "should be known");
5236   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
5237 }
5238 
5239 //=============================================================================
5240 
5241 //------------------------------hash-------------------------------------------
5242 // Type-specific hashing function.
5243 uint TypeNarrowPtr::hash(void) const {
5244   return _ptrtype->hash() + 7;
5245 }
5246 
5247 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
5248   return _ptrtype->singleton();
5249 }
5250 
5251 bool TypeNarrowPtr::empty(void) const {
5252   return _ptrtype->empty();
5253 }
5254 
5255 intptr_t TypeNarrowPtr::get_con() const {
5256   return _ptrtype->get_con();
5257 }
5258 
5259 bool TypeNarrowPtr::eq( const Type *t ) const {
5260   const TypeNarrowPtr* tc = isa_same_narrowptr(t);
5261   if (tc != nullptr) {
5262     if (_ptrtype->base() != tc->_ptrtype->base()) {
5263       return false;
5264     }
5265     return tc->_ptrtype->eq(_ptrtype);
5266   }
5267   return false;
5268 }
5269 
5270 const Type *TypeNarrowPtr::xdual() const {    // Compute dual right now.
5271   const TypePtr* odual = _ptrtype->dual()->is_ptr();
5272   return make_same_narrowptr(odual);
5273 }
5274 
5275 
5276 const Type *TypeNarrowPtr::filter_helper(const Type *kills, bool include_speculative) const {
5277   if (isa_same_narrowptr(kills)) {
5278     const Type* ft =_ptrtype->filter_helper(is_same_narrowptr(kills)->_ptrtype, include_speculative);
5279     if (ft->empty())
5280       return Type::TOP;           // Canonical empty value
5281     if (ft->isa_ptr()) {
5282       return make_hash_same_narrowptr(ft->isa_ptr());
5283     }
5284     return ft;
5285   } else if (kills->isa_ptr()) {
5286     const Type* ft = _ptrtype->join_helper(kills, include_speculative);
5287     if (ft->empty())
5288       return Type::TOP;           // Canonical empty value
5289     return ft;
5290   } else {
5291     return Type::TOP;
5292   }
5293 }
5294 
5295 //------------------------------xmeet------------------------------------------
5296 // Compute the MEET of two types.  It returns a new Type object.
5297 const Type *TypeNarrowPtr::xmeet( const Type *t ) const {
5298   // Perform a fast test for common case; meeting the same types together.
5299   if( this == t ) return this;  // Meeting same type-rep?
5300 
5301   if (t->base() == base()) {
5302     const Type* result = _ptrtype->xmeet(t->make_ptr());
5303     if (result->isa_ptr()) {
5304       return make_hash_same_narrowptr(result->is_ptr());
5305     }
5306     return result;
5307   }
5308 
5309   // Current "this->_base" is NarrowKlass or NarrowOop
5310   switch (t->base()) {          // switch on original type
5311 
5312   case Int:                     // Mixing ints & oops happens when javac
5313   case Long:                    // reuses local variables
5314   case FloatTop:
5315   case FloatCon:
5316   case FloatBot:
5317   case DoubleTop:
5318   case DoubleCon:
5319   case DoubleBot:
5320   case AnyPtr:
5321   case RawPtr:
5322   case OopPtr:
5323   case InstPtr:
5324   case AryPtr:
5325   case MetadataPtr:
5326   case KlassPtr:
5327   case InstKlassPtr:
5328   case AryKlassPtr:
5329   case NarrowOop:
5330   case NarrowKlass:
5331 
5332   case Bottom:                  // Ye Olde Default
5333     return Type::BOTTOM;
5334   case Top:
5335     return this;
5336 
5337   default:                      // All else is a mistake
5338     typerr(t);
5339 
5340   } // End of switch
5341 
5342   return this;
5343 }
5344 
5345 #ifndef PRODUCT
5346 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5347   _ptrtype->dump2(d, depth, st);
5348 }
5349 #endif
5350 
5351 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
5352 const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
5353 
5354 
5355 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
5356   return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();
5357 }
5358 
5359 const TypeNarrowOop* TypeNarrowOop::remove_speculative() const {
5360   return make(_ptrtype->remove_speculative()->is_ptr());
5361 }
5362 
5363 const Type* TypeNarrowOop::cleanup_speculative() const {
5364   return make(_ptrtype->cleanup_speculative()->is_ptr());
5365 }
5366 
5367 #ifndef PRODUCT
5368 void TypeNarrowOop::dump2( Dict & d, uint depth, outputStream *st ) const {
5369   st->print("narrowoop: ");
5370   TypeNarrowPtr::dump2(d, depth, st);
5371 }
5372 #endif
5373 
5374 const TypeNarrowKlass *TypeNarrowKlass::NULL_PTR;
5375 
5376 const TypeNarrowKlass* TypeNarrowKlass::make(const TypePtr* type) {
5377   return (const TypeNarrowKlass*)(new TypeNarrowKlass(type))->hashcons();
5378 }
5379 
5380 #ifndef PRODUCT
5381 void TypeNarrowKlass::dump2( Dict & d, uint depth, outputStream *st ) const {
5382   st->print("narrowklass: ");
5383   TypeNarrowPtr::dump2(d, depth, st);
5384 }
5385 #endif
5386 
5387 
5388 //------------------------------eq---------------------------------------------
5389 // Structural equality check for Type representations
5390 bool TypeMetadataPtr::eq( const Type *t ) const {
5391   const TypeMetadataPtr *a = (const TypeMetadataPtr*)t;
5392   ciMetadata* one = metadata();
5393   ciMetadata* two = a->metadata();
5394   if (one == nullptr || two == nullptr) {
5395     return (one == two) && TypePtr::eq(t);
5396   } else {
5397     return one->equals(two) && TypePtr::eq(t);
5398   }
5399 }
5400 
5401 //------------------------------hash-------------------------------------------
5402 // Type-specific hashing function.
5403 uint TypeMetadataPtr::hash(void) const {
5404   return
5405     (metadata() ? metadata()->hash() : 0) +
5406     TypePtr::hash();
5407 }
5408 
5409 //------------------------------singleton--------------------------------------
5410 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5411 // constants
5412 bool TypeMetadataPtr::singleton(void) const {
5413   // detune optimizer to not generate constant metadata + constant offset as a constant!
5414   // TopPTR, Null, AnyNull, Constant are all singletons
5415   return (_offset == 0) && !below_centerline(_ptr);
5416 }
5417 
5418 //------------------------------add_offset-------------------------------------
5419 const TypePtr* TypeMetadataPtr::add_offset( intptr_t offset ) const {
5420   return make( _ptr, _metadata, xadd_offset(offset));
5421 }
5422 
5423 //-----------------------------filter------------------------------------------
5424 // Do not allow interface-vs.-noninterface joins to collapse to top.
5425 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
5426   const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
5427   if (ft == nullptr || ft->empty())
5428     return Type::TOP;           // Canonical empty value
5429   return ft;
5430 }
5431 
5432  //------------------------------get_con----------------------------------------
5433 intptr_t TypeMetadataPtr::get_con() const {
5434   assert( _ptr == Null || _ptr == Constant, "" );
5435   assert( _offset >= 0, "" );
5436 
5437   if (_offset != 0) {
5438     // After being ported to the compiler interface, the compiler no longer
5439     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5440     // to a handle at compile time.  This handle is embedded in the generated
5441     // code and dereferenced at the time the nmethod is made.  Until that time,
5442     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5443     // have access to the addresses!).  This does not seem to currently happen,
5444     // but this assertion here is to help prevent its occurrence.
5445     tty->print_cr("Found oop constant with non-zero offset");
5446     ShouldNotReachHere();
5447   }
5448 
5449   return (intptr_t)metadata()->constant_encoding();
5450 }
5451 
5452 //------------------------------cast_to_ptr_type-------------------------------
5453 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
5454   if( ptr == _ptr ) return this;
5455   return make(ptr, metadata(), _offset);
5456 }
5457 
5458 //------------------------------meet-------------------------------------------
5459 // Compute the MEET of two types.  It returns a new Type object.
5460 const Type *TypeMetadataPtr::xmeet( const Type *t ) const {
5461   // Perform a fast test for common case; meeting the same types together.
5462   if( this == t ) return this;  // Meeting same type-rep?
5463 
5464   // Current "this->_base" is OopPtr
5465   switch (t->base()) {          // switch on original type
5466 
5467   case Int:                     // Mixing ints & oops happens when javac
5468   case Long:                    // reuses local variables
5469   case FloatTop:
5470   case FloatCon:
5471   case FloatBot:
5472   case DoubleTop:
5473   case DoubleCon:
5474   case DoubleBot:
5475   case NarrowOop:
5476   case NarrowKlass:
5477   case Bottom:                  // Ye Olde Default
5478     return Type::BOTTOM;
5479   case Top:
5480     return this;
5481 
5482   default:                      // All else is a mistake
5483     typerr(t);
5484 
5485   case AnyPtr: {
5486     // Found an AnyPtr type vs self-OopPtr type
5487     const TypePtr *tp = t->is_ptr();
5488     int offset = meet_offset(tp->offset());
5489     PTR ptr = meet_ptr(tp->ptr());
5490     switch (tp->ptr()) {
5491     case Null:
5492       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5493       // else fall through:
5494     case TopPTR:
5495     case AnyNull: {
5496       return make(ptr, _metadata, offset);
5497     }
5498     case BotPTR:
5499     case NotNull:
5500       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5501     default: typerr(t);
5502     }
5503   }
5504 
5505   case RawPtr:
5506   case KlassPtr:
5507   case InstKlassPtr:
5508   case AryKlassPtr:
5509   case OopPtr:
5510   case InstPtr:
5511   case AryPtr:
5512     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
5513 
5514   case MetadataPtr: {
5515     const TypeMetadataPtr *tp = t->is_metadataptr();
5516     int offset = meet_offset(tp->offset());
5517     PTR tptr = tp->ptr();
5518     PTR ptr = meet_ptr(tptr);
5519     ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
5520     if (tptr == TopPTR || _ptr == TopPTR ||
5521         metadata()->equals(tp->metadata())) {
5522       return make(ptr, md, offset);
5523     }
5524     // metadata is different
5525     if( ptr == Constant ) {  // Cannot be equal constants, so...
5526       if( tptr == Constant && _ptr != Constant)  return t;
5527       if( _ptr == Constant && tptr != Constant)  return this;
5528       ptr = NotNull;            // Fall down in lattice
5529     }
5530     return make(ptr, nullptr, offset);
5531     break;
5532   }
5533   } // End of switch
5534   return this;                  // Return the double constant
5535 }
5536 
5537 
5538 //------------------------------xdual------------------------------------------
5539 // Dual of a pure metadata pointer.
5540 const Type *TypeMetadataPtr::xdual() const {
5541   return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
5542 }
5543 
5544 //------------------------------dump2------------------------------------------
5545 #ifndef PRODUCT
5546 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5547   st->print("metadataptr:%s", ptr_msg[_ptr]);
5548   if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata()));
5549   switch( _offset ) {
5550   case OffsetTop: st->print("+top"); break;
5551   case OffsetBot: st->print("+any"); break;
5552   case         0: break;
5553   default:        st->print("+%d",_offset); break;
5554   }
5555 }
5556 #endif
5557 
5558 
5559 //=============================================================================
5560 // Convenience common pre-built type.
5561 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
5562 
5563 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset):
5564   TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
5565 }
5566 
5567 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
5568   return make(Constant, m, 0);
5569 }
5570 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
5571   return make(Constant, m, 0);
5572 }
5573 
5574 //------------------------------make-------------------------------------------
5575 // Create a meta data constant
5576 const TypeMetadataPtr *TypeMetadataPtr::make(PTR ptr, ciMetadata* m, int offset) {
5577   assert(m == nullptr || !m->is_klass(), "wrong type");
5578   return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
5579 }
5580 
5581 
5582 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
5583   const Type* elem = _ary->_elem;
5584   bool xk = klass_is_exact();
5585   if (elem->make_oopptr() != nullptr) {
5586     elem = elem->make_oopptr()->as_klass_type(try_for_exact);
5587     if (elem->is_klassptr()->klass_is_exact()) {
5588       xk = true;
5589     }
5590   }
5591   return TypeAryKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, elem, klass(), 0);
5592 }
5593 
5594 const TypeKlassPtr* TypeKlassPtr::make(ciKlass *klass, InterfaceHandling interface_handling) {
5595   if (klass->is_instance_klass()) {
5596     return TypeInstKlassPtr::make(klass, interface_handling);
5597   }
5598   return TypeAryKlassPtr::make(klass, interface_handling);
5599 }
5600 
5601 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* klass, int offset, InterfaceHandling interface_handling) {
5602   if (klass->is_instance_klass()) {
5603     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
5604     return TypeInstKlassPtr::make(ptr, klass, interfaces, offset);
5605   }
5606   return TypeAryKlassPtr::make(ptr, klass, offset, interface_handling);
5607 }
5608 
5609 
5610 //------------------------------TypeKlassPtr-----------------------------------
5611 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, int offset)
5612   : TypePtr(t, ptr, offset), _klass(klass), _interfaces(interfaces) {
5613   assert(klass == nullptr || !klass->is_loaded() || (klass->is_instance_klass() && !klass->is_interface()) ||
5614          klass->is_type_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "no interface here");
5615 }
5616 
5617 // Is there a single ciKlass* that can represent that type?
5618 ciKlass* TypeKlassPtr::exact_klass_helper() const {
5619   assert(_klass->is_instance_klass() && !_klass->is_interface(), "No interface");
5620   if (_interfaces->empty()) {
5621     return _klass;
5622   }
5623   if (_klass != ciEnv::current()->Object_klass()) {
5624     if (_interfaces->eq(_klass->as_instance_klass())) {
5625       return _klass;
5626     }
5627     return nullptr;
5628   }
5629   return _interfaces->exact_klass();
5630 }
5631 
5632 //------------------------------eq---------------------------------------------
5633 // Structural equality check for Type representations
5634 bool TypeKlassPtr::eq(const Type *t) const {
5635   const TypeKlassPtr *p = t->is_klassptr();
5636   return
5637     _interfaces->eq(p->_interfaces) &&
5638     TypePtr::eq(p);
5639 }
5640 
5641 //------------------------------hash-------------------------------------------
5642 // Type-specific hashing function.
5643 uint TypeKlassPtr::hash(void) const {
5644   return TypePtr::hash() + _interfaces->hash();
5645 }
5646 
5647 //------------------------------singleton--------------------------------------
5648 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5649 // constants
5650 bool TypeKlassPtr::singleton(void) const {
5651   // detune optimizer to not generate constant klass + constant offset as a constant!
5652   // TopPTR, Null, AnyNull, Constant are all singletons
5653   return (_offset == 0) && !below_centerline(_ptr);
5654 }
5655 
5656 // Do not allow interface-vs.-noninterface joins to collapse to top.
5657 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
5658   // logic here mirrors the one from TypeOopPtr::filter. See comments
5659   // there.
5660   const Type* ft = join_helper(kills, include_speculative);
5661   const TypeKlassPtr* ftkp = ft->isa_instklassptr();
5662   const TypeKlassPtr* ktkp = kills->isa_instklassptr();
5663 
5664   if (ft->empty()) {
5665     return Type::TOP;           // Canonical empty value
5666   }
5667 
5668   return ft;
5669 }
5670 
5671 const TypeInterfaces* TypeKlassPtr::meet_interfaces(const TypeKlassPtr* other) const {
5672   if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
5673     return _interfaces->union_with(other->_interfaces);
5674   } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
5675     return other->_interfaces;
5676   } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
5677     return _interfaces;
5678   }
5679   return _interfaces->intersection_with(other->_interfaces);
5680 }
5681 
5682 //------------------------------get_con----------------------------------------
5683 intptr_t TypeKlassPtr::get_con() const {
5684   assert( _ptr == Null || _ptr == Constant, "" );
5685   assert( _offset >= 0, "" );
5686 
5687   if (_offset != 0) {
5688     // After being ported to the compiler interface, the compiler no longer
5689     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5690     // to a handle at compile time.  This handle is embedded in the generated
5691     // code and dereferenced at the time the nmethod is made.  Until that time,
5692     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5693     // have access to the addresses!).  This does not seem to currently happen,
5694     // but this assertion here is to help prevent its occurrence.
5695     tty->print_cr("Found oop constant with non-zero offset");
5696     ShouldNotReachHere();
5697   }
5698 
5699   ciKlass* k = exact_klass();
5700 
5701   return (intptr_t)k->constant_encoding();
5702 }
5703 
5704 //------------------------------dump2------------------------------------------
5705 // Dump Klass Type
5706 #ifndef PRODUCT
5707 void TypeKlassPtr::dump2(Dict & d, uint depth, outputStream *st) const {
5708   switch(_ptr) {
5709   case Constant:
5710     st->print("precise ");
5711   case NotNull:
5712     {
5713       const char *name = klass()->name()->as_utf8();
5714       if (name) {
5715         st->print("%s: " INTPTR_FORMAT, name, p2i(klass()));
5716       } else {
5717         ShouldNotReachHere();
5718       }
5719       _interfaces->dump(st);
5720     }
5721   case BotPTR:
5722     if (!WizardMode && !Verbose && _ptr != Constant) break;
5723   case TopPTR:
5724   case AnyNull:
5725     st->print(":%s", ptr_msg[_ptr]);
5726     if (_ptr == Constant) st->print(":exact");
5727     break;
5728   default:
5729     break;
5730   }
5731 
5732   if (_offset) {               // Dump offset, if any
5733     if (_offset == OffsetBot)      { st->print("+any"); }
5734     else if (_offset == OffsetTop) { st->print("+unknown"); }
5735     else                            { st->print("+%d", _offset); }
5736   }
5737 
5738   st->print(" *");
5739 }
5740 #endif
5741 
5742 //=============================================================================
5743 // Convenience common pre-built types.
5744 
5745 // Not-null object klass or below
5746 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
5747 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
5748 
5749 bool TypeInstKlassPtr::eq(const Type *t) const {
5750   const TypeKlassPtr *p = t->is_klassptr();
5751   return
5752     klass()->equals(p->klass()) &&
5753     TypeKlassPtr::eq(p);
5754 }
5755 
5756 uint TypeInstKlassPtr::hash(void) const {
5757   return klass()->hash() + TypeKlassPtr::hash();
5758 }
5759 
5760 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, int offset) {
5761   TypeInstKlassPtr *r =
5762     (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, interfaces, offset))->hashcons();
5763 
5764   return r;
5765 }
5766 
5767 //------------------------------add_offset-------------------------------------
5768 // Access internals of klass object
5769 const TypePtr* TypeInstKlassPtr::add_offset( intptr_t offset ) const {
5770   return make( _ptr, klass(), _interfaces, xadd_offset(offset) );
5771 }
5772 
5773 const TypeInstKlassPtr* TypeInstKlassPtr::with_offset(intptr_t offset) const {
5774   return make(_ptr, klass(), _interfaces, offset);
5775 }
5776 
5777 //------------------------------cast_to_ptr_type-------------------------------
5778 const TypeInstKlassPtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
5779   assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
5780   if( ptr == _ptr ) return this;
5781   return make(ptr, _klass, _interfaces, _offset);
5782 }
5783 
5784 
5785 bool TypeInstKlassPtr::must_be_exact() const {
5786   if (!_klass->is_loaded())  return false;
5787   ciInstanceKlass* ik = _klass->as_instance_klass();
5788   if (ik->is_final())  return true;  // cannot clear xk
5789   return false;
5790 }
5791 
5792 //-----------------------------cast_to_exactness-------------------------------
5793 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
5794   if (klass_is_exact == (_ptr == Constant)) return this;
5795   if (must_be_exact()) return this;
5796   ciKlass* k = klass();
5797   return make(klass_is_exact ? Constant : NotNull, k, _interfaces, _offset);
5798 }
5799 
5800 
5801 //-----------------------------as_instance_type--------------------------------
5802 // Corresponding type for an instance of the given class.
5803 // It will be NotNull, and exact if and only if the klass type is exact.
5804 const TypeOopPtr* TypeInstKlassPtr::as_instance_type(bool klass_change) const {
5805   ciKlass* k = klass();
5806   bool xk = klass_is_exact();
5807   Compile* C = Compile::current();
5808   Dependencies* deps = C->dependencies();
5809   assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
5810   // Element is an instance
5811   bool klass_is_exact = false;
5812   const TypeInterfaces* interfaces = _interfaces;
5813   if (k->is_loaded()) {
5814     // Try to set klass_is_exact.
5815     ciInstanceKlass* ik = k->as_instance_klass();
5816     klass_is_exact = ik->is_final();
5817     if (!klass_is_exact && klass_change
5818         && deps != nullptr && UseUniqueSubclasses) {
5819       ciInstanceKlass* sub = ik->unique_concrete_subklass();
5820       if (sub != nullptr) {
5821         if (_interfaces->eq(sub)) {
5822           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
5823           k = ik = sub;
5824           xk = sub->is_final();
5825         }
5826       }
5827     }
5828   }
5829   return TypeInstPtr::make(TypePtr::BotPTR, k, interfaces, xk, nullptr, 0);
5830 }
5831 
5832 //------------------------------xmeet------------------------------------------
5833 // Compute the MEET of two types, return a new Type object.
5834 const Type    *TypeInstKlassPtr::xmeet( const Type *t ) const {
5835   // Perform a fast test for common case; meeting the same types together.
5836   if( this == t ) return this;  // Meeting same type-rep?
5837 
5838   // Current "this->_base" is Pointer
5839   switch (t->base()) {          // switch on original type
5840 
5841   case Int:                     // Mixing ints & oops happens when javac
5842   case Long:                    // reuses local variables
5843   case FloatTop:
5844   case FloatCon:
5845   case FloatBot:
5846   case DoubleTop:
5847   case DoubleCon:
5848   case DoubleBot:
5849   case NarrowOop:
5850   case NarrowKlass:
5851   case Bottom:                  // Ye Olde Default
5852     return Type::BOTTOM;
5853   case Top:
5854     return this;
5855 
5856   default:                      // All else is a mistake
5857     typerr(t);
5858 
5859   case AnyPtr: {                // Meeting to AnyPtrs
5860     // Found an AnyPtr type vs self-KlassPtr type
5861     const TypePtr *tp = t->is_ptr();
5862     int offset = meet_offset(tp->offset());
5863     PTR ptr = meet_ptr(tp->ptr());
5864     switch (tp->ptr()) {
5865     case TopPTR:
5866       return this;
5867     case Null:
5868       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5869     case AnyNull:
5870       return make( ptr, klass(), _interfaces, offset );
5871     case BotPTR:
5872     case NotNull:
5873       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5874     default: typerr(t);
5875     }
5876   }
5877 
5878   case RawPtr:
5879   case MetadataPtr:
5880   case OopPtr:
5881   case AryPtr:                  // Meet with AryPtr
5882   case InstPtr:                 // Meet with InstPtr
5883     return TypePtr::BOTTOM;
5884 
5885   //
5886   //             A-top         }
5887   //           /   |   \       }  Tops
5888   //       B-top A-any C-top   }
5889   //          | /  |  \ |      }  Any-nulls
5890   //       B-any   |   C-any   }
5891   //          |    |    |
5892   //       B-con A-con C-con   } constants; not comparable across classes
5893   //          |    |    |
5894   //       B-not   |   C-not   }
5895   //          | \  |  / |      }  not-nulls
5896   //       B-bot A-not C-bot   }
5897   //           \   |   /       }  Bottoms
5898   //             A-bot         }
5899   //
5900 
5901   case InstKlassPtr: {  // Meet two KlassPtr types
5902     const TypeInstKlassPtr *tkls = t->is_instklassptr();
5903     int  off     = meet_offset(tkls->offset());
5904     PTR  ptr     = meet_ptr(tkls->ptr());
5905     const TypeInterfaces* interfaces = meet_interfaces(tkls);
5906 
5907     ciKlass* res_klass = nullptr;
5908     bool res_xk = false;
5909     switch(meet_instptr(ptr, interfaces, this, tkls, res_klass, res_xk)) {
5910       case UNLOADED:
5911         ShouldNotReachHere();
5912       case SUBTYPE:
5913       case NOT_SUBTYPE:
5914       case LCA:
5915       case QUICK: {
5916         assert(res_xk == (ptr == Constant), "");
5917         const Type* res = make(ptr, res_klass, interfaces, off);
5918         return res;
5919       }
5920       default:
5921         ShouldNotReachHere();
5922     }
5923   } // End of case KlassPtr
5924   case AryKlassPtr: {                // All arrays inherit from Object class
5925     const TypeAryKlassPtr *tp = t->is_aryklassptr();
5926     int offset = meet_offset(tp->offset());
5927     PTR ptr = meet_ptr(tp->ptr());
5928     const TypeInterfaces* interfaces = meet_interfaces(tp);
5929     const TypeInterfaces* tp_interfaces = tp->_interfaces;
5930     const TypeInterfaces* this_interfaces = _interfaces;
5931 
5932     switch (ptr) {
5933     case TopPTR:
5934     case AnyNull:                // Fall 'down' to dual of object klass
5935       // For instances when a subclass meets a superclass we fall
5936       // below the centerline when the superclass is exact. We need to
5937       // do the same here.
5938       if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
5939         return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset);
5940       } else {
5941         // cannot subclass, so the meet has to fall badly below the centerline
5942         ptr = NotNull;
5943         interfaces = _interfaces->intersection_with(tp->_interfaces);
5944         return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
5945       }
5946     case Constant:
5947     case NotNull:
5948     case BotPTR:                // Fall down to object klass
5949       // LCA is object_klass, but if we subclass from the top we can do better
5950       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
5951         // If 'this' (InstPtr) is above the centerline and it is Object class
5952         // then we can subclass in the Java class hierarchy.
5953         // For instances when a subclass meets a superclass we fall
5954         // below the centerline when the superclass is exact. We need
5955         // to do the same here.
5956         if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
5957           // that is, tp's array type is a subtype of my klass
5958           return TypeAryKlassPtr::make(ptr,
5959                                        tp->elem(), tp->klass(), offset);
5960         }
5961       }
5962       // The other case cannot happen, since I cannot be a subtype of an array.
5963       // The meet falls down to Object class below centerline.
5964       if( ptr == Constant )
5965          ptr = NotNull;
5966       interfaces = this_interfaces->intersection_with(tp_interfaces);
5967       return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
5968     default: typerr(t);
5969     }
5970   }
5971 
5972   } // End of switch
5973   return this;                  // Return the double constant
5974 }
5975 
5976 //------------------------------xdual------------------------------------------
5977 // Dual: compute field-by-field dual
5978 const Type    *TypeInstKlassPtr::xdual() const {
5979   return new TypeInstKlassPtr(dual_ptr(), klass(), _interfaces, dual_offset());
5980 }
5981 
5982 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) {
5983   static_assert(std::is_base_of<T2, T1>::value, "");
5984   if (!this_one->is_loaded() || !other->is_loaded()) {
5985     return false;
5986   }
5987   if (!this_one->is_instance_type(other)) {
5988     return false;
5989   }
5990 
5991   if (!other_exact) {
5992     return false;
5993   }
5994 
5995   if (other->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces->empty()) {
5996     return true;
5997   }
5998 
5999   return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);
6000 }
6001 
6002 bool TypeInstKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6003   return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
6004 }
6005 
6006 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_instance(const T1* this_one, const T2* other) {
6007   static_assert(std::is_base_of<T2, T1>::value, "");
6008   if (!this_one->is_loaded() || !other->is_loaded()) {
6009     return false;
6010   }
6011   if (!this_one->is_instance_type(other)) {
6012     return false;
6013   }
6014   return this_one->klass()->equals(other->klass()) && this_one->_interfaces->eq(other->_interfaces);
6015 }
6016 
6017 bool TypeInstKlassPtr::is_same_java_type_as_helper(const TypeKlassPtr* other) const {
6018   return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
6019 }
6020 
6021 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) {
6022   static_assert(std::is_base_of<T2, T1>::value, "");
6023   if (!this_one->is_loaded() || !other->is_loaded()) {
6024     return true;
6025   }
6026 
6027   if (this_one->is_array_type(other)) {
6028     return !this_exact && this_one->klass()->equals(ciEnv::current()->Object_klass())  && other->_interfaces->contains(this_one->_interfaces);
6029   }
6030 
6031   assert(this_one->is_instance_type(other), "unsupported");
6032 
6033   if (this_exact && other_exact) {
6034     return this_one->is_java_subtype_of(other);
6035   }
6036 
6037   if (!this_one->klass()->is_subtype_of(other->klass()) && !other->klass()->is_subtype_of(this_one->klass())) {
6038     return false;
6039   }
6040 
6041   if (this_exact) {
6042     return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);
6043   }
6044 
6045   return true;
6046 }
6047 
6048 bool TypeInstKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6049   return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
6050 }
6051 
6052 const TypeKlassPtr* TypeInstKlassPtr::try_improve() const {
6053   if (!UseUniqueSubclasses) {
6054     return this;
6055   }
6056   ciKlass* k = klass();
6057   Compile* C = Compile::current();
6058   Dependencies* deps = C->dependencies();
6059   assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
6060   const TypeInterfaces* interfaces = _interfaces;
6061   if (k->is_loaded()) {
6062     ciInstanceKlass* ik = k->as_instance_klass();
6063     bool klass_is_exact = ik->is_final();
6064     if (!klass_is_exact &&
6065         deps != nullptr) {
6066       ciInstanceKlass* sub = ik->unique_concrete_subklass();
6067       if (sub != nullptr) {
6068         if (_interfaces->eq(sub)) {
6069           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6070           k = ik = sub;
6071           klass_is_exact = sub->is_final();
6072           return TypeKlassPtr::make(klass_is_exact ? Constant : _ptr, k, _offset);
6073         }
6074       }
6075     }
6076   }
6077   return this;
6078 }
6079 
6080 
6081 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, int offset) {
6082   return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset))->hashcons();
6083 }
6084 
6085 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, ciKlass* k, int offset, InterfaceHandling interface_handling) {
6086   if (k->is_obj_array_klass()) {
6087     // Element is an object array. Recursively call ourself.
6088     ciKlass* eklass = k->as_obj_array_klass()->element_klass();
6089     const TypeKlassPtr *etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6090     return TypeAryKlassPtr::make(ptr, etype, nullptr, offset);
6091   } else if (k->is_type_array_klass()) {
6092     // Element is an typeArray
6093     const Type* etype = get_const_basic_type(k->as_type_array_klass()->element_type());
6094     return TypeAryKlassPtr::make(ptr, etype, k, offset);
6095   } else {
6096     ShouldNotReachHere();
6097     return nullptr;
6098   }
6099 }
6100 
6101 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6102   return TypeAryKlassPtr::make(Constant, klass, 0, interface_handling);
6103 }
6104 
6105 //------------------------------eq---------------------------------------------
6106 // Structural equality check for Type representations
6107 bool TypeAryKlassPtr::eq(const Type *t) const {
6108   const TypeAryKlassPtr *p = t->is_aryklassptr();
6109   return
6110     _elem == p->_elem &&  // Check array
6111     TypeKlassPtr::eq(p);  // Check sub-parts
6112 }
6113 
6114 //------------------------------hash-------------------------------------------
6115 // Type-specific hashing function.
6116 uint TypeAryKlassPtr::hash(void) const {
6117   return (uint)(uintptr_t)_elem + TypeKlassPtr::hash();
6118 }
6119 
6120 //----------------------compute_klass------------------------------------------
6121 // Compute the defining klass for this class
6122 ciKlass* TypeAryPtr::compute_klass() const {
6123   // Compute _klass based on element type.
6124   ciKlass* k_ary = nullptr;
6125   const TypeInstPtr *tinst;
6126   const TypeAryPtr *tary;
6127   const Type* el = elem();
6128   if (el->isa_narrowoop()) {
6129     el = el->make_ptr();
6130   }
6131 
6132   // Get element klass
6133   if ((tinst = el->isa_instptr()) != nullptr) {
6134     // Leave k_ary at null.
6135   } else if ((tary = el->isa_aryptr()) != nullptr) {
6136     // Leave k_ary at null.
6137   } else if ((el->base() == Type::Top) ||
6138              (el->base() == Type::Bottom)) {
6139     // element type of Bottom occurs from meet of basic type
6140     // and object; Top occurs when doing join on Bottom.
6141     // Leave k_ary at null.
6142   } else {
6143     assert(!el->isa_int(), "integral arrays must be pre-equipped with a class");
6144     // Compute array klass directly from basic type
6145     k_ary = ciTypeArrayKlass::make(el->basic_type());
6146   }
6147   return k_ary;
6148 }
6149 
6150 //------------------------------klass------------------------------------------
6151 // Return the defining klass for this class
6152 ciKlass* TypeAryPtr::klass() const {
6153   if( _klass ) return _klass;   // Return cached value, if possible
6154 
6155   // Oops, need to compute _klass and cache it
6156   ciKlass* k_ary = compute_klass();
6157 
6158   if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) {
6159     // The _klass field acts as a cache of the underlying
6160     // ciKlass for this array type.  In order to set the field,
6161     // we need to cast away const-ness.
6162     //
6163     // IMPORTANT NOTE: we *never* set the _klass field for the
6164     // type TypeAryPtr::OOPS.  This Type is shared between all
6165     // active compilations.  However, the ciKlass which represents
6166     // this Type is *not* shared between compilations, so caching
6167     // this value would result in fetching a dangling pointer.
6168     //
6169     // Recomputing the underlying ciKlass for each request is
6170     // a bit less efficient than caching, but calls to
6171     // TypeAryPtr::OOPS->klass() are not common enough to matter.
6172     ((TypeAryPtr*)this)->_klass = k_ary;
6173   }
6174   return k_ary;
6175 }
6176 
6177 // Is there a single ciKlass* that can represent that type?
6178 ciKlass* TypeAryPtr::exact_klass_helper() const {
6179   if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) {
6180     ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper();
6181     if (k == nullptr) {
6182       return nullptr;
6183     }
6184     k = ciObjArrayKlass::make(k);
6185     return k;
6186   }
6187 
6188   return klass();
6189 }
6190 
6191 const Type* TypeAryPtr::base_element_type(int& dims) const {
6192   const Type* elem = this->elem();
6193   dims = 1;
6194   while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) {
6195     elem = elem->make_ptr()->is_aryptr()->elem();
6196     dims++;
6197   }
6198   return elem;
6199 }
6200 
6201 //------------------------------add_offset-------------------------------------
6202 // Access internals of klass object
6203 const TypePtr* TypeAryKlassPtr::add_offset(intptr_t offset) const {
6204   return make(_ptr, elem(), klass(), xadd_offset(offset));
6205 }
6206 
6207 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const {
6208   return make(_ptr, elem(), klass(), offset);
6209 }
6210 
6211 //------------------------------cast_to_ptr_type-------------------------------
6212 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6213   assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6214   if (ptr == _ptr) return this;
6215   return make(ptr, elem(), _klass, _offset);
6216 }
6217 
6218 bool TypeAryKlassPtr::must_be_exact() const {
6219   if (_elem == Type::BOTTOM) return false;
6220   if (_elem == Type::TOP   ) return false;
6221   const TypeKlassPtr*  tk = _elem->isa_klassptr();
6222   if (!tk)             return true;   // a primitive type, like int
6223   return tk->must_be_exact();
6224 }
6225 
6226 
6227 //-----------------------------cast_to_exactness-------------------------------
6228 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6229   if (must_be_exact()) return this;  // cannot clear xk
6230   ciKlass* k = _klass;
6231   const Type* elem = this->elem();
6232   if (elem->isa_klassptr() && !klass_is_exact) {
6233     elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
6234   }
6235   return make(klass_is_exact ? Constant : NotNull, elem, k, _offset);
6236 }
6237 
6238 
6239 //-----------------------------as_instance_type--------------------------------
6240 // Corresponding type for an instance of the given class.
6241 // It will be NotNull, and exact if and only if the klass type is exact.
6242 const TypeOopPtr* TypeAryKlassPtr::as_instance_type(bool klass_change) const {
6243   ciKlass* k = klass();
6244   bool    xk = klass_is_exact();
6245   const Type* el = nullptr;
6246   if (elem()->isa_klassptr()) {
6247     el = elem()->is_klassptr()->as_instance_type(false)->cast_to_exactness(false);
6248     k = nullptr;
6249   } else {
6250     el = elem();
6251   }
6252   return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS), k, xk, 0);
6253 }
6254 
6255 
6256 //------------------------------xmeet------------------------------------------
6257 // Compute the MEET of two types, return a new Type object.
6258 const Type    *TypeAryKlassPtr::xmeet( const Type *t ) const {
6259   // Perform a fast test for common case; meeting the same types together.
6260   if( this == t ) return this;  // Meeting same type-rep?
6261 
6262   // Current "this->_base" is Pointer
6263   switch (t->base()) {          // switch on original type
6264 
6265   case Int:                     // Mixing ints & oops happens when javac
6266   case Long:                    // reuses local variables
6267   case FloatTop:
6268   case FloatCon:
6269   case FloatBot:
6270   case DoubleTop:
6271   case DoubleCon:
6272   case DoubleBot:
6273   case NarrowOop:
6274   case NarrowKlass:
6275   case Bottom:                  // Ye Olde Default
6276     return Type::BOTTOM;
6277   case Top:
6278     return this;
6279 
6280   default:                      // All else is a mistake
6281     typerr(t);
6282 
6283   case AnyPtr: {                // Meeting to AnyPtrs
6284     // Found an AnyPtr type vs self-KlassPtr type
6285     const TypePtr *tp = t->is_ptr();
6286     int offset = meet_offset(tp->offset());
6287     PTR ptr = meet_ptr(tp->ptr());
6288     switch (tp->ptr()) {
6289     case TopPTR:
6290       return this;
6291     case Null:
6292       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6293     case AnyNull:
6294       return make( ptr, _elem, klass(), offset );
6295     case BotPTR:
6296     case NotNull:
6297       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6298     default: typerr(t);
6299     }
6300   }
6301 
6302   case RawPtr:
6303   case MetadataPtr:
6304   case OopPtr:
6305   case AryPtr:                  // Meet with AryPtr
6306   case InstPtr:                 // Meet with InstPtr
6307     return TypePtr::BOTTOM;
6308 
6309   //
6310   //             A-top         }
6311   //           /   |   \       }  Tops
6312   //       B-top A-any C-top   }
6313   //          | /  |  \ |      }  Any-nulls
6314   //       B-any   |   C-any   }
6315   //          |    |    |
6316   //       B-con A-con C-con   } constants; not comparable across classes
6317   //          |    |    |
6318   //       B-not   |   C-not   }
6319   //          | \  |  / |      }  not-nulls
6320   //       B-bot A-not C-bot   }
6321   //           \   |   /       }  Bottoms
6322   //             A-bot         }
6323   //
6324 
6325   case AryKlassPtr: {  // Meet two KlassPtr types
6326     const TypeAryKlassPtr *tap = t->is_aryklassptr();
6327     int off = meet_offset(tap->offset());
6328     const Type* elem = _elem->meet(tap->_elem);
6329 
6330     PTR ptr = meet_ptr(tap->ptr());
6331     ciKlass* res_klass = nullptr;
6332     bool res_xk = false;
6333     meet_aryptr(ptr, elem, this, tap, res_klass, res_xk);
6334     assert(res_xk == (ptr == Constant), "");
6335     return make(ptr, elem, res_klass, off);
6336   } // End of case KlassPtr
6337   case InstKlassPtr: {
6338     const TypeInstKlassPtr *tp = t->is_instklassptr();
6339     int offset = meet_offset(tp->offset());
6340     PTR ptr = meet_ptr(tp->ptr());
6341     const TypeInterfaces* interfaces = meet_interfaces(tp);
6342     const TypeInterfaces* tp_interfaces = tp->_interfaces;
6343     const TypeInterfaces* this_interfaces = _interfaces;
6344 
6345     switch (ptr) {
6346     case TopPTR:
6347     case AnyNull:                // Fall 'down' to dual of object klass
6348       // For instances when a subclass meets a superclass we fall
6349       // below the centerline when the superclass is exact. We need to
6350       // do the same here.
6351       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->intersection_with(tp_interfaces)->eq(tp_interfaces) && !tp->klass_is_exact()) {
6352         return TypeAryKlassPtr::make(ptr, _elem, _klass, offset);
6353       } else {
6354         // cannot subclass, so the meet has to fall badly below the centerline
6355         ptr = NotNull;
6356         interfaces = this_interfaces->intersection_with(tp->_interfaces);
6357         return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
6358       }
6359     case Constant:
6360     case NotNull:
6361     case BotPTR:                // Fall down to object klass
6362       // LCA is object_klass, but if we subclass from the top we can do better
6363       if (above_centerline(tp->ptr())) {
6364         // If 'tp'  is above the centerline and it is Object class
6365         // then we can subclass in the Java class hierarchy.
6366         // For instances when a subclass meets a superclass we fall
6367         // below the centerline when the superclass is exact. We need
6368         // to do the same here.
6369         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->intersection_with(tp_interfaces)->eq(tp_interfaces) && !tp->klass_is_exact()) {
6370           // that is, my array type is a subtype of 'tp' klass
6371           return make(ptr, _elem, _klass, offset);
6372         }
6373       }
6374       // The other case cannot happen, since t cannot be a subtype of an array.
6375       // The meet falls down to Object class below centerline.
6376       if (ptr == Constant)
6377          ptr = NotNull;
6378       interfaces = this_interfaces->intersection_with(tp_interfaces);
6379       return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
6380     default: typerr(t);
6381     }
6382   }
6383 
6384   } // End of switch
6385   return this;                  // Return the double constant
6386 }
6387 
6388 template <class T1, class T2> bool TypePtr::is_java_subtype_of_helper_for_array(const T1* this_one, const T2* other, bool this_exact, bool other_exact) {
6389   static_assert(std::is_base_of<T2, T1>::value, "");
6390 
6391   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
6392     return true;
6393   }
6394 
6395   int dummy;
6396   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6397 
6398   if (!this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
6399     return false;
6400   }
6401 
6402   if (this_one->is_instance_type(other)) {
6403     return other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->intersection_with(this_one->_interfaces)->eq(other->_interfaces) && other_exact;
6404   }
6405 
6406   assert(this_one->is_array_type(other), "");
6407   const T1* other_ary = this_one->is_array_type(other);
6408   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
6409   if (other_top_or_bottom) {
6410     return false;
6411   }
6412 
6413   const TypePtr* other_elem = other_ary->elem()->make_ptr();
6414   const TypePtr* this_elem = this_one->elem()->make_ptr();
6415   if (this_elem != nullptr && other_elem != nullptr) {
6416     return this_one->is_reference_type(this_elem)->is_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6417   }
6418   if (this_elem == nullptr && other_elem == nullptr) {
6419     return this_one->klass()->is_subtype_of(other->klass());
6420   }
6421   return false;
6422 }
6423 
6424 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6425   return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6426 }
6427 
6428 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other) {
6429   static_assert(std::is_base_of<T2, T1>::value, "");
6430 
6431   int dummy;
6432   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6433 
6434   if (!this_one->is_array_type(other) ||
6435       !this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
6436     return false;
6437   }
6438   const T1* other_ary = this_one->is_array_type(other);
6439   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
6440 
6441   if (other_top_or_bottom) {
6442     return false;
6443   }
6444 
6445   const TypePtr* other_elem = other_ary->elem()->make_ptr();
6446   const TypePtr* this_elem = this_one->elem()->make_ptr();
6447   if (other_elem != nullptr && this_elem != nullptr) {
6448     return this_one->is_reference_type(this_elem)->is_same_java_type_as(this_one->is_reference_type(other_elem));
6449   }
6450   if (other_elem == nullptr && this_elem == nullptr) {
6451     return this_one->klass()->equals(other->klass());
6452   }
6453   return false;
6454 }
6455 
6456 bool TypeAryKlassPtr::is_same_java_type_as_helper(const TypeKlassPtr* other) const {
6457   return TypePtr::is_same_java_type_as_helper_for_array(this, other);
6458 }
6459 
6460 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) {
6461   static_assert(std::is_base_of<T2, T1>::value, "");
6462   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
6463     return true;
6464   }
6465   if (!this_one->is_loaded() || !other->is_loaded()) {
6466     return true;
6467   }
6468   if (this_one->is_instance_type(other)) {
6469     return other->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces->intersection_with(this_one->_interfaces)->eq(other->_interfaces);
6470   }
6471 
6472   int dummy;
6473   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6474   if (this_top_or_bottom) {
6475     return true;
6476   }
6477 
6478   assert(this_one->is_array_type(other), "");
6479 
6480   const T1* other_ary = this_one->is_array_type(other);
6481   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
6482   if (other_top_or_bottom) {
6483     return true;
6484   }
6485   if (this_exact && other_exact) {
6486     return this_one->is_java_subtype_of(other);
6487   }
6488 
6489   const TypePtr* this_elem = this_one->elem()->make_ptr();
6490   const TypePtr* other_elem = other_ary->elem()->make_ptr();
6491   if (other_elem != nullptr && this_elem != nullptr) {
6492     return this_one->is_reference_type(this_elem)->maybe_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6493   }
6494   if (other_elem == nullptr && this_elem == nullptr) {
6495     return this_one->klass()->is_subtype_of(other->klass());
6496   }
6497   return false;
6498 }
6499 
6500 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6501   return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6502 }
6503 
6504 //------------------------------xdual------------------------------------------
6505 // Dual: compute field-by-field dual
6506 const Type    *TypeAryKlassPtr::xdual() const {
6507   return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset());
6508 }
6509 
6510 // Is there a single ciKlass* that can represent that type?
6511 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
6512   if (elem()->isa_klassptr()) {
6513     ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
6514     if (k == nullptr) {
6515       return nullptr;
6516     }
6517     k = ciObjArrayKlass::make(k);
6518     return k;
6519   }
6520 
6521   return klass();
6522 }
6523 
6524 ciKlass* TypeAryKlassPtr::klass() const {
6525   if (_klass != nullptr) {
6526     return _klass;
6527   }
6528   ciKlass* k = nullptr;
6529   if (elem()->isa_klassptr()) {
6530     // leave null
6531   } else if ((elem()->base() == Type::Top) ||
6532              (elem()->base() == Type::Bottom)) {
6533   } else {
6534     k = ciTypeArrayKlass::make(elem()->basic_type());
6535     ((TypeAryKlassPtr*)this)->_klass = k;
6536   }
6537   return k;
6538 }
6539 
6540 //------------------------------dump2------------------------------------------
6541 // Dump Klass Type
6542 #ifndef PRODUCT
6543 void TypeAryKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
6544   switch( _ptr ) {
6545   case Constant:
6546     st->print("precise ");
6547   case NotNull:
6548     {
6549       st->print("[");
6550       _elem->dump2(d, depth, st);
6551       _interfaces->dump(st);
6552       st->print(": ");
6553     }
6554   case BotPTR:
6555     if( !WizardMode && !Verbose && _ptr != Constant ) break;
6556   case TopPTR:
6557   case AnyNull:
6558     st->print(":%s", ptr_msg[_ptr]);
6559     if( _ptr == Constant ) st->print(":exact");
6560     break;
6561   default:
6562     break;
6563   }
6564 
6565   if( _offset ) {               // Dump offset, if any
6566     if( _offset == OffsetBot )      { st->print("+any"); }
6567     else if( _offset == OffsetTop ) { st->print("+unknown"); }
6568     else                            { st->print("+%d", _offset); }
6569   }
6570 
6571   st->print(" *");
6572 }
6573 #endif
6574 
6575 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
6576   const Type* elem = this->elem();
6577   dims = 1;
6578   while (elem->isa_aryklassptr()) {
6579     elem = elem->is_aryklassptr()->elem();
6580     dims++;
6581   }
6582   return elem;
6583 }
6584 
6585 //=============================================================================
6586 // Convenience common pre-built types.
6587 
6588 //------------------------------make-------------------------------------------
6589 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
6590   return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();
6591 }
6592 
6593 //------------------------------make-------------------------------------------
6594 const TypeFunc *TypeFunc::make(ciMethod* method) {
6595   Compile* C = Compile::current();
6596   const TypeFunc* tf = C->last_tf(method); // check cache
6597   if (tf != nullptr)  return tf;  // The hit rate here is almost 50%.
6598   const TypeTuple *domain;
6599   if (method->is_static()) {
6600     domain = TypeTuple::make_domain(nullptr, method->signature(), ignore_interfaces);
6601   } else {
6602     domain = TypeTuple::make_domain(method->holder(), method->signature(), ignore_interfaces);
6603   }
6604   const TypeTuple *range  = TypeTuple::make_range(method->signature(), ignore_interfaces);
6605   tf = TypeFunc::make(domain, range);
6606   C->set_last_tf(method, tf);  // fill cache
6607   return tf;
6608 }
6609 
6610 //------------------------------meet-------------------------------------------
6611 // Compute the MEET of two types.  It returns a new Type object.
6612 const Type *TypeFunc::xmeet( const Type *t ) const {
6613   // Perform a fast test for common case; meeting the same types together.
6614   if( this == t ) return this;  // Meeting same type-rep?
6615 
6616   // Current "this->_base" is Func
6617   switch (t->base()) {          // switch on original type
6618 
6619   case Bottom:                  // Ye Olde Default
6620     return t;
6621 
6622   default:                      // All else is a mistake
6623     typerr(t);
6624 
6625   case Top:
6626     break;
6627   }
6628   return this;                  // Return the double constant
6629 }
6630 
6631 //------------------------------xdual------------------------------------------
6632 // Dual: compute field-by-field dual
6633 const Type *TypeFunc::xdual() const {
6634   return this;
6635 }
6636 
6637 //------------------------------eq---------------------------------------------
6638 // Structural equality check for Type representations
6639 bool TypeFunc::eq( const Type *t ) const {
6640   const TypeFunc *a = (const TypeFunc*)t;
6641   return _domain == a->_domain &&
6642     _range == a->_range;
6643 }
6644 
6645 //------------------------------hash-------------------------------------------
6646 // Type-specific hashing function.
6647 uint TypeFunc::hash(void) const {
6648   return (uint)(uintptr_t)_domain + (uint)(uintptr_t)_range;
6649 }
6650 
6651 //------------------------------dump2------------------------------------------
6652 // Dump Function Type
6653 #ifndef PRODUCT
6654 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
6655   if( _range->cnt() <= Parms )
6656     st->print("void");
6657   else {
6658     uint i;
6659     for (i = Parms; i < _range->cnt()-1; i++) {
6660       _range->field_at(i)->dump2(d,depth,st);
6661       st->print("/");
6662     }
6663     _range->field_at(i)->dump2(d,depth,st);
6664   }
6665   st->print(" ");
6666   st->print("( ");
6667   if( !depth || d[this] ) {     // Check for recursive dump
6668     st->print("...)");
6669     return;
6670   }
6671   d.Insert((void*)this,(void*)this);    // Stop recursion
6672   if (Parms < _domain->cnt())
6673     _domain->field_at(Parms)->dump2(d,depth-1,st);
6674   for (uint i = Parms+1; i < _domain->cnt(); i++) {
6675     st->print(", ");
6676     _domain->field_at(i)->dump2(d,depth-1,st);
6677   }
6678   st->print(" )");
6679 }
6680 #endif
6681 
6682 //------------------------------singleton--------------------------------------
6683 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
6684 // constants (Ldi nodes).  Singletons are integer, float or double constants
6685 // or a single symbol.
6686 bool TypeFunc::singleton(void) const {
6687   return false;                 // Never a singleton
6688 }
6689 
6690 bool TypeFunc::empty(void) const {
6691   return false;                 // Never empty
6692 }
6693 
6694 
6695 BasicType TypeFunc::return_type() const{
6696   if (range()->cnt() == TypeFunc::Parms) {
6697     return T_VOID;
6698   }
6699   return range()->field_at(TypeFunc::Parms)->basic_type();
6700 }