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