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