1 /*
   2  * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "ci/ciField.hpp"
  26 #include "ci/ciFlatArrayKlass.hpp"
  27 #include "ci/ciInlineKlass.hpp"
  28 #include "ci/ciMethodData.hpp"
  29 #include "ci/ciObjArrayKlass.hpp"
  30 #include "ci/ciTypeFlow.hpp"
  31 #include "classfile/javaClasses.hpp"
  32 #include "classfile/symbolTable.hpp"
  33 #include "classfile/vmSymbols.hpp"
  34 #include "compiler/compileLog.hpp"
  35 #include "libadt/dict.hpp"
  36 #include "memory/oopFactory.hpp"
  37 #include "memory/resourceArea.hpp"
  38 #include "oops/instanceKlass.hpp"
  39 #include "oops/instanceMirrorKlass.hpp"
  40 #include "oops/objArrayKlass.hpp"
  41 #include "oops/typeArrayKlass.hpp"
  42 #include "opto/arraycopynode.hpp"
  43 #include "opto/callnode.hpp"
  44 #include "opto/matcher.hpp"
  45 #include "opto/node.hpp"
  46 #include "opto/opcodes.hpp"
  47 #include "opto/rangeinference.hpp"
  48 #include "opto/runtime.hpp"
  49 #include "opto/type.hpp"
  50 #include "runtime/globals.hpp"
  51 #include "runtime/stubRoutines.hpp"
  52 #include "utilities/checkedCast.hpp"
  53 #include "utilities/debug.hpp"
  54 #include "utilities/globalDefinitions.hpp"
  55 #include "utilities/ostream.hpp"
  56 #include "utilities/powerOfTwo.hpp"
  57 #include "utilities/stringUtils.hpp"
  58 
  59 // Portions of code courtesy of Clifford Click
  60 
  61 // Optimization - Graph Style
  62 
  63 // Dictionary of types shared among compilations.
  64 Dict* Type::_shared_type_dict = nullptr;
  65 const Type::Offset Type::Offset::top(Type::OffsetTop);
  66 const Type::Offset Type::Offset::bottom(Type::OffsetBot);
  67 
  68 const Type::Offset Type::Offset::meet(const Type::Offset other) const {
  69   // Either is 'TOP' offset?  Return the other offset!
  70   if (_offset == OffsetTop) return other;
  71   if (other._offset == OffsetTop) return *this;
  72   // If either is different, return 'BOTTOM' offset
  73   if (_offset != other._offset) return bottom;
  74   return Offset(_offset);
  75 }
  76 
  77 const Type::Offset Type::Offset::dual() const {
  78   if (_offset == OffsetTop) return bottom;// Map 'TOP' into 'BOTTOM'
  79   if (_offset == OffsetBot) return top;// Map 'BOTTOM' into 'TOP'
  80   return Offset(_offset);               // Map everything else into self
  81 }
  82 
  83 const Type::Offset Type::Offset::add(intptr_t offset) const {
  84   // Adding to 'TOP' offset?  Return 'TOP'!
  85   if (_offset == OffsetTop || offset == OffsetTop) return top;
  86   // Adding to 'BOTTOM' offset?  Return 'BOTTOM'!
  87   if (_offset == OffsetBot || offset == OffsetBot) return bottom;
  88   // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
  89   offset += (intptr_t)_offset;
  90   if (offset != (int)offset || offset == OffsetTop) return bottom;
  91 
  92   // assert( _offset >= 0 && _offset+offset >= 0, "" );
  93   // It is possible to construct a negative offset during PhaseCCP
  94 
  95   return Offset((int)offset);        // Sum valid offsets
  96 }
  97 
  98 void Type::Offset::dump2(outputStream *st) const {
  99   if (_offset == 0) {
 100     return;
 101   } else if (_offset == OffsetTop) {
 102     st->print("+top");
 103   }
 104   else if (_offset == OffsetBot) {
 105     st->print("+bot");
 106   } else if (_offset) {
 107     st->print("+%d", _offset);
 108   }
 109 }
 110 
 111 // Array which maps compiler types to Basic Types
 112 const Type::TypeInfo Type::_type_info[Type::lastype] = {
 113   { Bad,             T_ILLEGAL,    "bad",           false, Node::NotAMachineReg, relocInfo::none          },  // Bad
 114   { Control,         T_ILLEGAL,    "control",       false, 0,                    relocInfo::none          },  // Control
 115   { Bottom,          T_VOID,       "top",           false, 0,                    relocInfo::none          },  // Top
 116   { Bad,             T_INT,        "int:",          false, Op_RegI,              relocInfo::none          },  // Int
 117   { Bad,             T_LONG,       "long:",         false, Op_RegL,              relocInfo::none          },  // Long
 118   { Half,            T_VOID,       "half",          false, 0,                    relocInfo::none          },  // Half
 119   { Bad,             T_NARROWOOP,  "narrowoop:",    false, Op_RegN,              relocInfo::none          },  // NarrowOop
 120   { Bad,             T_NARROWKLASS,"narrowklass:",  false, Op_RegN,              relocInfo::none          },  // NarrowKlass
 121   { Bad,             T_ILLEGAL,    "tuple:",        false, Node::NotAMachineReg, relocInfo::none          },  // Tuple
 122   { Bad,             T_ARRAY,      "array:",        false, Node::NotAMachineReg, relocInfo::none          },  // Array
 123   { Bad,             T_ARRAY,      "interfaces:",   false, Node::NotAMachineReg, relocInfo::none          },  // Interfaces
 124 
 125 #if defined(PPC64)
 126   { Bad,             T_ILLEGAL,    "vectormask:",   false, Op_RegVectMask,       relocInfo::none          },  // VectorMask.
 127   { Bad,             T_ILLEGAL,    "vectora:",      false, Op_VecA,              relocInfo::none          },  // VectorA.
 128   { Bad,             T_ILLEGAL,    "vectors:",      false, 0,                    relocInfo::none          },  // VectorS
 129   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_RegL,              relocInfo::none          },  // VectorD
 130   { Bad,             T_ILLEGAL,    "vectorx:",      false, Op_VecX,              relocInfo::none          },  // VectorX
 131   { Bad,             T_ILLEGAL,    "vectory:",      false, 0,                    relocInfo::none          },  // VectorY
 132   { Bad,             T_ILLEGAL,    "vectorz:",      false, 0,                    relocInfo::none          },  // VectorZ
 133 #elif defined(S390)
 134   { Bad,             T_ILLEGAL,    "vectormask:",   false, Op_RegVectMask,       relocInfo::none          },  // VectorMask.
 135   { Bad,             T_ILLEGAL,    "vectora:",      false, Op_VecA,              relocInfo::none          },  // VectorA.
 136   { Bad,             T_ILLEGAL,    "vectors:",      false, 0,                    relocInfo::none          },  // VectorS
 137   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_RegL,              relocInfo::none          },  // VectorD
 138   { Bad,             T_ILLEGAL,    "vectorx:",      false, Op_VecX,              relocInfo::none          },  // VectorX
 139   { Bad,             T_ILLEGAL,    "vectory:",      false, 0,                    relocInfo::none          },  // VectorY
 140   { Bad,             T_ILLEGAL,    "vectorz:",      false, 0,                    relocInfo::none          },  // VectorZ
 141 #else // all other
 142   { Bad,             T_ILLEGAL,    "vectormask:",   false, Op_RegVectMask,       relocInfo::none          },  // VectorMask.
 143   { Bad,             T_ILLEGAL,    "vectora:",      false, Op_VecA,              relocInfo::none          },  // VectorA.
 144   { Bad,             T_ILLEGAL,    "vectors:",      false, Op_VecS,              relocInfo::none          },  // VectorS
 145   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_VecD,              relocInfo::none          },  // VectorD
 146   { Bad,             T_ILLEGAL,    "vectorx:",      false, Op_VecX,              relocInfo::none          },  // VectorX
 147   { Bad,             T_ILLEGAL,    "vectory:",      false, Op_VecY,              relocInfo::none          },  // VectorY
 148   { Bad,             T_ILLEGAL,    "vectorz:",      false, Op_VecZ,              relocInfo::none          },  // VectorZ
 149 #endif
 150   { Bad,             T_ADDRESS,    "anyptr:",       false, Op_RegP,              relocInfo::none          },  // AnyPtr
 151   { Bad,             T_ADDRESS,    "rawptr:",       false, Op_RegP,              relocInfo::none          },  // RawPtr
 152   { Bad,             T_OBJECT,     "oop:",          true,  Op_RegP,              relocInfo::oop_type      },  // OopPtr
 153   { Bad,             T_OBJECT,     "inst:",         true,  Op_RegP,              relocInfo::oop_type      },  // InstPtr
 154   { Bad,             T_OBJECT,     "ary:",          true,  Op_RegP,              relocInfo::oop_type      },  // AryPtr
 155   { Bad,             T_METADATA,   "metadata:",     false, Op_RegP,              relocInfo::metadata_type },  // MetadataPtr
 156   { Bad,             T_METADATA,   "klass:",        false, Op_RegP,              relocInfo::metadata_type },  // KlassPtr
 157   { Bad,             T_METADATA,   "instklass:",    false, Op_RegP,              relocInfo::metadata_type },  // InstKlassPtr
 158   { Bad,             T_METADATA,   "aryklass:",     false, Op_RegP,              relocInfo::metadata_type },  // AryKlassPtr
 159   { Bad,             T_OBJECT,     "func",          false, 0,                    relocInfo::none          },  // Function
 160   { Abio,            T_ILLEGAL,    "abIO",          false, 0,                    relocInfo::none          },  // Abio
 161   { Return_Address,  T_ADDRESS,    "return_address",false, Op_RegP,              relocInfo::none          },  // Return_Address
 162   { Memory,          T_ILLEGAL,    "memory",        false, 0,                    relocInfo::none          },  // Memory
 163   { HalfFloatBot,    T_SHORT,      "halffloat_top", false, Op_RegF,              relocInfo::none          },  // HalfFloatTop
 164   { HalfFloatCon,    T_SHORT,      "hfcon:",        false, Op_RegF,              relocInfo::none          },  // HalfFloatCon
 165   { HalfFloatTop,    T_SHORT,      "short",         false, Op_RegF,              relocInfo::none          },  // HalfFloatBot
 166   { FloatBot,        T_FLOAT,      "float_top",     false, Op_RegF,              relocInfo::none          },  // FloatTop
 167   { FloatCon,        T_FLOAT,      "ftcon:",        false, Op_RegF,              relocInfo::none          },  // FloatCon
 168   { FloatTop,        T_FLOAT,      "float",         false, Op_RegF,              relocInfo::none          },  // FloatBot
 169   { DoubleBot,       T_DOUBLE,     "double_top",    false, Op_RegD,              relocInfo::none          },  // DoubleTop
 170   { DoubleCon,       T_DOUBLE,     "dblcon:",       false, Op_RegD,              relocInfo::none          },  // DoubleCon
 171   { DoubleTop,       T_DOUBLE,     "double",        false, Op_RegD,              relocInfo::none          },  // DoubleBot
 172   { Top,             T_ILLEGAL,    "bottom",        false, 0,                    relocInfo::none          }   // Bottom
 173 };
 174 
 175 // Map ideal registers (machine types) to ideal types
 176 const Type *Type::mreg2type[_last_machine_leaf];
 177 
 178 // Map basic types to canonical Type* pointers.
 179 const Type* Type::     _const_basic_type[T_CONFLICT+1];
 180 
 181 // Map basic types to constant-zero Types.
 182 const Type* Type::            _zero_type[T_CONFLICT+1];
 183 
 184 // Map basic types to array-body alias types.
 185 const TypeAryPtr* TypeAryPtr::_array_body_type[T_CONFLICT+1];
 186 const TypeInterfaces* TypeAryPtr::_array_interfaces = nullptr;
 187 const TypeInterfaces* TypeAryKlassPtr::_array_interfaces = nullptr;
 188 
 189 //=============================================================================
 190 // Convenience common pre-built types.
 191 const Type *Type::ABIO;         // State-of-machine only
 192 const Type *Type::BOTTOM;       // All values
 193 const Type *Type::CONTROL;      // Control only
 194 const Type *Type::DOUBLE;       // All doubles
 195 const Type *Type::HALF_FLOAT;   // All half floats
 196 const Type *Type::FLOAT;        // All floats
 197 const Type *Type::HALF;         // Placeholder half of doublewide type
 198 const Type *Type::MEMORY;       // Abstract store only
 199 const Type *Type::RETURN_ADDRESS;
 200 const Type *Type::TOP;          // No values in set
 201 
 202 //------------------------------get_const_type---------------------------
 203 const Type* Type::get_const_type(ciType* type, InterfaceHandling interface_handling) {
 204   if (type == nullptr) {
 205     return nullptr;
 206   } else if (type->is_primitive_type()) {
 207     return get_const_basic_type(type->basic_type());
 208   } else {
 209     return TypeOopPtr::make_from_klass(type->as_klass(), interface_handling);
 210   }
 211 }
 212 
 213 //---------------------------array_element_basic_type---------------------------------
 214 // Mapping to the array element's basic type.
 215 BasicType Type::array_element_basic_type() const {
 216   BasicType bt = basic_type();
 217   if (bt == T_INT) {
 218     if (this == TypeInt::INT)   return T_INT;
 219     if (this == TypeInt::CHAR)  return T_CHAR;
 220     if (this == TypeInt::BYTE)  return T_BYTE;
 221     if (this == TypeInt::BOOL)  return T_BOOLEAN;
 222     if (this == TypeInt::SHORT) return T_SHORT;
 223     return T_VOID;
 224   }
 225   return bt;
 226 }
 227 
 228 // For two instance arrays of same dimension, return the base element types.
 229 // Otherwise or if the arrays have different dimensions, return null.
 230 void Type::get_arrays_base_elements(const Type *a1, const Type *a2,
 231                                     const TypeInstPtr **e1, const TypeInstPtr **e2) {
 232 
 233   if (e1) *e1 = nullptr;
 234   if (e2) *e2 = nullptr;
 235   const TypeAryPtr* a1tap = (a1 == nullptr) ? nullptr : a1->isa_aryptr();
 236   const TypeAryPtr* a2tap = (a2 == nullptr) ? nullptr : a2->isa_aryptr();
 237 
 238   if (a1tap != nullptr && a2tap != nullptr) {
 239     // Handle multidimensional arrays
 240     const TypePtr* a1tp = a1tap->elem()->make_ptr();
 241     const TypePtr* a2tp = a2tap->elem()->make_ptr();
 242     while (a1tp && a1tp->isa_aryptr() && a2tp && a2tp->isa_aryptr()) {
 243       a1tap = a1tp->is_aryptr();
 244       a2tap = a2tp->is_aryptr();
 245       a1tp = a1tap->elem()->make_ptr();
 246       a2tp = a2tap->elem()->make_ptr();
 247     }
 248     if (a1tp && a1tp->isa_instptr() && a2tp && a2tp->isa_instptr()) {
 249       if (e1) *e1 = a1tp->is_instptr();
 250       if (e2) *e2 = a2tp->is_instptr();
 251     }
 252   }
 253 }
 254 
 255 //---------------------------get_typeflow_type---------------------------------
 256 // Import a type produced by ciTypeFlow.
 257 const Type* Type::get_typeflow_type(ciType* type) {
 258   switch (type->basic_type()) {
 259 
 260   case ciTypeFlow::StateVector::T_BOTTOM:
 261     assert(type == ciTypeFlow::StateVector::bottom_type(), "");
 262     return Type::BOTTOM;
 263 
 264   case ciTypeFlow::StateVector::T_TOP:
 265     assert(type == ciTypeFlow::StateVector::top_type(), "");
 266     return Type::TOP;
 267 
 268   case ciTypeFlow::StateVector::T_NULL:
 269     assert(type == ciTypeFlow::StateVector::null_type(), "");
 270     return TypePtr::NULL_PTR;
 271 
 272   case ciTypeFlow::StateVector::T_LONG2:
 273     // The ciTypeFlow pass pushes a long, then the half.
 274     // We do the same.
 275     assert(type == ciTypeFlow::StateVector::long2_type(), "");
 276     return TypeInt::TOP;
 277 
 278   case ciTypeFlow::StateVector::T_DOUBLE2:
 279     // The ciTypeFlow pass pushes double, then the half.
 280     // Our convention is the same.
 281     assert(type == ciTypeFlow::StateVector::double2_type(), "");
 282     return Type::TOP;
 283 
 284   case T_ADDRESS:
 285     assert(type->is_return_address(), "");
 286     return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci());
 287 
 288   case T_OBJECT:
 289     return Type::get_const_type(type->unwrap())->join_speculative(type->is_null_free() ? TypePtr::NOTNULL : TypePtr::BOTTOM);
 290 
 291   default:
 292     // make sure we did not mix up the cases:
 293     assert(type != ciTypeFlow::StateVector::bottom_type(), "");
 294     assert(type != ciTypeFlow::StateVector::top_type(), "");
 295     assert(type != ciTypeFlow::StateVector::null_type(), "");
 296     assert(type != ciTypeFlow::StateVector::long2_type(), "");
 297     assert(type != ciTypeFlow::StateVector::double2_type(), "");
 298     assert(!type->is_return_address(), "");
 299 
 300     return Type::get_const_type(type);
 301   }
 302 }
 303 
 304 
 305 //-----------------------make_from_constant------------------------------------
 306 const Type* Type::make_from_constant(ciConstant constant, bool require_constant,
 307                                      int stable_dimension, bool is_narrow_oop,
 308                                      bool is_autobox_cache) {
 309   switch (constant.basic_type()) {
 310     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
 311     case T_CHAR:     return TypeInt::make(constant.as_char());
 312     case T_BYTE:     return TypeInt::make(constant.as_byte());
 313     case T_SHORT:    return TypeInt::make(constant.as_short());
 314     case T_INT:      return TypeInt::make(constant.as_int());
 315     case T_LONG:     return TypeLong::make(constant.as_long());
 316     case T_FLOAT:    return TypeF::make(constant.as_float());
 317     case T_DOUBLE:   return TypeD::make(constant.as_double());
 318     case T_ARRAY:
 319     case T_OBJECT: {
 320         const Type* con_type = nullptr;
 321         ciObject* oop_constant = constant.as_object();
 322         if (oop_constant->is_null_object()) {
 323           con_type = Type::get_zero_type(T_OBJECT);
 324         } else {
 325           guarantee(require_constant || oop_constant->should_be_constant(), "con_type must get computed");
 326           con_type = TypeOopPtr::make_from_constant(oop_constant, require_constant);
 327           if (Compile::current()->eliminate_boxing() && is_autobox_cache) {
 328             con_type = con_type->is_aryptr()->cast_to_autobox_cache();
 329           }
 330           if (stable_dimension > 0) {
 331             assert(FoldStableValues, "sanity");
 332             assert(!con_type->is_zero_type(), "default value for stable field");
 333             con_type = con_type->is_aryptr()->cast_to_stable(true, stable_dimension);
 334           }
 335         }
 336         if (is_narrow_oop) {
 337           con_type = con_type->make_narrowoop();
 338         }
 339         return con_type;
 340       }
 341     case T_ILLEGAL:
 342       // Invalid ciConstant returned due to OutOfMemoryError in the CI
 343       assert(Compile::current()->env()->failing(), "otherwise should not see this");
 344       return nullptr;
 345     default:
 346       // Fall through to failure
 347       return nullptr;
 348   }
 349 }
 350 
 351 static ciConstant check_mismatched_access(ciConstant con, BasicType loadbt, bool is_unsigned) {
 352   BasicType conbt = con.basic_type();
 353   switch (conbt) {
 354     case T_BOOLEAN: conbt = T_BYTE;   break;
 355     case T_ARRAY:   conbt = T_OBJECT; break;
 356     default:                          break;
 357   }
 358   switch (loadbt) {
 359     case T_BOOLEAN:   loadbt = T_BYTE;   break;
 360     case T_NARROWOOP: loadbt = T_OBJECT; break;
 361     case T_ARRAY:     loadbt = T_OBJECT; break;
 362     case T_ADDRESS:   loadbt = T_OBJECT; break;
 363     default:                             break;
 364   }
 365   if (conbt == loadbt) {
 366     if (is_unsigned && conbt == T_BYTE) {
 367       // LoadB (T_BYTE) with a small mask (<=8-bit) is converted to LoadUB (T_BYTE).
 368       return ciConstant(T_INT, con.as_int() & 0xFF);
 369     } else {
 370       return con;
 371     }
 372   }
 373   if (conbt == T_SHORT && loadbt == T_CHAR) {
 374     // LoadS (T_SHORT) with a small mask (<=16-bit) is converted to LoadUS (T_CHAR).
 375     return ciConstant(T_INT, con.as_int() & 0xFFFF);
 376   }
 377   return ciConstant(); // T_ILLEGAL
 378 }
 379 
 380 // Try to constant-fold a stable array element.
 381 const Type* Type::make_constant_from_array_element(ciArray* array, int off, int stable_dimension,
 382                                                    BasicType loadbt, bool is_unsigned_load) {
 383   // Decode the results of GraphKit::array_element_address.
 384   ciConstant element_value = array->element_value_by_offset(off);
 385   if (element_value.basic_type() == T_ILLEGAL) {
 386     return nullptr; // wrong offset
 387   }
 388   ciConstant con = check_mismatched_access(element_value, loadbt, is_unsigned_load);
 389 
 390   assert(con.basic_type() != T_ILLEGAL, "elembt=%s; loadbt=%s; unsigned=%d",
 391          type2name(element_value.basic_type()), type2name(loadbt), is_unsigned_load);
 392 
 393   if (con.is_valid() &&          // not a mismatched access
 394       !con.is_null_or_zero()) {  // not a default value
 395     bool is_narrow_oop = (loadbt == T_NARROWOOP);
 396     return Type::make_from_constant(con, /*require_constant=*/true, stable_dimension, is_narrow_oop, /*is_autobox_cache=*/false);
 397   }
 398   return nullptr;
 399 }
 400 
 401 const Type* Type::make_constant_from_field(ciInstance* holder, int off, bool is_unsigned_load, BasicType loadbt) {
 402   ciField* field;
 403   ciType* type = holder->java_mirror_type();
 404   if (type != nullptr && type->is_instance_klass() && off >= InstanceMirrorKlass::offset_of_static_fields()) {
 405     // Static field
 406     field = type->as_instance_klass()->get_field_by_offset(off, /*is_static=*/true);
 407   } else {
 408     // Instance field
 409     field = holder->klass()->as_instance_klass()->get_field_by_offset(off, /*is_static=*/false);
 410   }
 411   if (field == nullptr) {
 412     return nullptr; // Wrong offset
 413   }
 414   return Type::make_constant_from_field(field, holder, loadbt, is_unsigned_load);
 415 }
 416 
 417 const Type* Type::make_constant_from_field(ciField* field, ciInstance* holder,
 418                                            BasicType loadbt, bool is_unsigned_load) {
 419   if (!field->is_constant()) {
 420     return nullptr; // Non-constant field
 421   }
 422   ciConstant field_value;
 423   if (field->is_static()) {
 424     // final static field
 425     field_value = field->constant_value();
 426   } else if (holder != nullptr) {
 427     // final or stable non-static field
 428     // Treat final non-static fields of trusted classes (classes in
 429     // java.lang.invoke and sun.invoke packages and subpackages) as
 430     // compile time constants.
 431     field_value = field->constant_value_of(holder);
 432   }
 433   if (!field_value.is_valid()) {
 434     return nullptr; // Not a constant
 435   }
 436 
 437   ciConstant con = check_mismatched_access(field_value, loadbt, is_unsigned_load);
 438 
 439   assert(con.is_valid(), "elembt=%s; loadbt=%s; unsigned=%d",
 440          type2name(field_value.basic_type()), type2name(loadbt), is_unsigned_load);
 441 
 442   bool is_stable_array = FoldStableValues && field->is_stable() && field->type()->is_array_klass();
 443   int stable_dimension = (is_stable_array ? field->type()->as_array_klass()->dimension() : 0);
 444   bool is_narrow_oop = (loadbt == T_NARROWOOP);
 445 
 446   const Type* con_type = make_from_constant(con, /*require_constant=*/ true,
 447                                             stable_dimension, is_narrow_oop,
 448                                             field->is_autobox_cache());
 449   if (con_type != nullptr && field->is_call_site_target()) {
 450     ciCallSite* call_site = holder->as_call_site();
 451     if (!call_site->is_fully_initialized_constant_call_site()) {
 452       ciMethodHandle* target = con.as_object()->as_method_handle();
 453       Compile::current()->dependencies()->assert_call_site_target_value(call_site, target);
 454     }
 455   }
 456   return con_type;
 457 }
 458 
 459 //------------------------------make-------------------------------------------
 460 // Create a simple Type, with default empty symbol sets.  Then hashcons it
 461 // and look for an existing copy in the type dictionary.
 462 const Type *Type::make( enum TYPES t ) {
 463   return (new Type(t))->hashcons();
 464 }
 465 
 466 //------------------------------cmp--------------------------------------------
 467 bool Type::equals(const Type* t1, const Type* t2) {
 468   if (t1->_base != t2->_base) {
 469     return false; // Missed badly
 470   }
 471 
 472   assert(t1 != t2 || t1->eq(t2), "eq must be reflexive");
 473   return t1->eq(t2);
 474 }
 475 
 476 const Type* Type::maybe_remove_speculative(bool include_speculative) const {
 477   if (!include_speculative) {
 478     return remove_speculative();
 479   }
 480   return this;
 481 }
 482 
 483 //------------------------------hash-------------------------------------------
 484 int Type::uhash( const Type *const t ) {
 485   return (int)t->hash();
 486 }
 487 
 488 #define POSITIVE_INFINITE_F 0x7f800000 // hex representation for IEEE 754 single precision positive infinite
 489 #define POSITIVE_INFINITE_D 0x7ff0000000000000 // hex representation for IEEE 754 double precision positive infinite
 490 
 491 //--------------------------Initialize_shared----------------------------------
 492 void Type::Initialize_shared(Compile* current) {
 493   // This method does not need to be locked because the first system
 494   // compilations (stub compilations) occur serially.  If they are
 495   // changed to proceed in parallel, then this section will need
 496   // locking.
 497 
 498   Arena* save = current->type_arena();
 499   Arena* shared_type_arena = new (mtCompiler)Arena(mtCompiler, Arena::Tag::tag_type);
 500 
 501   current->set_type_arena(shared_type_arena);
 502 
 503   // Map the boolean result of Type::equals into a comparator result that CmpKey expects.
 504   CmpKey type_cmp = [](const void* t1, const void* t2) -> int32_t {
 505     return Type::equals((Type*) t1, (Type*) t2) ? 0 : 1;
 506   };
 507 
 508   _shared_type_dict = new (shared_type_arena) Dict(type_cmp, (Hash) Type::uhash, shared_type_arena, 128);
 509   current->set_type_dict(_shared_type_dict);
 510 
 511   // Make shared pre-built types.
 512   CONTROL = make(Control);      // Control only
 513   TOP     = make(Top);          // No values in set
 514   MEMORY  = make(Memory);       // Abstract store only
 515   ABIO    = make(Abio);         // State-of-machine only
 516   RETURN_ADDRESS=make(Return_Address);
 517   FLOAT   = make(FloatBot);     // All floats
 518   HALF_FLOAT = make(HalfFloatBot); // All half floats
 519   DOUBLE  = make(DoubleBot);    // All doubles
 520   BOTTOM  = make(Bottom);       // Everything
 521   HALF    = make(Half);         // Placeholder half of doublewide type
 522 
 523   TypeF::MAX = TypeF::make(max_jfloat); // Float MAX
 524   TypeF::MIN = TypeF::make(min_jfloat); // Float MIN
 525   TypeF::ZERO = TypeF::make(0.0); // Float 0 (positive zero)
 526   TypeF::ONE  = TypeF::make(1.0); // Float 1
 527   TypeF::POS_INF = TypeF::make(jfloat_cast(POSITIVE_INFINITE_F));
 528   TypeF::NEG_INF = TypeF::make(-jfloat_cast(POSITIVE_INFINITE_F));
 529 
 530   TypeH::MAX = TypeH::make(max_jfloat16); // HalfFloat MAX
 531   TypeH::MIN = TypeH::make(min_jfloat16); // HalfFloat MIN
 532   TypeH::ZERO = TypeH::make((jshort)0); // HalfFloat 0 (positive zero)
 533   TypeH::ONE  = TypeH::make(one_jfloat16); // HalfFloat 1
 534   TypeH::POS_INF = TypeH::make(pos_inf_jfloat16);
 535   TypeH::NEG_INF = TypeH::make(neg_inf_jfloat16);
 536 
 537   TypeD::MAX = TypeD::make(max_jdouble); // Double MAX
 538   TypeD::MIN = TypeD::make(min_jdouble); // Double MIN
 539   TypeD::ZERO = TypeD::make(0.0); // Double 0 (positive zero)
 540   TypeD::ONE  = TypeD::make(1.0); // Double 1
 541   TypeD::POS_INF = TypeD::make(jdouble_cast(POSITIVE_INFINITE_D));
 542   TypeD::NEG_INF = TypeD::make(-jdouble_cast(POSITIVE_INFINITE_D));
 543 
 544   TypeInt::MAX = TypeInt::make(max_jint); // Int MAX
 545   TypeInt::MIN = TypeInt::make(min_jint); // Int MIN
 546   TypeInt::MINUS_1  = TypeInt::make(-1);  // -1
 547   TypeInt::ZERO     = TypeInt::make( 0);  //  0
 548   TypeInt::ONE      = TypeInt::make( 1);  //  1
 549   TypeInt::BOOL     = TypeInt::make( 0, 1, WidenMin);  // 0 or 1, FALSE or TRUE.
 550   TypeInt::CC       = TypeInt::make(-1, 1, WidenMin);  // -1, 0 or 1, condition codes
 551   TypeInt::CC_LT    = TypeInt::make(-1,-1, WidenMin);  // == TypeInt::MINUS_1
 552   TypeInt::CC_GT    = TypeInt::make( 1, 1, WidenMin);  // == TypeInt::ONE
 553   TypeInt::CC_EQ    = TypeInt::make( 0, 0, WidenMin);  // == TypeInt::ZERO
 554   TypeInt::CC_NE    = TypeInt::make_or_top(TypeIntPrototype<jint, juint>{{-1, 1}, {1, max_juint}, {0, 1}}, WidenMin)->is_int();
 555   TypeInt::CC_LE    = TypeInt::make(-1, 0, WidenMin);
 556   TypeInt::CC_GE    = TypeInt::make( 0, 1, WidenMin);  // == TypeInt::BOOL
 557   TypeInt::BYTE     = TypeInt::make(-128, 127,     WidenMin); // Bytes
 558   TypeInt::UBYTE    = TypeInt::make(0, 255,        WidenMin); // Unsigned Bytes
 559   TypeInt::CHAR     = TypeInt::make(0, 65535,      WidenMin); // Java chars
 560   TypeInt::SHORT    = TypeInt::make(-32768, 32767, WidenMin); // Java shorts
 561   TypeInt::NON_ZERO = TypeInt::make_or_top(TypeIntPrototype<jint, juint>{{min_jint, max_jint}, {1, max_juint}, {0, 0}}, WidenMin)->is_int();
 562   TypeInt::POS      = TypeInt::make(0, max_jint,   WidenMin); // Non-neg values
 563   TypeInt::POS1     = TypeInt::make(1, max_jint,   WidenMin); // Positive values
 564   TypeInt::INT      = TypeInt::make(min_jint, max_jint, WidenMax); // 32-bit integers
 565   TypeInt::SYMINT   = TypeInt::make(-max_jint, max_jint, WidenMin); // symmetric range
 566   TypeInt::TYPE_DOMAIN = TypeInt::INT;
 567   // CmpL is overloaded both as the bytecode computation returning
 568   // a trinary (-1, 0, +1) integer result AND as an efficient long
 569   // compare returning optimizer ideal-type flags.
 570   assert(TypeInt::CC_LT == TypeInt::MINUS_1, "types must match for CmpL to work" );
 571   assert(TypeInt::CC_GT == TypeInt::ONE,     "types must match for CmpL to work" );
 572   assert(TypeInt::CC_EQ == TypeInt::ZERO,    "types must match for CmpL to work" );
 573   assert(TypeInt::CC_GE == TypeInt::BOOL,    "types must match for CmpL to work" );
 574 
 575   TypeLong::MAX = TypeLong::make(max_jlong); // Long MAX
 576   TypeLong::MIN = TypeLong::make(min_jlong); // Long MIN
 577   TypeLong::MINUS_1  = TypeLong::make(-1);   // -1
 578   TypeLong::ZERO     = TypeLong::make( 0);   //  0
 579   TypeLong::ONE      = TypeLong::make( 1);   //  1
 580   TypeLong::NON_ZERO = TypeLong::make_or_top(TypeIntPrototype<jlong, julong>{{min_jlong, max_jlong}, {1, max_julong}, {0, 0}}, WidenMin)->is_long();
 581   TypeLong::POS      = TypeLong::make(0, max_jlong, WidenMin); // Non-neg values
 582   TypeLong::NEG      = TypeLong::make(min_jlong, -1, WidenMin);
 583   TypeLong::LONG     = TypeLong::make(min_jlong, max_jlong, WidenMax); // 64-bit integers
 584   TypeLong::INT      = TypeLong::make((jlong)min_jint, (jlong)max_jint,WidenMin);
 585   TypeLong::UINT     = TypeLong::make(0, (jlong)max_juint, WidenMin);
 586   TypeLong::TYPE_DOMAIN = TypeLong::LONG;
 587 
 588   const Type **fboth =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 589   fboth[0] = Type::CONTROL;
 590   fboth[1] = Type::CONTROL;
 591   TypeTuple::IFBOTH = TypeTuple::make( 2, fboth );
 592 
 593   const Type **ffalse =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 594   ffalse[0] = Type::CONTROL;
 595   ffalse[1] = Type::TOP;
 596   TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
 597 
 598   const Type **fneither =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 599   fneither[0] = Type::TOP;
 600   fneither[1] = Type::TOP;
 601   TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
 602 
 603   const Type **ftrue =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 604   ftrue[0] = Type::TOP;
 605   ftrue[1] = Type::CONTROL;
 606   TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
 607 
 608   const Type **floop =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 609   floop[0] = Type::CONTROL;
 610   floop[1] = TypeInt::INT;
 611   TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
 612 
 613   TypePtr::NULL_PTR= TypePtr::make(AnyPtr, TypePtr::Null, Offset(0));
 614   TypePtr::NOTNULL = TypePtr::make(AnyPtr, TypePtr::NotNull, Offset::bottom);
 615   TypePtr::BOTTOM  = TypePtr::make(AnyPtr, TypePtr::BotPTR, Offset::bottom);
 616 
 617   TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
 618   TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
 619 
 620   const Type **fmembar = TypeTuple::fields(0);
 621   TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
 622 
 623   const Type **fsc = (const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 624   fsc[0] = TypeInt::CC;
 625   fsc[1] = Type::MEMORY;
 626   TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
 627 
 628   TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
 629   TypeInstPtr::BOTTOM  = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass());
 630   TypeInstPtr::MIRROR  = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
 631   TypeInstPtr::MARK    = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
 632                                            false, nullptr, Offset(oopDesc::mark_offset_in_bytes()));
 633   TypeInstPtr::KLASS   = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
 634                                            false, nullptr, Offset(oopDesc::klass_offset_in_bytes()));
 635   TypeOopPtr::BOTTOM  = TypeOopPtr::make(TypePtr::BotPTR, Offset::bottom, TypeOopPtr::InstanceBot);
 636 
 637   TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, nullptr, Offset::bottom);
 638 
 639   TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
 640   TypeNarrowOop::BOTTOM   = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
 641 
 642   TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
 643 
 644   mreg2type[Op_Node] = Type::BOTTOM;
 645   mreg2type[Op_Set ] = nullptr;
 646   mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
 647   mreg2type[Op_RegI] = TypeInt::INT;
 648   mreg2type[Op_RegP] = TypePtr::BOTTOM;
 649   mreg2type[Op_RegF] = Type::FLOAT;
 650   mreg2type[Op_RegD] = Type::DOUBLE;
 651   mreg2type[Op_RegL] = TypeLong::LONG;
 652   mreg2type[Op_RegFlags] = TypeInt::CC;
 653 
 654   GrowableArray<ciInstanceKlass*> array_interfaces;
 655   array_interfaces.push(current->env()->Cloneable_klass());
 656   array_interfaces.push(current->env()->Serializable_klass());
 657   TypeAryPtr::_array_interfaces = TypeInterfaces::make(&array_interfaces);
 658   TypeAryKlassPtr::_array_interfaces = TypeAryPtr::_array_interfaces;
 659 
 660   TypeAryPtr::BOTTOM = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::BOTTOM, TypeInt::POS, false, false, false, false, false), nullptr, false, Offset::bottom);
 661   TypeAryPtr::RANGE   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS, false, false, false, false, false), nullptr /* current->env()->Object_klass() */, false, Offset(arrayOopDesc::length_offset_in_bytes()));
 662 
 663   TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS, false, false, false, false, false), nullptr /*ciArrayKlass::make(o)*/,  false,  Offset::bottom);
 664 
 665 #ifdef _LP64
 666   if (UseCompressedOops) {
 667     assert(TypeAryPtr::NARROWOOPS->is_ptr_to_narrowoop(), "array of narrow oops must be ptr to narrow oop");
 668     TypeAryPtr::OOPS  = TypeAryPtr::NARROWOOPS;
 669   } else
 670 #endif
 671   {
 672     // There is no shared klass for Object[].  See note in TypeAryPtr::klass().
 673     TypeAryPtr::OOPS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS, false, false, false, false, false), nullptr /*ciArrayKlass::make(o)*/,  false,  Offset::bottom);
 674   }
 675   TypeAryPtr::BYTES   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE      ,TypeInt::POS, false, false, true, true, true), ciTypeArrayKlass::make(T_BYTE),   true,  Offset::bottom);
 676   TypeAryPtr::SHORTS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT     ,TypeInt::POS, false, false, true, true, true), ciTypeArrayKlass::make(T_SHORT),  true,  Offset::bottom);
 677   TypeAryPtr::CHARS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR      ,TypeInt::POS, false, false, true, true, true), ciTypeArrayKlass::make(T_CHAR),   true,  Offset::bottom);
 678   TypeAryPtr::INTS    = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT       ,TypeInt::POS, false, false, true, true, true), ciTypeArrayKlass::make(T_INT),    true,  Offset::bottom);
 679   TypeAryPtr::LONGS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG     ,TypeInt::POS, false, false, true, true, true), ciTypeArrayKlass::make(T_LONG),   true,  Offset::bottom);
 680   TypeAryPtr::FLOATS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT        ,TypeInt::POS, false, false, true, true, true), ciTypeArrayKlass::make(T_FLOAT),  true,  Offset::bottom);
 681   TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE       ,TypeInt::POS, false, false, true, true, true), ciTypeArrayKlass::make(T_DOUBLE), true,  Offset::bottom);
 682   TypeAryPtr::INLINES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS, /* stable= */ false, /* flat= */ true, false, false, false), nullptr, false, Offset::bottom);
 683 
 684   // Nobody should ask _array_body_type[T_NARROWOOP]. Use null as assert.
 685   TypeAryPtr::_array_body_type[T_NARROWOOP] = nullptr;
 686   TypeAryPtr::_array_body_type[T_OBJECT]  = TypeAryPtr::OOPS;
 687   TypeAryPtr::_array_body_type[T_FLAT_ELEMENT] = TypeAryPtr::OOPS;
 688   TypeAryPtr::_array_body_type[T_ARRAY]   = TypeAryPtr::OOPS; // arrays are stored in oop arrays
 689   TypeAryPtr::_array_body_type[T_BYTE]    = TypeAryPtr::BYTES;
 690   TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES;  // boolean[] is a byte array
 691   TypeAryPtr::_array_body_type[T_SHORT]   = TypeAryPtr::SHORTS;
 692   TypeAryPtr::_array_body_type[T_CHAR]    = TypeAryPtr::CHARS;
 693   TypeAryPtr::_array_body_type[T_INT]     = TypeAryPtr::INTS;
 694   TypeAryPtr::_array_body_type[T_LONG]    = TypeAryPtr::LONGS;
 695   TypeAryPtr::_array_body_type[T_FLOAT]   = TypeAryPtr::FLOATS;
 696   TypeAryPtr::_array_body_type[T_DOUBLE]  = TypeAryPtr::DOUBLES;
 697 
 698   TypeInstKlassPtr::OBJECT = TypeInstKlassPtr::make(TypePtr::NotNull, current->env()->Object_klass(), Offset(0));
 699   TypeInstKlassPtr::OBJECT_OR_NULL = TypeInstKlassPtr::make(TypePtr::BotPTR, current->env()->Object_klass(), Offset(0));
 700 
 701   const Type **fi2c = TypeTuple::fields(2);
 702   fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // Method*
 703   fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
 704   TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
 705 
 706   const Type **intpair = TypeTuple::fields(2);
 707   intpair[0] = TypeInt::INT;
 708   intpair[1] = TypeInt::INT;
 709   TypeTuple::INT_PAIR = TypeTuple::make(2, intpair);
 710 
 711   const Type **longpair = TypeTuple::fields(2);
 712   longpair[0] = TypeLong::LONG;
 713   longpair[1] = TypeLong::LONG;
 714   TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
 715 
 716   const Type **intccpair = TypeTuple::fields(2);
 717   intccpair[0] = TypeInt::INT;
 718   intccpair[1] = TypeInt::CC;
 719   TypeTuple::INT_CC_PAIR = TypeTuple::make(2, intccpair);
 720 
 721   const Type **longccpair = TypeTuple::fields(2);
 722   longccpair[0] = TypeLong::LONG;
 723   longccpair[1] = TypeInt::CC;
 724   TypeTuple::LONG_CC_PAIR = TypeTuple::make(2, longccpair);
 725 
 726   _const_basic_type[T_NARROWOOP]   = TypeNarrowOop::BOTTOM;
 727   _const_basic_type[T_NARROWKLASS] = Type::BOTTOM;
 728   _const_basic_type[T_BOOLEAN]     = TypeInt::BOOL;
 729   _const_basic_type[T_CHAR]        = TypeInt::CHAR;
 730   _const_basic_type[T_BYTE]        = TypeInt::BYTE;
 731   _const_basic_type[T_SHORT]       = TypeInt::SHORT;
 732   _const_basic_type[T_INT]         = TypeInt::INT;
 733   _const_basic_type[T_LONG]        = TypeLong::LONG;
 734   _const_basic_type[T_FLOAT]       = Type::FLOAT;
 735   _const_basic_type[T_DOUBLE]      = Type::DOUBLE;
 736   _const_basic_type[T_OBJECT]      = TypeInstPtr::BOTTOM;
 737   _const_basic_type[T_ARRAY]       = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays
 738   _const_basic_type[T_FLAT_ELEMENT] = TypeInstPtr::BOTTOM;
 739   _const_basic_type[T_VOID]        = TypePtr::NULL_PTR;   // reflection represents void this way
 740   _const_basic_type[T_ADDRESS]     = TypeRawPtr::BOTTOM;  // both interpreter return addresses & random raw ptrs
 741   _const_basic_type[T_CONFLICT]    = Type::BOTTOM;        // why not?
 742 
 743   _zero_type[T_NARROWOOP]   = TypeNarrowOop::NULL_PTR;
 744   _zero_type[T_NARROWKLASS] = TypeNarrowKlass::NULL_PTR;
 745   _zero_type[T_BOOLEAN]     = TypeInt::ZERO;     // false == 0
 746   _zero_type[T_CHAR]        = TypeInt::ZERO;     // '\0' == 0
 747   _zero_type[T_BYTE]        = TypeInt::ZERO;     // 0x00 == 0
 748   _zero_type[T_SHORT]       = TypeInt::ZERO;     // 0x0000 == 0
 749   _zero_type[T_INT]         = TypeInt::ZERO;
 750   _zero_type[T_LONG]        = TypeLong::ZERO;
 751   _zero_type[T_FLOAT]       = TypeF::ZERO;
 752   _zero_type[T_DOUBLE]      = TypeD::ZERO;
 753   _zero_type[T_OBJECT]      = TypePtr::NULL_PTR;
 754   _zero_type[T_ARRAY]       = TypePtr::NULL_PTR; // null array is null oop
 755   _zero_type[T_FLAT_ELEMENT] = TypePtr::NULL_PTR;
 756   _zero_type[T_ADDRESS]     = TypePtr::NULL_PTR; // raw pointers use the same null
 757   _zero_type[T_VOID]        = Type::TOP;         // the only void value is no value at all
 758 
 759   // get_zero_type() should not happen for T_CONFLICT
 760   _zero_type[T_CONFLICT]= nullptr;
 761 
 762   TypeVect::VECTMASK = (TypeVect*)(new TypeVectMask(T_BOOLEAN, MaxVectorSize))->hashcons();
 763   mreg2type[Op_RegVectMask] = TypeVect::VECTMASK;
 764 
 765   if (Matcher::supports_scalable_vector()) {
 766     TypeVect::VECTA = TypeVect::make(T_BYTE, Matcher::scalable_vector_reg_size(T_BYTE));
 767   }
 768 
 769   // Vector predefined types, it needs initialized _const_basic_type[].
 770   if (Matcher::vector_size_supported(T_BYTE, 4)) {
 771     TypeVect::VECTS = TypeVect::make(T_BYTE, 4);
 772   }
 773   if (Matcher::vector_size_supported(T_FLOAT, 2)) {
 774     TypeVect::VECTD = TypeVect::make(T_FLOAT, 2);
 775   }
 776   if (Matcher::vector_size_supported(T_FLOAT, 4)) {
 777     TypeVect::VECTX = TypeVect::make(T_FLOAT, 4);
 778   }
 779   if (Matcher::vector_size_supported(T_FLOAT, 8)) {
 780     TypeVect::VECTY = TypeVect::make(T_FLOAT, 8);
 781   }
 782   if (Matcher::vector_size_supported(T_FLOAT, 16)) {
 783     TypeVect::VECTZ = TypeVect::make(T_FLOAT, 16);
 784   }
 785 
 786   mreg2type[Op_VecA] = TypeVect::VECTA;
 787   mreg2type[Op_VecS] = TypeVect::VECTS;
 788   mreg2type[Op_VecD] = TypeVect::VECTD;
 789   mreg2type[Op_VecX] = TypeVect::VECTX;
 790   mreg2type[Op_VecY] = TypeVect::VECTY;
 791   mreg2type[Op_VecZ] = TypeVect::VECTZ;
 792 
 793   LockNode::initialize_lock_Type();
 794   ArrayCopyNode::initialize_arraycopy_Type();
 795   OptoRuntime::initialize_types();
 796 
 797   // Restore working type arena.
 798   current->set_type_arena(save);
 799   current->set_type_dict(nullptr);
 800 }
 801 
 802 //------------------------------Initialize-------------------------------------
 803 void Type::Initialize(Compile* current) {
 804   assert(current->type_arena() != nullptr, "must have created type arena");
 805 
 806   if (_shared_type_dict == nullptr) {
 807     Initialize_shared(current);
 808   }
 809 
 810   Arena* type_arena = current->type_arena();
 811 
 812   // Create the hash-cons'ing dictionary with top-level storage allocation
 813   Dict *tdic = new (type_arena) Dict(*_shared_type_dict, type_arena);
 814   current->set_type_dict(tdic);
 815 }
 816 
 817 //------------------------------hashcons---------------------------------------
 818 // Do the hash-cons trick.  If the Type already exists in the type table,
 819 // delete the current Type and return the existing Type.  Otherwise stick the
 820 // current Type in the Type table.
 821 const Type *Type::hashcons(void) {
 822   DEBUG_ONLY(base());           // Check the assertion in Type::base().
 823   // Look up the Type in the Type dictionary
 824   Dict *tdic = type_dict();
 825   Type* old = (Type*)(tdic->Insert(this, this, false));
 826   if( old ) {                   // Pre-existing Type?
 827     if( old != this )           // Yes, this guy is not the pre-existing?
 828       delete this;              // Yes, Nuke this guy
 829     assert( old->_dual, "" );
 830     return old;                 // Return pre-existing
 831   }
 832 
 833   // Every type has a dual (to make my lattice symmetric).
 834   // Since we just discovered a new Type, compute its dual right now.
 835   assert( !_dual, "" );         // No dual yet
 836   _dual = xdual();              // Compute the dual
 837   if (equals(this, _dual)) {    // Handle self-symmetric
 838     if (_dual != this) {
 839       delete _dual;
 840       _dual = this;
 841     }
 842     return this;
 843   }
 844   assert( !_dual->_dual, "" );  // No reverse dual yet
 845   assert( !(*tdic)[_dual], "" ); // Dual not in type system either
 846   // New Type, insert into Type table
 847   tdic->Insert((void*)_dual,(void*)_dual);
 848   ((Type*)_dual)->_dual = this; // Finish up being symmetric
 849 #ifdef ASSERT
 850   Type *dual_dual = (Type*)_dual->xdual();
 851   assert( eq(dual_dual), "xdual(xdual()) should be identity" );
 852   delete dual_dual;
 853 #endif
 854   return this;                  // Return new Type
 855 }
 856 
 857 //------------------------------eq---------------------------------------------
 858 // Structural equality check for Type representations
 859 bool Type::eq( const Type * ) const {
 860   return true;                  // Nothing else can go wrong
 861 }
 862 
 863 //------------------------------hash-------------------------------------------
 864 // Type-specific hashing function.
 865 uint Type::hash(void) const {
 866   return _base;
 867 }
 868 
 869 //------------------------------is_finite--------------------------------------
 870 // Has a finite value
 871 bool Type::is_finite() const {
 872   return false;
 873 }
 874 
 875 //------------------------------is_nan-----------------------------------------
 876 // Is not a number (NaN)
 877 bool Type::is_nan()    const {
 878   return false;
 879 }
 880 
 881 #ifdef ASSERT
 882 class VerifyMeet;
 883 class VerifyMeetResult : public ArenaObj {
 884   friend class VerifyMeet;
 885   friend class Type;
 886 private:
 887   class VerifyMeetResultEntry {
 888   private:
 889     const Type* _in1;
 890     const Type* _in2;
 891     const Type* _res;
 892   public:
 893     VerifyMeetResultEntry(const Type* in1, const Type* in2, const Type* res):
 894             _in1(in1), _in2(in2), _res(res) {
 895     }
 896     VerifyMeetResultEntry():
 897             _in1(nullptr), _in2(nullptr), _res(nullptr) {
 898     }
 899 
 900     bool operator==(const VerifyMeetResultEntry& rhs) const {
 901       return _in1 == rhs._in1 &&
 902              _in2 == rhs._in2 &&
 903              _res == rhs._res;
 904     }
 905 
 906     bool operator!=(const VerifyMeetResultEntry& rhs) const {
 907       return !(rhs == *this);
 908     }
 909 
 910     static int compare(const VerifyMeetResultEntry& v1, const VerifyMeetResultEntry& v2) {
 911       if ((intptr_t) v1._in1 < (intptr_t) v2._in1) {
 912         return -1;
 913       } else if (v1._in1 == v2._in1) {
 914         if ((intptr_t) v1._in2 < (intptr_t) v2._in2) {
 915           return -1;
 916         } else if (v1._in2 == v2._in2) {
 917           assert(v1._res == v2._res || v1._res == nullptr || v2._res == nullptr, "same inputs should lead to same result");
 918           return 0;
 919         }
 920         return 1;
 921       }
 922       return 1;
 923     }
 924     const Type* res() const { return _res; }
 925   };
 926   uint _depth;
 927   GrowableArray<VerifyMeetResultEntry> _cache;
 928 
 929   // With verification code, the meet of A and B causes the computation of:
 930   // 1- meet(A, B)
 931   // 2- meet(B, A)
 932   // 3- meet(dual(meet(A, B)), dual(A))
 933   // 4- meet(dual(meet(A, B)), dual(B))
 934   // 5- meet(dual(A), dual(B))
 935   // 6- meet(dual(B), dual(A))
 936   // 7- meet(dual(meet(dual(A), dual(B))), A)
 937   // 8- meet(dual(meet(dual(A), dual(B))), B)
 938   //
 939   // In addition the meet of A[] and B[] requires the computation of the meet of A and B.
 940   //
 941   // The meet of A[] and B[] triggers the computation of:
 942   // 1- meet(A[], B[][)
 943   //   1.1- meet(A, B)
 944   //   1.2- meet(B, A)
 945   //   1.3- meet(dual(meet(A, B)), dual(A))
 946   //   1.4- meet(dual(meet(A, B)), dual(B))
 947   //   1.5- meet(dual(A), dual(B))
 948   //   1.6- meet(dual(B), dual(A))
 949   //   1.7- meet(dual(meet(dual(A), dual(B))), A)
 950   //   1.8- meet(dual(meet(dual(A), dual(B))), B)
 951   // 2- meet(B[], A[])
 952   //   2.1- meet(B, A) = 1.2
 953   //   2.2- meet(A, B) = 1.1
 954   //   2.3- meet(dual(meet(B, A)), dual(B)) = 1.4
 955   //   2.4- meet(dual(meet(B, A)), dual(A)) = 1.3
 956   //   2.5- meet(dual(B), dual(A)) = 1.6
 957   //   2.6- meet(dual(A), dual(B)) = 1.5
 958   //   2.7- meet(dual(meet(dual(B), dual(A))), B) = 1.8
 959   //   2.8- meet(dual(meet(dual(B), dual(A))), B) = 1.7
 960   // etc.
 961   // The number of meet operations performed grows exponentially with the number of dimensions of the arrays but the number
 962   // of different meet operations is linear in the number of dimensions. The function below caches meet results for the
 963   // duration of the meet at the root of the recursive calls.
 964   //
 965   const Type* meet(const Type* t1, const Type* t2) {
 966     bool found = false;
 967     const VerifyMeetResultEntry meet(t1, t2, nullptr);
 968     int pos = _cache.find_sorted<VerifyMeetResultEntry, VerifyMeetResultEntry::compare>(meet, found);
 969     const Type* res = nullptr;
 970     if (found) {
 971       res = _cache.at(pos).res();
 972     } else {
 973       res = t1->xmeet(t2);
 974       _cache.insert_sorted<VerifyMeetResultEntry::compare>(VerifyMeetResultEntry(t1, t2, res));
 975       found = false;
 976       _cache.find_sorted<VerifyMeetResultEntry, VerifyMeetResultEntry::compare>(meet, found);
 977       assert(found, "should be in table after it's added");
 978     }
 979     return res;
 980   }
 981 
 982   void add(const Type* t1, const Type* t2, const Type* res) {
 983     _cache.insert_sorted<VerifyMeetResultEntry::compare>(VerifyMeetResultEntry(t1, t2, res));
 984   }
 985 
 986   bool empty_cache() const {
 987     return _cache.length() == 0;
 988   }
 989 public:
 990   VerifyMeetResult(Compile* C) :
 991           _depth(0), _cache(C->comp_arena(), 2, 0, VerifyMeetResultEntry()) {
 992   }
 993 };
 994 
 995 void Type::assert_type_verify_empty() const {
 996   assert(Compile::current()->_type_verify == nullptr || Compile::current()->_type_verify->empty_cache(), "cache should have been discarded");
 997 }
 998 
 999 class VerifyMeet {
1000 private:
1001   Compile* _C;
1002 public:
1003   VerifyMeet(Compile* C) : _C(C) {
1004     if (C->_type_verify == nullptr) {
1005       C->_type_verify = new (C->comp_arena())VerifyMeetResult(C);
1006     }
1007     _C->_type_verify->_depth++;
1008   }
1009 
1010   ~VerifyMeet() {
1011     assert(_C->_type_verify->_depth != 0, "");
1012     _C->_type_verify->_depth--;
1013     if (_C->_type_verify->_depth == 0) {
1014       _C->_type_verify->_cache.trunc_to(0);
1015     }
1016   }
1017 
1018   const Type* meet(const Type* t1, const Type* t2) const {
1019     return _C->_type_verify->meet(t1, t2);
1020   }
1021 
1022   void add(const Type* t1, const Type* t2, const Type* res) const {
1023     _C->_type_verify->add(t1, t2, res);
1024   }
1025 };
1026 
1027 void Type::check_symmetrical(const Type* t, const Type* mt, const VerifyMeet& verify) const {
1028   Compile* C = Compile::current();
1029   const Type* mt2 = verify.meet(t, this);
1030 
1031   // Verify that:
1032   //      this meet t == t meet this
1033   if (mt != mt2) {
1034     tty->print_cr("=== Meet Not Commutative ===");
1035     tty->print("t           = ");   t->dump(); tty->cr();
1036     tty->print("this        = ");      dump(); tty->cr();
1037     tty->print("t meet this = "); mt2->dump(); tty->cr();
1038     tty->print("this meet t = ");  mt->dump(); tty->cr();
1039     fatal("meet not commutative");
1040   }
1041   const Type* dual_join = mt->_dual;
1042   const Type* t2t    = verify.meet(dual_join,t->_dual);
1043   const Type* t2this = verify.meet(dual_join,this->_dual);
1044 
1045   // Interface meet Oop is Not Symmetric:
1046   // Interface:AnyNull meet Oop:AnyNull == Interface:AnyNull
1047   // Interface:NotNull meet Oop:NotNull == java/lang/Object:NotNull
1048 
1049   // Verify that:
1050   // 1)     mt_dual meet t_dual    == t_dual
1051   //    which corresponds to
1052   //       !(t meet this)  meet !t ==
1053   //       (!t join !this) meet !t == !t
1054   // 2)    mt_dual meet this_dual     == this_dual
1055   //    which corresponds to
1056   //       !(t meet this)  meet !this ==
1057   //       (!t join !this) meet !this == !this
1058   if (t2t != t->_dual || t2this != this->_dual) {
1059     tty->print_cr("=== Meet Not Symmetric ===");
1060     tty->print("t   =                   ");              t->dump(); tty->cr();
1061     tty->print("this=                   ");                 dump(); tty->cr();
1062     tty->print("mt=(t meet this)=       ");             mt->dump(); tty->cr();
1063 
1064     tty->print("t_dual=                 ");       t->_dual->dump(); tty->cr();
1065     tty->print("this_dual=              ");          _dual->dump(); tty->cr();
1066     tty->print("mt_dual=                ");      mt->_dual->dump(); tty->cr();
1067 
1068     // 1)
1069     tty->print("mt_dual meet t_dual=    "); t2t           ->dump(); tty->cr();
1070     // 2)
1071     tty->print("mt_dual meet this_dual= "); t2this        ->dump(); tty->cr();
1072     tty->cr();
1073     tty->print_cr("Fail: ");
1074     if (t2t != t->_dual) {
1075       tty->print_cr("- mt_dual meet t_dual != t_dual");
1076     }
1077     if (t2this != this->_dual) {
1078       tty->print_cr("- mt_dual meet this_dual != this_dual");
1079     }
1080     tty->cr();
1081 
1082     fatal("meet not symmetric");
1083   }
1084 }
1085 #endif
1086 
1087 //------------------------------meet-------------------------------------------
1088 // Compute the MEET of two types.  NOT virtual.  It enforces that meet is
1089 // commutative and the lattice is symmetric.
1090 const Type *Type::meet_helper(const Type *t, bool include_speculative) const {
1091   if (isa_narrowoop() && t->isa_narrowoop()) {
1092     const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
1093     return result->make_narrowoop();
1094   }
1095   if (isa_narrowklass() && t->isa_narrowklass()) {
1096     const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
1097     return result->make_narrowklass();
1098   }
1099 
1100 #ifdef ASSERT
1101   Compile* C = Compile::current();
1102   VerifyMeet verify(C);
1103 #endif
1104 
1105   const Type *this_t = maybe_remove_speculative(include_speculative);
1106   t = t->maybe_remove_speculative(include_speculative);
1107 
1108   const Type *mt = this_t->xmeet(t);
1109 #ifdef ASSERT
1110   verify.add(this_t, t, mt);
1111   if (isa_narrowoop() || t->isa_narrowoop()) {
1112     return mt;
1113   }
1114   if (isa_narrowklass() || t->isa_narrowklass()) {
1115     return mt;
1116   }
1117   // TODO 8350865 This currently triggers a verification failure, the code around "// Even though MyValue is final" needs adjustments
1118   if ((this_t->isa_ptr() && this_t->is_ptr()->is_not_flat()) ||
1119       (this_t->_dual->isa_ptr() && this_t->_dual->is_ptr()->is_not_flat())) return mt;
1120   this_t->check_symmetrical(t, mt, verify);
1121   const Type *mt_dual = verify.meet(this_t->_dual, t->_dual);
1122   this_t->_dual->check_symmetrical(t->_dual, mt_dual, verify);
1123 #endif
1124   return mt;
1125 }
1126 
1127 //------------------------------xmeet------------------------------------------
1128 // Compute the MEET of two types.  It returns a new Type object.
1129 const Type *Type::xmeet( const Type *t ) const {
1130   // Perform a fast test for common case; meeting the same types together.
1131   if( this == t ) return this;  // Meeting same type-rep?
1132 
1133   // Meeting TOP with anything?
1134   if( _base == Top ) return t;
1135 
1136   // Meeting BOTTOM with anything?
1137   if( _base == Bottom ) return BOTTOM;
1138 
1139   // Current "this->_base" is one of: Bad, Multi, Control, Top,
1140   // Abio, Abstore, Floatxxx, Doublexxx, Bottom, lastype.
1141   switch (t->base()) {  // Switch on original type
1142 
1143   // Cut in half the number of cases I must handle.  Only need cases for when
1144   // the given enum "t->type" is less than or equal to the local enum "type".
1145   case HalfFloatCon:
1146   case FloatCon:
1147   case DoubleCon:
1148   case Int:
1149   case Long:
1150     return t->xmeet(this);
1151 
1152   case OopPtr:
1153     return t->xmeet(this);
1154 
1155   case InstPtr:
1156     return t->xmeet(this);
1157 
1158   case MetadataPtr:
1159   case KlassPtr:
1160   case InstKlassPtr:
1161   case AryKlassPtr:
1162     return t->xmeet(this);
1163 
1164   case AryPtr:
1165     return t->xmeet(this);
1166 
1167   case NarrowOop:
1168     return t->xmeet(this);
1169 
1170   case NarrowKlass:
1171     return t->xmeet(this);
1172 
1173   case Bad:                     // Type check
1174   default:                      // Bogus type not in lattice
1175     typerr(t);
1176     return Type::BOTTOM;
1177 
1178   case Bottom:                  // Ye Olde Default
1179     return t;
1180 
1181   case HalfFloatTop:
1182     if (_base == HalfFloatTop) { return this; }
1183   case HalfFloatBot:            // Half Float
1184     if (_base == HalfFloatBot || _base == HalfFloatTop) { return HALF_FLOAT; }
1185     if (_base == FloatBot || _base == FloatTop) { return Type::BOTTOM; }
1186     if (_base == DoubleTop || _base == DoubleBot) { return Type::BOTTOM; }
1187     typerr(t);
1188     return Type::BOTTOM;
1189 
1190   case FloatTop:
1191     if (_base == FloatTop ) { return this; }
1192   case FloatBot:                // Float
1193     if (_base == FloatBot || _base == FloatTop) { return FLOAT; }
1194     if (_base == HalfFloatTop || _base == HalfFloatBot) { return Type::BOTTOM; }
1195     if (_base == DoubleTop || _base == DoubleBot) { return Type::BOTTOM; }
1196     typerr(t);
1197     return Type::BOTTOM;
1198 
1199   case DoubleTop:
1200     if (_base == DoubleTop) { return this; }
1201   case DoubleBot:               // Double
1202     if (_base == DoubleBot || _base == DoubleTop) { return DOUBLE; }
1203     if (_base == HalfFloatTop || _base == HalfFloatBot) { return Type::BOTTOM; }
1204     if (_base == FloatTop || _base == FloatBot) { return Type::BOTTOM; }
1205     typerr(t);
1206     return Type::BOTTOM;
1207 
1208   // These next few cases must match exactly or it is a compile-time error.
1209   case Control:                 // Control of code
1210   case Abio:                    // State of world outside of program
1211   case Memory:
1212     if (_base == t->_base)  { return this; }
1213     typerr(t);
1214     return Type::BOTTOM;
1215 
1216   case Top:                     // Top of the lattice
1217     return this;
1218   }
1219 
1220   // The type is unchanged
1221   return this;
1222 }
1223 
1224 //-----------------------------filter------------------------------------------
1225 const Type *Type::filter_helper(const Type *kills, bool include_speculative) const {
1226   const Type* ft = join_helper(kills, include_speculative);
1227   if (ft->empty())
1228     return Type::TOP;           // Canonical empty value
1229   return ft;
1230 }
1231 
1232 //------------------------------xdual------------------------------------------
1233 const Type *Type::xdual() const {
1234   // Note: the base() accessor asserts the sanity of _base.
1235   assert(_type_info[base()].dual_type != Bad, "implement with v-call");
1236   return new Type(_type_info[_base].dual_type);
1237 }
1238 
1239 //------------------------------has_memory-------------------------------------
1240 bool Type::has_memory() const {
1241   Type::TYPES tx = base();
1242   if (tx == Memory) return true;
1243   if (tx == Tuple) {
1244     const TypeTuple *t = is_tuple();
1245     for (uint i=0; i < t->cnt(); i++) {
1246       tx = t->field_at(i)->base();
1247       if (tx == Memory)  return true;
1248     }
1249   }
1250   return false;
1251 }
1252 
1253 #ifndef PRODUCT
1254 //------------------------------dump2------------------------------------------
1255 void Type::dump2( Dict &d, uint depth, outputStream *st ) const {
1256   st->print("%s", _type_info[_base].msg);
1257 }
1258 
1259 //------------------------------dump-------------------------------------------
1260 void Type::dump_on(outputStream *st) const {
1261   ResourceMark rm;
1262   Dict d(cmpkey,hashkey);       // Stop recursive type dumping
1263   dump2(d,1, st);
1264   if (is_ptr_to_narrowoop()) {
1265     st->print(" [narrow]");
1266   } else if (is_ptr_to_narrowklass()) {
1267     st->print(" [narrowklass]");
1268   }
1269 }
1270 
1271 //-----------------------------------------------------------------------------
1272 const char* Type::str(const Type* t) {
1273   stringStream ss;
1274   t->dump_on(&ss);
1275   return ss.as_string();
1276 }
1277 #endif
1278 
1279 //------------------------------singleton--------------------------------------
1280 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
1281 // constants (Ldi nodes).  Singletons are integer, float or double constants.
1282 bool Type::singleton(void) const {
1283   return _base == Top || _base == Half;
1284 }
1285 
1286 //------------------------------empty------------------------------------------
1287 // TRUE if Type is a type with no values, FALSE otherwise.
1288 bool Type::empty(void) const {
1289   switch (_base) {
1290   case DoubleTop:
1291   case FloatTop:
1292   case HalfFloatTop:
1293   case Top:
1294     return true;
1295 
1296   case Half:
1297   case Abio:
1298   case Return_Address:
1299   case Memory:
1300   case Bottom:
1301   case HalfFloatBot:
1302   case FloatBot:
1303   case DoubleBot:
1304     return false;  // never a singleton, therefore never empty
1305 
1306   default:
1307     ShouldNotReachHere();
1308     return false;
1309   }
1310 }
1311 
1312 //------------------------------dump_stats-------------------------------------
1313 // Dump collected statistics to stderr
1314 #ifndef PRODUCT
1315 void Type::dump_stats() {
1316   tty->print("Types made: %d\n", type_dict()->Size());
1317 }
1318 #endif
1319 
1320 //------------------------------category---------------------------------------
1321 #ifndef PRODUCT
1322 Type::Category Type::category() const {
1323   const TypeTuple* tuple;
1324   switch (base()) {
1325     case Type::Int:
1326     case Type::Long:
1327     case Type::Half:
1328     case Type::NarrowOop:
1329     case Type::NarrowKlass:
1330     case Type::Array:
1331     case Type::VectorA:
1332     case Type::VectorS:
1333     case Type::VectorD:
1334     case Type::VectorX:
1335     case Type::VectorY:
1336     case Type::VectorZ:
1337     case Type::VectorMask:
1338     case Type::AnyPtr:
1339     case Type::RawPtr:
1340     case Type::OopPtr:
1341     case Type::InstPtr:
1342     case Type::AryPtr:
1343     case Type::MetadataPtr:
1344     case Type::KlassPtr:
1345     case Type::InstKlassPtr:
1346     case Type::AryKlassPtr:
1347     case Type::Function:
1348     case Type::Return_Address:
1349     case Type::HalfFloatTop:
1350     case Type::HalfFloatCon:
1351     case Type::HalfFloatBot:
1352     case Type::FloatTop:
1353     case Type::FloatCon:
1354     case Type::FloatBot:
1355     case Type::DoubleTop:
1356     case Type::DoubleCon:
1357     case Type::DoubleBot:
1358       return Category::Data;
1359     case Type::Memory:
1360       return Category::Memory;
1361     case Type::Control:
1362       return Category::Control;
1363     case Type::Top:
1364     case Type::Abio:
1365     case Type::Bottom:
1366       return Category::Other;
1367     case Type::Bad:
1368     case Type::lastype:
1369       return Category::Undef;
1370     case Type::Tuple:
1371       // Recursive case. Return CatMixed if the tuple contains types of
1372       // different categories (e.g. CallStaticJavaNode's type), or the specific
1373       // category if all types are of the same category (e.g. IfNode's type).
1374       tuple = is_tuple();
1375       if (tuple->cnt() == 0) {
1376         return Category::Undef;
1377       } else {
1378         Category first = tuple->field_at(0)->category();
1379         for (uint i = 1; i < tuple->cnt(); i++) {
1380           if (tuple->field_at(i)->category() != first) {
1381             return Category::Mixed;
1382           }
1383         }
1384         return first;
1385       }
1386     default:
1387       assert(false, "unmatched base type: all base types must be categorized");
1388   }
1389   return Category::Undef;
1390 }
1391 
1392 bool Type::has_category(Type::Category cat) const {
1393   if (category() == cat) {
1394     return true;
1395   }
1396   if (category() == Category::Mixed) {
1397     const TypeTuple* tuple = is_tuple();
1398     for (uint i = 0; i < tuple->cnt(); i++) {
1399       if (tuple->field_at(i)->has_category(cat)) {
1400         return true;
1401       }
1402     }
1403   }
1404   return false;
1405 }
1406 #endif
1407 
1408 //------------------------------typerr-----------------------------------------
1409 void Type::typerr( const Type *t ) const {
1410 #ifndef PRODUCT
1411   tty->print("\nError mixing types: ");
1412   dump();
1413   tty->print(" and ");
1414   t->dump();
1415   tty->print("\n");
1416 #endif
1417   ShouldNotReachHere();
1418 }
1419 
1420 
1421 //=============================================================================
1422 // Convenience common pre-built types.
1423 const TypeF *TypeF::MAX;        // Floating point max
1424 const TypeF *TypeF::MIN;        // Floating point min
1425 const TypeF *TypeF::ZERO;       // Floating point zero
1426 const TypeF *TypeF::ONE;        // Floating point one
1427 const TypeF *TypeF::POS_INF;    // Floating point positive infinity
1428 const TypeF *TypeF::NEG_INF;    // Floating point negative infinity
1429 
1430 //------------------------------make-------------------------------------------
1431 // Create a float constant
1432 const TypeF *TypeF::make(float f) {
1433   return (TypeF*)(new TypeF(f))->hashcons();
1434 }
1435 
1436 //------------------------------meet-------------------------------------------
1437 // Compute the MEET of two types.  It returns a new Type object.
1438 const Type *TypeF::xmeet( const Type *t ) const {
1439   // Perform a fast test for common case; meeting the same types together.
1440   if( this == t ) return this;  // Meeting same type-rep?
1441 
1442   // Current "this->_base" is FloatCon
1443   switch (t->base()) {          // Switch on original type
1444   case AnyPtr:                  // Mixing with oops happens when javac
1445   case RawPtr:                  // reuses local variables
1446   case OopPtr:
1447   case InstPtr:
1448   case AryPtr:
1449   case MetadataPtr:
1450   case KlassPtr:
1451   case InstKlassPtr:
1452   case AryKlassPtr:
1453   case NarrowOop:
1454   case NarrowKlass:
1455   case Int:
1456   case Long:
1457   case HalfFloatTop:
1458   case HalfFloatCon:
1459   case HalfFloatBot:
1460   case DoubleTop:
1461   case DoubleCon:
1462   case DoubleBot:
1463   case Bottom:                  // Ye Olde Default
1464     return Type::BOTTOM;
1465 
1466   case FloatBot:
1467     return t;
1468 
1469   default:                      // All else is a mistake
1470     typerr(t);
1471 
1472   case FloatCon:                // Float-constant vs Float-constant?
1473     if( jint_cast(_f) != jint_cast(t->getf()) )         // unequal constants?
1474                                 // must compare bitwise as positive zero, negative zero and NaN have
1475                                 // all the same representation in C++
1476       return FLOAT;             // Return generic float
1477                                 // Equal constants
1478   case Top:
1479   case FloatTop:
1480     break;                      // Return the float constant
1481   }
1482   return this;                  // Return the float constant
1483 }
1484 
1485 //------------------------------xdual------------------------------------------
1486 // Dual: symmetric
1487 const Type *TypeF::xdual() const {
1488   return this;
1489 }
1490 
1491 //------------------------------eq---------------------------------------------
1492 // Structural equality check for Type representations
1493 bool TypeF::eq(const Type *t) const {
1494   // Bitwise comparison to distinguish between +/-0. These values must be treated
1495   // as different to be consistent with C1 and the interpreter.
1496   return (jint_cast(_f) == jint_cast(t->getf()));
1497 }
1498 
1499 //------------------------------hash-------------------------------------------
1500 // Type-specific hashing function.
1501 uint TypeF::hash(void) const {
1502   return *(uint*)(&_f);
1503 }
1504 
1505 //------------------------------is_finite--------------------------------------
1506 // Has a finite value
1507 bool TypeF::is_finite() const {
1508   return g_isfinite(getf()) != 0;
1509 }
1510 
1511 //------------------------------is_nan-----------------------------------------
1512 // Is not a number (NaN)
1513 bool TypeF::is_nan()    const {
1514   return g_isnan(getf()) != 0;
1515 }
1516 
1517 //------------------------------dump2------------------------------------------
1518 // Dump float constant Type
1519 #ifndef PRODUCT
1520 void TypeF::dump2( Dict &d, uint depth, outputStream *st ) const {
1521   Type::dump2(d,depth, st);
1522   st->print("%f", _f);
1523 }
1524 #endif
1525 
1526 //------------------------------singleton--------------------------------------
1527 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
1528 // constants (Ldi nodes).  Singletons are integer, float or double constants
1529 // or a single symbol.
1530 bool TypeF::singleton(void) const {
1531   return true;                  // Always a singleton
1532 }
1533 
1534 bool TypeF::empty(void) const {
1535   return false;                 // always exactly a singleton
1536 }
1537 
1538 //=============================================================================
1539 // Convenience common pre-built types.
1540 const TypeH* TypeH::MAX;        // Half float max
1541 const TypeH* TypeH::MIN;        // Half float min
1542 const TypeH* TypeH::ZERO;       // Half float zero
1543 const TypeH* TypeH::ONE;        // Half float one
1544 const TypeH* TypeH::POS_INF;    // Half float positive infinity
1545 const TypeH* TypeH::NEG_INF;    // Half float negative infinity
1546 
1547 //------------------------------make-------------------------------------------
1548 // Create a halffloat constant
1549 const TypeH* TypeH::make(short f) {
1550   return (TypeH*)(new TypeH(f))->hashcons();
1551 }
1552 
1553 const TypeH* TypeH::make(float f) {
1554   assert(StubRoutines::f2hf_adr() != nullptr, "");
1555   short hf = StubRoutines::f2hf(f);
1556   return (TypeH*)(new TypeH(hf))->hashcons();
1557 }
1558 
1559 //------------------------------xmeet-------------------------------------------
1560 // Compute the MEET of two types.  It returns a new Type object.
1561 const Type* TypeH::xmeet(const Type* t) const {
1562   // Perform a fast test for common case; meeting the same types together.
1563   if (this == t) return this;  // Meeting same type-rep?
1564 
1565   // Current "this->_base" is FloatCon
1566   switch (t->base()) {          // Switch on original type
1567   case AnyPtr:                  // Mixing with oops happens when javac
1568   case RawPtr:                  // reuses local variables
1569   case OopPtr:
1570   case InstPtr:
1571   case AryPtr:
1572   case MetadataPtr:
1573   case KlassPtr:
1574   case InstKlassPtr:
1575   case AryKlassPtr:
1576   case NarrowOop:
1577   case NarrowKlass:
1578   case Int:
1579   case Long:
1580   case FloatTop:
1581   case FloatCon:
1582   case FloatBot:
1583   case DoubleTop:
1584   case DoubleCon:
1585   case DoubleBot:
1586   case Bottom:                  // Ye Olde Default
1587     return Type::BOTTOM;
1588 
1589   case HalfFloatBot:
1590     return t;
1591 
1592   default:                      // All else is a mistake
1593     typerr(t);
1594 
1595   case HalfFloatCon:            // Half float-constant vs Half float-constant?
1596     if (_f != t->geth()) {      // unequal constants?
1597                                 // must compare bitwise as positive zero, negative zero and NaN have
1598                                 // all the same representation in C++
1599       return HALF_FLOAT;        // Return generic float
1600     }                           // Equal constants
1601   case Top:
1602   case HalfFloatTop:
1603     break;                      // Return the Half float constant
1604   }
1605   return this;                  // Return the Half float constant
1606 }
1607 
1608 //------------------------------xdual------------------------------------------
1609 // Dual: symmetric
1610 const Type* TypeH::xdual() const {
1611   return this;
1612 }
1613 
1614 //------------------------------eq---------------------------------------------
1615 // Structural equality check for Type representations
1616 bool TypeH::eq(const Type* t) const {
1617   // Bitwise comparison to distinguish between +/-0. These values must be treated
1618   // as different to be consistent with C1 and the interpreter.
1619   return (_f == t->geth());
1620 }
1621 
1622 //------------------------------hash-------------------------------------------
1623 // Type-specific hashing function.
1624 uint TypeH::hash(void) const {
1625   return *(jshort*)(&_f);
1626 }
1627 
1628 //------------------------------is_finite--------------------------------------
1629 // Has a finite value
1630 bool TypeH::is_finite() const {
1631   assert(StubRoutines::hf2f_adr() != nullptr, "");
1632   float f = StubRoutines::hf2f(geth());
1633   return g_isfinite(f) != 0;
1634 }
1635 
1636 float TypeH::getf() const {
1637   assert(StubRoutines::hf2f_adr() != nullptr, "");
1638   return StubRoutines::hf2f(geth());
1639 }
1640 
1641 //------------------------------is_nan-----------------------------------------
1642 // Is not a number (NaN)
1643 bool TypeH::is_nan() const {
1644   assert(StubRoutines::hf2f_adr() != nullptr, "");
1645   float f = StubRoutines::hf2f(geth());
1646   return g_isnan(f) != 0;
1647 }
1648 
1649 //------------------------------dump2------------------------------------------
1650 // Dump float constant Type
1651 #ifndef PRODUCT
1652 void TypeH::dump2(Dict &d, uint depth, outputStream* st) const {
1653   Type::dump2(d,depth, st);
1654   st->print("%f", getf());
1655 }
1656 #endif
1657 
1658 //------------------------------singleton--------------------------------------
1659 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
1660 // constants (Ldi nodes).  Singletons are integer, half float, float or double constants
1661 // or a single symbol.
1662 bool TypeH::singleton(void) const {
1663   return true;                  // Always a singleton
1664 }
1665 
1666 bool TypeH::empty(void) const {
1667   return false;                 // always exactly a singleton
1668 }
1669 
1670 //=============================================================================
1671 // Convenience common pre-built types.
1672 const TypeD *TypeD::MAX;        // Floating point max
1673 const TypeD *TypeD::MIN;        // Floating point min
1674 const TypeD *TypeD::ZERO;       // Floating point zero
1675 const TypeD *TypeD::ONE;        // Floating point one
1676 const TypeD *TypeD::POS_INF;    // Floating point positive infinity
1677 const TypeD *TypeD::NEG_INF;    // Floating point negative infinity
1678 
1679 //------------------------------make-------------------------------------------
1680 const TypeD *TypeD::make(double d) {
1681   return (TypeD*)(new TypeD(d))->hashcons();
1682 }
1683 
1684 //------------------------------meet-------------------------------------------
1685 // Compute the MEET of two types.  It returns a new Type object.
1686 const Type *TypeD::xmeet( const Type *t ) const {
1687   // Perform a fast test for common case; meeting the same types together.
1688   if( this == t ) return this;  // Meeting same type-rep?
1689 
1690   // Current "this->_base" is DoubleCon
1691   switch (t->base()) {          // Switch on original type
1692   case AnyPtr:                  // Mixing with oops happens when javac
1693   case RawPtr:                  // reuses local variables
1694   case OopPtr:
1695   case InstPtr:
1696   case AryPtr:
1697   case MetadataPtr:
1698   case KlassPtr:
1699   case InstKlassPtr:
1700   case AryKlassPtr:
1701   case NarrowOop:
1702   case NarrowKlass:
1703   case Int:
1704   case Long:
1705   case HalfFloatTop:
1706   case HalfFloatCon:
1707   case HalfFloatBot:
1708   case FloatTop:
1709   case FloatCon:
1710   case FloatBot:
1711   case Bottom:                  // Ye Olde Default
1712     return Type::BOTTOM;
1713 
1714   case DoubleBot:
1715     return t;
1716 
1717   default:                      // All else is a mistake
1718     typerr(t);
1719 
1720   case DoubleCon:               // Double-constant vs Double-constant?
1721     if( jlong_cast(_d) != jlong_cast(t->getd()) )       // unequal constants? (see comment in TypeF::xmeet)
1722       return DOUBLE;            // Return generic double
1723   case Top:
1724   case DoubleTop:
1725     break;
1726   }
1727   return this;                  // Return the double constant
1728 }
1729 
1730 //------------------------------xdual------------------------------------------
1731 // Dual: symmetric
1732 const Type *TypeD::xdual() const {
1733   return this;
1734 }
1735 
1736 //------------------------------eq---------------------------------------------
1737 // Structural equality check for Type representations
1738 bool TypeD::eq(const Type *t) const {
1739   // Bitwise comparison to distinguish between +/-0. These values must be treated
1740   // as different to be consistent with C1 and the interpreter.
1741   return (jlong_cast(_d) == jlong_cast(t->getd()));
1742 }
1743 
1744 //------------------------------hash-------------------------------------------
1745 // Type-specific hashing function.
1746 uint TypeD::hash(void) const {
1747   return *(uint*)(&_d);
1748 }
1749 
1750 //------------------------------is_finite--------------------------------------
1751 // Has a finite value
1752 bool TypeD::is_finite() const {
1753   return g_isfinite(getd()) != 0;
1754 }
1755 
1756 //------------------------------is_nan-----------------------------------------
1757 // Is not a number (NaN)
1758 bool TypeD::is_nan()    const {
1759   return g_isnan(getd()) != 0;
1760 }
1761 
1762 //------------------------------dump2------------------------------------------
1763 // Dump double constant Type
1764 #ifndef PRODUCT
1765 void TypeD::dump2( Dict &d, uint depth, outputStream *st ) const {
1766   Type::dump2(d,depth,st);
1767   st->print("%f", _d);
1768 }
1769 #endif
1770 
1771 //------------------------------singleton--------------------------------------
1772 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
1773 // constants (Ldi nodes).  Singletons are integer, float or double constants
1774 // or a single symbol.
1775 bool TypeD::singleton(void) const {
1776   return true;                  // Always a singleton
1777 }
1778 
1779 bool TypeD::empty(void) const {
1780   return false;                 // always exactly a singleton
1781 }
1782 
1783 const TypeInteger* TypeInteger::make(jlong lo, jlong hi, int w, BasicType bt) {
1784   if (bt == T_INT) {
1785     return TypeInt::make(checked_cast<jint>(lo), checked_cast<jint>(hi), w);
1786   }
1787   assert(bt == T_LONG, "basic type not an int or long");
1788   return TypeLong::make(lo, hi, w);
1789 }
1790 
1791 const TypeInteger* TypeInteger::make(jlong con, BasicType bt) {
1792   return make(con, con, WidenMin, bt);
1793 }
1794 
1795 jlong TypeInteger::get_con_as_long(BasicType bt) const {
1796   if (bt == T_INT) {
1797     return is_int()->get_con();
1798   }
1799   assert(bt == T_LONG, "basic type not an int or long");
1800   return is_long()->get_con();
1801 }
1802 
1803 const TypeInteger* TypeInteger::bottom(BasicType bt) {
1804   if (bt == T_INT) {
1805     return TypeInt::INT;
1806   }
1807   assert(bt == T_LONG, "basic type not an int or long");
1808   return TypeLong::LONG;
1809 }
1810 
1811 const TypeInteger* TypeInteger::zero(BasicType bt) {
1812   if (bt == T_INT) {
1813     return TypeInt::ZERO;
1814   }
1815   assert(bt == T_LONG, "basic type not an int or long");
1816   return TypeLong::ZERO;
1817 }
1818 
1819 const TypeInteger* TypeInteger::one(BasicType bt) {
1820   if (bt == T_INT) {
1821     return TypeInt::ONE;
1822   }
1823   assert(bt == T_LONG, "basic type not an int or long");
1824   return TypeLong::ONE;
1825 }
1826 
1827 const TypeInteger* TypeInteger::minus_1(BasicType bt) {
1828   if (bt == T_INT) {
1829     return TypeInt::MINUS_1;
1830   }
1831   assert(bt == T_LONG, "basic type not an int or long");
1832   return TypeLong::MINUS_1;
1833 }
1834 
1835 //=============================================================================
1836 // Convenience common pre-built types.
1837 const TypeInt* TypeInt::MAX;    // INT_MAX
1838 const TypeInt* TypeInt::MIN;    // INT_MIN
1839 const TypeInt* TypeInt::MINUS_1;// -1
1840 const TypeInt* TypeInt::ZERO;   // 0
1841 const TypeInt* TypeInt::ONE;    // 1
1842 const TypeInt* TypeInt::BOOL;   // 0 or 1, FALSE or TRUE.
1843 const TypeInt* TypeInt::CC;     // -1,0 or 1, condition codes
1844 const TypeInt* TypeInt::CC_LT;  // [-1]  == MINUS_1
1845 const TypeInt* TypeInt::CC_GT;  // [1]   == ONE
1846 const TypeInt* TypeInt::CC_EQ;  // [0]   == ZERO
1847 const TypeInt* TypeInt::CC_NE;
1848 const TypeInt* TypeInt::CC_LE;  // [-1,0]
1849 const TypeInt* TypeInt::CC_GE;  // [0,1] == BOOL (!)
1850 const TypeInt* TypeInt::BYTE;   // Bytes, -128 to 127
1851 const TypeInt* TypeInt::UBYTE;  // Unsigned Bytes, 0 to 255
1852 const TypeInt* TypeInt::CHAR;   // Java chars, 0-65535
1853 const TypeInt* TypeInt::SHORT;  // Java shorts, -32768-32767
1854 const TypeInt* TypeInt::NON_ZERO;
1855 const TypeInt* TypeInt::POS;    // Positive 32-bit integers or zero
1856 const TypeInt* TypeInt::POS1;   // Positive 32-bit integers
1857 const TypeInt* TypeInt::INT;    // 32-bit integers
1858 const TypeInt* TypeInt::SYMINT; // symmetric range [-max_jint..max_jint]
1859 const TypeInt* TypeInt::TYPE_DOMAIN; // alias for TypeInt::INT
1860 
1861 TypeInt::TypeInt(const TypeIntPrototype<jint, juint>& t, int widen, bool dual)
1862   : TypeInteger(Int, t.normalize_widen(widen), dual), _lo(t._srange._lo), _hi(t._srange._hi),
1863     _ulo(t._urange._lo), _uhi(t._urange._hi), _bits(t._bits) {
1864   DEBUG_ONLY(t.verify_constraints());
1865 }
1866 
1867 const Type* TypeInt::make_or_top(const TypeIntPrototype<jint, juint>& t, int widen, bool dual) {
1868   auto canonicalized_t = t.canonicalize_constraints();
1869   if (canonicalized_t.empty()) {
1870     return dual ? Type::BOTTOM : Type::TOP;
1871   }
1872   return (new TypeInt(canonicalized_t._data, widen, dual))->hashcons()->is_int();
1873 }
1874 
1875 const TypeInt* TypeInt::make(jint con) {
1876   juint ucon = con;
1877   return (new TypeInt(TypeIntPrototype<jint, juint>{{con, con}, {ucon, ucon}, {~ucon, ucon}},
1878                       WidenMin, false))->hashcons()->is_int();
1879 }
1880 
1881 const TypeInt* TypeInt::make(jint lo, jint hi, int widen) {
1882   assert(lo <= hi, "must be legal bounds");
1883   return make_or_top(TypeIntPrototype<jint, juint>{{lo, hi}, {0, max_juint}, {0, 0}}, widen)->is_int();
1884 }
1885 
1886 const Type* TypeInt::make_or_top(const TypeIntPrototype<jint, juint>& t, int widen) {
1887   return make_or_top(t, widen, false);
1888 }
1889 
1890 bool TypeInt::contains(jint i) const {
1891   assert(!_is_dual, "dual types should only be used for join calculation");
1892   juint u = i;
1893   return i >= _lo && i <= _hi &&
1894          u >= _ulo && u <= _uhi &&
1895          _bits.is_satisfied_by(u);
1896 }
1897 
1898 bool TypeInt::contains(const TypeInt* t) const {
1899   assert(!_is_dual && !t->_is_dual, "dual types should only be used for join calculation");
1900   return TypeIntHelper::int_type_is_subset(this, t);
1901 }
1902 
1903 const Type* TypeInt::xmeet(const Type* t) const {
1904   return TypeIntHelper::int_type_xmeet(this, t);
1905 }
1906 
1907 const Type* TypeInt::xdual() const {
1908   return new TypeInt(TypeIntPrototype<jint, juint>{{_lo, _hi}, {_ulo, _uhi}, _bits},
1909                      _widen, !_is_dual);
1910 }
1911 
1912 const Type* TypeInt::widen(const Type* old, const Type* limit) const {
1913   assert(!_is_dual, "dual types should only be used for join calculation");
1914   return TypeIntHelper::int_type_widen(this, old->isa_int(), limit->isa_int());
1915 }
1916 
1917 const Type* TypeInt::narrow(const Type* old) const {
1918   assert(!_is_dual, "dual types should only be used for join calculation");
1919   if (old == nullptr) {
1920     return this;
1921   }
1922 
1923   return TypeIntHelper::int_type_narrow(this, old->isa_int());
1924 }
1925 
1926 //-----------------------------filter------------------------------------------
1927 const Type* TypeInt::filter_helper(const Type* kills, bool include_speculative) const {
1928   assert(!_is_dual, "dual types should only be used for join calculation");
1929   const TypeInt* ft = join_helper(kills, include_speculative)->isa_int();
1930   if (ft == nullptr) {
1931     return Type::TOP;           // Canonical empty value
1932   }
1933   assert(!ft->_is_dual, "dual types should only be used for join calculation");
1934   if (ft->_widen < this->_widen) {
1935     // Do not allow the value of kill->_widen to affect the outcome.
1936     // The widen bits must be allowed to run freely through the graph.
1937     return (new TypeInt(TypeIntPrototype<jint, juint>{{ft->_lo, ft->_hi}, {ft->_ulo, ft->_uhi}, ft->_bits},
1938                         this->_widen, false))->hashcons();
1939   }
1940   return ft;
1941 }
1942 
1943 //------------------------------eq---------------------------------------------
1944 // Structural equality check for Type representations
1945 bool TypeInt::eq(const Type* t) const {
1946   const TypeInt* r = t->is_int();
1947   return TypeIntHelper::int_type_is_equal(this, r) && _widen == r->_widen && _is_dual == r->_is_dual;
1948 }
1949 
1950 //------------------------------hash-------------------------------------------
1951 // Type-specific hashing function.
1952 uint TypeInt::hash(void) const {
1953   return (uint)_lo + (uint)_hi + (uint)_ulo + (uint)_uhi +
1954          (uint)_bits._zeros + (uint)_bits._ones + (uint)_widen + (uint)_is_dual + (uint)Type::Int;
1955 }
1956 
1957 //------------------------------is_finite--------------------------------------
1958 // Has a finite value
1959 bool TypeInt::is_finite() const {
1960   return true;
1961 }
1962 
1963 //------------------------------singleton--------------------------------------
1964 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
1965 // constants.
1966 bool TypeInt::singleton(void) const {
1967   return _lo == _hi;
1968 }
1969 
1970 bool TypeInt::empty(void) const {
1971   return false;
1972 }
1973 
1974 //=============================================================================
1975 // Convenience common pre-built types.
1976 const TypeLong* TypeLong::MAX;
1977 const TypeLong* TypeLong::MIN;
1978 const TypeLong* TypeLong::MINUS_1;// -1
1979 const TypeLong* TypeLong::ZERO; // 0
1980 const TypeLong* TypeLong::ONE;  // 1
1981 const TypeLong* TypeLong::NON_ZERO;
1982 const TypeLong* TypeLong::POS;  // >=0
1983 const TypeLong* TypeLong::NEG;
1984 const TypeLong* TypeLong::LONG; // 64-bit integers
1985 const TypeLong* TypeLong::INT;  // 32-bit subrange
1986 const TypeLong* TypeLong::UINT; // 32-bit unsigned subrange
1987 const TypeLong* TypeLong::TYPE_DOMAIN; // alias for TypeLong::LONG
1988 
1989 TypeLong::TypeLong(const TypeIntPrototype<jlong, julong>& t, int widen, bool dual)
1990   : TypeInteger(Long, t.normalize_widen(widen), dual), _lo(t._srange._lo), _hi(t._srange._hi),
1991     _ulo(t._urange._lo), _uhi(t._urange._hi), _bits(t._bits) {
1992   DEBUG_ONLY(t.verify_constraints());
1993 }
1994 
1995 const Type* TypeLong::make_or_top(const TypeIntPrototype<jlong, julong>& t, int widen, bool dual) {
1996   auto canonicalized_t = t.canonicalize_constraints();
1997   if (canonicalized_t.empty()) {
1998     return dual ? Type::BOTTOM : Type::TOP;
1999   }
2000   return (new TypeLong(canonicalized_t._data, widen, dual))->hashcons()->is_long();
2001 }
2002 
2003 const TypeLong* TypeLong::make(jlong con) {
2004   julong ucon = con;
2005   return (new TypeLong(TypeIntPrototype<jlong, julong>{{con, con}, {ucon, ucon}, {~ucon, ucon}},
2006                        WidenMin, false))->hashcons()->is_long();
2007 }
2008 
2009 const TypeLong* TypeLong::make(jlong lo, jlong hi, int widen) {
2010   assert(lo <= hi, "must be legal bounds");
2011   return make_or_top(TypeIntPrototype<jlong, julong>{{lo, hi}, {0, max_julong}, {0, 0}}, widen)->is_long();
2012 }
2013 
2014 const Type* TypeLong::make_or_top(const TypeIntPrototype<jlong, julong>& t, int widen) {
2015   return make_or_top(t, widen, false);
2016 }
2017 
2018 bool TypeLong::contains(jlong i) const {
2019   assert(!_is_dual, "dual types should only be used for join calculation");
2020   julong u = i;
2021   return i >= _lo && i <= _hi &&
2022          u >= _ulo && u <= _uhi &&
2023          _bits.is_satisfied_by(u);
2024 }
2025 
2026 bool TypeLong::contains(const TypeLong* t) const {
2027   assert(!_is_dual && !t->_is_dual, "dual types should only be used for join calculation");
2028   return TypeIntHelper::int_type_is_subset(this, t);
2029 }
2030 
2031 const Type* TypeLong::xmeet(const Type* t) const {
2032   return TypeIntHelper::int_type_xmeet(this, t);
2033 }
2034 
2035 const Type* TypeLong::xdual() const {
2036   return new TypeLong(TypeIntPrototype<jlong, julong>{{_lo, _hi}, {_ulo, _uhi}, _bits},
2037                       _widen, !_is_dual);
2038 }
2039 
2040 const Type* TypeLong::widen(const Type* old, const Type* limit) const {
2041   assert(!_is_dual, "dual types should only be used for join calculation");
2042   return TypeIntHelper::int_type_widen(this, old->isa_long(), limit->isa_long());
2043 }
2044 
2045 const Type* TypeLong::narrow(const Type* old) const {
2046   assert(!_is_dual, "dual types should only be used for join calculation");
2047   if (old == nullptr) {
2048     return this;
2049   }
2050 
2051   return TypeIntHelper::int_type_narrow(this, old->isa_long());
2052 }
2053 
2054 //-----------------------------filter------------------------------------------
2055 const Type* TypeLong::filter_helper(const Type* kills, bool include_speculative) const {
2056   assert(!_is_dual, "dual types should only be used for join calculation");
2057   const TypeLong* ft = join_helper(kills, include_speculative)->isa_long();
2058   if (ft == nullptr) {
2059     return Type::TOP;           // Canonical empty value
2060   }
2061   assert(!ft->_is_dual, "dual types should only be used for join calculation");
2062   if (ft->_widen < this->_widen) {
2063     // Do not allow the value of kill->_widen to affect the outcome.
2064     // The widen bits must be allowed to run freely through the graph.
2065     return (new TypeLong(TypeIntPrototype<jlong, julong>{{ft->_lo, ft->_hi}, {ft->_ulo, ft->_uhi}, ft->_bits},
2066                          this->_widen, false))->hashcons();
2067   }
2068   return ft;
2069 }
2070 
2071 //------------------------------eq---------------------------------------------
2072 // Structural equality check for Type representations
2073 bool TypeLong::eq(const Type* t) const {
2074   const TypeLong* r = t->is_long();
2075   return TypeIntHelper::int_type_is_equal(this, r) && _widen == r->_widen && _is_dual == r->_is_dual;
2076 }
2077 
2078 //------------------------------hash-------------------------------------------
2079 // Type-specific hashing function.
2080 uint TypeLong::hash(void) const {
2081   return (uint)_lo + (uint)_hi + (uint)_ulo + (uint)_uhi +
2082          (uint)_bits._zeros + (uint)_bits._ones + (uint)_widen + (uint)_is_dual + (uint)Type::Long;
2083 }
2084 
2085 //------------------------------is_finite--------------------------------------
2086 // Has a finite value
2087 bool TypeLong::is_finite() const {
2088   return true;
2089 }
2090 
2091 //------------------------------singleton--------------------------------------
2092 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2093 // constants
2094 bool TypeLong::singleton(void) const {
2095   return _lo == _hi;
2096 }
2097 
2098 bool TypeLong::empty(void) const {
2099   return false;
2100 }
2101 
2102 //------------------------------dump2------------------------------------------
2103 #ifndef PRODUCT
2104 void TypeInt::dump2(Dict& d, uint depth, outputStream* st) const {
2105   TypeIntHelper::int_type_dump(this, st, false);
2106 }
2107 
2108 void TypeInt::dump_verbose() const {
2109   TypeIntHelper::int_type_dump(this, tty, true);
2110 }
2111 
2112 void TypeLong::dump2(Dict& d, uint depth, outputStream* st) const {
2113   TypeIntHelper::int_type_dump(this, st, false);
2114 }
2115 
2116 void TypeLong::dump_verbose() const {
2117   TypeIntHelper::int_type_dump(this, tty, true);
2118 }
2119 #endif
2120 
2121 //=============================================================================
2122 // Convenience common pre-built types.
2123 const TypeTuple *TypeTuple::IFBOTH;     // Return both arms of IF as reachable
2124 const TypeTuple *TypeTuple::IFFALSE;
2125 const TypeTuple *TypeTuple::IFTRUE;
2126 const TypeTuple *TypeTuple::IFNEITHER;
2127 const TypeTuple *TypeTuple::LOOPBODY;
2128 const TypeTuple *TypeTuple::MEMBAR;
2129 const TypeTuple *TypeTuple::STORECONDITIONAL;
2130 const TypeTuple *TypeTuple::START_I2C;
2131 const TypeTuple *TypeTuple::INT_PAIR;
2132 const TypeTuple *TypeTuple::LONG_PAIR;
2133 const TypeTuple *TypeTuple::INT_CC_PAIR;
2134 const TypeTuple *TypeTuple::LONG_CC_PAIR;
2135 
2136 static void collect_inline_fields(ciInlineKlass* vk, const Type** field_array, uint& pos) {
2137   for (int i = 0; i < vk->nof_declared_nonstatic_fields(); i++) {
2138     ciField* field = vk->declared_nonstatic_field_at(i);
2139     if (field->is_flat()) {
2140       collect_inline_fields(field->type()->as_inline_klass(), field_array, pos);
2141       if (!field->is_null_free()) {
2142         // Use T_INT instead of T_BOOLEAN here because the upper bits can contain garbage if the holder
2143         // is null and C2 will only zero them for T_INT assuming that T_BOOLEAN is already canonicalized.
2144         field_array[pos++] = Type::get_const_basic_type(T_INT);
2145       }
2146     } else {
2147       BasicType bt = field->type()->basic_type();
2148       const Type* ft = Type::get_const_type(field->type());
2149       field_array[pos++] = ft;
2150       if (type2size[bt] == 2) {
2151         field_array[pos++] = Type::HALF;
2152       }
2153     }
2154   }
2155 }
2156 
2157 //------------------------------make-------------------------------------------
2158 // Make a TypeTuple from the range of a method signature
2159 const TypeTuple *TypeTuple::make_range(ciSignature* sig, InterfaceHandling interface_handling, bool ret_vt_fields) {
2160   ciType* return_type = sig->return_type();
2161   uint arg_cnt = return_type->size();
2162   if (ret_vt_fields) {
2163     arg_cnt = return_type->as_inline_klass()->inline_arg_slots() + 1;
2164     // InlineTypeNode::NullMarker field used for null checking
2165     arg_cnt++;
2166   }
2167   const Type **field_array = fields(arg_cnt);
2168   switch (return_type->basic_type()) {
2169   case T_LONG:
2170     field_array[TypeFunc::Parms]   = TypeLong::LONG;
2171     field_array[TypeFunc::Parms+1] = Type::HALF;
2172     break;
2173   case T_DOUBLE:
2174     field_array[TypeFunc::Parms]   = Type::DOUBLE;
2175     field_array[TypeFunc::Parms+1] = Type::HALF;
2176     break;
2177   case T_OBJECT:
2178     if (return_type->is_inlinetype() && ret_vt_fields) {
2179       uint pos = TypeFunc::Parms;
2180       field_array[pos++] = get_const_type(return_type); // Oop might be null when returning as fields
2181       collect_inline_fields(return_type->as_inline_klass(), field_array, pos);
2182       // InlineTypeNode::NullMarker field used for null checking
2183       field_array[pos++] = get_const_basic_type(T_BOOLEAN);
2184       assert(pos == (TypeFunc::Parms + arg_cnt), "out of bounds");
2185       break;
2186     } else {
2187       field_array[TypeFunc::Parms] = get_const_type(return_type, interface_handling)->join_speculative(TypePtr::BOTTOM);
2188     }
2189     break;
2190   case T_ARRAY:
2191   case T_BOOLEAN:
2192   case T_CHAR:
2193   case T_FLOAT:
2194   case T_BYTE:
2195   case T_SHORT:
2196   case T_INT:
2197     field_array[TypeFunc::Parms] = get_const_type(return_type, interface_handling);
2198     break;
2199   case T_VOID:
2200     break;
2201   default:
2202     ShouldNotReachHere();
2203   }
2204   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2205 }
2206 
2207 // Make a TypeTuple from the domain of a method signature
2208 const TypeTuple *TypeTuple::make_domain(ciMethod* method, InterfaceHandling interface_handling, bool vt_fields_as_args) {
2209   ciSignature* sig = method->signature();
2210   uint arg_cnt = sig->size() + (method->is_static() ? 0 : 1);
2211   if (vt_fields_as_args) {
2212     arg_cnt = 0;
2213     assert(method->get_sig_cc() != nullptr, "Should have scalarized signature");
2214     for (ExtendedSignature sig_cc = ExtendedSignature(method->get_sig_cc(), SigEntryFilter()); !sig_cc.at_end(); ++sig_cc) {
2215       arg_cnt += type2size[(*sig_cc)._bt];
2216     }
2217   }
2218 
2219   uint pos = TypeFunc::Parms;
2220   const Type** field_array = fields(arg_cnt);
2221   if (!method->is_static()) {
2222     ciInstanceKlass* recv = method->holder();
2223     if (vt_fields_as_args && recv->is_inlinetype() && recv->as_inline_klass()->can_be_passed_as_fields() && method->is_scalarized_arg(0)) {
2224       collect_inline_fields(recv->as_inline_klass(), field_array, pos);
2225     } else {
2226       field_array[pos++] = get_const_type(recv, interface_handling)->join_speculative(TypePtr::NOTNULL);
2227     }
2228   }
2229 
2230   int i = 0;
2231   while (pos < TypeFunc::Parms + arg_cnt) {
2232     ciType* type = sig->type_at(i);
2233     BasicType bt = type->basic_type();
2234 
2235     switch (bt) {
2236     case T_LONG:
2237       field_array[pos++] = TypeLong::LONG;
2238       field_array[pos++] = Type::HALF;
2239       break;
2240     case T_DOUBLE:
2241       field_array[pos++] = Type::DOUBLE;
2242       field_array[pos++] = Type::HALF;
2243       break;
2244     case T_OBJECT:
2245       if (type->is_inlinetype() && vt_fields_as_args && method->is_scalarized_arg(i + (method->is_static() ? 0 : 1))) {
2246         // InlineTypeNode::NullMarker field used for null checking
2247         field_array[pos++] = get_const_basic_type(T_BOOLEAN);
2248         collect_inline_fields(type->as_inline_klass(), field_array, pos);
2249       } else {
2250         field_array[pos++] = get_const_type(type, interface_handling);
2251       }
2252       break;
2253     case T_ARRAY:
2254     case T_FLOAT:
2255     case T_INT:
2256       field_array[pos++] = get_const_type(type, interface_handling);
2257       break;
2258     case T_BOOLEAN:
2259     case T_CHAR:
2260     case T_BYTE:
2261     case T_SHORT:
2262       field_array[pos++] = TypeInt::INT;
2263       break;
2264     default:
2265       ShouldNotReachHere();
2266     }
2267     i++;
2268   }
2269   assert(pos == TypeFunc::Parms + arg_cnt, "wrong number of arguments");
2270 
2271   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2272 }
2273 
2274 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2275   return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2276 }
2277 
2278 //------------------------------fields-----------------------------------------
2279 // Subroutine call type with space allocated for argument types
2280 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
2281 const Type **TypeTuple::fields( uint arg_cnt ) {
2282   const Type **flds = (const Type **)(Compile::current()->type_arena()->AmallocWords((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
2283   flds[TypeFunc::Control  ] = Type::CONTROL;
2284   flds[TypeFunc::I_O      ] = Type::ABIO;
2285   flds[TypeFunc::Memory   ] = Type::MEMORY;
2286   flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
2287   flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
2288 
2289   return flds;
2290 }
2291 
2292 //------------------------------meet-------------------------------------------
2293 // Compute the MEET of two types.  It returns a new Type object.
2294 const Type *TypeTuple::xmeet( const Type *t ) const {
2295   // Perform a fast test for common case; meeting the same types together.
2296   if( this == t ) return this;  // Meeting same type-rep?
2297 
2298   // Current "this->_base" is Tuple
2299   switch (t->base()) {          // switch on original type
2300 
2301   case Bottom:                  // Ye Olde Default
2302     return t;
2303 
2304   default:                      // All else is a mistake
2305     typerr(t);
2306 
2307   case Tuple: {                 // Meeting 2 signatures?
2308     const TypeTuple *x = t->is_tuple();
2309     assert( _cnt == x->_cnt, "" );
2310     const Type **fields = (const Type **)(Compile::current()->type_arena()->AmallocWords( _cnt*sizeof(Type*) ));
2311     for( uint i=0; i<_cnt; i++ )
2312       fields[i] = field_at(i)->xmeet( x->field_at(i) );
2313     return TypeTuple::make(_cnt,fields);
2314   }
2315   case Top:
2316     break;
2317   }
2318   return this;                  // Return the double constant
2319 }
2320 
2321 //------------------------------xdual------------------------------------------
2322 // Dual: compute field-by-field dual
2323 const Type *TypeTuple::xdual() const {
2324   const Type **fields = (const Type **)(Compile::current()->type_arena()->AmallocWords( _cnt*sizeof(Type*) ));
2325   for( uint i=0; i<_cnt; i++ )
2326     fields[i] = _fields[i]->dual();
2327   return new TypeTuple(_cnt,fields);
2328 }
2329 
2330 //------------------------------eq---------------------------------------------
2331 // Structural equality check for Type representations
2332 bool TypeTuple::eq( const Type *t ) const {
2333   const TypeTuple *s = (const TypeTuple *)t;
2334   if (_cnt != s->_cnt)  return false;  // Unequal field counts
2335   for (uint i = 0; i < _cnt; i++)
2336     if (field_at(i) != s->field_at(i)) // POINTER COMPARE!  NO RECURSION!
2337       return false;             // Missed
2338   return true;
2339 }
2340 
2341 //------------------------------hash-------------------------------------------
2342 // Type-specific hashing function.
2343 uint TypeTuple::hash(void) const {
2344   uintptr_t sum = _cnt;
2345   for( uint i=0; i<_cnt; i++ )
2346     sum += (uintptr_t)_fields[i];     // Hash on pointers directly
2347   return (uint)sum;
2348 }
2349 
2350 //------------------------------dump2------------------------------------------
2351 // Dump signature Type
2352 #ifndef PRODUCT
2353 void TypeTuple::dump2( Dict &d, uint depth, outputStream *st ) const {
2354   st->print("{");
2355   if( !depth || d[this] ) {     // Check for recursive print
2356     st->print("...}");
2357     return;
2358   }
2359   d.Insert((void*)this, (void*)this);   // Stop recursion
2360   if( _cnt ) {
2361     uint i;
2362     for( i=0; i<_cnt-1; i++ ) {
2363       st->print("%d:", i);
2364       _fields[i]->dump2(d, depth-1, st);
2365       st->print(", ");
2366     }
2367     st->print("%d:", i);
2368     _fields[i]->dump2(d, depth-1, st);
2369   }
2370   st->print("}");
2371 }
2372 #endif
2373 
2374 //------------------------------singleton--------------------------------------
2375 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2376 // constants (Ldi nodes).  Singletons are integer, float or double constants
2377 // or a single symbol.
2378 bool TypeTuple::singleton(void) const {
2379   return false;                 // Never a singleton
2380 }
2381 
2382 bool TypeTuple::empty(void) const {
2383   for( uint i=0; i<_cnt; i++ ) {
2384     if (_fields[i]->empty())  return true;
2385   }
2386   return false;
2387 }
2388 
2389 //=============================================================================
2390 // Convenience common pre-built types.
2391 
2392 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2393   // Certain normalizations keep us sane when comparing types.
2394   // We do not want arrayOop variables to differ only by the wideness
2395   // of their index types.  Pick minimum wideness, since that is the
2396   // forced wideness of small ranges anyway.
2397   if (size->_widen != Type::WidenMin)
2398     return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2399   else
2400     return size;
2401 }
2402 
2403 //------------------------------make-------------------------------------------
2404 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable,
2405                              bool flat, bool not_flat, bool not_null_free, bool atomic) {
2406   if (UseCompressedOops && elem->isa_oopptr()) {
2407     elem = elem->make_narrowoop();
2408   }
2409   size = normalize_array_size(size);
2410   return (TypeAry*)(new TypeAry(elem, size, stable, flat, not_flat, not_null_free, atomic))->hashcons();
2411 }
2412 
2413 //------------------------------meet-------------------------------------------
2414 // Compute the MEET of two types.  It returns a new Type object.
2415 const Type *TypeAry::xmeet( const Type *t ) const {
2416   // Perform a fast test for common case; meeting the same types together.
2417   if( this == t ) return this;  // Meeting same type-rep?
2418 
2419   // Current "this->_base" is Ary
2420   switch (t->base()) {          // switch on original type
2421 
2422   case Bottom:                  // Ye Olde Default
2423     return t;
2424 
2425   default:                      // All else is a mistake
2426     typerr(t);
2427 
2428   case Array: {                 // Meeting 2 arrays?
2429     const TypeAry* a = t->is_ary();
2430     const Type* size = _size->xmeet(a->_size);
2431     const TypeInt* isize = size->isa_int();
2432     if (isize == nullptr) {
2433       assert(size == Type::TOP || size == Type::BOTTOM, "");
2434       return size;
2435     }
2436     return TypeAry::make(_elem->meet_speculative(a->_elem),
2437                          isize, _stable && a->_stable,
2438                          _flat && a->_flat,
2439                          _not_flat && a->_not_flat,
2440                          _not_null_free && a->_not_null_free,
2441                          _atomic && a->_atomic);
2442   }
2443   case Top:
2444     break;
2445   }
2446   return this;                  // Return the double constant
2447 }
2448 
2449 //------------------------------xdual------------------------------------------
2450 // Dual: compute field-by-field dual
2451 const Type *TypeAry::xdual() const {
2452   const TypeInt* size_dual = _size->dual()->is_int();
2453   size_dual = normalize_array_size(size_dual);
2454   return new TypeAry(_elem->dual(), size_dual, !_stable, !_flat, !_not_flat, !_not_null_free, !_atomic);
2455 }
2456 
2457 //------------------------------eq---------------------------------------------
2458 // Structural equality check for Type representations
2459 bool TypeAry::eq( const Type *t ) const {
2460   const TypeAry *a = (const TypeAry*)t;
2461   return _elem == a->_elem &&
2462     _stable == a->_stable &&
2463     _size == a->_size &&
2464     _flat == a->_flat &&
2465     _not_flat == a->_not_flat &&
2466     _not_null_free == a->_not_null_free &&
2467     _atomic == a->_atomic;
2468 
2469 }
2470 
2471 //------------------------------hash-------------------------------------------
2472 // Type-specific hashing function.
2473 uint TypeAry::hash(void) const {
2474   return (uint)(uintptr_t)_elem + (uint)(uintptr_t)_size + (uint)(_stable ? 43 : 0) +
2475       (uint)(_flat ? 44 : 0) + (uint)(_not_flat ? 45 : 0) + (uint)(_not_null_free ? 46 : 0) + (uint)(_atomic ? 47 : 0);
2476 }
2477 
2478 /**
2479  * Return same type without a speculative part in the element
2480  */
2481 const TypeAry* TypeAry::remove_speculative() const {
2482   return make(_elem->remove_speculative(), _size, _stable, _flat, _not_flat, _not_null_free, _atomic);
2483 }
2484 
2485 /**
2486  * Return same type with cleaned up speculative part of element
2487  */
2488 const Type* TypeAry::cleanup_speculative() const {
2489   return make(_elem->cleanup_speculative(), _size, _stable, _flat, _not_flat, _not_null_free, _atomic);
2490 }
2491 
2492 /**
2493  * Return same type but with a different inline depth (used for speculation)
2494  *
2495  * @param depth  depth to meet with
2496  */
2497 const TypePtr* TypePtr::with_inline_depth(int depth) const {
2498   if (!UseInlineDepthForSpeculativeTypes) {
2499     return this;
2500   }
2501   return make(AnyPtr, _ptr, _offset, _speculative, depth);
2502 }
2503 
2504 //------------------------------dump2------------------------------------------
2505 #ifndef PRODUCT
2506 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2507   if (_stable)  st->print("stable:");
2508   if (_flat) st->print("flat:");
2509   if (Verbose) {
2510     if (_not_flat) st->print("not flat:");
2511     if (_not_null_free) st->print("not null free:");
2512   }
2513   if (_atomic) st->print("atomic:");
2514   _elem->dump2(d, depth, st);
2515   st->print("[");
2516   _size->dump2(d, depth, st);
2517   st->print("]");
2518 }
2519 #endif
2520 
2521 //------------------------------singleton--------------------------------------
2522 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2523 // constants (Ldi nodes).  Singletons are integer, float or double constants
2524 // or a single symbol.
2525 bool TypeAry::singleton(void) const {
2526   return false;                 // Never a singleton
2527 }
2528 
2529 bool TypeAry::empty(void) const {
2530   return _elem->empty() || _size->empty();
2531 }
2532 
2533 //--------------------------ary_must_be_exact----------------------------------
2534 bool TypeAry::ary_must_be_exact() const {
2535   // This logic looks at the element type of an array, and returns true
2536   // if the element type is either a primitive or a final instance class.
2537   // In such cases, an array built on this ary must have no subclasses.
2538   if (_elem == BOTTOM)      return false;  // general array not exact
2539   if (_elem == TOP   )      return false;  // inverted general array not exact
2540   const TypeOopPtr*  toop = nullptr;
2541   if (UseCompressedOops && _elem->isa_narrowoop()) {
2542     toop = _elem->make_ptr()->isa_oopptr();
2543   } else {
2544     toop = _elem->isa_oopptr();
2545   }
2546   if (!toop)                return true;   // a primitive type, like int
2547   if (!toop->is_loaded())   return false;  // unloaded class
2548   const TypeInstPtr* tinst;
2549   if (_elem->isa_narrowoop())
2550     tinst = _elem->make_ptr()->isa_instptr();
2551   else
2552     tinst = _elem->isa_instptr();
2553   if (tinst) {
2554     if (tinst->instance_klass()->is_final()) {
2555       // Even though MyValue is final, [LMyValue is only exact if the array
2556       // is (not) null-free due to null-free [LMyValue <: null-able [LMyValue.
2557       // TODO 8350865 If we know that the array can't be null-free, it's allowed to be exact, right?
2558       // If so, we should add '&& !_not_null_free'
2559       if (tinst->is_inlinetypeptr() && (tinst->ptr() != TypePtr::NotNull)) {
2560         return false;
2561       }
2562       return true;
2563     }
2564     return false;
2565   }
2566   const TypeAryPtr*  tap;
2567   if (_elem->isa_narrowoop())
2568     tap = _elem->make_ptr()->isa_aryptr();
2569   else
2570     tap = _elem->isa_aryptr();
2571   if (tap)
2572     return tap->ary()->ary_must_be_exact();
2573   return false;
2574 }
2575 
2576 //==============================TypeVect=======================================
2577 // Convenience common pre-built types.
2578 const TypeVect* TypeVect::VECTA = nullptr; // vector length agnostic
2579 const TypeVect* TypeVect::VECTS = nullptr; //  32-bit vectors
2580 const TypeVect* TypeVect::VECTD = nullptr; //  64-bit vectors
2581 const TypeVect* TypeVect::VECTX = nullptr; // 128-bit vectors
2582 const TypeVect* TypeVect::VECTY = nullptr; // 256-bit vectors
2583 const TypeVect* TypeVect::VECTZ = nullptr; // 512-bit vectors
2584 const TypeVect* TypeVect::VECTMASK = nullptr; // predicate/mask vector
2585 
2586 //------------------------------make-------------------------------------------
2587 const TypeVect* TypeVect::make(BasicType elem_bt, uint length, bool is_mask) {
2588   if (is_mask) {
2589     return makemask(elem_bt, length);
2590   }
2591   assert(is_java_primitive(elem_bt), "only primitive types in vector");
2592   assert(Matcher::vector_size_supported(elem_bt, length), "length in range");
2593   int size = length * type2aelembytes(elem_bt);
2594   switch (Matcher::vector_ideal_reg(size)) {
2595   case Op_VecA:
2596     return (TypeVect*)(new TypeVectA(elem_bt, length))->hashcons();
2597   case Op_VecS:
2598     return (TypeVect*)(new TypeVectS(elem_bt, length))->hashcons();
2599   case Op_RegL:
2600   case Op_VecD:
2601   case Op_RegD:
2602     return (TypeVect*)(new TypeVectD(elem_bt, length))->hashcons();
2603   case Op_VecX:
2604     return (TypeVect*)(new TypeVectX(elem_bt, length))->hashcons();
2605   case Op_VecY:
2606     return (TypeVect*)(new TypeVectY(elem_bt, length))->hashcons();
2607   case Op_VecZ:
2608     return (TypeVect*)(new TypeVectZ(elem_bt, length))->hashcons();
2609   }
2610  ShouldNotReachHere();
2611   return nullptr;
2612 }
2613 
2614 const TypeVect* TypeVect::makemask(BasicType elem_bt, uint length) {
2615   if (Matcher::has_predicated_vectors() &&
2616       Matcher::match_rule_supported_vector_masked(Op_VectorLoadMask, length, elem_bt)) {
2617     return TypeVectMask::make(elem_bt, length);
2618   } else {
2619     return make(elem_bt, length);
2620   }
2621 }
2622 
2623 //------------------------------meet-------------------------------------------
2624 // Compute the MEET of two types. Since each TypeVect is the only instance of
2625 // its species, meeting often returns itself
2626 const Type* TypeVect::xmeet(const Type* t) const {
2627   // Perform a fast test for common case; meeting the same types together.
2628   if (this == t) {
2629     return this;
2630   }
2631 
2632   // Current "this->_base" is Vector
2633   switch (t->base()) {          // switch on original type
2634 
2635   case Bottom:                  // Ye Olde Default
2636     return t;
2637 
2638   default:                      // All else is a mistake
2639     typerr(t);
2640   case VectorMask:
2641   case VectorA:
2642   case VectorS:
2643   case VectorD:
2644   case VectorX:
2645   case VectorY:
2646   case VectorZ: {                // Meeting 2 vectors?
2647     const TypeVect* v = t->is_vect();
2648     assert(base() == v->base(), "");
2649     assert(length() == v->length(), "");
2650     assert(element_basic_type() == v->element_basic_type(), "");
2651     return this;
2652   }
2653   case Top:
2654     break;
2655   }
2656   return this;
2657 }
2658 
2659 //------------------------------xdual------------------------------------------
2660 // Since each TypeVect is the only instance of its species, it is self-dual
2661 const Type* TypeVect::xdual() const {
2662   return this;
2663 }
2664 
2665 //------------------------------eq---------------------------------------------
2666 // Structural equality check for Type representations
2667 bool TypeVect::eq(const Type* t) const {
2668   const TypeVect* v = t->is_vect();
2669   return (element_basic_type() == v->element_basic_type()) && (length() == v->length());
2670 }
2671 
2672 //------------------------------hash-------------------------------------------
2673 // Type-specific hashing function.
2674 uint TypeVect::hash(void) const {
2675   return (uint)base() + (uint)(uintptr_t)_elem_bt + (uint)(uintptr_t)_length;
2676 }
2677 
2678 //------------------------------singleton--------------------------------------
2679 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2680 // constants (Ldi nodes).  Vector is singleton if all elements are the same
2681 // constant value (when vector is created with Replicate code).
2682 bool TypeVect::singleton(void) const {
2683 // There is no Con node for vectors yet.
2684 //  return _elem->singleton();
2685   return false;
2686 }
2687 
2688 bool TypeVect::empty(void) const {
2689   return false;
2690 }
2691 
2692 //------------------------------dump2------------------------------------------
2693 #ifndef PRODUCT
2694 void TypeVect::dump2(Dict& d, uint depth, outputStream* st) const {
2695   switch (base()) {
2696   case VectorA:
2697     st->print("vectora"); break;
2698   case VectorS:
2699     st->print("vectors"); break;
2700   case VectorD:
2701     st->print("vectord"); break;
2702   case VectorX:
2703     st->print("vectorx"); break;
2704   case VectorY:
2705     st->print("vectory"); break;
2706   case VectorZ:
2707     st->print("vectorz"); break;
2708   case VectorMask:
2709     st->print("vectormask"); break;
2710   default:
2711     ShouldNotReachHere();
2712   }
2713   st->print("<%c,%u>", type2char(element_basic_type()), length());
2714 }
2715 #endif
2716 
2717 const TypeVectMask* TypeVectMask::make(const BasicType elem_bt, uint length) {
2718   return (TypeVectMask*) (new TypeVectMask(elem_bt, length))->hashcons();
2719 }
2720 
2721 //=============================================================================
2722 // Convenience common pre-built types.
2723 const TypePtr *TypePtr::NULL_PTR;
2724 const TypePtr *TypePtr::NOTNULL;
2725 const TypePtr *TypePtr::BOTTOM;
2726 
2727 //------------------------------meet-------------------------------------------
2728 // Meet over the PTR enum
2729 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2730   //              TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,
2731   { /* Top     */ TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,},
2732   { /* AnyNull */ AnyNull,   AnyNull,   Constant, BotPTR, NotNull, BotPTR,},
2733   { /* Constant*/ Constant,  Constant,  Constant, BotPTR, NotNull, BotPTR,},
2734   { /* Null    */ Null,      BotPTR,    BotPTR,   Null,   BotPTR,  BotPTR,},
2735   { /* NotNull */ NotNull,   NotNull,   NotNull,  BotPTR, NotNull, BotPTR,},
2736   { /* BotPTR  */ BotPTR,    BotPTR,    BotPTR,   BotPTR, BotPTR,  BotPTR,}
2737 };
2738 
2739 //------------------------------make-------------------------------------------
2740 const TypePtr* TypePtr::make(TYPES t, enum PTR ptr, Offset offset, const TypePtr* speculative, int inline_depth) {
2741   return (TypePtr*)(new TypePtr(t,ptr,offset, speculative, inline_depth))->hashcons();
2742 }
2743 
2744 //------------------------------cast_to_ptr_type-------------------------------
2745 const TypePtr* TypePtr::cast_to_ptr_type(PTR ptr) const {
2746   assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2747   if( ptr == _ptr ) return this;
2748   return make(_base, ptr, _offset, _speculative, _inline_depth);
2749 }
2750 
2751 //------------------------------get_con----------------------------------------
2752 intptr_t TypePtr::get_con() const {
2753   assert( _ptr == Null, "" );
2754   return offset();
2755 }
2756 
2757 //------------------------------meet-------------------------------------------
2758 // Compute the MEET of two types.  It returns a new Type object.
2759 const Type *TypePtr::xmeet(const Type *t) const {
2760   const Type* res = xmeet_helper(t);
2761   if (res->isa_ptr() == nullptr) {
2762     return res;
2763   }
2764 
2765   const TypePtr* res_ptr = res->is_ptr();
2766   if (res_ptr->speculative() != nullptr) {
2767     // type->speculative() is null means that speculation is no better
2768     // than type, i.e. type->speculative() == type. So there are 2
2769     // ways to represent the fact that we have no useful speculative
2770     // data and we should use a single one to be able to test for
2771     // equality between types. Check whether type->speculative() ==
2772     // type and set speculative to null if it is the case.
2773     if (res_ptr->remove_speculative() == res_ptr->speculative()) {
2774       return res_ptr->remove_speculative();
2775     }
2776   }
2777 
2778   return res;
2779 }
2780 
2781 const Type *TypePtr::xmeet_helper(const Type *t) const {
2782   // Perform a fast test for common case; meeting the same types together.
2783   if( this == t ) return this;  // Meeting same type-rep?
2784 
2785   // Current "this->_base" is AnyPtr
2786   switch (t->base()) {          // switch on original type
2787   case Int:                     // Mixing ints & oops happens when javac
2788   case Long:                    // reuses local variables
2789   case HalfFloatTop:
2790   case HalfFloatCon:
2791   case HalfFloatBot:
2792   case FloatTop:
2793   case FloatCon:
2794   case FloatBot:
2795   case DoubleTop:
2796   case DoubleCon:
2797   case DoubleBot:
2798   case NarrowOop:
2799   case NarrowKlass:
2800   case Bottom:                  // Ye Olde Default
2801     return Type::BOTTOM;
2802   case Top:
2803     return this;
2804 
2805   case AnyPtr: {                // Meeting to AnyPtrs
2806     const TypePtr *tp = t->is_ptr();
2807     const TypePtr* speculative = xmeet_speculative(tp);
2808     int depth = meet_inline_depth(tp->inline_depth());
2809     return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2810   }
2811   case RawPtr:                  // For these, flip the call around to cut down
2812   case OopPtr:
2813   case InstPtr:                 // on the cases I have to handle.
2814   case AryPtr:
2815   case MetadataPtr:
2816   case KlassPtr:
2817   case InstKlassPtr:
2818   case AryKlassPtr:
2819     return t->xmeet(this);      // Call in reverse direction
2820   default:                      // All else is a mistake
2821     typerr(t);
2822 
2823   }
2824   return this;
2825 }
2826 
2827 //------------------------------meet_offset------------------------------------
2828 Type::Offset TypePtr::meet_offset(int offset) const {
2829   return _offset.meet(Offset(offset));





2830 }
2831 
2832 //------------------------------dual_offset------------------------------------
2833 Type::Offset TypePtr::dual_offset() const {
2834   return _offset.dual();


2835 }
2836 
2837 //------------------------------xdual------------------------------------------
2838 // Dual: compute field-by-field dual
2839 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2840   BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2841 };
2842 
2843 const TypePtr::FlatInArray TypePtr::flat_in_array_dual[Uninitialized] = {
2844   /* TopFlat   -> */ MaybeFlat,
2845   /* Flat      -> */ NotFlat,
2846   /* NotFlat   -> */ Flat,
2847   /* MaybeFlat -> */ TopFlat
2848 };
2849 
2850 const char* const TypePtr::flat_in_array_msg[Uninitialized] = {
2851   "TOP flat in array", "flat in array", "not flat in array", "maybe flat in array"
2852 };
2853 
2854 const Type *TypePtr::xdual() const {
2855   return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
2856 }
2857 
2858 //------------------------------xadd_offset------------------------------------
2859 Type::Offset TypePtr::xadd_offset(intptr_t offset) const {
2860   return _offset.add(offset);











2861 }
2862 
2863 //------------------------------add_offset-------------------------------------
2864 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2865   return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth);
2866 }
2867 
2868 const TypePtr *TypePtr::with_offset(intptr_t offset) const {
2869   return make(AnyPtr, _ptr, Offset(offset), _speculative, _inline_depth);
2870 }
2871 
2872 //------------------------------eq---------------------------------------------
2873 // Structural equality check for Type representations
2874 bool TypePtr::eq( const Type *t ) const {
2875   const TypePtr *a = (const TypePtr*)t;
2876   return _ptr == a->ptr() && _offset == a->_offset && eq_speculative(a) && _inline_depth == a->_inline_depth;
2877 }
2878 
2879 //------------------------------hash-------------------------------------------
2880 // Type-specific hashing function.
2881 uint TypePtr::hash(void) const {
2882   return (uint)_ptr + (uint)offset() + (uint)hash_speculative() + (uint)_inline_depth;
2883 }
2884 
2885 /**
2886  * Return same type without a speculative part
2887  */
2888 const TypePtr* TypePtr::remove_speculative() const {
2889   if (_speculative == nullptr) {
2890     return this;
2891   }
2892   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2893   return make(AnyPtr, _ptr, _offset, nullptr, _inline_depth);
2894 }
2895 
2896 /**
2897  * Return same type but drop speculative part if we know we won't use
2898  * it
2899  */
2900 const Type* TypePtr::cleanup_speculative() const {
2901   if (speculative() == nullptr) {
2902     return this;
2903   }
2904   const Type* no_spec = remove_speculative();
2905   // If this is NULL_PTR then we don't need the speculative type
2906   // (with_inline_depth in case the current type inline depth is
2907   // InlineDepthTop)
2908   if (no_spec == NULL_PTR->with_inline_depth(inline_depth())) {
2909     return no_spec;
2910   }
2911   if (above_centerline(speculative()->ptr())) {
2912     return no_spec;
2913   }
2914   const TypeOopPtr* spec_oopptr = speculative()->isa_oopptr();
2915   // If the speculative may be null and is an inexact klass then it
2916   // doesn't help
2917   if (speculative() != TypePtr::NULL_PTR && speculative()->maybe_null() &&
2918       (spec_oopptr == nullptr || !spec_oopptr->klass_is_exact())) {
2919     return no_spec;
2920   }
2921   return this;
2922 }
2923 
2924 /**
2925  * dual of the speculative part of the type
2926  */
2927 const TypePtr* TypePtr::dual_speculative() const {
2928   if (_speculative == nullptr) {
2929     return nullptr;
2930   }
2931   return _speculative->dual()->is_ptr();
2932 }
2933 
2934 /**
2935  * meet of the speculative parts of 2 types
2936  *
2937  * @param other  type to meet with
2938  */
2939 const TypePtr* TypePtr::xmeet_speculative(const TypePtr* other) const {
2940   bool this_has_spec = (_speculative != nullptr);
2941   bool other_has_spec = (other->speculative() != nullptr);
2942 
2943   if (!this_has_spec && !other_has_spec) {
2944     return nullptr;
2945   }
2946 
2947   // If we are at a point where control flow meets and one branch has
2948   // a speculative type and the other has not, we meet the speculative
2949   // type of one branch with the actual type of the other. If the
2950   // actual type is exact and the speculative is as well, then the
2951   // result is a speculative type which is exact and we can continue
2952   // speculation further.
2953   const TypePtr* this_spec = _speculative;
2954   const TypePtr* other_spec = other->speculative();
2955 
2956   if (!this_has_spec) {
2957     this_spec = this;
2958   }
2959 
2960   if (!other_has_spec) {
2961     other_spec = other;
2962   }
2963 
2964   return this_spec->meet(other_spec)->is_ptr();
2965 }
2966 
2967 /**
2968  * dual of the inline depth for this type (used for speculation)
2969  */
2970 int TypePtr::dual_inline_depth() const {
2971   return -inline_depth();
2972 }
2973 
2974 /**
2975  * meet of 2 inline depths (used for speculation)
2976  *
2977  * @param depth  depth to meet with
2978  */
2979 int TypePtr::meet_inline_depth(int depth) const {
2980   return MAX2(inline_depth(), depth);
2981 }
2982 
2983 /**
2984  * Are the speculative parts of 2 types equal?
2985  *
2986  * @param other  type to compare this one to
2987  */
2988 bool TypePtr::eq_speculative(const TypePtr* other) const {
2989   if (_speculative == nullptr || other->speculative() == nullptr) {
2990     return _speculative == other->speculative();
2991   }
2992 
2993   if (_speculative->base() != other->speculative()->base()) {
2994     return false;
2995   }
2996 
2997   return _speculative->eq(other->speculative());
2998 }
2999 
3000 /**
3001  * Hash of the speculative part of the type
3002  */
3003 int TypePtr::hash_speculative() const {
3004   if (_speculative == nullptr) {
3005     return 0;
3006   }
3007 
3008   return _speculative->hash();
3009 }
3010 
3011 /**
3012  * add offset to the speculative part of the type
3013  *
3014  * @param offset  offset to add
3015  */
3016 const TypePtr* TypePtr::add_offset_speculative(intptr_t offset) const {
3017   if (_speculative == nullptr) {
3018     return nullptr;
3019   }
3020   return _speculative->add_offset(offset)->is_ptr();
3021 }
3022 
3023 const TypePtr* TypePtr::with_offset_speculative(intptr_t offset) const {
3024   if (_speculative == nullptr) {
3025     return nullptr;
3026   }
3027   return _speculative->with_offset(offset)->is_ptr();
3028 }
3029 
3030 /**
3031  * return exact klass from the speculative type if there's one
3032  */
3033 ciKlass* TypePtr::speculative_type() const {
3034   if (_speculative != nullptr && _speculative->isa_oopptr()) {
3035     const TypeOopPtr* speculative = _speculative->join(this)->is_oopptr();
3036     if (speculative->klass_is_exact()) {
3037       return speculative->exact_klass();
3038     }
3039   }
3040   return nullptr;
3041 }
3042 
3043 /**
3044  * return true if speculative type may be null
3045  */
3046 bool TypePtr::speculative_maybe_null() const {
3047   if (_speculative != nullptr) {
3048     const TypePtr* speculative = _speculative->join(this)->is_ptr();
3049     return speculative->maybe_null();
3050   }
3051   return true;
3052 }
3053 
3054 bool TypePtr::speculative_always_null() const {
3055   if (_speculative != nullptr) {
3056     const TypePtr* speculative = _speculative->join(this)->is_ptr();
3057     return speculative == TypePtr::NULL_PTR;
3058   }
3059   return false;
3060 }
3061 
3062 /**
3063  * Same as TypePtr::speculative_type() but return the klass only if
3064  * the speculative tells us is not null
3065  */
3066 ciKlass* TypePtr::speculative_type_not_null() const {
3067   if (speculative_maybe_null()) {
3068     return nullptr;
3069   }
3070   return speculative_type();
3071 }
3072 
3073 /**
3074  * Check whether new profiling would improve speculative type
3075  *
3076  * @param   exact_kls    class from profiling
3077  * @param   inline_depth inlining depth of profile point
3078  *
3079  * @return  true if type profile is valuable
3080  */
3081 bool TypePtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
3082   // no profiling?
3083   if (exact_kls == nullptr) {
3084     return false;
3085   }
3086   if (speculative() == TypePtr::NULL_PTR) {
3087     return false;
3088   }
3089   // no speculative type or non exact speculative type?
3090   if (speculative_type() == nullptr) {
3091     return true;
3092   }
3093   // If the node already has an exact speculative type keep it,
3094   // unless it was provided by profiling that is at a deeper
3095   // inlining level. Profiling at a higher inlining depth is
3096   // expected to be less accurate.
3097   if (_speculative->inline_depth() == InlineDepthBottom) {
3098     return false;
3099   }
3100   assert(_speculative->inline_depth() != InlineDepthTop, "can't do the comparison");
3101   return inline_depth < _speculative->inline_depth();
3102 }
3103 
3104 /**
3105  * Check whether new profiling would improve ptr (= tells us it is non
3106  * null)
3107  *
3108  * @param   ptr_kind always null or not null?
3109  *
3110  * @return  true if ptr profile is valuable
3111  */
3112 bool TypePtr::would_improve_ptr(ProfilePtrKind ptr_kind) const {
3113   // profiling doesn't tell us anything useful
3114   if (ptr_kind != ProfileAlwaysNull && ptr_kind != ProfileNeverNull) {
3115     return false;
3116   }
3117   // We already know this is not null
3118   if (!this->maybe_null()) {
3119     return false;
3120   }
3121   // We already know the speculative type cannot be null
3122   if (!speculative_maybe_null()) {
3123     return false;
3124   }
3125   // We already know this is always null
3126   if (this == TypePtr::NULL_PTR) {
3127     return false;
3128   }
3129   // We already know the speculative type is always null
3130   if (speculative_always_null()) {
3131     return false;
3132   }
3133   if (ptr_kind == ProfileAlwaysNull && speculative() != nullptr && speculative()->isa_oopptr()) {
3134     return false;
3135   }
3136   return true;
3137 }
3138 
3139 TypePtr::FlatInArray TypePtr::compute_flat_in_array(ciInstanceKlass* instance_klass, bool is_exact) {
3140   if (!instance_klass->can_be_inline_klass(is_exact)) {
3141     // Definitely not a value class and thus never flat in an array.
3142     return NotFlat;
3143   }
3144   if (instance_klass->is_inlinetype() && instance_klass->as_inline_klass()->is_always_flat_in_array()) {
3145     return Flat;
3146   }
3147   // We don't know.
3148   return MaybeFlat;
3149 }
3150 
3151 // Compute flat in array property if we don't know anything about it (i.e. old_flat_in_array == MaybeFlat).
3152 TypePtr::FlatInArray TypePtr::compute_flat_in_array_if_unknown(ciInstanceKlass* instance_klass, bool is_exact,
3153   FlatInArray old_flat_in_array) const {
3154   switch (old_flat_in_array) {
3155     case Flat:
3156       assert(can_be_inline_type(), "only value objects can be flat in array");
3157       assert(!instance_klass->is_inlinetype() || instance_klass->as_inline_klass()->is_always_flat_in_array(),
3158              "a value object is only marked flat in array if it's proven to be always flat in array");
3159       break;
3160     case NotFlat:
3161       assert(!instance_klass->maybe_flat_in_array(), "cannot be flat");
3162       break;
3163     case MaybeFlat:
3164       return compute_flat_in_array(instance_klass, is_exact);
3165       break;
3166     default:
3167       break;
3168   }
3169   return old_flat_in_array;
3170 }
3171 
3172 //------------------------------dump2------------------------------------------
3173 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
3174   "TopPTR","AnyNull","Constant","null","NotNull","BotPTR"
3175 };
3176 
3177 #ifndef PRODUCT
3178 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3179   st->print("ptr:%s", ptr_msg[_ptr]);
3180   dump_offset(st);
3181   dump_inline_depth(st);
3182   dump_speculative(st);
3183 }
3184 
3185 void TypePtr::dump_offset(outputStream* st) const {
3186   _offset.dump2(st);






3187 }
3188 
3189 /**
3190  *dump the speculative part of the type
3191  */
3192 void TypePtr::dump_speculative(outputStream *st) const {
3193   if (_speculative != nullptr) {
3194     st->print(" (speculative=");
3195     _speculative->dump_on(st);
3196     st->print(")");
3197   }
3198 }
3199 
3200 /**
3201  *dump the inline depth of the type
3202  */
3203 void TypePtr::dump_inline_depth(outputStream *st) const {
3204   if (_inline_depth != InlineDepthBottom) {
3205     if (_inline_depth == InlineDepthTop) {
3206       st->print(" (inline_depth=InlineDepthTop)");
3207     } else {
3208       st->print(" (inline_depth=%d)", _inline_depth);
3209     }
3210   }
3211 }
3212 
3213 void TypePtr::dump_flat_in_array(FlatInArray flat_in_array, outputStream* st) {
3214   switch (flat_in_array) {
3215     case MaybeFlat:
3216     case NotFlat:
3217       if (!Verbose) {
3218         break;
3219       }
3220     case TopFlat:
3221     case Flat:
3222       st->print(" (%s)", flat_in_array_msg[flat_in_array]);
3223       break;
3224     default:
3225       ShouldNotReachHere();
3226   }
3227 }
3228 #endif
3229 
3230 //------------------------------singleton--------------------------------------
3231 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3232 // constants
3233 bool TypePtr::singleton(void) const {
3234   // TopPTR, Null, AnyNull, Constant are all singletons
3235   return (_offset != Offset::bottom) && !below_centerline(_ptr);
3236 }
3237 
3238 bool TypePtr::empty(void) const {
3239   return (_offset == Offset::top) || above_centerline(_ptr);
3240 }
3241 
3242 //=============================================================================
3243 // Convenience common pre-built types.
3244 const TypeRawPtr *TypeRawPtr::BOTTOM;
3245 const TypeRawPtr *TypeRawPtr::NOTNULL;
3246 
3247 //------------------------------make-------------------------------------------
3248 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
3249   assert( ptr != Constant, "what is the constant?" );
3250   assert( ptr != Null, "Use TypePtr for null" );
3251   return (TypeRawPtr*)(new TypeRawPtr(ptr,nullptr))->hashcons();
3252 }
3253 
3254 const TypeRawPtr *TypeRawPtr::make(address bits) {
3255   assert(bits != nullptr, "Use TypePtr for null");
3256   return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
3257 }
3258 
3259 //------------------------------cast_to_ptr_type-------------------------------
3260 const TypeRawPtr* TypeRawPtr::cast_to_ptr_type(PTR ptr) const {
3261   assert( ptr != Constant, "what is the constant?" );
3262   assert( ptr != Null, "Use TypePtr for null" );
3263   assert( _bits == nullptr, "Why cast a constant address?");
3264   if( ptr == _ptr ) return this;
3265   return make(ptr);
3266 }
3267 
3268 //------------------------------get_con----------------------------------------
3269 intptr_t TypeRawPtr::get_con() const {
3270   assert( _ptr == Null || _ptr == Constant, "" );
3271   return (intptr_t)_bits;
3272 }
3273 
3274 //------------------------------meet-------------------------------------------
3275 // Compute the MEET of two types.  It returns a new Type object.
3276 const Type *TypeRawPtr::xmeet( const Type *t ) const {
3277   // Perform a fast test for common case; meeting the same types together.
3278   if( this == t ) return this;  // Meeting same type-rep?
3279 
3280   // Current "this->_base" is RawPtr
3281   switch( t->base() ) {         // switch on original type
3282   case Bottom:                  // Ye Olde Default
3283     return t;
3284   case Top:
3285     return this;
3286   case AnyPtr:                  // Meeting to AnyPtrs
3287     break;
3288   case RawPtr: {                // might be top, bot, any/not or constant
3289     enum PTR tptr = t->is_ptr()->ptr();
3290     enum PTR ptr = meet_ptr( tptr );
3291     if( ptr == Constant ) {     // Cannot be equal constants, so...
3292       if( tptr == Constant && _ptr != Constant)  return t;
3293       if( _ptr == Constant && tptr != Constant)  return this;
3294       ptr = NotNull;            // Fall down in lattice
3295     }
3296     return make( ptr );
3297   }
3298 
3299   case OopPtr:
3300   case InstPtr:
3301   case AryPtr:
3302   case MetadataPtr:
3303   case KlassPtr:
3304   case InstKlassPtr:
3305   case AryKlassPtr:
3306     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3307   default:                      // All else is a mistake
3308     typerr(t);
3309   }
3310 
3311   // Found an AnyPtr type vs self-RawPtr type
3312   const TypePtr *tp = t->is_ptr();
3313   switch (tp->ptr()) {
3314   case TypePtr::TopPTR:  return this;
3315   case TypePtr::BotPTR:  return t;
3316   case TypePtr::Null:
3317     if( _ptr == TypePtr::TopPTR ) return t;
3318     return TypeRawPtr::BOTTOM;
3319   case TypePtr::NotNull: return TypePtr::make(AnyPtr, meet_ptr(TypePtr::NotNull), tp->meet_offset(0), tp->speculative(), tp->inline_depth());
3320   case TypePtr::AnyNull:
3321     if( _ptr == TypePtr::Constant) return this;
3322     return make( meet_ptr(TypePtr::AnyNull) );
3323   default: ShouldNotReachHere();
3324   }
3325   return this;
3326 }
3327 
3328 //------------------------------xdual------------------------------------------
3329 // Dual: compute field-by-field dual
3330 const Type *TypeRawPtr::xdual() const {
3331   return new TypeRawPtr( dual_ptr(), _bits );
3332 }
3333 
3334 //------------------------------add_offset-------------------------------------
3335 const TypePtr* TypeRawPtr::add_offset(intptr_t offset) const {
3336   if( offset == OffsetTop ) return BOTTOM; // Undefined offset-> undefined pointer
3337   if( offset == OffsetBot ) return BOTTOM; // Unknown offset-> unknown pointer
3338   if( offset == 0 ) return this; // No change
3339   switch (_ptr) {
3340   case TypePtr::TopPTR:
3341   case TypePtr::BotPTR:
3342   case TypePtr::NotNull:
3343     return this;
3344   case TypePtr::Constant: {
3345     uintptr_t bits = (uintptr_t)_bits;
3346     uintptr_t sum = bits + offset;
3347     if (( offset < 0 )
3348         ? ( sum > bits )        // Underflow?
3349         : ( sum < bits )) {     // Overflow?
3350       return BOTTOM;
3351     } else if ( sum == 0 ) {
3352       return TypePtr::NULL_PTR;
3353     } else {
3354       return make( (address)sum );
3355     }
3356   }
3357   default:  ShouldNotReachHere();
3358   }
3359 }
3360 
3361 //------------------------------eq---------------------------------------------
3362 // Structural equality check for Type representations
3363 bool TypeRawPtr::eq( const Type *t ) const {
3364   const TypeRawPtr *a = (const TypeRawPtr*)t;
3365   return _bits == a->_bits && TypePtr::eq(t);
3366 }
3367 
3368 //------------------------------hash-------------------------------------------
3369 // Type-specific hashing function.
3370 uint TypeRawPtr::hash(void) const {
3371   return (uint)(uintptr_t)_bits + (uint)TypePtr::hash();
3372 }
3373 
3374 //------------------------------dump2------------------------------------------
3375 #ifndef PRODUCT
3376 void TypeRawPtr::dump2(Dict& d, uint depth, outputStream* st) const {
3377   if (_ptr == Constant) {
3378     st->print("rawptr:Constant:" INTPTR_FORMAT, p2i(_bits));
3379   } else {
3380     st->print("rawptr:%s", ptr_msg[_ptr]);
3381   }
3382 }
3383 #endif
3384 
3385 //=============================================================================
3386 // Convenience common pre-built type.
3387 const TypeOopPtr *TypeOopPtr::BOTTOM;
3388 
3389 TypeInterfaces::TypeInterfaces(ciInstanceKlass** interfaces_base, int nb_interfaces)
3390         : Type(Interfaces), _interfaces(interfaces_base, nb_interfaces),
3391           _hash(0), _exact_klass(nullptr) {
3392   _interfaces.sort(compare);
3393   initialize();
3394 }
3395 
3396 const TypeInterfaces* TypeInterfaces::make(GrowableArray<ciInstanceKlass*>* interfaces) {
3397   // hashcons() can only delete the last thing that was allocated: to
3398   // make sure all memory for the newly created TypeInterfaces can be
3399   // freed if an identical one exists, allocate space for the array of
3400   // interfaces right after the TypeInterfaces object so that they
3401   // form a contiguous piece of memory.
3402   int nb_interfaces = interfaces == nullptr ? 0 : interfaces->length();
3403   size_t total_size = sizeof(TypeInterfaces) + nb_interfaces * sizeof(ciInstanceKlass*);
3404 
3405   void* allocated_mem = operator new(total_size);
3406   ciInstanceKlass** interfaces_base = (ciInstanceKlass**)((char*)allocated_mem + sizeof(TypeInterfaces));
3407   for (int i = 0; i < nb_interfaces; ++i) {
3408     interfaces_base[i] = interfaces->at(i);
3409   }
3410   TypeInterfaces* result = ::new (allocated_mem) TypeInterfaces(interfaces_base, nb_interfaces);
3411   return (const TypeInterfaces*)result->hashcons();
3412 }
3413 
3414 void TypeInterfaces::initialize() {
3415   compute_hash();
3416   compute_exact_klass();
3417   DEBUG_ONLY(_initialized = true;)
3418 }
3419 
3420 int TypeInterfaces::compare(ciInstanceKlass* const& k1, ciInstanceKlass* const& k2) {
3421   if ((intptr_t)k1 < (intptr_t)k2) {
3422     return -1;
3423   } else if ((intptr_t)k1 > (intptr_t)k2) {
3424     return 1;
3425   }
3426   return 0;
3427 }
3428 
3429 int TypeInterfaces::compare(ciInstanceKlass** k1, ciInstanceKlass** k2) {
3430   return compare(*k1, *k2);
3431 }
3432 
3433 bool TypeInterfaces::eq(const Type* t) const {
3434   const TypeInterfaces* other = (const TypeInterfaces*)t;
3435   if (_interfaces.length() != other->_interfaces.length()) {
3436     return false;
3437   }
3438   for (int i = 0; i < _interfaces.length(); i++) {
3439     ciKlass* k1 = _interfaces.at(i);
3440     ciKlass* k2 = other->_interfaces.at(i);
3441     if (!k1->equals(k2)) {
3442       return false;
3443     }
3444   }
3445   return true;
3446 }
3447 
3448 bool TypeInterfaces::eq(ciInstanceKlass* k) const {
3449   assert(k->is_loaded(), "should be loaded");
3450   GrowableArray<ciInstanceKlass *>* interfaces = k->transitive_interfaces();
3451   if (_interfaces.length() != interfaces->length()) {
3452     return false;
3453   }
3454   for (int i = 0; i < interfaces->length(); i++) {
3455     bool found = false;
3456     _interfaces.find_sorted<ciInstanceKlass*, compare>(interfaces->at(i), found);
3457     if (!found) {
3458       return false;
3459     }
3460   }
3461   return true;
3462 }
3463 
3464 
3465 uint TypeInterfaces::hash() const {
3466   assert(_initialized, "must be");
3467   return _hash;
3468 }
3469 
3470 const Type* TypeInterfaces::xdual() const {
3471   return this;
3472 }
3473 
3474 void TypeInterfaces::compute_hash() {
3475   uint hash = 0;
3476   for (int i = 0; i < _interfaces.length(); i++) {
3477     ciKlass* k = _interfaces.at(i);
3478     hash += k->hash();
3479   }
3480   _hash = hash;
3481 }
3482 
3483 static int compare_interfaces(ciInstanceKlass** k1, ciInstanceKlass** k2) {
3484   return (int)((*k1)->ident() - (*k2)->ident());
3485 }
3486 
3487 void TypeInterfaces::dump(outputStream* st) const {
3488   if (_interfaces.length() == 0) {
3489     return;
3490   }
3491   ResourceMark rm;
3492   st->print(" (");
3493   GrowableArray<ciInstanceKlass*> interfaces;
3494   interfaces.appendAll(&_interfaces);
3495   // Sort the interfaces so they are listed in the same order from one run to the other of the same compilation
3496   interfaces.sort(compare_interfaces);
3497   for (int i = 0; i < interfaces.length(); i++) {
3498     if (i > 0) {
3499       st->print(",");
3500     }
3501     ciKlass* k = interfaces.at(i);
3502     k->print_name_on(st);
3503   }
3504   st->print(")");
3505 }
3506 
3507 #ifdef ASSERT
3508 void TypeInterfaces::verify() const {
3509   for (int i = 1; i < _interfaces.length(); i++) {
3510     ciInstanceKlass* k1 = _interfaces.at(i-1);
3511     ciInstanceKlass* k2 = _interfaces.at(i);
3512     assert(compare(k2, k1) > 0, "should be ordered");
3513     assert(k1 != k2, "no duplicate");
3514   }
3515 }
3516 #endif
3517 
3518 const TypeInterfaces* TypeInterfaces::union_with(const TypeInterfaces* other) const {
3519   GrowableArray<ciInstanceKlass*> result_list;
3520   int i = 0;
3521   int j = 0;
3522   while (i < _interfaces.length() || j < other->_interfaces.length()) {
3523     while (i < _interfaces.length() &&
3524            (j >= other->_interfaces.length() ||
3525             compare(_interfaces.at(i), other->_interfaces.at(j)) < 0)) {
3526       result_list.push(_interfaces.at(i));
3527       i++;
3528     }
3529     while (j < other->_interfaces.length() &&
3530            (i >= _interfaces.length() ||
3531             compare(other->_interfaces.at(j), _interfaces.at(i)) < 0)) {
3532       result_list.push(other->_interfaces.at(j));
3533       j++;
3534     }
3535     if (i < _interfaces.length() &&
3536         j < other->_interfaces.length() &&
3537         _interfaces.at(i) == other->_interfaces.at(j)) {
3538       result_list.push(_interfaces.at(i));
3539       i++;
3540       j++;
3541     }
3542   }
3543   const TypeInterfaces* result = TypeInterfaces::make(&result_list);
3544 #ifdef ASSERT
3545   result->verify();
3546   for (int i = 0; i < _interfaces.length(); i++) {
3547     assert(result->_interfaces.contains(_interfaces.at(i)), "missing");
3548   }
3549   for (int i = 0; i < other->_interfaces.length(); i++) {
3550     assert(result->_interfaces.contains(other->_interfaces.at(i)), "missing");
3551   }
3552   for (int i = 0; i < result->_interfaces.length(); i++) {
3553     assert(_interfaces.contains(result->_interfaces.at(i)) || other->_interfaces.contains(result->_interfaces.at(i)), "missing");
3554   }
3555 #endif
3556   return result;
3557 }
3558 
3559 const TypeInterfaces* TypeInterfaces::intersection_with(const TypeInterfaces* other) const {
3560   GrowableArray<ciInstanceKlass*> result_list;
3561   int i = 0;
3562   int j = 0;
3563   while (i < _interfaces.length() || j < other->_interfaces.length()) {
3564     while (i < _interfaces.length() &&
3565            (j >= other->_interfaces.length() ||
3566             compare(_interfaces.at(i), other->_interfaces.at(j)) < 0)) {
3567       i++;
3568     }
3569     while (j < other->_interfaces.length() &&
3570            (i >= _interfaces.length() ||
3571             compare(other->_interfaces.at(j), _interfaces.at(i)) < 0)) {
3572       j++;
3573     }
3574     if (i < _interfaces.length() &&
3575         j < other->_interfaces.length() &&
3576         _interfaces.at(i) == other->_interfaces.at(j)) {
3577       result_list.push(_interfaces.at(i));
3578       i++;
3579       j++;
3580     }
3581   }
3582   const TypeInterfaces* result = TypeInterfaces::make(&result_list);
3583 #ifdef ASSERT
3584   result->verify();
3585   for (int i = 0; i < _interfaces.length(); i++) {
3586     assert(!other->_interfaces.contains(_interfaces.at(i)) || result->_interfaces.contains(_interfaces.at(i)), "missing");
3587   }
3588   for (int i = 0; i < other->_interfaces.length(); i++) {
3589     assert(!_interfaces.contains(other->_interfaces.at(i)) || result->_interfaces.contains(other->_interfaces.at(i)), "missing");
3590   }
3591   for (int i = 0; i < result->_interfaces.length(); i++) {
3592     assert(_interfaces.contains(result->_interfaces.at(i)) && other->_interfaces.contains(result->_interfaces.at(i)), "missing");
3593   }
3594 #endif
3595   return result;
3596 }
3597 
3598 // Is there a single ciKlass* that can represent the interface set?
3599 ciInstanceKlass* TypeInterfaces::exact_klass() const {
3600   assert(_initialized, "must be");
3601   return _exact_klass;
3602 }
3603 
3604 void TypeInterfaces::compute_exact_klass() {
3605   if (_interfaces.length() == 0) {
3606     _exact_klass = nullptr;
3607     return;
3608   }
3609   ciInstanceKlass* res = nullptr;
3610   for (int i = 0; i < _interfaces.length(); i++) {
3611     ciInstanceKlass* interface = _interfaces.at(i);
3612     if (eq(interface)) {
3613       assert(res == nullptr, "");
3614       res = interface;
3615     }
3616   }
3617   _exact_klass = res;
3618 }
3619 
3620 #ifdef ASSERT
3621 void TypeInterfaces::verify_is_loaded() const {
3622   for (int i = 0; i < _interfaces.length(); i++) {
3623     ciKlass* interface = _interfaces.at(i);
3624     assert(interface->is_loaded(), "Interface not loaded");
3625   }
3626 }
3627 #endif
3628 
3629 // Can't be implemented because there's no way to know if the type is above or below the center line.
3630 const Type* TypeInterfaces::xmeet(const Type* t) const {
3631   ShouldNotReachHere();
3632   return Type::xmeet(t);
3633 }
3634 
3635 bool TypeInterfaces::singleton(void) const {
3636   ShouldNotReachHere();
3637   return Type::singleton();
3638 }
3639 
3640 bool TypeInterfaces::has_non_array_interface() const {
3641   assert(TypeAryPtr::_array_interfaces != nullptr, "How come Type::Initialize_shared wasn't called yet?");
3642 
3643   return !TypeAryPtr::_array_interfaces->contains(this);
3644 }
3645 
3646 //------------------------------TypeOopPtr-------------------------------------
3647 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset offset, Offset field_offset,
3648                        int instance_id, const TypePtr* speculative, int inline_depth)
3649   : TypePtr(t, ptr, offset, speculative, inline_depth),
3650     _const_oop(o), _klass(k),
3651     _interfaces(interfaces),
3652     _klass_is_exact(xk),
3653     _is_ptr_to_narrowoop(false),
3654     _is_ptr_to_narrowklass(false),
3655     _is_ptr_to_boxed_value(false),
3656     _is_ptr_to_strict_final_field(false),
3657     _instance_id(instance_id) {
3658 #ifdef ASSERT
3659   if (klass() != nullptr && klass()->is_loaded()) {
3660     interfaces->verify_is_loaded();
3661   }
3662 #endif
3663   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3664       (offset.get() > 0) && xk && (k != nullptr) && k->is_instance_klass()) {
3665     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset.get());
3666     _is_ptr_to_strict_final_field = _is_ptr_to_boxed_value;
3667   }
3668 
3669   if (klass() != nullptr && klass()->is_instance_klass() && klass()->is_loaded() &&
3670       this->offset() != Type::OffsetBot && this->offset() != Type::OffsetTop) {
3671     ciField* field = klass()->as_instance_klass()->get_field_by_offset(this->offset(), false);
3672     if (field != nullptr && field->is_strict() && field->is_final()) {
3673       _is_ptr_to_strict_final_field = true;
3674     }
3675   }
3676 
3677 #ifdef _LP64
3678   if (this->offset() > 0 || this->offset() == Type::OffsetTop || this->offset() == Type::OffsetBot) {
3679     if (this->offset() == oopDesc::klass_offset_in_bytes()) {
3680       _is_ptr_to_narrowklass = UseCompressedClassPointers;
3681     } else if (klass() == nullptr) {
3682       // Array with unknown body type
3683       assert(this->isa_aryptr(), "only arrays without klass");
3684       _is_ptr_to_narrowoop = UseCompressedOops;
3685     } else if (UseCompressedOops && this->isa_aryptr() && this->offset() != arrayOopDesc::length_offset_in_bytes()) {
3686       if (klass()->is_flat_array_klass() && field_offset != Offset::top && field_offset != Offset::bottom) {
3687         // Check if the field of the inline type array element contains oops
3688         ciInlineKlass* vk = klass()->as_flat_array_klass()->element_klass()->as_inline_klass();
3689         int foffset = field_offset.get() + vk->payload_offset();
3690         BasicType field_bt;
3691         ciField* field = vk->get_field_by_offset(foffset, false);
3692         if (field != nullptr) {
3693           field_bt = field->layout_type();
3694         } else {
3695           assert(field_offset.get() == vk->null_marker_offset_in_payload(), "no field or null marker of %s at offset %d", vk->name()->as_utf8(), foffset);
3696           field_bt = T_BOOLEAN;
3697         }
3698         _is_ptr_to_narrowoop = ::is_reference_type(field_bt);
3699       } else if (klass()->is_obj_array_klass()) {
3700         _is_ptr_to_narrowoop = true;
3701       }
3702     } else if (klass()->is_instance_klass()) {

3703       if (this->isa_klassptr()) {
3704         // Perm objects don't use compressed references
3705       } else if (_offset == Offset::bottom || _offset == Offset::top) {
3706         // unsafe access
3707         _is_ptr_to_narrowoop = UseCompressedOops;
3708       } else {
3709         assert(this->isa_instptr(), "must be an instance ptr.");

3710         if (klass() == ciEnv::current()->Class_klass() &&
3711             (this->offset() == java_lang_Class::klass_offset() ||
3712              this->offset() == java_lang_Class::array_klass_offset())) {
3713           // Special hidden fields from the Class.
3714           assert(this->isa_instptr(), "must be an instance ptr.");
3715           _is_ptr_to_narrowoop = false;
3716         } else if (klass() == ciEnv::current()->Class_klass() &&
3717                    this->offset() >= InstanceMirrorKlass::offset_of_static_fields()) {
3718           // Static fields
3719           BasicType basic_elem_type = T_ILLEGAL;
3720           if (const_oop() != nullptr) {
3721             ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3722             basic_elem_type = k->get_field_type_by_offset(this->offset(), true);
3723           }
3724           if (basic_elem_type != T_ILLEGAL) {
3725             _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3726           } else {
3727             // unsafe access
3728             _is_ptr_to_narrowoop = UseCompressedOops;
3729           }
3730         } else {
3731           // Instance fields which contains a compressed oop references.
3732           ciInstanceKlass* ik = klass()->as_instance_klass();
3733           BasicType basic_elem_type = ik->get_field_type_by_offset(this->offset(), false);
3734           if (basic_elem_type != T_ILLEGAL) {
3735             _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3736           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3737             // Compile::find_alias_type() cast exactness on all types to verify
3738             // that it does not affect alias type.
3739             _is_ptr_to_narrowoop = UseCompressedOops;
3740           } else {
3741             // Type for the copy start in LibraryCallKit::inline_native_clone().
3742             _is_ptr_to_narrowoop = UseCompressedOops;
3743           }
3744         }
3745       }
3746     }
3747   }
3748 #endif // _LP64
3749 }
3750 
3751 //------------------------------make-------------------------------------------
3752 const TypeOopPtr *TypeOopPtr::make(PTR ptr, Offset offset, int instance_id,
3753                                    const TypePtr* speculative, int inline_depth) {
3754   assert(ptr != Constant, "no constant generic pointers");
3755   ciKlass*  k = Compile::current()->env()->Object_klass();
3756   bool      xk = false;
3757   ciObject* o = nullptr;
3758   const TypeInterfaces* interfaces = TypeInterfaces::make();
3759   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, interfaces, xk, o, offset, Offset::bottom, instance_id, speculative, inline_depth))->hashcons();
3760 }
3761 
3762 
3763 //------------------------------cast_to_ptr_type-------------------------------
3764 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3765   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3766   if( ptr == _ptr ) return this;
3767   return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3768 }
3769 
3770 //-----------------------------cast_to_instance_id----------------------------
3771 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3772   // There are no instances of a general oop.
3773   // Return self unchanged.
3774   return this;
3775 }
3776 
3777 //-----------------------------cast_to_exactness-------------------------------
3778 const TypeOopPtr* TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3779   // There is no such thing as an exact general oop.
3780   // Return self unchanged.
3781   return this;
3782 }
3783 

