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