1 /*
   2  * Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "ci/ciMethodData.hpp"
  27 #include "ci/ciTypeFlow.hpp"
  28 #include "classfile/javaClasses.hpp"
  29 #include "classfile/symbolTable.hpp"
  30 #include "compiler/compileLog.hpp"
  31 #include "libadt/dict.hpp"
  32 #include "memory/oopFactory.hpp"
  33 #include "memory/resourceArea.hpp"
  34 #include "oops/instanceKlass.hpp"
  35 #include "oops/instanceMirrorKlass.hpp"
  36 #include "oops/objArrayKlass.hpp"
  37 #include "oops/typeArrayKlass.hpp"
  38 #include "opto/matcher.hpp"
  39 #include "opto/node.hpp"
  40 #include "opto/opcodes.hpp"
  41 #include "opto/type.hpp"
  42 #include "utilities/powerOfTwo.hpp"
  43 #include "utilities/stringUtils.hpp"
  44 
  45 // Portions of code courtesy of Clifford Click
  46 
  47 // Optimization - Graph Style
  48 
  49 // Dictionary of types shared among compilations.
  50 Dict* Type::_shared_type_dict = NULL;
  51 
  52 // Array which maps compiler types to Basic Types
  53 const Type::TypeInfo Type::_type_info[Type::lastype] = {
  54   { Bad,             T_ILLEGAL,    "bad",           false, Node::NotAMachineReg, relocInfo::none          },  // Bad
  55   { Control,         T_ILLEGAL,    "control",       false, 0,                    relocInfo::none          },  // Control
  56   { Bottom,          T_VOID,       "top",           false, 0,                    relocInfo::none          },  // Top
  57   { Bad,             T_INT,        "int:",          false, Op_RegI,              relocInfo::none          },  // Int
  58   { Bad,             T_LONG,       "long:",         false, Op_RegL,              relocInfo::none          },  // Long
  59   { Half,            T_VOID,       "half",          false, 0,                    relocInfo::none          },  // Half
  60   { Bad,             T_NARROWOOP,  "narrowoop:",    false, Op_RegN,              relocInfo::none          },  // NarrowOop
  61   { Bad,             T_NARROWKLASS,"narrowklass:",  false, Op_RegN,              relocInfo::none          },  // NarrowKlass
  62   { Bad,             T_ILLEGAL,    "tuple:",        false, Node::NotAMachineReg, relocInfo::none          },  // Tuple
  63   { Bad,             T_ARRAY,      "array:",        false, Node::NotAMachineReg, relocInfo::none          },  // Array
  64 
  65 #if defined(PPC64)
  66   { Bad,             T_ILLEGAL,    "vectormask:",   false, Op_RegVectMask,       relocInfo::none          },  // VectorMask.
  67   { Bad,             T_ILLEGAL,    "vectora:",      false, Op_VecA,              relocInfo::none          },  // VectorA.
  68   { Bad,             T_ILLEGAL,    "vectors:",      false, 0,                    relocInfo::none          },  // VectorS
  69   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_RegL,              relocInfo::none          },  // VectorD
  70   { Bad,             T_ILLEGAL,    "vectorx:",      false, Op_VecX,              relocInfo::none          },  // VectorX
  71   { Bad,             T_ILLEGAL,    "vectory:",      false, 0,                    relocInfo::none          },  // VectorY
  72   { Bad,             T_ILLEGAL,    "vectorz:",      false, 0,                    relocInfo::none          },  // VectorZ
  73 #elif defined(S390)
  74   { Bad,             T_ILLEGAL,    "vectormask:",   false, Op_RegVectMask,       relocInfo::none          },  // VectorMask.
  75   { Bad,             T_ILLEGAL,    "vectora:",      false, Op_VecA,              relocInfo::none          },  // VectorA.
  76   { Bad,             T_ILLEGAL,    "vectors:",      false, 0,                    relocInfo::none          },  // VectorS
  77   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_RegL,              relocInfo::none          },  // VectorD
  78   { Bad,             T_ILLEGAL,    "vectorx:",      false, 0,                    relocInfo::none          },  // VectorX
  79   { Bad,             T_ILLEGAL,    "vectory:",      false, 0,                    relocInfo::none          },  // VectorY
  80   { Bad,             T_ILLEGAL,    "vectorz:",      false, 0,                    relocInfo::none          },  // VectorZ
  81 #else // all other
  82   { Bad,             T_ILLEGAL,    "vectormask:",   false, Op_RegVectMask,       relocInfo::none          },  // VectorMask.
  83   { Bad,             T_ILLEGAL,    "vectora:",      false, Op_VecA,              relocInfo::none          },  // VectorA.
  84   { Bad,             T_ILLEGAL,    "vectors:",      false, Op_VecS,              relocInfo::none          },  // VectorS
  85   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_VecD,              relocInfo::none          },  // VectorD
  86   { Bad,             T_ILLEGAL,    "vectorx:",      false, Op_VecX,              relocInfo::none          },  // VectorX
  87   { Bad,             T_ILLEGAL,    "vectory:",      false, Op_VecY,              relocInfo::none          },  // VectorY
  88   { Bad,             T_ILLEGAL,    "vectorz:",      false, Op_VecZ,              relocInfo::none          },  // VectorZ
  89 #endif
  90   { Bad,             T_ADDRESS,    "anyptr:",       false, Op_RegP,              relocInfo::none          },  // AnyPtr
  91   { Bad,             T_ADDRESS,    "rawptr:",       false, Op_RegP,              relocInfo::none          },  // RawPtr
  92   { Bad,             T_OBJECT,     "oop:",          true,  Op_RegP,              relocInfo::oop_type      },  // OopPtr
  93   { Bad,             T_OBJECT,     "inst:",         true,  Op_RegP,              relocInfo::oop_type      },  // InstPtr
  94   { Bad,             T_OBJECT,     "ary:",          true,  Op_RegP,              relocInfo::oop_type      },  // AryPtr
  95   { Bad,             T_METADATA,   "metadata:",     false, Op_RegP,              relocInfo::metadata_type },  // MetadataPtr
  96   { Bad,             T_METADATA,   "klass:",        false, Op_RegP,              relocInfo::metadata_type },  // KlassPtr
  97   { Bad,             T_METADATA,   "instklass:",    false, Op_RegP,              relocInfo::metadata_type },  // InstKlassPtr
  98   { Bad,             T_METADATA,   "aryklass:",     false, Op_RegP,              relocInfo::metadata_type },  // AryKlassPtr
  99   { Bad,             T_OBJECT,     "func",          false, 0,                    relocInfo::none          },  // Function
 100   { Abio,            T_ILLEGAL,    "abIO",          false, 0,                    relocInfo::none          },  // Abio
 101   { Return_Address,  T_ADDRESS,    "return_address",false, Op_RegP,              relocInfo::none          },  // Return_Address
 102   { Memory,          T_ILLEGAL,    "memory",        false, 0,                    relocInfo::none          },  // Memory
 103   { FloatBot,        T_FLOAT,      "float_top",     false, Op_RegF,              relocInfo::none          },  // FloatTop
 104   { FloatCon,        T_FLOAT,      "ftcon:",        false, Op_RegF,              relocInfo::none          },  // FloatCon
 105   { FloatTop,        T_FLOAT,      "float",         false, Op_RegF,              relocInfo::none          },  // FloatBot
 106   { DoubleBot,       T_DOUBLE,     "double_top",    false, Op_RegD,              relocInfo::none          },  // DoubleTop
 107   { DoubleCon,       T_DOUBLE,     "dblcon:",       false, Op_RegD,              relocInfo::none          },  // DoubleCon
 108   { DoubleTop,       T_DOUBLE,     "double",        false, Op_RegD,              relocInfo::none          },  // DoubleBot
 109   { Top,             T_ILLEGAL,    "bottom",        false, 0,                    relocInfo::none          }   // Bottom
 110 };
 111 
 112 // Map ideal registers (machine types) to ideal types
 113 const Type *Type::mreg2type[_last_machine_leaf];
 114 
 115 // Map basic types to canonical Type* pointers.
 116 const Type* Type::     _const_basic_type[T_CONFLICT+1];
 117 
 118 // Map basic types to constant-zero Types.
 119 const Type* Type::            _zero_type[T_CONFLICT+1];
 120 
 121 // Map basic types to array-body alias types.
 122 const TypeAryPtr* TypeAryPtr::_array_body_type[T_CONFLICT+1];
 123 const TypePtr::InterfaceSet* TypeAryPtr::_array_interfaces = NULL;
 124 const TypePtr::InterfaceSet* TypeAryKlassPtr::_array_interfaces = NULL;
 125 
 126 //=============================================================================
 127 // Convenience common pre-built types.
 128 const Type *Type::ABIO;         // State-of-machine only
 129 const Type *Type::BOTTOM;       // All values
 130 const Type *Type::CONTROL;      // Control only
 131 const Type *Type::DOUBLE;       // All doubles
 132 const Type *Type::FLOAT;        // All floats
 133 const Type *Type::HALF;         // Placeholder half of doublewide type
 134 const Type *Type::MEMORY;       // Abstract store only
 135 const Type *Type::RETURN_ADDRESS;
 136 const Type *Type::TOP;          // No values in set
 137 
 138 //------------------------------get_const_type---------------------------
 139 const Type* Type::get_const_type(ciType* type, InterfaceHandling interface_handling) {
 140   if (type == NULL) {
 141     return NULL;
 142   } else if (type->is_primitive_type()) {
 143     return get_const_basic_type(type->basic_type());
 144   } else {
 145     return TypeOopPtr::make_from_klass(type->as_klass(), interface_handling);
 146   }
 147 }
 148 
 149 //---------------------------array_element_basic_type---------------------------------
 150 // Mapping to the array element's basic type.
 151 BasicType Type::array_element_basic_type() const {
 152   BasicType bt = basic_type();
 153   if (bt == T_INT) {
 154     if (this == TypeInt::INT)   return T_INT;
 155     if (this == TypeInt::CHAR)  return T_CHAR;
 156     if (this == TypeInt::BYTE)  return T_BYTE;
 157     if (this == TypeInt::BOOL)  return T_BOOLEAN;
 158     if (this == TypeInt::SHORT) return T_SHORT;
 159     return T_VOID;
 160   }
 161   return bt;
 162 }
 163 
 164 // For two instance arrays of same dimension, return the base element types.
 165 // Otherwise or if the arrays have different dimensions, return NULL.
 166 void Type::get_arrays_base_elements(const Type *a1, const Type *a2,
 167                                     const TypeInstPtr **e1, const TypeInstPtr **e2) {
 168 
 169   if (e1) *e1 = NULL;
 170   if (e2) *e2 = NULL;
 171   const TypeAryPtr* a1tap = (a1 == NULL) ? NULL : a1->isa_aryptr();
 172   const TypeAryPtr* a2tap = (a2 == NULL) ? NULL : a2->isa_aryptr();
 173 
 174   if (a1tap != NULL && a2tap != NULL) {
 175     // Handle multidimensional arrays
 176     const TypePtr* a1tp = a1tap->elem()->make_ptr();
 177     const TypePtr* a2tp = a2tap->elem()->make_ptr();
 178     while (a1tp && a1tp->isa_aryptr() && a2tp && a2tp->isa_aryptr()) {
 179       a1tap = a1tp->is_aryptr();
 180       a2tap = a2tp->is_aryptr();
 181       a1tp = a1tap->elem()->make_ptr();
 182       a2tp = a2tap->elem()->make_ptr();
 183     }
 184     if (a1tp && a1tp->isa_instptr() && a2tp && a2tp->isa_instptr()) {
 185       if (e1) *e1 = a1tp->is_instptr();
 186       if (e2) *e2 = a2tp->is_instptr();
 187     }
 188   }
 189 }
 190 
 191 //---------------------------get_typeflow_type---------------------------------
 192 // Import a type produced by ciTypeFlow.
 193 const Type* Type::get_typeflow_type(ciType* type) {
 194   switch (type->basic_type()) {
 195 
 196   case ciTypeFlow::StateVector::T_BOTTOM:
 197     assert(type == ciTypeFlow::StateVector::bottom_type(), "");
 198     return Type::BOTTOM;
 199 
 200   case ciTypeFlow::StateVector::T_TOP:
 201     assert(type == ciTypeFlow::StateVector::top_type(), "");
 202     return Type::TOP;
 203 
 204   case ciTypeFlow::StateVector::T_NULL:
 205     assert(type == ciTypeFlow::StateVector::null_type(), "");
 206     return TypePtr::NULL_PTR;
 207 
 208   case ciTypeFlow::StateVector::T_LONG2:
 209     // The ciTypeFlow pass pushes a long, then the half.
 210     // We do the same.
 211     assert(type == ciTypeFlow::StateVector::long2_type(), "");
 212     return TypeInt::TOP;
 213 
 214   case ciTypeFlow::StateVector::T_DOUBLE2:
 215     // The ciTypeFlow pass pushes double, then the half.
 216     // Our convention is the same.
 217     assert(type == ciTypeFlow::StateVector::double2_type(), "");
 218     return Type::TOP;
 219 
 220   case T_ADDRESS:
 221     assert(type->is_return_address(), "");
 222     return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci());
 223 
 224   default:
 225     // make sure we did not mix up the cases:
 226     assert(type != ciTypeFlow::StateVector::bottom_type(), "");
 227     assert(type != ciTypeFlow::StateVector::top_type(), "");
 228     assert(type != ciTypeFlow::StateVector::null_type(), "");
 229     assert(type != ciTypeFlow::StateVector::long2_type(), "");
 230     assert(type != ciTypeFlow::StateVector::double2_type(), "");
 231     assert(!type->is_return_address(), "");
 232 
 233     return Type::get_const_type(type);
 234   }
 235 }
 236 
 237 
 238 //-----------------------make_from_constant------------------------------------
 239 const Type* Type::make_from_constant(ciConstant constant, bool require_constant,
 240                                      int stable_dimension, bool is_narrow_oop,
 241                                      bool is_autobox_cache) {
 242   switch (constant.basic_type()) {
 243     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
 244     case T_CHAR:     return TypeInt::make(constant.as_char());
 245     case T_BYTE:     return TypeInt::make(constant.as_byte());
 246     case T_SHORT:    return TypeInt::make(constant.as_short());
 247     case T_INT:      return TypeInt::make(constant.as_int());
 248     case T_LONG:     return TypeLong::make(constant.as_long());
 249     case T_FLOAT:    return TypeF::make(constant.as_float());
 250     case T_DOUBLE:   return TypeD::make(constant.as_double());
 251     case T_ARRAY:
 252     case T_OBJECT: {
 253         const Type* con_type = NULL;
 254         ciObject* oop_constant = constant.as_object();
 255         if (oop_constant->is_null_object()) {
 256           con_type = Type::get_zero_type(T_OBJECT);
 257         } else {
 258           guarantee(require_constant || oop_constant->should_be_constant(), "con_type must get computed");
 259           con_type = TypeOopPtr::make_from_constant(oop_constant, require_constant);
 260           if (Compile::current()->eliminate_boxing() && is_autobox_cache) {
 261             con_type = con_type->is_aryptr()->cast_to_autobox_cache();
 262           }
 263           if (stable_dimension > 0) {
 264             assert(FoldStableValues, "sanity");
 265             assert(!con_type->is_zero_type(), "default value for stable field");
 266             con_type = con_type->is_aryptr()->cast_to_stable(true, stable_dimension);
 267           }
 268         }
 269         if (is_narrow_oop) {
 270           con_type = con_type->make_narrowoop();
 271         }
 272         return con_type;
 273       }
 274     case T_ILLEGAL:
 275       // Invalid ciConstant returned due to OutOfMemoryError in the CI
 276       assert(Compile::current()->env()->failing(), "otherwise should not see this");
 277       return NULL;
 278     default:
 279       // Fall through to failure
 280       return NULL;
 281   }
 282 }
 283 
 284 static ciConstant check_mismatched_access(ciConstant con, BasicType loadbt, bool is_unsigned) {
 285   BasicType conbt = con.basic_type();
 286   switch (conbt) {
 287     case T_BOOLEAN: conbt = T_BYTE;   break;
 288     case T_ARRAY:   conbt = T_OBJECT; break;
 289     default:                          break;
 290   }
 291   switch (loadbt) {
 292     case T_BOOLEAN:   loadbt = T_BYTE;   break;
 293     case T_NARROWOOP: loadbt = T_OBJECT; break;
 294     case T_ARRAY:     loadbt = T_OBJECT; break;
 295     case T_ADDRESS:   loadbt = T_OBJECT; break;
 296     default:                             break;
 297   }
 298   if (conbt == loadbt) {
 299     if (is_unsigned && conbt == T_BYTE) {
 300       // LoadB (T_BYTE) with a small mask (<=8-bit) is converted to LoadUB (T_BYTE).
 301       return ciConstant(T_INT, con.as_int() & 0xFF);
 302     } else {
 303       return con;
 304     }
 305   }
 306   if (conbt == T_SHORT && loadbt == T_CHAR) {
 307     // LoadS (T_SHORT) with a small mask (<=16-bit) is converted to LoadUS (T_CHAR).
 308     return ciConstant(T_INT, con.as_int() & 0xFFFF);
 309   }
 310   return ciConstant(); // T_ILLEGAL
 311 }
 312 
 313 // Try to constant-fold a stable array element.
 314 const Type* Type::make_constant_from_array_element(ciArray* array, int off, int stable_dimension,
 315                                                    BasicType loadbt, bool is_unsigned_load) {
 316   // Decode the results of GraphKit::array_element_address.
 317   ciConstant element_value = array->element_value_by_offset(off);
 318   if (element_value.basic_type() == T_ILLEGAL) {
 319     return NULL; // wrong offset
 320   }
 321   ciConstant con = check_mismatched_access(element_value, loadbt, is_unsigned_load);
 322 
 323   assert(con.basic_type() != T_ILLEGAL, "elembt=%s; loadbt=%s; unsigned=%d",
 324          type2name(element_value.basic_type()), type2name(loadbt), is_unsigned_load);
 325 
 326   if (con.is_valid() &&          // not a mismatched access
 327       !con.is_null_or_zero()) {  // not a default value
 328     bool is_narrow_oop = (loadbt == T_NARROWOOP);
 329     return Type::make_from_constant(con, /*require_constant=*/true, stable_dimension, is_narrow_oop, /*is_autobox_cache=*/false);
 330   }
 331   return NULL;
 332 }
 333 
 334 const Type* Type::make_constant_from_field(ciInstance* holder, int off, bool is_unsigned_load, BasicType loadbt) {
 335   ciField* field;
 336   ciType* type = holder->java_mirror_type();
 337   if (type != NULL && type->is_instance_klass() && off >= InstanceMirrorKlass::offset_of_static_fields()) {
 338     // Static field
 339     field = type->as_instance_klass()->get_field_by_offset(off, /*is_static=*/true);
 340   } else {
 341     // Instance field
 342     field = holder->klass()->as_instance_klass()->get_field_by_offset(off, /*is_static=*/false);
 343   }
 344   if (field == NULL) {
 345     return NULL; // Wrong offset
 346   }
 347   return Type::make_constant_from_field(field, holder, loadbt, is_unsigned_load);
 348 }
 349 
 350 const Type* Type::make_constant_from_field(ciField* field, ciInstance* holder,
 351                                            BasicType loadbt, bool is_unsigned_load) {
 352   if (!field->is_constant()) {
 353     return NULL; // Non-constant field
 354   }
 355   ciConstant field_value;
 356   if (field->is_static()) {
 357     // final static field
 358     field_value = field->constant_value();
 359   } else if (holder != NULL) {
 360     // final or stable non-static field
 361     // Treat final non-static fields of trusted classes (classes in
 362     // java.lang.invoke and sun.invoke packages and subpackages) as
 363     // compile time constants.
 364     field_value = field->constant_value_of(holder);
 365   }
 366   if (!field_value.is_valid()) {
 367     return NULL; // Not a constant
 368   }
 369 
 370   ciConstant con = check_mismatched_access(field_value, loadbt, is_unsigned_load);
 371 
 372   assert(con.is_valid(), "elembt=%s; loadbt=%s; unsigned=%d",
 373          type2name(field_value.basic_type()), type2name(loadbt), is_unsigned_load);
 374 
 375   bool is_stable_array = FoldStableValues && field->is_stable() && field->type()->is_array_klass();
 376   int stable_dimension = (is_stable_array ? field->type()->as_array_klass()->dimension() : 0);
 377   bool is_narrow_oop = (loadbt == T_NARROWOOP);
 378 
 379   const Type* con_type = make_from_constant(con, /*require_constant=*/ true,
 380                                             stable_dimension, is_narrow_oop,
 381                                             field->is_autobox_cache());
 382   if (con_type != NULL && field->is_call_site_target()) {
 383     ciCallSite* call_site = holder->as_call_site();
 384     if (!call_site->is_fully_initialized_constant_call_site()) {
 385       ciMethodHandle* target = con.as_object()->as_method_handle();
 386       Compile::current()->dependencies()->assert_call_site_target_value(call_site, target);
 387     }
 388   }
 389   return con_type;
 390 }
 391 
 392 //------------------------------make-------------------------------------------
 393 // Create a simple Type, with default empty symbol sets.  Then hashcons it
 394 // and look for an existing copy in the type dictionary.
 395 const Type *Type::make( enum TYPES t ) {
 396   return (new Type(t))->hashcons();
 397 }
 398 
 399 //------------------------------cmp--------------------------------------------
 400 int Type::cmp( const Type *const t1, const Type *const t2 ) {
 401   if( t1->_base != t2->_base )
 402     return 1;                   // Missed badly
 403   assert(t1 != t2 || t1->eq(t2), "eq must be reflexive");
 404   return !t1->eq(t2);           // Return ZERO if equal
 405 }
 406 
 407 const Type* Type::maybe_remove_speculative(bool include_speculative) const {
 408   if (!include_speculative) {
 409     return remove_speculative();
 410   }
 411   return this;
 412 }
 413 
 414 //------------------------------hash-------------------------------------------
 415 int Type::uhash( const Type *const t ) {
 416   return t->hash();
 417 }
 418 
 419 #define SMALLINT ((juint)3)  // a value too insignificant to consider widening
 420 #define POSITIVE_INFINITE_F 0x7f800000 // hex representation for IEEE 754 single precision positive infinite
 421 #define POSITIVE_INFINITE_D 0x7ff0000000000000 // hex representation for IEEE 754 double precision positive infinite
 422 
 423 //--------------------------Initialize_shared----------------------------------
 424 void Type::Initialize_shared(Compile* current) {
 425   // This method does not need to be locked because the first system
 426   // compilations (stub compilations) occur serially.  If they are
 427   // changed to proceed in parallel, then this section will need
 428   // locking.
 429 
 430   Arena* save = current->type_arena();
 431   Arena* shared_type_arena = new (mtCompiler)Arena(mtCompiler);
 432 
 433   current->set_type_arena(shared_type_arena);
 434   _shared_type_dict =
 435     new (shared_type_arena) Dict( (CmpKey)Type::cmp, (Hash)Type::uhash,
 436                                   shared_type_arena, 128 );
 437   current->set_type_dict(_shared_type_dict);
 438 
 439   // Make shared pre-built types.
 440   CONTROL = make(Control);      // Control only
 441   TOP     = make(Top);          // No values in set
 442   MEMORY  = make(Memory);       // Abstract store only
 443   ABIO    = make(Abio);         // State-of-machine only
 444   RETURN_ADDRESS=make(Return_Address);
 445   FLOAT   = make(FloatBot);     // All floats
 446   DOUBLE  = make(DoubleBot);    // All doubles
 447   BOTTOM  = make(Bottom);       // Everything
 448   HALF    = make(Half);         // Placeholder half of doublewide type
 449 
 450   TypeF::MAX = TypeF::make(max_jfloat); // Float MAX
 451   TypeF::MIN = TypeF::make(min_jfloat); // Float MIN
 452   TypeF::ZERO = TypeF::make(0.0); // Float 0 (positive zero)
 453   TypeF::ONE  = TypeF::make(1.0); // Float 1
 454   TypeF::POS_INF = TypeF::make(jfloat_cast(POSITIVE_INFINITE_F));
 455   TypeF::NEG_INF = TypeF::make(-jfloat_cast(POSITIVE_INFINITE_F));
 456 
 457   TypeD::MAX = TypeD::make(max_jdouble); // Double MAX
 458   TypeD::MIN = TypeD::make(min_jdouble); // Double MIN
 459   TypeD::ZERO = TypeD::make(0.0); // Double 0 (positive zero)
 460   TypeD::ONE  = TypeD::make(1.0); // Double 1
 461   TypeD::POS_INF = TypeD::make(jdouble_cast(POSITIVE_INFINITE_D));
 462   TypeD::NEG_INF = TypeD::make(-jdouble_cast(POSITIVE_INFINITE_D));
 463 
 464   TypeInt::MAX = TypeInt::make(max_jint); // Int MAX
 465   TypeInt::MIN = TypeInt::make(min_jint); // Int MIN
 466   TypeInt::MINUS_1 = TypeInt::make(-1);  // -1
 467   TypeInt::ZERO    = TypeInt::make( 0);  //  0
 468   TypeInt::ONE     = TypeInt::make( 1);  //  1
 469   TypeInt::BOOL    = TypeInt::make(0,1,   WidenMin);  // 0 or 1, FALSE or TRUE.
 470   TypeInt::CC      = TypeInt::make(-1, 1, WidenMin);  // -1, 0 or 1, condition codes
 471   TypeInt::CC_LT   = TypeInt::make(-1,-1, WidenMin);  // == TypeInt::MINUS_1
 472   TypeInt::CC_GT   = TypeInt::make( 1, 1, WidenMin);  // == TypeInt::ONE
 473   TypeInt::CC_EQ   = TypeInt::make( 0, 0, WidenMin);  // == TypeInt::ZERO
 474   TypeInt::CC_LE   = TypeInt::make(-1, 0, WidenMin);
 475   TypeInt::CC_GE   = TypeInt::make( 0, 1, WidenMin);  // == TypeInt::BOOL
 476   TypeInt::BYTE    = TypeInt::make(-128,127,     WidenMin); // Bytes
 477   TypeInt::UBYTE   = TypeInt::make(0, 255,       WidenMin); // Unsigned Bytes
 478   TypeInt::CHAR    = TypeInt::make(0,65535,      WidenMin); // Java chars
 479   TypeInt::SHORT   = TypeInt::make(-32768,32767, WidenMin); // Java shorts
 480   TypeInt::POS     = TypeInt::make(0,max_jint,   WidenMin); // Non-neg values
 481   TypeInt::POS1    = TypeInt::make(1,max_jint,   WidenMin); // Positive values
 482   TypeInt::INT     = TypeInt::make(min_jint,max_jint, WidenMax); // 32-bit integers
 483   TypeInt::SYMINT  = TypeInt::make(-max_jint,max_jint,WidenMin); // symmetric range
 484   TypeInt::TYPE_DOMAIN  = TypeInt::INT;
 485   // CmpL is overloaded both as the bytecode computation returning
 486   // a trinary (-1,0,+1) integer result AND as an efficient long
 487   // compare returning optimizer ideal-type flags.
 488   assert( TypeInt::CC_LT == TypeInt::MINUS_1, "types must match for CmpL to work" );
 489   assert( TypeInt::CC_GT == TypeInt::ONE,     "types must match for CmpL to work" );
 490   assert( TypeInt::CC_EQ == TypeInt::ZERO,    "types must match for CmpL to work" );
 491   assert( TypeInt::CC_GE == TypeInt::BOOL,    "types must match for CmpL to work" );
 492   assert( (juint)(TypeInt::CC->_hi - TypeInt::CC->_lo) <= SMALLINT, "CC is truly small");
 493 
 494   TypeLong::MAX = TypeLong::make(max_jlong);  // Long MAX
 495   TypeLong::MIN = TypeLong::make(min_jlong);  // Long MIN
 496   TypeLong::MINUS_1 = TypeLong::make(-1);        // -1
 497   TypeLong::ZERO    = TypeLong::make( 0);        //  0
 498   TypeLong::ONE     = TypeLong::make( 1);        //  1
 499   TypeLong::POS     = TypeLong::make(0,max_jlong, WidenMin); // Non-neg values
 500   TypeLong::LONG    = TypeLong::make(min_jlong,max_jlong,WidenMax); // 64-bit integers
 501   TypeLong::INT     = TypeLong::make((jlong)min_jint,(jlong)max_jint,WidenMin);
 502   TypeLong::UINT    = TypeLong::make(0,(jlong)max_juint,WidenMin);
 503   TypeLong::TYPE_DOMAIN  = TypeLong::LONG;
 504 
 505   const Type **fboth =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 506   fboth[0] = Type::CONTROL;
 507   fboth[1] = Type::CONTROL;
 508   TypeTuple::IFBOTH = TypeTuple::make( 2, fboth );
 509 
 510   const Type **ffalse =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 511   ffalse[0] = Type::CONTROL;
 512   ffalse[1] = Type::TOP;
 513   TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
 514 
 515   const Type **fneither =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 516   fneither[0] = Type::TOP;
 517   fneither[1] = Type::TOP;
 518   TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
 519 
 520   const Type **ftrue =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 521   ftrue[0] = Type::TOP;
 522   ftrue[1] = Type::CONTROL;
 523   TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
 524 
 525   const Type **floop =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 526   floop[0] = Type::CONTROL;
 527   floop[1] = TypeInt::INT;
 528   TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
 529 
 530   TypePtr::NULL_PTR= TypePtr::make(AnyPtr, TypePtr::Null, 0);
 531   TypePtr::NOTNULL = TypePtr::make(AnyPtr, TypePtr::NotNull, OffsetBot);
 532   TypePtr::BOTTOM  = TypePtr::make(AnyPtr, TypePtr::BotPTR, OffsetBot);
 533 
 534   TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
 535   TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
 536 
 537   const Type **fmembar = TypeTuple::fields(0);
 538   TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
 539 
 540   const Type **fsc = (const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 541   fsc[0] = TypeInt::CC;
 542   fsc[1] = Type::MEMORY;
 543   TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
 544 
 545   TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
 546   TypeInstPtr::BOTTOM  = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass());
 547   TypeInstPtr::MIRROR  = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
 548   TypeInstPtr::MARK    = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
 549                                            false, 0, oopDesc::mark_offset_in_bytes());
 550   TypeInstPtr::KLASS   = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
 551                                            false, 0, oopDesc::klass_offset_in_bytes());
 552   TypeOopPtr::BOTTOM  = TypeOopPtr::make(TypePtr::BotPTR, OffsetBot, TypeOopPtr::InstanceBot);
 553 
 554   TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, NULL, OffsetBot);
 555 
 556   TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
 557   TypeNarrowOop::BOTTOM   = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
 558 
 559   TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
 560 
 561   mreg2type[Op_Node] = Type::BOTTOM;
 562   mreg2type[Op_Set ] = 0;
 563   mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
 564   mreg2type[Op_RegI] = TypeInt::INT;
 565   mreg2type[Op_RegP] = TypePtr::BOTTOM;
 566   mreg2type[Op_RegF] = Type::FLOAT;
 567   mreg2type[Op_RegD] = Type::DOUBLE;
 568   mreg2type[Op_RegL] = TypeLong::LONG;
 569   mreg2type[Op_RegFlags] = TypeInt::CC;
 570 
 571   GrowableArray<ciInstanceKlass*> array_interfaces;
 572   array_interfaces.push(current->env()->Cloneable_klass());
 573   array_interfaces.push(current->env()->Serializable_klass());
 574   TypeAryPtr::_array_interfaces = new TypePtr::InterfaceSet(&array_interfaces);
 575   TypeAryKlassPtr::_array_interfaces = TypeAryPtr::_array_interfaces;
 576 
 577   TypeAryPtr::RANGE   = TypeAryPtr::make( TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), NULL /* current->env()->Object_klass() */, false, arrayOopDesc::length_offset_in_bytes());
 578 
 579   TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS), NULL /*ciArrayKlass::make(o)*/,  false,  Type::OffsetBot);
 580 
 581 #ifdef _LP64
 582   if (UseCompressedOops) {
 583     assert(TypeAryPtr::NARROWOOPS->is_ptr_to_narrowoop(), "array of narrow oops must be ptr to narrow oop");
 584     TypeAryPtr::OOPS  = TypeAryPtr::NARROWOOPS;
 585   } else
 586 #endif
 587   {
 588     // There is no shared klass for Object[].  See note in TypeAryPtr::klass().
 589     TypeAryPtr::OOPS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS), NULL /*ciArrayKlass::make(o)*/,  false,  Type::OffsetBot);
 590   }
 591   TypeAryPtr::BYTES   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE      ,TypeInt::POS), ciTypeArrayKlass::make(T_BYTE),   true,  Type::OffsetBot);
 592   TypeAryPtr::SHORTS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT     ,TypeInt::POS), ciTypeArrayKlass::make(T_SHORT),  true,  Type::OffsetBot);
 593   TypeAryPtr::CHARS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR      ,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR),   true,  Type::OffsetBot);
 594   TypeAryPtr::INTS    = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT       ,TypeInt::POS), ciTypeArrayKlass::make(T_INT),    true,  Type::OffsetBot);
 595   TypeAryPtr::LONGS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG     ,TypeInt::POS), ciTypeArrayKlass::make(T_LONG),   true,  Type::OffsetBot);
 596   TypeAryPtr::FLOATS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT        ,TypeInt::POS), ciTypeArrayKlass::make(T_FLOAT),  true,  Type::OffsetBot);
 597   TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE       ,TypeInt::POS), ciTypeArrayKlass::make(T_DOUBLE), true,  Type::OffsetBot);
 598 
 599   // Nobody should ask _array_body_type[T_NARROWOOP]. Use NULL as assert.
 600   TypeAryPtr::_array_body_type[T_NARROWOOP] = NULL;
 601   TypeAryPtr::_array_body_type[T_OBJECT]  = TypeAryPtr::OOPS;
 602   TypeAryPtr::_array_body_type[T_ARRAY]   = TypeAryPtr::OOPS; // arrays are stored in oop arrays
 603   TypeAryPtr::_array_body_type[T_BYTE]    = TypeAryPtr::BYTES;
 604   TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES;  // boolean[] is a byte array
 605   TypeAryPtr::_array_body_type[T_SHORT]   = TypeAryPtr::SHORTS;
 606   TypeAryPtr::_array_body_type[T_CHAR]    = TypeAryPtr::CHARS;
 607   TypeAryPtr::_array_body_type[T_INT]     = TypeAryPtr::INTS;
 608   TypeAryPtr::_array_body_type[T_LONG]    = TypeAryPtr::LONGS;
 609   TypeAryPtr::_array_body_type[T_FLOAT]   = TypeAryPtr::FLOATS;
 610   TypeAryPtr::_array_body_type[T_DOUBLE]  = TypeAryPtr::DOUBLES;
 611 
 612   TypeInstKlassPtr::OBJECT = TypeInstKlassPtr::make(TypePtr::NotNull, current->env()->Object_klass(), 0);
 613   TypeInstKlassPtr::OBJECT_OR_NULL = TypeInstKlassPtr::make(TypePtr::BotPTR, current->env()->Object_klass(), 0);
 614 
 615   const Type **fi2c = TypeTuple::fields(2);
 616   fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // Method*
 617   fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
 618   TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
 619 
 620   const Type **intpair = TypeTuple::fields(2);
 621   intpair[0] = TypeInt::INT;
 622   intpair[1] = TypeInt::INT;
 623   TypeTuple::INT_PAIR = TypeTuple::make(2, intpair);
 624 
 625   const Type **longpair = TypeTuple::fields(2);
 626   longpair[0] = TypeLong::LONG;
 627   longpair[1] = TypeLong::LONG;
 628   TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
 629 
 630   const Type **intccpair = TypeTuple::fields(2);
 631   intccpair[0] = TypeInt::INT;
 632   intccpair[1] = TypeInt::CC;
 633   TypeTuple::INT_CC_PAIR = TypeTuple::make(2, intccpair);
 634 
 635   const Type **longccpair = TypeTuple::fields(2);
 636   longccpair[0] = TypeLong::LONG;
 637   longccpair[1] = TypeInt::CC;
 638   TypeTuple::LONG_CC_PAIR = TypeTuple::make(2, longccpair);
 639 
 640   _const_basic_type[T_NARROWOOP]   = TypeNarrowOop::BOTTOM;
 641   _const_basic_type[T_NARROWKLASS] = Type::BOTTOM;
 642   _const_basic_type[T_BOOLEAN]     = TypeInt::BOOL;
 643   _const_basic_type[T_CHAR]        = TypeInt::CHAR;
 644   _const_basic_type[T_BYTE]        = TypeInt::BYTE;
 645   _const_basic_type[T_SHORT]       = TypeInt::SHORT;
 646   _const_basic_type[T_INT]         = TypeInt::INT;
 647   _const_basic_type[T_LONG]        = TypeLong::LONG;
 648   _const_basic_type[T_FLOAT]       = Type::FLOAT;
 649   _const_basic_type[T_DOUBLE]      = Type::DOUBLE;
 650   _const_basic_type[T_OBJECT]      = TypeInstPtr::BOTTOM;
 651   _const_basic_type[T_ARRAY]       = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays
 652   _const_basic_type[T_VOID]        = TypePtr::NULL_PTR;   // reflection represents void this way
 653   _const_basic_type[T_ADDRESS]     = TypeRawPtr::BOTTOM;  // both interpreter return addresses & random raw ptrs
 654   _const_basic_type[T_CONFLICT]    = Type::BOTTOM;        // why not?
 655 
 656   _zero_type[T_NARROWOOP]   = TypeNarrowOop::NULL_PTR;
 657   _zero_type[T_NARROWKLASS] = TypeNarrowKlass::NULL_PTR;
 658   _zero_type[T_BOOLEAN]     = TypeInt::ZERO;     // false == 0
 659   _zero_type[T_CHAR]        = TypeInt::ZERO;     // '\0' == 0
 660   _zero_type[T_BYTE]        = TypeInt::ZERO;     // 0x00 == 0
 661   _zero_type[T_SHORT]       = TypeInt::ZERO;     // 0x0000 == 0
 662   _zero_type[T_INT]         = TypeInt::ZERO;
 663   _zero_type[T_LONG]        = TypeLong::ZERO;
 664   _zero_type[T_FLOAT]       = TypeF::ZERO;
 665   _zero_type[T_DOUBLE]      = TypeD::ZERO;
 666   _zero_type[T_OBJECT]      = TypePtr::NULL_PTR;
 667   _zero_type[T_ARRAY]       = TypePtr::NULL_PTR; // null array is null oop
 668   _zero_type[T_ADDRESS]     = TypePtr::NULL_PTR; // raw pointers use the same null
 669   _zero_type[T_VOID]        = Type::TOP;         // the only void value is no value at all
 670 
 671   // get_zero_type() should not happen for T_CONFLICT
 672   _zero_type[T_CONFLICT]= NULL;
 673 
 674   TypeVect::VECTMASK = (TypeVect*)(new TypeVectMask(TypeInt::BOOL, MaxVectorSize))->hashcons();
 675   mreg2type[Op_RegVectMask] = TypeVect::VECTMASK;
 676 
 677   if (Matcher::supports_scalable_vector()) {
 678     TypeVect::VECTA = TypeVect::make(T_BYTE, Matcher::scalable_vector_reg_size(T_BYTE));
 679   }
 680 
 681   // Vector predefined types, it needs initialized _const_basic_type[].
 682   if (Matcher::vector_size_supported(T_BYTE,4)) {
 683     TypeVect::VECTS = TypeVect::make(T_BYTE,4);
 684   }
 685   if (Matcher::vector_size_supported(T_FLOAT,2)) {
 686     TypeVect::VECTD = TypeVect::make(T_FLOAT,2);
 687   }
 688   if (Matcher::vector_size_supported(T_FLOAT,4)) {
 689     TypeVect::VECTX = TypeVect::make(T_FLOAT,4);
 690   }
 691   if (Matcher::vector_size_supported(T_FLOAT,8)) {
 692     TypeVect::VECTY = TypeVect::make(T_FLOAT,8);
 693   }
 694   if (Matcher::vector_size_supported(T_FLOAT,16)) {
 695     TypeVect::VECTZ = TypeVect::make(T_FLOAT,16);
 696   }
 697 
 698   mreg2type[Op_VecA] = TypeVect::VECTA;
 699   mreg2type[Op_VecS] = TypeVect::VECTS;
 700   mreg2type[Op_VecD] = TypeVect::VECTD;
 701   mreg2type[Op_VecX] = TypeVect::VECTX;
 702   mreg2type[Op_VecY] = TypeVect::VECTY;
 703   mreg2type[Op_VecZ] = TypeVect::VECTZ;
 704 
 705   // Restore working type arena.
 706   current->set_type_arena(save);
 707   current->set_type_dict(NULL);
 708 }
 709 
 710 //------------------------------Initialize-------------------------------------
 711 void Type::Initialize(Compile* current) {
 712   assert(current->type_arena() != NULL, "must have created type arena");
 713 
 714   if (_shared_type_dict == NULL) {
 715     Initialize_shared(current);
 716   }
 717 
 718   Arena* type_arena = current->type_arena();
 719 
 720   // Create the hash-cons'ing dictionary with top-level storage allocation
 721   Dict *tdic = new (type_arena) Dict(*_shared_type_dict, type_arena);
 722   current->set_type_dict(tdic);
 723 }
 724 
 725 //------------------------------hashcons---------------------------------------
 726 // Do the hash-cons trick.  If the Type already exists in the type table,
 727 // delete the current Type and return the existing Type.  Otherwise stick the
 728 // current Type in the Type table.
 729 const Type *Type::hashcons(void) {
 730   debug_only(base());           // Check the assertion in Type::base().
 731   // Look up the Type in the Type dictionary
 732   Dict *tdic = type_dict();
 733   Type* old = (Type*)(tdic->Insert(this, this, false));
 734   if( old ) {                   // Pre-existing Type?
 735     if( old != this )           // Yes, this guy is not the pre-existing?
 736       delete this;              // Yes, Nuke this guy
 737     assert( old->_dual, "" );
 738     return old;                 // Return pre-existing
 739   }
 740 
 741   // Every type has a dual (to make my lattice symmetric).
 742   // Since we just discovered a new Type, compute its dual right now.
 743   assert( !_dual, "" );         // No dual yet
 744   _dual = xdual();              // Compute the dual
 745   if (cmp(this, _dual) == 0) {  // Handle self-symmetric
 746     if (_dual != this) {
 747       delete _dual;
 748       _dual = this;
 749     }
 750     return this;
 751   }
 752   assert( !_dual->_dual, "" );  // No reverse dual yet
 753   assert( !(*tdic)[_dual], "" ); // Dual not in type system either
 754   // New Type, insert into Type table
 755   tdic->Insert((void*)_dual,(void*)_dual);
 756   ((Type*)_dual)->_dual = this; // Finish up being symmetric
 757 #ifdef ASSERT
 758   Type *dual_dual = (Type*)_dual->xdual();
 759   assert( eq(dual_dual), "xdual(xdual()) should be identity" );
 760   delete dual_dual;
 761 #endif
 762   return this;                  // Return new Type
 763 }
 764 
 765 //------------------------------eq---------------------------------------------
 766 // Structural equality check for Type representations
 767 bool Type::eq( const Type * ) const {
 768   return true;                  // Nothing else can go wrong
 769 }
 770 
 771 //------------------------------hash-------------------------------------------
 772 // Type-specific hashing function.
 773 int Type::hash(void) const {
 774   return _base;
 775 }
 776 
 777 //------------------------------is_finite--------------------------------------
 778 // Has a finite value
 779 bool Type::is_finite() const {
 780   return false;
 781 }
 782 
 783 //------------------------------is_nan-----------------------------------------
 784 // Is not a number (NaN)
 785 bool Type::is_nan()    const {
 786   return false;
 787 }
 788 
 789 void Type::check_symmetrical(const Type* t, const Type* mt) const {
 790 #ifdef ASSERT
 791   const Type* mt2 = t->xmeet(this);
 792   if (mt != mt2) {
 793     tty->print_cr("=== Meet Not Commutative ===");
 794     tty->print("t           = ");   t->dump(); tty->cr();
 795     tty->print("this        = ");      dump(); tty->cr();
 796     tty->print("t meet this = "); mt2->dump(); tty->cr();
 797     tty->print("this meet t = ");  mt->dump(); tty->cr();
 798     fatal("meet not commutative");
 799   }
 800   const Type* dual_join = mt->_dual;
 801   const Type* t2t    = dual_join->xmeet(t->_dual);
 802   const Type* t2this = dual_join->xmeet(this->_dual);
 803 
 804   // Interface meet Oop is Not Symmetric:
 805   // Interface:AnyNull meet Oop:AnyNull == Interface:AnyNull
 806   // Interface:NotNull meet Oop:NotNull == java/lang/Object:NotNull
 807 
 808   if (t2t != t->_dual || t2this != this->_dual) {
 809     tty->print_cr("=== Meet Not Symmetric ===");
 810     tty->print("t   =                   ");              t->dump(); tty->cr();
 811     tty->print("this=                   ");                 dump(); tty->cr();
 812     tty->print("mt=(t meet this)=       ");             mt->dump(); tty->cr();
 813 
 814     tty->print("t_dual=                 ");       t->_dual->dump(); tty->cr();
 815     tty->print("this_dual=              ");          _dual->dump(); tty->cr();
 816     tty->print("mt_dual=                ");      mt->_dual->dump(); tty->cr();
 817 
 818     tty->print("mt_dual meet t_dual=    "); t2t           ->dump(); tty->cr();
 819     tty->print("mt_dual meet this_dual= "); t2this        ->dump(); tty->cr();
 820 
 821     fatal("meet not symmetric");
 822   }
 823 #endif
 824 }
 825 
 826 //------------------------------meet-------------------------------------------
 827 // Compute the MEET of two types.  NOT virtual.  It enforces that meet is
 828 // commutative and the lattice is symmetric.
 829 const Type *Type::meet_helper(const Type *t, bool include_speculative) const {
 830   if (isa_narrowoop() && t->isa_narrowoop()) {
 831     const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
 832     return result->make_narrowoop();
 833   }
 834   if (isa_narrowklass() && t->isa_narrowklass()) {
 835     const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
 836     return result->make_narrowklass();
 837   }
 838 
 839   const Type *this_t = maybe_remove_speculative(include_speculative);
 840   t = t->maybe_remove_speculative(include_speculative);
 841 
 842   const Type *mt = this_t->xmeet(t);
 843 #ifdef ASSERT
 844   if (isa_narrowoop() || t->isa_narrowoop()) return mt;
 845   if (isa_narrowklass() || t->isa_narrowklass()) return mt;
 846   Compile* C = Compile::current();
 847   if (!C->_type_verify_symmetry) {
 848     return mt;
 849   }
 850   this_t->check_symmetrical(t, mt);
 851   // In the case of an array, computing the meet above, caused the
 852   // computation of the meet of the elements which at verification
 853   // time caused the computation of the meet of the dual of the
 854   // elements. Computing the meet of the dual of the arrays here
 855   // causes the meet of the dual of the elements to be computed which
 856   // would cause the meet of the dual of the dual of the elements,
 857   // that is the meet of the elements already computed above to be
 858   // computed. Avoid redundant computations by requesting no
 859   // verification.
 860   C->_type_verify_symmetry = false;
 861   const Type *mt_dual = this_t->_dual->xmeet(t->_dual);
 862   this_t->_dual->check_symmetrical(t->_dual, mt_dual);
 863   assert(!C->_type_verify_symmetry, "shouldn't have changed");
 864   C->_type_verify_symmetry = true;
 865 #endif
 866   return mt;
 867 }
 868 
 869 //------------------------------xmeet------------------------------------------
 870 // Compute the MEET of two types.  It returns a new Type object.
 871 const Type *Type::xmeet( const Type *t ) const {
 872   // Perform a fast test for common case; meeting the same types together.
 873   if( this == t ) return this;  // Meeting same type-rep?
 874 
 875   // Meeting TOP with anything?
 876   if( _base == Top ) return t;
 877 
 878   // Meeting BOTTOM with anything?
 879   if( _base == Bottom ) return BOTTOM;
 880 
 881   // Current "this->_base" is one of: Bad, Multi, Control, Top,
 882   // Abio, Abstore, Floatxxx, Doublexxx, Bottom, lastype.
 883   switch (t->base()) {  // Switch on original type
 884 
 885   // Cut in half the number of cases I must handle.  Only need cases for when
 886   // the given enum "t->type" is less than or equal to the local enum "type".
 887   case FloatCon:
 888   case DoubleCon:
 889   case Int:
 890   case Long:
 891     return t->xmeet(this);
 892 
 893   case OopPtr:
 894     return t->xmeet(this);
 895 
 896   case InstPtr:
 897     return t->xmeet(this);
 898 
 899   case MetadataPtr:
 900   case KlassPtr:
 901   case InstKlassPtr:
 902   case AryKlassPtr:
 903     return t->xmeet(this);
 904 
 905   case AryPtr:
 906     return t->xmeet(this);
 907 
 908   case NarrowOop:
 909     return t->xmeet(this);
 910 
 911   case NarrowKlass:
 912     return t->xmeet(this);
 913 
 914   case Bad:                     // Type check
 915   default:                      // Bogus type not in lattice
 916     typerr(t);
 917     return Type::BOTTOM;
 918 
 919   case Bottom:                  // Ye Olde Default
 920     return t;
 921 
 922   case FloatTop:
 923     if( _base == FloatTop ) return this;
 924   case FloatBot:                // Float
 925     if( _base == FloatBot || _base == FloatTop ) return FLOAT;
 926     if( _base == DoubleTop || _base == DoubleBot ) return Type::BOTTOM;
 927     typerr(t);
 928     return Type::BOTTOM;
 929 
 930   case DoubleTop:
 931     if( _base == DoubleTop ) return this;
 932   case DoubleBot:               // Double
 933     if( _base == DoubleBot || _base == DoubleTop ) return DOUBLE;
 934     if( _base == FloatTop || _base == FloatBot ) return Type::BOTTOM;
 935     typerr(t);
 936     return Type::BOTTOM;
 937 
 938   // These next few cases must match exactly or it is a compile-time error.
 939   case Control:                 // Control of code
 940   case Abio:                    // State of world outside of program
 941   case Memory:
 942     if( _base == t->_base )  return this;
 943     typerr(t);
 944     return Type::BOTTOM;
 945 
 946   case Top:                     // Top of the lattice
 947     return this;
 948   }
 949 
 950   // The type is unchanged
 951   return this;
 952 }
 953 
 954 //-----------------------------filter------------------------------------------
 955 const Type *Type::filter_helper(const Type *kills, bool include_speculative) const {
 956   const Type* ft = join_helper(kills, include_speculative);
 957   if (ft->empty())
 958     return Type::TOP;           // Canonical empty value
 959   return ft;
 960 }
 961 
 962 //------------------------------xdual------------------------------------------
 963 const Type *Type::xdual() const {
 964   // Note: the base() accessor asserts the sanity of _base.
 965   assert(_type_info[base()].dual_type != Bad, "implement with v-call");
 966   return new Type(_type_info[_base].dual_type);
 967 }
 968 
 969 //------------------------------has_memory-------------------------------------
 970 bool Type::has_memory() const {
 971   Type::TYPES tx = base();
 972   if (tx == Memory) return true;
 973   if (tx == Tuple) {
 974     const TypeTuple *t = is_tuple();
 975     for (uint i=0; i < t->cnt(); i++) {
 976       tx = t->field_at(i)->base();
 977       if (tx == Memory)  return true;
 978     }
 979   }
 980   return false;
 981 }
 982 
 983 #ifndef PRODUCT
 984 //------------------------------dump2------------------------------------------
 985 void Type::dump2( Dict &d, uint depth, outputStream *st ) const {
 986   st->print("%s", _type_info[_base].msg);
 987 }
 988 
 989 //------------------------------dump-------------------------------------------
 990 void Type::dump_on(outputStream *st) const {
 991   ResourceMark rm;
 992   Dict d(cmpkey,hashkey);       // Stop recursive type dumping
 993   dump2(d,1, st);
 994   if (is_ptr_to_narrowoop()) {
 995     st->print(" [narrow]");
 996   } else if (is_ptr_to_narrowklass()) {
 997     st->print(" [narrowklass]");
 998   }
 999 }