3784 //------------------------------as_klass_type----------------------------------
3785 // Return the klass type corresponding to this instance or array type.
3786 // It is the type that is loaded from an object of this type.
3787 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3788   ShouldNotReachHere();
3789   return nullptr;
3790 }
3791 
3792 //------------------------------meet-------------------------------------------
3793 // Compute the MEET of two types.  It returns a new Type object.
3794 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3795   // Perform a fast test for common case; meeting the same types together.
3796   if( this == t ) return this;  // Meeting same type-rep?
3797 
3798   // Current "this->_base" is OopPtr
3799   switch (t->base()) {          // switch on original type
3800 
3801   case Int:                     // Mixing ints & oops happens when javac
3802   case Long:                    // reuses local variables
3803   case HalfFloatTop:
3804   case HalfFloatCon:
3805   case HalfFloatBot:
3806   case FloatTop:
3807   case FloatCon:
3808   case FloatBot:
3809   case DoubleTop:
3810   case DoubleCon:
3811   case DoubleBot:
3812   case NarrowOop:
3813   case NarrowKlass:
3814   case Bottom:                  // Ye Olde Default
3815     return Type::BOTTOM;
3816   case Top:
3817     return this;
3818 
3819   default:                      // All else is a mistake
3820     typerr(t);
3821 
3822   case RawPtr:
3823   case MetadataPtr:
3824   case KlassPtr:
3825   case InstKlassPtr:
3826   case AryKlassPtr:
3827     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3828 
3829   case AnyPtr: {
3830     // Found an AnyPtr type vs self-OopPtr type
3831     const TypePtr *tp = t->is_ptr();
3832     Offset offset = meet_offset(tp->offset());
3833     PTR ptr = meet_ptr(tp->ptr());
3834     const TypePtr* speculative = xmeet_speculative(tp);
3835     int depth = meet_inline_depth(tp->inline_depth());
3836     switch (tp->ptr()) {
3837     case Null:
3838       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3839       // else fall through:
3840     case TopPTR:
3841     case AnyNull: {
3842       int instance_id = meet_instance_id(InstanceTop);
3843       return make(ptr, offset, instance_id, speculative, depth);
3844     }
3845     case BotPTR:
3846     case NotNull:
3847       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3848     default: typerr(t);
3849     }
3850   }
3851 
3852   case OopPtr: {                 // Meeting to other OopPtrs
3853     const TypeOopPtr *tp = t->is_oopptr();
3854     int instance_id = meet_instance_id(tp->instance_id());
3855     const TypePtr* speculative = xmeet_speculative(tp);
3856     int depth = meet_inline_depth(tp->inline_depth());
3857     return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3858   }
3859 
3860   case InstPtr:                  // For these, flip the call around to cut down
3861   case AryPtr:
3862     return t->xmeet(this);      // Call in reverse direction
3863 
3864   } // End of switch
3865   return this;                  // Return the double constant
3866 }
3867 
3868 
3869 //------------------------------xdual------------------------------------------
3870 // Dual of a pure heap pointer.  No relevant klass or oop information.
3871 const Type *TypeOopPtr::xdual() const {
3872   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3873   assert(const_oop() == nullptr,             "no constants here");
3874   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());
3875 }
3876 
3877 //--------------------------make_from_klass_common-----------------------------
3878 // Computes the element-type given a klass.
3879 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling) {
3880   if (klass->is_instance_klass() || klass->is_inlinetype()) {
3881     Compile* C = Compile::current();
3882     Dependencies* deps = C->dependencies();
3883     assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
3884     // Element is an instance
3885     bool klass_is_exact = false;
3886     ciInstanceKlass* ik = klass->as_instance_klass();
3887     if (klass->is_loaded()) {
3888       // Try to set klass_is_exact.

3889       klass_is_exact = ik->is_final();
3890       if (!klass_is_exact && klass_change
3891           && deps != nullptr && UseUniqueSubclasses) {
3892         ciInstanceKlass* sub = ik->unique_concrete_subklass();
3893         if (sub != nullptr) {
3894           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3895           klass = ik = sub;
3896           klass_is_exact = sub->is_final();
3897         }
3898       }
3899       if (!klass_is_exact && try_for_exact && deps != nullptr &&
3900           !ik->is_interface() && !ik->has_subklass()) {
3901         // Add a dependence; if concrete subclass added we need to recompile
3902         deps->assert_leaf_type(ik);
3903         klass_is_exact = true;
3904       }
3905     }
3906     FlatInArray flat_in_array = compute_flat_in_array(ik, klass_is_exact);
3907     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
3908     return TypeInstPtr::make(TypePtr::BotPTR, klass, interfaces, klass_is_exact, nullptr, Offset(0), flat_in_array);
3909   } else if (klass->is_obj_array_klass()) {
3910     // Element is an object or inline type array. Recursively call ourself.
3911     ciObjArrayKlass* array_klass = klass->as_obj_array_klass();
3912     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_common(array_klass->element_klass(), /* klass_change= */ false, try_for_exact, interface_handling);
3913     bool xk = array_klass->is_loaded() && array_klass->is_refined();
3914 
3915     // Determine null-free/flat properties
3916     bool flat;
3917     bool not_flat;
3918     bool is_null_free;
3919     bool not_null_free;
3920     bool atomic;
3921     if (xk) {
3922       flat = array_klass->is_flat_array_klass();
3923       not_flat = !flat;
3924       is_null_free = array_klass->is_elem_null_free();
3925       not_null_free = !is_null_free;
3926       atomic = array_klass->is_elem_atomic();
3927 
3928       if (is_null_free) {
3929         etype = etype->join_speculative(NOTNULL)->is_oopptr();
3930       }
3931     } else {
3932       const TypeOopPtr* exact_etype = etype;
3933       if (etype->can_be_inline_type()) {
3934         // Use exact type if element can be an inline type
3935         exact_etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), /* klass_change= */ true, /* try_for_exact= */ true, interface_handling);
3936       }
3937 
3938       flat = false;
3939       bool not_inline = !exact_etype->can_be_inline_type();
3940       not_null_free = not_inline;
3941       not_flat = !UseArrayFlattening || not_inline || (exact_etype->is_inlinetypeptr() && !exact_etype->inline_klass()->maybe_flat_in_array());
3942       atomic = not_flat;
3943     }
3944 
3945     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS, /* stable= */ false, flat, not_flat, not_null_free, atomic);
3946     // We used to pass NotNull in here, asserting that the sub-arrays
3947     // are all not-null.  This is not true in generally, as code can
3948     // slam nullptrs down in the subarrays.
3949     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, nullptr, xk, Offset(0));
3950     return arr;
3951   } else if (klass->is_type_array_klass()) {
3952     // Element is an typeArray
3953     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3954     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS,
3955                                         /* stable= */ false, /* flat= */ false, /* not_flat= */ true, /* not_null_free= */ true, true);
3956     // We used to pass NotNull in here, asserting that the array pointer
3957     // is not-null. That was not true in general.
3958     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
3959     return arr;
3960   } else {
3961     ShouldNotReachHere();
3962     return nullptr;
3963   }
3964 }
3965 
3966 //------------------------------make_from_constant-----------------------------
3967 // Make a java pointer from an oop constant
3968 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3969   assert(!o->is_null_object(), "null object not yet handled here.");
3970 
3971   const bool make_constant = require_constant || o->should_be_constant();
3972 
3973   ciKlass* klass = o->klass();
3974   if (klass->is_instance_klass() || klass->is_inlinetype()) {
3975     // Element is an instance or inline type
3976     if (make_constant) {
3977       return TypeInstPtr::make(o);
3978     } else {
3979       return TypeInstPtr::make(TypePtr::NotNull, klass, true, nullptr, Offset(0));
3980     }
3981   } else if (klass->is_obj_array_klass()) {
3982     // Element is an object array. Recursively call ourself.
3983     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass(), trust_interfaces);
3984     bool is_flat = o->as_array()->is_flat();
3985     bool is_null_free = o->as_array()->is_null_free();
3986     if (is_null_free) {
3987       etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3988     }
3989     bool is_atomic = o->as_array()->is_atomic();
3990     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()), /* stable= */ false, /* flat= */ is_flat,
3991                                         /* not_flat= */ !is_flat, /* not_null_free= */ !is_null_free, /* atomic= */ is_atomic);
3992     // We used to pass NotNull in here, asserting that the sub-arrays
3993     // are all not-null.  This is not true in generally, as code can
3994     // slam nulls down in the subarrays.
3995     if (make_constant) {
3996       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3997     } else {
3998       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3999     }
4000   } else if (klass->is_type_array_klass()) {
4001     // Element is an typeArray
4002     const Type* etype = (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
4003     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()), /* stable= */ false, /* flat= */ false,
4004                                         /* not_flat= */ true, /* not_null_free= */ true, true);
4005     // We used to pass NotNull in here, asserting that the array pointer
4006     // is not-null. That was not true in general.
4007     if (make_constant) {
4008       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
4009     } else {
4010       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
4011     }
4012   }
4013 
4014   fatal("unhandled object type");
4015   return nullptr;
4016 }
4017 
4018 //------------------------------get_con----------------------------------------
4019 intptr_t TypeOopPtr::get_con() const {
4020   assert( _ptr == Null || _ptr == Constant, "" );
4021   assert(offset() >= 0, "");
4022 
4023   if (offset() != 0) {
4024     // After being ported to the compiler interface, the compiler no longer
4025     // directly manipulates the addresses of oops.  Rather, it only has a pointer
4026     // to a handle at compile time.  This handle is embedded in the generated
4027     // code and dereferenced at the time the nmethod is made.  Until that time,
4028     // it is not reasonable to do arithmetic with the addresses of oops (we don't
4029     // have access to the addresses!).  This does not seem to currently happen,
4030     // but this assertion here is to help prevent its occurrence.
4031     tty->print_cr("Found oop constant with non-zero offset");
4032     ShouldNotReachHere();
4033   }
4034 
4035   return (intptr_t)const_oop()->constant_encoding();
4036 }
4037 
4038 
4039 //-----------------------------filter------------------------------------------
4040 // Do not allow interface-vs.-noninterface joins to collapse to top.
4041 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
4042 
4043   const Type* ft = join_helper(kills, include_speculative);
4044 
4045   if (ft->empty()) {
4046     return Type::TOP;           // Canonical empty value
4047   }
4048 
4049   return ft;
4050 }
4051 
4052 //------------------------------eq---------------------------------------------
4053 // Structural equality check for Type representations
4054 bool TypeOopPtr::eq( const Type *t ) const {
4055   const TypeOopPtr *a = (const TypeOopPtr*)t;
4056   if (_klass_is_exact != a->_klass_is_exact ||
4057       _instance_id != a->_instance_id)  return false;
4058   ciObject* one = const_oop();
4059   ciObject* two = a->const_oop();
4060   if (one == nullptr || two == nullptr) {
4061     return (one == two) && TypePtr::eq(t);
4062   } else {
4063     return one->equals(two) && TypePtr::eq(t);
4064   }
4065 }
4066 
4067 //------------------------------hash-------------------------------------------
4068 // Type-specific hashing function.
4069 uint TypeOopPtr::hash(void) const {
4070   return
4071     (uint)(const_oop() ? const_oop()->hash() : 0) +
4072     (uint)_klass_is_exact +
4073     (uint)_instance_id + TypePtr::hash();
4074 }
4075 
4076 //------------------------------dump2------------------------------------------
4077 #ifndef PRODUCT
4078 void TypeOopPtr::dump2(Dict& d, uint depth, outputStream* st) const {
4079   st->print("oopptr:%s", ptr_msg[_ptr]);
4080   if (_klass_is_exact) {
4081     st->print(":exact");
4082   }
4083   if (const_oop() != nullptr) {
4084     st->print(":" INTPTR_FORMAT, p2i(const_oop()));
4085   }
4086   dump_offset(st);
4087   dump_instance_id(st);
4088   dump_inline_depth(st);
4089   dump_speculative(st);
4090 }
4091 
4092 void TypeOopPtr::dump_instance_id(outputStream* st) const {
4093   if (_instance_id == InstanceTop) {
4094     st->print(",iid=top");
4095   } else if (_instance_id == InstanceBot) {
4096     st->print(",iid=bot");
4097   } else {
4098     st->print(",iid=%d", _instance_id);
4099   }
4100 }
4101 #endif
4102 
4103 //------------------------------singleton--------------------------------------
4104 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
4105 // constants
4106 bool TypeOopPtr::singleton(void) const {
4107   // detune optimizer to not generate constant oop + constant offset as a constant!
4108   // TopPTR, Null, AnyNull, Constant are all singletons
4109   return (offset() == 0) && !below_centerline(_ptr);
4110 }
4111 
4112 //------------------------------add_offset-------------------------------------
4113 const TypePtr* TypeOopPtr::add_offset(intptr_t offset) const {
4114   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
4115 }
4116 
4117 const TypeOopPtr* TypeOopPtr::with_offset(intptr_t offset) const {
4118   return make(_ptr, Offset(offset), _instance_id, with_offset_speculative(offset), _inline_depth);
4119 }
4120 
4121 /**
4122  * Return same type without a speculative part
4123  */
4124 const TypeOopPtr* TypeOopPtr::remove_speculative() const {
4125   if (_speculative == nullptr) {
4126     return this;
4127   }
4128   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4129   return make(_ptr, _offset, _instance_id, nullptr, _inline_depth);
4130 }
4131 
4132 /**
4133  * Return same type but drop speculative part if we know we won't use
4134  * it
4135  */
4136 const Type* TypeOopPtr::cleanup_speculative() const {
4137   // If the klass is exact and the ptr is not null then there's
4138   // nothing that the speculative type can help us with
4139   if (klass_is_exact() && !maybe_null()) {
4140     return remove_speculative();
4141   }
4142   return TypePtr::cleanup_speculative();
4143 }
4144 
4145 /**
4146  * Return same type but with a different inline depth (used for speculation)
4147  *
4148  * @param depth  depth to meet with
4149  */
4150 const TypePtr* TypeOopPtr::with_inline_depth(int depth) const {
4151   if (!UseInlineDepthForSpeculativeTypes) {
4152     return this;
4153   }
4154   return make(_ptr, _offset, _instance_id, _speculative, depth);
4155 }
4156 
4157 //------------------------------with_instance_id--------------------------------
4158 const TypePtr* TypeOopPtr::with_instance_id(int instance_id) const {
4159   assert(_instance_id != -1, "should be known");
4160   return make(_ptr, _offset, instance_id, _speculative, _inline_depth);
4161 }
4162 
4163 //------------------------------meet_instance_id--------------------------------
4164 int TypeOopPtr::meet_instance_id( int instance_id ) const {
4165   // Either is 'TOP' instance?  Return the other instance!
4166   if( _instance_id == InstanceTop ) return  instance_id;
4167   if(  instance_id == InstanceTop ) return _instance_id;
4168   // If either is different, return 'BOTTOM' instance
4169   if( _instance_id != instance_id ) return InstanceBot;
4170   return _instance_id;
4171 }
4172 
4173 //------------------------------dual_instance_id--------------------------------
4174 int TypeOopPtr::dual_instance_id( ) const {
4175   if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM
4176   if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP
4177   return _instance_id;              // Map everything else into self
4178 }
4179 
4180 
4181 const TypeInterfaces* TypeOopPtr::meet_interfaces(const TypeOopPtr* other) const {
4182   if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
4183     return _interfaces->union_with(other->_interfaces);
4184   } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
4185     return other->_interfaces;
4186   } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
4187     return _interfaces;
4188   }
4189   return _interfaces->intersection_with(other->_interfaces);
4190 }
4191 
4192 /**
4193  * Check whether new profiling would improve speculative type
4194  *
4195  * @param   exact_kls    class from profiling
4196  * @param   inline_depth inlining depth of profile point
4197  *
4198  * @return  true if type profile is valuable
4199  */
4200 bool TypeOopPtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
4201   // no way to improve an already exact type
4202   if (klass_is_exact()) {
4203     return false;
4204   }
4205   return TypePtr::would_improve_type(exact_kls, inline_depth);
4206 }
4207 
4208 //=============================================================================
4209 // Convenience common pre-built types.
4210 const TypeInstPtr *TypeInstPtr::NOTNULL;
4211 const TypeInstPtr *TypeInstPtr::BOTTOM;
4212 const TypeInstPtr *TypeInstPtr::MIRROR;
4213 const TypeInstPtr *TypeInstPtr::MARK;
4214 const TypeInstPtr *TypeInstPtr::KLASS;
4215 
4216 // Is there a single ciKlass* that can represent that type?
4217 ciKlass* TypeInstPtr::exact_klass_helper() const {
4218   if (_interfaces->empty()) {
4219     return _klass;
4220   }
4221   if (_klass != ciEnv::current()->Object_klass()) {
4222     if (_interfaces->eq(_klass->as_instance_klass())) {
4223       return _klass;
4224     }
4225     return nullptr;
4226   }
4227   return _interfaces->exact_klass();
4228 }
4229 
4230 //------------------------------TypeInstPtr-------------------------------------
4231 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset off,
4232                          FlatInArray flat_in_array, int instance_id, const TypePtr* speculative, int inline_depth)
4233   : TypeOopPtr(InstPtr, ptr, k, interfaces, xk, o, off, Offset::bottom, instance_id, speculative, inline_depth),
4234     _flat_in_array(flat_in_array) {
4235 
4236   assert(flat_in_array != Uninitialized, "must be set now");
4237   assert(k == nullptr || !k->is_loaded() || !k->is_interface(), "no interface here");
4238   assert(k != nullptr &&
4239          (k->is_loaded() || o == nullptr),
4240          "cannot have constants with non-loaded klass");
4241 };
4242 
4243 //------------------------------make-------------------------------------------
4244 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
4245                                      ciKlass* k,
4246                                      const TypeInterfaces* interfaces,
4247                                      bool xk,
4248                                      ciObject* o,
4249                                      Offset offset,
4250                                      FlatInArray flat_in_array,
4251                                      int instance_id,
4252                                      const TypePtr* speculative,
4253                                      int inline_depth) {
4254   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
4255   // Either const_oop() is null or else ptr is Constant
4256   assert( (!o && ptr != Constant) || (o && ptr == Constant),
4257           "constant pointers must have a value supplied" );
4258   // Ptr is never Null
4259   assert( ptr != Null, "null pointers are not typed" );
4260 
4261   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4262   ciInstanceKlass* ik = k->as_instance_klass();
4263   if (ptr == Constant) {
4264     // Note:  This case includes meta-object constants, such as methods.
4265     xk = true;
4266   } else if (k->is_loaded()) {

4267     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
4268     assert(!ik->is_interface(), "no interface here");
4269     if (xk && ik->is_interface())  xk = false;  // no exact interface
4270   }
4271 
4272   if (flat_in_array == Uninitialized) {
4273     flat_in_array = compute_flat_in_array(ik, xk);
4274   }
4275   // Now hash this baby
4276   TypeInstPtr *result =
4277     (TypeInstPtr*)(new TypeInstPtr(ptr, k, interfaces, xk, o, offset, flat_in_array, instance_id, speculative, inline_depth))->hashcons();
4278 
4279   return result;
4280 }
4281 
4282 const TypeInterfaces* TypePtr::interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling) {
4283   if (k->is_instance_klass()) {
4284     if (k->is_loaded()) {
4285       if (k->is_interface() && interface_handling == ignore_interfaces) {
4286         assert(interface, "no interface expected");
4287         k = ciEnv::current()->Object_klass();
4288         const TypeInterfaces* interfaces = TypeInterfaces::make();
4289         return interfaces;
4290       }
4291       GrowableArray<ciInstanceKlass *>* k_interfaces = k->as_instance_klass()->transitive_interfaces();
4292       const TypeInterfaces* interfaces = TypeInterfaces::make(k_interfaces);
4293       if (k->is_interface()) {
4294         assert(interface, "no interface expected");
4295         k = ciEnv::current()->Object_klass();
4296       } else {
4297         assert(klass, "no instance klass expected");
4298       }
4299       return interfaces;
4300     }
4301     const TypeInterfaces* interfaces = TypeInterfaces::make();
4302     return interfaces;
4303   }
4304   assert(array, "no array expected");
4305   assert(k->is_array_klass(), "Not an array?");
4306   ciType* e = k->as_array_klass()->base_element_type();
4307   if (e->is_loaded() && e->is_instance_klass() && e->as_instance_klass()->is_interface()) {
4308     if (interface_handling == ignore_interfaces) {
4309       k = ciObjArrayKlass::make(ciEnv::current()->Object_klass(), k->as_array_klass()->dimension());
4310     }
4311   }
4312   return TypeAryPtr::_array_interfaces;
4313 }
4314 
4315 /**
4316  *  Create constant type for a constant boxed value
4317  */
4318 const Type* TypeInstPtr::get_const_boxed_value() const {
4319   assert(is_ptr_to_boxed_value(), "should be called only for boxed value");
4320   assert((const_oop() != nullptr), "should be called only for constant object");
4321   ciConstant constant = const_oop()->as_instance()->field_value_by_offset(offset());
4322   BasicType bt = constant.basic_type();
4323   switch (bt) {
4324     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
4325     case T_INT:      return TypeInt::make(constant.as_int());
4326     case T_CHAR:     return TypeInt::make(constant.as_char());
4327     case T_BYTE:     return TypeInt::make(constant.as_byte());
4328     case T_SHORT:    return TypeInt::make(constant.as_short());
4329     case T_FLOAT:    return TypeF::make(constant.as_float());
4330     case T_DOUBLE:   return TypeD::make(constant.as_double());
4331     case T_LONG:     return TypeLong::make(constant.as_long());
4332     default:         break;
4333   }
4334   fatal("Invalid boxed value type '%s'", type2name(bt));
4335   return nullptr;
4336 }
4337 
4338 //------------------------------cast_to_ptr_type-------------------------------
4339 const TypeInstPtr* TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
4340   if( ptr == _ptr ) return this;
4341   // Reconstruct _sig info here since not a problem with later lazy
4342   // construction, _sig will show up on demand.
4343   return make(ptr, klass(), _interfaces, klass_is_exact(), ptr == Constant ? const_oop() : nullptr, _offset, _flat_in_array, _instance_id, _speculative, _inline_depth);
4344 }
4345 
4346 
4347 //-----------------------------cast_to_exactness-------------------------------
4348 const TypeInstPtr* TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
4349   if( klass_is_exact == _klass_is_exact ) return this;
4350   if (!_klass->is_loaded())  return this;
4351   ciInstanceKlass* ik = _klass->as_instance_klass();
4352   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
4353   assert(!ik->is_interface(), "no interface here");
4354   FlatInArray flat_in_array = compute_flat_in_array(ik, klass_is_exact);
4355   return make(ptr(), klass(), _interfaces, klass_is_exact, const_oop(), _offset, flat_in_array, _instance_id, _speculative, _inline_depth);
4356 }
4357 
4358 //-----------------------------cast_to_instance_id----------------------------
4359 const TypeInstPtr* TypeInstPtr::cast_to_instance_id(int instance_id) const {
4360   if( instance_id == _instance_id ) return this;
4361   return make(_ptr, klass(), _interfaces, _klass_is_exact, const_oop(), _offset, _flat_in_array, instance_id, _speculative, _inline_depth);
4362 }
4363 
4364 //------------------------------xmeet_unloaded---------------------------------
4365 // Compute the MEET of two InstPtrs when at least one is unloaded.
4366 // Assume classes are different since called after check for same name/class-loader
4367 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst, const TypeInterfaces* interfaces) const {
4368   Offset off = meet_offset(tinst->offset());
4369   PTR ptr = meet_ptr(tinst->ptr());
4370   int instance_id = meet_instance_id(tinst->instance_id());
4371   const TypePtr* speculative = xmeet_speculative(tinst);
4372   int depth = meet_inline_depth(tinst->inline_depth());
4373 
4374   const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
4375   const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
4376   if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
4377     //
4378     // Meet unloaded class with java/lang/Object
4379     //
4380     // Meet
4381     //          |                     Unloaded Class
4382     //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
4383     //  ===================================================================
4384     //   TOP    | ..........................Unloaded......................|
4385     //  AnyNull |  U-AN    |................Unloaded......................|
4386     // Constant | ... O-NN .................................. |   O-BOT   |
4387     //  NotNull | ... O-NN .................................. |   O-BOT   |
4388     //  BOTTOM  | ........................Object-BOTTOM ..................|
4389     //
4390     assert(loaded->ptr() != TypePtr::Null, "insanity check");
4391     //
4392     if (loaded->ptr() == TypePtr::TopPTR)        { return unloaded->with_speculative(speculative); }
4393     else if (loaded->ptr() == TypePtr::AnyNull)  {
4394       FlatInArray flat_in_array = meet_flat_in_array(_flat_in_array, tinst->flat_in_array());
4395       return make(ptr, unloaded->klass(), interfaces, false, nullptr, off, flat_in_array, instance_id,
4396                   speculative, depth);
4397     }
4398     else if (loaded->ptr() == TypePtr::BotPTR)   { return TypeInstPtr::BOTTOM->with_speculative(speculative); }
4399     else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
4400       if (unloaded->ptr() == TypePtr::BotPTR)    { return TypeInstPtr::BOTTOM->with_speculative(speculative);  }
4401       else                                       { return TypeInstPtr::NOTNULL->with_speculative(speculative); }
4402     }
4403     else if (unloaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); }
4404 
4405     return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr()->with_speculative(speculative);
4406   }
4407 
4408   // Both are unloaded, not the same class, not Object
4409   // Or meet unloaded with a different loaded class, not java/lang/Object
4410   if (ptr != TypePtr::BotPTR) {
4411     return TypeInstPtr::NOTNULL->with_speculative(speculative);
4412   }
4413   return TypeInstPtr::BOTTOM->with_speculative(speculative);
4414 }
4415 
4416 
4417 //------------------------------meet-------------------------------------------
4418 // Compute the MEET of two types.  It returns a new Type object.
4419 const Type *TypeInstPtr::xmeet_helper(const Type *t) const {
4420   // Perform a fast test for common case; meeting the same types together.
4421   if( this == t ) return this;  // Meeting same type-rep?
4422 
4423   // Current "this->_base" is Pointer
4424   switch (t->base()) {          // switch on original type
4425 
4426   case Int:                     // Mixing ints & oops happens when javac
4427   case Long:                    // reuses local variables
4428   case HalfFloatTop:
4429   case HalfFloatCon:
4430   case HalfFloatBot:
4431   case FloatTop:
4432   case FloatCon:
4433   case FloatBot:
4434   case DoubleTop:
4435   case DoubleCon:
4436   case DoubleBot:
4437   case NarrowOop:
4438   case NarrowKlass:
4439   case Bottom:                  // Ye Olde Default
4440     return Type::BOTTOM;
4441   case Top:
4442     return this;
4443 
4444   default:                      // All else is a mistake
4445     typerr(t);
4446 
4447   case MetadataPtr:
4448   case KlassPtr:
4449   case InstKlassPtr:
4450   case AryKlassPtr:
4451   case RawPtr: return TypePtr::BOTTOM;
4452 
4453   case AryPtr: {                // All arrays inherit from Object class
4454     // Call in reverse direction to avoid duplication
4455     return t->is_aryptr()->xmeet_helper(this);
4456   }
4457 
4458   case OopPtr: {                // Meeting to OopPtrs
4459     // Found a OopPtr type vs self-InstPtr type
4460     const TypeOopPtr *tp = t->is_oopptr();
4461     Offset offset = meet_offset(tp->offset());
4462     PTR ptr = meet_ptr(tp->ptr());
4463     switch (tp->ptr()) {
4464     case TopPTR:
4465     case AnyNull: {
4466       int instance_id = meet_instance_id(InstanceTop);
4467       const TypePtr* speculative = xmeet_speculative(tp);
4468       int depth = meet_inline_depth(tp->inline_depth());
4469       return make(ptr, klass(), _interfaces, klass_is_exact(),
4470                   (ptr == Constant ? const_oop() : nullptr), offset, flat_in_array(), instance_id, speculative, depth);
4471     }
4472     case NotNull:
4473     case BotPTR: {
4474       int instance_id = meet_instance_id(tp->instance_id());
4475       const TypePtr* speculative = xmeet_speculative(tp);
4476       int depth = meet_inline_depth(tp->inline_depth());
4477       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4478     }
4479     default: typerr(t);
4480     }
4481   }
4482 
4483   case AnyPtr: {                // Meeting to AnyPtrs
4484     // Found an AnyPtr type vs self-InstPtr type
4485     const TypePtr *tp = t->is_ptr();
4486     Offset offset = meet_offset(tp->offset());
4487     PTR ptr = meet_ptr(tp->ptr());
4488     int instance_id = meet_instance_id(InstanceTop);
4489     const TypePtr* speculative = xmeet_speculative(tp);
4490     int depth = meet_inline_depth(tp->inline_depth());
4491     switch (tp->ptr()) {
4492     case Null:
4493       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4494       // else fall through to AnyNull
4495     case TopPTR:
4496     case AnyNull: {
4497       return make(ptr, klass(), _interfaces, klass_is_exact(),
4498                   (ptr == Constant ? const_oop() : nullptr), offset, flat_in_array(), instance_id, speculative, depth);
4499     }
4500     case NotNull:
4501     case BotPTR:
4502       return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4503     default: typerr(t);
4504     }
4505   }
4506 
4507   /*
4508                  A-top         }
4509                /   |   \       }  Tops
4510            B-top A-any C-top   }
4511               | /  |  \ |      }  Any-nulls
4512            B-any   |   C-any   }
4513               |    |    |
4514            B-con A-con C-con   } constants; not comparable across classes
4515               |    |    |
4516            B-not   |   C-not   }
4517               | \  |  / |      }  not-nulls
4518            B-bot A-not C-bot   }
4519                \   |   /       }  Bottoms
4520                  A-bot         }
4521   */
4522 
4523   case InstPtr: {                // Meeting 2 Oops?
4524     // Found an InstPtr sub-type vs self-InstPtr type
4525     const TypeInstPtr *tinst = t->is_instptr();
4526     Offset off = meet_offset(tinst->offset());
4527     PTR ptr = meet_ptr(tinst->ptr());
4528     int instance_id = meet_instance_id(tinst->instance_id());
4529     const TypePtr* speculative = xmeet_speculative(tinst);
4530     int depth = meet_inline_depth(tinst->inline_depth());
4531     const TypeInterfaces* interfaces = meet_interfaces(tinst);
4532 
4533     ciKlass* tinst_klass = tinst->klass();
4534     ciKlass* this_klass  = klass();
4535 
4536     ciKlass* res_klass = nullptr;
4537     bool res_xk = false;
4538     const Type* res;
4539     MeetResult kind = meet_instptr(ptr, interfaces, this, tinst, res_klass, res_xk);
4540 
4541     if (kind == UNLOADED) {
4542       // One of these classes has not been loaded
4543       const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst, interfaces);
4544 #ifndef PRODUCT
4545       if (PrintOpto && Verbose) {
4546         tty->print("meet of unloaded classes resulted in: ");
4547         unloaded_meet->dump();
4548         tty->cr();
4549         tty->print("  this == ");
4550         dump();
4551         tty->cr();
4552         tty->print(" tinst == ");
4553         tinst->dump();
4554         tty->cr();
4555       }
4556 #endif
4557       res = unloaded_meet;
4558     } else {
4559       FlatInArray flat_in_array = meet_flat_in_array(_flat_in_array, tinst->flat_in_array());
4560       if (kind == NOT_SUBTYPE && instance_id > 0) {
4561         instance_id = InstanceBot;
4562       } else if (kind == LCA) {
4563         instance_id = InstanceBot;
4564       }
4565       ciObject* o = nullptr;             // Assume not constant when done
4566       ciObject* this_oop = const_oop();
4567       ciObject* tinst_oop = tinst->const_oop();
4568       if (ptr == Constant) {
4569         if (this_oop != nullptr && tinst_oop != nullptr &&
4570             this_oop->equals(tinst_oop))
4571           o = this_oop;
4572         else if (above_centerline(_ptr)) {
4573           assert(!tinst_klass->is_interface(), "");
4574           o = tinst_oop;
4575         } else if (above_centerline(tinst->_ptr)) {
4576           assert(!this_klass->is_interface(), "");
4577           o = this_oop;
4578         } else
4579           ptr = NotNull;
4580       }
4581       res = make(ptr, res_klass, interfaces, res_xk, o, off, flat_in_array, instance_id, speculative, depth);
4582     }
4583 
4584     return res;
4585 
4586   } // End of case InstPtr
4587 
4588   } // End of switch
4589   return this;                  // Return the double constant
4590 }
4591 
4592 template<class T> TypePtr::MeetResult TypePtr::meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type, const T* other_type,
4593                                                             ciKlass*& res_klass, bool& res_xk) {
4594   ciKlass* this_klass = this_type->klass();
4595   ciKlass* other_klass = other_type->klass();
4596 
4597   bool this_xk = this_type->klass_is_exact();
4598   bool other_xk = other_type->klass_is_exact();
4599   PTR this_ptr = this_type->ptr();
4600   PTR other_ptr = other_type->ptr();
4601   const TypeInterfaces* this_interfaces = this_type->interfaces();
4602   const TypeInterfaces* other_interfaces = other_type->interfaces();
4603   // Check for easy case; klasses are equal (and perhaps not loaded!)
4604   // If we have constants, then we created oops so classes are loaded
4605   // and we can handle the constants further down.  This case handles
4606   // both-not-loaded or both-loaded classes
4607   if (ptr != Constant && this_klass->equals(other_klass) && this_xk == other_xk) {
4608     res_klass = this_klass;
4609     res_xk = this_xk;
4610     return QUICK;
4611   }
4612 
4613   // Classes require inspection in the Java klass hierarchy.  Must be loaded.
4614   if (!other_klass->is_loaded() || !this_klass->is_loaded()) {
4615     return UNLOADED;
4616   }
4617 
4618   // !!! Here's how the symmetry requirement breaks down into invariants:
4619   // If we split one up & one down AND they subtype, take the down man.
4620   // If we split one up & one down AND they do NOT subtype, "fall hard".
4621   // If both are up and they subtype, take the subtype class.
4622   // If both are up and they do NOT subtype, "fall hard".
4623   // If both are down and they subtype, take the supertype class.
4624   // If both are down and they do NOT subtype, "fall hard".
4625   // Constants treated as down.
4626 
4627   // Now, reorder the above list; observe that both-down+subtype is also
4628   // "fall hard"; "fall hard" becomes the default case:
4629   // If we split one up & one down AND they subtype, take the down man.
4630   // If both are up and they subtype, take the subtype class.
4631 
4632   // If both are down and they subtype, "fall hard".
4633   // If both are down and they do NOT subtype, "fall hard".
4634   // If both are up and they do NOT subtype, "fall hard".
4635   // If we split one up & one down AND they do NOT subtype, "fall hard".
4636 
4637   // If a proper subtype is exact, and we return it, we return it exactly.
4638   // If a proper supertype is exact, there can be no subtyping relationship!
4639   // If both types are equal to the subtype, exactness is and-ed below the
4640   // centerline and or-ed above it.  (N.B. Constants are always exact.)
4641 

4642   const T* subtype = nullptr;
4643   bool subtype_exact = false;
4644   if (this_type->is_same_java_type_as(other_type)) {
4645     // Same klass
4646     subtype = this_type;
4647     subtype_exact = below_centerline(ptr) ? (this_xk && other_xk) : (this_xk || other_xk);
4648   } else if (!other_xk && this_type->is_meet_subtype_of(other_type)) {
4649     subtype = this_type;     // Pick subtyping class
4650     subtype_exact = this_xk;
4651   } else if (!this_xk && other_type->is_meet_subtype_of(this_type)) {
4652     subtype = other_type;    // Pick subtyping class
4653     subtype_exact = other_xk;
4654   }
4655 
4656   if (subtype != nullptr) {
4657     if (above_centerline(ptr)) {
4658       // Both types are empty.
4659       this_type = other_type = subtype;
4660       this_xk = other_xk = subtype_exact;
4661     } else if (above_centerline(this_ptr) && !above_centerline(other_ptr)) {
4662       // this_type is empty while other_type is not. Take other_type.
4663       this_type = other_type;
4664       this_xk = other_xk;
4665     } else if (above_centerline(other_ptr) && !above_centerline(this_ptr)) {
4666       // other_type is empty while this_type is not. Take this_type.
4667       other_type = this_type; // this is down; keep down man

4668     } else {
4669       // this_type and other_type are both non-empty.
4670       this_xk = subtype_exact;  // either they are equal, or we'll do an LCA
4671     }
4672   }
4673 
4674   // Check for classes now being equal
4675   if (this_type->is_same_java_type_as(other_type)) {
4676     // If the klasses are equal, the constants may still differ.  Fall to
4677     // NotNull if they do (neither constant is null; that is a special case
4678     // handled elsewhere).
4679     res_klass = this_type->klass();
4680     res_xk = this_xk;
4681     return SUBTYPE;
4682   } // Else classes are not equal
4683 
4684   // Since klasses are different, we require a LCA in the Java
4685   // class hierarchy - which means we have to fall to at least NotNull.
4686   if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4687     ptr = NotNull;
4688   }
4689 
4690   interfaces = this_interfaces->intersection_with(other_interfaces);
4691 
4692   // Now we find the LCA of Java classes
4693   ciKlass* k = this_klass->least_common_ancestor(other_klass);
4694 
4695   res_klass = k;
4696   res_xk = false;

