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