1000 
1001 //-----------------------------------------------------------------------------
1002 const char* Type::str(const Type* t) {
1003   stringStream ss;
1004   t->dump_on(&ss);
1005   return ss.as_string();
1006 }
1007 #endif
1008 
1009 //------------------------------singleton--------------------------------------
1010 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
1011 // constants (Ldi nodes).  Singletons are integer, float or double constants.
1012 bool Type::singleton(void) const {
1013   return _base == Top || _base == Half;
1014 }
1015 
1016 //------------------------------empty------------------------------------------
1017 // TRUE if Type is a type with no values, FALSE otherwise.
1018 bool Type::empty(void) const {
1019   switch (_base) {
1020   case DoubleTop:
1021   case FloatTop:
1022   case Top:
1023     return true;
1024 
1025   case Half:
1026   case Abio:
1027   case Return_Address:
1028   case Memory:
1029   case Bottom:
1030   case FloatBot:
1031   case DoubleBot:
1032     return false;  // never a singleton, therefore never empty
1033 
1034   default:
1035     ShouldNotReachHere();
1036     return false;
1037   }
1038 }
1039 
1040 //------------------------------dump_stats-------------------------------------
1041 // Dump collected statistics to stderr
1042 #ifndef PRODUCT
1043 void Type::dump_stats() {
1044   tty->print("Types made: %d\n", type_dict()->Size());
1045 }
1046 #endif
1047 
1048 //------------------------------category---------------------------------------
1049 #ifndef PRODUCT
1050 Type::Category Type::category() const {
1051   const TypeTuple* tuple;
1052   switch (base()) {
1053     case Type::Int:
1054     case Type::Long:
1055     case Type::Half:
1056     case Type::NarrowOop:
1057     case Type::NarrowKlass:
1058     case Type::Array:
1059     case Type::VectorA:
1060     case Type::VectorS:
1061     case Type::VectorD:
1062     case Type::VectorX:
1063     case Type::VectorY:
1064     case Type::VectorZ:
1065     case Type::VectorMask:
1066     case Type::AnyPtr:
1067     case Type::RawPtr:
1068     case Type::OopPtr:
1069     case Type::InstPtr:
1070     case Type::AryPtr:
1071     case Type::MetadataPtr:
1072     case Type::KlassPtr:
1073     case Type::InstKlassPtr:
1074     case Type::AryKlassPtr:
1075     case Type::Function:
1076     case Type::Return_Address:
1077     case Type::FloatTop:
1078     case Type::FloatCon:
1079     case Type::FloatBot:
1080     case Type::DoubleTop:
1081     case Type::DoubleCon:
1082     case Type::DoubleBot:
1083       return Category::Data;
1084     case Type::Memory:
1085       return Category::Memory;
1086     case Type::Control:
1087       return Category::Control;
1088     case Type::Top:
1089     case Type::Abio:
1090     case Type::Bottom:
1091       return Category::Other;
1092     case Type::Bad:
1093     case Type::lastype:
1094       return Category::Undef;
1095     case Type::Tuple:
1096       // Recursive case. Return CatMixed if the tuple contains types of
1097       // different categories (e.g. CallStaticJavaNode's type), or the specific
1098       // category if all types are of the same category (e.g. IfNode's type).
1099       tuple = is_tuple();
1100       if (tuple->cnt() == 0) {
1101         return Category::Undef;
1102       } else {
1103         Category first = tuple->field_at(0)->category();
1104         for (uint i = 1; i < tuple->cnt(); i++) {
1105           if (tuple->field_at(i)->category() != first) {
1106             return Category::Mixed;
1107           }
1108         }
1109         return first;
1110       }
1111     default:
1112       assert(false, "unmatched base type: all base types must be categorized");
1113   }
1114   return Category::Undef;
1115 }
1116 
1117 bool Type::has_category(Type::Category cat) const {
1118   if (category() == cat) {
1119     return true;
1120   }
1121   if (category() == Category::Mixed) {
1122     const TypeTuple* tuple = is_tuple();
1123     for (uint i = 0; i < tuple->cnt(); i++) {
1124       if (tuple->field_at(i)->has_category(cat)) {
1125         return true;
1126       }
1127     }
1128   }
1129   return false;
1130 }
1131 #endif
1132 
1133 //------------------------------typerr-----------------------------------------
1134 void Type::typerr( const Type *t ) const {
1135 #ifndef PRODUCT
1136   tty->print("\nError mixing types: ");
1137   dump();
1138   tty->print(" and ");
1139   t->dump();
1140   tty->print("\n");
1141 #endif
1142   ShouldNotReachHere();
1143 }
1144 
1145 
1146 //=============================================================================
1147 // Convenience common pre-built types.
1148 const TypeF *TypeF::MAX;        // Floating point max
1149 const TypeF *TypeF::MIN;        // Floating point min
1150 const TypeF *TypeF::ZERO;       // Floating point zero
1151 const TypeF *TypeF::ONE;        // Floating point one
1152 const TypeF *TypeF::POS_INF;    // Floating point positive infinity
1153 const TypeF *TypeF::NEG_INF;    // Floating point negative infinity
1154 
1155 //------------------------------make-------------------------------------------
1156 // Create a float constant
1157 const TypeF *TypeF::make(float f) {
1158   return (TypeF*)(new TypeF(f))->hashcons();
1159 }
1160 
1161 //------------------------------meet-------------------------------------------
1162 // Compute the MEET of two types.  It returns a new Type object.
1163 const Type *TypeF::xmeet( const Type *t ) const {
1164   // Perform a fast test for common case; meeting the same types together.
1165   if( this == t ) return this;  // Meeting same type-rep?
1166 
1167   // Current "this->_base" is FloatCon
1168   switch (t->base()) {          // Switch on original type
1169   case AnyPtr:                  // Mixing with oops happens when javac
1170   case RawPtr:                  // reuses local variables
1171   case OopPtr:
1172   case InstPtr:
1173   case AryPtr:
1174   case MetadataPtr:
1175   case KlassPtr:
1176   case InstKlassPtr:
1177   case AryKlassPtr:
1178   case NarrowOop:
1179   case NarrowKlass:
1180   case Int:
1181   case Long:
1182   case DoubleTop:
1183   case DoubleCon:
1184   case DoubleBot:
1185   case Bottom:                  // Ye Olde Default
1186     return Type::BOTTOM;
1187 
1188   case FloatBot:
1189     return t;
1190 
1191   default:                      // All else is a mistake
1192     typerr(t);
1193 
1194   case FloatCon:                // Float-constant vs Float-constant?
1195     if( jint_cast(_f) != jint_cast(t->getf()) )         // unequal constants?
1196                                 // must compare bitwise as positive zero, negative zero and NaN have
1197                                 // all the same representation in C++
1198       return FLOAT;             // Return generic float
1199                                 // Equal constants
1200   case Top:
1201   case FloatTop:
1202     break;                      // Return the float constant
1203   }
1204   return this;                  // Return the float constant
1205 }
1206 
1207 //------------------------------xdual------------------------------------------
1208 // Dual: symmetric
1209 const Type *TypeF::xdual() const {
1210   return this;
1211 }
1212 
1213 //------------------------------eq---------------------------------------------
1214 // Structural equality check for Type representations
1215 bool TypeF::eq(const Type *t) const {
1216   // Bitwise comparison to distinguish between +/-0. These values must be treated
1217   // as different to be consistent with C1 and the interpreter.
1218   return (jint_cast(_f) == jint_cast(t->getf()));
1219 }
1220 
1221 //------------------------------hash-------------------------------------------
1222 // Type-specific hashing function.
1223 int TypeF::hash(void) const {
1224   return *(int*)(&_f);
1225 }
1226 
1227 //------------------------------is_finite--------------------------------------
1228 // Has a finite value
1229 bool TypeF::is_finite() const {
1230   return g_isfinite(getf()) != 0;
1231 }
1232 
1233 //------------------------------is_nan-----------------------------------------
1234 // Is not a number (NaN)
1235 bool TypeF::is_nan()    const {
1236   return g_isnan(getf()) != 0;
1237 }
1238 
1239 //------------------------------dump2------------------------------------------
1240 // Dump float constant Type
1241 #ifndef PRODUCT
1242 void TypeF::dump2( Dict &d, uint depth, outputStream *st ) const {
1243   Type::dump2(d,depth, st);
1244   st->print("%f", _f);
1245 }
1246 #endif
1247 
1248 //------------------------------singleton--------------------------------------
1249 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
1250 // constants (Ldi nodes).  Singletons are integer, float or double constants
1251 // or a single symbol.
1252 bool TypeF::singleton(void) const {
1253   return true;                  // Always a singleton
1254 }
1255 
1256 bool TypeF::empty(void) const {
1257   return false;                 // always exactly a singleton
1258 }
1259 
1260 //=============================================================================
1261 // Convenience common pre-built types.
1262 const TypeD *TypeD::MAX;        // Floating point max
1263 const TypeD *TypeD::MIN;        // Floating point min
1264 const TypeD *TypeD::ZERO;       // Floating point zero
1265 const TypeD *TypeD::ONE;        // Floating point one
1266 const TypeD *TypeD::POS_INF;    // Floating point positive infinity
1267 const TypeD *TypeD::NEG_INF;    // Floating point negative infinity
1268 
1269 //------------------------------make-------------------------------------------
1270 const TypeD *TypeD::make(double d) {
1271   return (TypeD*)(new TypeD(d))->hashcons();
1272 }
1273 
1274 //------------------------------meet-------------------------------------------
1275 // Compute the MEET of two types.  It returns a new Type object.
1276 const Type *TypeD::xmeet( const Type *t ) const {
1277   // Perform a fast test for common case; meeting the same types together.
1278   if( this == t ) return this;  // Meeting same type-rep?
1279 
1280   // Current "this->_base" is DoubleCon
1281   switch (t->base()) {          // Switch on original type
1282   case AnyPtr:                  // Mixing with oops happens when javac
1283   case RawPtr:                  // reuses local variables
1284   case OopPtr:
1285   case InstPtr:
1286   case AryPtr:
1287   case MetadataPtr:
1288   case KlassPtr:
1289   case InstKlassPtr:
1290   case AryKlassPtr:
1291   case NarrowOop:
1292   case NarrowKlass:
1293   case Int:
1294   case Long:
1295   case FloatTop:
1296   case FloatCon:
1297   case FloatBot:
1298   case Bottom:                  // Ye Olde Default
1299     return Type::BOTTOM;
1300 
1301   case DoubleBot:
1302     return t;
1303 
1304   default:                      // All else is a mistake
1305     typerr(t);
1306 
1307   case DoubleCon:               // Double-constant vs Double-constant?
1308     if( jlong_cast(_d) != jlong_cast(t->getd()) )       // unequal constants? (see comment in TypeF::xmeet)
1309       return DOUBLE;            // Return generic double
1310   case Top:
1311   case DoubleTop:
1312     break;
1313   }
1314   return this;                  // Return the double constant
1315 }
1316 
1317 //------------------------------xdual------------------------------------------
1318 // Dual: symmetric
1319 const Type *TypeD::xdual() const {
1320   return this;
1321 }
1322 
1323 //------------------------------eq---------------------------------------------
1324 // Structural equality check for Type representations
1325 bool TypeD::eq(const Type *t) const {
1326   // Bitwise comparison to distinguish between +/-0. These values must be treated
1327   // as different to be consistent with C1 and the interpreter.
1328   return (jlong_cast(_d) == jlong_cast(t->getd()));
1329 }
1330 
1331 //------------------------------hash-------------------------------------------
1332 // Type-specific hashing function.
1333 int TypeD::hash(void) const {
1334   return *(int*)(&_d);
1335 }
1336 
1337 //------------------------------is_finite--------------------------------------
1338 // Has a finite value
1339 bool TypeD::is_finite() const {
1340   return g_isfinite(getd()) != 0;
1341 }
1342 
1343 //------------------------------is_nan-----------------------------------------
1344 // Is not a number (NaN)
1345 bool TypeD::is_nan()    const {
1346   return g_isnan(getd()) != 0;
1347 }
1348 
1349 //------------------------------dump2------------------------------------------
1350 // Dump double constant Type
1351 #ifndef PRODUCT
1352 void TypeD::dump2( Dict &d, uint depth, outputStream *st ) const {
1353   Type::dump2(d,depth,st);
1354   st->print("%f", _d);
1355 }
1356 #endif
1357 
1358 //------------------------------singleton--------------------------------------
1359 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
1360 // constants (Ldi nodes).  Singletons are integer, float or double constants
1361 // or a single symbol.
1362 bool TypeD::singleton(void) const {
1363   return true;                  // Always a singleton
1364 }
1365 
1366 bool TypeD::empty(void) const {
1367   return false;                 // always exactly a singleton
1368 }
1369 
1370 const TypeInteger* TypeInteger::make(jlong lo, jlong hi, int w, BasicType bt) {
1371   if (bt == T_INT) {
1372     return TypeInt::make(checked_cast<jint>(lo), checked_cast<jint>(hi), w);
1373   }
1374   assert(bt == T_LONG, "basic type not an int or long");
1375   return TypeLong::make(lo, hi, w);
1376 }
1377 
1378 jlong TypeInteger::get_con_as_long(BasicType bt) const {
1379   if (bt == T_INT) {
1380     return is_int()->get_con();
1381   }
1382   assert(bt == T_LONG, "basic type not an int or long");
1383   return is_long()->get_con();
1384 }
1385 
1386 const TypeInteger* TypeInteger::bottom(BasicType bt) {
1387   if (bt == T_INT) {
1388     return TypeInt::INT;
1389   }
1390   assert(bt == T_LONG, "basic type not an int or long");
1391   return TypeLong::LONG;
1392 }
1393 
1394 const TypeInteger* TypeInteger::zero(BasicType bt) {
1395   if (bt == T_INT) {
1396     return TypeInt::ZERO;
1397   }
1398   assert(bt == T_LONG, "basic type not an int or long");
1399   return TypeLong::ZERO;
1400 }
1401 
1402 const TypeInteger* TypeInteger::one(BasicType bt) {
1403   if (bt == T_INT) {
1404     return TypeInt::ONE;
1405   }
1406   assert(bt == T_LONG, "basic type not an int or long");
1407   return TypeLong::ONE;
1408 }
1409 
1410 const TypeInteger* TypeInteger::minus_1(BasicType bt) {
1411   if (bt == T_INT) {
1412     return TypeInt::MINUS_1;
1413   }
1414   assert(bt == T_LONG, "basic type not an int or long");
1415   return TypeLong::MINUS_1;
1416 }
1417 
1418 //=============================================================================
1419 // Convenience common pre-built types.
1420 const TypeInt *TypeInt::MAX;    // INT_MAX
1421 const TypeInt *TypeInt::MIN;    // INT_MIN
1422 const TypeInt *TypeInt::MINUS_1;// -1
1423 const TypeInt *TypeInt::ZERO;   // 0
1424 const TypeInt *TypeInt::ONE;    // 1
1425 const TypeInt *TypeInt::BOOL;   // 0 or 1, FALSE or TRUE.
1426 const TypeInt *TypeInt::CC;     // -1,0 or 1, condition codes
1427 const TypeInt *TypeInt::CC_LT;  // [-1]  == MINUS_1
1428 const TypeInt *TypeInt::CC_GT;  // [1]   == ONE
1429 const TypeInt *TypeInt::CC_EQ;  // [0]   == ZERO
1430 const TypeInt *TypeInt::CC_LE;  // [-1,0]
1431 const TypeInt *TypeInt::CC_GE;  // [0,1] == BOOL (!)
1432 const TypeInt *TypeInt::BYTE;   // Bytes, -128 to 127
1433 const TypeInt *TypeInt::UBYTE;  // Unsigned Bytes, 0 to 255
1434 const TypeInt *TypeInt::CHAR;   // Java chars, 0-65535
1435 const TypeInt *TypeInt::SHORT;  // Java shorts, -32768-32767
1436 const TypeInt *TypeInt::POS;    // Positive 32-bit integers or zero
1437 const TypeInt *TypeInt::POS1;   // Positive 32-bit integers
1438 const TypeInt *TypeInt::INT;    // 32-bit integers
1439 const TypeInt *TypeInt::SYMINT; // symmetric range [-max_jint..max_jint]
1440 const TypeInt *TypeInt::TYPE_DOMAIN; // alias for TypeInt::INT
1441 
1442 //------------------------------TypeInt----------------------------------------
1443 TypeInt::TypeInt( jint lo, jint hi, int w ) : TypeInteger(Int, w), _lo(lo), _hi(hi) {
1444 }
1445 
1446 //------------------------------make-------------------------------------------
1447 const TypeInt *TypeInt::make( jint lo ) {
1448   return (TypeInt*)(new TypeInt(lo,lo,WidenMin))->hashcons();
1449 }
1450 
1451 static int normalize_int_widen( jint lo, jint hi, int w ) {
1452   // Certain normalizations keep us sane when comparing types.
1453   // The 'SMALLINT' covers constants and also CC and its relatives.
1454   if (lo <= hi) {
1455     if (((juint)hi - lo) <= SMALLINT)  w = Type::WidenMin;
1456     if (((juint)hi - lo) >= max_juint) w = Type::WidenMax; // TypeInt::INT
1457   } else {
1458     if (((juint)lo - hi) <= SMALLINT)  w = Type::WidenMin;
1459     if (((juint)lo - hi) >= max_juint) w = Type::WidenMin; // dual TypeInt::INT
1460   }
1461   return w;
1462 }
1463 
1464 const TypeInt *TypeInt::make( jint lo, jint hi, int w ) {
1465   w = normalize_int_widen(lo, hi, w);
1466   return (TypeInt*)(new TypeInt(lo,hi,w))->hashcons();
1467 }
1468 
1469 //------------------------------meet-------------------------------------------
1470 // Compute the MEET of two types.  It returns a new Type representation object
1471 // with reference count equal to the number of Types pointing at it.
1472 // Caller should wrap a Types around it.
1473 const Type *TypeInt::xmeet( const Type *t ) const {
1474   // Perform a fast test for common case; meeting the same types together.
1475   if( this == t ) return this;  // Meeting same type?
1476 
1477   // Currently "this->_base" is a TypeInt
1478   switch (t->base()) {          // Switch on original type
1479   case AnyPtr:                  // Mixing with oops happens when javac
1480   case RawPtr:                  // reuses local variables
1481   case OopPtr:
1482   case InstPtr:
1483   case AryPtr:
1484   case MetadataPtr:
1485   case KlassPtr:
1486   case InstKlassPtr:
1487   case AryKlassPtr:
1488   case NarrowOop:
1489   case NarrowKlass:
1490   case Long:
1491   case FloatTop:
1492   case FloatCon:
1493   case FloatBot:
1494   case DoubleTop:
1495   case DoubleCon:
1496   case DoubleBot:
1497   case Bottom:                  // Ye Olde Default
1498     return Type::BOTTOM;
1499   default:                      // All else is a mistake
1500     typerr(t);
1501   case Top:                     // No change
1502     return this;
1503   case Int:                     // Int vs Int?
1504     break;
1505   }
1506 
1507   // Expand covered set
1508   const TypeInt *r = t->is_int();
1509   return make( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) );
1510 }
1511 
1512 //------------------------------xdual------------------------------------------
1513 // Dual: reverse hi & lo; flip widen
1514 const Type *TypeInt::xdual() const {
1515   int w = normalize_int_widen(_hi,_lo, WidenMax-_widen);
1516   return new TypeInt(_hi,_lo,w);
1517 }
1518 
1519 //------------------------------widen------------------------------------------
1520 // Only happens for optimistic top-down optimizations.
1521 const Type *TypeInt::widen( const Type *old, const Type* limit ) const {
1522   // Coming from TOP or such; no widening
1523   if( old->base() != Int ) return this;
1524   const TypeInt *ot = old->is_int();
1525 
1526   // If new guy is equal to old guy, no widening
1527   if( _lo == ot->_lo && _hi == ot->_hi )
1528     return old;
1529 
1530   // If new guy contains old, then we widened
1531   if( _lo <= ot->_lo && _hi >= ot->_hi ) {
1532     // New contains old
1533     // If new guy is already wider than old, no widening
1534     if( _widen > ot->_widen ) return this;
1535     // If old guy was a constant, do not bother
1536     if (ot->_lo == ot->_hi)  return this;
1537     // Now widen new guy.
1538     // Check for widening too far
1539     if (_widen == WidenMax) {
1540       int max = max_jint;
1541       int min = min_jint;
1542       if (limit->isa_int()) {
1543         max = limit->is_int()->_hi;
1544         min = limit->is_int()->_lo;
1545       }
1546       if (min < _lo && _hi < max) {
1547         // If neither endpoint is extremal yet, push out the endpoint
1548         // which is closer to its respective limit.
1549         if (_lo >= 0 ||                 // easy common case
1550             (juint)(_lo - min) >= (juint)(max - _hi)) {
1551           // Try to widen to an unsigned range type of 31 bits:
1552           return make(_lo, max, WidenMax);
1553         } else {
1554           return make(min, _hi, WidenMax);
1555         }
1556       }
1557       return TypeInt::INT;
1558     }
1559     // Returned widened new guy
1560     return make(_lo,_hi,_widen+1);
1561   }
1562 
1563   // If old guy contains new, then we probably widened too far & dropped to
1564   // bottom.  Return the wider fellow.
1565   if ( ot->_lo <= _lo && ot->_hi >= _hi )
1566     return old;
1567 
1568   //fatal("Integer value range is not subset");
1569   //return this;
1570   return TypeInt::INT;
1571 }
1572 
1573 //------------------------------narrow---------------------------------------
1574 // Only happens for pessimistic optimizations.
1575 const Type *TypeInt::narrow( const Type *old ) const {
1576   if (_lo >= _hi)  return this;   // already narrow enough
1577   if (old == NULL)  return this;
1578   const TypeInt* ot = old->isa_int();
1579   if (ot == NULL)  return this;
1580   jint olo = ot->_lo;
1581   jint ohi = ot->_hi;
1582 
1583   // If new guy is equal to old guy, no narrowing
1584   if (_lo == olo && _hi == ohi)  return old;
1585 
1586   // If old guy was maximum range, allow the narrowing
1587   if (olo == min_jint && ohi == max_jint)  return this;
1588 
1589   if (_lo < olo || _hi > ohi)
1590     return this;                // doesn't narrow; pretty weird
1591 
1592   // The new type narrows the old type, so look for a "death march".
1593   // See comments on PhaseTransform::saturate.
1594   juint nrange = (juint)_hi - _lo;
1595   juint orange = (juint)ohi - olo;
1596   if (nrange < max_juint - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
1597     // Use the new type only if the range shrinks a lot.
1598     // We do not want the optimizer computing 2^31 point by point.
1599     return old;
1600   }
1601 
1602   return this;
1603 }
1604 
1605 //-----------------------------filter------------------------------------------
1606 const Type *TypeInt::filter_helper(const Type *kills, bool include_speculative) const {
1607   const TypeInt* ft = join_helper(kills, include_speculative)->isa_int();
1608   if (ft == NULL || ft->empty())
1609     return Type::TOP;           // Canonical empty value
1610   if (ft->_widen < this->_widen) {
1611     // Do not allow the value of kill->_widen to affect the outcome.
1612     // The widen bits must be allowed to run freely through the graph.
1613     ft = TypeInt::make(ft->_lo, ft->_hi, this->_widen);
1614   }
1615   return ft;
1616 }
1617 
1618 //------------------------------eq---------------------------------------------
1619 // Structural equality check for Type representations
1620 bool TypeInt::eq( const Type *t ) const {
1621   const TypeInt *r = t->is_int(); // Handy access
1622   return r->_lo == _lo && r->_hi == _hi && r->_widen == _widen;
1623 }
1624 
1625 //------------------------------hash-------------------------------------------
1626 // Type-specific hashing function.
1627 int TypeInt::hash(void) const {
1628   return java_add(java_add(_lo, _hi), java_add((jint)_widen, (jint)Type::Int));
1629 }
1630 
1631 //------------------------------is_finite--------------------------------------
1632 // Has a finite value
1633 bool TypeInt::is_finite() const {
1634   return true;
1635 }
1636 
1637 //------------------------------dump2------------------------------------------
1638 // Dump TypeInt
1639 #ifndef PRODUCT
1640 static const char* intname(char* buf, size_t buf_size, jint n) {
1641   if (n == min_jint)
1642     return "min";
1643   else if (n < min_jint + 10000)
1644     os::snprintf_checked(buf, buf_size, "min+" INT32_FORMAT, n - min_jint);
1645   else if (n == max_jint)
1646     return "max";
1647   else if (n > max_jint - 10000)
1648     os::snprintf_checked(buf, buf_size, "max-" INT32_FORMAT, max_jint - n);
1649   else
1650     os::snprintf_checked(buf, buf_size, INT32_FORMAT, n);
1651   return buf;
1652 }
1653 
1654 void TypeInt::dump2( Dict &d, uint depth, outputStream *st ) const {
1655   char buf[40], buf2[40];
1656   if (_lo == min_jint && _hi == max_jint)
1657     st->print("int");
1658   else if (is_con())
1659     st->print("int:%s", intname(buf, sizeof(buf), get_con()));
1660   else if (_lo == BOOL->_lo && _hi == BOOL->_hi)
1661     st->print("bool");
1662   else if (_lo == BYTE->_lo && _hi == BYTE->_hi)
1663     st->print("byte");
1664   else if (_lo == CHAR->_lo && _hi == CHAR->_hi)
1665     st->print("char");
1666   else if (_lo == SHORT->_lo && _hi == SHORT->_hi)
1667     st->print("short");
1668   else if (_hi == max_jint)
1669     st->print("int:>=%s", intname(buf, sizeof(buf), _lo));
1670   else if (_lo == min_jint)
1671     st->print("int:<=%s", intname(buf, sizeof(buf), _hi));
1672   else
1673     st->print("int:%s..%s", intname(buf, sizeof(buf), _lo), intname(buf2, sizeof(buf2), _hi));
1674 
1675   if (_widen != 0 && this != TypeInt::INT)
1676     st->print(":%.*s", _widen, "wwww");
1677 }
1678 #endif
1679 
1680 //------------------------------singleton--------------------------------------
1681 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
1682 // constants.
1683 bool TypeInt::singleton(void) const {
1684   return _lo >= _hi;
1685 }
1686 
1687 bool TypeInt::empty(void) const {
1688   return _lo > _hi;
1689 }
1690 
1691 //=============================================================================
1692 // Convenience common pre-built types.
1693 const TypeLong *TypeLong::MAX;
1694 const TypeLong *TypeLong::MIN;
1695 const TypeLong *TypeLong::MINUS_1;// -1
1696 const TypeLong *TypeLong::ZERO; // 0
1697 const TypeLong *TypeLong::ONE;  // 1
1698 const TypeLong *TypeLong::POS;  // >=0
1699 const TypeLong *TypeLong::LONG; // 64-bit integers
1700 const TypeLong *TypeLong::INT;  // 32-bit subrange
1701 const TypeLong *TypeLong::UINT; // 32-bit unsigned subrange
1702 const TypeLong *TypeLong::TYPE_DOMAIN; // alias for TypeLong::LONG
1703 
1704 //------------------------------TypeLong---------------------------------------
1705 TypeLong::TypeLong(jlong lo, jlong hi, int w) : TypeInteger(Long, w), _lo(lo), _hi(hi) {
1706 }
1707 
1708 //------------------------------make-------------------------------------------
1709 const TypeLong *TypeLong::make( jlong lo ) {
1710   return (TypeLong*)(new TypeLong(lo,lo,WidenMin))->hashcons();
1711 }
1712 
1713 static int normalize_long_widen( jlong lo, jlong hi, int w ) {
1714   // Certain normalizations keep us sane when comparing types.
1715   // The 'SMALLINT' covers constants.
1716   if (lo <= hi) {
1717     if (((julong)hi - lo) <= SMALLINT)   w = Type::WidenMin;
1718     if (((julong)hi - lo) >= max_julong) w = Type::WidenMax; // TypeLong::LONG
1719   } else {
1720     if (((julong)lo - hi) <= SMALLINT)   w = Type::WidenMin;
1721     if (((julong)lo - hi) >= max_julong) w = Type::WidenMin; // dual TypeLong::LONG
1722   }
1723   return w;
1724 }
1725 
1726 const TypeLong *TypeLong::make( jlong lo, jlong hi, int w ) {
1727   w = normalize_long_widen(lo, hi, w);
1728   return (TypeLong*)(new TypeLong(lo,hi,w))->hashcons();
1729 }
1730 
1731 
1732 //------------------------------meet-------------------------------------------
1733 // Compute the MEET of two types.  It returns a new Type representation object
1734 // with reference count equal to the number of Types pointing at it.
1735 // Caller should wrap a Types around it.
1736 const Type *TypeLong::xmeet( const Type *t ) const {
1737   // Perform a fast test for common case; meeting the same types together.
1738   if( this == t ) return this;  // Meeting same type?
1739 
1740   // Currently "this->_base" is a TypeLong
1741   switch (t->base()) {          // Switch on original type
1742   case AnyPtr:                  // Mixing with oops happens when javac
1743   case RawPtr:                  // reuses local variables
1744   case OopPtr:
1745   case InstPtr:
1746   case AryPtr:
1747   case MetadataPtr:
1748   case KlassPtr:
1749   case InstKlassPtr:
1750   case AryKlassPtr:
1751   case NarrowOop:
1752   case NarrowKlass:
1753   case Int:
1754   case FloatTop:
1755   case FloatCon:
1756   case FloatBot:
1757   case DoubleTop:
1758   case DoubleCon:
1759   case DoubleBot:
1760   case Bottom:                  // Ye Olde Default
1761     return Type::BOTTOM;
1762   default:                      // All else is a mistake
1763     typerr(t);
1764   case Top:                     // No change
1765     return this;
1766   case Long:                    // Long vs Long?
1767     break;
1768   }
1769 
1770   // Expand covered set
1771   const TypeLong *r = t->is_long(); // Turn into a TypeLong
1772   return make( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) );
1773 }
1774 
1775 //------------------------------xdual------------------------------------------
1776 // Dual: reverse hi & lo; flip widen
1777 const Type *TypeLong::xdual() const {
1778   int w = normalize_long_widen(_hi,_lo, WidenMax-_widen);
1779   return new TypeLong(_hi,_lo,w);
1780 }
1781 
1782 //------------------------------widen------------------------------------------
1783 // Only happens for optimistic top-down optimizations.
1784 const Type *TypeLong::widen( const Type *old, const Type* limit ) const {
1785   // Coming from TOP or such; no widening
1786   if( old->base() != Long ) return this;
1787   const TypeLong *ot = old->is_long();
1788 
1789   // If new guy is equal to old guy, no widening
1790   if( _lo == ot->_lo && _hi == ot->_hi )
1791     return old;
1792 
1793   // If new guy contains old, then we widened
1794   if( _lo <= ot->_lo && _hi >= ot->_hi ) {
1795     // New contains old
1796     // If new guy is already wider than old, no widening
1797     if( _widen > ot->_widen ) return this;
1798     // If old guy was a constant, do not bother
1799     if (ot->_lo == ot->_hi)  return this;
1800     // Now widen new guy.
1801     // Check for widening too far
1802     if (_widen == WidenMax) {
1803       jlong max = max_jlong;
1804       jlong min = min_jlong;
1805       if (limit->isa_long()) {
1806         max = limit->is_long()->_hi;
1807         min = limit->is_long()->_lo;
1808       }
1809       if (min < _lo && _hi < max) {
1810         // If neither endpoint is extremal yet, push out the endpoint
1811         // which is closer to its respective limit.
1812         if (_lo >= 0 ||                 // easy common case
1813             ((julong)_lo - min) >= ((julong)max - _hi)) {
1814           // Try to widen to an unsigned range type of 32/63 bits:
1815           if (max >= max_juint && _hi < max_juint)
1816             return make(_lo, max_juint, WidenMax);
1817           else
1818             return make(_lo, max, WidenMax);
1819         } else {
1820           return make(min, _hi, WidenMax);
1821         }
1822       }
1823       return TypeLong::LONG;
1824     }
1825     // Returned widened new guy
1826     return make(_lo,_hi,_widen+1);
1827   }
1828 
1829   // If old guy contains new, then we probably widened too far & dropped to
1830   // bottom.  Return the wider fellow.
1831   if ( ot->_lo <= _lo && ot->_hi >= _hi )
1832     return old;
1833 
1834   //  fatal("Long value range is not subset");
1835   // return this;
1836   return TypeLong::LONG;
1837 }
1838 
1839 //------------------------------narrow----------------------------------------
1840 // Only happens for pessimistic optimizations.
1841 const Type *TypeLong::narrow( const Type *old ) const {
1842   if (_lo >= _hi)  return this;   // already narrow enough
1843   if (old == NULL)  return this;
1844   const TypeLong* ot = old->isa_long();
1845   if (ot == NULL)  return this;
1846   jlong olo = ot->_lo;
1847   jlong ohi = ot->_hi;
1848 
1849   // If new guy is equal to old guy, no narrowing
1850   if (_lo == olo && _hi == ohi)  return old;
1851 
1852   // If old guy was maximum range, allow the narrowing
1853   if (olo == min_jlong && ohi == max_jlong)  return this;
1854 
1855   if (_lo < olo || _hi > ohi)
1856     return this;                // doesn't narrow; pretty weird
1857 
1858   // The new type narrows the old type, so look for a "death march".
1859   // See comments on PhaseTransform::saturate.
1860   julong nrange = _hi - _lo;
1861   julong orange = ohi - olo;
1862   if (nrange < max_julong - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
1863     // Use the new type only if the range shrinks a lot.
1864     // We do not want the optimizer computing 2^31 point by point.
1865     return old;
1866   }
1867 
1868   return this;
1869 }
1870 
1871 //-----------------------------filter------------------------------------------
1872 const Type *TypeLong::filter_helper(const Type *kills, bool include_speculative) const {
1873   const TypeLong* ft = join_helper(kills, include_speculative)->isa_long();
1874   if (ft == NULL || ft->empty())
1875     return Type::TOP;           // Canonical empty value
1876   if (ft->_widen < this->_widen) {
1877     // Do not allow the value of kill->_widen to affect the outcome.
1878     // The widen bits must be allowed to run freely through the graph.
1879     ft = TypeLong::make(ft->_lo, ft->_hi, this->_widen);
1880   }
1881   return ft;
1882 }
1883 
1884 //------------------------------eq---------------------------------------------
1885 // Structural equality check for Type representations
1886 bool TypeLong::eq( const Type *t ) const {
1887   const TypeLong *r = t->is_long(); // Handy access
1888   return r->_lo == _lo &&  r->_hi == _hi  && r->_widen == _widen;
1889 }
1890 
1891 //------------------------------hash-------------------------------------------
1892 // Type-specific hashing function.
1893 int TypeLong::hash(void) const {
1894   return (int)(_lo+_hi+_widen+(int)Type::Long);
1895 }
1896 
1897 //------------------------------is_finite--------------------------------------
1898 // Has a finite value
1899 bool TypeLong::is_finite() const {
1900   return true;
1901 }
1902 
1903 //------------------------------dump2------------------------------------------
1904 // Dump TypeLong
1905 #ifndef PRODUCT
1906 static const char* longnamenear(jlong x, const char* xname, char* buf, size_t buf_size, jlong n) {
1907   if (n > x) {
1908     if (n >= x + 10000)  return NULL;
1909     os::snprintf_checked(buf, buf_size, "%s+" JLONG_FORMAT, xname, n - x);
1910   } else if (n < x) {
1911     if (n <= x - 10000)  return NULL;
1912     os::snprintf_checked(buf, buf_size, "%s-" JLONG_FORMAT, xname, x - n);
1913   } else {
1914     return xname;
1915   }
1916   return buf;
1917 }
1918 
1919 static const char* longname(char* buf, size_t buf_size, jlong n) {
1920   const char* str;
1921   if (n == min_jlong)
1922     return "min";
1923   else if (n < min_jlong + 10000)
1924     os::snprintf_checked(buf, buf_size, "min+" JLONG_FORMAT, n - min_jlong);
1925   else if (n == max_jlong)
1926     return "max";
1927   else if (n > max_jlong - 10000)
1928     os::snprintf_checked(buf, buf_size, "max-" JLONG_FORMAT, max_jlong - n);
1929   else if ((str = longnamenear(max_juint, "maxuint", buf, buf_size, n)) != NULL)
1930     return str;
1931   else if ((str = longnamenear(max_jint, "maxint", buf, buf_size, n)) != NULL)
1932     return str;
1933   else if ((str = longnamenear(min_jint, "minint", buf, buf_size, n)) != NULL)
1934     return str;
1935   else
1936     os::snprintf_checked(buf, buf_size, JLONG_FORMAT, n);
1937   return buf;
1938 }
1939 
1940 void TypeLong::dump2( Dict &d, uint depth, outputStream *st ) const {
1941   char buf[80], buf2[80];
1942   if (_lo == min_jlong && _hi == max_jlong)
1943     st->print("long");
1944   else if (is_con())
1945     st->print("long:%s", longname(buf, sizeof(buf), get_con()));
1946   else if (_hi == max_jlong)
1947     st->print("long:>=%s", longname(buf, sizeof(buf), _lo));
1948   else if (_lo == min_jlong)
1949     st->print("long:<=%s", longname(buf, sizeof(buf), _hi));
1950   else
1951     st->print("long:%s..%s", longname(buf, sizeof(buf), _lo), longname(buf2,sizeof(buf2),  _hi));
1952 
1953   if (_widen != 0 && this != TypeLong::LONG)
1954     st->print(":%.*s", _widen, "wwww");
1955 }
1956 #endif
1957 
1958 //------------------------------singleton--------------------------------------
1959 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
1960 // constants
1961 bool TypeLong::singleton(void) const {
1962   return _lo >= _hi;
1963 }
1964 
1965 bool TypeLong::empty(void) const {
1966   return _lo > _hi;
1967 }
1968 
1969 //=============================================================================
1970 // Convenience common pre-built types.
1971 const TypeTuple *TypeTuple::IFBOTH;     // Return both arms of IF as reachable
1972 const TypeTuple *TypeTuple::IFFALSE;
1973 const TypeTuple *TypeTuple::IFTRUE;
1974 const TypeTuple *TypeTuple::IFNEITHER;
1975 const TypeTuple *TypeTuple::LOOPBODY;
1976 const TypeTuple *TypeTuple::MEMBAR;
1977 const TypeTuple *TypeTuple::STORECONDITIONAL;
1978 const TypeTuple *TypeTuple::START_I2C;
1979 const TypeTuple *TypeTuple::INT_PAIR;
1980 const TypeTuple *TypeTuple::LONG_PAIR;
1981 const TypeTuple *TypeTuple::INT_CC_PAIR;
1982 const TypeTuple *TypeTuple::LONG_CC_PAIR;
1983 
1984 //------------------------------make-------------------------------------------
1985 // Make a TypeTuple from the range of a method signature
1986 const TypeTuple *TypeTuple::make_range(ciSignature* sig, InterfaceHandling interface_handling) {
1987   ciType* return_type = sig->return_type();
1988   uint arg_cnt = return_type->size();
1989   const Type **field_array = fields(arg_cnt);
1990   switch (return_type->basic_type()) {
1991   case T_LONG:
1992     field_array[TypeFunc::Parms]   = TypeLong::LONG;
1993     field_array[TypeFunc::Parms+1] = Type::HALF;
1994     break;
1995   case T_DOUBLE:
1996     field_array[TypeFunc::Parms]   = Type::DOUBLE;
1997     field_array[TypeFunc::Parms+1] = Type::HALF;
1998     break;
1999   case T_OBJECT:
2000   case T_ARRAY:
2001   case T_BOOLEAN:
2002   case T_CHAR:
2003   case T_FLOAT:
2004   case T_BYTE:
2005   case T_SHORT:
2006   case T_INT:
2007     field_array[TypeFunc::Parms] = get_const_type(return_type, interface_handling);
2008     break;
2009   case T_VOID:
2010     break;
2011   default:
2012     ShouldNotReachHere();
2013   }
2014   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2015 }
2016 
2017 // Make a TypeTuple from the domain of a method signature
2018 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig, InterfaceHandling interface_handling) {
2019   uint arg_cnt = sig->size();
2020 
2021   uint pos = TypeFunc::Parms;
2022   const Type **field_array;
2023   if (recv != NULL) {
2024     arg_cnt++;
2025     field_array = fields(arg_cnt);
2026     // Use get_const_type here because it respects UseUniqueSubclasses:
2027     field_array[pos++] = get_const_type(recv, interface_handling)->join_speculative(TypePtr::NOTNULL);
2028   } else {
2029     field_array = fields(arg_cnt);
2030   }
2031 
2032   int i = 0;
2033   while (pos < TypeFunc::Parms + arg_cnt) {
2034     ciType* type = sig->type_at(i);
2035 
2036     switch (type->basic_type()) {
2037     case T_LONG:
2038       field_array[pos++] = TypeLong::LONG;
2039       field_array[pos++] = Type::HALF;
2040       break;
2041     case T_DOUBLE:
2042       field_array[pos++] = Type::DOUBLE;
2043       field_array[pos++] = Type::HALF;
2044       break;
2045     case T_OBJECT:
2046     case T_ARRAY:
2047     case T_FLOAT:
2048     case T_INT:
2049       field_array[pos++] = get_const_type(type, interface_handling);
2050       break;
2051     case T_BOOLEAN:
2052     case T_CHAR:
2053     case T_BYTE:
2054     case T_SHORT:
2055       field_array[pos++] = TypeInt::INT;
2056       break;
2057     default:
2058       ShouldNotReachHere();
2059     }
2060     i++;
2061   }
2062 
2063   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2064 }
2065 
2066 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2067   return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2068 }
2069 
2070 //------------------------------fields-----------------------------------------
2071 // Subroutine call type with space allocated for argument types
2072 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
2073 const Type **TypeTuple::fields( uint arg_cnt ) {
2074   const Type **flds = (const Type **)(Compile::current()->type_arena()->AmallocWords((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
2075   flds[TypeFunc::Control  ] = Type::CONTROL;
2076   flds[TypeFunc::I_O      ] = Type::ABIO;
2077   flds[TypeFunc::Memory   ] = Type::MEMORY;
2078   flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
2079   flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
2080 
2081   return flds;
2082 }
2083 
2084 //------------------------------meet-------------------------------------------
2085 // Compute the MEET of two types.  It returns a new Type object.
2086 const Type *TypeTuple::xmeet( const Type *t ) const {
2087   // Perform a fast test for common case; meeting the same types together.
2088   if( this == t ) return this;  // Meeting same type-rep?
2089 
2090   // Current "this->_base" is Tuple
2091   switch (t->base()) {          // switch on original type
2092 
2093   case Bottom:                  // Ye Olde Default
2094     return t;
2095 
2096   default:                      // All else is a mistake
2097     typerr(t);
2098 
2099   case Tuple: {                 // Meeting 2 signatures?
2100     const TypeTuple *x = t->is_tuple();
2101     assert( _cnt == x->_cnt, "" );
2102     const Type **fields = (const Type **)(Compile::current()->type_arena()->AmallocWords( _cnt*sizeof(Type*) ));
2103     for( uint i=0; i<_cnt; i++ )
2104       fields[i] = field_at(i)->xmeet( x->field_at(i) );
2105     return TypeTuple::make(_cnt,fields);
2106   }
2107   case Top:
2108     break;
2109   }
2110   return this;                  // Return the double constant
2111 }
2112 
2113 //------------------------------xdual------------------------------------------
2114 // Dual: compute field-by-field dual
2115 const Type *TypeTuple::xdual() const {
2116   const Type **fields = (const Type **)(Compile::current()->type_arena()->AmallocWords( _cnt*sizeof(Type*) ));
2117   for( uint i=0; i<_cnt; i++ )
2118     fields[i] = _fields[i]->dual();
2119   return new TypeTuple(_cnt,fields);
2120 }
2121 
2122 //------------------------------eq---------------------------------------------
2123 // Structural equality check for Type representations
2124 bool TypeTuple::eq( const Type *t ) const {
2125   const TypeTuple *s = (const TypeTuple *)t;
2126   if (_cnt != s->_cnt)  return false;  // Unequal field counts
2127   for (uint i = 0; i < _cnt; i++)
2128     if (field_at(i) != s->field_at(i)) // POINTER COMPARE!  NO RECURSION!
2129       return false;             // Missed
2130   return true;
2131 }
2132 
2133 //------------------------------hash-------------------------------------------
2134 // Type-specific hashing function.
2135 int TypeTuple::hash(void) const {
2136   intptr_t sum = _cnt;
2137   for( uint i=0; i<_cnt; i++ )
2138     sum += (intptr_t)_fields[i];     // Hash on pointers directly
2139   return sum;
2140 }
2141 
2142 //------------------------------dump2------------------------------------------
2143 // Dump signature Type
2144 #ifndef PRODUCT
2145 void TypeTuple::dump2( Dict &d, uint depth, outputStream *st ) const {
2146   st->print("{");
2147   if( !depth || d[this] ) {     // Check for recursive print
2148     st->print("...}");
2149     return;
2150   }
2151   d.Insert((void*)this, (void*)this);   // Stop recursion
2152   if( _cnt ) {
2153     uint i;
2154     for( i=0; i<_cnt-1; i++ ) {
2155       st->print("%d:", i);
2156       _fields[i]->dump2(d, depth-1, st);
2157       st->print(", ");
2158     }
2159     st->print("%d:", i);
2160     _fields[i]->dump2(d, depth-1, st);
2161   }
2162   st->print("}");
2163 }
2164 #endif
2165 
2166 //------------------------------singleton--------------------------------------
2167 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2168 // constants (Ldi nodes).  Singletons are integer, float or double constants
2169 // or a single symbol.
2170 bool TypeTuple::singleton(void) const {
2171   return false;                 // Never a singleton
2172 }
2173 
2174 bool TypeTuple::empty(void) const {
2175   for( uint i=0; i<_cnt; i++ ) {
2176     if (_fields[i]->empty())  return true;
2177   }
2178   return false;
2179 }
2180 
2181 //=============================================================================
2182 // Convenience common pre-built types.
2183 
2184 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2185   // Certain normalizations keep us sane when comparing types.
2186   // We do not want arrayOop variables to differ only by the wideness
2187   // of their index types.  Pick minimum wideness, since that is the
2188   // forced wideness of small ranges anyway.
2189   if (size->_widen != Type::WidenMin)
2190     return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2191   else
2192     return size;
2193 }
2194 
2195 //------------------------------make-------------------------------------------
2196 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable) {
2197   if (UseCompressedOops && elem->isa_oopptr()) {
2198     elem = elem->make_narrowoop();
2199   }
2200   size = normalize_array_size(size);
2201   return (TypeAry*)(new TypeAry(elem,size,stable))->hashcons();
2202 }
2203 
2204 //------------------------------meet-------------------------------------------
2205 // Compute the MEET of two types.  It returns a new Type object.
2206 const Type *TypeAry::xmeet( const Type *t ) const {
2207   // Perform a fast test for common case; meeting the same types together.
2208   if( this == t ) return this;  // Meeting same type-rep?
2209 
2210   // Current "this->_base" is Ary
2211   switch (t->base()) {          // switch on original type
2212 
2213   case Bottom:                  // Ye Olde Default
2214     return t;
2215 
2216   default:                      // All else is a mistake
2217     typerr(t);
2218 
2219   case Array: {                 // Meeting 2 arrays?
2220     const TypeAry *a = t->is_ary();
2221     return TypeAry::make(_elem->meet_speculative(a->_elem),
2222                          _size->xmeet(a->_size)->is_int(),
2223                          _stable && a->_stable);
2224   }
2225   case Top:
2226     break;
2227   }
2228   return this;                  // Return the double constant
2229 }
2230 
2231 //------------------------------xdual------------------------------------------
2232 // Dual: compute field-by-field dual
2233 const Type *TypeAry::xdual() const {
2234   const TypeInt* size_dual = _size->dual()->is_int();
2235   size_dual = normalize_array_size(size_dual);
2236   return new TypeAry(_elem->dual(), size_dual, !_stable);
2237 }
2238 
2239 //------------------------------eq---------------------------------------------
2240 // Structural equality check for Type representations
2241 bool TypeAry::eq( const Type *t ) const {
2242   const TypeAry *a = (const TypeAry*)t;
2243   return _elem == a->_elem &&
2244     _stable == a->_stable &&
2245     _size == a->_size;
2246 }
2247 
2248 //------------------------------hash-------------------------------------------
2249 // Type-specific hashing function.
2250 int TypeAry::hash(void) const {
2251   return (intptr_t)_elem + (intptr_t)_size + (_stable ? 43 : 0);
2252 }
2253 
2254 /**
2255  * Return same type without a speculative part in the element
2256  */
2257 const TypeAry* TypeAry::remove_speculative() const {
2258   return make(_elem->remove_speculative(), _size, _stable);
2259 }
2260 
2261 /**
2262  * Return same type with cleaned up speculative part of element
2263  */
2264 const Type* TypeAry::cleanup_speculative() const {
2265   return make(_elem->cleanup_speculative(), _size, _stable);
2266 }
2267 
2268 /**
2269  * Return same type but with a different inline depth (used for speculation)
2270  *
2271  * @param depth  depth to meet with
2272  */
2273 const TypePtr* TypePtr::with_inline_depth(int depth) const {
2274   if (!UseInlineDepthForSpeculativeTypes) {
2275     return this;
2276   }
2277   return make(AnyPtr, _ptr, _offset, _speculative, depth);
2278 }
2279 
2280 //------------------------------dump2------------------------------------------
2281 #ifndef PRODUCT
2282 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2283   if (_stable)  st->print("stable:");
2284   _elem->dump2(d, depth, st);
2285   st->print("[");
2286   _size->dump2(d, depth, st);
2287   st->print("]");
2288 }
2289 #endif
2290 
2291 //------------------------------singleton--------------------------------------
2292 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2293 // constants (Ldi nodes).  Singletons are integer, float or double constants
2294 // or a single symbol.
2295 bool TypeAry::singleton(void) const {
2296   return false;                 // Never a singleton
2297 }
2298 
2299 bool TypeAry::empty(void) const {
2300   return _elem->empty() || _size->empty();
2301 }
2302 
2303 //--------------------------ary_must_be_exact----------------------------------
2304 bool TypeAry::ary_must_be_exact() const {
2305   // This logic looks at the element type of an array, and returns true
2306   // if the element type is either a primitive or a final instance class.
2307   // In such cases, an array built on this ary must have no subclasses.
2308   if (_elem == BOTTOM)      return false;  // general array not exact
2309   if (_elem == TOP   )      return false;  // inverted general array not exact
2310   const TypeOopPtr*  toop = NULL;
2311   if (UseCompressedOops && _elem->isa_narrowoop()) {
2312     toop = _elem->make_ptr()->isa_oopptr();
2313   } else {
2314     toop = _elem->isa_oopptr();
2315   }
2316   if (!toop)                return true;   // a primitive type, like int
2317   if (!toop->is_loaded())   return false;  // unloaded class
2318   const TypeInstPtr* tinst;
2319   if (_elem->isa_narrowoop())
2320     tinst = _elem->make_ptr()->isa_instptr();
2321   else
2322     tinst = _elem->isa_instptr();
2323   if (tinst)
2324     return tinst->instance_klass()->is_final();
2325   const TypeAryPtr*  tap;
2326   if (_elem->isa_narrowoop())
2327     tap = _elem->make_ptr()->isa_aryptr();
2328   else
2329     tap = _elem->isa_aryptr();
2330   if (tap)
2331     return tap->ary()->ary_must_be_exact();
2332   return false;
2333 }
2334 
2335 //==============================TypeVect=======================================
2336 // Convenience common pre-built types.
2337 const TypeVect *TypeVect::VECTA = NULL; // vector length agnostic
2338 const TypeVect *TypeVect::VECTS = NULL; //  32-bit vectors
2339 const TypeVect *TypeVect::VECTD = NULL; //  64-bit vectors
2340 const TypeVect *TypeVect::VECTX = NULL; // 128-bit vectors
2341 const TypeVect *TypeVect::VECTY = NULL; // 256-bit vectors
2342 const TypeVect *TypeVect::VECTZ = NULL; // 512-bit vectors
2343 const TypeVect *TypeVect::VECTMASK = NULL; // predicate/mask vector
2344 
2345 //------------------------------make-------------------------------------------
2346 const TypeVect* TypeVect::make(const Type *elem, uint length, bool is_mask) {
2347   if (is_mask) {
2348     return makemask(elem, length);
2349   }
2350   BasicType elem_bt = elem->array_element_basic_type();
2351   assert(is_java_primitive(elem_bt), "only primitive types in vector");
2352   assert(Matcher::vector_size_supported(elem_bt, length), "length in range");
2353   int size = length * type2aelembytes(elem_bt);
2354   switch (Matcher::vector_ideal_reg(size)) {
2355   case Op_VecA:
2356     return (TypeVect*)(new TypeVectA(elem, length))->hashcons();
2357   case Op_VecS:
2358     return (TypeVect*)(new TypeVectS(elem, length))->hashcons();
2359   case Op_RegL:
2360   case Op_VecD:
2361   case Op_RegD:
2362     return (TypeVect*)(new TypeVectD(elem, length))->hashcons();
2363   case Op_VecX:
2364     return (TypeVect*)(new TypeVectX(elem, length))->hashcons();
2365   case Op_VecY:
2366     return (TypeVect*)(new TypeVectY(elem, length))->hashcons();
2367   case Op_VecZ:
2368     return (TypeVect*)(new TypeVectZ(elem, length))->hashcons();
2369   }
2370  ShouldNotReachHere();
2371   return NULL;
2372 }
2373 
2374 const TypeVect *TypeVect::makemask(const Type* elem, uint length) {
2375   BasicType elem_bt = elem->array_element_basic_type();
2376   if (Matcher::has_predicated_vectors() &&
2377       Matcher::match_rule_supported_vector_masked(Op_VectorLoadMask, length, elem_bt)) {
2378     return TypeVectMask::make(elem, length);
2379   } else {
2380     return make(elem, length);
2381   }
2382 }
2383 
2384 //------------------------------meet-------------------------------------------
2385 // Compute the MEET of two types.  It returns a new Type object.
2386 const Type *TypeVect::xmeet( const Type *t ) const {
2387   // Perform a fast test for common case; meeting the same types together.
2388   if( this == t ) return this;  // Meeting same type-rep?
2389 
2390   // Current "this->_base" is Vector
2391   switch (t->base()) {          // switch on original type
2392 
2393   case Bottom:                  // Ye Olde Default
2394     return t;
2395 
2396   default:                      // All else is a mistake
2397     typerr(t);
2398   case VectorMask: {
2399     const TypeVectMask* v = t->is_vectmask();
2400     assert(  base() == v->base(), "");
2401     assert(length() == v->length(), "");
2402     assert(element_basic_type() == v->element_basic_type(), "");
2403     return TypeVect::makemask(_elem->xmeet(v->_elem), _length);
2404   }
2405   case VectorA:
2406   case VectorS:
2407   case VectorD:
2408   case VectorX:
2409   case VectorY:
2410   case VectorZ: {                // Meeting 2 vectors?
2411     const TypeVect* v = t->is_vect();
2412     assert(  base() == v->base(), "");
2413     assert(length() == v->length(), "");
2414     assert(element_basic_type() == v->element_basic_type(), "");
2415     return TypeVect::make(_elem->xmeet(v->_elem), _length);
2416   }
2417   case Top:
2418     break;
2419   }
2420   return this;
2421 }
2422 
2423 //------------------------------xdual------------------------------------------
2424 // Dual: compute field-by-field dual
2425 const Type *TypeVect::xdual() const {
2426   return new TypeVect(base(), _elem->dual(), _length);
2427 }
2428 
2429 //------------------------------eq---------------------------------------------
2430 // Structural equality check for Type representations
2431 bool TypeVect::eq(const Type *t) const {
2432   const TypeVect *v = t->is_vect();
2433   return (_elem == v->_elem) && (_length == v->_length);
2434 }
2435 
2436 //------------------------------hash-------------------------------------------
2437 // Type-specific hashing function.
2438 int TypeVect::hash(void) const {
2439   return (intptr_t)_elem + (intptr_t)_length;
2440 }
2441 
2442 //------------------------------singleton--------------------------------------
2443 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2444 // constants (Ldi nodes).  Vector is singleton if all elements are the same
2445 // constant value (when vector is created with Replicate code).
2446 bool TypeVect::singleton(void) const {
2447 // There is no Con node for vectors yet.
2448 //  return _elem->singleton();
2449   return false;
2450 }
2451 
2452 bool TypeVect::empty(void) const {
2453   return _elem->empty();
2454 }
2455 
2456 //------------------------------dump2------------------------------------------
2457 #ifndef PRODUCT
2458 void TypeVect::dump2(Dict &d, uint depth, outputStream *st) const {
2459   switch (base()) {
2460   case VectorA:
2461     st->print("vectora["); break;
2462   case VectorS:
2463     st->print("vectors["); break;
2464   case VectorD:
2465     st->print("vectord["); break;
2466   case VectorX:
2467     st->print("vectorx["); break;
2468   case VectorY:
2469     st->print("vectory["); break;
2470   case VectorZ:
2471     st->print("vectorz["); break;
2472   case VectorMask:
2473     st->print("vectormask["); break;
2474   default:
2475     ShouldNotReachHere();
2476   }
2477   st->print("%d]:{", _length);
2478   _elem->dump2(d, depth, st);
2479   st->print("}");
2480 }
2481 #endif
2482 
2483 bool TypeVectMask::eq(const Type *t) const {
2484   const TypeVectMask *v = t->is_vectmask();
2485   return (element_type() == v->element_type()) && (length() == v->length());
2486 }
2487 
2488 const Type *TypeVectMask::xdual() const {
2489   return new TypeVectMask(element_type()->dual(), length());
2490 }
2491 
2492 const TypeVectMask *TypeVectMask::make(const BasicType elem_bt, uint length) {
2493   return make(get_const_basic_type(elem_bt), length);
2494 }
2495 
2496 const TypeVectMask *TypeVectMask::make(const Type* elem, uint length) {
2497   const TypeVectMask* mtype = Matcher::predicate_reg_type(elem, length);
2498   return (TypeVectMask*) const_cast<TypeVectMask*>(mtype)->hashcons();
2499 }
2500 
2501 //=============================================================================
2502 // Convenience common pre-built types.
2503 const TypePtr *TypePtr::NULL_PTR;
2504 const TypePtr *TypePtr::NOTNULL;
2505 const TypePtr *TypePtr::BOTTOM;
2506 
2507 //------------------------------meet-------------------------------------------
2508 // Meet over the PTR enum
2509 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2510   //              TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,
2511   { /* Top     */ TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,},
2512   { /* AnyNull */ AnyNull,   AnyNull,   Constant, BotPTR, NotNull, BotPTR,},
2513   { /* Constant*/ Constant,  Constant,  Constant, BotPTR, NotNull, BotPTR,},
2514   { /* Null    */ Null,      BotPTR,    BotPTR,   Null,   BotPTR,  BotPTR,},
2515   { /* NotNull */ NotNull,   NotNull,   NotNull,  BotPTR, NotNull, BotPTR,},
2516   { /* BotPTR  */ BotPTR,    BotPTR,    BotPTR,   BotPTR, BotPTR,  BotPTR,}
2517 };
2518 
2519 //------------------------------make-------------------------------------------
2520 const TypePtr *TypePtr::make(TYPES t, enum PTR ptr, int offset, const TypePtr* speculative, int inline_depth) {
2521   return (TypePtr*)(new TypePtr(t,ptr,offset, speculative, inline_depth))->hashcons();
2522 }
2523 
2524 //------------------------------cast_to_ptr_type-------------------------------
2525 const TypePtr* TypePtr::cast_to_ptr_type(PTR ptr) const {
2526   assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2527   if( ptr == _ptr ) return this;
2528   return make(_base, ptr, _offset, _speculative, _inline_depth);
2529 }
2530 
2531 //------------------------------get_con----------------------------------------
2532 intptr_t TypePtr::get_con() const {
2533   assert( _ptr == Null, "" );
2534   return _offset;
2535 }
2536 
2537 //------------------------------meet-------------------------------------------
2538 // Compute the MEET of two types.  It returns a new Type object.
2539 const Type *TypePtr::xmeet(const Type *t) const {
2540   const Type* res = xmeet_helper(t);
2541   if (res->isa_ptr() == NULL) {
2542     return res;
2543   }
2544 
2545   const TypePtr* res_ptr = res->is_ptr();
2546   if (res_ptr->speculative() != NULL) {
2547     // type->speculative() == NULL means that speculation is no better
2548     // than type, i.e. type->speculative() == type. So there are 2
2549     // ways to represent the fact that we have no useful speculative
2550     // data and we should use a single one to be able to test for
2551     // equality between types. Check whether type->speculative() ==
2552     // type and set speculative to NULL if it is the case.
2553     if (res_ptr->remove_speculative() == res_ptr->speculative()) {
2554       return res_ptr->remove_speculative();
2555     }
2556   }
2557 
2558   return res;
2559 }
2560 
2561 const Type *TypePtr::xmeet_helper(const Type *t) const {
2562   // Perform a fast test for common case; meeting the same types together.
2563   if( this == t ) return this;  // Meeting same type-rep?
2564 
2565   // Current "this->_base" is AnyPtr
2566   switch (t->base()) {          // switch on original type
2567   case Int:                     // Mixing ints & oops happens when javac
2568   case Long:                    // reuses local variables
2569   case FloatTop:
2570   case FloatCon:
2571   case FloatBot:
2572   case DoubleTop:
2573   case DoubleCon:
2574   case DoubleBot:
2575   case NarrowOop:
2576   case NarrowKlass:
2577   case Bottom:                  // Ye Olde Default
2578     return Type::BOTTOM;
2579   case Top:
2580     return this;
2581 
2582   case AnyPtr: {                // Meeting to AnyPtrs
2583     const TypePtr *tp = t->is_ptr();
2584     const TypePtr* speculative = xmeet_speculative(tp);
2585     int depth = meet_inline_depth(tp->inline_depth());
2586     return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2587   }
2588   case RawPtr:                  // For these, flip the call around to cut down
2589   case OopPtr:
2590   case InstPtr:                 // on the cases I have to handle.
2591   case AryPtr:
2592   case MetadataPtr:
2593   case KlassPtr:
2594   case InstKlassPtr:
2595   case AryKlassPtr:
2596     return t->xmeet(this);      // Call in reverse direction
2597   default:                      // All else is a mistake
2598     typerr(t);
2599 
2600   }
2601   return this;
2602 }
2603 
2604 //------------------------------meet_offset------------------------------------
2605 int TypePtr::meet_offset( int offset ) const {
2606   // Either is 'TOP' offset?  Return the other offset!
2607   if( _offset == OffsetTop ) return offset;
2608   if( offset == OffsetTop ) return _offset;
2609   // If either is different, return 'BOTTOM' offset
2610   if( _offset != offset ) return OffsetBot;
2611   return _offset;
2612 }
2613 
2614 //------------------------------dual_offset------------------------------------
2615 int TypePtr::dual_offset( ) const {
2616   if( _offset == OffsetTop ) return OffsetBot;// Map 'TOP' into 'BOTTOM'
2617   if( _offset == OffsetBot ) return OffsetTop;// Map 'BOTTOM' into 'TOP'
2618   return _offset;               // Map everything else into self
2619 }
2620 
2621 //------------------------------xdual------------------------------------------
2622 // Dual: compute field-by-field dual
2623 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2624   BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2625 };
2626 const Type *TypePtr::xdual() const {
2627   return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
2628 }
2629 
2630 //------------------------------xadd_offset------------------------------------
2631 int TypePtr::xadd_offset( intptr_t offset ) const {
2632   // Adding to 'TOP' offset?  Return 'TOP'!
2633   if( _offset == OffsetTop || offset == OffsetTop ) return OffsetTop;
2634   // Adding to 'BOTTOM' offset?  Return 'BOTTOM'!
2635   if( _offset == OffsetBot || offset == OffsetBot ) return OffsetBot;
2636   // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
2637   offset += (intptr_t)_offset;
2638   if (offset != (int)offset || offset == OffsetTop) return OffsetBot;
2639 
2640   // assert( _offset >= 0 && _offset+offset >= 0, "" );
2641   // It is possible to construct a negative offset during PhaseCCP
2642 
2643   return (int)offset;        // Sum valid offsets
2644 }
2645 
2646 //------------------------------add_offset-------------------------------------
2647 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2648   return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth);
2649 }
2650 
2651 const TypePtr *TypePtr::with_offset(intptr_t offset) const {
2652   return make(AnyPtr, _ptr, offset, _speculative, _inline_depth);
2653 }
2654 
2655 //------------------------------eq---------------------------------------------
2656 // Structural equality check for Type representations
2657 bool TypePtr::eq( const Type *t ) const {
2658   const TypePtr *a = (const TypePtr*)t;
2659   return _ptr == a->ptr() && _offset == a->offset() && eq_speculative(a) && _inline_depth == a->_inline_depth;
2660 }
2661 
2662 //------------------------------hash-------------------------------------------
2663 // Type-specific hashing function.
2664 int TypePtr::hash(void) const {
2665   return java_add(java_add((jint)_ptr, (jint)_offset), java_add((jint)hash_speculative(), (jint)_inline_depth));
2666 ;
2667 }
2668 
2669 /**
2670  * Return same type without a speculative part
2671  */
2672 const TypePtr* TypePtr::remove_speculative() const {
2673   if (_speculative == NULL) {
2674     return this;
2675   }
2676   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2677   return make(AnyPtr, _ptr, _offset, NULL, _inline_depth);
2678 }
2679 
2680 /**
2681  * Return same type but drop speculative part if we know we won't use
2682  * it
2683  */
2684 const Type* TypePtr::cleanup_speculative() const {
2685   if (speculative() == NULL) {
2686     return this;
2687   }
2688   const Type* no_spec = remove_speculative();
2689   // If this is NULL_PTR then we don't need the speculative type
2690   // (with_inline_depth in case the current type inline depth is
2691   // InlineDepthTop)
2692   if (no_spec == NULL_PTR->with_inline_depth(inline_depth())) {
2693     return no_spec;
2694   }
2695   if (above_centerline(speculative()->ptr())) {
2696     return no_spec;
2697   }
2698   const TypeOopPtr* spec_oopptr = speculative()->isa_oopptr();
2699   // If the speculative may be null and is an inexact klass then it
2700   // doesn't help
2701   if (speculative() != TypePtr::NULL_PTR && speculative()->maybe_null() &&
2702       (spec_oopptr == NULL || !spec_oopptr->klass_is_exact())) {
2703     return no_spec;
2704   }
2705   return this;
2706 }
2707 
2708 /**
2709  * dual of the speculative part of the type
2710  */
2711 const TypePtr* TypePtr::dual_speculative() const {
2712   if (_speculative == NULL) {
2713     return NULL;
2714   }
2715   return _speculative->dual()->is_ptr();
2716 }
2717 
2718 /**
2719  * meet of the speculative parts of 2 types
2720  *
2721  * @param other  type to meet with
2722  */
2723 const TypePtr* TypePtr::xmeet_speculative(const TypePtr* other) const {
2724   bool this_has_spec = (_speculative != NULL);
2725   bool other_has_spec = (other->speculative() != NULL);
2726 
2727   if (!this_has_spec && !other_has_spec) {
2728     return NULL;
2729   }
2730 
2731   // If we are at a point where control flow meets and one branch has
2732   // a speculative type and the other has not, we meet the speculative
2733   // type of one branch with the actual type of the other. If the
2734   // actual type is exact and the speculative is as well, then the
2735   // result is a speculative type which is exact and we can continue
2736   // speculation further.
2737   const TypePtr* this_spec = _speculative;
2738   const TypePtr* other_spec = other->speculative();
2739 
2740   if (!this_has_spec) {
2741     this_spec = this;
2742   }
2743 
2744   if (!other_has_spec) {
2745     other_spec = other;
2746   }
2747 
2748   return this_spec->meet(other_spec)->is_ptr();
2749 }
2750 
2751 /**
2752  * dual of the inline depth for this type (used for speculation)
2753  */
2754 int TypePtr::dual_inline_depth() const {
2755   return -inline_depth();
2756 }
2757 
2758 /**
2759  * meet of 2 inline depths (used for speculation)
2760  *
2761  * @param depth  depth to meet with
2762  */
2763 int TypePtr::meet_inline_depth(int depth) const {
2764   return MAX2(inline_depth(), depth);
2765 }
2766 
2767 /**
2768  * Are the speculative parts of 2 types equal?
2769  *
2770  * @param other  type to compare this one to
2771  */
2772 bool TypePtr::eq_speculative(const TypePtr* other) const {
2773   if (_speculative == NULL || other->speculative() == NULL) {
2774     return _speculative == other->speculative();
2775   }
2776 
2777   if (_speculative->base() != other->speculative()->base()) {
2778     return false;
2779   }
2780 
2781   return _speculative->eq(other->speculative());
2782 }
2783 
2784 /**
2785  * Hash of the speculative part of the type
2786  */
2787 int TypePtr::hash_speculative() const {
2788   if (_speculative == NULL) {
2789     return 0;
2790   }
2791 
2792   return _speculative->hash();
2793 }
2794 
2795 /**
2796  * add offset to the speculative part of the type
2797  *
2798  * @param offset  offset to add
2799  */
2800 const TypePtr* TypePtr::add_offset_speculative(intptr_t offset) const {
2801   if (_speculative == NULL) {
2802     return NULL;
2803   }
2804   return _speculative->add_offset(offset)->is_ptr();
2805 }
2806 
2807 const TypePtr* TypePtr::with_offset_speculative(intptr_t offset) const {
2808   if (_speculative == NULL) {
2809     return NULL;
2810   }
2811   return _speculative->with_offset(offset)->is_ptr();
2812 }
2813 
2814 /**
2815  * return exact klass from the speculative type if there's one
2816  */
2817 ciKlass* TypePtr::speculative_type() const {
2818   if (_speculative != NULL && _speculative->isa_oopptr()) {
2819     const TypeOopPtr* speculative = _speculative->join(this)->is_oopptr();
2820     if (speculative->klass_is_exact()) {
2821       return speculative->klass();
2822     }
2823   }
2824   return NULL;
2825 }
2826 
2827 /**
2828  * return true if speculative type may be null
2829  */
2830 bool TypePtr::speculative_maybe_null() const {
2831   if (_speculative != NULL) {
2832     const TypePtr* speculative = _speculative->join(this)->is_ptr();
2833     return speculative->maybe_null();
2834   }
2835   return true;
2836 }
2837 
2838 bool TypePtr::speculative_always_null() const {
2839   if (_speculative != NULL) {
2840     const TypePtr* speculative = _speculative->join(this)->is_ptr();
2841     return speculative == TypePtr::NULL_PTR;
2842   }
2843   return false;
2844 }
2845 
2846 /**
2847  * Same as TypePtr::speculative_type() but return the klass only if
2848  * the speculative tells us is not null
2849  */
2850 ciKlass* TypePtr::speculative_type_not_null() const {
2851   if (speculative_maybe_null()) {
2852     return NULL;
2853   }
2854   return speculative_type();
2855 }
2856 
2857 /**
2858  * Check whether new profiling would improve speculative type
2859  *
2860  * @param   exact_kls    class from profiling
2861  * @param   inline_depth inlining depth of profile point
2862  *
2863  * @return  true if type profile is valuable
2864  */
2865 bool TypePtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
2866   // no profiling?
2867   if (exact_kls == NULL) {
2868     return false;
2869   }
2870   if (speculative() == TypePtr::NULL_PTR) {
2871     return false;
2872   }
2873   // no speculative type or non exact speculative type?
2874   if (speculative_type() == NULL) {
2875     return true;
2876   }
2877   // If the node already has an exact speculative type keep it,
2878   // unless it was provided by profiling that is at a deeper
2879   // inlining level. Profiling at a higher inlining depth is
2880   // expected to be less accurate.
2881   if (_speculative->inline_depth() == InlineDepthBottom) {
2882     return false;
2883   }
2884   assert(_speculative->inline_depth() != InlineDepthTop, "can't do the comparison");
2885   return inline_depth < _speculative->inline_depth();
2886 }
2887 
2888 /**
2889  * Check whether new profiling would improve ptr (= tells us it is non
2890  * null)
2891  *
2892  * @param   ptr_kind always null or not null?
2893  *
2894  * @return  true if ptr profile is valuable
2895  */
2896 bool TypePtr::would_improve_ptr(ProfilePtrKind ptr_kind) const {
2897   // profiling doesn't tell us anything useful
2898   if (ptr_kind != ProfileAlwaysNull && ptr_kind != ProfileNeverNull) {
2899     return false;
2900   }
2901   // We already know this is not null
2902   if (!this->maybe_null()) {
2903     return false;
2904   }
2905   // We already know the speculative type cannot be null
2906   if (!speculative_maybe_null()) {
2907     return false;
2908   }
2909   // We already know this is always null
2910   if (this == TypePtr::NULL_PTR) {
2911     return false;
2912   }
2913   // We already know the speculative type is always null
2914   if (speculative_always_null()) {
2915     return false;
2916   }
2917   if (ptr_kind == ProfileAlwaysNull && speculative() != NULL && speculative()->isa_oopptr()) {
2918     return false;
2919   }
2920   return true;
2921 }
2922 
2923 //------------------------------dump2------------------------------------------
2924 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
2925   "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR"
2926 };
2927 
2928 #ifndef PRODUCT
2929 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2930   if( _ptr == Null ) st->print("NULL");
2931   else st->print("%s *", ptr_msg[_ptr]);
2932   if( _offset == OffsetTop ) st->print("+top");
2933   else if( _offset == OffsetBot ) st->print("+bot");
2934   else if( _offset ) st->print("+%d", _offset);
2935   dump_inline_depth(st);
2936   dump_speculative(st);
2937 }
2938 
2939 /**
2940  *dump the speculative part of the type
2941  */
2942 void TypePtr::dump_speculative(outputStream *st) const {
2943   if (_speculative != NULL) {
2944     st->print(" (speculative=");
2945     _speculative->dump_on(st);
2946     st->print(")");
2947   }
2948 }
2949 
2950 /**
2951  *dump the inline depth of the type
2952  */
2953 void TypePtr::dump_inline_depth(outputStream *st) const {
2954   if (_inline_depth != InlineDepthBottom) {
2955     if (_inline_depth == InlineDepthTop) {
2956       st->print(" (inline_depth=InlineDepthTop)");
2957     } else {
2958       st->print(" (inline_depth=%d)", _inline_depth);
2959     }
2960   }
2961 }
2962 #endif
2963 
2964 //------------------------------singleton--------------------------------------
2965 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2966 // constants
2967 bool TypePtr::singleton(void) const {
2968   // TopPTR, Null, AnyNull, Constant are all singletons
2969   return (_offset != OffsetBot) && !below_centerline(_ptr);
2970 }
2971 
2972 bool TypePtr::empty(void) const {
2973   return (_offset == OffsetTop) || above_centerline(_ptr);
2974 }
2975 
2976 //=============================================================================
2977 // Convenience common pre-built types.
2978 const TypeRawPtr *TypeRawPtr::BOTTOM;
2979 const TypeRawPtr *TypeRawPtr::NOTNULL;
2980 
2981 //------------------------------make-------------------------------------------
2982 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
2983   assert( ptr != Constant, "what is the constant?" );
2984   assert( ptr != Null, "Use TypePtr for NULL" );
2985   return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons();
2986 }
2987 
2988 const TypeRawPtr *TypeRawPtr::make( address bits ) {
2989   assert( bits, "Use TypePtr for NULL" );
2990   return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
2991 }
2992 
2993 //------------------------------cast_to_ptr_type-------------------------------
2994 const TypeRawPtr* TypeRawPtr::cast_to_ptr_type(PTR ptr) const {
2995   assert( ptr != Constant, "what is the constant?" );
2996   assert( ptr != Null, "Use TypePtr for NULL" );
2997   assert( _bits==0, "Why cast a constant address?");
2998   if( ptr == _ptr ) return this;
2999   return make(ptr);
3000 }
3001 
3002 //------------------------------get_con----------------------------------------
3003 intptr_t TypeRawPtr::get_con() const {
3004   assert( _ptr == Null || _ptr == Constant, "" );
3005   return (intptr_t)_bits;
3006 }
3007 
3008 //------------------------------meet-------------------------------------------
3009 // Compute the MEET of two types.  It returns a new Type object.
3010 const Type *TypeRawPtr::xmeet( const Type *t ) const {
3011   // Perform a fast test for common case; meeting the same types together.
3012   if( this == t ) return this;  // Meeting same type-rep?
3013 
3014   // Current "this->_base" is RawPtr
3015   switch( t->base() ) {         // switch on original type
3016   case Bottom:                  // Ye Olde Default
3017     return t;
3018   case Top:
3019     return this;
3020   case AnyPtr:                  // Meeting to AnyPtrs
3021     break;
3022   case RawPtr: {                // might be top, bot, any/not or constant
3023     enum PTR tptr = t->is_ptr()->ptr();
3024     enum PTR ptr = meet_ptr( tptr );
3025     if( ptr == Constant ) {     // Cannot be equal constants, so...
3026       if( tptr == Constant && _ptr != Constant)  return t;
3027       if( _ptr == Constant && tptr != Constant)  return this;
3028       ptr = NotNull;            // Fall down in lattice
3029     }
3030     return make( ptr );
3031   }
3032 
3033   case OopPtr:
3034   case InstPtr:
3035   case AryPtr:
3036   case MetadataPtr:
3037   case KlassPtr:
3038   case InstKlassPtr:
3039   case AryKlassPtr:
3040     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3041   default:                      // All else is a mistake
3042     typerr(t);
3043   }
3044 
3045   // Found an AnyPtr type vs self-RawPtr type
3046   const TypePtr *tp = t->is_ptr();
3047   switch (tp->ptr()) {
3048   case TypePtr::TopPTR:  return this;
3049   case TypePtr::BotPTR:  return t;
3050   case TypePtr::Null:
3051     if( _ptr == TypePtr::TopPTR ) return t;
3052     return TypeRawPtr::BOTTOM;
3053   case TypePtr::NotNull: return TypePtr::make(AnyPtr, meet_ptr(TypePtr::NotNull), tp->meet_offset(0), tp->speculative(), tp->inline_depth());
3054   case TypePtr::AnyNull:
3055     if( _ptr == TypePtr::Constant) return this;
3056     return make( meet_ptr(TypePtr::AnyNull) );
3057   default: ShouldNotReachHere();
3058   }
3059   return this;
3060 }
3061 
3062 //------------------------------xdual------------------------------------------
3063 // Dual: compute field-by-field dual
3064 const Type *TypeRawPtr::xdual() const {
3065   return new TypeRawPtr( dual_ptr(), _bits );
3066 }
3067 
3068 //------------------------------add_offset-------------------------------------
3069 const TypePtr* TypeRawPtr::add_offset(intptr_t offset) const {
3070   if( offset == OffsetTop ) return BOTTOM; // Undefined offset-> undefined pointer
3071   if( offset == OffsetBot ) return BOTTOM; // Unknown offset-> unknown pointer
3072   if( offset == 0 ) return this; // No change
3073   switch (_ptr) {
3074   case TypePtr::TopPTR:
3075   case TypePtr::BotPTR:
3076   case TypePtr::NotNull:
3077     return this;
3078   case TypePtr::Null:
3079   case TypePtr::Constant: {
3080     address bits = _bits+offset;
3081     if ( bits == 0 ) return TypePtr::NULL_PTR;
3082     return make( bits );
3083   }
3084   default:  ShouldNotReachHere();
3085   }
3086   return NULL;                  // Lint noise
3087 }
3088 
3089 //------------------------------eq---------------------------------------------
3090 // Structural equality check for Type representations
3091 bool TypeRawPtr::eq( const Type *t ) const {
3092   const TypeRawPtr *a = (const TypeRawPtr*)t;
3093   return _bits == a->_bits && TypePtr::eq(t);
3094 }
3095 
3096 //------------------------------hash-------------------------------------------
3097 // Type-specific hashing function.
3098 int TypeRawPtr::hash(void) const {
3099   return (intptr_t)_bits + TypePtr::hash();
3100 }
3101 
3102 //------------------------------dump2------------------------------------------
3103 #ifndef PRODUCT
3104 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3105   if( _ptr == Constant )
3106     st->print(INTPTR_FORMAT, p2i(_bits));
3107   else
3108     st->print("rawptr:%s", ptr_msg[_ptr]);
3109 }
3110 #endif
3111 
3112 //=============================================================================
3113 // Convenience common pre-built type.
3114 const TypeOopPtr *TypeOopPtr::BOTTOM;
3115 
3116 TypePtr::InterfaceSet::InterfaceSet()
3117         : _list(Compile::current()->type_arena(), 0, 0, NULL),
3118           _hash_computed(0), _exact_klass_computed(0), _is_loaded_computed(0) {
3119 }
3120 
3121 TypePtr::InterfaceSet::InterfaceSet(GrowableArray<ciInstanceKlass*>* interfaces)
3122         : _list(Compile::current()->type_arena(), interfaces->length(), 0, NULL),
3123           _hash_computed(0), _exact_klass_computed(0), _is_loaded_computed(0) {
3124   for (int i = 0; i < interfaces->length(); i++) {
3125     add(interfaces->at(i));
3126   }
3127 }
3128 
3129 
3130 int TypePtr::InterfaceSet::compare(ciKlass* const& k1, ciKlass* const& k2) {
3131   if ((intptr_t)k1 < (intptr_t)k2) {
3132     return -1;
3133   } else if ((intptr_t)k1 > (intptr_t)k2) {
3134     return 1;
3135   }
3136   return 0;
3137 }
3138 
3139 void TypePtr::InterfaceSet::add(ciKlass* interface) {
3140   assert(interface->is_interface(), "for interfaces only");
3141   _list.insert_sorted<compare>(interface);
3142   verify();
3143 }
3144 
3145 void TypePtr::InterfaceSet::raw_add(ciKlass* interface) {
3146   assert(interface->is_interface(), "for interfaces only");
3147   _list.push(interface);
3148 }
3149 
3150 bool TypePtr::InterfaceSet::eq(const InterfaceSet& other) const {
3151   if (_list.length() != other._list.length()) {
3152     return false;
3153   }
3154   for (int i = 0; i < _list.length(); i++) {
3155     ciKlass* k1 = _list.at(i);
3156     ciKlass* k2 = other._list.at(i);
3157     if (!k1->equals(k2)) {
3158       return false;
3159     }
3160   }
3161   return true;
3162 }
3163 
3164 int TypePtr::InterfaceSet::hash() const {
3165   if (_hash_computed) {
3166     return _hash;
3167   }
3168   const_cast<InterfaceSet*>(this)->compute_hash();
3169   assert(_hash_computed, "should be computed now");
3170   return _hash;
3171 }
3172 
3173 void TypePtr::InterfaceSet::compute_hash() {
3174   int hash = 0;
3175   for (int i = 0; i < _list.length(); i++) {
3176     ciKlass* k = _list.at(i);
3177     hash += (jint)k->hash();
3178   }
3179   _hash_computed = 1;
3180   _hash = hash;
3181 }
3182 
3183 static int compare_interfaces(ciKlass** k1, ciKlass** k2) {
3184   return (int)((*k1)->ident() - (*k2)->ident());
3185 }
3186 
3187 void TypePtr::InterfaceSet::dump(outputStream *st) const {
3188   if (_list.length() == 0) {
3189     return;
3190   }
3191   ResourceMark rm;
3192   st->print(" (");
3193   GrowableArray<ciKlass*> interfaces;
3194   interfaces.appendAll(&_list);
3195   // Sort the interfaces so they are listed in the same order from one run to the other of the same compilation
3196   interfaces.sort(compare_interfaces);
3197   for (int i = 0; i < interfaces.length(); i++) {
3198     if (i > 0) {
3199       st->print(",");
3200     }
3201     ciKlass* k = interfaces.at(i);
3202     k->print_name_on(st);
3203   }
3204   st->print(")");
3205 }
3206 
3207 void TypePtr::InterfaceSet::verify() const {
3208 #ifdef DEBUG
3209   for (int i = 1; i < _list.length(); i++) {
3210     ciKlass* k1 = _list.at(i-1);
3211     ciKlass* k2 = _list.at(i);
3212     assert(compare(k2, k1) > 0, "should be ordered");
3213     assert(k1 != k2, "no duplicate");
3214   }
3215 #endif
3216 }
3217 
3218 TypePtr::InterfaceSet TypeOopPtr::InterfaceSet::union_with(const InterfaceSet& other) const {
3219   InterfaceSet result;
3220   int i = 0;
3221   int j = 0;
3222   while (i < _list.length() || j < other._list.length()) {
3223     while (i < _list.length() &&
3224            (j >= other._list.length() ||
3225             compare(_list.at(i), other._list.at(j)) < 0)) {
3226       result.raw_add(_list.at(i));
3227       i++;
3228     }
3229     while (j < other._list.length() &&
3230            (i >= _list.length() ||
3231             compare(other._list.at(j), _list.at(i)) < 0)) {
3232       result.raw_add(other._list.at(j));
3233       j++;
3234     }
3235     if (i < _list.length() &&
3236         j < other._list.length() &&
3237         _list.at(i) == other._list.at(j)) {
3238       result.raw_add(_list.at(i));
3239       i++;
3240       j++;
3241     }
3242   }
3243   result.verify();
3244 #ifdef DEBUG
3245   for (int i = 0; i < _list.length(); i++) {
3246     assert(result.contains(_list.at(i)), "missing");
3247   }
3248   for (int i = 0; i < other._list.length(); i++) {
3249     assert(result.contains(other._list.at(i)), "missing");
3250   }
3251   for (int i = 0; i < result._list.length(); i++) {
3252     assert(_list.contains(result._list.at(i)) || other._list.contains(result._list.at(i)), "missing");
3253   }
3254 #endif
3255   return result;
3256 }
3257 
3258 TypePtr::InterfaceSet TypeOopPtr::InterfaceSet::intersection_with(const InterfaceSet& other) const {
3259   InterfaceSet result;
3260   int i = 0;
3261   int j = 0;
3262   while (i < _list.length() || j < other._list.length()) {
3263     while (i < _list.length() &&
3264            (j >= other._list.length() ||
3265             compare(_list.at(i), other._list.at(j)) < 0)) {
3266       i++;
3267     }
3268     while (j < other._list.length() &&
3269            (i >= _list.length() ||
3270             compare(other._list.at(j), _list.at(i)) < 0)) {
3271       j++;
3272     }
3273     if (i < _list.length() &&
3274         j < other._list.length() &&
3275         _list.at(i) == other._list.at(j)) {
3276       result.raw_add(_list.at(i));
3277       i++;
3278       j++;
3279     }
3280   }
3281   result.verify();
3282 #ifdef DEBUG
3283   for (int i = 0; i < _list.length(); i++) {
3284     assert(!other._list.contains(_list.at(i)) || result.contains(_list.at(i)), "missing");
3285   }
3286   for (int i = 0; i < other._list.length(); i++) {
3287     assert(!_list.contains(other._list.at(i)) || result.contains(other._list.at(i)), "missing");
3288   }
3289   for (int i = 0; i < result._list.length(); i++) {
3290     assert(_list.contains(result._list.at(i)) && other._list.contains(result._list.at(i)), "missing");
3291   }
3292 #endif
3293   return result;
3294 }
3295 
3296 // Is there a single ciKlass* that can represent the interface set?
3297 ciKlass* TypePtr::InterfaceSet::exact_klass() const {
3298   if (_exact_klass_computed) {
3299     return _exact_klass;
3300   }
3301   const_cast<InterfaceSet*>(this)->compute_exact_klass();
3302   assert(_exact_klass_computed, "should be computed now");
3303   return _exact_klass;
3304 }
3305 
3306 void TypePtr::InterfaceSet::compute_exact_klass() {
3307   if (_list.length() == 0) {
3308     _exact_klass_computed = 1;
3309     _exact_klass = NULL;
3310     return;
3311   }
3312   ciKlass* res = NULL;
3313   for (int i = 0; i < _list.length(); i++) {
3314     ciKlass* interface = _list.at(i);
3315     if (eq(interfaces(interface, false, true, false, trust_interfaces))) {
3316       assert(res == NULL, "");
3317       res = _list.at(i);
3318     }
3319   }
3320   _exact_klass_computed = 1;
3321   _exact_klass = res;
3322 }
3323 
3324 bool TypePtr::InterfaceSet::is_loaded() const {
3325   if (_is_loaded_computed) {
3326     return _is_loaded;
3327   }
3328   const_cast<InterfaceSet*>(this)->compute_is_loaded();
3329   assert(_is_loaded_computed, "should be computed now");
3330   return _is_loaded;
3331 }
3332 
3333 void TypePtr::InterfaceSet::compute_is_loaded() {
3334   _is_loaded_computed = 1;
3335   for (int i = 0; i < _list.length(); i++) {
3336     ciKlass* interface = _list.at(i);
3337     if (!interface->is_loaded()) {
3338       _is_loaded = false;
3339       return;
3340     }
3341   }
3342   _is_loaded = true;
3343 }
3344 
3345 //------------------------------TypeOopPtr-------------------------------------
3346 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const InterfaceSet& interfaces, bool xk, ciObject* o, int offset,
3347                        int instance_id, const TypePtr* speculative, int inline_depth)
3348   : TypePtr(t, ptr, offset, speculative, inline_depth),
3349     _const_oop(o), _klass(k),
3350     _interfaces(interfaces),
3351     _klass_is_exact(xk),
3352     _is_ptr_to_narrowoop(false),
3353     _is_ptr_to_narrowklass(false),
3354     _is_ptr_to_boxed_value(false),
3355     _instance_id(instance_id) {
3356   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3357       (offset > 0) && xk && (k != 0) && k->is_instance_klass()) {
3358     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset);
3359   }
3360 #ifdef _LP64
3361   if (_offset > 0 || _offset == Type::OffsetTop || _offset == Type::OffsetBot) {
3362     if (_offset == oopDesc::klass_offset_in_bytes()) {
3363       _is_ptr_to_narrowklass = UseCompressedClassPointers;
3364     } else if (klass() == NULL) {
3365       // Array with unknown body type
3366       assert(this->isa_aryptr(), "only arrays without klass");
3367       _is_ptr_to_narrowoop = UseCompressedOops;
3368     } else if (this->isa_aryptr()) {
3369       _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() &&
3370                              _offset != arrayOopDesc::length_offset_in_bytes());
3371     } else if (klass()->is_instance_klass()) {
3372       ciInstanceKlass* ik = klass()->as_instance_klass();
3373       if (this->isa_klassptr()) {
3374         // Perm objects don't use compressed references
3375       } else if (_offset == OffsetBot || _offset == OffsetTop) {
3376         // unsafe access
3377         _is_ptr_to_narrowoop = UseCompressedOops;
3378       } else {
3379         assert(this->isa_instptr(), "must be an instance ptr.");
3380 
3381         if (klass() == ciEnv::current()->Class_klass() &&
3382             (_offset == java_lang_Class::klass_offset() ||
3383              _offset == java_lang_Class::array_klass_offset())) {
3384           // Special hidden fields from the Class.
3385           assert(this->isa_instptr(), "must be an instance ptr.");
3386           _is_ptr_to_narrowoop = false;
3387         } else if (klass() == ciEnv::current()->Class_klass() &&
3388                    _offset >= InstanceMirrorKlass::offset_of_static_fields()) {
3389           // Static fields
3390           ciField* field = NULL;
3391           if (const_oop() != NULL) {
3392             ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3393             field = k->get_field_by_offset(_offset, true);
3394           }
3395           if (field != NULL) {
3396             BasicType basic_elem_type = field->layout_type();
3397             _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3398           } else {
3399             // unsafe access
3400             _is_ptr_to_narrowoop = UseCompressedOops;
3401           }
3402         } else {
3403           // Instance fields which contains a compressed oop references.
3404           ciField* field = ik->get_field_by_offset(_offset, false);
3405           if (field != NULL) {
3406             BasicType basic_elem_type = field->layout_type();
3407             _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3408           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3409             // Compile::find_alias_type() cast exactness on all types to verify
3410             // that it does not affect alias type.
3411             _is_ptr_to_narrowoop = UseCompressedOops;
3412           } else {
3413             // Type for the copy start in LibraryCallKit::inline_native_clone().
3414             _is_ptr_to_narrowoop = UseCompressedOops;
3415           }
3416         }
3417       }
3418     }
3419   }
3420 #endif
3421 }
3422 
3423 //------------------------------make-------------------------------------------
3424 const TypeOopPtr *TypeOopPtr::make(PTR ptr, int offset, int instance_id,
3425                                      const TypePtr* speculative, int inline_depth) {
3426   assert(ptr != Constant, "no constant generic pointers");
3427   ciKlass*  k = Compile::current()->env()->Object_klass();
3428   bool      xk = false;
3429   ciObject* o = NULL;
3430   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, InterfaceSet(), xk, o, offset, instance_id, speculative, inline_depth))->hashcons();
3431 }
3432 
3433 
3434 //------------------------------cast_to_ptr_type-------------------------------
3435 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3436   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3437   if( ptr == _ptr ) return this;
3438   return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3439 }
3440 
3441 //-----------------------------cast_to_instance_id----------------------------
3442 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3443   // There are no instances of a general oop.
3444   // Return self unchanged.
3445   return this;
3446 }
3447 
3448 //-----------------------------cast_to_exactness-------------------------------
3449 const TypeOopPtr* TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3450   // There is no such thing as an exact general oop.
3451   // Return self unchanged.
3452   return this;
3453 }
3454 
3455 
3456 //------------------------------as_klass_type----------------------------------
3457 // Return the klass type corresponding to this instance or array type.
3458 // It is the type that is loaded from an object of this type.
3459 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3460   ShouldNotReachHere();
3461   return NULL;
3462 }
3463 
3464 //------------------------------meet-------------------------------------------
3465 // Compute the MEET of two types.  It returns a new Type object.
3466 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3467   // Perform a fast test for common case; meeting the same types together.
3468   if( this == t ) return this;  // Meeting same type-rep?
3469 
3470   // Current "this->_base" is OopPtr
3471   switch (t->base()) {          // switch on original type
3472 
3473   case Int:                     // Mixing ints & oops happens when javac
3474   case Long:                    // reuses local variables
3475   case FloatTop:
3476   case FloatCon:
3477   case FloatBot:
3478   case DoubleTop:
3479   case DoubleCon:
3480   case DoubleBot:
3481   case NarrowOop:
3482   case NarrowKlass:
3483   case Bottom:                  // Ye Olde Default
3484     return Type::BOTTOM;
3485   case Top:
3486     return this;
3487 
3488   default:                      // All else is a mistake
3489     typerr(t);
3490 
3491   case RawPtr:
3492   case MetadataPtr:
3493   case KlassPtr:
3494   case InstKlassPtr:
3495   case AryKlassPtr:
3496     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3497 
3498   case AnyPtr: {
3499     // Found an AnyPtr type vs self-OopPtr type
3500     const TypePtr *tp = t->is_ptr();
3501     int offset = meet_offset(tp->offset());
3502     PTR ptr = meet_ptr(tp->ptr());
3503     const TypePtr* speculative = xmeet_speculative(tp);
3504     int depth = meet_inline_depth(tp->inline_depth());
3505     switch (tp->ptr()) {
3506     case Null:
3507       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3508       // else fall through:
3509     case TopPTR:
3510     case AnyNull: {
3511       int instance_id = meet_instance_id(InstanceTop);
3512       return make(ptr, offset, instance_id, speculative, depth);
3513     }
3514     case BotPTR:
3515     case NotNull:
3516       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3517     default: typerr(t);
3518     }
3519   }
3520 
3521   case OopPtr: {                 // Meeting to other OopPtrs
3522     const TypeOopPtr *tp = t->is_oopptr();
3523     int instance_id = meet_instance_id(tp->instance_id());
3524     const TypePtr* speculative = xmeet_speculative(tp);
3525     int depth = meet_inline_depth(tp->inline_depth());
3526     return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3527   }
3528 
3529   case InstPtr:                  // For these, flip the call around to cut down
3530   case AryPtr:
3531     return t->xmeet(this);      // Call in reverse direction
3532 
3533   } // End of switch
3534   return this;                  // Return the double constant
3535 }
3536 
3537 
3538 //------------------------------xdual------------------------------------------
3539 // Dual of a pure heap pointer.  No relevant klass or oop information.
3540 const Type *TypeOopPtr::xdual() const {
3541   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3542   assert(const_oop() == NULL,             "no constants here");
3543   return new TypeOopPtr(_base, dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
3544 }
3545 
3546 //--------------------------make_from_klass_common-----------------------------
3547 // Computes the element-type given a klass.
3548 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling) {
3549   if (klass->is_instance_klass()) {
3550     Compile* C = Compile::current();
3551     Dependencies* deps = C->dependencies();
3552     assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
3553     // Element is an instance
3554     bool klass_is_exact = false;
3555     if (klass->is_loaded()) {
3556       // Try to set klass_is_exact.
3557       ciInstanceKlass* ik = klass->as_instance_klass();
3558       klass_is_exact = ik->is_final();
3559       if (!klass_is_exact && klass_change
3560           && deps != NULL && UseUniqueSubclasses) {
3561         ciInstanceKlass* sub = ik->unique_concrete_subklass();
3562         if (sub != NULL) {
3563           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3564           klass = ik = sub;
3565           klass_is_exact = sub->is_final();
3566         }
3567       }
3568       if (!klass_is_exact && try_for_exact && deps != NULL &&
3569           !ik->is_interface() && !ik->has_subklass()) {
3570         // Add a dependence; if concrete subclass added we need to recompile
3571         deps->assert_leaf_type(ik);
3572         klass_is_exact = true;
3573       }
3574     }
3575     const TypePtr::InterfaceSet interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
3576     return TypeInstPtr::make(TypePtr::BotPTR, klass, interfaces, klass_is_exact, NULL, 0);
3577   } else if (klass->is_obj_array_klass()) {
3578     // Element is an object array. Recursively call ourself.
3579     ciKlass* eklass = klass->as_obj_array_klass()->element_klass();
3580     const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(eklass, false, try_for_exact, interface_handling);
3581     bool xk = etype->klass_is_exact();
3582     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3583     // We used to pass NotNull in here, asserting that the sub-arrays
3584     // are all not-null.  This is not true in generally, as code can
3585     // slam NULLs down in the subarrays.
3586     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, NULL, xk, 0);
3587     return arr;
3588   } else if (klass->is_type_array_klass()) {
3589     // Element is an typeArray
3590     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3591     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3592     // We used to pass NotNull in here, asserting that the array pointer
3593     // is not-null. That was not true in general.
3594     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, 0);
3595     return arr;
3596   } else {
3597     ShouldNotReachHere();
3598     return NULL;
3599   }
3600 }
3601 
3602 //------------------------------make_from_constant-----------------------------
3603 // Make a java pointer from an oop constant
3604 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3605   assert(!o->is_null_object(), "null object not yet handled here.");
3606 
3607   const bool make_constant = require_constant || o->should_be_constant();
3608 
3609   ciKlass* klass = o->klass();
3610   if (klass->is_instance_klass()) {
3611     // Element is an instance
3612     if (make_constant) {
3613       return TypeInstPtr::make(o);
3614     } else {
3615       return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, 0);
3616     }
3617   } else if (klass->is_obj_array_klass()) {
3618     // Element is an object array. Recursively call ourself.
3619     const TypeOopPtr *etype =
3620       TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass(), trust_interfaces);
3621     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3622     // We used to pass NotNull in here, asserting that the sub-arrays
3623     // are all not-null.  This is not true in generally, as code can
3624     // slam NULLs down in the subarrays.
3625     if (make_constant) {
3626       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3627     } else {
3628       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
3629     }
3630   } else if (klass->is_type_array_klass()) {
3631     // Element is an typeArray
3632     const Type* etype =
3633       (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3634     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3635     // We used to pass NotNull in here, asserting that the array pointer
3636     // is not-null. That was not true in general.
3637     if (make_constant) {
3638       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3639     } else {
3640       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
3641     }
3642   }
3643 
3644   fatal("unhandled object type");
3645   return NULL;
3646 }
3647 
3648 //------------------------------get_con----------------------------------------
3649 intptr_t TypeOopPtr::get_con() const {
3650   assert( _ptr == Null || _ptr == Constant, "" );
3651   assert( _offset >= 0, "" );
3652 
3653   if (_offset != 0) {
3654     // After being ported to the compiler interface, the compiler no longer
3655     // directly manipulates the addresses of oops.  Rather, it only has a pointer
3656     // to a handle at compile time.  This handle is embedded in the generated
3657     // code and dereferenced at the time the nmethod is made.  Until that time,
3658     // it is not reasonable to do arithmetic with the addresses of oops (we don't
3659     // have access to the addresses!).  This does not seem to currently happen,
3660     // but this assertion here is to help prevent its occurrence.
3661     tty->print_cr("Found oop constant with non-zero offset");
3662     ShouldNotReachHere();
3663   }
3664 
3665   return (intptr_t)const_oop()->constant_encoding();
3666 }
3667 
3668 
3669 //-----------------------------filter------------------------------------------
3670 // Do not allow interface-vs.-noninterface joins to collapse to top.
3671 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
3672 
3673   const Type* ft = join_helper(kills, include_speculative);
3674   const TypeInstPtr* ftip = ft->isa_instptr();
3675   const TypeInstPtr* ktip = kills->isa_instptr();
3676 
3677   if (ft->empty()) {
3678     return Type::TOP;           // Canonical empty value
3679   }
3680 
3681   return ft;
3682 }
3683 
3684 //------------------------------eq---------------------------------------------
3685 // Structural equality check for Type representations
3686 bool TypeOopPtr::eq( const Type *t ) const {
3687   const TypeOopPtr *a = (const TypeOopPtr*)t;
3688   if (_klass_is_exact != a->_klass_is_exact ||
3689       _instance_id != a->_instance_id)  return false;
3690   ciObject* one = const_oop();
3691   ciObject* two = a->const_oop();
3692   if (one == NULL || two == NULL) {
3693     return (one == two) && TypePtr::eq(t);
3694   } else {
3695     return one->equals(two) && TypePtr::eq(t);
3696   }
3697 }
3698 
3699 //------------------------------hash-------------------------------------------
3700 // Type-specific hashing function.
3701 int TypeOopPtr::hash(void) const {
3702   return
3703     java_add(java_add((jint)(const_oop() ? const_oop()->hash() : 0), (jint)_klass_is_exact),
3704              java_add((jint)_instance_id, (jint)TypePtr::hash()));
3705 }
3706 
3707 //------------------------------dump2------------------------------------------
3708 #ifndef PRODUCT
3709 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3710   st->print("oopptr:%s", ptr_msg[_ptr]);
3711   if( _klass_is_exact ) st->print(":exact");
3712   if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
3713   switch( _offset ) {
3714   case OffsetTop: st->print("+top"); break;
3715   case OffsetBot: st->print("+any"); break;
3716   case         0: break;
3717   default:        st->print("+%d",_offset); break;
3718   }
3719   if (_instance_id == InstanceTop)
3720     st->print(",iid=top");
3721   else if (_instance_id != InstanceBot)
3722     st->print(",iid=%d",_instance_id);
3723 
3724   dump_inline_depth(st);
3725   dump_speculative(st);
3726 }
3727 #endif
3728 
3729 //------------------------------singleton--------------------------------------
3730 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3731 // constants
3732 bool TypeOopPtr::singleton(void) const {
3733   // detune optimizer to not generate constant oop + constant offset as a constant!
3734   // TopPTR, Null, AnyNull, Constant are all singletons
3735   return (_offset == 0) && !below_centerline(_ptr);
3736 }
3737 
3738 //------------------------------add_offset-------------------------------------
3739 const TypePtr* TypeOopPtr::add_offset(intptr_t offset) const {
3740   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
3741 }
3742 
3743 const TypeOopPtr* TypeOopPtr::with_offset(intptr_t offset) const {
3744   return make(_ptr, offset, _instance_id, with_offset_speculative(offset), _inline_depth);
3745 }
3746 
3747 /**
3748  * Return same type without a speculative part
3749  */
3750 const TypeOopPtr* TypeOopPtr::remove_speculative() const {
3751   if (_speculative == NULL) {
3752     return this;
3753   }
3754   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
3755   return make(_ptr, _offset, _instance_id, NULL, _inline_depth);
3756 }
3757 
3758 /**
3759  * Return same type but drop speculative part if we know we won't use
3760  * it
3761  */
3762 const Type* TypeOopPtr::cleanup_speculative() const {
3763   // If the klass is exact and the ptr is not null then there's
3764   // nothing that the speculative type can help us with
3765   if (klass_is_exact() && !maybe_null()) {
3766     return remove_speculative();
3767   }
3768   return TypePtr::cleanup_speculative();
3769 }
3770 
3771 /**
3772  * Return same type but with a different inline depth (used for speculation)
3773  *
3774  * @param depth  depth to meet with
3775  */
3776 const TypePtr* TypeOopPtr::with_inline_depth(int depth) const {
3777   if (!UseInlineDepthForSpeculativeTypes) {
3778     return this;
3779   }
3780   return make(_ptr, _offset, _instance_id, _speculative, depth);
3781 }
3782 
3783 //------------------------------with_instance_id--------------------------------
3784 const TypePtr* TypeOopPtr::with_instance_id(int instance_id) const {
3785   assert(_instance_id != -1, "should be known");
3786   return make(_ptr, _offset, instance_id, _speculative, _inline_depth);
3787 }
3788 
3789 //------------------------------meet_instance_id--------------------------------
3790 int TypeOopPtr::meet_instance_id( int instance_id ) const {
3791   // Either is 'TOP' instance?  Return the other instance!
3792   if( _instance_id == InstanceTop ) return  instance_id;
3793   if(  instance_id == InstanceTop ) return _instance_id;
3794   // If either is different, return 'BOTTOM' instance
3795   if( _instance_id != instance_id ) return InstanceBot;
3796   return _instance_id;
3797 }
3798 
3799 //------------------------------dual_instance_id--------------------------------
3800 int TypeOopPtr::dual_instance_id( ) const {
3801   if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM
3802   if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP
3803   return _instance_id;              // Map everything else into self
3804 }
3805 
3806 
3807 TypePtr::InterfaceSet TypeOopPtr::meet_interfaces(const TypeOopPtr* other) const {
3808   if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
3809     return _interfaces.union_with(other->_interfaces);
3810   } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
3811     return other->_interfaces;
3812   } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
3813     return _interfaces;
3814   }
3815   return _interfaces.intersection_with(other->_interfaces);
3816 }
3817 
3818 /**
3819  * Check whether new profiling would improve speculative type
3820  *
3821  * @param   exact_kls    class from profiling
3822  * @param   inline_depth inlining depth of profile point
3823  *
3824  * @return  true if type profile is valuable
3825  */
3826 bool TypeOopPtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
3827   // no way to improve an already exact type
3828   if (klass_is_exact()) {
3829     return false;
3830   }
3831   return TypePtr::would_improve_type(exact_kls, inline_depth);
3832 }
3833 
3834 //=============================================================================
3835 // Convenience common pre-built types.
3836 const TypeInstPtr *TypeInstPtr::NOTNULL;
3837 const TypeInstPtr *TypeInstPtr::BOTTOM;
3838 const TypeInstPtr *TypeInstPtr::MIRROR;
3839 const TypeInstPtr *TypeInstPtr::MARK;
3840 const TypeInstPtr *TypeInstPtr::KLASS;
3841 
3842 // Is there a single ciKlass* that can represent that type?
3843 ciKlass* TypeInstPtr::exact_klass_helper() const {
3844   if (_interfaces.empty()) {
3845     return _klass;
3846   }
3847   if (_klass != ciEnv::current()->Object_klass()) {
3848     ciKlass* k = _klass;
3849     const TypePtr::InterfaceSet interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
3850     if (_interfaces.eq(interfaces)) {
3851       return _klass;
3852     }
3853     return NULL;
3854   }
3855   return _interfaces.exact_klass();
3856 }
3857 
3858 //------------------------------TypeInstPtr-------------------------------------
3859 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, const InterfaceSet& interfaces, bool xk, ciObject* o, int off,
3860                          int instance_id, const TypePtr* speculative, int inline_depth)
3861   : TypeOopPtr(InstPtr, ptr, k, interfaces, xk, o, off, instance_id, speculative, inline_depth) {
3862   assert(k == NULL || !k->is_loaded() || !k->is_interface(), "no interface here");
3863   assert(k != NULL &&
3864          (k->is_loaded() || o == NULL),
3865          "cannot have constants with non-loaded klass");
3866 };
3867 
3868 //------------------------------make-------------------------------------------
3869 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
3870                                      ciKlass* k,
3871                                      const InterfaceSet& interfaces,
3872                                      bool xk,
3873                                      ciObject* o,
3874                                      int offset,
3875                                      int instance_id,
3876                                      const TypePtr* speculative,
3877                                      int inline_depth) {
3878   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
3879   // Either const_oop() is NULL or else ptr is Constant
3880   assert( (!o && ptr != Constant) || (o && ptr == Constant),
3881           "constant pointers must have a value supplied" );
3882   // Ptr is never Null
3883   assert( ptr != Null, "NULL pointers are not typed" );
3884 
3885   assert(instance_id <= 0 || xk, "instances are always exactly typed");
3886   if (ptr == Constant) {
3887     // Note:  This case includes meta-object constants, such as methods.
3888     xk = true;
3889   } else if (k->is_loaded()) {
3890     ciInstanceKlass* ik = k->as_instance_klass();
3891     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
3892     assert(!ik->is_interface(), "no interface here");
3893     if (xk && ik->is_interface())  xk = false;  // no exact interface
3894   }
3895 
3896   // Now hash this baby
3897   TypeInstPtr *result =
3898     (TypeInstPtr*)(new TypeInstPtr(ptr, k, interfaces, xk, o ,offset, instance_id, speculative, inline_depth))->hashcons();
3899 
3900   return result;
3901 }
3902 
3903 TypePtr::InterfaceSet TypePtr::interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling) {
3904   if (k->is_instance_klass()) {
3905     if (k->is_loaded()) {
3906       if (k->is_interface() && interface_handling == ignore_interfaces) {
3907         assert(interface, "no interface expected");
3908         k = ciEnv::current()->Object_klass();
3909         InterfaceSet interfaces;
3910         return interfaces;
3911       }
3912       GrowableArray<ciInstanceKlass *> *k_interfaces = k->as_instance_klass()->transitive_interfaces();
3913       InterfaceSet interfaces(k_interfaces);
3914       if (k->is_interface()) {
3915         assert(interface, "no interface expected");
3916         k = ciEnv::current()->Object_klass();
3917       } else {
3918         assert(klass, "no instance klass expected");
3919       }
3920       return interfaces;
3921     }
3922     InterfaceSet interfaces;
3923     return interfaces;
3924   }
3925   assert(array, "no array expected");
3926   assert(k->is_array_klass(), "Not an array?");
3927   ciType* e = k->as_array_klass()->base_element_type();
3928   if (e->is_loaded() && e->is_instance_klass() && e->as_instance_klass()->is_interface()) {
3929     if (interface_handling == ignore_interfaces) {
3930       k = ciObjArrayKlass::make(ciEnv::current()->Object_klass(), k->as_array_klass()->dimension());
3931     }
3932   }
3933   return *TypeAryPtr::_array_interfaces;
3934 }
3935 
3936 /**
3937  *  Create constant type for a constant boxed value
3938  */
3939 const Type* TypeInstPtr::get_const_boxed_value() const {
3940   assert(is_ptr_to_boxed_value(), "should be called only for boxed value");
3941   assert((const_oop() != NULL), "should be called only for constant object");
3942   ciConstant constant = const_oop()->as_instance()->field_value_by_offset(offset());
3943   BasicType bt = constant.basic_type();
3944   switch (bt) {
3945     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
3946     case T_INT:      return TypeInt::make(constant.as_int());
3947     case T_CHAR:     return TypeInt::make(constant.as_char());
3948     case T_BYTE:     return TypeInt::make(constant.as_byte());
3949     case T_SHORT:    return TypeInt::make(constant.as_short());
3950     case T_FLOAT:    return TypeF::make(constant.as_float());
3951     case T_DOUBLE:   return TypeD::make(constant.as_double());
3952     case T_LONG:     return TypeLong::make(constant.as_long());
3953     default:         break;
3954   }
3955   fatal("Invalid boxed value type '%s'", type2name(bt));
3956   return NULL;
3957 }
3958 
3959 //------------------------------cast_to_ptr_type-------------------------------
3960 const TypeInstPtr* TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
3961   if( ptr == _ptr ) return this;
3962   // Reconstruct _sig info here since not a problem with later lazy
3963   // construction, _sig will show up on demand.
3964   return make(ptr, klass(), _interfaces, klass_is_exact(), ptr == Constant ? const_oop() : NULL, _offset, _instance_id, _speculative, _inline_depth);
3965 }
3966 
3967 
3968 //-----------------------------cast_to_exactness-------------------------------
3969 const TypeInstPtr* TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
3970   if( klass_is_exact == _klass_is_exact ) return this;
3971   if (!_klass->is_loaded())  return this;
3972   ciInstanceKlass* ik = _klass->as_instance_klass();
3973   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
3974   assert(!ik->is_interface(), "no interface here");
3975   return make(ptr(), klass(), _interfaces, klass_is_exact, const_oop(), _offset, _instance_id, _speculative, _inline_depth);
3976 }
3977 
3978 //-----------------------------cast_to_instance_id----------------------------
3979 const TypeInstPtr* TypeInstPtr::cast_to_instance_id(int instance_id) const {
3980   if( instance_id == _instance_id ) return this;
3981   return make(_ptr, klass(),  _interfaces, _klass_is_exact, const_oop(), _offset, instance_id, _speculative, _inline_depth);
3982 }
3983 
3984 //------------------------------xmeet_unloaded---------------------------------
3985 // Compute the MEET of two InstPtrs when at least one is unloaded.
3986 // Assume classes are different since called after check for same name/class-loader
3987 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst, const InterfaceSet& interfaces) const {
3988   int off = meet_offset(tinst->offset());
3989   PTR ptr = meet_ptr(tinst->ptr());
3990   int instance_id = meet_instance_id(tinst->instance_id());
3991   const TypePtr* speculative = xmeet_speculative(tinst);
3992   int depth = meet_inline_depth(tinst->inline_depth());
3993 
3994   const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
3995   const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
3996   if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
3997     //
3998     // Meet unloaded class with java/lang/Object
3999     //
4000     // Meet
4001     //          |                     Unloaded Class
4002     //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
4003     //  ===================================================================
4004     //   TOP    | ..........................Unloaded......................|
4005     //  AnyNull |  U-AN    |................Unloaded......................|
4006     // Constant | ... O-NN .................................. |   O-BOT   |
4007     //  NotNull | ... O-NN .................................. |   O-BOT   |
4008     //  BOTTOM  | ........................Object-BOTTOM ..................|
4009     //
4010     assert(loaded->ptr() != TypePtr::Null, "insanity check");
4011     //
4012     if (loaded->ptr() == TypePtr::TopPTR)        { return unloaded; }
4013     else if (loaded->ptr() == TypePtr::AnyNull)  { return make(ptr, unloaded->klass(), interfaces, false, NULL, off, instance_id, speculative, depth); }
4014     else if (loaded->ptr() == TypePtr::BotPTR)   { return TypeInstPtr::BOTTOM; }
4015     else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
4016       if (unloaded->ptr() == TypePtr::BotPTR)    { return TypeInstPtr::BOTTOM;  }
4017       else                                       { return TypeInstPtr::NOTNULL; }
4018     }
4019     else if (unloaded->ptr() == TypePtr::TopPTR) { return unloaded; }
4020 
4021     return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr();
4022   }
4023 
4024   // Both are unloaded, not the same class, not Object
4025   // Or meet unloaded with a different loaded class, not java/lang/Object
4026   if (ptr != TypePtr::BotPTR) {
4027     return TypeInstPtr::NOTNULL;
4028   }
4029   return TypeInstPtr::BOTTOM;
4030 }
4031 
4032 
4033 //------------------------------meet-------------------------------------------
4034 // Compute the MEET of two types.  It returns a new Type object.
4035 const Type *TypeInstPtr::xmeet_helper(const Type *t) const {
4036   // Perform a fast test for common case; meeting the same types together.
4037   if( this == t ) return this;  // Meeting same type-rep?
4038 
4039   // Current "this->_base" is Pointer
4040   switch (t->base()) {          // switch on original type
4041 
4042   case Int:                     // Mixing ints & oops happens when javac
4043   case Long:                    // reuses local variables
4044   case FloatTop:
4045   case FloatCon:
4046   case FloatBot:
4047   case DoubleTop:
4048   case DoubleCon:
4049   case DoubleBot:
4050   case NarrowOop:
4051   case NarrowKlass:
4052   case Bottom:                  // Ye Olde Default
4053     return Type::BOTTOM;
4054   case Top:
4055     return this;
4056 
4057   default:                      // All else is a mistake
4058     typerr(t);
4059 
4060   case MetadataPtr:
4061   case KlassPtr:
4062   case InstKlassPtr:
4063   case AryKlassPtr:
4064   case RawPtr: return TypePtr::BOTTOM;
4065 
4066   case AryPtr: {                // All arrays inherit from Object class
4067     // Call in reverse direction to avoid duplication
4068     return t->is_aryptr()->xmeet_helper(this);
4069   }
4070 
4071   case OopPtr: {                // Meeting to OopPtrs
4072     // Found a OopPtr type vs self-InstPtr type
4073     const TypeOopPtr *tp = t->is_oopptr();
4074     int offset = meet_offset(tp->offset());
4075     PTR ptr = meet_ptr(tp->ptr());
4076     switch (tp->ptr()) {
4077     case TopPTR:
4078     case AnyNull: {
4079       int instance_id = meet_instance_id(InstanceTop);
4080       const TypePtr* speculative = xmeet_speculative(tp);
4081       int depth = meet_inline_depth(tp->inline_depth());
4082       return make(ptr, klass(), _interfaces, klass_is_exact(),
4083                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth);
4084     }
4085     case NotNull:
4086     case BotPTR: {
4087       int instance_id = meet_instance_id(tp->instance_id());
4088       const TypePtr* speculative = xmeet_speculative(tp);
4089       int depth = meet_inline_depth(tp->inline_depth());
4090       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4091     }
4092     default: typerr(t);
4093     }
4094   }
4095 
4096   case AnyPtr: {                // Meeting to AnyPtrs
4097     // Found an AnyPtr type vs self-InstPtr type
4098     const TypePtr *tp = t->is_ptr();
4099     int offset = meet_offset(tp->offset());
4100     PTR ptr = meet_ptr(tp->ptr());
4101     int instance_id = meet_instance_id(InstanceTop);
4102     const TypePtr* speculative = xmeet_speculative(tp);
4103     int depth = meet_inline_depth(tp->inline_depth());
4104     switch (tp->ptr()) {
4105     case Null:
4106       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4107       // else fall through to AnyNull
4108     case TopPTR:
4109     case AnyNull: {
4110       return make(ptr, klass(), _interfaces, klass_is_exact(),
4111                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth);
4112     }
4113     case NotNull:
4114     case BotPTR:
4115       return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4116     default: typerr(t);
4117     }
4118   }
4119 
4120   /*
4121                  A-top         }
4122                /   |   \       }  Tops
4123            B-top A-any C-top   }
4124               | /  |  \ |      }  Any-nulls
4125            B-any   |   C-any   }
4126               |    |    |
4127            B-con A-con C-con   } constants; not comparable across classes
4128               |    |    |
4129            B-not   |   C-not   }
4130               | \  |  / |      }  not-nulls
4131            B-bot A-not C-bot   }
4132                \   |   /       }  Bottoms
4133                  A-bot         }
4134   */
4135 
4136   case InstPtr: {                // Meeting 2 Oops?
4137     // Found an InstPtr sub-type vs self-InstPtr type
4138     const TypeInstPtr *tinst = t->is_instptr();
4139     int off = meet_offset(tinst->offset());
4140     PTR ptr = meet_ptr(tinst->ptr());
4141     int instance_id = meet_instance_id(tinst->instance_id());
4142     const TypePtr* speculative = xmeet_speculative(tinst);
4143     int depth = meet_inline_depth(tinst->inline_depth());
4144     InterfaceSet interfaces = meet_interfaces(tinst);
4145 
4146     ciKlass* tinst_klass = tinst->klass();
4147     ciKlass* this_klass  = klass();
4148 
4149     ciKlass* res_klass = NULL;
4150     bool res_xk = false;
4151     const Type* res;
4152     MeetResult kind = meet_instptr(ptr, interfaces, this, tinst, res_klass, res_xk);
4153 
4154     if (kind == UNLOADED) {
4155       // One of these classes has not been loaded
4156       const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst, interfaces);
4157 #ifndef PRODUCT
4158       if (PrintOpto && Verbose) {
4159         tty->print("meet of unloaded classes resulted in: ");
4160         unloaded_meet->dump();
4161         tty->cr();
4162         tty->print("  this == ");
4163         dump();
4164         tty->cr();
4165         tty->print(" tinst == ");
4166         tinst->dump();
4167         tty->cr();
4168       }
4169 #endif
4170       res = unloaded_meet;
4171     } else {
4172       if (kind == NOT_SUBTYPE && instance_id > 0) {
4173         instance_id = InstanceBot;
4174       } else if (kind == LCA) {
4175         instance_id = InstanceBot;
4176       }
4177       ciObject* o = NULL;             // Assume not constant when done
4178       ciObject* this_oop = const_oop();
4179       ciObject* tinst_oop = tinst->const_oop();
4180       if (ptr == Constant) {
4181         if (this_oop != NULL && tinst_oop != NULL &&
4182             this_oop->equals(tinst_oop))
4183           o = this_oop;
4184         else if (above_centerline(_ptr)) {
4185           assert(!tinst_klass->is_interface(), "");
4186           o = tinst_oop;
4187         } else if (above_centerline(tinst->_ptr)) {
4188           assert(!this_klass->is_interface(), "");
4189           o = this_oop;
4190         } else
4191           ptr = NotNull;
4192       }
4193       res = make(ptr, res_klass, interfaces, res_xk, o, off, instance_id, speculative, depth);
4194     }
4195 
4196     return res;
4197 
4198   } // End of case InstPtr
4199 
4200   } // End of switch
4201   return this;                  // Return the double constant
4202 }
4203 
4204 template<class T> TypePtr::MeetResult TypePtr::meet_instptr(PTR& ptr, InterfaceSet& interfaces, const T* this_type, const T* other_type,
4205                       ciKlass*& res_klass, bool& res_xk) {
4206   ciKlass* this_klass = this_type->klass();
4207   ciKlass* other_klass = other_type->klass();
4208   bool this_xk = this_type->klass_is_exact();
4209   bool other_xk = other_type->klass_is_exact();
4210   PTR this_ptr = this_type->ptr();
4211   PTR other_ptr = other_type->ptr();
4212   InterfaceSet this_interfaces = this_type->interfaces();
4213   InterfaceSet other_interfaces = other_type->interfaces();
4214   // Check for easy case; klasses are equal (and perhaps not loaded!)
4215   // If we have constants, then we created oops so classes are loaded
4216   // and we can handle the constants further down.  This case handles
4217   // both-not-loaded or both-loaded classes
4218   if (ptr != Constant && this_klass->equals(other_klass) && this_xk == other_xk) {
4219     res_klass = this_klass;
4220     res_xk = this_xk;
4221     return QUICK;
4222   }
4223 
4224   // Classes require inspection in the Java klass hierarchy.  Must be loaded.
4225   if (!other_klass->is_loaded() || !this_klass->is_loaded()) {
4226     return UNLOADED;
4227   }
4228 
4229   // !!! Here's how the symmetry requirement breaks down into invariants:
4230   // If we split one up & one down AND they subtype, take the down man.
4231   // If we split one up & one down AND they do NOT subtype, "fall hard".
4232   // If both are up and they subtype, take the subtype class.
4233   // If both are up and they do NOT subtype, "fall hard".
4234   // If both are down and they subtype, take the supertype class.
4235   // If both are down and they do NOT subtype, "fall hard".
4236   // Constants treated as down.
4237 
4238   // Now, reorder the above list; observe that both-down+subtype is also
4239   // "fall hard"; "fall hard" becomes the default case:
4240   // If we split one up & one down AND they subtype, take the down man.
4241   // If both are up and they subtype, take the subtype class.
4242 
4243   // If both are down and they subtype, "fall hard".
4244   // If both are down and they do NOT subtype, "fall hard".
4245   // If both are up and they do NOT subtype, "fall hard".
4246   // If we split one up & one down AND they do NOT subtype, "fall hard".
4247 
4248   // If a proper subtype is exact, and we return it, we return it exactly.
4249   // If a proper supertype is exact, there can be no subtyping relationship!
4250   // If both types are equal to the subtype, exactness is and-ed below the
4251   // centerline and or-ed above it.  (N.B. Constants are always exact.)
4252 
4253   // Check for subtyping:
4254   const T* subtype = NULL;
4255   bool subtype_exact = false;
4256   InterfaceSet subtype_interfaces;
4257 
4258   if (this_type->is_same_java_type_as(other_type)) {
4259     subtype = this_type;
4260     subtype_exact = below_centerline(ptr) ? (this_xk && other_xk) : (this_xk || other_xk);
4261   } else if (!other_xk && this_type->is_meet_subtype_of(other_type)) {
4262     subtype = this_type;     // Pick subtyping class
4263     subtype_exact = this_xk;
4264   } else if(!this_xk && other_type->is_meet_subtype_of(this_type)) {
4265     subtype = other_type;    // Pick subtyping class
4266     subtype_exact = other_xk;
4267   }
4268 
4269   if (subtype) {
4270     if (above_centerline(ptr)) { // both are up?
4271       this_type = other_type = subtype;
4272       this_xk = other_xk = subtype_exact;
4273     } else if (above_centerline(this_ptr) && !above_centerline(other_ptr)) {
4274       this_type = other_type; // tinst is down; keep down man
4275       this_xk = other_xk;
4276     } else if (above_centerline(other_ptr) && !above_centerline(this_ptr)) {
4277       other_type = this_type; // this is down; keep down man
4278       other_xk = this_xk;
4279     } else {
4280       this_xk = subtype_exact;  // either they are equal, or we'll do an LCA
4281     }
4282   }
4283 
4284   // Check for classes now being equal
4285   if (this_type->is_same_java_type_as(other_type)) {
4286     // If the klasses are equal, the constants may still differ.  Fall to
4287     // NotNull if they do (neither constant is NULL; that is a special case
4288     // handled elsewhere).
4289     res_klass = this_type->klass();
4290     res_xk = this_xk;
4291     return SUBTYPE;
4292   } // Else classes are not equal
4293 
4294   // Since klasses are different, we require a LCA in the Java
4295   // class hierarchy - which means we have to fall to at least NotNull.
4296   if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4297     ptr = NotNull;
4298   }
4299 
4300   interfaces = this_interfaces.intersection_with(other_interfaces);
4301 
4302   // Now we find the LCA of Java classes
4303   ciKlass* k = this_klass->least_common_ancestor(other_klass);
4304 
4305   res_klass = k;
4306   res_xk = false;
4307 
4308   return LCA;
4309 }
4310 
4311 //------------------------java_mirror_type--------------------------------------
4312 ciType* TypeInstPtr::java_mirror_type() const {
4313   // must be a singleton type
4314   if( const_oop() == NULL )  return NULL;
4315 
4316   // must be of type java.lang.Class
4317   if( klass() != ciEnv::current()->Class_klass() )  return NULL;
4318 
4319   return const_oop()->as_instance()->java_mirror_type();
4320 }
4321 
4322 
4323 //------------------------------xdual------------------------------------------
4324 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
4325 // inheritance mechanism.
4326 const Type *TypeInstPtr::xdual() const {
4327   return new TypeInstPtr(dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4328 }
4329 
4330 //------------------------------eq---------------------------------------------
4331 // Structural equality check for Type representations
4332 bool TypeInstPtr::eq( const Type *t ) const {
4333   const TypeInstPtr *p = t->is_instptr();
4334   return
4335     klass()->equals(p->klass()) &&
4336     _interfaces.eq(p->_interfaces) &&
4337     TypeOopPtr::eq(p);          // Check sub-type stuff
4338 }
4339 
4340 //------------------------------hash-------------------------------------------
4341 // Type-specific hashing function.
4342 int TypeInstPtr::hash(void) const {
4343   int hash = java_add(java_add((jint)klass()->hash(), (jint)TypeOopPtr::hash()), _interfaces.hash());
4344   return hash;
4345 }
4346 
4347 bool TypeInstPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4348   return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4349 }
4350 
4351 
4352 bool TypeInstPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4353   return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
4354 }
4355 
4356 bool TypeInstPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4357   return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4358 }
4359 
4360 
4361 //------------------------------dump2------------------------------------------
4362 // Dump oop Type
4363 #ifndef PRODUCT
4364 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {
4365   // Print the name of the klass.
4366   klass()->print_name_on(st);
4367   _interfaces.dump(st);
4368 
4369   switch( _ptr ) {
4370   case Constant:
4371     if (WizardMode || Verbose) {
4372       ResourceMark rm;
4373       stringStream ss;
4374 
4375       st->print(" ");
4376       const_oop()->print_oop(&ss);
4377       // 'const_oop->print_oop()' may emit newlines('\n') into ss.
4378       // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4379       char* buf = ss.as_string(/* c_heap= */false);
4380       StringUtils::replace_no_expand(buf, "\n", "");
4381       st->print_raw(buf);
4382     }
4383   case BotPTR:
4384     if (!WizardMode && !Verbose) {
4385       if( _klass_is_exact ) st->print(":exact");
4386       break;
4387     }
4388   case TopPTR:
4389   case AnyNull:
4390   case NotNull:
4391     st->print(":%s", ptr_msg[_ptr]);
4392     if( _klass_is_exact ) st->print(":exact");
4393     break;
4394   default:
4395     break;
4396   }
4397 
4398   if( _offset ) {               // Dump offset, if any
4399     if( _offset == OffsetBot )      st->print("+any");
4400     else if( _offset == OffsetTop ) st->print("+unknown");
4401     else st->print("+%d", _offset);
4402   }
4403 
4404   st->print(" *");
4405   if (_instance_id == InstanceTop)
4406     st->print(",iid=top");
4407   else if (_instance_id != InstanceBot)
4408     st->print(",iid=%d",_instance_id);
4409 
4410   dump_inline_depth(st);
4411   dump_speculative(st);
4412 }
4413 #endif
4414 
4415 //------------------------------add_offset-------------------------------------
4416 const TypePtr* TypeInstPtr::add_offset(intptr_t offset) const {
4417   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), xadd_offset(offset),
4418               _instance_id, add_offset_speculative(offset), _inline_depth);
4419 }
4420 
4421 const TypeInstPtr* TypeInstPtr::with_offset(intptr_t offset) const {
4422   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), offset,
4423               _instance_id, with_offset_speculative(offset), _inline_depth);
4424 }
4425 
4426 const TypeInstPtr* TypeInstPtr::remove_speculative() const {
4427   if (_speculative == NULL) {
4428     return this;
4429   }
4430   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4431   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset,
4432               _instance_id, NULL, _inline_depth);
4433 }
4434 
4435 const TypePtr* TypeInstPtr::with_inline_depth(int depth) const {
4436   if (!UseInlineDepthForSpeculativeTypes) {
4437     return this;
4438   }
4439   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth);
4440 }
4441 
4442 const TypePtr* TypeInstPtr::with_instance_id(int instance_id) const {
4443   assert(is_known_instance(), "should be known");
4444   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, instance_id, _speculative, _inline_depth);
4445 }
4446 
4447 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4448   bool xk = klass_is_exact();
4449   ciInstanceKlass* ik = klass()->as_instance_klass();
4450   if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final()) {
4451     ciKlass* k = ik;
4452     TypePtr::InterfaceSet interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
4453     assert(k == ik, "");
4454     if (interfaces.eq(_interfaces)) {
4455       Compile *C = Compile::current();
4456       Dependencies* deps = C->dependencies();
4457       deps->assert_leaf_type(ik);
4458       xk = true;
4459     }
4460   }
4461   return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), _interfaces, 0);
4462 }
4463 
4464 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) {
4465   static_assert(std::is_base_of<T2, T1>::value, "");
4466 
4467   if (!this_one->is_instance_type(other)) {
4468     return false;
4469   }
4470 
4471   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces.empty()) {
4472     return true;
4473   }
4474 
4475   return this_one->klass()->is_subtype_of(other->klass()) &&
4476          (!this_xk || this_one->_interfaces.contains(other->_interfaces));
4477 }
4478 
4479 
4480 bool TypeInstPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4481   return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4482 }
4483 
4484 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) {
4485   static_assert(std::is_base_of<T2, T1>::value, "");
4486   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces.empty()) {
4487     return true;
4488   }
4489 
4490   if (this_one->is_instance_type(other)) {
4491     return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces.contains(other->_interfaces);
4492   }
4493 
4494   int dummy;
4495   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
4496   if (this_top_or_bottom) {
4497     return false;
4498   }
4499 
4500   const T1* other_ary = this_one->is_array_type(other);
4501   const TypePtr* other_elem = other_ary->elem()->make_ptr();
4502   const TypePtr* this_elem = this_one->elem()->make_ptr();
4503   if (other_elem != NULL && this_elem != NULL) {
4504     return this_one->is_reference_type(this_elem)->is_meet_subtype_of_helper(this_one->is_reference_type(other_elem), this_xk, other_xk);
4505   }
4506 
4507   if (other_elem == NULL && this_elem == NULL) {
4508     return this_one->_klass->is_subtype_of(other->_klass);
4509   }
4510 
4511   return false;
4512 }
4513 
4514 bool TypeAryPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4515   return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4516 }
4517 
4518 bool TypeInstKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4519   return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4520 }
4521 
4522 bool TypeAryKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4523   return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4524 }
4525 
4526 //=============================================================================
4527 // Convenience common pre-built types.
4528 const TypeAryPtr *TypeAryPtr::RANGE;
4529 const TypeAryPtr *TypeAryPtr::OOPS;
4530 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
4531 const TypeAryPtr *TypeAryPtr::BYTES;
4532 const TypeAryPtr *TypeAryPtr::SHORTS;
4533 const TypeAryPtr *TypeAryPtr::CHARS;
4534 const TypeAryPtr *TypeAryPtr::INTS;
4535 const TypeAryPtr *TypeAryPtr::LONGS;
4536 const TypeAryPtr *TypeAryPtr::FLOATS;
4537 const TypeAryPtr *TypeAryPtr::DOUBLES;
4538 
4539 //------------------------------make-------------------------------------------
4540 const TypeAryPtr *TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4541                                    int instance_id, const TypePtr* speculative, int inline_depth) {
4542   assert(!(k == NULL && ary->_elem->isa_int()),
4543          "integral arrays must be pre-equipped with a class");
4544   if (!xk)  xk = ary->ary_must_be_exact();
4545   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4546   if (k != NULL && k->is_loaded() && k->is_obj_array_klass() &&
4547       k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4548     k = NULL;
4549   }
4550   return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id, false, speculative, inline_depth))->hashcons();
4551 }
4552 
4553 //------------------------------make-------------------------------------------
4554 const TypeAryPtr *TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4555                                    int instance_id, const TypePtr* speculative, int inline_depth,
4556                                    bool is_autobox_cache) {
4557   assert(!(k == NULL && ary->_elem->isa_int()),
4558          "integral arrays must be pre-equipped with a class");
4559   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4560   if (!xk)  xk = (o != NULL) || ary->ary_must_be_exact();
4561   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4562   if (k != NULL && k->is_loaded() && k->is_obj_array_klass() &&
4563       k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4564     k = NULL;
4565   }
4566   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4567 }
4568 
4569 //------------------------------cast_to_ptr_type-------------------------------
4570 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4571   if( ptr == _ptr ) return this;
4572   return make(ptr, ptr == Constant ? const_oop() : NULL, _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4573 }
4574 
4575 
4576 //-----------------------------cast_to_exactness-------------------------------
4577 const TypeAryPtr* TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4578   if( klass_is_exact == _klass_is_exact ) return this;
4579   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
4580   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
4581 }
4582 
4583 //-----------------------------cast_to_instance_id----------------------------
4584 const TypeAryPtr* TypeAryPtr::cast_to_instance_id(int instance_id) const {
4585   if( instance_id == _instance_id ) return this;
4586   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
4587 }
4588 
4589 
4590 //-----------------------------max_array_length-------------------------------
4591 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
4592 jint TypeAryPtr::max_array_length(BasicType etype) {
4593   if (!is_java_primitive(etype) && !::is_reference_type(etype)) {
4594     if (etype == T_NARROWOOP) {
4595       etype = T_OBJECT;
4596     } else if (etype == T_ILLEGAL) { // bottom[]
4597       etype = T_BYTE; // will produce conservatively high value
4598     } else {
4599       fatal("not an element type: %s", type2name(etype));
4600     }
4601   }
4602   return arrayOopDesc::max_array_length(etype);
4603 }
4604 
4605 //-----------------------------narrow_size_type-------------------------------
4606 // Narrow the given size type to the index range for the given array base type.
4607 // Return NULL if the resulting int type becomes empty.
4608 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const {
4609   jint hi = size->_hi;
4610   jint lo = size->_lo;
4611   jint min_lo = 0;
4612   jint max_hi = max_array_length(elem()->basic_type());
4613   //if (index_not_size)  --max_hi;     // type of a valid array index, FTR
4614   bool chg = false;
4615   if (lo < min_lo) {
4616     lo = min_lo;
4617     if (size->is_con()) {
4618       hi = lo;
4619     }
4620     chg = true;
4621   }
4622   if (hi > max_hi) {
4623     hi = max_hi;
4624     if (size->is_con()) {
4625       lo = hi;
4626     }
4627     chg = true;
4628   }
4629   // Negative length arrays will produce weird intermediate dead fast-path code
4630   if (lo > hi)
4631     return TypeInt::ZERO;
4632   if (!chg)
4633     return size;
4634   return TypeInt::make(lo, hi, Type::WidenMin);
4635 }
4636 
4637 //-------------------------------cast_to_size----------------------------------
4638 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4639   assert(new_size != NULL, "");
4640   new_size = narrow_size_type(new_size);
4641   if (new_size == size())  return this;
4642   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
4643   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4644 }
4645 
4646 //------------------------------cast_to_stable---------------------------------
4647 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
4648   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
4649     return this;
4650 
4651   const Type* elem = this->elem();
4652   const TypePtr* elem_ptr = elem->make_ptr();
4653 
4654   if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) {
4655     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
4656     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
4657   }
4658 
4659   const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
4660 
4661   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4662 }
4663 
4664 //-----------------------------stable_dimension--------------------------------
4665 int TypeAryPtr::stable_dimension() const {
4666   if (!is_stable())  return 0;
4667   int dim = 1;
4668   const TypePtr* elem_ptr = elem()->make_ptr();
4669   if (elem_ptr != NULL && elem_ptr->isa_aryptr())
4670     dim += elem_ptr->is_aryptr()->stable_dimension();
4671   return dim;
4672 }
4673 
4674 //----------------------cast_to_autobox_cache-----------------------------------
4675 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
4676   if (is_autobox_cache())  return this;
4677   const TypeOopPtr* etype = elem()->make_oopptr();
4678   if (etype == NULL)  return this;
4679   // The pointers in the autobox arrays are always non-null.
4680   etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
4681   const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable());
4682   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
4683 }
4684 
4685 //------------------------------eq---------------------------------------------
4686 // Structural equality check for Type representations
4687 bool TypeAryPtr::eq( const Type *t ) const {
4688   const TypeAryPtr *p = t->is_aryptr();
4689   return
4690     _ary == p->_ary &&  // Check array
4691     TypeOopPtr::eq(p);  // Check sub-parts
4692 }
4693 
4694 //------------------------------hash-------------------------------------------
4695 // Type-specific hashing function.
4696 int TypeAryPtr::hash(void) const {
4697   return (intptr_t)_ary + TypeOopPtr::hash();
4698 }
4699 
4700 bool TypeAryPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4701   return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
4702 }
4703 
4704 bool TypeAryPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4705   return TypePtr::is_same_java_type_as_helper_for_array(this, other);
4706 }
4707 
4708 bool TypeAryPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4709   return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
4710 }
4711 //------------------------------meet-------------------------------------------
4712 // Compute the MEET of two types.  It returns a new Type object.
4713 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
4714   // Perform a fast test for common case; meeting the same types together.
4715   if( this == t ) return this;  // Meeting same type-rep?
4716   // Current "this->_base" is Pointer
4717   switch (t->base()) {          // switch on original type
4718 
4719   // Mixing ints & oops happens when javac reuses local variables
4720   case Int:
4721   case Long:
4722   case FloatTop:
4723   case FloatCon:
4724   case FloatBot:
4725   case DoubleTop:
4726   case DoubleCon:
4727   case DoubleBot:
4728   case NarrowOop:
4729   case NarrowKlass:
4730   case Bottom:                  // Ye Olde Default
4731     return Type::BOTTOM;
4732   case Top:
4733     return this;
4734 
4735   default:                      // All else is a mistake
4736     typerr(t);
4737 
4738   case OopPtr: {                // Meeting to OopPtrs
4739     // Found a OopPtr type vs self-AryPtr type
4740     const TypeOopPtr *tp = t->is_oopptr();
4741     int offset = meet_offset(tp->offset());
4742     PTR ptr = meet_ptr(tp->ptr());
4743     int depth = meet_inline_depth(tp->inline_depth());
4744     const TypePtr* speculative = xmeet_speculative(tp);
4745     switch (tp->ptr()) {
4746     case TopPTR:
4747     case AnyNull: {
4748       int instance_id = meet_instance_id(InstanceTop);
4749       return make(ptr, (ptr == Constant ? const_oop() : NULL),
4750                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4751     }
4752     case BotPTR:
4753     case NotNull: {
4754       int instance_id = meet_instance_id(tp->instance_id());
4755       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4756     }
4757     default: ShouldNotReachHere();
4758     }
4759   }
4760 
4761   case AnyPtr: {                // Meeting two AnyPtrs
4762     // Found an AnyPtr type vs self-AryPtr type
4763     const TypePtr *tp = t->is_ptr();
4764     int offset = meet_offset(tp->offset());
4765     PTR ptr = meet_ptr(tp->ptr());
4766     const TypePtr* speculative = xmeet_speculative(tp);
4767     int depth = meet_inline_depth(tp->inline_depth());
4768     switch (tp->ptr()) {
4769     case TopPTR:
4770       return this;
4771     case BotPTR:
4772     case NotNull:
4773       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4774     case Null:
4775       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4776       // else fall through to AnyNull
4777     case AnyNull: {
4778       int instance_id = meet_instance_id(InstanceTop);
4779       return make(ptr, (ptr == Constant ? const_oop() : NULL),
4780                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4781     }
4782     default: ShouldNotReachHere();
4783     }
4784   }
4785 
4786   case MetadataPtr:
4787   case KlassPtr:
4788   case InstKlassPtr:
4789   case AryKlassPtr:
4790   case RawPtr: return TypePtr::BOTTOM;
4791 
4792   case AryPtr: {                // Meeting 2 references?
4793     const TypeAryPtr *tap = t->is_aryptr();
4794     int off = meet_offset(tap->offset());
4795     const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
4796     PTR ptr = meet_ptr(tap->ptr());
4797     int instance_id = meet_instance_id(tap->instance_id());
4798     const TypePtr* speculative = xmeet_speculative(tap);
4799     int depth = meet_inline_depth(tap->inline_depth());
4800 
4801     ciKlass* res_klass = NULL;
4802     bool res_xk = false;
4803     const Type* elem = tary->_elem;
4804     if (meet_aryptr(ptr, elem, this, tap, res_klass, res_xk) == NOT_SUBTYPE) {
4805       instance_id = InstanceBot;
4806     }
4807 
4808     ciObject* o = NULL;             // Assume not constant when done
4809     ciObject* this_oop = const_oop();
4810     ciObject* tap_oop = tap->const_oop();
4811     if (ptr == Constant) {
4812       if (this_oop != NULL && tap_oop != NULL &&
4813           this_oop->equals(tap_oop)) {
4814         o = tap_oop;
4815       } else if (above_centerline(_ptr)) {
4816         o = tap_oop;
4817       } else if (above_centerline(tap->_ptr)) {
4818         o = this_oop;
4819       } else {
4820         ptr = NotNull;
4821       }
4822     }
4823     return make(ptr, o, TypeAry::make(elem, tary->_size, tary->_stable), res_klass, res_xk, off, instance_id, speculative, depth);
4824   }
4825 
4826   // All arrays inherit from Object class
4827   case InstPtr: {
4828     const TypeInstPtr *tp = t->is_instptr();
4829     int offset = meet_offset(tp->offset());
4830     PTR ptr = meet_ptr(tp->ptr());
4831     int instance_id = meet_instance_id(tp->instance_id());
4832     const TypePtr* speculative = xmeet_speculative(tp);
4833     int depth = meet_inline_depth(tp->inline_depth());
4834     InterfaceSet interfaces = meet_interfaces(tp);
4835     InterfaceSet tp_interfaces = tp->_interfaces;
4836     InterfaceSet this_interfaces = _interfaces;
4837 
4838     switch (ptr) {
4839     case TopPTR:
4840     case AnyNull:                // Fall 'down' to dual of object klass
4841       // For instances when a subclass meets a superclass we fall
4842       // below the centerline when the superclass is exact. We need to
4843       // do the same here.
4844       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces.contains(tp_interfaces) && !tp->klass_is_exact()) {
4845         return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4846       } else {
4847         // cannot subclass, so the meet has to fall badly below the centerline
4848         ptr = NotNull;
4849         instance_id = InstanceBot;
4850         interfaces = this_interfaces.intersection_with(tp_interfaces);
4851         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, NULL,offset, instance_id, speculative, depth);
4852       }
4853     case Constant:
4854     case NotNull:
4855     case BotPTR:                // Fall down to object klass
4856       // LCA is object_klass, but if we subclass from the top we can do better
4857       if (above_centerline(tp->ptr())) {
4858         // If 'tp'  is above the centerline and it is Object class
4859         // then we can subclass in the Java class hierarchy.
4860         // For instances when a subclass meets a superclass we fall
4861         // below the centerline when the superclass is exact. We need
4862         // to do the same here.
4863         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces.contains(tp_interfaces) && !tp->klass_is_exact()) {
4864           // that is, my array type is a subtype of 'tp' klass
4865           return make(ptr, (ptr == Constant ? const_oop() : NULL),
4866                       _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4867         }
4868       }
4869       // The other case cannot happen, since t cannot be a subtype of an array.
4870       // The meet falls down to Object class below centerline.
4871       if (ptr == Constant) {
4872          ptr = NotNull;
4873       }
4874       if (instance_id > 0) {
4875         instance_id = InstanceBot;
4876       }
4877       interfaces = this_interfaces.intersection_with(tp_interfaces);
4878       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, NULL, offset, instance_id, speculative, depth);
4879     default: typerr(t);
4880     }
4881   }
4882   }
4883   return this;                  // Lint noise
4884 }
4885 
4886 
4887 template<class T> TypePtr::MeetResult TypePtr::meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary,
4888                                                            const T* other_ary, ciKlass*& res_klass, bool& res_xk) {
4889   int dummy;
4890   bool this_top_or_bottom = (this_ary->base_element_type(dummy) == Type::TOP || this_ary->base_element_type(dummy) == Type::BOTTOM);
4891   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
4892   ciKlass* this_klass = this_ary->klass();
4893   ciKlass* other_klass = other_ary->klass();
4894   bool this_xk = this_ary->klass_is_exact();
4895   bool other_xk = other_ary->klass_is_exact();
4896   PTR this_ptr = this_ary->ptr();
4897   PTR other_ptr = other_ary->ptr();
4898   res_klass = NULL;
4899   MeetResult result = SUBTYPE;
4900   if (elem->isa_int()) {
4901     // Integral array element types have irrelevant lattice relations.
4902     // It is the klass that determines array layout, not the element type.
4903     if (this_top_or_bottom)
4904       res_klass = other_klass;
4905     else if (other_top_or_bottom || other_klass == this_klass) {
4906       res_klass = this_klass;
4907     } else {
4908       // Something like byte[int+] meets char[int+].
4909       // This must fall to bottom, not (int[-128..65535])[int+].
4910       // instance_id = InstanceBot;
4911       elem = Type::BOTTOM;
4912       result = NOT_SUBTYPE;
4913     }
4914   } else {// Non integral arrays.
4915     // Must fall to bottom if exact klasses in upper lattice
4916     // are not equal or super klass is exact.
4917     if ((above_centerline(ptr) || ptr == Constant) && !this_ary->is_same_java_type_as(other_ary) &&
4918         // meet with top[] and bottom[] are processed further down:
4919         !this_top_or_bottom && !other_top_or_bottom &&
4920         // both are exact and not equal:
4921         ((other_xk && this_xk) ||
4922          // 'tap'  is exact and super or unrelated:
4923          (other_xk && !other_ary->is_meet_subtype_of(this_ary)) ||
4924          // 'this' is exact and super or unrelated:
4925          (this_xk && !this_ary->is_meet_subtype_of(other_ary)))) {
4926       if (above_centerline(ptr) || (elem->make_ptr() && above_centerline(elem->make_ptr()->_ptr))) {
4927         elem = Type::BOTTOM;
4928       }
4929       ptr = NotNull;
4930       res_xk = false;
4931       return NOT_SUBTYPE;
4932     }
4933   }
4934 
4935   res_xk = false;
4936   switch (other_ptr) {
4937     case AnyNull:
4938     case TopPTR:
4939       // Compute new klass on demand, do not use tap->_klass
4940       if (below_centerline(this_ptr)) {
4941         res_xk = this_xk;
4942       } else {
4943         res_xk = (other_xk || this_xk);
4944       }
4945       return result;
4946     case Constant: {
4947       if (this_ptr == Constant) {
4948           res_xk = true;
4949       } else if(above_centerline(this_ptr)) {
4950         res_xk = true;
4951       } else {
4952         // Only precise for identical arrays
4953         res_xk = this_xk && (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom));
4954       }
4955       return result;
4956     }
4957     case NotNull:
4958     case BotPTR:
4959       // Compute new klass on demand, do not use tap->_klass
4960       if (above_centerline(this_ptr)) {
4961         res_xk = other_xk;
4962       } else {
4963         res_xk = (other_xk && this_xk) &&
4964                  (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom)); // Only precise for identical arrays
4965       }
4966       return result;
4967     default:  {
4968       ShouldNotReachHere();
4969       return result;
4970     }
4971   }
4972   return result;
4973 }
4974 
4975 
4976 //------------------------------xdual------------------------------------------
4977 // Dual: compute field-by-field dual
4978 const Type *TypeAryPtr::xdual() const {
4979   return new TypeAryPtr(dual_ptr(), _const_oop, _ary->dual()->is_ary(),_klass, _klass_is_exact, dual_offset(), dual_instance_id(), is_autobox_cache(), dual_speculative(), dual_inline_depth());
4980 }
4981 
4982 //------------------------------dump2------------------------------------------
4983 #ifndef PRODUCT
4984 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4985   _ary->dump2(d,depth,st);
4986   _interfaces.dump(st);
4987 
4988   switch( _ptr ) {
4989   case Constant:
4990     const_oop()->print(st);
4991     break;
4992   case BotPTR:
4993     if (!WizardMode && !Verbose) {
4994       if( _klass_is_exact ) st->print(":exact");
4995       break;
4996     }
4997   case TopPTR:
4998   case AnyNull:
4999   case NotNull:
5000     st->print(":%s", ptr_msg[_ptr]);
5001     if( _klass_is_exact ) st->print(":exact");
5002     break;
5003   default:
5004     break;
5005   }
5006 
5007   if( _offset != 0 ) {
5008     int header_size = objArrayOopDesc::header_size() * wordSize;

5009     if( _offset == OffsetTop )       st->print("+undefined");
5010     else if( _offset == OffsetBot )  st->print("+any");
5011     else if( _offset < header_size ) st->print("+%d", _offset);
5012     else {
5013       BasicType basic_elem_type = elem()->basic_type();
5014       if (basic_elem_type == T_ILLEGAL) {
5015         st->print("+any");
5016       } else {
5017         int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5018         int elem_size = type2aelembytes(basic_elem_type);
5019         st->print("[%d]", (_offset - array_base)/elem_size);
5020       }
5021     }
5022   }
5023   st->print(" *");
5024   if (_instance_id == InstanceTop)
5025     st->print(",iid=top");
5026   else if (_instance_id != InstanceBot)
5027     st->print(",iid=%d",_instance_id);
5028 
5029   dump_inline_depth(st);
5030   dump_speculative(st);
5031 }
5032 #endif
5033 
5034 bool TypeAryPtr::empty(void) const {
5035   if (_ary->empty())       return true;
5036   return TypeOopPtr::empty();
5037 }
5038 
5039 //------------------------------add_offset-------------------------------------
5040 const TypePtr* TypeAryPtr::add_offset(intptr_t offset) const {
5041   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
5042 }
5043 
5044 const TypeAryPtr* TypeAryPtr::with_offset(intptr_t offset) const {
5045   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, offset, _instance_id, with_offset_speculative(offset), _inline_depth);
5046 }
5047 
5048 const TypeAryPtr* TypeAryPtr::with_ary(const TypeAry* ary) const {
5049   return make(_ptr, _const_oop, ary, _klass, _klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
5050 }
5051 
5052 const TypeAryPtr* TypeAryPtr::remove_speculative() const {
5053   if (_speculative == NULL) {
5054     return this;
5055   }
5056   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
5057   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, NULL, _inline_depth);
5058 }
5059 
5060 const TypePtr* TypeAryPtr::with_inline_depth(int depth) const {
5061   if (!UseInlineDepthForSpeculativeTypes) {
5062     return this;
5063   }
5064   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, _speculative, depth);
5065 }
5066 
5067 const TypePtr* TypeAryPtr::with_instance_id(int instance_id) const {
5068   assert(is_known_instance(), "should be known");
5069   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
5070 }
5071 
5072 //=============================================================================
5073 
5074 //------------------------------hash-------------------------------------------
5075 // Type-specific hashing function.
5076 int TypeNarrowPtr::hash(void) const {
5077   return _ptrtype->hash() + 7;
5078 }
5079 
5080 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
5081   return _ptrtype->singleton();
5082 }
5083 
5084 bool TypeNarrowPtr::empty(void) const {
5085   return _ptrtype->empty();
5086 }
5087 
5088 intptr_t TypeNarrowPtr::get_con() const {
5089   return _ptrtype->get_con();
5090 }
5091 
5092 bool TypeNarrowPtr::eq( const Type *t ) const {
5093   const TypeNarrowPtr* tc = isa_same_narrowptr(t);
5094   if (tc != NULL) {
5095     if (_ptrtype->base() != tc->_ptrtype->base()) {
5096       return false;
5097     }
5098     return tc->_ptrtype->eq(_ptrtype);
5099   }
5100   return false;
5101 }
5102 
5103 const Type *TypeNarrowPtr::xdual() const {    // Compute dual right now.
5104   const TypePtr* odual = _ptrtype->dual()->is_ptr();
5105   return make_same_narrowptr(odual);
5106 }
5107 
5108 
5109 const Type *TypeNarrowPtr::filter_helper(const Type *kills, bool include_speculative) const {
5110   if (isa_same_narrowptr(kills)) {
5111     const Type* ft =_ptrtype->filter_helper(is_same_narrowptr(kills)->_ptrtype, include_speculative);
5112     if (ft->empty())
5113       return Type::TOP;           // Canonical empty value
5114     if (ft->isa_ptr()) {
5115       return make_hash_same_narrowptr(ft->isa_ptr());
5116     }
5117     return ft;
5118   } else if (kills->isa_ptr()) {
5119     const Type* ft = _ptrtype->join_helper(kills, include_speculative);
5120     if (ft->empty())
5121       return Type::TOP;           // Canonical empty value
5122     return ft;
5123   } else {
5124     return Type::TOP;
5125   }
5126 }
5127 
5128 //------------------------------xmeet------------------------------------------
5129 // Compute the MEET of two types.  It returns a new Type object.
5130 const Type *TypeNarrowPtr::xmeet( const Type *t ) const {
5131   // Perform a fast test for common case; meeting the same types together.
5132   if( this == t ) return this;  // Meeting same type-rep?
5133 
5134   if (t->base() == base()) {
5135     const Type* result = _ptrtype->xmeet(t->make_ptr());
5136     if (result->isa_ptr()) {
5137       return make_hash_same_narrowptr(result->is_ptr());
5138     }
5139     return result;
5140   }
5141 
5142   // Current "this->_base" is NarrowKlass or NarrowOop
5143   switch (t->base()) {          // switch on original type
5144 
5145   case Int:                     // Mixing ints & oops happens when javac
5146   case Long:                    // reuses local variables
5147   case FloatTop:
5148   case FloatCon:
5149   case FloatBot:
5150   case DoubleTop:
5151   case DoubleCon:
5152   case DoubleBot:
5153   case AnyPtr:
5154   case RawPtr:
5155   case OopPtr:
5156   case InstPtr:
5157   case AryPtr:
5158   case MetadataPtr:
5159   case KlassPtr:
5160   case InstKlassPtr:
5161   case AryKlassPtr:
5162   case NarrowOop:
5163   case NarrowKlass:
5164 
5165   case Bottom:                  // Ye Olde Default
5166     return Type::BOTTOM;
5167   case Top:
5168     return this;
5169 
5170   default:                      // All else is a mistake
5171     typerr(t);
5172 
5173   } // End of switch
5174 
5175   return this;
5176 }
5177 
5178 #ifndef PRODUCT
5179 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5180   _ptrtype->dump2(d, depth, st);
5181 }
5182 #endif
5183 
5184 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
5185 const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
5186 
5187 
5188 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
5189   return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();
5190 }
5191 
5192 const TypeNarrowOop* TypeNarrowOop::remove_speculative() const {
5193   return make(_ptrtype->remove_speculative()->is_ptr());
5194 }
5195 
5196 const Type* TypeNarrowOop::cleanup_speculative() const {
5197   return make(_ptrtype->cleanup_speculative()->is_ptr());
5198 }
5199 
5200 #ifndef PRODUCT
5201 void TypeNarrowOop::dump2( Dict & d, uint depth, outputStream *st ) const {
5202   st->print("narrowoop: ");
5203   TypeNarrowPtr::dump2(d, depth, st);
5204 }
5205 #endif
5206 
5207 const TypeNarrowKlass *TypeNarrowKlass::NULL_PTR;
5208 
5209 const TypeNarrowKlass* TypeNarrowKlass::make(const TypePtr* type) {
5210   return (const TypeNarrowKlass*)(new TypeNarrowKlass(type))->hashcons();
5211 }
5212 
5213 #ifndef PRODUCT
5214 void TypeNarrowKlass::dump2( Dict & d, uint depth, outputStream *st ) const {
5215   st->print("narrowklass: ");
5216   TypeNarrowPtr::dump2(d, depth, st);
5217 }
5218 #endif
5219 
5220 
5221 //------------------------------eq---------------------------------------------
5222 // Structural equality check for Type representations
5223 bool TypeMetadataPtr::eq( const Type *t ) const {
5224   const TypeMetadataPtr *a = (const TypeMetadataPtr*)t;
5225   ciMetadata* one = metadata();
5226   ciMetadata* two = a->metadata();
5227   if (one == NULL || two == NULL) {
5228     return (one == two) && TypePtr::eq(t);
5229   } else {
5230     return one->equals(two) && TypePtr::eq(t);
5231   }
5232 }
5233 
5234 //------------------------------hash-------------------------------------------
5235 // Type-specific hashing function.
5236 int TypeMetadataPtr::hash(void) const {
5237   return
5238     (metadata() ? metadata()->hash() : 0) +
5239     TypePtr::hash();
5240 }
5241 
5242 //------------------------------singleton--------------------------------------
5243 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5244 // constants
5245 bool TypeMetadataPtr::singleton(void) const {
5246   // detune optimizer to not generate constant metadata + constant offset as a constant!
5247   // TopPTR, Null, AnyNull, Constant are all singletons
5248   return (_offset == 0) && !below_centerline(_ptr);
5249 }
5250 
5251 //------------------------------add_offset-------------------------------------
5252 const TypePtr* TypeMetadataPtr::add_offset( intptr_t offset ) const {
5253   return make( _ptr, _metadata, xadd_offset(offset));
5254 }
5255 
5256 //-----------------------------filter------------------------------------------
5257 // Do not allow interface-vs.-noninterface joins to collapse to top.
5258 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
5259   const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
5260   if (ft == NULL || ft->empty())
5261     return Type::TOP;           // Canonical empty value
5262   return ft;
5263 }
5264 
5265  //------------------------------get_con----------------------------------------
5266 intptr_t TypeMetadataPtr::get_con() const {
5267   assert( _ptr == Null || _ptr == Constant, "" );
5268   assert( _offset >= 0, "" );
5269 
5270   if (_offset != 0) {
5271     // After being ported to the compiler interface, the compiler no longer
5272     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5273     // to a handle at compile time.  This handle is embedded in the generated
5274     // code and dereferenced at the time the nmethod is made.  Until that time,
5275     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5276     // have access to the addresses!).  This does not seem to currently happen,
5277     // but this assertion here is to help prevent its occurrence.
5278     tty->print_cr("Found oop constant with non-zero offset");
5279     ShouldNotReachHere();
5280   }
5281 
5282   return (intptr_t)metadata()->constant_encoding();
5283 }
5284 
5285 //------------------------------cast_to_ptr_type-------------------------------
5286 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
5287   if( ptr == _ptr ) return this;
5288   return make(ptr, metadata(), _offset);
5289 }
5290 
5291 //------------------------------meet-------------------------------------------
5292 // Compute the MEET of two types.  It returns a new Type object.
5293 const Type *TypeMetadataPtr::xmeet( const Type *t ) const {
5294   // Perform a fast test for common case; meeting the same types together.
5295   if( this == t ) return this;  // Meeting same type-rep?
5296 
5297   // Current "this->_base" is OopPtr
5298   switch (t->base()) {          // switch on original type
5299 
5300   case Int:                     // Mixing ints & oops happens when javac
5301   case Long:                    // reuses local variables
5302   case FloatTop:
5303   case FloatCon:
5304   case FloatBot:
5305   case DoubleTop:
5306   case DoubleCon:
5307   case DoubleBot:
5308   case NarrowOop:
5309   case NarrowKlass:
5310   case Bottom:                  // Ye Olde Default
5311     return Type::BOTTOM;
5312   case Top:
5313     return this;
5314 
5315   default:                      // All else is a mistake
5316     typerr(t);
5317 
5318   case AnyPtr: {
5319     // Found an AnyPtr type vs self-OopPtr type
5320     const TypePtr *tp = t->is_ptr();
5321     int offset = meet_offset(tp->offset());
5322     PTR ptr = meet_ptr(tp->ptr());
5323     switch (tp->ptr()) {
5324     case Null:
5325       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5326       // else fall through:
5327     case TopPTR:
5328     case AnyNull: {
5329       return make(ptr, _metadata, offset);
5330     }
5331     case BotPTR:
5332     case NotNull:
5333       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5334     default: typerr(t);
5335     }
5336   }
5337 
5338   case RawPtr:
5339   case KlassPtr:
5340   case InstKlassPtr:
5341   case AryKlassPtr:
5342   case OopPtr:
5343   case InstPtr:
5344   case AryPtr:
5345     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
5346 
5347   case MetadataPtr: {
5348     const TypeMetadataPtr *tp = t->is_metadataptr();
5349     int offset = meet_offset(tp->offset());
5350     PTR tptr = tp->ptr();
5351     PTR ptr = meet_ptr(tptr);
5352     ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
5353     if (tptr == TopPTR || _ptr == TopPTR ||
5354         metadata()->equals(tp->metadata())) {
5355       return make(ptr, md, offset);
5356     }
5357     // metadata is different
5358     if( ptr == Constant ) {  // Cannot be equal constants, so...
5359       if( tptr == Constant && _ptr != Constant)  return t;
5360       if( _ptr == Constant && tptr != Constant)  return this;
5361       ptr = NotNull;            // Fall down in lattice
5362     }
5363     return make(ptr, NULL, offset);
5364     break;
5365   }
5366   } // End of switch
5367   return this;                  // Return the double constant
5368 }
5369 
5370 
5371 //------------------------------xdual------------------------------------------
5372 // Dual of a pure metadata pointer.
5373 const Type *TypeMetadataPtr::xdual() const {
5374   return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
5375 }
5376 
5377 //------------------------------dump2------------------------------------------
5378 #ifndef PRODUCT
5379 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5380   st->print("metadataptr:%s", ptr_msg[_ptr]);
5381   if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata()));
5382   switch( _offset ) {
5383   case OffsetTop: st->print("+top"); break;
5384   case OffsetBot: st->print("+any"); break;
5385   case         0: break;
5386   default:        st->print("+%d",_offset); break;
5387   }
5388 }
5389 #endif
5390 
5391 
5392 //=============================================================================
5393 // Convenience common pre-built type.
5394 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
5395 
5396 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset):
5397   TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
5398 }
5399 
5400 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
5401   return make(Constant, m, 0);
5402 }
5403 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
5404   return make(Constant, m, 0);
5405 }
5406 
5407 //------------------------------make-------------------------------------------
5408 // Create a meta data constant
5409 const TypeMetadataPtr *TypeMetadataPtr::make(PTR ptr, ciMetadata* m, int offset) {
5410   assert(m == NULL || !m->is_klass(), "wrong type");
5411   return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
5412 }
5413 
5414 
5415 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
5416   const Type* elem = _ary->_elem;
5417   bool xk = klass_is_exact();
5418   if (elem->make_oopptr() != NULL) {
5419     elem = elem->make_oopptr()->as_klass_type(try_for_exact);
5420     if (elem->is_klassptr()->klass_is_exact()) {
5421       xk = true;
5422     }
5423   }
5424   return TypeAryKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, elem, klass(), 0);
5425 }
5426 
5427 const TypeKlassPtr* TypeKlassPtr::make(ciKlass *klass, InterfaceHandling interface_handling) {
5428   if (klass->is_instance_klass()) {
5429     return TypeInstKlassPtr::make(klass, interface_handling);
5430   }
5431   return TypeAryKlassPtr::make(klass, interface_handling);
5432 }
5433 
5434 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* klass, int offset, InterfaceHandling interface_handling) {
5435   if (klass->is_instance_klass()) {
5436     const InterfaceSet interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
5437     return TypeInstKlassPtr::make(ptr, klass, interfaces, offset);
5438   }
5439   return TypeAryKlassPtr::make(ptr, klass, offset, interface_handling);
5440 }
5441 
5442 
5443 //------------------------------TypeKlassPtr-----------------------------------
5444 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const InterfaceSet& interfaces, int offset)
5445   : TypePtr(t, ptr, offset), _klass(klass), _interfaces(interfaces) {
5446   assert(klass == NULL || !klass->is_loaded() || (klass->is_instance_klass() && !klass->is_interface()) ||
5447          klass->is_type_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "no interface here");
5448 }
5449 
5450 // Is there a single ciKlass* that can represent that type?
5451 ciKlass* TypeKlassPtr::exact_klass_helper() const {
5452   assert(_klass->is_instance_klass() && !_klass->is_interface(), "No interface");
5453   if (_interfaces.empty()) {
5454     return _klass;
5455   }
5456   if (_klass != ciEnv::current()->Object_klass()) {
5457     ciKlass* k = _klass;
5458     if (_interfaces.eq(TypePtr::interfaces(k, true, false, true, ignore_interfaces))) {
5459       return _klass;
5460     }
5461     return NULL;
5462   }
5463   return _interfaces.exact_klass();
5464 }
5465 
5466 //------------------------------eq---------------------------------------------
5467 // Structural equality check for Type representations
5468 bool TypeKlassPtr::eq(const Type *t) const {
5469   const TypeKlassPtr *p = t->is_klassptr();
5470   return
5471     _interfaces.eq(p->_interfaces) &&
5472     TypePtr::eq(p);
5473 }
5474 
5475 //------------------------------hash-------------------------------------------
5476 // Type-specific hashing function.
5477 int TypeKlassPtr::hash(void) const {
5478   return java_add((jint)TypePtr::hash(), _interfaces.hash());
5479 }
5480 
5481 //------------------------------singleton--------------------------------------
5482 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5483 // constants
5484 bool TypeKlassPtr::singleton(void) const {
5485   // detune optimizer to not generate constant klass + constant offset as a constant!
5486   // TopPTR, Null, AnyNull, Constant are all singletons
5487   return (_offset == 0) && !below_centerline(_ptr);
5488 }
5489 
5490 // Do not allow interface-vs.-noninterface joins to collapse to top.
5491 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
5492   // logic here mirrors the one from TypeOopPtr::filter. See comments
5493   // there.
5494   const Type* ft = join_helper(kills, include_speculative);
5495   const TypeKlassPtr* ftkp = ft->isa_instklassptr();
5496   const TypeKlassPtr* ktkp = kills->isa_instklassptr();
5497 
5498   if (ft->empty()) {
5499     return Type::TOP;           // Canonical empty value
5500   }
5501 
5502   return ft;
5503 }
5504 
5505 TypePtr::InterfaceSet TypeKlassPtr::meet_interfaces(const TypeKlassPtr* other) const {
5506   if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
5507     return _interfaces.union_with(other->_interfaces);
5508   } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
5509     return other->_interfaces;
5510   } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
5511     return _interfaces;
5512   }
5513   return _interfaces.intersection_with(other->_interfaces);
5514 }
5515 
5516 //------------------------------get_con----------------------------------------
5517 intptr_t TypeKlassPtr::get_con() const {
5518   assert( _ptr == Null || _ptr == Constant, "" );
5519   assert( _offset >= 0, "" );
5520 
5521   if (_offset != 0) {
5522     // After being ported to the compiler interface, the compiler no longer
5523     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5524     // to a handle at compile time.  This handle is embedded in the generated
5525     // code and dereferenced at the time the nmethod is made.  Until that time,
5526     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5527     // have access to the addresses!).  This does not seem to currently happen,
5528     // but this assertion here is to help prevent its occurrence.
5529     tty->print_cr("Found oop constant with non-zero offset");
5530     ShouldNotReachHere();
5531   }
5532 
5533   ciKlass* k = exact_klass();
5534 
5535   return (intptr_t)k->constant_encoding();
5536 }
5537 
5538 //------------------------------dump2------------------------------------------
5539 // Dump Klass Type
5540 #ifndef PRODUCT
5541 void TypeKlassPtr::dump2(Dict & d, uint depth, outputStream *st) const {
5542   switch(_ptr) {
5543   case Constant:
5544     st->print("precise ");
5545   case NotNull:
5546     {
5547       const char *name = klass()->name()->as_utf8();
5548       if (name) {
5549         st->print("%s: " INTPTR_FORMAT, name, p2i(klass()));
5550       } else {
5551         ShouldNotReachHere();
5552       }
5553       _interfaces.dump(st);
5554     }
5555   case BotPTR:
5556     if (!WizardMode && !Verbose && _ptr != Constant) break;
5557   case TopPTR:
5558   case AnyNull:
5559     st->print(":%s", ptr_msg[_ptr]);
5560     if (_ptr == Constant) st->print(":exact");
5561     break;
5562   default:
5563     break;
5564   }
5565 
5566   if (_offset) {               // Dump offset, if any
5567     if (_offset == OffsetBot)      { st->print("+any"); }
5568     else if (_offset == OffsetTop) { st->print("+unknown"); }
5569     else                            { st->print("+%d", _offset); }
5570   }
5571 
5572   st->print(" *");
5573 }
5574 #endif
5575 
5576 //=============================================================================
5577 // Convenience common pre-built types.
5578 
5579 // Not-null object klass or below
5580 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
5581 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
5582 
5583 bool TypeInstKlassPtr::eq(const Type *t) const {
5584   const TypeKlassPtr *p = t->is_klassptr();
5585   return
5586     klass()->equals(p->klass()) &&
5587     TypeKlassPtr::eq(p);
5588 }
5589 
5590 int TypeInstKlassPtr::hash(void) const {
5591   return java_add((jint)klass()->hash(), TypeKlassPtr::hash());
5592 }
5593 
5594 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, const InterfaceSet& interfaces, int offset) {
5595   TypeInstKlassPtr *r =
5596     (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, interfaces, offset))->hashcons();
5597 
5598   return r;
5599 }
5600 
5601 //------------------------------add_offset-------------------------------------
5602 // Access internals of klass object
5603 const TypePtr* TypeInstKlassPtr::add_offset( intptr_t offset ) const {
5604   return make( _ptr, klass(), _interfaces, xadd_offset(offset) );
5605 }
5606 
5607 const TypeInstKlassPtr* TypeInstKlassPtr::with_offset(intptr_t offset) const {
5608   return make(_ptr, klass(), _interfaces, offset);
5609 }
5610 
5611 //------------------------------cast_to_ptr_type-------------------------------
5612 const TypeInstKlassPtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
5613   assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
5614   if( ptr == _ptr ) return this;
5615   return make(ptr, _klass, _interfaces, _offset);
5616 }
5617 
5618 
5619 bool TypeInstKlassPtr::must_be_exact() const {
5620   if (!_klass->is_loaded())  return false;
5621   ciInstanceKlass* ik = _klass->as_instance_klass();
5622   if (ik->is_final())  return true;  // cannot clear xk
5623   return false;
5624 }
5625 
5626 //-----------------------------cast_to_exactness-------------------------------
5627 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
5628   if (klass_is_exact == (_ptr == Constant)) return this;
5629   if (must_be_exact()) return this;
5630   ciKlass* k = klass();
5631   return make(klass_is_exact ? Constant : NotNull, k, _interfaces, _offset);
5632 }
5633 
5634 
5635 //-----------------------------as_instance_type--------------------------------
5636 // Corresponding type for an instance of the given class.
5637 // It will be NotNull, and exact if and only if the klass type is exact.
5638 const TypeOopPtr* TypeInstKlassPtr::as_instance_type(bool klass_change) const {
5639   ciKlass* k = klass();
5640   bool xk = klass_is_exact();
5641   Compile* C = Compile::current();
5642   Dependencies* deps = C->dependencies();
5643   assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
5644   // Element is an instance
5645   bool klass_is_exact = false;
5646   TypePtr::InterfaceSet interfaces = _interfaces;
5647   if (k->is_loaded()) {
5648     // Try to set klass_is_exact.
5649     ciInstanceKlass* ik = k->as_instance_klass();
5650     klass_is_exact = ik->is_final();
5651     if (!klass_is_exact && klass_change
5652         && deps != NULL && UseUniqueSubclasses) {
5653       ciInstanceKlass* sub = ik->unique_concrete_subklass();
5654       if (sub != NULL) {
5655         ciKlass* sub_k = sub;
5656         TypePtr::InterfaceSet sub_interfaces = TypePtr::interfaces(sub_k, true, false, false, ignore_interfaces);
5657         assert(sub_k == sub, "");
5658         if (sub_interfaces.eq(_interfaces)) {
5659           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
5660           k = ik = sub;
5661           xk = sub->is_final();
5662         }
5663       }
5664     }
5665   }
5666   return TypeInstPtr::make(TypePtr::BotPTR, k, interfaces, xk, NULL, 0);
5667 }
5668 
5669 //------------------------------xmeet------------------------------------------
5670 // Compute the MEET of two types, return a new Type object.
5671 const Type    *TypeInstKlassPtr::xmeet( const Type *t ) const {
5672   // Perform a fast test for common case; meeting the same types together.
5673   if( this == t ) return this;  // Meeting same type-rep?
5674 
5675   // Current "this->_base" is Pointer
5676   switch (t->base()) {          // switch on original type
5677 
5678   case Int:                     // Mixing ints & oops happens when javac
5679   case Long:                    // reuses local variables
5680   case FloatTop:
5681   case FloatCon:
5682   case FloatBot:
5683   case DoubleTop:
5684   case DoubleCon:
5685   case DoubleBot:
5686   case NarrowOop:
5687   case NarrowKlass:
5688   case Bottom:                  // Ye Olde Default
5689     return Type::BOTTOM;
5690   case Top:
5691     return this;
5692 
5693   default:                      // All else is a mistake
5694     typerr(t);
5695 
5696   case AnyPtr: {                // Meeting to AnyPtrs
5697     // Found an AnyPtr type vs self-KlassPtr type
5698     const TypePtr *tp = t->is_ptr();
5699     int offset = meet_offset(tp->offset());
5700     PTR ptr = meet_ptr(tp->ptr());
5701     switch (tp->ptr()) {
5702     case TopPTR:
5703       return this;
5704     case Null:
5705       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5706     case AnyNull:
5707       return make( ptr, klass(), _interfaces, offset );
5708     case BotPTR:
5709     case NotNull:
5710       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5711     default: typerr(t);
5712     }
5713   }
5714 
5715   case RawPtr:
5716   case MetadataPtr:
5717   case OopPtr:
5718   case AryPtr:                  // Meet with AryPtr
5719   case InstPtr:                 // Meet with InstPtr
5720     return TypePtr::BOTTOM;
5721 
5722   //
5723   //             A-top         }
5724   //           /   |   \       }  Tops
5725   //       B-top A-any C-top   }
5726   //          | /  |  \ |      }  Any-nulls
5727   //       B-any   |   C-any   }
5728   //          |    |    |
5729   //       B-con A-con C-con   } constants; not comparable across classes
5730   //          |    |    |
5731   //       B-not   |   C-not   }
5732   //          | \  |  / |      }  not-nulls
5733   //       B-bot A-not C-bot   }
5734   //           \   |   /       }  Bottoms
5735   //             A-bot         }
5736   //
5737 
5738   case InstKlassPtr: {  // Meet two KlassPtr types
5739     const TypeInstKlassPtr *tkls = t->is_instklassptr();
5740     int  off     = meet_offset(tkls->offset());
5741     PTR  ptr     = meet_ptr(tkls->ptr());
5742     InterfaceSet interfaces = meet_interfaces(tkls);
5743 
5744     ciKlass* res_klass = NULL;
5745     bool res_xk = false;
5746     switch(meet_instptr(ptr, interfaces, this, tkls, res_klass, res_xk)) {
5747       case UNLOADED:
5748         ShouldNotReachHere();
5749       case SUBTYPE:
5750       case NOT_SUBTYPE:
5751       case LCA:
5752       case QUICK: {
5753         assert(res_xk == (ptr == Constant), "");
5754         const Type* res = make(ptr, res_klass, interfaces, off);
5755         return res;
5756       }
5757       default:
5758         ShouldNotReachHere();
5759     }
5760   } // End of case KlassPtr
5761   case AryKlassPtr: {                // All arrays inherit from Object class
5762     const TypeAryKlassPtr *tp = t->is_aryklassptr();
5763     int offset = meet_offset(tp->offset());
5764     PTR ptr = meet_ptr(tp->ptr());
5765     InterfaceSet interfaces = meet_interfaces(tp);
5766     InterfaceSet tp_interfaces = tp->_interfaces;
5767     InterfaceSet this_interfaces = _interfaces;
5768 
5769     switch (ptr) {
5770     case TopPTR:
5771     case AnyNull:                // Fall 'down' to dual of object klass
5772       // For instances when a subclass meets a superclass we fall
5773       // below the centerline when the superclass is exact. We need to
5774       // do the same here.
5775       if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces.contains(this_interfaces) && !klass_is_exact()) {
5776         return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset);
5777       } else {
5778         // cannot subclass, so the meet has to fall badly below the centerline
5779         ptr = NotNull;
5780         interfaces = _interfaces.intersection_with(tp->_interfaces);
5781         return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
5782       }
5783     case Constant:
5784     case NotNull:
5785     case BotPTR:                // Fall down to object klass
5786       // LCA is object_klass, but if we subclass from the top we can do better
5787       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
5788         // If 'this' (InstPtr) is above the centerline and it is Object class
5789         // then we can subclass in the Java class hierarchy.
5790         // For instances when a subclass meets a superclass we fall
5791         // below the centerline when the superclass is exact. We need
5792         // to do the same here.
5793         if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces.contains(this_interfaces) && !klass_is_exact()) {
5794           // that is, tp's array type is a subtype of my klass
5795           return TypeAryKlassPtr::make(ptr,
5796                                        tp->elem(), tp->klass(), offset);
5797         }
5798       }
5799       // The other case cannot happen, since I cannot be a subtype of an array.
5800       // The meet falls down to Object class below centerline.
5801       if( ptr == Constant )
5802          ptr = NotNull;
5803       interfaces = this_interfaces.intersection_with(tp_interfaces);
5804       return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
5805     default: typerr(t);
5806     }
5807   }
5808 
5809   } // End of switch
5810   return this;                  // Return the double constant
5811 }
5812 
5813 //------------------------------xdual------------------------------------------
5814 // Dual: compute field-by-field dual
5815 const Type    *TypeInstKlassPtr::xdual() const {
5816   return new TypeInstKlassPtr(dual_ptr(), klass(), _interfaces, dual_offset());
5817 }
5818 
5819 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) {
5820   static_assert(std::is_base_of<T2, T1>::value, "");
5821   if (!this_one->is_loaded() || !other->is_loaded()) {
5822     return false;
5823   }
5824   if (!this_one->is_instance_type(other)) {
5825     return false;
5826   }
5827 
5828   if (!other_exact) {
5829     return false;
5830   }
5831 
5832   if (other->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces.empty()) {
5833     return true;
5834   }
5835 
5836   return this_one->_klass->is_subtype_of(other->_klass) && this_one->_interfaces.contains(other->_interfaces);
5837 }
5838 
5839 bool TypeInstKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
5840   return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
5841 }
5842 
5843 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_instance(const T1* this_one, const T2* other) {
5844   static_assert(std::is_base_of<T2, T1>::value, "");
5845   if (!this_one->is_loaded() || !other->is_loaded()) {
5846     return false;
5847   }
5848   if (!this_one->is_instance_type(other)) {
5849     return false;
5850   }
5851   return this_one->_klass->equals(other->_klass) && this_one->_interfaces.eq(other->_interfaces);
5852 }
5853 
5854 bool TypeInstKlassPtr::is_same_java_type_as_helper(const TypeKlassPtr* other) const {
5855   return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
5856 }
5857 
5858 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) {
5859   static_assert(std::is_base_of<T2, T1>::value, "");
5860   if (!this_one->is_loaded() || !other->is_loaded()) {
5861     return true;
5862   }
5863 
5864   if (this_one->is_array_type(other)) {
5865     return !this_exact && this_one->_klass->equals(ciEnv::current()->Object_klass())  && other->_interfaces.contains(this_one->_interfaces);
5866   }
5867 
5868   assert(this_one->is_instance_type(other), "unsupported");
5869 
5870   if (this_exact && other_exact) {
5871     return this_one->is_java_subtype_of(other);
5872   }
5873 
5874   if (!this_one->_klass->is_subtype_of(other->_klass) && !other->_klass->is_subtype_of(this_one->_klass)) {
5875     return false;
5876   }
5877 
5878   if (this_exact) {
5879     return this_one->_klass->is_subtype_of(other->_klass) && this_one->_interfaces.contains(other->_interfaces);
5880   }
5881 
5882   return true;
5883 }
5884 
5885 bool TypeInstKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
5886   return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
5887 }
5888 
5889 const TypeKlassPtr* TypeInstKlassPtr::try_improve() const {
5890   if (!UseUniqueSubclasses) {
5891     return this;
5892   }
5893   ciKlass* k = klass();
5894   Compile* C = Compile::current();
5895   Dependencies* deps = C->dependencies();
5896   assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
5897   TypePtr::InterfaceSet interfaces = _interfaces;
5898   if (k->is_loaded()) {
5899     ciInstanceKlass* ik = k->as_instance_klass();
5900     bool klass_is_exact = ik->is_final();
5901     if (!klass_is_exact &&
5902         deps != NULL) {
5903       ciInstanceKlass* sub = ik->unique_concrete_subklass();
5904       if (sub != NULL) {
5905         ciKlass *sub_k = sub;
5906         TypePtr::InterfaceSet sub_interfaces = TypePtr::interfaces(sub_k, true, false, false, ignore_interfaces);
5907         assert(sub_k == sub, "");
5908         if (sub_interfaces.eq(_interfaces)) {
5909           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
5910           k = ik = sub;
5911           klass_is_exact = sub->is_final();
5912           return TypeKlassPtr::make(klass_is_exact ? Constant : _ptr, k, _offset);
5913         }
5914       }
5915     }
5916   }
5917   return this;
5918 }
5919 
5920 
5921 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, int offset) {
5922   return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset))->hashcons();
5923 }
5924 
5925 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, ciKlass* k, int offset, InterfaceHandling interface_handling) {
5926   if (k->is_obj_array_klass()) {
5927     // Element is an object array. Recursively call ourself.
5928     ciKlass* eklass = k->as_obj_array_klass()->element_klass();
5929     const TypeKlassPtr *etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
5930     return TypeAryKlassPtr::make(ptr, etype, NULL, offset);
5931   } else if (k->is_type_array_klass()) {
5932     // Element is an typeArray
5933     const Type* etype = get_const_basic_type(k->as_type_array_klass()->element_type());
5934     return TypeAryKlassPtr::make(ptr, etype, k, offset);
5935   } else {
5936     ShouldNotReachHere();
5937     return NULL;
5938   }
5939 }
5940 
5941 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
5942   return TypeAryKlassPtr::make(Constant, klass, 0, interface_handling);
5943 }
5944 
5945 //------------------------------eq---------------------------------------------
5946 // Structural equality check for Type representations
5947 bool TypeAryKlassPtr::eq(const Type *t) const {
5948   const TypeAryKlassPtr *p = t->is_aryklassptr();
5949   return
5950     _elem == p->_elem &&  // Check array
5951     TypeKlassPtr::eq(p);  // Check sub-parts
5952 }
5953 
5954 //------------------------------hash-------------------------------------------
5955 // Type-specific hashing function.
5956 int TypeAryKlassPtr::hash(void) const {
5957   return (intptr_t)_elem + TypeKlassPtr::hash();
5958 }
5959 
5960 //----------------------compute_klass------------------------------------------
5961 // Compute the defining klass for this class
5962 ciKlass* TypeAryPtr::compute_klass(DEBUG_ONLY(bool verify)) const {
5963   // Compute _klass based on element type.
5964   ciKlass* k_ary = NULL;
5965   const TypeInstPtr *tinst;
5966   const TypeAryPtr *tary;
5967   const Type* el = elem();
5968   if (el->isa_narrowoop()) {
5969     el = el->make_ptr();
5970   }
5971 
5972   // Get element klass
5973   if ((tinst = el->isa_instptr()) != NULL) {
5974     // Leave k_ary at NULL.
5975   } else if ((tary = el->isa_aryptr()) != NULL) {
5976     // Leave k_ary at NULL.
5977   } else if ((el->base() == Type::Top) ||
5978              (el->base() == Type::Bottom)) {
5979     // element type of Bottom occurs from meet of basic type
5980     // and object; Top occurs when doing join on Bottom.
5981     // Leave k_ary at NULL.
5982   } else {
5983     // Cannot compute array klass directly from basic type,
5984     // since subtypes of TypeInt all have basic type T_INT.
5985 #ifdef ASSERT
5986     if (verify && el->isa_int()) {
5987       // Check simple cases when verifying klass.
5988       BasicType bt = T_ILLEGAL;
5989       if (el == TypeInt::BYTE) {
5990         bt = T_BYTE;
5991       } else if (el == TypeInt::SHORT) {
5992         bt = T_SHORT;
5993       } else if (el == TypeInt::CHAR) {
5994         bt = T_CHAR;
5995       } else if (el == TypeInt::INT) {
5996         bt = T_INT;
5997       } else {
5998         return _klass; // just return specified klass
5999       }
6000       return ciTypeArrayKlass::make(bt);
6001     }
6002 #endif
6003     assert(!el->isa_int(),
6004            "integral arrays must be pre-equipped with a class");
6005     // Compute array klass directly from basic type
6006     k_ary = ciTypeArrayKlass::make(el->basic_type());
6007   }
6008   return k_ary;
6009 }
6010 
6011 //------------------------------klass------------------------------------------
6012 // Return the defining klass for this class
6013 ciKlass* TypeAryPtr::klass() const {
6014   if( _klass ) return _klass;   // Return cached value, if possible
6015 
6016   // Oops, need to compute _klass and cache it
6017   ciKlass* k_ary = compute_klass();
6018 
6019   if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) {
6020     // The _klass field acts as a cache of the underlying
6021     // ciKlass for this array type.  In order to set the field,
6022     // we need to cast away const-ness.
6023     //
6024     // IMPORTANT NOTE: we *never* set the _klass field for the
6025     // type TypeAryPtr::OOPS.  This Type is shared between all
6026     // active compilations.  However, the ciKlass which represents
6027     // this Type is *not* shared between compilations, so caching
6028     // this value would result in fetching a dangling pointer.
6029     //
6030     // Recomputing the underlying ciKlass for each request is
6031     // a bit less efficient than caching, but calls to
6032     // TypeAryPtr::OOPS->klass() are not common enough to matter.
6033     ((TypeAryPtr*)this)->_klass = k_ary;
6034   }
6035   return k_ary;
6036 }
6037 
6038 // Is there a single ciKlass* that can represent that type?
6039 ciKlass* TypeAryPtr::exact_klass_helper() const {
6040   if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) {
6041     ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper();
6042     if (k == NULL) {
6043       return NULL;
6044     }
6045     k = ciObjArrayKlass::make(k);
6046     return k;
6047   }
6048 
6049   return klass();
6050 }
6051 
6052 const Type* TypeAryPtr::base_element_type(int& dims) const {
6053   const Type* elem = this->elem();
6054   dims = 1;
6055   while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) {
6056     elem = elem->make_ptr()->is_aryptr()->elem();
6057     dims++;
6058   }
6059   return elem;
6060 }
6061 
6062 //------------------------------add_offset-------------------------------------
6063 // Access internals of klass object
6064 const TypePtr* TypeAryKlassPtr::add_offset(intptr_t offset) const {
6065   return make(_ptr, elem(), klass(), xadd_offset(offset));
6066 }
6067 
6068 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const {
6069   return make(_ptr, elem(), klass(), offset);
6070 }
6071 
6072 //------------------------------cast_to_ptr_type-------------------------------
6073 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6074   assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6075   if (ptr == _ptr) return this;
6076   return make(ptr, elem(), _klass, _offset);
6077 }
6078 
6079 bool TypeAryKlassPtr::must_be_exact() const {
6080   if (_elem == Type::BOTTOM) return false;
6081   if (_elem == Type::TOP   ) return false;
6082   const TypeKlassPtr*  tk = _elem->isa_klassptr();
6083   if (!tk)             return true;   // a primitive type, like int
6084   return tk->must_be_exact();
6085 }
6086 
6087 
6088 //-----------------------------cast_to_exactness-------------------------------
6089 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6090   if (must_be_exact()) return this;  // cannot clear xk
6091   ciKlass* k = _klass;
6092   const Type* elem = this->elem();
6093   if (elem->isa_klassptr() && !klass_is_exact) {
6094     elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
6095   }
6096   return make(klass_is_exact ? Constant : NotNull, elem, k, _offset);
6097 }
6098 
6099 
6100 //-----------------------------as_instance_type--------------------------------
6101 // Corresponding type for an instance of the given class.
6102 // It will be NotNull, and exact if and only if the klass type is exact.
6103 const TypeOopPtr* TypeAryKlassPtr::as_instance_type(bool klass_change) const {
6104   ciKlass* k = klass();
6105   bool    xk = klass_is_exact();
6106   const Type* el = NULL;
6107   if (elem()->isa_klassptr()) {
6108     el = elem()->is_klassptr()->as_instance_type(false)->cast_to_exactness(false);
6109     k = NULL;
6110   } else {
6111     el = elem();
6112   }
6113   return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS), k, xk, 0);
6114 }
6115 
6116 
6117 //------------------------------xmeet------------------------------------------
6118 // Compute the MEET of two types, return a new Type object.
6119 const Type    *TypeAryKlassPtr::xmeet( const Type *t ) const {
6120   // Perform a fast test for common case; meeting the same types together.
6121   if( this == t ) return this;  // Meeting same type-rep?
6122 
6123   // Current "this->_base" is Pointer
6124   switch (t->base()) {          // switch on original type
6125 
6126   case Int:                     // Mixing ints & oops happens when javac
6127   case Long:                    // reuses local variables
6128   case FloatTop:
6129   case FloatCon:
6130   case FloatBot:
6131   case DoubleTop:
6132   case DoubleCon:
6133   case DoubleBot:
6134   case NarrowOop:
6135   case NarrowKlass:
6136   case Bottom:                  // Ye Olde Default
6137     return Type::BOTTOM;
6138   case Top:
6139     return this;
6140 
6141   default:                      // All else is a mistake
6142     typerr(t);
6143 
6144   case AnyPtr: {                // Meeting to AnyPtrs
6145     // Found an AnyPtr type vs self-KlassPtr type
6146     const TypePtr *tp = t->is_ptr();
6147     int offset = meet_offset(tp->offset());
6148     PTR ptr = meet_ptr(tp->ptr());
6149     switch (tp->ptr()) {
6150     case TopPTR:
6151       return this;
6152     case Null:
6153       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6154     case AnyNull:
6155       return make( ptr, _elem, klass(), offset );
6156     case BotPTR:
6157     case NotNull:
6158       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6159     default: typerr(t);
6160     }
6161   }
6162 
6163   case RawPtr:
6164   case MetadataPtr:
6165   case OopPtr:
6166   case AryPtr:                  // Meet with AryPtr
6167   case InstPtr:                 // Meet with InstPtr
6168     return TypePtr::BOTTOM;
6169 
6170   //
6171   //             A-top         }
6172   //           /   |   \       }  Tops
6173   //       B-top A-any C-top   }
6174   //          | /  |  \ |      }  Any-nulls
6175   //       B-any   |   C-any   }
6176   //          |    |    |
6177   //       B-con A-con C-con   } constants; not comparable across classes
6178   //          |    |    |
6179   //       B-not   |   C-not   }
6180   //          | \  |  / |      }  not-nulls
6181   //       B-bot A-not C-bot   }
6182   //           \   |   /       }  Bottoms
6183   //             A-bot         }
6184   //
6185 
6186   case AryKlassPtr: {  // Meet two KlassPtr types
6187     const TypeAryKlassPtr *tap = t->is_aryklassptr();
6188     int off = meet_offset(tap->offset());
6189     const Type* elem = _elem->meet(tap->_elem);
6190 
6191     PTR ptr = meet_ptr(tap->ptr());
6192     ciKlass* res_klass = NULL;
6193     bool res_xk = false;
6194     meet_aryptr(ptr, elem, this, tap, res_klass, res_xk);
6195     assert(res_xk == (ptr == Constant), "");
6196     return make(ptr, elem, res_klass, off);
6197   } // End of case KlassPtr
6198   case InstKlassPtr: {
6199     const TypeInstKlassPtr *tp = t->is_instklassptr();
6200     int offset = meet_offset(tp->offset());
6201     PTR ptr = meet_ptr(tp->ptr());
6202     InterfaceSet interfaces = meet_interfaces(tp);
6203     InterfaceSet tp_interfaces = tp->_interfaces;
6204     InterfaceSet this_interfaces = _interfaces;
6205 
6206     switch (ptr) {
6207     case TopPTR:
6208     case AnyNull:                // Fall 'down' to dual of object klass
6209       // For instances when a subclass meets a superclass we fall
6210       // below the centerline when the superclass is exact. We need to
6211       // do the same here.
6212       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces.intersection_with(tp_interfaces).eq(tp_interfaces) && !tp->klass_is_exact()) {
6213         return TypeAryKlassPtr::make(ptr, _elem, _klass, offset);
6214       } else {
6215         // cannot subclass, so the meet has to fall badly below the centerline
6216         ptr = NotNull;
6217         interfaces = this_interfaces.intersection_with(tp->_interfaces);
6218         return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
6219       }
6220     case Constant:
6221     case NotNull:
6222     case BotPTR:                // Fall down to object klass
6223       // LCA is object_klass, but if we subclass from the top we can do better
6224       if (above_centerline(tp->ptr())) {
6225         // If 'tp'  is above the centerline and it is Object class
6226         // then we can subclass in the Java class hierarchy.
6227         // For instances when a subclass meets a superclass we fall
6228         // below the centerline when the superclass is exact. We need
6229         // to do the same here.
6230         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces.intersection_with(tp_interfaces).eq(tp_interfaces) && !tp->klass_is_exact()) {
6231           // that is, my array type is a subtype of 'tp' klass
6232           return make(ptr, _elem, _klass, offset);
6233         }
6234       }
6235       // The other case cannot happen, since t cannot be a subtype of an array.
6236       // The meet falls down to Object class below centerline.
6237       if (ptr == Constant)
6238          ptr = NotNull;
6239       interfaces = this_interfaces.intersection_with(tp_interfaces);
6240       return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
6241     default: typerr(t);
6242     }
6243   }
6244 
6245   } // End of switch
6246   return this;                  // Return the double constant
6247 }
6248 
6249 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) {
6250   static_assert(std::is_base_of<T2, T1>::value, "");
6251 
6252   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces.empty() && other_exact) {
6253     return true;
6254   }
6255 
6256   int dummy;
6257   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6258 
6259   if (!this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
6260     return false;
6261   }
6262 
6263   if (this_one->is_instance_type(other)) {
6264     return other->klass() == ciEnv::current()->Object_klass() && other->_interfaces.intersection_with(this_one->_interfaces).eq(other->_interfaces) && other_exact;
6265   }
6266 
6267   assert(this_one->is_array_type(other), "");
6268   const T1* other_ary = this_one->is_array_type(other);
6269   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
6270   if (other_top_or_bottom) {
6271     return false;
6272   }
6273 
6274   const TypePtr* other_elem = other_ary->elem()->make_ptr();
6275   const TypePtr* this_elem = this_one->elem()->make_ptr();
6276   if (this_elem != NULL && other_elem != NULL) {
6277     return this_one->is_reference_type(this_elem)->is_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6278   }
6279   if (this_elem == NULL && other_elem == NULL) {
6280     return this_one->_klass->is_subtype_of(other->_klass);
6281   }
6282   return false;
6283 }
6284 
6285 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6286   return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6287 }
6288 
6289 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other) {
6290   static_assert(std::is_base_of<T2, T1>::value, "");
6291 
6292   int dummy;
6293   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6294 
6295   if (!this_one->is_array_type(other) ||
6296       !this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
6297     return false;
6298   }
6299   const T1* other_ary = this_one->is_array_type(other);
6300   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
6301 
6302   if (other_top_or_bottom) {
6303     return false;
6304   }
6305 
6306   const TypePtr* other_elem = other_ary->elem()->make_ptr();
6307   const TypePtr* this_elem = this_one->elem()->make_ptr();
6308   if (other_elem != NULL && this_elem != NULL) {
6309     return this_one->is_reference_type(this_elem)->is_same_java_type_as(this_one->is_reference_type(other_elem));
6310   }
6311   if (other_elem == NULL && this_elem == NULL) {
6312     assert(this_one->_klass != NULL && other->_klass != NULL, "");
6313     return this_one->_klass->equals(other->_klass);
6314   }
6315   return false;
6316 }
6317 
6318 bool TypeAryKlassPtr::is_same_java_type_as_helper(const TypeKlassPtr* other) const {
6319   return TypePtr::is_same_java_type_as_helper_for_array(this, other);
6320 }
6321 
6322 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) {
6323   static_assert(std::is_base_of<T2, T1>::value, "");
6324   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces.empty() && other_exact) {
6325     return true;
6326   }
6327   int dummy;
6328   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6329   if (!this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
6330     return true;
6331   }
6332   if (this_one->is_instance_type(other)) {
6333     return other->_klass->equals(ciEnv::current()->Object_klass()) && other->_interfaces.intersection_with(this_one->_interfaces).eq(other->_interfaces);
6334   }
6335   assert(this_one->is_array_type(other), "");
6336 
6337   const T1* other_ary = this_one->is_array_type(other);
6338   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
6339   if (other_top_or_bottom) {
6340     return true;
6341   }
6342   if (this_exact && other_exact) {
6343     return this_one->is_java_subtype_of(other);
6344   }
6345 
6346   const TypePtr* this_elem = this_one->elem()->make_ptr();
6347   const TypePtr* other_elem = other_ary->elem()->make_ptr();
6348   if (other_elem != NULL && this_elem != NULL) {
6349     return this_one->is_reference_type(this_elem)->maybe_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6350   }
6351   if (other_elem == NULL && this_elem == NULL) {
6352     return this_one->_klass->is_subtype_of(other->_klass);
6353   }
6354   return false;
6355 }
6356 
6357 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6358   return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6359 }
6360 
6361 //------------------------------xdual------------------------------------------
6362 // Dual: compute field-by-field dual
6363 const Type    *TypeAryKlassPtr::xdual() const {
6364   return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset());
6365 }
6366 
6367 // Is there a single ciKlass* that can represent that type?
6368 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
6369   if (elem()->isa_klassptr()) {
6370     ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
6371     if (k == NULL) {
6372       return NULL;
6373     }
6374     k = ciObjArrayKlass::make(k);
6375     return k;
6376   }
6377 
6378   return klass();
6379 }
6380 
6381 ciKlass* TypeAryKlassPtr::klass() const {
6382   if (_klass != NULL) {
6383     return _klass;
6384   }
6385   ciKlass* k = NULL;
6386   if (elem()->isa_klassptr()) {
6387     // leave NULL
6388   } else if ((elem()->base() == Type::Top) ||
6389              (elem()->base() == Type::Bottom)) {
6390   } else {
6391     k = ciTypeArrayKlass::make(elem()->basic_type());
6392     ((TypeAryKlassPtr*)this)->_klass = k;
6393   }
6394   return k;
6395 }
6396 
6397 //------------------------------dump2------------------------------------------
6398 // Dump Klass Type
6399 #ifndef PRODUCT
6400 void TypeAryKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
6401   switch( _ptr ) {
6402   case Constant:
6403     st->print("precise ");
6404   case NotNull:
6405     {
6406       st->print("[");
6407       _elem->dump2(d, depth, st);
6408       _interfaces.dump(st);
6409       st->print(": ");
6410     }
6411   case BotPTR:
6412     if( !WizardMode && !Verbose && _ptr != Constant ) break;
6413   case TopPTR:
6414   case AnyNull:
6415     st->print(":%s", ptr_msg[_ptr]);
6416     if( _ptr == Constant ) st->print(":exact");
6417     break;
6418   default:
6419     break;
6420   }
6421 
6422   if( _offset ) {               // Dump offset, if any
6423     if( _offset == OffsetBot )      { st->print("+any"); }
6424     else if( _offset == OffsetTop ) { st->print("+unknown"); }
6425     else                            { st->print("+%d", _offset); }
6426   }
6427 
6428   st->print(" *");
6429 }
6430 #endif
6431 
6432 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
6433   const Type* elem = this->elem();
6434   dims = 1;
6435   while (elem->isa_aryklassptr()) {
6436     elem = elem->is_aryklassptr()->elem();
6437     dims++;
6438   }
6439   return elem;
6440 }
6441 
6442 //=============================================================================
6443 // Convenience common pre-built types.
6444 
6445 //------------------------------make-------------------------------------------
6446 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
6447   return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();
6448 }
6449 
6450 //------------------------------make-------------------------------------------
6451 const TypeFunc *TypeFunc::make(ciMethod* method) {
6452   Compile* C = Compile::current();
6453   const TypeFunc* tf = C->last_tf(method); // check cache
6454   if (tf != NULL)  return tf;  // The hit rate here is almost 50%.
6455   const TypeTuple *domain;
6456   if (method->is_static()) {
6457     domain = TypeTuple::make_domain(NULL, method->signature(), ignore_interfaces);
6458   } else {
6459     domain = TypeTuple::make_domain(method->holder(), method->signature(), ignore_interfaces);
6460   }
6461   const TypeTuple *range  = TypeTuple::make_range(method->signature(), ignore_interfaces);
6462   tf = TypeFunc::make(domain, range);
6463   C->set_last_tf(method, tf);  // fill cache
6464   return tf;
6465 }
6466 
6467 //------------------------------meet-------------------------------------------
6468 // Compute the MEET of two types.  It returns a new Type object.
6469 const Type *TypeFunc::xmeet( const Type *t ) const {
6470   // Perform a fast test for common case; meeting the same types together.
6471   if( this == t ) return this;  // Meeting same type-rep?
6472 
6473   // Current "this->_base" is Func
6474   switch (t->base()) {          // switch on original type
6475 
6476   case Bottom:                  // Ye Olde Default
6477     return t;
6478 
6479   default:                      // All else is a mistake
6480     typerr(t);
6481 
6482   case Top:
6483     break;
6484   }
6485   return this;                  // Return the double constant
6486 }
6487 
6488 //------------------------------xdual------------------------------------------
6489 // Dual: compute field-by-field dual
6490 const Type *TypeFunc::xdual() const {
6491   return this;
6492 }
6493 
6494 //------------------------------eq---------------------------------------------
6495 // Structural equality check for Type representations
6496 bool TypeFunc::eq( const Type *t ) const {
6497   const TypeFunc *a = (const TypeFunc*)t;
6498   return _domain == a->_domain &&
6499     _range == a->_range;
6500 }
6501 
6502 //------------------------------hash-------------------------------------------
6503 // Type-specific hashing function.
6504 int TypeFunc::hash(void) const {
6505   return (intptr_t)_domain + (intptr_t)_range;
6506 }
6507 
6508 //------------------------------dump2------------------------------------------
6509 // Dump Function Type
6510 #ifndef PRODUCT
6511 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
6512   if( _range->cnt() <= Parms )
6513     st->print("void");
6514   else {
6515     uint i;
6516     for (i = Parms; i < _range->cnt()-1; i++) {
6517       _range->field_at(i)->dump2(d,depth,st);
6518       st->print("/");
6519     }
6520     _range->field_at(i)->dump2(d,depth,st);
6521   }
6522   st->print(" ");
6523   st->print("( ");
6524   if( !depth || d[this] ) {     // Check for recursive dump
6525     st->print("...)");
6526     return;
6527   }
6528   d.Insert((void*)this,(void*)this);    // Stop recursion
6529   if (Parms < _domain->cnt())
6530     _domain->field_at(Parms)->dump2(d,depth-1,st);
6531   for (uint i = Parms+1; i < _domain->cnt(); i++) {
6532     st->print(", ");
6533     _domain->field_at(i)->dump2(d,depth-1,st);
6534   }
6535   st->print(" )");
6536 }
6537 #endif
6538 
6539 //------------------------------singleton--------------------------------------
6540 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
6541 // constants (Ldi nodes).  Singletons are integer, float or double constants
6542 // or a single symbol.
6543 bool TypeFunc::singleton(void) const {
6544   return false;                 // Never a singleton
6545 }
6546 
6547 bool TypeFunc::empty(void) const {
6548   return false;                 // Never empty
6549 }
6550 
6551 
6552 BasicType TypeFunc::return_type() const{
6553   if (range()->cnt() == TypeFunc::Parms) {
6554     return T_VOID;
6555   }
6556   return range()->field_at(TypeFunc::Parms)->basic_type();
6557 }
--- EOF ---