4697   return LCA;
4698 }
4699 
4700 //                Top-Flat    Flat        Not-Flat    Maybe-Flat
4701 // -------------------------------------------------------------
4702 //    Top-Flat    Top-Flat    Flat        Not-Flat    Maybe-Flat
4703 //        Flat    Flat        Flat        Maybe-Flat  Maybe-Flat
4704 //    Not-Flat    Not-Flat    Maybe-Flat  Not-Flat    Maybe-Flat
4705 //  Maybe-Flat    Maybe-Flat  Maybe-Flat  Maybe-Flat  Maybe-flat
4706 TypePtr::FlatInArray TypePtr::meet_flat_in_array(const FlatInArray left, const FlatInArray right) {
4707   if (left == TopFlat) {
4708     return right;
4709   }
4710   if (right == TopFlat) {
4711     return left;
4712   }
4713   if (left == MaybeFlat || right == MaybeFlat) {
4714     return MaybeFlat;
4715   }
4716 
4717   switch (left) {
4718     case Flat:
4719       if (right == Flat) {
4720         return Flat;
4721       }
4722       return MaybeFlat;
4723     case NotFlat:
4724       if (right == NotFlat) {
4725         return NotFlat;
4726       }
4727       return MaybeFlat;
4728     default:
4729       ShouldNotReachHere();
4730       return Uninitialized;
4731   }
4732 }
4733 
4734 //------------------------java_mirror_type--------------------------------------
4735 ciType* TypeInstPtr::java_mirror_type() const {
4736   // must be a singleton type
4737   if( const_oop() == nullptr )  return nullptr;
4738 
4739   // must be of type java.lang.Class
4740   if( klass() != ciEnv::current()->Class_klass() )  return nullptr;

4741   return const_oop()->as_instance()->java_mirror_type();
4742 }
4743 
4744 
4745 //------------------------------xdual------------------------------------------
4746 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
4747 // inheritance mechanism.
4748 const Type* TypeInstPtr::xdual() const {
4749   return new TypeInstPtr(dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(),
4750                          dual_flat_in_array(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4751 }
4752 
4753 //------------------------------eq---------------------------------------------
4754 // Structural equality check for Type representations
4755 bool TypeInstPtr::eq( const Type *t ) const {
4756   const TypeInstPtr *p = t->is_instptr();
4757   return
4758     klass()->equals(p->klass()) &&
4759     _flat_in_array == p->_flat_in_array &&
4760     _interfaces->eq(p->_interfaces) &&
4761     TypeOopPtr::eq(p);          // Check sub-type stuff
4762 }
4763 
4764 //------------------------------hash-------------------------------------------
4765 // Type-specific hashing function.
4766 uint TypeInstPtr::hash() const {
4767   return klass()->hash() + TypeOopPtr::hash() + _interfaces->hash() + static_cast<uint>(_flat_in_array);
4768 }
4769 
4770 bool TypeInstPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4771   return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4772 }
4773 
4774 
4775 bool TypeInstPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4776   return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
4777 }
4778 
4779 bool TypeInstPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4780   return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4781 }
4782 
4783 
4784 //------------------------------dump2------------------------------------------
4785 // Dump oop Type
4786 #ifndef PRODUCT
4787 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {
4788   // Print the name of the klass.
4789   st->print("instptr:");
4790   klass()->print_name_on(st);
4791   _interfaces->dump(st);
4792 
4793   if (_ptr == Constant && (WizardMode || Verbose)) {
4794     ResourceMark rm;
4795     stringStream ss;
4796 
4797     st->print(" ");
4798     const_oop()->print_oop(&ss);
4799     // 'const_oop->print_oop()' may emit newlines('\n') into ss.
4800     // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4801     char* buf = ss.as_string(/* c_heap= */false);
4802     StringUtils::replace_no_expand(buf, "\n", "");
4803     st->print_raw(buf);
4804   }
4805 
4806   st->print(":%s", ptr_msg[_ptr]);
4807   if (_klass_is_exact) {
4808     st->print(":exact");
4809   }
4810 
4811   st->print(" *");
4812 
4813   dump_offset(st);
4814   dump_instance_id(st);
4815   dump_inline_depth(st);
4816   dump_speculative(st);
4817   dump_flat_in_array(_flat_in_array, st);
4818 }
4819 #endif
4820 
4821 bool TypeInstPtr::empty() const {
4822   if (_flat_in_array == TopFlat) {
4823     return true;
4824   }
4825   return TypeOopPtr::empty();
4826 }
4827 
4828 //------------------------------add_offset-------------------------------------
4829 const TypePtr* TypeInstPtr::add_offset(intptr_t offset) const {
4830   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), xadd_offset(offset), _flat_in_array,
4831               _instance_id, add_offset_speculative(offset), _inline_depth);
4832 }
4833 
4834 const TypeInstPtr* TypeInstPtr::with_offset(intptr_t offset) const {
4835   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), Offset(offset), _flat_in_array,
4836               _instance_id, with_offset_speculative(offset), _inline_depth);
4837 }
4838 
4839 const TypeInstPtr* TypeInstPtr::remove_speculative() const {
4840   if (_speculative == nullptr) {
4841     return this;
4842   }
4843   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4844   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _flat_in_array,
4845               _instance_id, nullptr, _inline_depth);
4846 }
4847 
4848 const TypeInstPtr* TypeInstPtr::with_speculative(const TypePtr* speculative) const {
4849   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _flat_in_array, _instance_id, speculative, _inline_depth);
4850 }
4851 
4852 const TypePtr* TypeInstPtr::with_inline_depth(int depth) const {
4853   if (!UseInlineDepthForSpeculativeTypes) {
4854     return this;
4855   }
4856   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _flat_in_array, _instance_id, _speculative, depth);
4857 }
4858 
4859 const TypePtr* TypeInstPtr::with_instance_id(int instance_id) const {
4860   assert(is_known_instance(), "should be known");
4861   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _flat_in_array, instance_id, _speculative, _inline_depth);
4862 }
4863 
4864 const TypeInstPtr *TypeInstPtr::cast_to_flat_in_array() const {
4865   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, Flat, _instance_id, _speculative, _inline_depth);
4866 }
4867 
4868 const TypeInstPtr *TypeInstPtr::cast_to_maybe_flat_in_array() const {
4869   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, MaybeFlat, _instance_id, _speculative, _inline_depth);
4870 }
4871 
4872 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4873   bool xk = klass_is_exact();
4874   ciInstanceKlass* ik = klass()->as_instance_klass();
4875   if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final()) {
4876     if (_interfaces->eq(ik)) {
4877       Compile* C = Compile::current();
4878       Dependencies* deps = C->dependencies();
4879       deps->assert_leaf_type(ik);
4880       xk = true;
4881     }
4882   }
4883   FlatInArray flat_in_array = compute_flat_in_array_if_unknown(ik, xk, _flat_in_array);
4884   return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), _interfaces, Offset(0), flat_in_array);
4885 }
4886 
4887 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) {
4888   static_assert(std::is_base_of<T2, T1>::value, "");
4889 
4890   if (!this_one->is_instance_type(other)) {
4891     return false;
4892   }
4893 
4894   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4895     return true;
4896   }
4897 
4898   return this_one->klass()->is_subtype_of(other->klass()) &&
4899          (!this_xk || this_one->_interfaces->contains(other->_interfaces));
4900 }
4901 
4902 
4903 bool TypeInstPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4904   return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4905 }
4906 
4907 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) {
4908   static_assert(std::is_base_of<T2, T1>::value, "");
4909   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4910     return true;
4911   }
4912 
4913   if (this_one->is_instance_type(other)) {
4914     return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces);
4915   }
4916 
4917   int dummy;
4918   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
4919   if (this_top_or_bottom) {
4920     return false;
4921   }
4922 
4923   const T1* other_ary = this_one->is_array_type(other);
4924   const TypePtr* other_elem = other_ary->elem()->make_ptr();
4925   const TypePtr* this_elem = this_one->elem()->make_ptr();
4926   if (other_elem != nullptr && this_elem != nullptr) {
4927     return this_one->is_reference_type(this_elem)->is_meet_subtype_of_helper(this_one->is_reference_type(other_elem), this_xk, other_xk);
4928   }

