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