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