4929   if (other_elem == nullptr && this_elem == nullptr) {
4930     return this_one->klass()->is_subtype_of(other->klass());
4931   }
4932 
4933   return false;
4934 }
4935 
4936 bool TypeAryPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4937   return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4938 }
4939 
4940 bool TypeInstKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4941   return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4942 }
4943 
4944 bool TypeAryKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4945   return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4946 }
4947 
4948 //=============================================================================
4949 // Convenience common pre-built types.
4950 const TypeAryPtr* TypeAryPtr::BOTTOM;
4951 const TypeAryPtr *TypeAryPtr::RANGE;
4952 const TypeAryPtr *TypeAryPtr::OOPS;
4953 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
4954 const TypeAryPtr *TypeAryPtr::BYTES;
4955 const TypeAryPtr *TypeAryPtr::SHORTS;
4956 const TypeAryPtr *TypeAryPtr::CHARS;
4957 const TypeAryPtr *TypeAryPtr::INTS;
4958 const TypeAryPtr *TypeAryPtr::LONGS;
4959 const TypeAryPtr *TypeAryPtr::FLOATS;
4960 const TypeAryPtr *TypeAryPtr::DOUBLES;
4961 const TypeAryPtr *TypeAryPtr::INLINES;
4962 
4963 //------------------------------make-------------------------------------------
4964 const TypeAryPtr* TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4965                                    int instance_id, const TypePtr* speculative, int inline_depth) {
4966   assert(!(k == nullptr && ary->_elem->isa_int()),
4967          "integral arrays must be pre-equipped with a class");
4968   if (!xk)  xk = ary->ary_must_be_exact();
4969   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4970   if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4971       k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4972     k = nullptr;
4973   }
4974   return (TypeAryPtr*)(new TypeAryPtr(ptr, nullptr, ary, k, xk, offset, field_offset, instance_id, false, speculative, inline_depth))->hashcons();
4975 }
4976 
4977 //------------------------------make-------------------------------------------
4978 const TypeAryPtr* TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4979                                    int instance_id, const TypePtr* speculative, int inline_depth,
4980                                    bool is_autobox_cache) {
4981   assert(!(k == nullptr && ary->_elem->isa_int()),
4982          "integral arrays must be pre-equipped with a class");
4983   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4984   if (!xk)  xk = (o != nullptr) || ary->ary_must_be_exact();
4985   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4986   if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4987       k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4988     k = nullptr;
4989   }
4990   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, field_offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4991 }
4992 
4993 //------------------------------cast_to_ptr_type-------------------------------
4994 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4995   if( ptr == _ptr ) return this;
4996   return make(ptr, ptr == Constant ? const_oop() : nullptr, _ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4997 }
4998 
4999 
5000 //-----------------------------cast_to_exactness-------------------------------
5001 const TypeAryPtr* TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
5002   if( klass_is_exact == _klass_is_exact ) return this;
5003   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
5004   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5005 }
5006 
5007 //-----------------------------cast_to_instance_id----------------------------
5008 const TypeAryPtr* TypeAryPtr::cast_to_instance_id(int instance_id) const {
5009   if( instance_id == _instance_id ) return this;
5010   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth, _is_autobox_cache);
5011 }
5012 
5013 
5014 //-----------------------------max_array_length-------------------------------
5015 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
5016 jint TypeAryPtr::max_array_length(BasicType etype) {
5017   if (!is_java_primitive(etype) && !::is_reference_type(etype)) {
5018     if (etype == T_NARROWOOP) {
5019       etype = T_OBJECT;
5020     } else if (etype == T_ILLEGAL) { // bottom[]
5021       etype = T_BYTE; // will produce conservatively high value
5022     } else {
5023       fatal("not an element type: %s", type2name(etype));
5024     }
5025   }
5026   return arrayOopDesc::max_array_length(etype);
5027 }
5028 
5029 //-----------------------------narrow_size_type-------------------------------
5030 // Narrow the given size type to the index range for the given array base type.
5031 // Return null if the resulting int type becomes empty.
5032 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const {
5033   jint hi = size->_hi;
5034   jint lo = size->_lo;
5035   jint min_lo = 0;
5036   jint max_hi = max_array_length(elem()->array_element_basic_type());
5037   //if (index_not_size)  --max_hi;     // type of a valid array index, FTR
5038   bool chg = false;
5039   if (lo < min_lo) {
5040     lo = min_lo;
5041     if (size->is_con()) {
5042       hi = lo;
5043     }
5044     chg = true;
5045   }
5046   if (hi > max_hi) {
5047     hi = max_hi;
5048     if (size->is_con()) {
5049       lo = hi;
5050     }
5051     chg = true;
5052   }
5053   // Negative length arrays will produce weird intermediate dead fast-path code
5054   if (lo > hi) {
5055     return TypeInt::ZERO;
5056   }
5057   if (!chg) {
5058     return size;
5059   }
5060   return TypeInt::make(lo, hi, Type::WidenMin);
5061 }
5062 
5063 //-------------------------------cast_to_size----------------------------------
5064 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
5065   assert(new_size != nullptr, "");
5066   new_size = narrow_size_type(new_size);
5067   if (new_size == size())  return this;
5068   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable(), is_flat(), is_not_flat(), is_not_null_free(), is_atomic());
5069   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5070 }
5071 
5072 const TypeAryPtr* TypeAryPtr::cast_to_flat(bool flat) const {
5073   if (flat == is_flat()) {
5074     return this;
5075   }
5076   assert(!flat || !is_not_flat(), "inconsistency");
5077   const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), flat, is_not_flat(), is_not_null_free(), is_atomic());
5078   const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5079   if (res->speculative() == res->remove_speculative()) {
5080     return res->remove_speculative();
5081   }
5082   return res;
5083 }
5084 
5085 //-------------------------------cast_to_not_flat------------------------------
5086 const TypeAryPtr* TypeAryPtr::cast_to_not_flat(bool not_flat) const {
5087   if (not_flat == is_not_flat()) {
5088     return this;
5089   }
5090   assert(!not_flat || !is_flat(), "inconsistency");
5091   const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), is_flat(), not_flat, is_not_null_free(), is_atomic());
5092   const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5093   // We keep the speculative part if it contains information about flat-/nullability.
5094   // Make sure it's removed if it's not better than the non-speculative type anymore.
5095   if (res->speculative() == res->remove_speculative()) {
5096     return res->remove_speculative();
5097   }
5098   return res;
5099 }
5100 
5101 const TypeAryPtr* TypeAryPtr::cast_to_null_free(bool null_free) const {
5102   if (null_free == is_null_free()) {
5103     return this;
5104   }
5105   assert(!null_free || !is_not_null_free(), "inconsistency");
5106   const Type* elem = this->elem();
5107   const Type* new_elem = elem->make_ptr();
5108   if (null_free) {
5109     new_elem = new_elem->join_speculative(TypePtr::NOTNULL);
5110   } else {
5111     new_elem = new_elem->meet_speculative(TypePtr::NULL_PTR);
5112   }
5113   new_elem = elem->isa_narrowoop() ? new_elem->make_narrowoop() : new_elem;
5114   const TypeAry* new_ary = TypeAry::make(new_elem, size(), is_stable(), is_flat(), is_not_flat(), is_not_null_free(), is_atomic());
5115   const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5116   if (res->speculative() == res->remove_speculative()) {
5117     return res->remove_speculative();
5118   }
5119   return res;
5120 }
5121 
5122 //-------------------------------cast_to_not_null_free-------------------------
5123 const TypeAryPtr* TypeAryPtr::cast_to_not_null_free(bool not_null_free) const {
5124   if (not_null_free == is_not_null_free()) {
5125     return this;
5126   }
5127   assert(!not_null_free || !is_null_free(), "inconsistency");
5128   const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), is_flat(), is_not_flat(), not_null_free, is_atomic());
5129   const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset,
5130                                _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5131   // We keep the speculative part if it contains information about flat-/nullability.
5132   // Make sure it's removed if it's not better than the non-speculative type anymore.
5133   if (res->speculative() == res->remove_speculative()) {
5134     return res->remove_speculative();
5135   }
5136   return res;
5137 }
5138 
5139 //---------------------------------update_properties---------------------------
5140 const TypeAryPtr* TypeAryPtr::update_properties(const TypeAryPtr* from) const {
5141   if ((from->is_flat()          && is_not_flat()) ||
5142       (from->is_not_flat()      && is_flat()) ||
5143       (from->is_null_free()     && is_not_null_free()) ||
5144       (from->is_not_null_free() && is_null_free())) {
5145     return nullptr; // Inconsistent properties
5146   }
5147   const TypeAryPtr* res = this;
5148   if (from->is_not_null_free()) {
5149     res = res->cast_to_not_null_free();
5150   }
5151   if (from->is_not_flat()) {
5152     res = res->cast_to_not_flat();
5153   }
5154   return res;
5155 }
5156 
5157 jint TypeAryPtr::flat_layout_helper() const {
5158   return exact_klass()->as_flat_array_klass()->layout_helper();
5159 }
5160 
5161 int TypeAryPtr::flat_elem_size() const {
5162   return exact_klass()->as_flat_array_klass()->element_byte_size();
5163 }
5164 
5165 int TypeAryPtr::flat_log_elem_size() const {
5166   return exact_klass()->as_flat_array_klass()->log2_element_size();
5167 }
5168 
5169 //------------------------------cast_to_stable---------------------------------
5170 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
5171   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
5172     return this;
5173 
5174   const Type* elem = this->elem();
5175   const TypePtr* elem_ptr = elem->make_ptr();
5176 
5177   if (stable_dimension > 1 && elem_ptr != nullptr && elem_ptr->isa_aryptr()) {
5178     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
5179     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
5180   }
5181 
5182   const TypeAry* new_ary = TypeAry::make(elem, size(), stable, is_flat(), is_not_flat(), is_not_null_free(), is_atomic());
5183 
5184   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5185 }
5186 
5187 //-----------------------------stable_dimension--------------------------------
5188 int TypeAryPtr::stable_dimension() const {
5189   if (!is_stable())  return 0;
5190   int dim = 1;
5191   const TypePtr* elem_ptr = elem()->make_ptr();
5192   if (elem_ptr != nullptr && elem_ptr->isa_aryptr())
5193     dim += elem_ptr->is_aryptr()->stable_dimension();
5194   return dim;
5195 }
5196 
5197 //----------------------cast_to_autobox_cache-----------------------------------
5198 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
5199   if (is_autobox_cache())  return this;
5200   const TypeOopPtr* etype = elem()->make_oopptr();
5201   if (etype == nullptr)  return this;
5202   // The pointers in the autobox arrays are always non-null.
5203   etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
5204   const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable(), is_flat(), is_not_flat(), is_not_null_free(), is_atomic());
5205   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
5206 }
5207 
5208 //------------------------------eq---------------------------------------------
5209 // Structural equality check for Type representations
5210 bool TypeAryPtr::eq( const Type *t ) const {
5211   const TypeAryPtr *p = t->is_aryptr();
5212   return
5213     _ary == p->_ary &&  // Check array
5214     TypeOopPtr::eq(p) &&// Check sub-parts
5215     _field_offset == p->_field_offset;
5216 }
5217 
5218 //------------------------------hash-------------------------------------------
5219 // Type-specific hashing function.
5220 uint TypeAryPtr::hash(void) const {
5221   return (uint)(uintptr_t)_ary + TypeOopPtr::hash() + _field_offset.get();
5222 }
5223 
5224 bool TypeAryPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
5225   return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
5226 }
5227 
5228 bool TypeAryPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
5229   return TypePtr::is_same_java_type_as_helper_for_array(this, other);
5230 }
5231 
5232 bool TypeAryPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
5233   return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
5234 }
5235 //------------------------------meet-------------------------------------------
5236 // Compute the MEET of two types.  It returns a new Type object.
5237 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
5238   // Perform a fast test for common case; meeting the same types together.
5239   if( this == t ) return this;  // Meeting same type-rep?
5240   // Current "this->_base" is Pointer
5241   switch (t->base()) {          // switch on original type
5242 
5243   // Mixing ints & oops happens when javac reuses local variables
5244   case Int:
5245   case Long:
5246   case HalfFloatTop:
5247   case HalfFloatCon:
5248   case HalfFloatBot:
5249   case FloatTop:
5250   case FloatCon:
5251   case FloatBot:
5252   case DoubleTop:
5253   case DoubleCon:
5254   case DoubleBot:
5255   case NarrowOop:
5256   case NarrowKlass:
5257   case Bottom:                  // Ye Olde Default
5258     return Type::BOTTOM;
5259   case Top:
5260     return this;
5261 
5262   default:                      // All else is a mistake
5263     typerr(t);
5264 
5265   case OopPtr: {                // Meeting to OopPtrs
5266     // Found a OopPtr type vs self-AryPtr type
5267     const TypeOopPtr *tp = t->is_oopptr();
5268     Offset offset = meet_offset(tp->offset());
5269     PTR ptr = meet_ptr(tp->ptr());
5270     int depth = meet_inline_depth(tp->inline_depth());
5271     const TypePtr* speculative = xmeet_speculative(tp);
5272     switch (tp->ptr()) {
5273     case TopPTR:
5274     case AnyNull: {
5275       int instance_id = meet_instance_id(InstanceTop);
5276       return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5277                   _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5278     }
5279     case BotPTR:
5280     case NotNull: {
5281       int instance_id = meet_instance_id(tp->instance_id());
5282       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
5283     }
5284     default: ShouldNotReachHere();
5285     }
5286   }
5287 
5288   case AnyPtr: {                // Meeting two AnyPtrs
5289     // Found an AnyPtr type vs self-AryPtr type
5290     const TypePtr *tp = t->is_ptr();
5291     Offset offset = meet_offset(tp->offset());
5292     PTR ptr = meet_ptr(tp->ptr());
5293     const TypePtr* speculative = xmeet_speculative(tp);
5294     int depth = meet_inline_depth(tp->inline_depth());
5295     switch (tp->ptr()) {
5296     case TopPTR:
5297       return this;
5298     case BotPTR:
5299     case NotNull:
5300       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5301     case Null:
5302       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5303       // else fall through to AnyNull
5304     case AnyNull: {
5305       int instance_id = meet_instance_id(InstanceTop);
5306       return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5307                   _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5308     }
5309     default: ShouldNotReachHere();
5310     }
5311   }
5312 
5313   case MetadataPtr:
5314   case KlassPtr:
5315   case InstKlassPtr:
5316   case AryKlassPtr:
5317   case RawPtr: return TypePtr::BOTTOM;
5318 
5319   case AryPtr: {                // Meeting 2 references?
5320     const TypeAryPtr *tap = t->is_aryptr();
5321     Offset off = meet_offset(tap->offset());
5322     Offset field_off = meet_field_offset(tap->field_offset());
5323     const Type* tm = _ary->meet_speculative(tap->_ary);
5324     const TypeAry* tary = tm->isa_ary();
5325     if (tary == nullptr) {
5326       assert(tm == Type::TOP || tm == Type::BOTTOM, "");
5327       return tm;
5328     }
5329     PTR ptr = meet_ptr(tap->ptr());
5330     int instance_id = meet_instance_id(tap->instance_id());
5331     const TypePtr* speculative = xmeet_speculative(tap);
5332     int depth = meet_inline_depth(tap->inline_depth());
5333 
5334     ciKlass* res_klass = nullptr;
5335     bool res_xk = false;
5336     bool res_flat = false;
5337     bool res_not_flat = false;
5338     bool res_not_null_free = false;
5339     bool res_atomic = false;
5340     const Type* elem = tary->_elem;
5341     if (meet_aryptr(ptr, elem, this, tap, res_klass, res_xk, res_flat, res_not_flat, res_not_null_free, res_atomic) == NOT_SUBTYPE) {
5342       instance_id = InstanceBot;
5343     } else if (this->is_flat() != tap->is_flat()) {
5344       // Meeting flat inline type array with non-flat array. Adjust (field) offset accordingly.
5345       if (tary->_flat) {
5346         // Result is in a flat representation
5347         off = Offset(is_flat() ? offset() : tap->offset());
5348         field_off = is_flat() ? field_offset() : tap->field_offset();
5349       } else if (below_centerline(ptr)) {
5350         // Result is in a non-flat representation
5351         off = Offset(flat_offset()).meet(Offset(tap->flat_offset()));
5352         field_off = (field_off == Offset::top) ? Offset::top : Offset::bottom;
5353       } else if (flat_offset() == tap->flat_offset()) {
5354         off = Offset(!is_flat() ? offset() : tap->offset());
5355         field_off = !is_flat() ? field_offset() : tap->field_offset();
5356       }
5357     }
5358 
5359     ciObject* o = nullptr;             // Assume not constant when done
5360     ciObject* this_oop = const_oop();
5361     ciObject* tap_oop = tap->const_oop();
5362     if (ptr == Constant) {
5363       if (this_oop != nullptr && tap_oop != nullptr &&
5364           this_oop->equals(tap_oop)) {
5365         o = tap_oop;
5366       } else if (above_centerline(_ptr)) {
5367         o = tap_oop;
5368       } else if (above_centerline(tap->_ptr)) {
5369         o = this_oop;
5370       } else {
5371         ptr = NotNull;
5372       }
5373     }
5374     return make(ptr, o, TypeAry::make(elem, tary->_size, tary->_stable, res_flat, res_not_flat, res_not_null_free, res_atomic), res_klass, res_xk, off, field_off, instance_id, speculative, depth);
5375   }
5376 
5377   // All arrays inherit from Object class
5378   case InstPtr: {
5379     const TypeInstPtr *tp = t->is_instptr();
5380     Offset offset = meet_offset(tp->offset());
5381     PTR ptr = meet_ptr(tp->ptr());
5382     int instance_id = meet_instance_id(tp->instance_id());
5383     const TypePtr* speculative = xmeet_speculative(tp);
5384     int depth = meet_inline_depth(tp->inline_depth());
5385     const TypeInterfaces* interfaces = meet_interfaces(tp);
5386     const TypeInterfaces* tp_interfaces = tp->_interfaces;
5387     const TypeInterfaces* this_interfaces = _interfaces;
5388 
5389     switch (ptr) {
5390     case TopPTR:
5391     case AnyNull:                // Fall 'down' to dual of object klass
5392       // For instances when a subclass meets a superclass we fall
5393       // below the centerline when the superclass is exact. We need to
5394       // do the same here.
5395       //
5396       // Flat in array:
5397       // We do
5398       //   dual(TypeAryPtr) MEET dual(TypeInstPtr)
5399       // If TypeInstPtr is anything else than Object, then the result of the meet is bottom Object (i.e. we could have
5400       // instances or arrays).
5401       // If TypeInstPtr is an Object and either
5402       // - exact
5403       // - inexact AND flat in array == dual(not flat in array) (i.e. not an array type)
5404       // then the result of the meet is bottom Object (i.e. we could have instances or arrays).
5405       // Otherwise, we meet two array pointers and create a new TypeAryPtr.
5406       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
5407           !tp->klass_is_exact() && !tp->is_not_flat_in_array()) {
5408         return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5409       } else {
5410         // cannot subclass, so the meet has to fall badly below the centerline
5411         ptr = NotNull;
5412         instance_id = InstanceBot;
5413         interfaces = this_interfaces->intersection_with(tp_interfaces);
5414         FlatInArray flat_in_array = meet_flat_in_array(NotFlat, tp->flat_in_array());
5415         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset, flat_in_array, instance_id, speculative, depth);
5416       }
5417     case Constant:
5418     case NotNull:
5419     case BotPTR: { // Fall down to object klass
5420       // LCA is object_klass, but if we subclass from the top we can do better
5421       if (above_centerline(tp->ptr())) {
5422         // If 'tp'  is above the centerline and it is Object class
5423         // then we can subclass in the Java class hierarchy.
5424         // For instances when a subclass meets a superclass we fall
5425         // below the centerline when the superclass is exact. We need
5426         // to do the same here.
5427 
5428         // Flat in array: We do TypeAryPtr MEET dual(TypeInstPtr), same applies as above in TopPTR/AnyNull case.
5429         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
5430             !tp->klass_is_exact() && !tp->is_not_flat_in_array()) {
5431           // that is, my array type is a subtype of 'tp' klass
5432           return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5433                       _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5434         }
5435       }
5436       // The other case cannot happen, since t cannot be a subtype of an array.
5437       // The meet falls down to Object class below centerline.
5438       if (ptr == Constant) {
5439         ptr = NotNull;
5440       }
5441       if (instance_id > 0) {
5442         instance_id = InstanceBot;
5443       }
5444 
5445       FlatInArray flat_in_array = meet_flat_in_array(NotFlat, tp->flat_in_array());
5446       interfaces = this_interfaces->intersection_with(tp_interfaces);
5447       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset,
5448                                flat_in_array, instance_id, speculative, depth);
5449     }
5450     default: typerr(t);
5451     }
5452   }
5453   }
5454   return this;                  // Lint noise
5455 }
5456 
5457 
5458 template<class T> TypePtr::MeetResult TypePtr::meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary, const T* other_ary,
5459                                                            ciKlass*& res_klass, bool& res_xk, bool &res_flat, bool& res_not_flat, bool& res_not_null_free, bool &res_atomic) {
5460   int dummy;
5461   bool this_top_or_bottom = (this_ary->base_element_type(dummy) == Type::TOP || this_ary->base_element_type(dummy) == Type::BOTTOM);
5462   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
5463   ciKlass* this_klass = this_ary->klass();
5464   ciKlass* other_klass = other_ary->klass();
5465   bool this_xk = this_ary->klass_is_exact();
5466   bool other_xk = other_ary->klass_is_exact();
5467   PTR this_ptr = this_ary->ptr();
5468   PTR other_ptr = other_ary->ptr();
5469   bool this_flat = this_ary->is_flat();
5470   bool this_not_flat = this_ary->is_not_flat();
5471   bool other_flat = other_ary->is_flat();
5472   bool other_not_flat = other_ary->is_not_flat();
5473   bool this_not_null_free = this_ary->is_not_null_free();
5474   bool other_not_null_free = other_ary->is_not_null_free();
5475   bool this_atomic = this_ary->is_atomic();
5476   bool other_atomic = other_ary->is_atomic();
5477   const bool same_nullness = this_ary->is_null_free() == other_ary->is_null_free();
5478   res_klass = nullptr;
5479   MeetResult result = SUBTYPE;
5480   res_flat = this_flat && other_flat;
5481   bool res_null_free = this_ary->is_null_free() && other_ary->is_null_free();
5482   res_not_flat = this_not_flat && other_not_flat;
5483   res_not_null_free = this_not_null_free && other_not_null_free;
5484   res_atomic = this_atomic && other_atomic;
5485 
5486   if (elem->isa_int()) {
5487     // Integral array element types have irrelevant lattice relations.
5488     // It is the klass that determines array layout, not the element type.
5489       if (this_top_or_bottom) {
5490         res_klass = other_klass;
5491       } else if (other_top_or_bottom || other_klass == this_klass) {
5492       res_klass = this_klass;
5493     } else {
5494       // Something like byte[int+] meets char[int+].
5495       // This must fall to bottom, not (int[-128..65535])[int+].
5496       // instance_id = InstanceBot;
5497       elem = Type::BOTTOM;
5498       result = NOT_SUBTYPE;
5499       if (above_centerline(ptr) || ptr == Constant) {
5500         ptr = NotNull;
5501         res_xk = false;
5502         return NOT_SUBTYPE;
5503       }
5504     }
5505   } else {// Non integral arrays.
5506     // Must fall to bottom if exact klasses in upper lattice
5507     // are not equal or super klass is exact.
5508     if ((above_centerline(ptr) || ptr == Constant) && !this_ary->is_same_java_type_as(other_ary) &&
5509         // meet with top[] and bottom[] are processed further down:
5510         !this_top_or_bottom && !other_top_or_bottom &&
5511         // both are exact and not equal:
5512         ((other_xk && this_xk) ||
5513          // 'tap'  is exact and super or unrelated:
5514          (other_xk && !other_ary->is_meet_subtype_of(this_ary)) ||
5515          // 'this' is exact and super or unrelated:
5516          (this_xk && !this_ary->is_meet_subtype_of(other_ary)))) {
5517       if (above_centerline(ptr) || (elem->make_ptr() && above_centerline(elem->make_ptr()->_ptr))) {
5518         elem = Type::BOTTOM;
5519       }
5520       ptr = NotNull;
5521       res_xk = false;
5522       return NOT_SUBTYPE;
5523     }
5524   }
5525 
5526   res_xk = false;
5527   switch (other_ptr) {
5528     case AnyNull:
5529     case TopPTR:
5530       // Compute new klass on demand, do not use tap->_klass
5531       if (below_centerline(this_ptr)) {
5532         res_xk = this_xk;
5533         if (this_ary->is_flat()) {
5534           elem = this_ary->elem();
5535         }
5536       } else {
5537         res_xk = (other_xk || this_xk);
5538       }
5539       break;
5540     case Constant: {
5541       if (this_ptr == Constant && same_nullness) {
5542         // Only exact if same nullness since:
5543         //     null-free [LMyValue <: nullable [LMyValue.
5544         res_xk = true;
5545       } else if (above_centerline(this_ptr)) {
5546         res_xk = true;
5547       } else {
5548         // Only precise for identical arrays
5549         res_xk = this_xk && (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom));
5550         // Even though MyValue is final, [LMyValue is only exact if the array
5551         // is (not) null-free due to null-free [LMyValue <: null-able [LMyValue.
5552         if (res_xk && !res_null_free && !res_not_null_free) {
5553           ptr = NotNull;
5554           res_xk = false;
5555         }
5556       }
5557       break;
5558     }
5559     case NotNull:
5560     case BotPTR:
5561       // Compute new klass on demand, do not use tap->_klass
5562       if (above_centerline(this_ptr)) {
5563         res_xk = other_xk;
5564         if (other_ary->is_flat()) {
5565           elem = other_ary->elem();
5566         }
5567       } else {
5568         res_xk = (other_xk && this_xk) &&
5569                  (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom)); // Only precise for identical arrays
5570         // Even though MyValue is final, [LMyValue is only exact if the array
5571         // is (not) null-free due to null-free [LMyValue <: null-able [LMyValue.
5572         if (res_xk && !res_null_free && !res_not_null_free) {
5573           ptr = NotNull;
5574           res_xk = false;
5575         }
5576       }
5577       break;
5578     default:  {
5579       ShouldNotReachHere();
5580       return result;
5581     }
5582   }
5583   return result;
5584 }
5585 
5586 
5587 //------------------------------xdual------------------------------------------
5588 // Dual: compute field-by-field dual
5589 const Type *TypeAryPtr::xdual() const {
5590   bool xk = _klass_is_exact;
5591   return new TypeAryPtr(dual_ptr(), _const_oop, _ary->dual()->is_ary(), _klass, xk, dual_offset(), dual_field_offset(), dual_instance_id(), is_autobox_cache(), dual_speculative(), dual_inline_depth());
5592 }
5593 
5594 Type::Offset TypeAryPtr::meet_field_offset(const Type::Offset offset) const {
5595   return _field_offset.meet(offset);
5596 }
5597 
5598 //------------------------------dual_offset------------------------------------
5599 Type::Offset TypeAryPtr::dual_field_offset() const {
5600   return _field_offset.dual();
5601 }
5602 
5603 //------------------------------dump2------------------------------------------
5604 #ifndef PRODUCT
5605 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5606   st->print("aryptr:");
5607   _ary->dump2(d, depth, st);
5608   _interfaces->dump(st);
5609 
5610   if (_ptr == Constant) {
5611     const_oop()->print(st);
5612   }
5613 
5614   st->print(":%s", ptr_msg[_ptr]);
5615   if (_klass_is_exact) {
5616     st->print(":exact");
5617   }
5618 
5619   if (is_flat()) {
5620     st->print(":flat");
5621     st->print("(");
5622     _field_offset.dump2(st);
5623     st->print(")");
5624   } else if (is_not_flat()) {
5625     st->print(":not_flat");
5626   }
5627   if (is_null_free()) {
5628     st->print(":null free");
5629   }
5630   if (is_atomic()) {
5631     st->print(":atomic");
5632   }
5633   if (Verbose) {
5634     if (is_not_flat()) {
5635       st->print(":not flat");
5636     }
5637     if (is_not_null_free()) {
5638       st->print(":nullable");
5639     }
5640   }
5641   if (offset() != 0) {
5642     BasicType basic_elem_type = elem()->basic_type();
5643     int header_size = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5644     if( _offset == Offset::top )       st->print("+undefined");
5645     else if( _offset == Offset::bottom )  st->print("+any");
5646     else if( offset() < header_size ) st->print("+%d", offset());
5647     else {
5648       if (basic_elem_type == T_ILLEGAL) {
5649         st->print("+any");
5650       } else {
5651         int elem_size = type2aelembytes(basic_elem_type);
5652         st->print("[%d]", (offset() - header_size)/elem_size);
5653       }
5654     }
5655   }
5656 
5657   dump_instance_id(st);
5658   dump_inline_depth(st);
5659   dump_speculative(st);
5660 }
5661 #endif
5662 
5663 bool TypeAryPtr::empty(void) const {
5664   if (_ary->empty())       return true;
5665   // FIXME: Does this belong here? Or in the meet code itself?
5666   if (is_flat() && is_not_flat()) {
5667     return true;
5668   }
5669   return TypeOopPtr::empty();
5670 }
5671 
5672 //------------------------------add_offset-------------------------------------
5673 const TypePtr* TypeAryPtr::add_offset(intptr_t offset) const {
5674   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);
5675 }
5676 
5677 const TypeAryPtr* TypeAryPtr::with_offset(intptr_t offset) const {
5678   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);
5679 }
5680 
5681 const TypeAryPtr* TypeAryPtr::with_ary(const TypeAry* ary) const {
5682   return make(_ptr, _const_oop, ary, _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5683 }
5684 
5685 const TypeAryPtr* TypeAryPtr::remove_speculative() const {
5686   if (_speculative == nullptr) {
5687     return this;
5688   }
5689   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
5690   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);
5691 }
5692 
5693 const Type* TypeAryPtr::cleanup_speculative() const {
5694   if (speculative() == nullptr) {
5695     return this;
5696   }
5697   // Keep speculative part if it contains information about flat-/nullability
5698   const TypeAryPtr* spec_aryptr = speculative()->isa_aryptr();
5699   if (spec_aryptr != nullptr && !above_centerline(spec_aryptr->ptr()) &&
5700       (spec_aryptr->is_not_flat() || spec_aryptr->is_not_null_free())) {
5701     return this;
5702   }
5703   return TypeOopPtr::cleanup_speculative();
5704 }
5705 
5706 const TypePtr* TypeAryPtr::with_inline_depth(int depth) const {
5707   if (!UseInlineDepthForSpeculativeTypes) {
5708     return this;
5709   }
5710   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, depth, _is_autobox_cache);
5711 }
5712 
5713 const TypeAryPtr* TypeAryPtr::with_field_offset(int offset) const {
5714   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);
5715 }
5716 
5717 const TypePtr* TypeAryPtr::add_field_offset_and_offset(intptr_t offset) const {
5718   int adj = 0;
5719   if (is_flat() && klass_is_exact() && offset != Type::OffsetBot && offset != Type::OffsetTop) {
5720     if (_offset.get() != OffsetBot && _offset.get() != OffsetTop) {
5721       adj = _offset.get();
5722       offset += _offset.get();
5723     }
5724     uint header = arrayOopDesc::base_offset_in_bytes(T_FLAT_ELEMENT);
5725     if (_field_offset.get() != OffsetBot && _field_offset.get() != OffsetTop) {
5726       offset += _field_offset.get();
5727       if (_offset.get() == OffsetBot || _offset.get() == OffsetTop) {
5728         offset += header;
5729       }
5730     }
5731     if (elem()->make_oopptr()->is_inlinetypeptr() && (offset >= (intptr_t)header || offset < 0)) {
5732       // Try to get the field of the inline type array element we are pointing to
5733       ciInlineKlass* vk = elem()->inline_klass();
5734       int shift = flat_log_elem_size();
5735       int mask = (1 << shift) - 1;
5736       intptr_t field_offset = ((offset - header) & mask);
5737       ciField* field = vk->get_field_by_offset(field_offset + vk->payload_offset(), false);
5738       if (field != nullptr || field_offset == vk->null_marker_offset_in_payload()) {
5739         return with_field_offset(field_offset)->add_offset(offset - field_offset - adj);
5740       }
5741     }
5742   }
5743   return add_offset(offset - adj);
5744 }
5745 
5746 // Return offset incremented by field_offset for flat inline type arrays
5747 int TypeAryPtr::flat_offset() const {
5748   int offset = _offset.get();
5749   if (offset != Type::OffsetBot && offset != Type::OffsetTop &&
5750       _field_offset != Offset::bottom && _field_offset != Offset::top) {
5751     offset += _field_offset.get();
5752   }
5753   return offset;
5754 }
5755 
5756 const TypePtr* TypeAryPtr::with_instance_id(int instance_id) const {
5757   assert(is_known_instance(), "should be known");
5758   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth);
5759 }
5760 
5761 //=============================================================================
5762 
5763 
5764 //------------------------------hash-------------------------------------------
5765 // Type-specific hashing function.
5766 uint TypeNarrowPtr::hash(void) const {
5767   return _ptrtype->hash() + 7;
5768 }
5769 
5770 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
5771   return _ptrtype->singleton();
5772 }
5773 
5774 bool TypeNarrowPtr::empty(void) const {
5775   return _ptrtype->empty();
5776 }
5777 
5778 intptr_t TypeNarrowPtr::get_con() const {
5779   return _ptrtype->get_con();
5780 }
5781 
5782 bool TypeNarrowPtr::eq( const Type *t ) const {
5783   const TypeNarrowPtr* tc = isa_same_narrowptr(t);
5784   if (tc != nullptr) {
5785     if (_ptrtype->base() != tc->_ptrtype->base()) {
5786       return false;
5787     }
5788     return tc->_ptrtype->eq(_ptrtype);
5789   }
5790   return false;
5791 }
5792 
5793 const Type *TypeNarrowPtr::xdual() const {    // Compute dual right now.
5794   const TypePtr* odual = _ptrtype->dual()->is_ptr();
5795   return make_same_narrowptr(odual);
5796 }
5797 
5798 
5799 const Type *TypeNarrowPtr::filter_helper(const Type *kills, bool include_speculative) const {
5800   if (isa_same_narrowptr(kills)) {
5801     const Type* ft =_ptrtype->filter_helper(is_same_narrowptr(kills)->_ptrtype, include_speculative);
5802     if (ft->empty())
5803       return Type::TOP;           // Canonical empty value
5804     if (ft->isa_ptr()) {
5805       return make_hash_same_narrowptr(ft->isa_ptr());
5806     }
5807     return ft;
5808   } else if (kills->isa_ptr()) {
5809     const Type* ft = _ptrtype->join_helper(kills, include_speculative);
5810     if (ft->empty())
5811       return Type::TOP;           // Canonical empty value
5812     return ft;
5813   } else {
5814     return Type::TOP;
5815   }
5816 }
5817 
5818 //------------------------------xmeet------------------------------------------
5819 // Compute the MEET of two types.  It returns a new Type object.
5820 const Type *TypeNarrowPtr::xmeet( const Type *t ) const {
5821   // Perform a fast test for common case; meeting the same types together.
5822   if( this == t ) return this;  // Meeting same type-rep?
5823 
5824   if (t->base() == base()) {
5825     const Type* result = _ptrtype->xmeet(t->make_ptr());
5826     if (result->isa_ptr()) {
5827       return make_hash_same_narrowptr(result->is_ptr());
5828     }
5829     return result;
5830   }
5831 
5832   // Current "this->_base" is NarrowKlass or NarrowOop
5833   switch (t->base()) {          // switch on original type
5834 
5835   case Int:                     // Mixing ints & oops happens when javac
5836   case Long:                    // reuses local variables
5837   case HalfFloatTop:
5838   case HalfFloatCon:
5839   case HalfFloatBot:
5840   case FloatTop:
5841   case FloatCon:
5842   case FloatBot:
5843   case DoubleTop:
5844   case DoubleCon:
5845   case DoubleBot:
5846   case AnyPtr:
5847   case RawPtr:
5848   case OopPtr:
5849   case InstPtr:
5850   case AryPtr:
5851   case MetadataPtr:
5852   case KlassPtr:
5853   case InstKlassPtr:
5854   case AryKlassPtr:
5855   case NarrowOop:
5856   case NarrowKlass:

5857   case Bottom:                  // Ye Olde Default
5858     return Type::BOTTOM;
5859   case Top:
5860     return this;
5861 
5862   default:                      // All else is a mistake
5863     typerr(t);
5864 
5865   } // End of switch
5866 
5867   return this;
5868 }
5869 
5870 #ifndef PRODUCT
5871 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5872   _ptrtype->dump2(d, depth, st);
5873 }
5874 #endif
5875 
5876 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
5877 const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
5878 
5879 
5880 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
5881   return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();
5882 }
5883 
5884 const TypeNarrowOop* TypeNarrowOop::remove_speculative() const {
5885   return make(_ptrtype->remove_speculative()->is_ptr());
5886 }
5887 
5888 const Type* TypeNarrowOop::cleanup_speculative() const {
5889   return make(_ptrtype->cleanup_speculative()->is_ptr());
5890 }
5891 
5892 #ifndef PRODUCT
5893 void TypeNarrowOop::dump2( Dict & d, uint depth, outputStream *st ) const {
5894   st->print("narrowoop: ");
5895   TypeNarrowPtr::dump2(d, depth, st);
5896 }
5897 #endif
5898 
5899 const TypeNarrowKlass *TypeNarrowKlass::NULL_PTR;
5900 
5901 const TypeNarrowKlass* TypeNarrowKlass::make(const TypePtr* type) {
5902   return (const TypeNarrowKlass*)(new TypeNarrowKlass(type))->hashcons();
5903 }
5904 
5905 #ifndef PRODUCT
5906 void TypeNarrowKlass::dump2( Dict & d, uint depth, outputStream *st ) const {
5907   st->print("narrowklass: ");
5908   TypeNarrowPtr::dump2(d, depth, st);
5909 }
5910 #endif
5911 
5912 
5913 //------------------------------eq---------------------------------------------
5914 // Structural equality check for Type representations
5915 bool TypeMetadataPtr::eq( const Type *t ) const {
5916   const TypeMetadataPtr *a = (const TypeMetadataPtr*)t;
5917   ciMetadata* one = metadata();
5918   ciMetadata* two = a->metadata();
5919   if (one == nullptr || two == nullptr) {
5920     return (one == two) && TypePtr::eq(t);
5921   } else {
5922     return one->equals(two) && TypePtr::eq(t);
5923   }
5924 }
5925 
5926 //------------------------------hash-------------------------------------------
5927 // Type-specific hashing function.
5928 uint TypeMetadataPtr::hash(void) const {
5929   return
5930     (metadata() ? metadata()->hash() : 0) +
5931     TypePtr::hash();
5932 }
5933 
5934 //------------------------------singleton--------------------------------------
5935 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5936 // constants
5937 bool TypeMetadataPtr::singleton(void) const {
5938   // detune optimizer to not generate constant metadata + constant offset as a constant!
5939   // TopPTR, Null, AnyNull, Constant are all singletons
5940   return (offset() == 0) && !below_centerline(_ptr);
5941 }
5942 
5943 //------------------------------add_offset-------------------------------------
5944 const TypePtr* TypeMetadataPtr::add_offset( intptr_t offset ) const {
5945   return make( _ptr, _metadata, xadd_offset(offset));
5946 }
5947 
5948 //-----------------------------filter------------------------------------------
5949 // Do not allow interface-vs.-noninterface joins to collapse to top.
5950 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
5951   const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
5952   if (ft == nullptr || ft->empty())
5953     return Type::TOP;           // Canonical empty value
5954   return ft;
5955 }
5956 
5957  //------------------------------get_con----------------------------------------
5958 intptr_t TypeMetadataPtr::get_con() const {
5959   assert( _ptr == Null || _ptr == Constant, "" );
5960   assert(offset() >= 0, "");
5961 
5962   if (offset() != 0) {
5963     // After being ported to the compiler interface, the compiler no longer
5964     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5965     // to a handle at compile time.  This handle is embedded in the generated
5966     // code and dereferenced at the time the nmethod is made.  Until that time,
5967     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5968     // have access to the addresses!).  This does not seem to currently happen,
5969     // but this assertion here is to help prevent its occurrence.
5970     tty->print_cr("Found oop constant with non-zero offset");
5971     ShouldNotReachHere();
5972   }
5973 
5974   return (intptr_t)metadata()->constant_encoding();
5975 }
5976 
5977 //------------------------------cast_to_ptr_type-------------------------------
5978 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
5979   if( ptr == _ptr ) return this;
5980   return make(ptr, metadata(), _offset);
5981 }
5982 
5983 //------------------------------meet-------------------------------------------
5984 // Compute the MEET of two types.  It returns a new Type object.
5985 const Type *TypeMetadataPtr::xmeet( const Type *t ) const {
5986   // Perform a fast test for common case; meeting the same types together.
5987   if( this == t ) return this;  // Meeting same type-rep?
5988 
5989   // Current "this->_base" is OopPtr
5990   switch (t->base()) {          // switch on original type
5991 
5992   case Int:                     // Mixing ints & oops happens when javac
5993   case Long:                    // reuses local variables
5994   case HalfFloatTop:
5995   case HalfFloatCon:
5996   case HalfFloatBot:
5997   case FloatTop:
5998   case FloatCon:
5999   case FloatBot:
6000   case DoubleTop:
6001   case DoubleCon:
6002   case DoubleBot:
6003   case NarrowOop:
6004   case NarrowKlass:
6005   case Bottom:                  // Ye Olde Default
6006     return Type::BOTTOM;
6007   case Top:
6008     return this;
6009 
6010   default:                      // All else is a mistake
6011     typerr(t);
6012 
6013   case AnyPtr: {
6014     // Found an AnyPtr type vs self-OopPtr type
6015     const TypePtr *tp = t->is_ptr();
6016     Offset offset = meet_offset(tp->offset());
6017     PTR ptr = meet_ptr(tp->ptr());
6018     switch (tp->ptr()) {
6019     case Null:
6020       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6021       // else fall through:
6022     case TopPTR:
6023     case AnyNull: {
6024       return make(ptr, _metadata, offset);
6025     }
6026     case BotPTR:
6027     case NotNull:
6028       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6029     default: typerr(t);
6030     }
6031   }
6032 
6033   case RawPtr:
6034   case KlassPtr:
6035   case InstKlassPtr:
6036   case AryKlassPtr:
6037   case OopPtr:
6038   case InstPtr:
6039   case AryPtr:
6040     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
6041 
6042   case MetadataPtr: {
6043     const TypeMetadataPtr *tp = t->is_metadataptr();
6044     Offset offset = meet_offset(tp->offset());
6045     PTR tptr = tp->ptr();
6046     PTR ptr = meet_ptr(tptr);
6047     ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
6048     if (tptr == TopPTR || _ptr == TopPTR ||
6049         metadata()->equals(tp->metadata())) {
6050       return make(ptr, md, offset);
6051     }
6052     // metadata is different
6053     if( ptr == Constant ) {  // Cannot be equal constants, so...
6054       if( tptr == Constant && _ptr != Constant)  return t;
6055       if( _ptr == Constant && tptr != Constant)  return this;
6056       ptr = NotNull;            // Fall down in lattice
6057     }
6058     return make(ptr, nullptr, offset);
6059     break;
6060   }
6061   } // End of switch
6062   return this;                  // Return the double constant
6063 }
6064 
6065 
6066 //------------------------------xdual------------------------------------------
6067 // Dual of a pure metadata pointer.
6068 const Type *TypeMetadataPtr::xdual() const {
6069   return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
6070 }
6071 
6072 //------------------------------dump2------------------------------------------
6073 #ifndef PRODUCT
6074 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
6075   st->print("metadataptr:%s", ptr_msg[_ptr]);
6076   if (metadata() != nullptr) {
6077     st->print(":" INTPTR_FORMAT, p2i(metadata()));
6078   }
6079   dump_offset(st);
6080 }
6081 #endif
6082 
6083 
6084 //=============================================================================
6085 // Convenience common pre-built type.
6086 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
6087 
6088 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, Offset offset):
6089   TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
6090 }
6091 
6092 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
6093   return make(Constant, m, Offset(0));
6094 }
6095 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
6096   return make(Constant, m, Offset(0));
6097 }
6098 
6099 //------------------------------make-------------------------------------------
6100 // Create a meta data constant
6101 const TypeMetadataPtr* TypeMetadataPtr::make(PTR ptr, ciMetadata* m, Offset offset) {
6102   assert(m == nullptr || !m->is_klass(), "wrong type");
6103   return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
6104 }
6105 
6106 
6107 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
6108   const Type* elem = _ary->_elem;
6109   bool xk = klass_is_exact();
6110   bool is_refined = false;
6111   if (elem->make_oopptr() != nullptr) {
6112     is_refined = true;
6113     elem = elem->make_oopptr()->as_klass_type(try_for_exact);
6114     if (elem->isa_aryklassptr()) {
6115       const TypeAryKlassPtr* elem_klass = elem->is_aryklassptr();
6116       if (elem_klass->is_refined_type()) {
6117         elem = elem_klass->cast_to_non_refined();
6118       }
6119     } else {
6120       const TypeInstKlassPtr* elem_klass = elem->is_instklassptr();
6121       if (try_for_exact && !xk && elem_klass->klass_is_exact() &&
6122           !elem_klass->exact_klass()->as_instance_klass()->can_be_inline_klass()) {
6123         xk = true;
6124       }
6125     }
6126   }
6127   return TypeAryKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, elem, klass(), Offset(0), is_not_flat(), is_not_null_free(), is_flat(), is_null_free(), is_atomic(), is_refined);
6128 }
6129 
6130 const TypeKlassPtr* TypeKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6131   if (klass->is_instance_klass()) {
6132     return TypeInstKlassPtr::make(klass, interface_handling);
6133   }
6134   return TypeAryKlassPtr::make(klass, interface_handling);
6135 }
6136 
6137 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, Offset offset)










