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