6138   : TypePtr(t, ptr, offset), _klass(klass), _interfaces(interfaces) {
6139   assert(klass == nullptr || !klass->is_loaded() || (klass->is_instance_klass() && !klass->is_interface()) ||
6140          klass->is_type_array_klass() || klass->is_flat_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "no interface here");
6141 }
6142 
6143 // Is there a single ciKlass* that can represent that type?
6144 ciKlass* TypeKlassPtr::exact_klass_helper() const {
6145   assert(_klass->is_instance_klass() && !_klass->is_interface(), "No interface");
6146   if (_interfaces->empty()) {
6147     return _klass;
6148   }
6149   if (_klass != ciEnv::current()->Object_klass()) {
6150     if (_interfaces->eq(_klass->as_instance_klass())) {
6151       return _klass;
6152     }
6153     return nullptr;
6154   }
6155   return _interfaces->exact_klass();
6156 }
6157 
6158 //------------------------------eq---------------------------------------------
6159 // Structural equality check for Type representations
6160 bool TypeKlassPtr::eq(const Type *t) const {
6161   const TypeKlassPtr *p = t->is_klassptr();
6162   return
6163     _interfaces->eq(p->_interfaces) &&
6164     TypePtr::eq(p);
6165 }
6166 
6167 //------------------------------hash-------------------------------------------
6168 // Type-specific hashing function.
6169 uint TypeKlassPtr::hash(void) const {
6170   return TypePtr::hash() + _interfaces->hash();
6171 }
6172 
6173 //------------------------------singleton--------------------------------------
6174 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
6175 // constants
6176 bool TypeKlassPtr::singleton(void) const {
6177   // detune optimizer to not generate constant klass + constant offset as a constant!
6178   // TopPTR, Null, AnyNull, Constant are all singletons
6179   return (offset() == 0) && !below_centerline(_ptr);
6180 }
6181 
6182 // Do not allow interface-vs.-noninterface joins to collapse to top.
6183 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
6184   // logic here mirrors the one from TypeOopPtr::filter. See comments
6185   // there.
6186   const Type* ft = join_helper(kills, include_speculative);
6187 
6188   if (ft->empty()) {
6189     return Type::TOP;           // Canonical empty value
6190   }
6191 
6192   return ft;
6193 }
6194 
6195 const TypeInterfaces* TypeKlassPtr::meet_interfaces(const TypeKlassPtr* other) const {
6196   if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
6197     return _interfaces->union_with(other->_interfaces);
6198   } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
6199     return other->_interfaces;
6200   } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
6201     return _interfaces;
6202   }
6203   return _interfaces->intersection_with(other->_interfaces);
6204 }
6205 
6206 //------------------------------get_con----------------------------------------
6207 intptr_t TypeKlassPtr::get_con() const {
6208   assert( _ptr == Null || _ptr == Constant, "" );
6209   assert( offset() >= 0, "" );
6210 
6211   if (offset() != 0) {
6212     // After being ported to the compiler interface, the compiler no longer
6213     // directly manipulates the addresses of oops.  Rather, it only has a pointer
6214     // to a handle at compile time.  This handle is embedded in the generated
6215     // code and dereferenced at the time the nmethod is made.  Until that time,
6216     // it is not reasonable to do arithmetic with the addresses of oops (we don't
6217     // have access to the addresses!).  This does not seem to currently happen,
6218     // but this assertion here is to help prevent its occurrence.
6219     tty->print_cr("Found oop constant with non-zero offset");
6220     ShouldNotReachHere();
6221   }
6222 
6223   ciKlass* k = exact_klass();
6224 
6225   return (intptr_t)k->constant_encoding();
6226 }
6227 
6228 //=============================================================================
6229 // Convenience common pre-built types.
6230 
6231 // Not-null object klass or below
6232 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
6233 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
6234 
6235 bool TypeInstKlassPtr::eq(const Type *t) const {
6236   const TypeInstKlassPtr* p = t->is_instklassptr();
6237   return
6238     klass()->equals(p->klass()) &&
6239     _flat_in_array == p->_flat_in_array &&
6240     TypeKlassPtr::eq(p);
6241 }
6242 
6243 uint TypeInstKlassPtr::hash() const {
6244   return klass()->hash() + TypeKlassPtr::hash() + static_cast<uint>(_flat_in_array);
6245 }
6246 
6247 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, Offset offset, FlatInArray flat_in_array) {
6248   if (flat_in_array == Uninitialized) {
6249     flat_in_array = compute_flat_in_array(k->as_instance_klass(), ptr == Constant);
6250   }
6251   TypeInstKlassPtr *r =
6252     (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, interfaces, offset, flat_in_array))->hashcons();
6253 
6254   return r;
6255 }
6256 
6257 bool TypeInstKlassPtr::empty() const {
6258   if (_flat_in_array == TopFlat) {
6259     return true;
6260   }
6261   return TypeKlassPtr::empty();
6262 }
6263 
6264 //------------------------------add_offset-------------------------------------
6265 // Access internals of klass object
6266 const TypePtr *TypeInstKlassPtr::add_offset( intptr_t offset ) const {
6267   return make(_ptr, klass(), _interfaces, xadd_offset(offset), _flat_in_array);
6268 }
6269 
6270 const TypeInstKlassPtr* TypeInstKlassPtr::with_offset(intptr_t offset) const {
6271   return make(_ptr, klass(), _interfaces, Offset(offset), _flat_in_array);
6272 }
6273 
6274 //------------------------------cast_to_ptr_type-------------------------------
6275 const TypeInstKlassPtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
6276   assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
6277   if( ptr == _ptr ) return this;
6278   return make(ptr, _klass, _interfaces, _offset, _flat_in_array);
6279 }
6280 
6281 
6282 bool TypeInstKlassPtr::must_be_exact() const {
6283   if (!_klass->is_loaded())  return false;
6284   ciInstanceKlass* ik = _klass->as_instance_klass();
6285   if (ik->is_final())  return true;  // cannot clear xk
6286   return false;
6287 }
6288 
6289 //-----------------------------cast_to_exactness-------------------------------
6290 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6291   if (klass_is_exact == (_ptr == Constant)) return this;
6292   if (must_be_exact()) return this;
6293   ciKlass* k = klass();
6294   FlatInArray flat_in_array = compute_flat_in_array(k->as_instance_klass(), klass_is_exact);
6295   return make(klass_is_exact ? Constant : NotNull, k, _interfaces, _offset, flat_in_array);
6296 }
6297 
6298 
6299 //-----------------------------as_instance_type--------------------------------
6300 // Corresponding type for an instance of the given class.
6301 // It will be NotNull, and exact if and only if the klass type is exact.
6302 const TypeOopPtr* TypeInstKlassPtr::as_instance_type(bool klass_change) const {
6303   ciKlass* k = klass();
6304   bool xk = klass_is_exact();
6305   Compile* C = Compile::current();
6306   Dependencies* deps = C->dependencies();
6307   assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
6308   // Element is an instance
6309   bool klass_is_exact = false;
6310   const TypeInterfaces* interfaces = _interfaces;
6311   ciInstanceKlass* ik = k->as_instance_klass();
6312   if (k->is_loaded()) {
6313     // Try to set klass_is_exact.

6314     klass_is_exact = ik->is_final();
6315     if (!klass_is_exact && klass_change
6316         && deps != nullptr && UseUniqueSubclasses) {
6317       ciInstanceKlass* sub = ik->unique_concrete_subklass();
6318       if (sub != nullptr) {
6319         if (_interfaces->eq(sub)) {
6320           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6321           k = ik = sub;
6322           xk = sub->is_final();
6323         }
6324       }
6325     }
6326   }
6327 
6328   FlatInArray flat_in_array = compute_flat_in_array_if_unknown(ik, xk, _flat_in_array);
6329   return TypeInstPtr::make(TypePtr::BotPTR, k, interfaces, xk, nullptr, Offset(0), flat_in_array);
6330 }
6331 
6332 //------------------------------xmeet------------------------------------------
6333 // Compute the MEET of two types, return a new Type object.
6334 const Type    *TypeInstKlassPtr::xmeet( const Type *t ) const {
6335   // Perform a fast test for common case; meeting the same types together.
6336   if( this == t ) return this;  // Meeting same type-rep?
6337 
6338   // Current "this->_base" is Pointer
6339   switch (t->base()) {          // switch on original type
6340 
6341   case Int:                     // Mixing ints & oops happens when javac
6342   case Long:                    // reuses local variables
6343   case HalfFloatTop:
6344   case HalfFloatCon:
6345   case HalfFloatBot:
6346   case FloatTop:
6347   case FloatCon:
6348   case FloatBot:
6349   case DoubleTop:
6350   case DoubleCon:
6351   case DoubleBot:
6352   case NarrowOop:
6353   case NarrowKlass:
6354   case Bottom:                  // Ye Olde Default
6355     return Type::BOTTOM;
6356   case Top:
6357     return this;
6358 
6359   default:                      // All else is a mistake
6360     typerr(t);
6361 
6362   case AnyPtr: {                // Meeting to AnyPtrs
6363     // Found an AnyPtr type vs self-KlassPtr type
6364     const TypePtr *tp = t->is_ptr();
6365     Offset offset = meet_offset(tp->offset());
6366     PTR ptr = meet_ptr(tp->ptr());
6367     switch (tp->ptr()) {
6368     case TopPTR:
6369       return this;
6370     case Null:
6371       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6372     case AnyNull:
6373       return make(ptr, klass(), _interfaces, offset, _flat_in_array);
6374     case BotPTR:
6375     case NotNull:
6376       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6377     default: typerr(t);
6378     }
6379   }
6380 
6381   case RawPtr:
6382   case MetadataPtr:
6383   case OopPtr:
6384   case AryPtr:                  // Meet with AryPtr
6385   case InstPtr:                 // Meet with InstPtr
6386       return TypePtr::BOTTOM;
6387 
6388   //
6389   //             A-top         }
6390   //           /   |   \       }  Tops
6391   //       B-top A-any C-top   }
6392   //          | /  |  \ |      }  Any-nulls
6393   //       B-any   |   C-any   }
6394   //          |    |    |
6395   //       B-con A-con C-con   } constants; not comparable across classes
6396   //          |    |    |
6397   //       B-not   |   C-not   }
6398   //          | \  |  / |      }  not-nulls
6399   //       B-bot A-not C-bot   }
6400   //           \   |   /       }  Bottoms
6401   //             A-bot         }
6402   //
6403 
6404   case InstKlassPtr: {  // Meet two KlassPtr types
6405     const TypeInstKlassPtr *tkls = t->is_instklassptr();
6406     Offset  off     = meet_offset(tkls->offset());
6407     PTR  ptr     = meet_ptr(tkls->ptr());
6408     const TypeInterfaces* interfaces = meet_interfaces(tkls);
6409 
6410     ciKlass* res_klass = nullptr;
6411     bool res_xk = false;
6412     const FlatInArray flat_in_array = meet_flat_in_array(_flat_in_array, tkls->flat_in_array());
6413     switch (meet_instptr(ptr, interfaces, this, tkls, res_klass, res_xk)) {
6414       case UNLOADED:
6415         ShouldNotReachHere();
6416       case SUBTYPE:
6417       case NOT_SUBTYPE:
6418       case LCA:
6419       case QUICK: {
6420         assert(res_xk == (ptr == Constant), "");
6421         const Type* res = make(ptr, res_klass, interfaces, off, flat_in_array);
6422         return res;
6423       }
6424       default:
6425         ShouldNotReachHere();
6426     }
6427   } // End of case KlassPtr
6428   case AryKlassPtr: {                // All arrays inherit from Object class
6429     const TypeAryKlassPtr *tp = t->is_aryklassptr();
6430     Offset offset = meet_offset(tp->offset());
6431     PTR ptr = meet_ptr(tp->ptr());
6432     const TypeInterfaces* interfaces = meet_interfaces(tp);
6433     const TypeInterfaces* tp_interfaces = tp->_interfaces;
6434     const TypeInterfaces* this_interfaces = _interfaces;
6435 
6436     switch (ptr) {
6437     case TopPTR:
6438     case AnyNull:                // Fall 'down' to dual of object klass
6439       // For instances when a subclass meets a superclass we fall
6440       // below the centerline when the superclass is exact. We need to
6441       // do the same here.
6442       //
6443       // Flat in array: See explanation for meet with TypeInstPtr in TypeAryPtr::xmeet_helper().
6444       if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) &&
6445           !klass_is_exact() && !is_not_flat_in_array()) {
6446         return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset, tp->is_not_flat(), tp->is_not_null_free(), tp->is_flat(), tp->is_null_free(), tp->is_atomic(), tp->is_refined_type());
6447       } else {
6448         // cannot subclass, so the meet has to fall badly below the centerline
6449         ptr = NotNull;
6450         interfaces = _interfaces->intersection_with(tp->_interfaces);
6451         FlatInArray flat_in_array = meet_flat_in_array(_flat_in_array, NotFlat);
6452         return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, flat_in_array);
6453       }
6454     case Constant:
6455     case NotNull:
6456     case BotPTR: { // Fall down to object klass
6457       // LCA is object_klass, but if we subclass from the top we can do better
6458       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
6459         // If 'this' (InstPtr) is above the centerline and it is Object class
6460         // then we can subclass in the Java class hierarchy.
6461         // For instances when a subclass meets a superclass we fall
6462         // below the centerline when the superclass is exact. We need
6463         // to do the same here.
6464         //
6465         // Flat in array: See explanation for meet with TypeInstPtr in TypeAryPtr::xmeet_helper().
6466         if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) &&
6467             !klass_is_exact() && !is_not_flat_in_array()) {
6468           // that is, tp's array type is a subtype of my klass
6469           return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset, tp->is_not_flat(), tp->is_not_null_free(), tp->is_flat(), tp->is_null_free(), tp->is_atomic(), tp->is_refined_type());

6470         }
6471       }
6472       // The other case cannot happen, since I cannot be a subtype of an array.
6473       // The meet falls down to Object class below centerline.
6474       if( ptr == Constant )
6475         ptr = NotNull;
6476       interfaces = this_interfaces->intersection_with(tp_interfaces);
6477       FlatInArray flat_in_array = meet_flat_in_array(_flat_in_array, NotFlat);
6478       return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, flat_in_array);
6479     }
6480     default: typerr(t);
6481     }
6482   }
6483 
6484   } // End of switch
6485   return this;                  // Return the double constant
6486 }
6487 
6488 //------------------------------xdual------------------------------------------
6489 // Dual: compute field-by-field dual
6490 const Type* TypeInstKlassPtr::xdual() const {
6491   return new TypeInstKlassPtr(dual_ptr(), klass(), _interfaces, dual_offset(), dual_flat_in_array());
6492 }
6493 
6494 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) {
6495   static_assert(std::is_base_of<T2, T1>::value, "");
6496   if (!this_one->is_loaded() || !other->is_loaded()) {
6497     return false;
6498   }
6499   if (!this_one->is_instance_type(other)) {
6500     return false;
6501   }
6502 
6503   if (!other_exact) {
6504     return false;
6505   }
6506 
6507   if (other->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces->empty()) {
6508     return true;
6509   }
6510 
6511   return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);
6512 }
6513 
6514 bool TypeInstKlassPtr::might_be_an_array() const {
6515   if (!instance_klass()->is_java_lang_Object()) {
6516     // TypeInstKlassPtr can be an array only if it is java.lang.Object: the only supertype of array types.
6517     return false;
6518   }
6519   if (interfaces()->has_non_array_interface()) {
6520     // Arrays only implement Cloneable and Serializable. If we see any other interface, [this] cannot be an array.
6521     return false;
6522   }
6523   // Cannot prove it's not an array.
6524   return true;
6525 }
6526 
6527 bool TypeInstKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6528   return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
6529 }
6530 
6531 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_instance(const T1* this_one, const T2* other) {
6532   static_assert(std::is_base_of<T2, T1>::value, "");
6533   if (!this_one->is_loaded() || !other->is_loaded()) {
6534     return false;
6535   }
6536   if (!this_one->is_instance_type(other)) {
6537     return false;
6538   }
6539   return this_one->klass()->equals(other->klass()) && this_one->_interfaces->eq(other->_interfaces);
6540 }
6541 
6542 bool TypeInstKlassPtr::is_same_java_type_as_helper(const TypeKlassPtr* other) const {
6543   return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
6544 }
6545 
6546 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) {
6547   static_assert(std::is_base_of<T2, T1>::value, "");
6548   if (!this_one->is_loaded() || !other->is_loaded()) {
6549     return true;
6550   }
6551 
6552   if (this_one->is_array_type(other)) {
6553     return !this_exact && this_one->klass()->equals(ciEnv::current()->Object_klass())  && other->_interfaces->contains(this_one->_interfaces);
6554   }
6555 
6556   assert(this_one->is_instance_type(other), "unsupported");
6557 
6558   if (this_exact && other_exact) {
6559     return this_one->is_java_subtype_of(other);
6560   }
6561 
6562   if (!this_one->klass()->is_subtype_of(other->klass()) && !other->klass()->is_subtype_of(this_one->klass())) {
6563     return false;
6564   }
6565 
6566   if (this_exact) {
6567     return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);
6568   }
6569 
6570   return true;
6571 }
6572 
6573 bool TypeInstKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6574   return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
6575 }
6576 
6577 const TypeKlassPtr* TypeInstKlassPtr::try_improve() const {
6578   if (!UseUniqueSubclasses) {
6579     return this;
6580   }
6581   ciKlass* k = klass();
6582   Compile* C = Compile::current();
6583   Dependencies* deps = C->dependencies();
6584   assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");

6585   if (k->is_loaded()) {
6586     ciInstanceKlass* ik = k->as_instance_klass();
6587     if (deps != nullptr) {


6588       ciInstanceKlass* sub = ik->unique_concrete_subklass();
6589       if (sub != nullptr) {
6590         bool improve_to_exact = sub->is_final() && _ptr == NotNull;
6591         const TypeInstKlassPtr* improved = TypeInstKlassPtr::make(improve_to_exact ? Constant : _ptr, sub, _offset);
6592         if (improved->_interfaces->contains(_interfaces)) {
6593           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6594           return improved;


6595         }
6596       }
6597     }
6598   }
6599   return this;
6600 }
6601 
6602 bool TypeInstKlassPtr::can_be_inline_array() const {
6603   return _klass->equals(ciEnv::current()->Object_klass()) && TypeAryKlassPtr::_array_interfaces->contains(_interfaces);
6604 }
6605 
6606 #ifndef PRODUCT
6607 void TypeInstKlassPtr::dump2(Dict& d, uint depth, outputStream* st) const {
6608   st->print("instklassptr:");
6609   klass()->print_name_on(st);
6610   _interfaces->dump(st);
6611   st->print(":%s", ptr_msg[_ptr]);
6612   dump_offset(st);
6613   dump_flat_in_array(_flat_in_array, st);
6614 }
6615 #endif // PRODUCT
6616 
6617 bool TypeAryKlassPtr::can_be_inline_array() const {
6618   return _elem->isa_instklassptr() && _elem->is_instklassptr()->_klass->can_be_inline_klass();
6619 }
6620 
6621 bool TypeInstPtr::can_be_inline_array() const {
6622   return _klass->equals(ciEnv::current()->Object_klass()) && TypeAryPtr::_array_interfaces->contains(_interfaces);
6623 }
6624 
6625 bool TypeAryPtr::can_be_inline_array() const {
6626   return elem()->make_ptr() && elem()->make_ptr()->isa_instptr() && elem()->make_ptr()->is_instptr()->_klass->can_be_inline_klass();
6627 }
6628 
6629 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, Offset offset, bool not_flat, bool not_null_free, bool flat, bool null_free, bool atomic, bool refined_type) {
6630   return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset, not_flat, not_null_free, flat, null_free, atomic, refined_type))->hashcons();
6631 }
6632 
6633 const TypeAryKlassPtr* TypeAryKlassPtr::make(PTR ptr, ciKlass* k, Offset offset, InterfaceHandling interface_handling, bool not_flat, bool not_null_free, bool flat, bool null_free, bool atomic, bool refined_type) {
6634   const Type* etype;
6635   if (k->is_obj_array_klass()) {
6636     // Element is an object array. Recursively call ourself.
6637     ciKlass* eklass = k->as_obj_array_klass()->element_klass();
6638     etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6639     k = nullptr;
6640   } else if (k->is_type_array_klass()) {
6641     // Element is an typeArray
6642     etype = get_const_basic_type(k->as_type_array_klass()->element_type());

6643   } else {
6644     ShouldNotReachHere();

6645   }
6646 
6647   return TypeAryKlassPtr::make(ptr, etype, k, offset, not_flat, not_null_free, flat, null_free, atomic, refined_type);
6648 }
6649 
6650 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6651   ciArrayKlass* k = klass->as_array_klass();
6652   if (k->is_refined()) {
6653     return TypeAryKlassPtr::make(Constant, k, Offset(0), interface_handling, !k->is_flat_array_klass(), !k->is_elem_null_free(),
6654                                  k->is_flat_array_klass(), k->is_elem_null_free(), k->is_elem_atomic(), true);
6655   } else {
6656     // Use the default combination to canonicalize all non-refined klass pointers
6657     return TypeAryKlassPtr::make(Constant, k, Offset(0), interface_handling, true, true, false, false, true, false);
6658   }
6659 }
6660 
6661 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_non_refined() const {
6662   assert(is_refined_type(), "must be a refined type");
6663   PTR ptr = _ptr;
6664   // There can be multiple refined array types corresponding to a single unrefined type
6665   if (ptr == NotNull && elem()->is_klassptr()->klass_is_exact()) {
6666     ptr = Constant;
6667   }
6668   return make(ptr, elem(), nullptr, _offset, true, true, false, false, true, false);
6669 }
6670 
6671 // Get the (non-)refined array klass ptr
6672 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_refined_array_klass_ptr(bool refined) const {
6673   if ((refined == is_refined_type()) || !klass_is_exact() || !exact_klass()->is_obj_array_klass()) {
6674     return this;
6675   }
6676   ciArrayKlass* k = exact_klass()->as_array_klass();
6677   k = ciObjArrayKlass::make(k->element_klass(), refined);
6678   return make(k, trust_interfaces);
6679 }
6680 
6681 //------------------------------eq---------------------------------------------
6682 // Structural equality check for Type representations
6683 bool TypeAryKlassPtr::eq(const Type *t) const {
6684   const TypeAryKlassPtr *p = t->is_aryklassptr();
6685   return
6686     _elem == p->_elem &&  // Check array
6687     _flat == p->_flat &&
6688     _not_flat == p->_not_flat &&
6689     _null_free == p->_null_free &&
6690     _not_null_free == p->_not_null_free &&
6691     _atomic == p->_atomic &&
6692     _refined_type == p->_refined_type &&
6693     TypeKlassPtr::eq(p);  // Check sub-parts
6694 }
6695 
6696 //------------------------------hash-------------------------------------------
6697 // Type-specific hashing function.
6698 uint TypeAryKlassPtr::hash(void) const {
6699   return (uint)(uintptr_t)_elem + TypeKlassPtr::hash() + (uint)(_not_flat ? 43 : 0) +
6700       (uint)(_not_null_free ? 44 : 0) + (uint)(_flat ? 45 : 0) + (uint)(_null_free ? 46 : 0)  + (uint)(_atomic ? 47 : 0) + (uint)(_refined_type ? 48 : 0);
6701 }
6702 
6703 //----------------------compute_klass------------------------------------------
6704 // Compute the defining klass for this class
6705 ciKlass* TypeAryPtr::compute_klass() const {
6706   // Compute _klass based on element type.
6707   ciKlass* k_ary = nullptr;
6708   const TypeInstPtr *tinst;
6709   const TypeAryPtr *tary;
6710   const Type* el = elem();
6711   if (el->isa_narrowoop()) {
6712     el = el->make_ptr();
6713   }
6714 
6715   // Get element klass
6716   if ((tinst = el->isa_instptr()) != nullptr) {
6717     // Leave k_ary at nullptr.
6718   } else if ((tary = el->isa_aryptr()) != nullptr) {
6719     // Leave k_ary at nullptr.
6720   } else if ((el->base() == Type::Top) ||
6721              (el->base() == Type::Bottom)) {
6722     // element type of Bottom occurs from meet of basic type
6723     // and object; Top occurs when doing join on Bottom.
6724     // Leave k_ary at null.
6725   } else {
6726     assert(!el->isa_int(), "integral arrays must be pre-equipped with a class");
6727     // Compute array klass directly from basic type
6728     k_ary = ciTypeArrayKlass::make(el->basic_type());
6729   }
6730   return k_ary;
6731 }
6732 
6733 //------------------------------klass------------------------------------------
6734 // Return the defining klass for this class
6735 ciKlass* TypeAryPtr::klass() const {
6736   if( _klass ) return _klass;   // Return cached value, if possible
6737 
6738   // Oops, need to compute _klass and cache it
6739   ciKlass* k_ary = compute_klass();
6740 
6741   if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) {
6742     // The _klass field acts as a cache of the underlying
6743     // ciKlass for this array type.  In order to set the field,
6744     // we need to cast away const-ness.
6745     //
6746     // IMPORTANT NOTE: we *never* set the _klass field for the
6747     // type TypeAryPtr::OOPS.  This Type is shared between all
6748     // active compilations.  However, the ciKlass which represents
6749     // this Type is *not* shared between compilations, so caching
6750     // this value would result in fetching a dangling pointer.
6751     //
6752     // Recomputing the underlying ciKlass for each request is
6753     // a bit less efficient than caching, but calls to
6754     // TypeAryPtr::OOPS->klass() are not common enough to matter.
6755     ((TypeAryPtr*)this)->_klass = k_ary;
6756   }
6757   return k_ary;
6758 }
6759 
6760 // Is there a single ciKlass* that can represent that type?
6761 ciKlass* TypeAryPtr::exact_klass_helper() const {
6762   if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) {
6763     ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper();
6764     if (k == nullptr) {
6765       return nullptr;
6766     }
6767     if (k->is_array_klass() && k->as_array_klass()->is_refined()) {
6768       // We have no mechanism to create an array of refined arrays
6769       k = ciObjArrayKlass::make(k->as_array_klass()->element_klass(), false);
6770     }
6771     if (klass_is_exact()) {
6772       return ciObjArrayKlass::make(k, true, is_null_free(), is_atomic());
6773     } else {
6774       // We may reach here if called recursively, must be an unrefined type then
6775       return ciObjArrayKlass::make(k, false);
6776     }
6777   }
6778 
6779   return klass();
6780 }
6781 
6782 const Type* TypeAryPtr::base_element_type(int& dims) const {
6783   const Type* elem = this->elem();
6784   dims = 1;
6785   while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) {
6786     elem = elem->make_ptr()->is_aryptr()->elem();
6787     dims++;
6788   }
6789   return elem;
6790 }
6791 
6792 //------------------------------add_offset-------------------------------------
6793 // Access internals of klass object
6794 const TypePtr* TypeAryKlassPtr::add_offset(intptr_t offset) const {
6795   return make(_ptr, elem(), klass(), xadd_offset(offset), is_not_flat(), is_not_null_free(), _flat, _null_free, _atomic, _refined_type);
6796 }
6797 
6798 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const {
6799   return make(_ptr, elem(), klass(), Offset(offset), is_not_flat(), is_not_null_free(), _flat, _null_free, _atomic, _refined_type);
6800 }
6801 
6802 //------------------------------cast_to_ptr_type-------------------------------
6803 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6804   assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6805   if (ptr == _ptr) return this;
6806   return make(ptr, elem(), _klass, _offset, is_not_flat(), is_not_null_free(), _flat, _null_free, _atomic, _refined_type);
6807 }
6808 
6809 bool TypeAryKlassPtr::must_be_exact() const {
6810   assert(klass_is_exact(), "precondition");
6811   if (_elem == Type::BOTTOM || _elem == Type::TOP) {
6812     return false;
6813   }
6814   const TypeKlassPtr* elem = _elem->isa_klassptr();
6815   if (elem == nullptr) {
6816     // primitive arrays
6817     return true;
6818   }
6819 
6820   // refined types are final
6821   return _refined_type;
6822 }
6823 
6824 //-----------------------------cast_to_exactness-------------------------------
6825 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6826   if (klass_is_exact == this->klass_is_exact()) {
6827     return this;
6828   }
6829   if (!klass_is_exact && must_be_exact()) {
6830     return this;
6831   }
6832   const Type* elem = this->elem();
6833   if (elem->isa_klassptr() && !klass_is_exact) {
6834     elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
6835   }


6836 
6837   if (klass_is_exact) {
6838     // cast_to_exactness(true) really means get the LCA of all values represented by this
6839     // TypeAryKlassPtr. As a result, it must be an unrefined klass pointer.
6840     return make(Constant, elem, nullptr, _offset, true, true, false, false, true, false);
6841   } else {
6842     // cast_to_exactness(false) means get the TypeAryKlassPtr representing all values that subtype
6843     // this value
6844     bool not_inline = !_elem->isa_instklassptr() || !_elem->is_instklassptr()->instance_klass()->can_be_inline_klass();
6845     bool not_flat = !UseArrayFlattening || not_inline ||
6846                     (_elem->isa_instklassptr() && _elem->is_instklassptr()->instance_klass()->is_inlinetype() && !_elem->is_instklassptr()->instance_klass()->maybe_flat_in_array());
6847     bool not_null_free = not_inline;
6848     bool atomic = not_flat;
6849     return make(NotNull, elem, nullptr, _offset, not_flat, not_null_free, false, false, atomic, false);
6850   }
6851 }
6852 
6853 //-----------------------------as_instance_type--------------------------------
6854 // Corresponding type for an instance of the given class.
6855 // It will be NotNull, and exact if and only if the klass type is exact.
6856 const TypeOopPtr* TypeAryKlassPtr::as_instance_type(bool klass_change) const {
6857   ciKlass* k = klass();
6858   bool    xk = klass_is_exact();
6859   const Type* el = nullptr;
6860   if (elem()->isa_klassptr()) {
6861     el = elem()->is_klassptr()->as_instance_type(false)->cast_to_exactness(false);
6862     k = nullptr;
6863   } else {
6864     el = elem();
6865   }
6866   bool null_free = _null_free;
6867   if (null_free && el->isa_ptr()) {
6868     el = el->is_ptr()->join_speculative(TypePtr::NOTNULL);
6869   }
6870   return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS, false, is_flat(), is_not_flat(), is_not_null_free(), is_atomic()), k, xk, Offset(0));
6871 }
6872 
6873 
6874 //------------------------------xmeet------------------------------------------
6875 // Compute the MEET of two types, return a new Type object.
6876 const Type    *TypeAryKlassPtr::xmeet( const Type *t ) const {
6877   // Perform a fast test for common case; meeting the same types together.
6878   if( this == t ) return this;  // Meeting same type-rep?
6879 
6880   // Current "this->_base" is Pointer
6881   switch (t->base()) {          // switch on original type
6882 
6883   case Int:                     // Mixing ints & oops happens when javac
6884   case Long:                    // reuses local variables
6885   case HalfFloatTop:
6886   case HalfFloatCon:
6887   case HalfFloatBot:
6888   case FloatTop:
6889   case FloatCon:
6890   case FloatBot:
6891   case DoubleTop:
6892   case DoubleCon:
6893   case DoubleBot:
6894   case NarrowOop:
6895   case NarrowKlass:
6896   case Bottom:                  // Ye Olde Default
6897     return Type::BOTTOM;
6898   case Top:
6899     return this;
6900 
6901   default:                      // All else is a mistake
6902     typerr(t);
6903 
6904   case AnyPtr: {                // Meeting to AnyPtrs
6905     // Found an AnyPtr type vs self-KlassPtr type
6906     const TypePtr *tp = t->is_ptr();
6907     Offset offset = meet_offset(tp->offset());
6908     PTR ptr = meet_ptr(tp->ptr());
6909     switch (tp->ptr()) {
6910     case TopPTR:
6911       return this;
6912     case Null:
6913       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6914     case AnyNull:
6915       return make(ptr, _elem, klass(), offset, is_not_flat(), is_not_null_free(), is_flat(), is_null_free(), is_atomic(), is_refined_type());
6916     case BotPTR:
6917     case NotNull:
6918       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6919     default: typerr(t);
6920     }
6921   }
6922 
6923   case RawPtr:
6924   case MetadataPtr:
6925   case OopPtr:
6926   case AryPtr:                  // Meet with AryPtr
6927   case InstPtr:                 // Meet with InstPtr
6928     return TypePtr::BOTTOM;
6929 
6930   //
6931   //             A-top         }
6932   //           /   |   \       }  Tops
6933   //       B-top A-any C-top   }
6934   //          | /  |  \ |      }  Any-nulls
6935   //       B-any   |   C-any   }
6936   //          |    |    |
6937   //       B-con A-con C-con   } constants; not comparable across classes
6938   //          |    |    |
6939   //       B-not   |   C-not   }
6940   //          | \  |  / |      }  not-nulls
6941   //       B-bot A-not C-bot   }
6942   //           \   |   /       }  Bottoms
6943   //             A-bot         }
6944   //
6945 
6946   case AryKlassPtr: {  // Meet two KlassPtr types
6947     const TypeAryKlassPtr *tap = t->is_aryklassptr();
6948     Offset off = meet_offset(tap->offset());
6949     const Type* elem = _elem->meet(tap->_elem);

6950     PTR ptr = meet_ptr(tap->ptr());
6951     ciKlass* res_klass = nullptr;
6952     bool res_xk = false;
6953     bool res_flat = false;
6954     bool res_not_flat = false;
6955     bool res_not_null_free = false;
6956     bool res_atomic = false;
6957     MeetResult res = meet_aryptr(ptr, elem, this, tap,
6958                                  res_klass, res_xk, res_flat, res_not_flat, res_not_null_free, res_atomic);
6959     assert(res_xk == (ptr == Constant), "");
6960     bool flat = meet_flat(tap->_flat);
6961     bool null_free = meet_null_free(tap->_null_free);
6962     bool atomic = meet_atomic(tap->_atomic);
6963     bool refined_type = _refined_type && tap->_refined_type;
6964     if (res == NOT_SUBTYPE) {
6965       flat = false;
6966       null_free = false;
6967       atomic = false;
6968       refined_type = false;
6969     } else if (res == SUBTYPE) {
6970       if (above_centerline(tap->ptr()) && !above_centerline(this->ptr())) {
6971         flat = _flat;
6972         null_free = _null_free;
6973         atomic = _atomic;
6974         refined_type = _refined_type;
6975       } else if (above_centerline(this->ptr()) && !above_centerline(tap->ptr())) {
6976         flat = tap->_flat;
6977         null_free = tap->_null_free;
6978         atomic = tap->_atomic;
6979         refined_type = tap->_refined_type;
6980       } else if (above_centerline(this->ptr()) && above_centerline(tap->ptr())) {
6981         flat = _flat || tap->_flat;
6982         null_free = _null_free || tap->_null_free;
6983         atomic = _atomic || tap->_atomic;
6984         refined_type = _refined_type || tap->_refined_type;
6985       } else if (res_xk && _refined_type != tap->_refined_type) {
6986         // This can happen if the phi emitted by LibraryCallKit::load_default_refined_array_klass/load_non_refined_array_klass
6987         // is processed before the typeArray guard is folded. Both inputs are constant but the input corresponding to the
6988         // typeArray will go away. Don't constant fold it yet but wait for the control input to collapse.
6989         ptr = PTR::NotNull;
6990       }
6991     }
6992     return make(ptr, elem, res_klass, off, res_not_flat, res_not_null_free, flat, null_free, atomic, refined_type);
6993   } // End of case KlassPtr
6994   case InstKlassPtr: {
6995     const TypeInstKlassPtr *tp = t->is_instklassptr();
6996     Offset offset = meet_offset(tp->offset());
6997     PTR ptr = meet_ptr(tp->ptr());
6998     const TypeInterfaces* interfaces = meet_interfaces(tp);
6999     const TypeInterfaces* tp_interfaces = tp->_interfaces;
7000     const TypeInterfaces* this_interfaces = _interfaces;
7001 
7002     switch (ptr) {
7003     case TopPTR:
7004     case AnyNull:                // Fall 'down' to dual of object klass
7005       // For instances when a subclass meets a superclass we fall
7006       // below the centerline when the superclass is exact. We need to
7007       // do the same here.
7008       //
7009       // Flat in array: See explanation for meet with TypeInstPtr in TypeAryPtr::xmeet_helper().
7010       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
7011           !tp->klass_is_exact() && !tp->is_not_flat_in_array()) {
7012         return TypeAryKlassPtr::make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), is_flat(), is_null_free(), is_atomic(), is_refined_type());
7013       } else {
7014         // cannot subclass, so the meet has to fall badly below the centerline
7015         ptr = NotNull;
7016         interfaces = this_interfaces->intersection_with(tp->_interfaces);
7017         FlatInArray flat_in_array = meet_flat_in_array(NotFlat, tp->flat_in_array());
7018         return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, flat_in_array);
7019       }
7020     case Constant:
7021     case NotNull:
7022     case BotPTR: { // Fall down to object klass
7023       // LCA is object_klass, but if we subclass from the top we can do better
7024       if (above_centerline(tp->ptr())) {
7025         // If 'tp'  is above the centerline and it is Object class
7026         // then we can subclass in the Java class hierarchy.
7027         // For instances when a subclass meets a superclass we fall
7028         // below the centerline when the superclass is exact. We need
7029         // to do the same here.
7030         //
7031         // Flat in array: See explanation for meet with TypeInstPtr in TypeAryPtr::xmeet_helper().
7032         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
7033             !tp->klass_is_exact() && !tp->is_not_flat_in_array()) {
7034           // that is, my array type is a subtype of 'tp' klass
7035           return make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), is_flat(), is_null_free(), is_atomic(), is_refined_type());
7036         }
7037       }
7038       // The other case cannot happen, since t cannot be a subtype of an array.
7039       // The meet falls down to Object class below centerline.
7040       if (ptr == Constant)
7041         ptr = NotNull;
7042       interfaces = this_interfaces->intersection_with(tp_interfaces);
7043       FlatInArray flat_in_array = meet_flat_in_array(NotFlat, tp->flat_in_array());
7044       return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, tp->flat_in_array());
7045     }
7046     default: typerr(t);
7047     }
7048   }
7049 
7050   } // End of switch
7051   return this;                  // Return the double constant
7052 }
7053 
7054 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) {
7055   static_assert(std::is_base_of<T2, T1>::value, "");
7056 
7057   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
7058     return true;
7059   }
7060 
7061   int dummy;
7062   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
7063 
7064   if (!this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
7065     return false;
7066   }
7067 
7068   if (this_one->is_instance_type(other)) {
7069     return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces) &&
7070            other_exact;
7071   }
7072 
7073   assert(this_one->is_array_type(other), "");
7074   const T1* other_ary = this_one->is_array_type(other);
7075   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
7076   if (other_top_or_bottom) {
7077     return false;
7078   }
7079 
7080   const TypePtr* other_elem = other_ary->elem()->make_ptr();
7081   const TypePtr* this_elem = this_one->elem()->make_ptr();
7082   if (this_elem != nullptr && other_elem != nullptr) {
7083     if (other->is_null_free() && !this_one->is_null_free()) {
7084       return false; // A nullable array can't be a subtype of a null-free array
7085     }
7086     return this_one->is_reference_type(this_elem)->is_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
7087   }
7088   if (this_elem == nullptr && other_elem == nullptr) {
7089     return this_one->klass()->is_subtype_of(other->klass());
7090   }
7091   return false;
7092 }
7093 
7094 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
7095   return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
7096 }
7097 
7098 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other) {
7099   static_assert(std::is_base_of<T2, T1>::value, "");
7100 
7101   int dummy;
7102   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
7103 
7104   if (!this_one->is_array_type(other) ||
7105       !this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
7106     return false;
7107   }
7108   const T1* other_ary = this_one->is_array_type(other);
7109   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
7110 
7111   if (other_top_or_bottom) {
7112     return false;
7113   }
7114 
7115   const TypePtr* other_elem = other_ary->elem()->make_ptr();
7116   const TypePtr* this_elem = this_one->elem()->make_ptr();
7117   if (other_elem != nullptr && this_elem != nullptr) {
7118     return this_one->is_reference_type(this_elem)->is_same_java_type_as(this_one->is_reference_type(other_elem));
7119   }
7120   if (other_elem == nullptr && this_elem == nullptr) {
7121     return this_one->klass()->equals(other->klass());
7122   }
7123   return false;
7124 }
7125 
7126 bool TypeAryKlassPtr::is_same_java_type_as_helper(const TypeKlassPtr* other) const {
7127   return TypePtr::is_same_java_type_as_helper_for_array(this, other);
7128 }
7129 
7130 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) {
7131   static_assert(std::is_base_of<T2, T1>::value, "");
7132   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
7133     return true;
7134   }
7135   if (!this_one->is_loaded() || !other->is_loaded()) {
7136     return true;
7137   }
7138   if (this_one->is_instance_type(other)) {
7139     return other->klass()->equals(ciEnv::current()->Object_klass()) &&
7140            this_one->_interfaces->contains(other->_interfaces);
7141   }
7142 
7143   int dummy;
7144   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
7145   if (this_top_or_bottom) {
7146     return true;
7147   }
7148 
7149   assert(this_one->is_array_type(other), "");
7150 
7151   const T1* other_ary = this_one->is_array_type(other);
7152   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
7153   if (other_top_or_bottom) {
7154     return true;
7155   }
7156   if (this_exact && other_exact) {
7157     return this_one->is_java_subtype_of(other);
7158   }
7159 
7160   const TypePtr* this_elem = this_one->elem()->make_ptr();
7161   const TypePtr* other_elem = other_ary->elem()->make_ptr();
7162   if (other_elem != nullptr && this_elem != nullptr) {
7163     return this_one->is_reference_type(this_elem)->maybe_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
7164   }
7165   if (other_elem == nullptr && this_elem == nullptr) {
7166     return this_one->klass()->is_subtype_of(other->klass());
7167   }
7168   return false;
7169 }
7170 
7171 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
7172   return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
7173 }
7174 
7175 //------------------------------xdual------------------------------------------
7176 // Dual: compute field-by-field dual
7177 const Type    *TypeAryKlassPtr::xdual() const {
7178   return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset(), !is_not_flat(), !is_not_null_free(), dual_flat(), dual_null_free(), dual_atomic(), _refined_type);
7179 }
7180 
7181 // Is there a single ciKlass* that can represent that type?
7182 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
7183   if (elem()->isa_klassptr()) {
7184     ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
7185     if (k == nullptr) {
7186       return nullptr;
7187     }
7188     assert(!k->is_array_klass() || !k->as_array_klass()->is_refined(), "no mechanism to create an array of refined arrays %s", k->name()->as_utf8());
7189     k = ciArrayKlass::make(k, is_null_free(), is_atomic(), _refined_type);
7190     return k;
7191   }
7192 
7193   return klass();
7194 }
7195 
7196 ciKlass* TypeAryKlassPtr::klass() const {
7197   if (_klass != nullptr) {
7198     return _klass;
7199   }
7200   ciKlass* k = nullptr;
7201   if (elem()->isa_klassptr()) {
7202     // leave null
7203   } else if ((elem()->base() == Type::Top) ||
7204              (elem()->base() == Type::Bottom)) {
7205   } else {
7206     k = ciTypeArrayKlass::make(elem()->basic_type());
7207     ((TypeAryKlassPtr*)this)->_klass = k;
7208   }
7209   return k;
7210 }
7211 
7212 //------------------------------dump2------------------------------------------
7213 // Dump Klass Type
7214 #ifndef PRODUCT
7215 void TypeAryKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
7216   st->print("aryklassptr:[");
7217   _elem->dump2(d, depth, st);
7218   _interfaces->dump(st);
7219   st->print(":%s", ptr_msg[_ptr]);
7220   if (_flat) st->print(":flat");
7221   if (_null_free) st->print(":null free");
7222   if (_atomic) st->print(":atomic");
7223   if (_refined_type) st->print(":refined_type");
7224   if (Verbose) {
7225     if (_not_flat) st->print(":not flat");
7226     if (_not_null_free) st->print(":nullable");
7227   }
7228   dump_offset(st);
7229 }
7230 #endif
7231 
7232 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
7233   const Type* elem = this->elem();
7234   dims = 1;
7235   while (elem->isa_aryklassptr()) {
7236     elem = elem->is_aryklassptr()->elem();
7237     dims++;
7238   }
7239   return elem;
7240 }
7241 
7242 //=============================================================================
7243 // Convenience common pre-built types.
7244 
7245 //------------------------------make-------------------------------------------
7246 const TypeFunc *TypeFunc::make(const TypeTuple *domain_sig, const TypeTuple* domain_cc,
7247                                const TypeTuple *range_sig, const TypeTuple *range_cc) {
7248   return (TypeFunc*)(new TypeFunc(domain_sig, domain_cc, range_sig, range_cc))->hashcons();
7249 }
7250 
7251 const TypeFunc *TypeFunc::make(const TypeTuple *domain, const TypeTuple *range) {
7252   return make(domain, domain, range, range);
7253 }
7254 
7255 //------------------------------osr_domain-----------------------------
7256 const TypeTuple* osr_domain() {
7257   const Type **fields = TypeTuple::fields(2);
7258   fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM;  // address of osr buffer
7259   return TypeTuple::make(TypeFunc::Parms+1, fields);
7260 }
7261 
7262 //------------------------------make-------------------------------------------
7263 const TypeFunc* TypeFunc::make(ciMethod* method, bool is_osr_compilation) {
7264   Compile* C = Compile::current();
7265   const TypeFunc* tf = nullptr;
7266   if (!is_osr_compilation) {
7267     tf = C->last_tf(method); // check cache
7268     if (tf != nullptr)  return tf;  // The hit rate here is almost 50%.
7269   }
7270   // Inline types are not passed/returned by reference, instead each field of
7271   // the inline type is passed/returned as an argument. We maintain two views of
7272   // the argument/return list here: one based on the signature (with an inline
7273   // type argument/return as a single slot), one based on the actual calling
7274   // convention (with an inline type argument/return as a list of its fields).
7275   bool has_scalar_args = method->has_scalarized_args() && !is_osr_compilation;
7276   // Fall back to the non-scalarized calling convention when compiling a call via a mismatching method
7277   if (method != C->method() && method->get_Method()->mismatch()) {
7278     has_scalar_args = false;
7279   }
7280   const TypeTuple* domain_sig = is_osr_compilation ? osr_domain() : TypeTuple::make_domain(method, ignore_interfaces, false);
7281   const TypeTuple* domain_cc = has_scalar_args ? TypeTuple::make_domain(method, ignore_interfaces, true) : domain_sig;
7282   ciSignature* sig = method->signature();
7283   bool has_scalar_ret = !method->is_native() && sig->return_type()->is_inlinetype() && sig->return_type()->as_inline_klass()->can_be_returned_as_fields();
7284   const TypeTuple* range_sig = TypeTuple::make_range(sig, ignore_interfaces, false);
7285   const TypeTuple* range_cc = has_scalar_ret ? TypeTuple::make_range(sig, ignore_interfaces, true) : range_sig;
7286   tf = TypeFunc::make(domain_sig, domain_cc, range_sig, range_cc);
7287   if (!is_osr_compilation) {
7288     C->set_last_tf(method, tf);  // fill cache
7289   }



7290   return tf;
7291 }
7292 
7293 //------------------------------meet-------------------------------------------
7294 // Compute the MEET of two types.  It returns a new Type object.
7295 const Type *TypeFunc::xmeet( const Type *t ) const {
7296   // Perform a fast test for common case; meeting the same types together.
7297   if( this == t ) return this;  // Meeting same type-rep?
7298 
7299   // Current "this->_base" is Func
7300   switch (t->base()) {          // switch on original type
7301 
7302   case Bottom:                  // Ye Olde Default
7303     return t;
7304 
7305   default:                      // All else is a mistake
7306     typerr(t);
7307 
7308   case Top:
7309     break;
7310   }
7311   return this;                  // Return the double constant
7312 }
7313 
7314 //------------------------------xdual------------------------------------------
7315 // Dual: compute field-by-field dual
7316 const Type *TypeFunc::xdual() const {
7317   return this;
7318 }
7319 
7320 //------------------------------eq---------------------------------------------
7321 // Structural equality check for Type representations
7322 bool TypeFunc::eq( const Type *t ) const {
7323   const TypeFunc *a = (const TypeFunc*)t;
7324   return _domain_sig == a->_domain_sig &&
7325     _domain_cc == a->_domain_cc &&
7326     _range_sig == a->_range_sig &&
7327     _range_cc == a->_range_cc;
7328 }
7329 
7330 //------------------------------hash-------------------------------------------
7331 // Type-specific hashing function.
7332 uint TypeFunc::hash(void) const {
7333   return (uint)(intptr_t)_domain_sig + (uint)(intptr_t)_domain_cc + (uint)(intptr_t)_range_sig + (uint)(intptr_t)_range_cc;
7334 }
7335 
7336 //------------------------------dump2------------------------------------------
7337 // Dump Function Type
7338 #ifndef PRODUCT
7339 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
7340   if( _range_sig->cnt() <= Parms )
7341     st->print("void");
7342   else {
7343     uint i;
7344     for (i = Parms; i < _range_sig->cnt()-1; i++) {
7345       _range_sig->field_at(i)->dump2(d,depth,st);
7346       st->print("/");
7347     }
7348     _range_sig->field_at(i)->dump2(d,depth,st);
7349   }
7350   st->print(" ");
7351   st->print("( ");
7352   if( !depth || d[this] ) {     // Check for recursive dump
7353     st->print("...)");
7354     return;
7355   }
7356   d.Insert((void*)this,(void*)this);    // Stop recursion
7357   if (Parms < _domain_sig->cnt())
7358     _domain_sig->field_at(Parms)->dump2(d,depth-1,st);
7359   for (uint i = Parms+1; i < _domain_sig->cnt(); i++) {
7360     st->print(", ");
7361     _domain_sig->field_at(i)->dump2(d,depth-1,st);
7362   }
7363   st->print(" )");
7364 }
7365 #endif
7366 
7367 //------------------------------singleton--------------------------------------
7368 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
7369 // constants (Ldi nodes).  Singletons are integer, float or double constants
7370 // or a single symbol.
7371 bool TypeFunc::singleton(void) const {
7372   return false;                 // Never a singleton
7373 }
7374 
7375 bool TypeFunc::empty(void) const {
7376   return false;                 // Never empty
7377 }
7378 
7379 
7380 BasicType TypeFunc::return_type() const{
7381   if (range_sig()->cnt() == TypeFunc::Parms) {
7382     return T_VOID;
7383   }
7384   return range_sig()->field_at(TypeFunc::Parms)->basic_type();
7385 }
--- EOF ---