1 /*
   2  * Copyright (c) 1997, 2021, 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->klass()->is_interface();
 795     bool    t_interface =    t_inst->klass()->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 #endif
1154 
1155 //------------------------------typerr-----------------------------------------
1156 void Type::typerr( const Type *t ) const {
1157 #ifndef PRODUCT
1158   tty->print("\nError mixing types: ");
1159   dump();
1160   tty->print(" and ");
1161   t->dump();
1162   tty->print("\n");
1163 #endif
1164   ShouldNotReachHere();
1165 }
1166 
1167 
1168 //=============================================================================
1169 // Convenience common pre-built types.
1170 const TypeF *TypeF::MAX;        // Floating point max
1171 const TypeF *TypeF::MIN;        // Floating point min
1172 const TypeF *TypeF::ZERO;       // Floating point zero
1173 const TypeF *TypeF::ONE;        // Floating point one
1174 const TypeF *TypeF::POS_INF;    // Floating point positive infinity
1175 const TypeF *TypeF::NEG_INF;    // Floating point negative infinity
1176 
1177 //------------------------------make-------------------------------------------
1178 // Create a float constant
1179 const TypeF *TypeF::make(float f) {
1180   return (TypeF*)(new TypeF(f))->hashcons();
1181 }
1182 
1183 //------------------------------meet-------------------------------------------
1184 // Compute the MEET of two types.  It returns a new Type object.
1185 const Type *TypeF::xmeet( const Type *t ) const {
1186   // Perform a fast test for common case; meeting the same types together.
1187   if( this == t ) return this;  // Meeting same type-rep?
1188 
1189   // Current "this->_base" is FloatCon
1190   switch (t->base()) {          // Switch on original type
1191   case AnyPtr:                  // Mixing with oops happens when javac
1192   case RawPtr:                  // reuses local variables
1193   case OopPtr:
1194   case InstPtr:
1195   case AryPtr:
1196   case MetadataPtr:
1197   case KlassPtr:
1198   case InstKlassPtr:
1199   case AryKlassPtr:
1200   case NarrowOop:
1201   case NarrowKlass:
1202   case Int:
1203   case Long:
1204   case DoubleTop:
1205   case DoubleCon:
1206   case DoubleBot:
1207   case Bottom:                  // Ye Olde Default
1208     return Type::BOTTOM;
1209 
1210   case FloatBot:
1211     return t;
1212 
1213   default:                      // All else is a mistake
1214     typerr(t);
1215 
1216   case FloatCon:                // Float-constant vs Float-constant?
1217     if( jint_cast(_f) != jint_cast(t->getf()) )         // unequal constants?
1218                                 // must compare bitwise as positive zero, negative zero and NaN have
1219                                 // all the same representation in C++
1220       return FLOAT;             // Return generic float
1221                                 // Equal constants
1222   case Top:
1223   case FloatTop:
1224     break;                      // Return the float constant
1225   }
1226   return this;                  // Return the float constant
1227 }
1228 
1229 //------------------------------xdual------------------------------------------
1230 // Dual: symmetric
1231 const Type *TypeF::xdual() const {
1232   return this;
1233 }
1234 
1235 //------------------------------eq---------------------------------------------
1236 // Structural equality check for Type representations
1237 bool TypeF::eq(const Type *t) const {
1238   // Bitwise comparison to distinguish between +/-0. These values must be treated
1239   // as different to be consistent with C1 and the interpreter.
1240   return (jint_cast(_f) == jint_cast(t->getf()));
1241 }
1242 
1243 //------------------------------hash-------------------------------------------
1244 // Type-specific hashing function.
1245 int TypeF::hash(void) const {
1246   return *(int*)(&_f);
1247 }
1248 
1249 //------------------------------is_finite--------------------------------------
1250 // Has a finite value
1251 bool TypeF::is_finite() const {
1252   return g_isfinite(getf()) != 0;
1253 }
1254 
1255 //------------------------------is_nan-----------------------------------------
1256 // Is not a number (NaN)
1257 bool TypeF::is_nan()    const {
1258   return g_isnan(getf()) != 0;
1259 }
1260 
1261 //------------------------------dump2------------------------------------------
1262 // Dump float constant Type
1263 #ifndef PRODUCT
1264 void TypeF::dump2( Dict &d, uint depth, outputStream *st ) const {
1265   Type::dump2(d,depth, st);
1266   st->print("%f", _f);
1267 }
1268 #endif
1269 
1270 //------------------------------singleton--------------------------------------
1271 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
1272 // constants (Ldi nodes).  Singletons are integer, float or double constants
1273 // or a single symbol.
1274 bool TypeF::singleton(void) const {
1275   return true;                  // Always a singleton
1276 }
1277 
1278 bool TypeF::empty(void) const {
1279   return false;                 // always exactly a singleton
1280 }
1281 
1282 //=============================================================================
1283 // Convenience common pre-built types.
1284 const TypeD *TypeD::MAX;        // Floating point max
1285 const TypeD *TypeD::MIN;        // Floating point min
1286 const TypeD *TypeD::ZERO;       // Floating point zero
1287 const TypeD *TypeD::ONE;        // Floating point one
1288 const TypeD *TypeD::POS_INF;    // Floating point positive infinity
1289 const TypeD *TypeD::NEG_INF;    // Floating point negative infinity
1290 
1291 //------------------------------make-------------------------------------------
1292 const TypeD *TypeD::make(double d) {
1293   return (TypeD*)(new TypeD(d))->hashcons();
1294 }
1295 
1296 //------------------------------meet-------------------------------------------
1297 // Compute the MEET of two types.  It returns a new Type object.
1298 const Type *TypeD::xmeet( const Type *t ) const {
1299   // Perform a fast test for common case; meeting the same types together.
1300   if( this == t ) return this;  // Meeting same type-rep?
1301 
1302   // Current "this->_base" is DoubleCon
1303   switch (t->base()) {          // Switch on original type
1304   case AnyPtr:                  // Mixing with oops happens when javac
1305   case RawPtr:                  // reuses local variables
1306   case OopPtr:
1307   case InstPtr:
1308   case AryPtr:
1309   case MetadataPtr:
1310   case KlassPtr:
1311   case InstKlassPtr:
1312   case AryKlassPtr:
1313   case NarrowOop:
1314   case NarrowKlass:
1315   case Int:
1316   case Long:
1317   case FloatTop:
1318   case FloatCon:
1319   case FloatBot:
1320   case Bottom:                  // Ye Olde Default
1321     return Type::BOTTOM;
1322 
1323   case DoubleBot:
1324     return t;
1325 
1326   default:                      // All else is a mistake
1327     typerr(t);
1328 
1329   case DoubleCon:               // Double-constant vs Double-constant?
1330     if( jlong_cast(_d) != jlong_cast(t->getd()) )       // unequal constants? (see comment in TypeF::xmeet)
1331       return DOUBLE;            // Return generic double
1332   case Top:
1333   case DoubleTop:
1334     break;
1335   }
1336   return this;                  // Return the double constant
1337 }
1338 
1339 //------------------------------xdual------------------------------------------
1340 // Dual: symmetric
1341 const Type *TypeD::xdual() const {
1342   return this;
1343 }
1344 
1345 //------------------------------eq---------------------------------------------
1346 // Structural equality check for Type representations
1347 bool TypeD::eq(const Type *t) const {
1348   // Bitwise comparison to distinguish between +/-0. These values must be treated
1349   // as different to be consistent with C1 and the interpreter.
1350   return (jlong_cast(_d) == jlong_cast(t->getd()));
1351 }
1352 
1353 //------------------------------hash-------------------------------------------
1354 // Type-specific hashing function.
1355 int TypeD::hash(void) const {
1356   return *(int*)(&_d);
1357 }
1358 
1359 //------------------------------is_finite--------------------------------------
1360 // Has a finite value
1361 bool TypeD::is_finite() const {
1362   return g_isfinite(getd()) != 0;
1363 }
1364 
1365 //------------------------------is_nan-----------------------------------------
1366 // Is not a number (NaN)
1367 bool TypeD::is_nan()    const {
1368   return g_isnan(getd()) != 0;
1369 }
1370 
1371 //------------------------------dump2------------------------------------------
1372 // Dump double constant Type
1373 #ifndef PRODUCT
1374 void TypeD::dump2( Dict &d, uint depth, outputStream *st ) const {
1375   Type::dump2(d,depth,st);
1376   st->print("%f", _d);
1377 }
1378 #endif
1379 
1380 //------------------------------singleton--------------------------------------
1381 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
1382 // constants (Ldi nodes).  Singletons are integer, float or double constants
1383 // or a single symbol.
1384 bool TypeD::singleton(void) const {
1385   return true;                  // Always a singleton
1386 }
1387 
1388 bool TypeD::empty(void) const {
1389   return false;                 // always exactly a singleton
1390 }
1391 
1392 const TypeInteger* TypeInteger::make(jlong lo, jlong hi, int w, BasicType bt) {
1393   if (bt == T_INT) {
1394     return TypeInt::make(checked_cast<jint>(lo), checked_cast<jint>(hi), w);
1395   }
1396   assert(bt == T_LONG, "basic type not an int or long");
1397   return TypeLong::make(lo, hi, w);
1398 }
1399 
1400 jlong TypeInteger::get_con_as_long(BasicType bt) const {
1401   if (bt == T_INT) {
1402     return is_int()->get_con();
1403   }
1404   assert(bt == T_LONG, "basic type not an int or long");
1405   return is_long()->get_con();
1406 }
1407 
1408 const TypeInteger* TypeInteger::bottom(BasicType bt) {
1409   if (bt == T_INT) {
1410     return TypeInt::INT;
1411   }
1412   assert(bt == T_LONG, "basic type not an int or long");
1413   return TypeLong::LONG;
1414 }
1415 
1416 //=============================================================================
1417 // Convience common pre-built types.
1418 const TypeInt *TypeInt::MAX;    // INT_MAX
1419 const TypeInt *TypeInt::MIN;    // INT_MIN
1420 const TypeInt *TypeInt::MINUS_1;// -1
1421 const TypeInt *TypeInt::ZERO;   // 0
1422 const TypeInt *TypeInt::ONE;    // 1
1423 const TypeInt *TypeInt::BOOL;   // 0 or 1, FALSE or TRUE.
1424 const TypeInt *TypeInt::CC;     // -1,0 or 1, condition codes
1425 const TypeInt *TypeInt::CC_LT;  // [-1]  == MINUS_1
1426 const TypeInt *TypeInt::CC_GT;  // [1]   == ONE
1427 const TypeInt *TypeInt::CC_EQ;  // [0]   == ZERO
1428 const TypeInt *TypeInt::CC_LE;  // [-1,0]
1429 const TypeInt *TypeInt::CC_GE;  // [0,1] == BOOL (!)
1430 const TypeInt *TypeInt::BYTE;   // Bytes, -128 to 127
1431 const TypeInt *TypeInt::UBYTE;  // Unsigned Bytes, 0 to 255
1432 const TypeInt *TypeInt::CHAR;   // Java chars, 0-65535
1433 const TypeInt *TypeInt::SHORT;  // Java shorts, -32768-32767
1434 const TypeInt *TypeInt::POS;    // Positive 32-bit integers or zero
1435 const TypeInt *TypeInt::POS1;   // Positive 32-bit integers
1436 const TypeInt *TypeInt::INT;    // 32-bit integers
1437 const TypeInt *TypeInt::SYMINT; // symmetric range [-max_jint..max_jint]
1438 const TypeInt *TypeInt::TYPE_DOMAIN; // alias for TypeInt::INT
1439 
1440 //------------------------------TypeInt----------------------------------------
1441 TypeInt::TypeInt( jint lo, jint hi, int w ) : TypeInteger(Int), _lo(lo), _hi(hi), _widen(w) {
1442 }
1443 
1444 //------------------------------make-------------------------------------------
1445 const TypeInt *TypeInt::make( jint lo ) {
1446   return (TypeInt*)(new TypeInt(lo,lo,WidenMin))->hashcons();
1447 }
1448 
1449 static int normalize_int_widen( jint lo, jint hi, int w ) {
1450   // Certain normalizations keep us sane when comparing types.
1451   // The 'SMALLINT' covers constants and also CC and its relatives.
1452   if (lo <= hi) {
1453     if (((juint)hi - lo) <= SMALLINT)  w = Type::WidenMin;
1454     if (((juint)hi - lo) >= max_juint) w = Type::WidenMax; // TypeInt::INT
1455   } else {
1456     if (((juint)lo - hi) <= SMALLINT)  w = Type::WidenMin;
1457     if (((juint)lo - hi) >= max_juint) w = Type::WidenMin; // dual TypeInt::INT
1458   }
1459   return w;
1460 }
1461 
1462 const TypeInt *TypeInt::make( jint lo, jint hi, int w ) {
1463   w = normalize_int_widen(lo, hi, w);
1464   return (TypeInt*)(new TypeInt(lo,hi,w))->hashcons();
1465 }
1466 
1467 //------------------------------meet-------------------------------------------
1468 // Compute the MEET of two types.  It returns a new Type representation object
1469 // with reference count equal to the number of Types pointing at it.
1470 // Caller should wrap a Types around it.
1471 const Type *TypeInt::xmeet( const Type *t ) const {
1472   // Perform a fast test for common case; meeting the same types together.
1473   if( this == t ) return this;  // Meeting same type?
1474 
1475   // Currently "this->_base" is a TypeInt
1476   switch (t->base()) {          // Switch on original type
1477   case AnyPtr:                  // Mixing with oops happens when javac
1478   case RawPtr:                  // reuses local variables
1479   case OopPtr:
1480   case InstPtr:
1481   case AryPtr:
1482   case MetadataPtr:
1483   case KlassPtr:
1484   case InstKlassPtr:
1485   case AryKlassPtr:
1486   case NarrowOop:
1487   case NarrowKlass:
1488   case Long:
1489   case FloatTop:
1490   case FloatCon:
1491   case FloatBot:
1492   case DoubleTop:
1493   case DoubleCon:
1494   case DoubleBot:
1495   case Bottom:                  // Ye Olde Default
1496     return Type::BOTTOM;
1497   default:                      // All else is a mistake
1498     typerr(t);
1499   case Top:                     // No change
1500     return this;
1501   case Int:                     // Int vs Int?
1502     break;
1503   }
1504 
1505   // Expand covered set
1506   const TypeInt *r = t->is_int();
1507   return make( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) );
1508 }
1509 
1510 //------------------------------xdual------------------------------------------
1511 // Dual: reverse hi & lo; flip widen
1512 const Type *TypeInt::xdual() const {
1513   int w = normalize_int_widen(_hi,_lo, WidenMax-_widen);
1514   return new TypeInt(_hi,_lo,w);
1515 }
1516 
1517 //------------------------------widen------------------------------------------
1518 // Only happens for optimistic top-down optimizations.
1519 const Type *TypeInt::widen( const Type *old, const Type* limit ) const {
1520   // Coming from TOP or such; no widening
1521   if( old->base() != Int ) return this;
1522   const TypeInt *ot = old->is_int();
1523 
1524   // If new guy is equal to old guy, no widening
1525   if( _lo == ot->_lo && _hi == ot->_hi )
1526     return old;
1527 
1528   // If new guy contains old, then we widened
1529   if( _lo <= ot->_lo && _hi >= ot->_hi ) {
1530     // New contains old
1531     // If new guy is already wider than old, no widening
1532     if( _widen > ot->_widen ) return this;
1533     // If old guy was a constant, do not bother
1534     if (ot->_lo == ot->_hi)  return this;
1535     // Now widen new guy.
1536     // Check for widening too far
1537     if (_widen == WidenMax) {
1538       int max = max_jint;
1539       int min = min_jint;
1540       if (limit->isa_int()) {
1541         max = limit->is_int()->_hi;
1542         min = limit->is_int()->_lo;
1543       }
1544       if (min < _lo && _hi < max) {
1545         // If neither endpoint is extremal yet, push out the endpoint
1546         // which is closer to its respective limit.
1547         if (_lo >= 0 ||                 // easy common case
1548             (juint)(_lo - min) >= (juint)(max - _hi)) {
1549           // Try to widen to an unsigned range type of 31 bits:
1550           return make(_lo, max, WidenMax);
1551         } else {
1552           return make(min, _hi, WidenMax);
1553         }
1554       }
1555       return TypeInt::INT;
1556     }
1557     // Returned widened new guy
1558     return make(_lo,_hi,_widen+1);
1559   }
1560 
1561   // If old guy contains new, then we probably widened too far & dropped to
1562   // bottom.  Return the wider fellow.
1563   if ( ot->_lo <= _lo && ot->_hi >= _hi )
1564     return old;
1565 
1566   //fatal("Integer value range is not subset");
1567   //return this;
1568   return TypeInt::INT;
1569 }
1570 
1571 //------------------------------narrow---------------------------------------
1572 // Only happens for pessimistic optimizations.
1573 const Type *TypeInt::narrow( const Type *old ) const {
1574   if (_lo >= _hi)  return this;   // already narrow enough
1575   if (old == NULL)  return this;
1576   const TypeInt* ot = old->isa_int();
1577   if (ot == NULL)  return this;
1578   jint olo = ot->_lo;
1579   jint ohi = ot->_hi;
1580 
1581   // If new guy is equal to old guy, no narrowing
1582   if (_lo == olo && _hi == ohi)  return old;
1583 
1584   // If old guy was maximum range, allow the narrowing
1585   if (olo == min_jint && ohi == max_jint)  return this;
1586 
1587   if (_lo < olo || _hi > ohi)
1588     return this;                // doesn't narrow; pretty wierd
1589 
1590   // The new type narrows the old type, so look for a "death march".
1591   // See comments on PhaseTransform::saturate.
1592   juint nrange = (juint)_hi - _lo;
1593   juint orange = (juint)ohi - olo;
1594   if (nrange < max_juint - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
1595     // Use the new type only if the range shrinks a lot.
1596     // We do not want the optimizer computing 2^31 point by point.
1597     return old;
1598   }
1599 
1600   return this;
1601 }
1602 
1603 //-----------------------------filter------------------------------------------
1604 const Type *TypeInt::filter_helper(const Type *kills, bool include_speculative) const {
1605   const TypeInt* ft = join_helper(kills, include_speculative)->isa_int();
1606   if (ft == NULL || ft->empty())
1607     return Type::TOP;           // Canonical empty value
1608   if (ft->_widen < this->_widen) {
1609     // Do not allow the value of kill->_widen to affect the outcome.
1610     // The widen bits must be allowed to run freely through the graph.
1611     ft = TypeInt::make(ft->_lo, ft->_hi, this->_widen);
1612   }
1613   return ft;
1614 }
1615 
1616 //------------------------------eq---------------------------------------------
1617 // Structural equality check for Type representations
1618 bool TypeInt::eq( const Type *t ) const {
1619   const TypeInt *r = t->is_int(); // Handy access
1620   return r->_lo == _lo && r->_hi == _hi && r->_widen == _widen;
1621 }
1622 
1623 //------------------------------hash-------------------------------------------
1624 // Type-specific hashing function.
1625 int TypeInt::hash(void) const {
1626   return java_add(java_add(_lo, _hi), java_add((jint)_widen, (jint)Type::Int));
1627 }
1628 
1629 //------------------------------is_finite--------------------------------------
1630 // Has a finite value
1631 bool TypeInt::is_finite() const {
1632   return true;
1633 }
1634 
1635 //------------------------------dump2------------------------------------------
1636 // Dump TypeInt
1637 #ifndef PRODUCT
1638 static const char* intname(char* buf, jint n) {
1639   if (n == min_jint)
1640     return "min";
1641   else if (n < min_jint + 10000)
1642     sprintf(buf, "min+" INT32_FORMAT, n - min_jint);
1643   else if (n == max_jint)
1644     return "max";
1645   else if (n > max_jint - 10000)
1646     sprintf(buf, "max-" INT32_FORMAT, max_jint - n);
1647   else
1648     sprintf(buf, INT32_FORMAT, n);
1649   return buf;
1650 }
1651 
1652 void TypeInt::dump2( Dict &d, uint depth, outputStream *st ) const {
1653   char buf[40], buf2[40];
1654   if (_lo == min_jint && _hi == max_jint)
1655     st->print("int");
1656   else if (is_con())
1657     st->print("int:%s", intname(buf, get_con()));
1658   else if (_lo == BOOL->_lo && _hi == BOOL->_hi)
1659     st->print("bool");
1660   else if (_lo == BYTE->_lo && _hi == BYTE->_hi)
1661     st->print("byte");
1662   else if (_lo == CHAR->_lo && _hi == CHAR->_hi)
1663     st->print("char");
1664   else if (_lo == SHORT->_lo && _hi == SHORT->_hi)
1665     st->print("short");
1666   else if (_hi == max_jint)
1667     st->print("int:>=%s", intname(buf, _lo));
1668   else if (_lo == min_jint)
1669     st->print("int:<=%s", intname(buf, _hi));
1670   else
1671     st->print("int:%s..%s", intname(buf, _lo), intname(buf2, _hi));
1672 
1673   if (_widen != 0 && this != TypeInt::INT)
1674     st->print(":%.*s", _widen, "wwww");
1675 }
1676 #endif
1677 
1678 //------------------------------singleton--------------------------------------
1679 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
1680 // constants.
1681 bool TypeInt::singleton(void) const {
1682   return _lo >= _hi;
1683 }
1684 
1685 bool TypeInt::empty(void) const {
1686   return _lo > _hi;
1687 }
1688 
1689 //=============================================================================
1690 // Convenience common pre-built types.
1691 const TypeLong *TypeLong::MAX;
1692 const TypeLong *TypeLong::MIN;
1693 const TypeLong *TypeLong::MINUS_1;// -1
1694 const TypeLong *TypeLong::ZERO; // 0
1695 const TypeLong *TypeLong::ONE;  // 1
1696 const TypeLong *TypeLong::POS;  // >=0
1697 const TypeLong *TypeLong::LONG; // 64-bit integers
1698 const TypeLong *TypeLong::INT;  // 32-bit subrange
1699 const TypeLong *TypeLong::UINT; // 32-bit unsigned subrange
1700 const TypeLong *TypeLong::TYPE_DOMAIN; // alias for TypeLong::LONG
1701 
1702 //------------------------------TypeLong---------------------------------------
1703 TypeLong::TypeLong(jlong lo, jlong hi, int w) : TypeInteger(Long), _lo(lo), _hi(hi), _widen(w) {
1704 }
1705 
1706 //------------------------------make-------------------------------------------
1707 const TypeLong *TypeLong::make( jlong lo ) {
1708   return (TypeLong*)(new TypeLong(lo,lo,WidenMin))->hashcons();
1709 }
1710 
1711 static int normalize_long_widen( jlong lo, jlong hi, int w ) {
1712   // Certain normalizations keep us sane when comparing types.
1713   // The 'SMALLINT' covers constants.
1714   if (lo <= hi) {
1715     if (((julong)hi - lo) <= SMALLINT)   w = Type::WidenMin;
1716     if (((julong)hi - lo) >= max_julong) w = Type::WidenMax; // TypeLong::LONG
1717   } else {
1718     if (((julong)lo - hi) <= SMALLINT)   w = Type::WidenMin;
1719     if (((julong)lo - hi) >= max_julong) w = Type::WidenMin; // dual TypeLong::LONG
1720   }
1721   return w;
1722 }
1723 
1724 const TypeLong *TypeLong::make( jlong lo, jlong hi, int w ) {
1725   w = normalize_long_widen(lo, hi, w);
1726   return (TypeLong*)(new TypeLong(lo,hi,w))->hashcons();
1727 }
1728 
1729 
1730 //------------------------------meet-------------------------------------------
1731 // Compute the MEET of two types.  It returns a new Type representation object
1732 // with reference count equal to the number of Types pointing at it.
1733 // Caller should wrap a Types around it.
1734 const Type *TypeLong::xmeet( const Type *t ) const {
1735   // Perform a fast test for common case; meeting the same types together.
1736   if( this == t ) return this;  // Meeting same type?
1737 
1738   // Currently "this->_base" is a TypeLong
1739   switch (t->base()) {          // Switch on original type
1740   case AnyPtr:                  // Mixing with oops happens when javac
1741   case RawPtr:                  // reuses local variables
1742   case OopPtr:
1743   case InstPtr:
1744   case AryPtr:
1745   case MetadataPtr:
1746   case KlassPtr:
1747   case InstKlassPtr:
1748   case AryKlassPtr:
1749   case NarrowOop:
1750   case NarrowKlass:
1751   case Int:
1752   case FloatTop:
1753   case FloatCon:
1754   case FloatBot:
1755   case DoubleTop:
1756   case DoubleCon:
1757   case DoubleBot:
1758   case Bottom:                  // Ye Olde Default
1759     return Type::BOTTOM;
1760   default:                      // All else is a mistake
1761     typerr(t);
1762   case Top:                     // No change
1763     return this;
1764   case Long:                    // Long vs Long?
1765     break;
1766   }
1767 
1768   // Expand covered set
1769   const TypeLong *r = t->is_long(); // Turn into a TypeLong
1770   return make( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) );
1771 }
1772 
1773 //------------------------------xdual------------------------------------------
1774 // Dual: reverse hi & lo; flip widen
1775 const Type *TypeLong::xdual() const {
1776   int w = normalize_long_widen(_hi,_lo, WidenMax-_widen);
1777   return new TypeLong(_hi,_lo,w);
1778 }
1779 
1780 //------------------------------widen------------------------------------------
1781 // Only happens for optimistic top-down optimizations.
1782 const Type *TypeLong::widen( const Type *old, const Type* limit ) const {
1783   // Coming from TOP or such; no widening
1784   if( old->base() != Long ) return this;
1785   const TypeLong *ot = old->is_long();
1786 
1787   // If new guy is equal to old guy, no widening
1788   if( _lo == ot->_lo && _hi == ot->_hi )
1789     return old;
1790 
1791   // If new guy contains old, then we widened
1792   if( _lo <= ot->_lo && _hi >= ot->_hi ) {
1793     // New contains old
1794     // If new guy is already wider than old, no widening
1795     if( _widen > ot->_widen ) return this;
1796     // If old guy was a constant, do not bother
1797     if (ot->_lo == ot->_hi)  return this;
1798     // Now widen new guy.
1799     // Check for widening too far
1800     if (_widen == WidenMax) {
1801       jlong max = max_jlong;
1802       jlong min = min_jlong;
1803       if (limit->isa_long()) {
1804         max = limit->is_long()->_hi;
1805         min = limit->is_long()->_lo;
1806       }
1807       if (min < _lo && _hi < max) {
1808         // If neither endpoint is extremal yet, push out the endpoint
1809         // which is closer to its respective limit.
1810         if (_lo >= 0 ||                 // easy common case
1811             ((julong)_lo - min) >= ((julong)max - _hi)) {
1812           // Try to widen to an unsigned range type of 32/63 bits:
1813           if (max >= max_juint && _hi < max_juint)
1814             return make(_lo, max_juint, WidenMax);
1815           else
1816             return make(_lo, max, WidenMax);
1817         } else {
1818           return make(min, _hi, WidenMax);
1819         }
1820       }
1821       return TypeLong::LONG;
1822     }
1823     // Returned widened new guy
1824     return make(_lo,_hi,_widen+1);
1825   }
1826 
1827   // If old guy contains new, then we probably widened too far & dropped to
1828   // bottom.  Return the wider fellow.
1829   if ( ot->_lo <= _lo && ot->_hi >= _hi )
1830     return old;
1831 
1832   //  fatal("Long value range is not subset");
1833   // return this;
1834   return TypeLong::LONG;
1835 }
1836 
1837 //------------------------------narrow----------------------------------------
1838 // Only happens for pessimistic optimizations.
1839 const Type *TypeLong::narrow( const Type *old ) const {
1840   if (_lo >= _hi)  return this;   // already narrow enough
1841   if (old == NULL)  return this;
1842   const TypeLong* ot = old->isa_long();
1843   if (ot == NULL)  return this;
1844   jlong olo = ot->_lo;
1845   jlong ohi = ot->_hi;
1846 
1847   // If new guy is equal to old guy, no narrowing
1848   if (_lo == olo && _hi == ohi)  return old;
1849 
1850   // If old guy was maximum range, allow the narrowing
1851   if (olo == min_jlong && ohi == max_jlong)  return this;
1852 
1853   if (_lo < olo || _hi > ohi)
1854     return this;                // doesn't narrow; pretty wierd
1855 
1856   // The new type narrows the old type, so look for a "death march".
1857   // See comments on PhaseTransform::saturate.
1858   julong nrange = _hi - _lo;
1859   julong orange = ohi - olo;
1860   if (nrange < max_julong - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
1861     // Use the new type only if the range shrinks a lot.
1862     // We do not want the optimizer computing 2^31 point by point.
1863     return old;
1864   }
1865 
1866   return this;
1867 }
1868 
1869 //-----------------------------filter------------------------------------------
1870 const Type *TypeLong::filter_helper(const Type *kills, bool include_speculative) const {
1871   const TypeLong* ft = join_helper(kills, include_speculative)->isa_long();
1872   if (ft == NULL || ft->empty())
1873     return Type::TOP;           // Canonical empty value
1874   if (ft->_widen < this->_widen) {
1875     // Do not allow the value of kill->_widen to affect the outcome.
1876     // The widen bits must be allowed to run freely through the graph.
1877     ft = TypeLong::make(ft->_lo, ft->_hi, this->_widen);
1878   }
1879   return ft;
1880 }
1881 
1882 //------------------------------eq---------------------------------------------
1883 // Structural equality check for Type representations
1884 bool TypeLong::eq( const Type *t ) const {
1885   const TypeLong *r = t->is_long(); // Handy access
1886   return r->_lo == _lo &&  r->_hi == _hi  && r->_widen == _widen;
1887 }
1888 
1889 //------------------------------hash-------------------------------------------
1890 // Type-specific hashing function.
1891 int TypeLong::hash(void) const {
1892   return (int)(_lo+_hi+_widen+(int)Type::Long);
1893 }
1894 
1895 //------------------------------is_finite--------------------------------------
1896 // Has a finite value
1897 bool TypeLong::is_finite() const {
1898   return true;
1899 }
1900 
1901 //------------------------------dump2------------------------------------------
1902 // Dump TypeLong
1903 #ifndef PRODUCT
1904 static const char* longnamenear(jlong x, const char* xname, char* buf, jlong n) {
1905   if (n > x) {
1906     if (n >= x + 10000)  return NULL;
1907     sprintf(buf, "%s+" JLONG_FORMAT, xname, n - x);
1908   } else if (n < x) {
1909     if (n <= x - 10000)  return NULL;
1910     sprintf(buf, "%s-" JLONG_FORMAT, xname, x - n);
1911   } else {
1912     return xname;
1913   }
1914   return buf;
1915 }
1916 
1917 static const char* longname(char* buf, jlong n) {
1918   const char* str;
1919   if (n == min_jlong)
1920     return "min";
1921   else if (n < min_jlong + 10000)
1922     sprintf(buf, "min+" JLONG_FORMAT, n - min_jlong);
1923   else if (n == max_jlong)
1924     return "max";
1925   else if (n > max_jlong - 10000)
1926     sprintf(buf, "max-" JLONG_FORMAT, max_jlong - n);
1927   else if ((str = longnamenear(max_juint, "maxuint", buf, n)) != NULL)
1928     return str;
1929   else if ((str = longnamenear(max_jint, "maxint", buf, n)) != NULL)
1930     return str;
1931   else if ((str = longnamenear(min_jint, "minint", buf, n)) != NULL)
1932     return str;
1933   else
1934     sprintf(buf, JLONG_FORMAT, n);
1935   return buf;
1936 }
1937 
1938 void TypeLong::dump2( Dict &d, uint depth, outputStream *st ) const {
1939   char buf[80], buf2[80];
1940   if (_lo == min_jlong && _hi == max_jlong)
1941     st->print("long");
1942   else if (is_con())
1943     st->print("long:%s", longname(buf, get_con()));
1944   else if (_hi == max_jlong)
1945     st->print("long:>=%s", longname(buf, _lo));
1946   else if (_lo == min_jlong)
1947     st->print("long:<=%s", longname(buf, _hi));
1948   else
1949     st->print("long:%s..%s", longname(buf, _lo), longname(buf2, _hi));
1950 
1951   if (_widen != 0 && this != TypeLong::LONG)
1952     st->print(":%.*s", _widen, "wwww");
1953 }
1954 #endif
1955 
1956 //------------------------------singleton--------------------------------------
1957 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
1958 // constants
1959 bool TypeLong::singleton(void) const {
1960   return _lo >= _hi;
1961 }
1962 
1963 bool TypeLong::empty(void) const {
1964   return _lo > _hi;
1965 }
1966 
1967 //=============================================================================
1968 // Convenience common pre-built types.
1969 const TypeTuple *TypeTuple::IFBOTH;     // Return both arms of IF as reachable
1970 const TypeTuple *TypeTuple::IFFALSE;
1971 const TypeTuple *TypeTuple::IFTRUE;
1972 const TypeTuple *TypeTuple::IFNEITHER;
1973 const TypeTuple *TypeTuple::LOOPBODY;
1974 const TypeTuple *TypeTuple::MEMBAR;
1975 const TypeTuple *TypeTuple::STORECONDITIONAL;
1976 const TypeTuple *TypeTuple::START_I2C;
1977 const TypeTuple *TypeTuple::INT_PAIR;
1978 const TypeTuple *TypeTuple::LONG_PAIR;
1979 const TypeTuple *TypeTuple::INT_CC_PAIR;
1980 const TypeTuple *TypeTuple::LONG_CC_PAIR;
1981 
1982 //------------------------------make-------------------------------------------
1983 // Make a TypeTuple from the range of a method signature
1984 const TypeTuple *TypeTuple::make_range(ciSignature* sig) {
1985   ciType* return_type = sig->return_type();
1986   uint arg_cnt = return_type->size();
1987   const Type **field_array = fields(arg_cnt);
1988   switch (return_type->basic_type()) {
1989   case T_LONG:
1990     field_array[TypeFunc::Parms]   = TypeLong::LONG;
1991     field_array[TypeFunc::Parms+1] = Type::HALF;
1992     break;
1993   case T_DOUBLE:
1994     field_array[TypeFunc::Parms]   = Type::DOUBLE;
1995     field_array[TypeFunc::Parms+1] = Type::HALF;
1996     break;
1997   case T_OBJECT:
1998   case T_ARRAY:
1999   case T_BOOLEAN:
2000   case T_CHAR:
2001   case T_FLOAT:
2002   case T_BYTE:
2003   case T_SHORT:
2004   case T_INT:
2005     field_array[TypeFunc::Parms] = get_const_type(return_type);
2006     break;
2007   case T_VOID:
2008     break;
2009   default:
2010     ShouldNotReachHere();
2011   }
2012   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2013 }
2014 
2015 // Make a TypeTuple from the domain of a method signature
2016 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig) {
2017   uint arg_cnt = sig->size();
2018 
2019   uint pos = TypeFunc::Parms;
2020   const Type **field_array;
2021   if (recv != NULL) {
2022     arg_cnt++;
2023     field_array = fields(arg_cnt);
2024     // Use get_const_type here because it respects UseUniqueSubclasses:
2025     field_array[pos++] = get_const_type(recv)->join_speculative(TypePtr::NOTNULL);
2026   } else {
2027     field_array = fields(arg_cnt);
2028   }
2029 
2030   int i = 0;
2031   while (pos < TypeFunc::Parms + arg_cnt) {
2032     ciType* type = sig->type_at(i);
2033 
2034     switch (type->basic_type()) {
2035     case T_LONG:
2036       field_array[pos++] = TypeLong::LONG;
2037       field_array[pos++] = Type::HALF;
2038       break;
2039     case T_DOUBLE:
2040       field_array[pos++] = Type::DOUBLE;
2041       field_array[pos++] = Type::HALF;
2042       break;
2043     case T_OBJECT:
2044     case T_ARRAY:
2045     case T_FLOAT:
2046     case T_INT:
2047       field_array[pos++] = get_const_type(type);
2048       break;
2049     case T_BOOLEAN:
2050     case T_CHAR:
2051     case T_BYTE:
2052     case T_SHORT:
2053       field_array[pos++] = TypeInt::INT;
2054       break;
2055     default:
2056       ShouldNotReachHere();
2057     }
2058     i++;
2059   }
2060 
2061   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2062 }
2063 
2064 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2065   return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2066 }
2067 
2068 //------------------------------fields-----------------------------------------
2069 // Subroutine call type with space allocated for argument types
2070 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
2071 const Type **TypeTuple::fields( uint arg_cnt ) {
2072   const Type **flds = (const Type **)(Compile::current()->type_arena()->AmallocWords((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
2073   flds[TypeFunc::Control  ] = Type::CONTROL;
2074   flds[TypeFunc::I_O      ] = Type::ABIO;
2075   flds[TypeFunc::Memory   ] = Type::MEMORY;
2076   flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
2077   flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
2078 
2079   return flds;
2080 }
2081 
2082 //------------------------------meet-------------------------------------------
2083 // Compute the MEET of two types.  It returns a new Type object.
2084 const Type *TypeTuple::xmeet( const Type *t ) const {
2085   // Perform a fast test for common case; meeting the same types together.
2086   if( this == t ) return this;  // Meeting same type-rep?
2087 
2088   // Current "this->_base" is Tuple
2089   switch (t->base()) {          // switch on original type
2090 
2091   case Bottom:                  // Ye Olde Default
2092     return t;
2093 
2094   default:                      // All else is a mistake
2095     typerr(t);
2096 
2097   case Tuple: {                 // Meeting 2 signatures?
2098     const TypeTuple *x = t->is_tuple();
2099     assert( _cnt == x->_cnt, "" );
2100     const Type **fields = (const Type **)(Compile::current()->type_arena()->AmallocWords( _cnt*sizeof(Type*) ));
2101     for( uint i=0; i<_cnt; i++ )
2102       fields[i] = field_at(i)->xmeet( x->field_at(i) );
2103     return TypeTuple::make(_cnt,fields);
2104   }
2105   case Top:
2106     break;
2107   }
2108   return this;                  // Return the double constant
2109 }
2110 
2111 //------------------------------xdual------------------------------------------
2112 // Dual: compute field-by-field dual
2113 const Type *TypeTuple::xdual() const {
2114   const Type **fields = (const Type **)(Compile::current()->type_arena()->AmallocWords( _cnt*sizeof(Type*) ));
2115   for( uint i=0; i<_cnt; i++ )
2116     fields[i] = _fields[i]->dual();
2117   return new TypeTuple(_cnt,fields);
2118 }
2119 
2120 //------------------------------eq---------------------------------------------
2121 // Structural equality check for Type representations
2122 bool TypeTuple::eq( const Type *t ) const {
2123   const TypeTuple *s = (const TypeTuple *)t;
2124   if (_cnt != s->_cnt)  return false;  // Unequal field counts
2125   for (uint i = 0; i < _cnt; i++)
2126     if (field_at(i) != s->field_at(i)) // POINTER COMPARE!  NO RECURSION!
2127       return false;             // Missed
2128   return true;
2129 }
2130 
2131 //------------------------------hash-------------------------------------------
2132 // Type-specific hashing function.
2133 int TypeTuple::hash(void) const {
2134   intptr_t sum = _cnt;
2135   for( uint i=0; i<_cnt; i++ )
2136     sum += (intptr_t)_fields[i];     // Hash on pointers directly
2137   return sum;
2138 }
2139 
2140 //------------------------------dump2------------------------------------------
2141 // Dump signature Type
2142 #ifndef PRODUCT
2143 void TypeTuple::dump2( Dict &d, uint depth, outputStream *st ) const {
2144   st->print("{");
2145   if( !depth || d[this] ) {     // Check for recursive print
2146     st->print("...}");
2147     return;
2148   }
2149   d.Insert((void*)this, (void*)this);   // Stop recursion
2150   if( _cnt ) {
2151     uint i;
2152     for( i=0; i<_cnt-1; i++ ) {
2153       st->print("%d:", i);
2154       _fields[i]->dump2(d, depth-1, st);
2155       st->print(", ");
2156     }
2157     st->print("%d:", i);
2158     _fields[i]->dump2(d, depth-1, st);
2159   }
2160   st->print("}");
2161 }
2162 #endif
2163 
2164 //------------------------------singleton--------------------------------------
2165 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2166 // constants (Ldi nodes).  Singletons are integer, float or double constants
2167 // or a single symbol.
2168 bool TypeTuple::singleton(void) const {
2169   return false;                 // Never a singleton
2170 }
2171 
2172 bool TypeTuple::empty(void) const {
2173   for( uint i=0; i<_cnt; i++ ) {
2174     if (_fields[i]->empty())  return true;
2175   }
2176   return false;
2177 }
2178 
2179 //=============================================================================
2180 // Convenience common pre-built types.
2181 
2182 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2183   // Certain normalizations keep us sane when comparing types.
2184   // We do not want arrayOop variables to differ only by the wideness
2185   // of their index types.  Pick minimum wideness, since that is the
2186   // forced wideness of small ranges anyway.
2187   if (size->_widen != Type::WidenMin)
2188     return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2189   else
2190     return size;
2191 }
2192 
2193 //------------------------------make-------------------------------------------
2194 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable) {
2195   if (UseCompressedOops && elem->isa_oopptr()) {
2196     elem = elem->make_narrowoop();
2197   }
2198   size = normalize_array_size(size);
2199   return (TypeAry*)(new TypeAry(elem,size,stable))->hashcons();
2200 }
2201 
2202 //------------------------------meet-------------------------------------------
2203 // Compute the MEET of two types.  It returns a new Type object.
2204 const Type *TypeAry::xmeet( const Type *t ) const {
2205   // Perform a fast test for common case; meeting the same types together.
2206   if( this == t ) return this;  // Meeting same type-rep?
2207 
2208   // Current "this->_base" is Ary
2209   switch (t->base()) {          // switch on original type
2210 
2211   case Bottom:                  // Ye Olde Default
2212     return t;
2213 
2214   default:                      // All else is a mistake
2215     typerr(t);
2216 
2217   case Array: {                 // Meeting 2 arrays?
2218     const TypeAry *a = t->is_ary();
2219     return TypeAry::make(_elem->meet_speculative(a->_elem),
2220                          _size->xmeet(a->_size)->is_int(),
2221                          _stable && a->_stable);
2222   }
2223   case Top:
2224     break;
2225   }
2226   return this;                  // Return the double constant
2227 }
2228 
2229 //------------------------------xdual------------------------------------------
2230 // Dual: compute field-by-field dual
2231 const Type *TypeAry::xdual() const {
2232   const TypeInt* size_dual = _size->dual()->is_int();
2233   size_dual = normalize_array_size(size_dual);
2234   return new TypeAry(_elem->dual(), size_dual, !_stable);
2235 }
2236 
2237 //------------------------------eq---------------------------------------------
2238 // Structural equality check for Type representations
2239 bool TypeAry::eq( const Type *t ) const {
2240   const TypeAry *a = (const TypeAry*)t;
2241   return _elem == a->_elem &&
2242     _stable == a->_stable &&
2243     _size == a->_size;
2244 }
2245 
2246 //------------------------------hash-------------------------------------------
2247 // Type-specific hashing function.
2248 int TypeAry::hash(void) const {
2249   return (intptr_t)_elem + (intptr_t)_size + (_stable ? 43 : 0);
2250 }
2251 
2252 /**
2253  * Return same type without a speculative part in the element
2254  */
2255 const Type* TypeAry::remove_speculative() const {
2256   return make(_elem->remove_speculative(), _size, _stable);
2257 }
2258 
2259 /**
2260  * Return same type with cleaned up speculative part of element
2261  */
2262 const Type* TypeAry::cleanup_speculative() const {
2263   return make(_elem->cleanup_speculative(), _size, _stable);
2264 }
2265 
2266 /**
2267  * Return same type but with a different inline depth (used for speculation)
2268  *
2269  * @param depth  depth to meet with
2270  */
2271 const TypePtr* TypePtr::with_inline_depth(int depth) const {
2272   if (!UseInlineDepthForSpeculativeTypes) {
2273     return this;
2274   }
2275   return make(AnyPtr, _ptr, _offset, _speculative, depth);
2276 }
2277 
2278 //----------------------interface_vs_oop---------------------------------------
2279 #ifdef ASSERT
2280 bool TypeAry::interface_vs_oop(const Type *t) const {
2281   const TypeAry* t_ary = t->is_ary();
2282   if (t_ary) {
2283     const TypePtr* this_ptr = _elem->make_ptr(); // In case we have narrow_oops
2284     const TypePtr*    t_ptr = t_ary->_elem->make_ptr();
2285     if(this_ptr != NULL && t_ptr != NULL) {
2286       return this_ptr->interface_vs_oop(t_ptr);
2287     }
2288   }
2289   return false;
2290 }
2291 #endif
2292 
2293 //------------------------------dump2------------------------------------------
2294 #ifndef PRODUCT
2295 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2296   if (_stable)  st->print("stable:");
2297   _elem->dump2(d, depth, st);
2298   st->print("[");
2299   _size->dump2(d, depth, st);
2300   st->print("]");
2301 }
2302 #endif
2303 
2304 //------------------------------singleton--------------------------------------
2305 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2306 // constants (Ldi nodes).  Singletons are integer, float or double constants
2307 // or a single symbol.
2308 bool TypeAry::singleton(void) const {
2309   return false;                 // Never a singleton
2310 }
2311 
2312 bool TypeAry::empty(void) const {
2313   return _elem->empty() || _size->empty();
2314 }
2315 
2316 //--------------------------ary_must_be_exact----------------------------------
2317 bool TypeAry::ary_must_be_exact() const {
2318   // This logic looks at the element type of an array, and returns true
2319   // if the element type is either a primitive or a final instance class.
2320   // In such cases, an array built on this ary must have no subclasses.
2321   if (_elem == BOTTOM)      return false;  // general array not exact
2322   if (_elem == TOP   )      return false;  // inverted general array not exact
2323   const TypeOopPtr*  toop = NULL;
2324   if (UseCompressedOops && _elem->isa_narrowoop()) {
2325     toop = _elem->make_ptr()->isa_oopptr();
2326   } else {
2327     toop = _elem->isa_oopptr();
2328   }
2329   if (!toop)                return true;   // a primitive type, like int
2330   ciKlass* tklass = toop->klass();
2331   if (tklass == NULL)       return false;  // unloaded class
2332   if (!tklass->is_loaded()) return false;  // unloaded class
2333   const TypeInstPtr* tinst;
2334   if (_elem->isa_narrowoop())
2335     tinst = _elem->make_ptr()->isa_instptr();
2336   else
2337     tinst = _elem->isa_instptr();
2338   if (tinst)
2339     return tklass->as_instance_klass()->is_final();
2340   const TypeAryPtr*  tap;
2341   if (_elem->isa_narrowoop())
2342     tap = _elem->make_ptr()->isa_aryptr();
2343   else
2344     tap = _elem->isa_aryptr();
2345   if (tap)
2346     return tap->ary()->ary_must_be_exact();
2347   return false;
2348 }
2349 
2350 //==============================TypeVect=======================================
2351 // Convenience common pre-built types.
2352 const TypeVect *TypeVect::VECTA = NULL; // vector length agnostic
2353 const TypeVect *TypeVect::VECTS = NULL; //  32-bit vectors
2354 const TypeVect *TypeVect::VECTD = NULL; //  64-bit vectors
2355 const TypeVect *TypeVect::VECTX = NULL; // 128-bit vectors
2356 const TypeVect *TypeVect::VECTY = NULL; // 256-bit vectors
2357 const TypeVect *TypeVect::VECTZ = NULL; // 512-bit vectors
2358 const TypeVect *TypeVect::VECTMASK = NULL; // predicate/mask vector
2359 
2360 //------------------------------make-------------------------------------------
2361 const TypeVect* TypeVect::make(const Type *elem, uint length, bool is_mask) {
2362   if (is_mask) {
2363     return makemask(elem, length);
2364   }
2365   BasicType elem_bt = elem->array_element_basic_type();
2366   assert(is_java_primitive(elem_bt), "only primitive types in vector");
2367   assert(Matcher::vector_size_supported(elem_bt, length), "length in range");
2368   int size = length * type2aelembytes(elem_bt);
2369   switch (Matcher::vector_ideal_reg(size)) {
2370   case Op_VecA:
2371     return (TypeVect*)(new TypeVectA(elem, length))->hashcons();
2372   case Op_VecS:
2373     return (TypeVect*)(new TypeVectS(elem, length))->hashcons();
2374   case Op_RegL:
2375   case Op_VecD:
2376   case Op_RegD:
2377     return (TypeVect*)(new TypeVectD(elem, length))->hashcons();
2378   case Op_VecX:
2379     return (TypeVect*)(new TypeVectX(elem, length))->hashcons();
2380   case Op_VecY:
2381     return (TypeVect*)(new TypeVectY(elem, length))->hashcons();
2382   case Op_VecZ:
2383     return (TypeVect*)(new TypeVectZ(elem, length))->hashcons();
2384   }
2385  ShouldNotReachHere();
2386   return NULL;
2387 }
2388 
2389 const TypeVect *TypeVect::makemask(const Type* elem, uint length) {
2390   BasicType elem_bt = elem->array_element_basic_type();
2391   if (Matcher::has_predicated_vectors() &&
2392       Matcher::match_rule_supported_vector_masked(Op_VectorLoadMask, length, elem_bt)) {
2393     const TypeVect* mtype = Matcher::predicate_reg_type(elem, length);
2394     return (TypeVect*)(const_cast<TypeVect*>(mtype))->hashcons();
2395   } else {
2396     return make(elem, length);
2397   }
2398 }
2399 
2400 //------------------------------meet-------------------------------------------
2401 // Compute the MEET of two types.  It returns a new Type object.
2402 const Type *TypeVect::xmeet( const Type *t ) const {
2403   // Perform a fast test for common case; meeting the same types together.
2404   if( this == t ) return this;  // Meeting same type-rep?
2405 
2406   // Current "this->_base" is Vector
2407   switch (t->base()) {          // switch on original type
2408 
2409   case Bottom:                  // Ye Olde Default
2410     return t;
2411 
2412   default:                      // All else is a mistake
2413     typerr(t);
2414   case VectorMask: {
2415     const TypeVectMask* v = t->is_vectmask();
2416     assert(  base() == v->base(), "");
2417     assert(length() == v->length(), "");
2418     assert(element_basic_type() == v->element_basic_type(), "");
2419     return TypeVect::makemask(_elem->xmeet(v->_elem), _length);
2420   }
2421   case VectorA:
2422   case VectorS:
2423   case VectorD:
2424   case VectorX:
2425   case VectorY:
2426   case VectorZ: {                // Meeting 2 vectors?
2427     const TypeVect* v = t->is_vect();
2428     assert(  base() == v->base(), "");
2429     assert(length() == v->length(), "");
2430     assert(element_basic_type() == v->element_basic_type(), "");
2431     return TypeVect::make(_elem->xmeet(v->_elem), _length);
2432   }
2433   case Top:
2434     break;
2435   }
2436   return this;
2437 }
2438 
2439 //------------------------------xdual------------------------------------------
2440 // Dual: compute field-by-field dual
2441 const Type *TypeVect::xdual() const {
2442   return new TypeVect(base(), _elem->dual(), _length);
2443 }
2444 
2445 //------------------------------eq---------------------------------------------
2446 // Structural equality check for Type representations
2447 bool TypeVect::eq(const Type *t) const {
2448   const TypeVect *v = t->is_vect();
2449   return (_elem == v->_elem) && (_length == v->_length);
2450 }
2451 
2452 //------------------------------hash-------------------------------------------
2453 // Type-specific hashing function.
2454 int TypeVect::hash(void) const {
2455   return (intptr_t)_elem + (intptr_t)_length;
2456 }
2457 
2458 //------------------------------singleton--------------------------------------
2459 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2460 // constants (Ldi nodes).  Vector is singleton if all elements are the same
2461 // constant value (when vector is created with Replicate code).
2462 bool TypeVect::singleton(void) const {
2463 // There is no Con node for vectors yet.
2464 //  return _elem->singleton();
2465   return false;
2466 }
2467 
2468 bool TypeVect::empty(void) const {
2469   return _elem->empty();
2470 }
2471 
2472 //------------------------------dump2------------------------------------------
2473 #ifndef PRODUCT
2474 void TypeVect::dump2(Dict &d, uint depth, outputStream *st) const {
2475   switch (base()) {
2476   case VectorA:
2477     st->print("vectora["); break;
2478   case VectorS:
2479     st->print("vectors["); break;
2480   case VectorD:
2481     st->print("vectord["); break;
2482   case VectorX:
2483     st->print("vectorx["); break;
2484   case VectorY:
2485     st->print("vectory["); break;
2486   case VectorZ:
2487     st->print("vectorz["); break;
2488   case VectorMask:
2489     st->print("vectormask["); break;
2490   default:
2491     ShouldNotReachHere();
2492   }
2493   st->print("%d]:{", _length);
2494   _elem->dump2(d, depth, st);
2495   st->print("}");
2496 }
2497 #endif
2498 
2499 bool TypeVectMask::eq(const Type *t) const {
2500   const TypeVectMask *v = t->is_vectmask();
2501   return (element_type() == v->element_type()) && (length() == v->length());
2502 }
2503 
2504 const Type *TypeVectMask::xdual() const {
2505   return new TypeVectMask(element_type()->dual(), length());
2506 }
2507 
2508 //=============================================================================
2509 // Convenience common pre-built types.
2510 const TypePtr *TypePtr::NULL_PTR;
2511 const TypePtr *TypePtr::NOTNULL;
2512 const TypePtr *TypePtr::BOTTOM;
2513 
2514 //------------------------------meet-------------------------------------------
2515 // Meet over the PTR enum
2516 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2517   //              TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,
2518   { /* Top     */ TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,},
2519   { /* AnyNull */ AnyNull,   AnyNull,   Constant, BotPTR, NotNull, BotPTR,},
2520   { /* Constant*/ Constant,  Constant,  Constant, BotPTR, NotNull, BotPTR,},
2521   { /* Null    */ Null,      BotPTR,    BotPTR,   Null,   BotPTR,  BotPTR,},
2522   { /* NotNull */ NotNull,   NotNull,   NotNull,  BotPTR, NotNull, BotPTR,},
2523   { /* BotPTR  */ BotPTR,    BotPTR,    BotPTR,   BotPTR, BotPTR,  BotPTR,}
2524 };
2525 
2526 //------------------------------make-------------------------------------------
2527 const TypePtr *TypePtr::make(TYPES t, enum PTR ptr, int offset, const TypePtr* speculative, int inline_depth) {
2528   return (TypePtr*)(new TypePtr(t,ptr,offset, speculative, inline_depth))->hashcons();
2529 }
2530 
2531 //------------------------------cast_to_ptr_type-------------------------------
2532 const Type *TypePtr::cast_to_ptr_type(PTR ptr) const {
2533   assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2534   if( ptr == _ptr ) return this;
2535   return make(_base, ptr, _offset, _speculative, _inline_depth);
2536 }
2537 
2538 //------------------------------get_con----------------------------------------
2539 intptr_t TypePtr::get_con() const {
2540   assert( _ptr == Null, "" );
2541   return _offset;
2542 }
2543 
2544 //------------------------------meet-------------------------------------------
2545 // Compute the MEET of two types.  It returns a new Type object.
2546 const Type *TypePtr::xmeet(const Type *t) const {
2547   const Type* res = xmeet_helper(t);
2548   if (res->isa_ptr() == NULL) {
2549     return res;
2550   }
2551 
2552   const TypePtr* res_ptr = res->is_ptr();
2553   if (res_ptr->speculative() != NULL) {
2554     // type->speculative() == NULL means that speculation is no better
2555     // than type, i.e. type->speculative() == type. So there are 2
2556     // ways to represent the fact that we have no useful speculative
2557     // data and we should use a single one to be able to test for
2558     // equality between types. Check whether type->speculative() ==
2559     // type and set speculative to NULL if it is the case.
2560     if (res_ptr->remove_speculative() == res_ptr->speculative()) {
2561       return res_ptr->remove_speculative();
2562     }
2563   }
2564 
2565   return res;
2566 }
2567 
2568 const Type *TypePtr::xmeet_helper(const Type *t) const {
2569   // Perform a fast test for common case; meeting the same types together.
2570   if( this == t ) return this;  // Meeting same type-rep?
2571 
2572   // Current "this->_base" is AnyPtr
2573   switch (t->base()) {          // switch on original type
2574   case Int:                     // Mixing ints & oops happens when javac
2575   case Long:                    // reuses local variables
2576   case FloatTop:
2577   case FloatCon:
2578   case FloatBot:
2579   case DoubleTop:
2580   case DoubleCon:
2581   case DoubleBot:
2582   case NarrowOop:
2583   case NarrowKlass:
2584   case Bottom:                  // Ye Olde Default
2585     return Type::BOTTOM;
2586   case Top:
2587     return this;
2588 
2589   case AnyPtr: {                // Meeting to AnyPtrs
2590     const TypePtr *tp = t->is_ptr();
2591     const TypePtr* speculative = xmeet_speculative(tp);
2592     int depth = meet_inline_depth(tp->inline_depth());
2593     return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2594   }
2595   case RawPtr:                  // For these, flip the call around to cut down
2596   case OopPtr:
2597   case InstPtr:                 // on the cases I have to handle.
2598   case AryPtr:
2599   case MetadataPtr:
2600   case KlassPtr:
2601   case InstKlassPtr:
2602   case AryKlassPtr:
2603     return t->xmeet(this);      // Call in reverse direction
2604   default:                      // All else is a mistake
2605     typerr(t);
2606 
2607   }
2608   return this;
2609 }
2610 
2611 //------------------------------meet_offset------------------------------------
2612 int TypePtr::meet_offset( int offset ) const {
2613   // Either is 'TOP' offset?  Return the other offset!
2614   if( _offset == OffsetTop ) return offset;
2615   if( offset == OffsetTop ) return _offset;
2616   // If either is different, return 'BOTTOM' offset
2617   if( _offset != offset ) return OffsetBot;
2618   return _offset;
2619 }
2620 
2621 //------------------------------dual_offset------------------------------------
2622 int TypePtr::dual_offset( ) const {
2623   if( _offset == OffsetTop ) return OffsetBot;// Map 'TOP' into 'BOTTOM'
2624   if( _offset == OffsetBot ) return OffsetTop;// Map 'BOTTOM' into 'TOP'
2625   return _offset;               // Map everything else into self
2626 }
2627 
2628 //------------------------------xdual------------------------------------------
2629 // Dual: compute field-by-field dual
2630 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2631   BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2632 };
2633 const Type *TypePtr::xdual() const {
2634   return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
2635 }
2636 
2637 //------------------------------xadd_offset------------------------------------
2638 int TypePtr::xadd_offset( intptr_t offset ) const {
2639   // Adding to 'TOP' offset?  Return 'TOP'!
2640   if( _offset == OffsetTop || offset == OffsetTop ) return OffsetTop;
2641   // Adding to 'BOTTOM' offset?  Return 'BOTTOM'!
2642   if( _offset == OffsetBot || offset == OffsetBot ) return OffsetBot;
2643   // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
2644   offset += (intptr_t)_offset;
2645   if (offset != (int)offset || offset == OffsetTop) return OffsetBot;
2646 
2647   // assert( _offset >= 0 && _offset+offset >= 0, "" );
2648   // It is possible to construct a negative offset during PhaseCCP
2649 
2650   return (int)offset;        // Sum valid offsets
2651 }
2652 
2653 //------------------------------add_offset-------------------------------------
2654 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2655   return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth);
2656 }
2657 
2658 //------------------------------eq---------------------------------------------
2659 // Structural equality check for Type representations
2660 bool TypePtr::eq( const Type *t ) const {
2661   const TypePtr *a = (const TypePtr*)t;
2662   return _ptr == a->ptr() && _offset == a->offset() && eq_speculative(a) && _inline_depth == a->_inline_depth;
2663 }
2664 
2665 //------------------------------hash-------------------------------------------
2666 // Type-specific hashing function.
2667 int TypePtr::hash(void) const {
2668   return java_add(java_add((jint)_ptr, (jint)_offset), java_add((jint)hash_speculative(), (jint)_inline_depth));
2669 ;
2670 }
2671 
2672 /**
2673  * Return same type without a speculative part
2674  */
2675 const Type* TypePtr::remove_speculative() const {
2676   if (_speculative == NULL) {
2677     return this;
2678   }
2679   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2680   return make(AnyPtr, _ptr, _offset, NULL, _inline_depth);
2681 }
2682 
2683 /**
2684  * Return same type but drop speculative part if we know we won't use
2685  * it
2686  */
2687 const Type* TypePtr::cleanup_speculative() const {
2688   if (speculative() == NULL) {
2689     return this;
2690   }
2691   const Type* no_spec = remove_speculative();
2692   // If this is NULL_PTR then we don't need the speculative type
2693   // (with_inline_depth in case the current type inline depth is
2694   // InlineDepthTop)
2695   if (no_spec == NULL_PTR->with_inline_depth(inline_depth())) {
2696     return no_spec;
2697   }
2698   if (above_centerline(speculative()->ptr())) {
2699     return no_spec;
2700   }
2701   const TypeOopPtr* spec_oopptr = speculative()->isa_oopptr();
2702   // If the speculative may be null and is an inexact klass then it
2703   // doesn't help
2704   if (speculative() != TypePtr::NULL_PTR && speculative()->maybe_null() &&
2705       (spec_oopptr == NULL || !spec_oopptr->klass_is_exact())) {
2706     return no_spec;
2707   }
2708   return this;
2709 }
2710 
2711 /**
2712  * dual of the speculative part of the type
2713  */
2714 const TypePtr* TypePtr::dual_speculative() const {
2715   if (_speculative == NULL) {
2716     return NULL;
2717   }
2718   return _speculative->dual()->is_ptr();
2719 }
2720 
2721 /**
2722  * meet of the speculative parts of 2 types
2723  *
2724  * @param other  type to meet with
2725  */
2726 const TypePtr* TypePtr::xmeet_speculative(const TypePtr* other) const {
2727   bool this_has_spec = (_speculative != NULL);
2728   bool other_has_spec = (other->speculative() != NULL);
2729 
2730   if (!this_has_spec && !other_has_spec) {
2731     return NULL;
2732   }
2733 
2734   // If we are at a point where control flow meets and one branch has
2735   // a speculative type and the other has not, we meet the speculative
2736   // type of one branch with the actual type of the other. If the
2737   // actual type is exact and the speculative is as well, then the
2738   // result is a speculative type which is exact and we can continue
2739   // speculation further.
2740   const TypePtr* this_spec = _speculative;
2741   const TypePtr* other_spec = other->speculative();
2742 
2743   if (!this_has_spec) {
2744     this_spec = this;
2745   }
2746 
2747   if (!other_has_spec) {
2748     other_spec = other;
2749   }
2750 
2751   return this_spec->meet(other_spec)->is_ptr();
2752 }
2753 
2754 /**
2755  * dual of the inline depth for this type (used for speculation)
2756  */
2757 int TypePtr::dual_inline_depth() const {
2758   return -inline_depth();
2759 }
2760 
2761 /**
2762  * meet of 2 inline depths (used for speculation)
2763  *
2764  * @param depth  depth to meet with
2765  */
2766 int TypePtr::meet_inline_depth(int depth) const {
2767   return MAX2(inline_depth(), depth);
2768 }
2769 
2770 /**
2771  * Are the speculative parts of 2 types equal?
2772  *
2773  * @param other  type to compare this one to
2774  */
2775 bool TypePtr::eq_speculative(const TypePtr* other) const {
2776   if (_speculative == NULL || other->speculative() == NULL) {
2777     return _speculative == other->speculative();
2778   }
2779 
2780   if (_speculative->base() != other->speculative()->base()) {
2781     return false;
2782   }
2783 
2784   return _speculative->eq(other->speculative());
2785 }
2786 
2787 /**
2788  * Hash of the speculative part of the type
2789  */
2790 int TypePtr::hash_speculative() const {
2791   if (_speculative == NULL) {
2792     return 0;
2793   }
2794 
2795   return _speculative->hash();
2796 }
2797 
2798 /**
2799  * add offset to the speculative part of the type
2800  *
2801  * @param offset  offset to add
2802  */
2803 const TypePtr* TypePtr::add_offset_speculative(intptr_t offset) const {
2804   if (_speculative == NULL) {
2805     return NULL;
2806   }
2807   return _speculative->add_offset(offset)->is_ptr();
2808 }
2809 
2810 /**
2811  * return exact klass from the speculative type if there's one
2812  */
2813 ciKlass* TypePtr::speculative_type() const {
2814   if (_speculative != NULL && _speculative->isa_oopptr()) {
2815     const TypeOopPtr* speculative = _speculative->join(this)->is_oopptr();
2816     if (speculative->klass_is_exact()) {
2817       return speculative->klass();
2818     }
2819   }
2820   return NULL;
2821 }
2822 
2823 /**
2824  * return true if speculative type may be null
2825  */
2826 bool TypePtr::speculative_maybe_null() const {
2827   if (_speculative != NULL) {
2828     const TypePtr* speculative = _speculative->join(this)->is_ptr();
2829     return speculative->maybe_null();
2830   }
2831   return true;
2832 }
2833 
2834 bool TypePtr::speculative_always_null() const {
2835   if (_speculative != NULL) {
2836     const TypePtr* speculative = _speculative->join(this)->is_ptr();
2837     return speculative == TypePtr::NULL_PTR;
2838   }
2839   return false;
2840 }
2841 
2842 /**
2843  * Same as TypePtr::speculative_type() but return the klass only if
2844  * the speculative tells us is not null
2845  */
2846 ciKlass* TypePtr::speculative_type_not_null() const {
2847   if (speculative_maybe_null()) {
2848     return NULL;
2849   }
2850   return speculative_type();
2851 }
2852 
2853 /**
2854  * Check whether new profiling would improve speculative type
2855  *
2856  * @param   exact_kls    class from profiling
2857  * @param   inline_depth inlining depth of profile point
2858  *
2859  * @return  true if type profile is valuable
2860  */
2861 bool TypePtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
2862   // no profiling?
2863   if (exact_kls == NULL) {
2864     return false;
2865   }
2866   if (speculative() == TypePtr::NULL_PTR) {
2867     return false;
2868   }
2869   // no speculative type or non exact speculative type?
2870   if (speculative_type() == NULL) {
2871     return true;
2872   }
2873   // If the node already has an exact speculative type keep it,
2874   // unless it was provided by profiling that is at a deeper
2875   // inlining level. Profiling at a higher inlining depth is
2876   // expected to be less accurate.
2877   if (_speculative->inline_depth() == InlineDepthBottom) {
2878     return false;
2879   }
2880   assert(_speculative->inline_depth() != InlineDepthTop, "can't do the comparison");
2881   return inline_depth < _speculative->inline_depth();
2882 }
2883 
2884 /**
2885  * Check whether new profiling would improve ptr (= tells us it is non
2886  * null)
2887  *
2888  * @param   ptr_kind always null or not null?
2889  *
2890  * @return  true if ptr profile is valuable
2891  */
2892 bool TypePtr::would_improve_ptr(ProfilePtrKind ptr_kind) const {
2893   // profiling doesn't tell us anything useful
2894   if (ptr_kind != ProfileAlwaysNull && ptr_kind != ProfileNeverNull) {
2895     return false;
2896   }
2897   // We already know this is not null
2898   if (!this->maybe_null()) {
2899     return false;
2900   }
2901   // We already know the speculative type cannot be null
2902   if (!speculative_maybe_null()) {
2903     return false;
2904   }
2905   // We already know this is always null
2906   if (this == TypePtr::NULL_PTR) {
2907     return false;
2908   }
2909   // We already know the speculative type is always null
2910   if (speculative_always_null()) {
2911     return false;
2912   }
2913   if (ptr_kind == ProfileAlwaysNull && speculative() != NULL && speculative()->isa_oopptr()) {
2914     return false;
2915   }
2916   return true;
2917 }
2918 
2919 //------------------------------dump2------------------------------------------
2920 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
2921   "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR"
2922 };
2923 
2924 #ifndef PRODUCT
2925 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2926   if( _ptr == Null ) st->print("NULL");
2927   else st->print("%s *", ptr_msg[_ptr]);
2928   if( _offset == OffsetTop ) st->print("+top");
2929   else if( _offset == OffsetBot ) st->print("+bot");
2930   else if( _offset ) st->print("+%d", _offset);
2931   dump_inline_depth(st);
2932   dump_speculative(st);
2933 }
2934 
2935 /**
2936  *dump the speculative part of the type
2937  */
2938 void TypePtr::dump_speculative(outputStream *st) const {
2939   if (_speculative != NULL) {
2940     st->print(" (speculative=");
2941     _speculative->dump_on(st);
2942     st->print(")");
2943   }
2944 }
2945 
2946 /**
2947  *dump the inline depth of the type
2948  */
2949 void TypePtr::dump_inline_depth(outputStream *st) const {
2950   if (_inline_depth != InlineDepthBottom) {
2951     if (_inline_depth == InlineDepthTop) {
2952       st->print(" (inline_depth=InlineDepthTop)");
2953     } else {
2954       st->print(" (inline_depth=%d)", _inline_depth);
2955     }
2956   }
2957 }
2958 #endif
2959 
2960 //------------------------------singleton--------------------------------------
2961 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2962 // constants
2963 bool TypePtr::singleton(void) const {
2964   // TopPTR, Null, AnyNull, Constant are all singletons
2965   return (_offset != OffsetBot) && !below_centerline(_ptr);
2966 }
2967 
2968 bool TypePtr::empty(void) const {
2969   return (_offset == OffsetTop) || above_centerline(_ptr);
2970 }
2971 
2972 //=============================================================================
2973 // Convenience common pre-built types.
2974 const TypeRawPtr *TypeRawPtr::BOTTOM;
2975 const TypeRawPtr *TypeRawPtr::NOTNULL;
2976 
2977 //------------------------------make-------------------------------------------
2978 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
2979   assert( ptr != Constant, "what is the constant?" );
2980   assert( ptr != Null, "Use TypePtr for NULL" );
2981   return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons();
2982 }
2983 
2984 const TypeRawPtr *TypeRawPtr::make( address bits ) {
2985   assert( bits, "Use TypePtr for NULL" );
2986   return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
2987 }
2988 
2989 //------------------------------cast_to_ptr_type-------------------------------
2990 const TypeRawPtr* TypeRawPtr::cast_to_ptr_type(PTR ptr) const {
2991   assert( ptr != Constant, "what is the constant?" );
2992   assert( ptr != Null, "Use TypePtr for NULL" );
2993   assert( _bits==0, "Why cast a constant address?");
2994   if( ptr == _ptr ) return this;
2995   return make(ptr);
2996 }
2997 
2998 //------------------------------get_con----------------------------------------
2999 intptr_t TypeRawPtr::get_con() const {
3000   assert( _ptr == Null || _ptr == Constant, "" );
3001   return (intptr_t)_bits;
3002 }
3003 
3004 //------------------------------meet-------------------------------------------
3005 // Compute the MEET of two types.  It returns a new Type object.
3006 const Type *TypeRawPtr::xmeet( const Type *t ) const {
3007   // Perform a fast test for common case; meeting the same types together.
3008   if( this == t ) return this;  // Meeting same type-rep?
3009 
3010   // Current "this->_base" is RawPtr
3011   switch( t->base() ) {         // switch on original type
3012   case Bottom:                  // Ye Olde Default
3013     return t;
3014   case Top:
3015     return this;
3016   case AnyPtr:                  // Meeting to AnyPtrs
3017     break;
3018   case RawPtr: {                // might be top, bot, any/not or constant
3019     enum PTR tptr = t->is_ptr()->ptr();
3020     enum PTR ptr = meet_ptr( tptr );
3021     if( ptr == Constant ) {     // Cannot be equal constants, so...
3022       if( tptr == Constant && _ptr != Constant)  return t;
3023       if( _ptr == Constant && tptr != Constant)  return this;
3024       ptr = NotNull;            // Fall down in lattice
3025     }
3026     return make( ptr );
3027   }
3028 
3029   case OopPtr:
3030   case InstPtr:
3031   case AryPtr:
3032   case MetadataPtr:
3033   case KlassPtr:
3034   case InstKlassPtr:
3035   case AryKlassPtr:
3036     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3037   default:                      // All else is a mistake
3038     typerr(t);
3039   }
3040 
3041   // Found an AnyPtr type vs self-RawPtr type
3042   const TypePtr *tp = t->is_ptr();
3043   switch (tp->ptr()) {
3044   case TypePtr::TopPTR:  return this;
3045   case TypePtr::BotPTR:  return t;
3046   case TypePtr::Null:
3047     if( _ptr == TypePtr::TopPTR ) return t;
3048     return TypeRawPtr::BOTTOM;
3049   case TypePtr::NotNull: return TypePtr::make(AnyPtr, meet_ptr(TypePtr::NotNull), tp->meet_offset(0), tp->speculative(), tp->inline_depth());
3050   case TypePtr::AnyNull:
3051     if( _ptr == TypePtr::Constant) return this;
3052     return make( meet_ptr(TypePtr::AnyNull) );
3053   default: ShouldNotReachHere();
3054   }
3055   return this;
3056 }
3057 
3058 //------------------------------xdual------------------------------------------
3059 // Dual: compute field-by-field dual
3060 const Type *TypeRawPtr::xdual() const {
3061   return new TypeRawPtr( dual_ptr(), _bits );
3062 }
3063 
3064 //------------------------------add_offset-------------------------------------
3065 const TypePtr *TypeRawPtr::add_offset( intptr_t offset ) const {
3066   if( offset == OffsetTop ) return BOTTOM; // Undefined offset-> undefined pointer
3067   if( offset == OffsetBot ) return BOTTOM; // Unknown offset-> unknown pointer
3068   if( offset == 0 ) return this; // No change
3069   switch (_ptr) {
3070   case TypePtr::TopPTR:
3071   case TypePtr::BotPTR:
3072   case TypePtr::NotNull:
3073     return this;
3074   case TypePtr::Null:
3075   case TypePtr::Constant: {
3076     address bits = _bits+offset;
3077     if ( bits == 0 ) return TypePtr::NULL_PTR;
3078     return make( bits );
3079   }
3080   default:  ShouldNotReachHere();
3081   }
3082   return NULL;                  // Lint noise
3083 }
3084 
3085 //------------------------------eq---------------------------------------------
3086 // Structural equality check for Type representations
3087 bool TypeRawPtr::eq( const Type *t ) const {
3088   const TypeRawPtr *a = (const TypeRawPtr*)t;
3089   return _bits == a->_bits && TypePtr::eq(t);
3090 }
3091 
3092 //------------------------------hash-------------------------------------------
3093 // Type-specific hashing function.
3094 int TypeRawPtr::hash(void) const {
3095   return (intptr_t)_bits + TypePtr::hash();
3096 }
3097 
3098 //------------------------------dump2------------------------------------------
3099 #ifndef PRODUCT
3100 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3101   if( _ptr == Constant )
3102     st->print(INTPTR_FORMAT, p2i(_bits));
3103   else
3104     st->print("rawptr:%s", ptr_msg[_ptr]);
3105 }
3106 #endif
3107 
3108 //=============================================================================
3109 // Convenience common pre-built type.
3110 const TypeOopPtr *TypeOopPtr::BOTTOM;
3111 
3112 //------------------------------TypeOopPtr-------------------------------------
3113 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset,
3114                        int instance_id, const TypePtr* speculative, int inline_depth)
3115   : TypePtr(t, ptr, offset, speculative, inline_depth),
3116     _const_oop(o), _klass(k),
3117     _klass_is_exact(xk),
3118     _is_ptr_to_narrowoop(false),
3119     _is_ptr_to_narrowklass(false),
3120     _is_ptr_to_boxed_value(false),
3121     _instance_id(instance_id) {
3122   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3123       (offset > 0) && xk && (k != 0) && k->is_instance_klass()) {
3124     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset);
3125   }
3126 #ifdef _LP64
3127   if (_offset > 0 || _offset == Type::OffsetTop || _offset == Type::OffsetBot) {
3128     if (_offset == oopDesc::klass_offset_in_bytes()) {
3129       _is_ptr_to_narrowklass = UseCompressedClassPointers;
3130     } else if (klass() == NULL) {
3131       // Array with unknown body type
3132       assert(this->isa_aryptr(), "only arrays without klass");
3133       _is_ptr_to_narrowoop = UseCompressedOops;
3134     } else if (this->isa_aryptr()) {
3135       _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() &&
3136                              _offset != arrayOopDesc::length_offset_in_bytes());
3137     } else if (klass()->is_instance_klass()) {
3138       ciInstanceKlass* ik = klass()->as_instance_klass();
3139       ciField* field = NULL;
3140       if (this->isa_klassptr()) {
3141         // Perm objects don't use compressed references
3142       } else if (_offset == OffsetBot || _offset == OffsetTop) {
3143         // unsafe access
3144         _is_ptr_to_narrowoop = UseCompressedOops;
3145       } else {
3146         assert(this->isa_instptr(), "must be an instance ptr.");
3147 
3148         if (klass() == ciEnv::current()->Class_klass() &&
3149             (_offset == java_lang_Class::klass_offset() ||
3150              _offset == java_lang_Class::array_klass_offset())) {
3151           // Special hidden fields from the Class.
3152           assert(this->isa_instptr(), "must be an instance ptr.");
3153           _is_ptr_to_narrowoop = false;
3154         } else if (klass() == ciEnv::current()->Class_klass() &&
3155                    _offset >= InstanceMirrorKlass::offset_of_static_fields()) {
3156           // Static fields
3157           ciField* field = NULL;
3158           if (const_oop() != NULL) {
3159             ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3160             field = k->get_field_by_offset(_offset, true);
3161           }
3162           if (field != NULL) {
3163             BasicType basic_elem_type = field->layout_type();
3164             _is_ptr_to_narrowoop = UseCompressedOops && is_reference_type(basic_elem_type);
3165           } else {
3166             // unsafe access
3167             _is_ptr_to_narrowoop = UseCompressedOops;
3168           }
3169         } else {
3170           // Instance fields which contains a compressed oop references.
3171           field = ik->get_field_by_offset(_offset, false);
3172           if (field != NULL) {
3173             BasicType basic_elem_type = field->layout_type();
3174             _is_ptr_to_narrowoop = UseCompressedOops && is_reference_type(basic_elem_type);
3175           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3176             // Compile::find_alias_type() cast exactness on all types to verify
3177             // that it does not affect alias type.
3178             _is_ptr_to_narrowoop = UseCompressedOops;
3179           } else {
3180             // Type for the copy start in LibraryCallKit::inline_native_clone().
3181             _is_ptr_to_narrowoop = UseCompressedOops;
3182           }
3183         }
3184       }
3185     }
3186   }
3187 #endif
3188 }
3189 
3190 //------------------------------make-------------------------------------------
3191 const TypeOopPtr *TypeOopPtr::make(PTR ptr, int offset, int instance_id,
3192                                      const TypePtr* speculative, int inline_depth) {
3193   assert(ptr != Constant, "no constant generic pointers");
3194   ciKlass*  k = Compile::current()->env()->Object_klass();
3195   bool      xk = false;
3196   ciObject* o = NULL;
3197   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, instance_id, speculative, inline_depth))->hashcons();
3198 }
3199 
3200 
3201 //------------------------------cast_to_ptr_type-------------------------------
3202 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3203   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3204   if( ptr == _ptr ) return this;
3205   return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3206 }
3207 
3208 //-----------------------------cast_to_instance_id----------------------------
3209 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3210   // There are no instances of a general oop.
3211   // Return self unchanged.
3212   return this;
3213 }
3214 
3215 //-----------------------------cast_to_exactness-------------------------------
3216 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3217   // There is no such thing as an exact general oop.
3218   // Return self unchanged.
3219   return this;
3220 }
3221 
3222 
3223 //------------------------------as_klass_type----------------------------------
3224 // Return the klass type corresponding to this instance or array type.
3225 // It is the type that is loaded from an object of this type.
3226 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3227   ShouldNotReachHere();
3228   return NULL;
3229 }
3230 
3231 //------------------------------meet-------------------------------------------
3232 // Compute the MEET of two types.  It returns a new Type object.
3233 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3234   // Perform a fast test for common case; meeting the same types together.
3235   if( this == t ) return this;  // Meeting same type-rep?
3236 
3237   // Current "this->_base" is OopPtr
3238   switch (t->base()) {          // switch on original type
3239 
3240   case Int:                     // Mixing ints & oops happens when javac
3241   case Long:                    // reuses local variables
3242   case FloatTop:
3243   case FloatCon:
3244   case FloatBot:
3245   case DoubleTop:
3246   case DoubleCon:
3247   case DoubleBot:
3248   case NarrowOop:
3249   case NarrowKlass:
3250   case Bottom:                  // Ye Olde Default
3251     return Type::BOTTOM;
3252   case Top:
3253     return this;
3254 
3255   default:                      // All else is a mistake
3256     typerr(t);
3257 
3258   case RawPtr:
3259   case MetadataPtr:
3260   case KlassPtr:
3261   case InstKlassPtr:
3262   case AryKlassPtr:
3263     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3264 
3265   case AnyPtr: {
3266     // Found an AnyPtr type vs self-OopPtr type
3267     const TypePtr *tp = t->is_ptr();
3268     int offset = meet_offset(tp->offset());
3269     PTR ptr = meet_ptr(tp->ptr());
3270     const TypePtr* speculative = xmeet_speculative(tp);
3271     int depth = meet_inline_depth(tp->inline_depth());
3272     switch (tp->ptr()) {
3273     case Null:
3274       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3275       // else fall through:
3276     case TopPTR:
3277     case AnyNull: {
3278       int instance_id = meet_instance_id(InstanceTop);
3279       return make(ptr, offset, instance_id, speculative, depth);
3280     }
3281     case BotPTR:
3282     case NotNull:
3283       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3284     default: typerr(t);
3285     }
3286   }
3287 
3288   case OopPtr: {                 // Meeting to other OopPtrs
3289     const TypeOopPtr *tp = t->is_oopptr();
3290     int instance_id = meet_instance_id(tp->instance_id());
3291     const TypePtr* speculative = xmeet_speculative(tp);
3292     int depth = meet_inline_depth(tp->inline_depth());
3293     return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3294   }
3295 
3296   case InstPtr:                  // For these, flip the call around to cut down
3297   case AryPtr:
3298     return t->xmeet(this);      // Call in reverse direction
3299 
3300   } // End of switch
3301   return this;                  // Return the double constant
3302 }
3303 
3304 
3305 //------------------------------xdual------------------------------------------
3306 // Dual of a pure heap pointer.  No relevant klass or oop information.
3307 const Type *TypeOopPtr::xdual() const {
3308   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3309   assert(const_oop() == NULL,             "no constants here");
3310   return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
3311 }
3312 
3313 //--------------------------make_from_klass_common-----------------------------
3314 // Computes the element-type given a klass.
3315 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) {
3316   if (klass->is_instance_klass()) {
3317     Compile* C = Compile::current();
3318     Dependencies* deps = C->dependencies();
3319     assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
3320     // Element is an instance
3321     bool klass_is_exact = false;
3322     if (klass->is_loaded()) {
3323       // Try to set klass_is_exact.
3324       ciInstanceKlass* ik = klass->as_instance_klass();
3325       klass_is_exact = ik->is_final();
3326       if (!klass_is_exact && klass_change
3327           && deps != NULL && UseUniqueSubclasses) {
3328         ciInstanceKlass* sub = ik->unique_concrete_subklass();
3329         if (sub != NULL) {
3330           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3331           klass = ik = sub;
3332           klass_is_exact = sub->is_final();
3333         }
3334       }
3335       if (!klass_is_exact && try_for_exact && deps != NULL &&
3336           !ik->is_interface() && !ik->has_subklass()) {
3337         // Add a dependence; if concrete subclass added we need to recompile
3338         deps->assert_leaf_type(ik);
3339         klass_is_exact = true;
3340       }
3341     }
3342     return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, 0);
3343   } else if (klass->is_obj_array_klass()) {
3344     // Element is an object array. Recursively call ourself.
3345     const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(klass->as_obj_array_klass()->element_klass(), false, try_for_exact);
3346     bool xk = etype->klass_is_exact();
3347     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3348     // We used to pass NotNull in here, asserting that the sub-arrays
3349     // are all not-null.  This is not true in generally, as code can
3350     // slam NULLs down in the subarrays.
3351     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, 0);
3352     return arr;
3353   } else if (klass->is_type_array_klass()) {
3354     // Element is an typeArray
3355     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3356     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3357     // We used to pass NotNull in here, asserting that the array pointer
3358     // is not-null. That was not true in general.
3359     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, 0);
3360     return arr;
3361   } else {
3362     ShouldNotReachHere();
3363     return NULL;
3364   }
3365 }
3366 
3367 //------------------------------make_from_constant-----------------------------
3368 // Make a java pointer from an oop constant
3369 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3370   assert(!o->is_null_object(), "null object not yet handled here.");
3371 
3372   const bool make_constant = require_constant || o->should_be_constant();
3373 
3374   ciKlass* klass = o->klass();
3375   if (klass->is_instance_klass()) {
3376     // Element is an instance
3377     if (make_constant) {
3378       return TypeInstPtr::make(o);
3379     } else {
3380       return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, 0);
3381     }
3382   } else if (klass->is_obj_array_klass()) {
3383     // Element is an object array. Recursively call ourself.
3384     const TypeOopPtr *etype =
3385       TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass());
3386     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3387     // We used to pass NotNull in here, asserting that the sub-arrays
3388     // are all not-null.  This is not true in generally, as code can
3389     // slam NULLs down in the subarrays.
3390     if (make_constant) {
3391       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3392     } else {
3393       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
3394     }
3395   } else if (klass->is_type_array_klass()) {
3396     // Element is an typeArray
3397     const Type* etype =
3398       (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3399     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3400     // We used to pass NotNull in here, asserting that the array pointer
3401     // is not-null. That was not true in general.
3402     if (make_constant) {
3403       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3404     } else {
3405       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
3406     }
3407   }
3408 
3409   fatal("unhandled object type");
3410   return NULL;
3411 }
3412 
3413 //------------------------------get_con----------------------------------------
3414 intptr_t TypeOopPtr::get_con() const {
3415   assert( _ptr == Null || _ptr == Constant, "" );
3416   assert( _offset >= 0, "" );
3417 
3418   if (_offset != 0) {
3419     // After being ported to the compiler interface, the compiler no longer
3420     // directly manipulates the addresses of oops.  Rather, it only has a pointer
3421     // to a handle at compile time.  This handle is embedded in the generated
3422     // code and dereferenced at the time the nmethod is made.  Until that time,
3423     // it is not reasonable to do arithmetic with the addresses of oops (we don't
3424     // have access to the addresses!).  This does not seem to currently happen,
3425     // but this assertion here is to help prevent its occurence.
3426     tty->print_cr("Found oop constant with non-zero offset");
3427     ShouldNotReachHere();
3428   }
3429 
3430   return (intptr_t)const_oop()->constant_encoding();
3431 }
3432 
3433 
3434 //-----------------------------filter------------------------------------------
3435 // Do not allow interface-vs.-noninterface joins to collapse to top.
3436 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
3437 
3438   const Type* ft = join_helper(kills, include_speculative);
3439   const TypeInstPtr* ftip = ft->isa_instptr();
3440   const TypeInstPtr* ktip = kills->isa_instptr();
3441 
3442   if (ft->empty()) {
3443     // Check for evil case of 'this' being a class and 'kills' expecting an
3444     // interface.  This can happen because the bytecodes do not contain
3445     // enough type info to distinguish a Java-level interface variable
3446     // from a Java-level object variable.  If we meet 2 classes which
3447     // both implement interface I, but their meet is at 'j/l/O' which
3448     // doesn't implement I, we have no way to tell if the result should
3449     // be 'I' or 'j/l/O'.  Thus we'll pick 'j/l/O'.  If this then flows
3450     // into a Phi which "knows" it's an Interface type we'll have to
3451     // uplift the type.
3452     if (!empty()) {
3453       if (ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface()) {
3454         return kills;           // Uplift to interface
3455       }
3456       // Also check for evil cases of 'this' being a class array
3457       // and 'kills' expecting an array of interfaces.
3458       Type::get_arrays_base_elements(ft, kills, NULL, &ktip);
3459       if (ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface()) {
3460         return kills;           // Uplift to array of interface
3461       }
3462     }
3463 
3464     return Type::TOP;           // Canonical empty value
3465   }
3466 
3467   // If we have an interface-typed Phi or cast and we narrow to a class type,
3468   // the join should report back the class.  However, if we have a J/L/Object
3469   // class-typed Phi and an interface flows in, it's possible that the meet &
3470   // join report an interface back out.  This isn't possible but happens
3471   // because the type system doesn't interact well with interfaces.
3472   if (ftip != NULL && ktip != NULL &&
3473       ftip->is_loaded() &&  ftip->klass()->is_interface() &&
3474       ktip->is_loaded() && !ktip->klass()->is_interface()) {
3475     assert(!ftip->klass_is_exact(), "interface could not be exact");
3476     return ktip->cast_to_ptr_type(ftip->ptr());
3477   }
3478 
3479   return ft;
3480 }
3481 
3482 //------------------------------eq---------------------------------------------
3483 // Structural equality check for Type representations
3484 bool TypeOopPtr::eq( const Type *t ) const {
3485   const TypeOopPtr *a = (const TypeOopPtr*)t;
3486   if (_klass_is_exact != a->_klass_is_exact ||
3487       _instance_id != a->_instance_id)  return false;
3488   ciObject* one = const_oop();
3489   ciObject* two = a->const_oop();
3490   if (one == NULL || two == NULL) {
3491     return (one == two) && TypePtr::eq(t);
3492   } else {
3493     return one->equals(two) && TypePtr::eq(t);
3494   }
3495 }
3496 
3497 //------------------------------hash-------------------------------------------
3498 // Type-specific hashing function.
3499 int TypeOopPtr::hash(void) const {
3500   return
3501     java_add(java_add((jint)(const_oop() ? const_oop()->hash() : 0), (jint)_klass_is_exact),
3502              java_add((jint)_instance_id, (jint)TypePtr::hash()));
3503 }
3504 
3505 //------------------------------dump2------------------------------------------
3506 #ifndef PRODUCT
3507 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3508   st->print("oopptr:%s", ptr_msg[_ptr]);
3509   if( _klass_is_exact ) st->print(":exact");
3510   if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
3511   switch( _offset ) {
3512   case OffsetTop: st->print("+top"); break;
3513   case OffsetBot: st->print("+any"); break;
3514   case         0: break;
3515   default:        st->print("+%d",_offset); break;
3516   }
3517   if (_instance_id == InstanceTop)
3518     st->print(",iid=top");
3519   else if (_instance_id != InstanceBot)
3520     st->print(",iid=%d",_instance_id);
3521 
3522   dump_inline_depth(st);
3523   dump_speculative(st);
3524 }
3525 #endif
3526 
3527 //------------------------------singleton--------------------------------------
3528 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3529 // constants
3530 bool TypeOopPtr::singleton(void) const {
3531   // detune optimizer to not generate constant oop + constant offset as a constant!
3532   // TopPTR, Null, AnyNull, Constant are all singletons
3533   return (_offset == 0) && !below_centerline(_ptr);
3534 }
3535 
3536 //------------------------------add_offset-------------------------------------
3537 const TypePtr *TypeOopPtr::add_offset(intptr_t offset) const {
3538   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
3539 }
3540 
3541 /**
3542  * Return same type without a speculative part
3543  */
3544 const Type* TypeOopPtr::remove_speculative() const {
3545   if (_speculative == NULL) {
3546     return this;
3547   }
3548   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
3549   return make(_ptr, _offset, _instance_id, NULL, _inline_depth);
3550 }
3551 
3552 /**
3553  * Return same type but drop speculative part if we know we won't use
3554  * it
3555  */
3556 const Type* TypeOopPtr::cleanup_speculative() const {
3557   // If the klass is exact and the ptr is not null then there's
3558   // nothing that the speculative type can help us with
3559   if (klass_is_exact() && !maybe_null()) {
3560     return remove_speculative();
3561   }
3562   return TypePtr::cleanup_speculative();
3563 }
3564 
3565 /**
3566  * Return same type but with a different inline depth (used for speculation)
3567  *
3568  * @param depth  depth to meet with
3569  */
3570 const TypePtr* TypeOopPtr::with_inline_depth(int depth) const {
3571   if (!UseInlineDepthForSpeculativeTypes) {
3572     return this;
3573   }
3574   return make(_ptr, _offset, _instance_id, _speculative, depth);
3575 }
3576 
3577 //------------------------------with_instance_id--------------------------------
3578 const TypePtr* TypeOopPtr::with_instance_id(int instance_id) const {
3579   assert(_instance_id != -1, "should be known");
3580   return make(_ptr, _offset, instance_id, _speculative, _inline_depth);
3581 }
3582 
3583 //------------------------------meet_instance_id--------------------------------
3584 int TypeOopPtr::meet_instance_id( int instance_id ) const {
3585   // Either is 'TOP' instance?  Return the other instance!
3586   if( _instance_id == InstanceTop ) return  instance_id;
3587   if(  instance_id == InstanceTop ) return _instance_id;
3588   // If either is different, return 'BOTTOM' instance
3589   if( _instance_id != instance_id ) return InstanceBot;
3590   return _instance_id;
3591 }
3592 
3593 //------------------------------dual_instance_id--------------------------------
3594 int TypeOopPtr::dual_instance_id( ) const {
3595   if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM
3596   if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP
3597   return _instance_id;              // Map everything else into self
3598 }
3599 
3600 /**
3601  * Check whether new profiling would improve speculative type
3602  *
3603  * @param   exact_kls    class from profiling
3604  * @param   inline_depth inlining depth of profile point
3605  *
3606  * @return  true if type profile is valuable
3607  */
3608 bool TypeOopPtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
3609   // no way to improve an already exact type
3610   if (klass_is_exact()) {
3611     return false;
3612   }
3613   return TypePtr::would_improve_type(exact_kls, inline_depth);
3614 }
3615 
3616 //=============================================================================
3617 // Convenience common pre-built types.
3618 const TypeInstPtr *TypeInstPtr::NOTNULL;
3619 const TypeInstPtr *TypeInstPtr::BOTTOM;
3620 const TypeInstPtr *TypeInstPtr::MIRROR;
3621 const TypeInstPtr *TypeInstPtr::MARK;
3622 const TypeInstPtr *TypeInstPtr::KLASS;
3623 
3624 //------------------------------TypeInstPtr-------------------------------------
3625 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int off,
3626                          int instance_id, const TypePtr* speculative, int inline_depth)
3627   : TypeOopPtr(InstPtr, ptr, k, xk, o, off, instance_id, speculative, inline_depth),
3628     _name(k->name()) {
3629    assert(k != NULL &&
3630           (k->is_loaded() || o == NULL),
3631           "cannot have constants with non-loaded klass");
3632 };
3633 
3634 //------------------------------make-------------------------------------------
3635 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
3636                                      ciKlass* k,
3637                                      bool xk,
3638                                      ciObject* o,
3639                                      int offset,
3640                                      int instance_id,
3641                                      const TypePtr* speculative,
3642                                      int inline_depth) {
3643   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
3644   // Either const_oop() is NULL or else ptr is Constant
3645   assert( (!o && ptr != Constant) || (o && ptr == Constant),
3646           "constant pointers must have a value supplied" );
3647   // Ptr is never Null
3648   assert( ptr != Null, "NULL pointers are not typed" );
3649 
3650   assert(instance_id <= 0 || xk, "instances are always exactly typed");
3651   if (ptr == Constant) {
3652     // Note:  This case includes meta-object constants, such as methods.
3653     xk = true;
3654   } else if (k->is_loaded()) {
3655     ciInstanceKlass* ik = k->as_instance_klass();
3656     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
3657     if (xk && ik->is_interface())  xk = false;  // no exact interface
3658   }
3659 
3660   // Now hash this baby
3661   TypeInstPtr *result =
3662     (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o ,offset, instance_id, speculative, inline_depth))->hashcons();
3663 
3664   return result;
3665 }
3666 
3667 /**
3668  *  Create constant type for a constant boxed value
3669  */
3670 const Type* TypeInstPtr::get_const_boxed_value() const {
3671   assert(is_ptr_to_boxed_value(), "should be called only for boxed value");
3672   assert((const_oop() != NULL), "should be called only for constant object");
3673   ciConstant constant = const_oop()->as_instance()->field_value_by_offset(offset());
3674   BasicType bt = constant.basic_type();
3675   switch (bt) {
3676     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
3677     case T_INT:      return TypeInt::make(constant.as_int());
3678     case T_CHAR:     return TypeInt::make(constant.as_char());
3679     case T_BYTE:     return TypeInt::make(constant.as_byte());
3680     case T_SHORT:    return TypeInt::make(constant.as_short());
3681     case T_FLOAT:    return TypeF::make(constant.as_float());
3682     case T_DOUBLE:   return TypeD::make(constant.as_double());
3683     case T_LONG:     return TypeLong::make(constant.as_long());
3684     default:         break;
3685   }
3686   fatal("Invalid boxed value type '%s'", type2name(bt));
3687   return NULL;
3688 }
3689 
3690 //------------------------------cast_to_ptr_type-------------------------------
3691 const TypeInstPtr *TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
3692   if( ptr == _ptr ) return this;
3693   // Reconstruct _sig info here since not a problem with later lazy
3694   // construction, _sig will show up on demand.
3695   return make(ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, _inline_depth);
3696 }
3697 
3698 
3699 //-----------------------------cast_to_exactness-------------------------------
3700 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
3701   if( klass_is_exact == _klass_is_exact ) return this;
3702   if (!_klass->is_loaded())  return this;
3703   ciInstanceKlass* ik = _klass->as_instance_klass();
3704   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
3705   if( ik->is_interface() )              return this;  // cannot set xk
3706   return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id, _speculative, _inline_depth);
3707 }
3708 
3709 //-----------------------------cast_to_instance_id----------------------------
3710 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const {
3711   if( instance_id == _instance_id ) return this;
3712   return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id, _speculative, _inline_depth);
3713 }
3714 
3715 //------------------------------xmeet_unloaded---------------------------------
3716 // Compute the MEET of two InstPtrs when at least one is unloaded.
3717 // Assume classes are different since called after check for same name/class-loader
3718 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
3719     int off = meet_offset(tinst->offset());
3720     PTR ptr = meet_ptr(tinst->ptr());
3721     int instance_id = meet_instance_id(tinst->instance_id());
3722     const TypePtr* speculative = xmeet_speculative(tinst);
3723     int depth = meet_inline_depth(tinst->inline_depth());
3724 
3725     const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
3726     const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
3727     if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
3728       //
3729       // Meet unloaded class with java/lang/Object
3730       //
3731       // Meet
3732       //          |                     Unloaded Class
3733       //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
3734       //  ===================================================================
3735       //   TOP    | ..........................Unloaded......................|
3736       //  AnyNull |  U-AN    |................Unloaded......................|
3737       // Constant | ... O-NN .................................. |   O-BOT   |
3738       //  NotNull | ... O-NN .................................. |   O-BOT   |
3739       //  BOTTOM  | ........................Object-BOTTOM ..................|
3740       //
3741       assert(loaded->ptr() != TypePtr::Null, "insanity check");
3742       //
3743       if(      loaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
3744       else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make(ptr, unloaded->klass(), false, NULL, off, instance_id, speculative, depth); }
3745       else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
3746       else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
3747         if (unloaded->ptr() == TypePtr::BotPTR  ) { return TypeInstPtr::BOTTOM;  }
3748         else                                      { return TypeInstPtr::NOTNULL; }
3749       }
3750       else if( unloaded->ptr() == TypePtr::TopPTR )  { return unloaded; }
3751 
3752       return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr();
3753     }
3754 
3755     // Both are unloaded, not the same class, not Object
3756     // Or meet unloaded with a different loaded class, not java/lang/Object
3757     if( ptr != TypePtr::BotPTR ) {
3758       return TypeInstPtr::NOTNULL;
3759     }
3760     return TypeInstPtr::BOTTOM;
3761 }
3762 
3763 
3764 //------------------------------meet-------------------------------------------
3765 // Compute the MEET of two types.  It returns a new Type object.
3766 const Type *TypeInstPtr::xmeet_helper(const Type *t) const {
3767   // Perform a fast test for common case; meeting the same types together.
3768   if( this == t ) return this;  // Meeting same type-rep?
3769 
3770   // Current "this->_base" is Pointer
3771   switch (t->base()) {          // switch on original type
3772 
3773   case Int:                     // Mixing ints & oops happens when javac
3774   case Long:                    // reuses local variables
3775   case FloatTop:
3776   case FloatCon:
3777   case FloatBot:
3778   case DoubleTop:
3779   case DoubleCon:
3780   case DoubleBot:
3781   case NarrowOop:
3782   case NarrowKlass:
3783   case Bottom:                  // Ye Olde Default
3784     return Type::BOTTOM;
3785   case Top:
3786     return this;
3787 
3788   default:                      // All else is a mistake
3789     typerr(t);
3790 
3791   case MetadataPtr:
3792   case KlassPtr:
3793   case InstKlassPtr:
3794   case AryKlassPtr:
3795   case RawPtr: return TypePtr::BOTTOM;
3796 
3797   case AryPtr: {                // All arrays inherit from Object class
3798     // Call in reverse direction to avoid duplication
3799     return t->is_aryptr()->xmeet_helper(this);
3800   }
3801 
3802   case OopPtr: {                // Meeting to OopPtrs
3803     // Found a OopPtr type vs self-InstPtr type
3804     const TypeOopPtr *tp = t->is_oopptr();
3805     int offset = meet_offset(tp->offset());
3806     PTR ptr = meet_ptr(tp->ptr());
3807     switch (tp->ptr()) {
3808     case TopPTR:
3809     case AnyNull: {
3810       int instance_id = meet_instance_id(InstanceTop);
3811       const TypePtr* speculative = xmeet_speculative(tp);
3812       int depth = meet_inline_depth(tp->inline_depth());
3813       return make(ptr, klass(), klass_is_exact(),
3814                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth);
3815     }
3816     case NotNull:
3817     case BotPTR: {
3818       int instance_id = meet_instance_id(tp->instance_id());
3819       const TypePtr* speculative = xmeet_speculative(tp);
3820       int depth = meet_inline_depth(tp->inline_depth());
3821       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
3822     }
3823     default: typerr(t);
3824     }
3825   }
3826 
3827   case AnyPtr: {                // Meeting to AnyPtrs
3828     // Found an AnyPtr type vs self-InstPtr type
3829     const TypePtr *tp = t->is_ptr();
3830     int offset = meet_offset(tp->offset());
3831     PTR ptr = meet_ptr(tp->ptr());
3832     int instance_id = meet_instance_id(InstanceTop);
3833     const TypePtr* speculative = xmeet_speculative(tp);
3834     int depth = meet_inline_depth(tp->inline_depth());
3835     switch (tp->ptr()) {
3836     case Null:
3837       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3838       // else fall through to AnyNull
3839     case TopPTR:
3840     case AnyNull: {
3841       return make(ptr, klass(), klass_is_exact(),
3842                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth);
3843     }
3844     case NotNull:
3845     case BotPTR:
3846       return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
3847     default: typerr(t);
3848     }
3849   }
3850 
3851   /*
3852                  A-top         }
3853                /   |   \       }  Tops
3854            B-top A-any C-top   }
3855               | /  |  \ |      }  Any-nulls
3856            B-any   |   C-any   }
3857               |    |    |
3858            B-con A-con C-con   } constants; not comparable across classes
3859               |    |    |
3860            B-not   |   C-not   }
3861               | \  |  / |      }  not-nulls
3862            B-bot A-not C-bot   }
3863                \   |   /       }  Bottoms
3864                  A-bot         }
3865   */
3866 
3867   case InstPtr: {                // Meeting 2 Oops?
3868     // Found an InstPtr sub-type vs self-InstPtr type
3869     const TypeInstPtr *tinst = t->is_instptr();
3870     int off = meet_offset(tinst->offset());
3871     PTR ptr = meet_ptr(tinst->ptr());
3872     int instance_id = meet_instance_id(tinst->instance_id());
3873     const TypePtr* speculative = xmeet_speculative(tinst);
3874     int depth = meet_inline_depth(tinst->inline_depth());
3875     ciKlass* tinst_klass = tinst->klass();
3876     ciKlass* this_klass  = klass();
3877     bool tinst_xk = tinst->klass_is_exact();
3878     bool this_xk  = klass_is_exact();
3879 
3880     ciKlass* res_klass = NULL;
3881     bool res_xk = false;
3882     const Type* res;
3883     MeetResult kind = meet_instptr(ptr, this_klass, tinst_klass, this_xk, tinst_xk, this->_ptr, tinst->_ptr, res_klass, res_xk);
3884     if (kind == UNLOADED) {
3885       // One of these classes has not been loaded
3886       const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst);
3887 #ifndef PRODUCT
3888       if (PrintOpto && Verbose) {
3889         tty->print("meet of unloaded classes resulted in: ");
3890         unloaded_meet->dump();
3891         tty->cr();
3892         tty->print("  this == ");
3893         dump();
3894         tty->cr();
3895         tty->print(" tinst == ");
3896         tinst->dump();
3897         tty->cr();
3898       }
3899 #endif
3900       res = unloaded_meet;
3901     } else {
3902       if (kind == NOT_SUBTYPE && instance_id > 0) {
3903         instance_id = InstanceBot;
3904       } else if (kind == LCA) {
3905         instance_id = InstanceBot;
3906       }
3907       ciObject* o = NULL;             // Assume not constant when done
3908       ciObject* this_oop = const_oop();
3909       ciObject* tinst_oop = tinst->const_oop();
3910       if (ptr == Constant) {
3911         if (this_oop != NULL && tinst_oop != NULL &&
3912             this_oop->equals(tinst_oop))
3913           o = this_oop;
3914         else if (above_centerline(_ptr)) {
3915           assert(!tinst_klass->is_interface(), "");
3916           o = tinst_oop;
3917         } else if (above_centerline(tinst->_ptr)) {
3918           assert(!this_klass->is_interface(), "");
3919           o = this_oop;
3920         } else
3921           ptr = NotNull;
3922       }
3923       res = make(ptr, res_klass, res_xk, o, off, instance_id, speculative, depth);
3924     }
3925 
3926     return res;
3927 
3928   } // End of case InstPtr
3929 
3930   } // End of switch
3931   return this;                  // Return the double constant
3932 }
3933 
3934 TypePtr::MeetResult TypePtr::meet_instptr(PTR &ptr, ciKlass* this_klass, ciKlass* tinst_klass, bool this_xk, bool tinst_xk,
3935                                           PTR this_ptr,
3936                                           PTR tinst_ptr, ciKlass*&res_klass, bool &res_xk) {
3937 
3938   // Check for easy case; klasses are equal (and perhaps not loaded!)
3939   // If we have constants, then we created oops so classes are loaded
3940   // and we can handle the constants further down.  This case handles
3941   // both-not-loaded or both-loaded classes
3942   if (ptr != Constant && this_klass->equals(tinst_klass) && this_xk == tinst_xk) {
3943     res_klass = this_klass;
3944     res_xk = this_xk;
3945     return QUICK;
3946   }
3947 
3948   // Classes require inspection in the Java klass hierarchy.  Must be loaded.
3949   if (!tinst_klass->is_loaded() || !this_klass->is_loaded()) {
3950     return UNLOADED;
3951   }
3952 
3953   // Handle mixing oops and interfaces first.
3954   if (this_klass->is_interface() && !(tinst_klass->is_interface() ||
3955                                       tinst_klass == ciEnv::current()->Object_klass())) {
3956     ciKlass *tmp = tinst_klass; // Swap interface around
3957     tinst_klass = this_klass;
3958     this_klass = tmp;
3959     bool tmp2 = tinst_xk;
3960     tinst_xk = this_xk;
3961     this_xk = tmp2;
3962   }
3963   if (tinst_klass->is_interface() &&
3964       !(this_klass->is_interface() ||
3965         // Treat java/lang/Object as an honorary interface,
3966         // because we need a bottom for the interface hierarchy.
3967         this_klass == ciEnv::current()->Object_klass())) {
3968     // Oop meets interface!
3969 
3970     // See if the oop subtypes (implements) interface.
3971     if (this_klass->is_subtype_of(tinst_klass)) {
3972       // Oop indeed subtypes.  Now keep oop or interface depending
3973       // on whether we are both above the centerline or either is
3974       // below the centerline.  If we are on the centerline
3975       // (e.g., Constant vs. AnyNull interface), use the constant.
3976       res_klass  = below_centerline(ptr) ? tinst_klass : this_klass;
3977       // If we are keeping this_klass, keep its exactness too.
3978       res_xk = below_centerline(ptr) ? tinst_xk    : this_xk;
3979       return SUBTYPE;
3980     } else {                  // Does not implement, fall to Object
3981       // Oop does not implement interface, so mixing falls to Object
3982       // just like the verifier does (if both are above the
3983       // centerline fall to interface)
3984       res_klass = above_centerline(ptr) ? tinst_klass : ciEnv::current()->Object_klass();
3985       res_xk = above_centerline(ptr) ? tinst_xk : false;
3986       // Watch out for Constant vs. AnyNull interface.
3987       if (ptr == Constant)  ptr = NotNull;   // forget it was a constant
3988       return NOT_SUBTYPE;
3989     }
3990   }
3991 
3992   // Either oop vs oop or interface vs interface or interface vs Object
3993 
3994   // !!! Here's how the symmetry requirement breaks down into invariants:
3995   // If we split one up & one down AND they subtype, take the down man.
3996   // If we split one up & one down AND they do NOT subtype, "fall hard".
3997   // If both are up and they subtype, take the subtype class.
3998   // If both are up and they do NOT subtype, "fall hard".
3999   // If both are down and they subtype, take the supertype class.
4000   // If both are down and they do NOT subtype, "fall hard".
4001   // Constants treated as down.
4002 
4003   // Now, reorder the above list; observe that both-down+subtype is also
4004   // "fall hard"; "fall hard" becomes the default case:
4005   // If we split one up & one down AND they subtype, take the down man.
4006   // If both are up and they subtype, take the subtype class.
4007 
4008   // If both are down and they subtype, "fall hard".
4009   // If both are down and they do NOT subtype, "fall hard".
4010   // If both are up and they do NOT subtype, "fall hard".
4011   // If we split one up & one down AND they do NOT subtype, "fall hard".
4012 
4013   // If a proper subtype is exact, and we return it, we return it exactly.
4014   // If a proper supertype is exact, there can be no subtyping relationship!
4015   // If both types are equal to the subtype, exactness is and-ed below the
4016   // centerline and or-ed above it.  (N.B. Constants are always exact.)
4017 
4018   // Check for subtyping:
4019   ciKlass *subtype = NULL;
4020   bool subtype_exact = false;
4021   if (tinst_klass->equals(this_klass)) {
4022     subtype = this_klass;
4023     subtype_exact = below_centerline(ptr) ? (this_xk && tinst_xk) : (this_xk || tinst_xk);
4024   } else if (!tinst_xk && this_klass->is_subtype_of(tinst_klass)) {
4025     subtype = this_klass;     // Pick subtyping class
4026     subtype_exact = this_xk;
4027   } else if (!this_xk && tinst_klass->is_subtype_of(this_klass)) {
4028     subtype = tinst_klass;    // Pick subtyping class
4029     subtype_exact = tinst_xk;
4030   }
4031 
4032   if (subtype) {
4033     if (above_centerline(ptr)) { // both are up?
4034       this_klass = tinst_klass = subtype;
4035       this_xk = tinst_xk = subtype_exact;
4036     } else if (above_centerline(this_ptr) && !above_centerline(tinst_ptr)) {
4037       this_klass = tinst_klass; // tinst is down; keep down man
4038       this_xk = tinst_xk;
4039     } else if (above_centerline(tinst_ptr) && !above_centerline(this_ptr)) {
4040       tinst_klass = this_klass; // this is down; keep down man
4041       tinst_xk = this_xk;
4042     } else {
4043       this_xk = subtype_exact;  // either they are equal, or we'll do an LCA
4044     }
4045   }
4046 
4047   // Check for classes now being equal
4048   if (tinst_klass->equals(this_klass)) {
4049     // If the klasses are equal, the constants may still differ.  Fall to
4050     // NotNull if they do (neither constant is NULL; that is a special case
4051     // handled elsewhere).
4052     res_klass = this_klass;
4053     res_xk = this_xk;
4054     return SUBTYPE;
4055   } // Else classes are not equal
4056 
4057   // Since klasses are different, we require a LCA in the Java
4058   // class hierarchy - which means we have to fall to at least NotNull.
4059   if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4060     ptr = NotNull;
4061   }
4062 
4063   // Now we find the LCA of Java classes
4064   ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
4065 
4066   res_klass = k;
4067   res_xk = false;
4068 
4069   return LCA;
4070 }
4071 
4072 
4073 //------------------------java_mirror_type--------------------------------------
4074 ciType* TypeInstPtr::java_mirror_type() const {
4075   // must be a singleton type
4076   if( const_oop() == NULL )  return NULL;
4077 
4078   // must be of type java.lang.Class
4079   if( klass() != ciEnv::current()->Class_klass() )  return NULL;
4080 
4081   return const_oop()->as_instance()->java_mirror_type();
4082 }
4083 
4084 
4085 //------------------------------xdual------------------------------------------
4086 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
4087 // inheritance mechanism.
4088 const Type *TypeInstPtr::xdual() const {
4089   return new TypeInstPtr(dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4090 }
4091 
4092 //------------------------------eq---------------------------------------------
4093 // Structural equality check for Type representations
4094 bool TypeInstPtr::eq( const Type *t ) const {
4095   const TypeInstPtr *p = t->is_instptr();
4096   return
4097     klass()->equals(p->klass()) &&
4098     TypeOopPtr::eq(p);          // Check sub-type stuff
4099 }
4100 
4101 //------------------------------hash-------------------------------------------
4102 // Type-specific hashing function.
4103 int TypeInstPtr::hash(void) const {
4104   int hash = java_add((jint)klass()->hash(), (jint)TypeOopPtr::hash());
4105   return hash;
4106 }
4107 
4108 //------------------------------dump2------------------------------------------
4109 // Dump oop Type
4110 #ifndef PRODUCT
4111 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {
4112   // Print the name of the klass.
4113   klass()->print_name_on(st);
4114 
4115   switch( _ptr ) {
4116   case Constant:
4117     if (WizardMode || Verbose) {
4118       ResourceMark rm;
4119       stringStream ss;
4120 
4121       st->print(" ");
4122       const_oop()->print_oop(&ss);
4123       // 'const_oop->print_oop()' may emit newlines('\n') into ss.
4124       // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4125       char* buf = ss.as_string(/* c_heap= */false);
4126       StringUtils::replace_no_expand(buf, "\n", "");
4127       st->print_raw(buf);
4128     }
4129   case BotPTR:
4130     if (!WizardMode && !Verbose) {
4131       if( _klass_is_exact ) st->print(":exact");
4132       break;
4133     }
4134   case TopPTR:
4135   case AnyNull:
4136   case NotNull:
4137     st->print(":%s", ptr_msg[_ptr]);
4138     if( _klass_is_exact ) st->print(":exact");
4139     break;
4140   default:
4141     break;
4142   }
4143 
4144   if( _offset ) {               // Dump offset, if any
4145     if( _offset == OffsetBot )      st->print("+any");
4146     else if( _offset == OffsetTop ) st->print("+unknown");
4147     else st->print("+%d", _offset);
4148   }
4149 
4150   st->print(" *");
4151   if (_instance_id == InstanceTop)
4152     st->print(",iid=top");
4153   else if (_instance_id != InstanceBot)
4154     st->print(",iid=%d",_instance_id);
4155 
4156   dump_inline_depth(st);
4157   dump_speculative(st);
4158 }
4159 #endif
4160 
4161 //------------------------------add_offset-------------------------------------
4162 const TypePtr *TypeInstPtr::add_offset(intptr_t offset) const {
4163   return make(_ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset),
4164               _instance_id, add_offset_speculative(offset), _inline_depth);
4165 }
4166 
4167 const Type *TypeInstPtr::remove_speculative() const {
4168   if (_speculative == NULL) {
4169     return this;
4170   }
4171   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4172   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset,
4173               _instance_id, NULL, _inline_depth);
4174 }
4175 
4176 const TypePtr *TypeInstPtr::with_inline_depth(int depth) const {
4177   if (!UseInlineDepthForSpeculativeTypes) {
4178     return this;
4179   }
4180   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth);
4181 }
4182 
4183 const TypePtr *TypeInstPtr::with_instance_id(int instance_id) const {
4184   assert(is_known_instance(), "should be known");
4185   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, instance_id, _speculative, _inline_depth);
4186 }
4187 
4188 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4189   bool xk = klass_is_exact();
4190   ciInstanceKlass* ik = klass()->as_instance_klass();
4191   if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final() && !ik->is_interface()) {
4192     Compile* C = Compile::current();
4193     Dependencies* deps = C->dependencies();
4194     deps->assert_leaf_type(ik);
4195     xk = true;
4196   }
4197   return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), 0);
4198 }
4199 
4200 //=============================================================================
4201 // Convenience common pre-built types.
4202 const TypeAryPtr *TypeAryPtr::RANGE;
4203 const TypeAryPtr *TypeAryPtr::OOPS;
4204 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
4205 const TypeAryPtr *TypeAryPtr::BYTES;
4206 const TypeAryPtr *TypeAryPtr::SHORTS;
4207 const TypeAryPtr *TypeAryPtr::CHARS;
4208 const TypeAryPtr *TypeAryPtr::INTS;
4209 const TypeAryPtr *TypeAryPtr::LONGS;
4210 const TypeAryPtr *TypeAryPtr::FLOATS;
4211 const TypeAryPtr *TypeAryPtr::DOUBLES;
4212 
4213 //------------------------------make-------------------------------------------
4214 const TypeAryPtr *TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4215                                    int instance_id, const TypePtr* speculative, int inline_depth) {
4216   assert(!(k == NULL && ary->_elem->isa_int()),
4217          "integral arrays must be pre-equipped with a class");
4218   if (!xk)  xk = ary->ary_must_be_exact();
4219   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4220   return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id, false, speculative, inline_depth))->hashcons();
4221 }
4222 
4223 //------------------------------make-------------------------------------------
4224 const TypeAryPtr *TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4225                                    int instance_id, const TypePtr* speculative, int inline_depth,
4226                                    bool is_autobox_cache) {
4227   assert(!(k == NULL && ary->_elem->isa_int()),
4228          "integral arrays must be pre-equipped with a class");
4229   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4230   if (!xk)  xk = (o != NULL) || ary->ary_must_be_exact();
4231   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4232   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4233 }
4234 
4235 //------------------------------cast_to_ptr_type-------------------------------
4236 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4237   if( ptr == _ptr ) return this;
4238   return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4239 }
4240 
4241 
4242 //-----------------------------cast_to_exactness-------------------------------
4243 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4244   if( klass_is_exact == _klass_is_exact ) return this;
4245   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
4246   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
4247 }
4248 
4249 //-----------------------------cast_to_instance_id----------------------------
4250 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const {
4251   if( instance_id == _instance_id ) return this;
4252   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
4253 }
4254 
4255 
4256 //-----------------------------max_array_length-------------------------------
4257 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
4258 jint TypeAryPtr::max_array_length(BasicType etype) {
4259   if (!is_java_primitive(etype) && !is_reference_type(etype)) {
4260     if (etype == T_NARROWOOP) {
4261       etype = T_OBJECT;
4262     } else if (etype == T_ILLEGAL) { // bottom[]
4263       etype = T_BYTE; // will produce conservatively high value
4264     } else {
4265       fatal("not an element type: %s", type2name(etype));
4266     }
4267   }
4268   return arrayOopDesc::max_array_length(etype);
4269 }
4270 
4271 //-----------------------------narrow_size_type-------------------------------
4272 // Narrow the given size type to the index range for the given array base type.
4273 // Return NULL if the resulting int type becomes empty.
4274 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const {
4275   jint hi = size->_hi;
4276   jint lo = size->_lo;
4277   jint min_lo = 0;
4278   jint max_hi = max_array_length(elem()->basic_type());
4279   //if (index_not_size)  --max_hi;     // type of a valid array index, FTR
4280   bool chg = false;
4281   if (lo < min_lo) {
4282     lo = min_lo;
4283     if (size->is_con()) {
4284       hi = lo;
4285     }
4286     chg = true;
4287   }
4288   if (hi > max_hi) {
4289     hi = max_hi;
4290     if (size->is_con()) {
4291       lo = hi;
4292     }
4293     chg = true;
4294   }
4295   // Negative length arrays will produce weird intermediate dead fast-path code
4296   if (lo > hi)
4297     return TypeInt::ZERO;
4298   if (!chg)
4299     return size;
4300   return TypeInt::make(lo, hi, Type::WidenMin);
4301 }
4302 
4303 //-------------------------------cast_to_size----------------------------------
4304 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4305   assert(new_size != NULL, "");
4306   new_size = narrow_size_type(new_size);
4307   if (new_size == size())  return this;
4308   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
4309   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4310 }
4311 
4312 //------------------------------cast_to_stable---------------------------------
4313 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
4314   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
4315     return this;
4316 
4317   const Type* elem = this->elem();
4318   const TypePtr* elem_ptr = elem->make_ptr();
4319 
4320   if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) {
4321     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
4322     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
4323   }
4324 
4325   const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
4326 
4327   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4328 }
4329 
4330 //-----------------------------stable_dimension--------------------------------
4331 int TypeAryPtr::stable_dimension() const {
4332   if (!is_stable())  return 0;
4333   int dim = 1;
4334   const TypePtr* elem_ptr = elem()->make_ptr();
4335   if (elem_ptr != NULL && elem_ptr->isa_aryptr())
4336     dim += elem_ptr->is_aryptr()->stable_dimension();
4337   return dim;
4338 }
4339 
4340 //----------------------cast_to_autobox_cache-----------------------------------
4341 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
4342   if (is_autobox_cache())  return this;
4343   const TypeOopPtr* etype = elem()->make_oopptr();
4344   if (etype == NULL)  return this;
4345   // The pointers in the autobox arrays are always non-null.
4346   etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
4347   const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable());
4348   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
4349 }
4350 
4351 //------------------------------eq---------------------------------------------
4352 // Structural equality check for Type representations
4353 bool TypeAryPtr::eq( const Type *t ) const {
4354   const TypeAryPtr *p = t->is_aryptr();
4355   return
4356     _ary == p->_ary &&  // Check array
4357     TypeOopPtr::eq(p);  // Check sub-parts
4358 }
4359 
4360 //------------------------------hash-------------------------------------------
4361 // Type-specific hashing function.
4362 int TypeAryPtr::hash(void) const {
4363   return (intptr_t)_ary + TypeOopPtr::hash();
4364 }
4365 
4366 //------------------------------meet-------------------------------------------
4367 // Compute the MEET of two types.  It returns a new Type object.
4368 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
4369   // Perform a fast test for common case; meeting the same types together.
4370   if( this == t ) return this;  // Meeting same type-rep?
4371   // Current "this->_base" is Pointer
4372   switch (t->base()) {          // switch on original type
4373 
4374   // Mixing ints & oops happens when javac reuses local variables
4375   case Int:
4376   case Long:
4377   case FloatTop:
4378   case FloatCon:
4379   case FloatBot:
4380   case DoubleTop:
4381   case DoubleCon:
4382   case DoubleBot:
4383   case NarrowOop:
4384   case NarrowKlass:
4385   case Bottom:                  // Ye Olde Default
4386     return Type::BOTTOM;
4387   case Top:
4388     return this;
4389 
4390   default:                      // All else is a mistake
4391     typerr(t);
4392 
4393   case OopPtr: {                // Meeting to OopPtrs
4394     // Found a OopPtr type vs self-AryPtr type
4395     const TypeOopPtr *tp = t->is_oopptr();
4396     int offset = meet_offset(tp->offset());
4397     PTR ptr = meet_ptr(tp->ptr());
4398     int depth = meet_inline_depth(tp->inline_depth());
4399     const TypePtr* speculative = xmeet_speculative(tp);
4400     switch (tp->ptr()) {
4401     case TopPTR:
4402     case AnyNull: {
4403       int instance_id = meet_instance_id(InstanceTop);
4404       return make(ptr, (ptr == Constant ? const_oop() : NULL),
4405                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4406     }
4407     case BotPTR:
4408     case NotNull: {
4409       int instance_id = meet_instance_id(tp->instance_id());
4410       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4411     }
4412     default: ShouldNotReachHere();
4413     }
4414   }
4415 
4416   case AnyPtr: {                // Meeting two AnyPtrs
4417     // Found an AnyPtr type vs self-AryPtr type
4418     const TypePtr *tp = t->is_ptr();
4419     int offset = meet_offset(tp->offset());
4420     PTR ptr = meet_ptr(tp->ptr());
4421     const TypePtr* speculative = xmeet_speculative(tp);
4422     int depth = meet_inline_depth(tp->inline_depth());
4423     switch (tp->ptr()) {
4424     case TopPTR:
4425       return this;
4426     case BotPTR:
4427     case NotNull:
4428       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4429     case Null:
4430       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4431       // else fall through to AnyNull
4432     case AnyNull: {
4433       int instance_id = meet_instance_id(InstanceTop);
4434       return make(ptr, (ptr == Constant ? const_oop() : NULL),
4435                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4436     }
4437     default: ShouldNotReachHere();
4438     }
4439   }
4440 
4441   case MetadataPtr:
4442   case KlassPtr:
4443   case InstKlassPtr:
4444   case AryKlassPtr:
4445   case RawPtr: return TypePtr::BOTTOM;
4446 
4447   case AryPtr: {                // Meeting 2 references?
4448     const TypeAryPtr *tap = t->is_aryptr();
4449     int off = meet_offset(tap->offset());
4450     const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
4451     PTR ptr = meet_ptr(tap->ptr());
4452     int instance_id = meet_instance_id(tap->instance_id());
4453     const TypePtr* speculative = xmeet_speculative(tap);
4454     int depth = meet_inline_depth(tap->inline_depth());
4455 
4456     ciKlass* res_klass = NULL;
4457     bool res_xk = false;
4458     const Type* elem = tary->_elem;
4459     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) {
4460       instance_id = InstanceBot;
4461     }
4462 
4463     ciObject* o = NULL;             // Assume not constant when done
4464     ciObject* this_oop = const_oop();
4465     ciObject* tap_oop = tap->const_oop();
4466     if (ptr == Constant) {
4467       if (this_oop != NULL && tap_oop != NULL &&
4468           this_oop->equals(tap_oop)) {
4469         o = tap_oop;
4470       } else if (above_centerline(_ptr)) {
4471         o = tap_oop;
4472       } else if (above_centerline(tap->_ptr)) {
4473         o = this_oop;
4474       } else {
4475         ptr = NotNull;
4476       }
4477     }
4478     return make(ptr, o, TypeAry::make(elem, tary->_size, tary->_stable), res_klass, res_xk, off, instance_id, speculative, depth);
4479   }
4480 
4481   // All arrays inherit from Object class
4482   case InstPtr: {
4483     const TypeInstPtr *tp = t->is_instptr();
4484     int offset = meet_offset(tp->offset());
4485     PTR ptr = meet_ptr(tp->ptr());
4486     int instance_id = meet_instance_id(tp->instance_id());
4487     const TypePtr* speculative = xmeet_speculative(tp);
4488     int depth = meet_inline_depth(tp->inline_depth());
4489     switch (ptr) {
4490     case TopPTR:
4491     case AnyNull:                // Fall 'down' to dual of object klass
4492       // For instances when a subclass meets a superclass we fall
4493       // below the centerline when the superclass is exact. We need to
4494       // do the same here.
4495       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
4496         return make(ptr, _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4497       } else {
4498         // cannot subclass, so the meet has to fall badly below the centerline
4499         ptr = NotNull;
4500         instance_id = InstanceBot;
4501         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative, depth);
4502       }
4503     case Constant:
4504     case NotNull:
4505     case BotPTR:                // Fall down to object klass
4506       // LCA is object_klass, but if we subclass from the top we can do better
4507       if (above_centerline(tp->ptr())) {
4508         // If 'tp'  is above the centerline and it is Object class
4509         // then we can subclass in the Java class hierarchy.
4510         // For instances when a subclass meets a superclass we fall
4511         // below the centerline when the superclass is exact. We need
4512         // to do the same here.
4513         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
4514           // that is, my array type is a subtype of 'tp' klass
4515           return make(ptr, (ptr == Constant ? const_oop() : NULL),
4516                       _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4517         }
4518       }
4519       // The other case cannot happen, since t cannot be a subtype of an array.
4520       // The meet falls down to Object class below centerline.
4521       if (ptr == Constant) {
4522          ptr = NotNull;
4523       }
4524       if (instance_id > 0) {
4525         instance_id = InstanceBot;
4526       }
4527       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
4528     default: typerr(t);
4529     }
4530   }
4531   }
4532   return this;                  // Lint noise
4533 }
4534 
4535 
4536 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) {
4537   res_klass = NULL;
4538   MeetResult result = SUBTYPE;
4539   if (elem->isa_int()) {
4540     // Integral array element types have irrelevant lattice relations.
4541     // It is the klass that determines array layout, not the element type.
4542     if (this_klass == NULL)
4543       res_klass = tap_klass;
4544     else if (tap_klass == NULL || tap_klass == this_klass) {
4545       res_klass = this_klass;
4546     } else {
4547       // Something like byte[int+] meets char[int+].
4548       // This must fall to bottom, not (int[-128..65535])[int+].
4549       // instance_id = InstanceBot;
4550       elem = Type::BOTTOM;
4551       result = NOT_SUBTYPE;
4552     }
4553   } else // Non integral arrays.
4554     // Must fall to bottom if exact klasses in upper lattice
4555     // are not equal or super klass is exact.
4556     if ((above_centerline(ptr) || ptr == Constant) && this_klass != tap_klass &&
4557         // meet with top[] and bottom[] are processed further down:
4558         tap_klass != NULL  && this_klass != NULL   &&
4559         // both are exact and not equal:
4560         ((tap_xk && this_xk) ||
4561          // 'tap'  is exact and super or unrelated:
4562          (tap_xk && !tap_klass->is_subtype_of(this_klass)) ||
4563          // 'this' is exact and super or unrelated:
4564          (this_xk && !this_klass->is_subtype_of(tap_klass)))) {
4565       if (above_centerline(ptr) || (elem->make_ptr() && above_centerline(elem->make_ptr()->_ptr))) {
4566         elem = Type::BOTTOM;
4567       }
4568       ptr = NotNull;
4569       res_xk = false;
4570       return NOT_SUBTYPE;
4571     }
4572 
4573   res_xk = false;
4574   switch (tap_ptr) {
4575     case AnyNull:
4576     case TopPTR:
4577       // Compute new klass on demand, do not use tap->_klass
4578       if (below_centerline(this_ptr)) {
4579         res_xk = this_xk;
4580       } else {
4581         res_xk = (tap_xk || this_xk);
4582       }
4583       return result;
4584     case Constant: {
4585       if (this_ptr == Constant) {
4586           res_xk = true;
4587       } else if(above_centerline(this_ptr)) {
4588         res_xk = true;
4589       } else {
4590         // Only precise for identical arrays
4591         res_xk = this_xk && (this_klass == tap_klass);
4592       }
4593       return result;
4594     }
4595     case NotNull:
4596     case BotPTR:
4597       // Compute new klass on demand, do not use tap->_klass
4598       if (above_centerline(this_ptr)) {
4599         res_xk = tap_xk;
4600       } else {
4601         res_xk = (tap_xk && this_xk) &&
4602           (this_klass == tap_klass); // Only precise for identical arrays
4603       }
4604       return result;
4605     default:  {
4606       ShouldNotReachHere();
4607       return result;
4608     }
4609   }
4610   return result;
4611 }
4612 
4613 
4614 //------------------------------xdual------------------------------------------
4615 // Dual: compute field-by-field dual
4616 const Type *TypeAryPtr::xdual() const {
4617   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());
4618 }
4619 
4620 //----------------------interface_vs_oop---------------------------------------
4621 #ifdef ASSERT
4622 bool TypeAryPtr::interface_vs_oop(const Type *t) const {
4623   const TypeAryPtr* t_aryptr = t->isa_aryptr();
4624   if (t_aryptr) {
4625     return _ary->interface_vs_oop(t_aryptr->_ary);
4626   }
4627   return false;
4628 }
4629 #endif
4630 
4631 //------------------------------dump2------------------------------------------
4632 #ifndef PRODUCT
4633 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4634   _ary->dump2(d,depth,st);
4635   switch( _ptr ) {
4636   case Constant:
4637     const_oop()->print(st);
4638     break;
4639   case BotPTR:
4640     if (!WizardMode && !Verbose) {
4641       if( _klass_is_exact ) st->print(":exact");
4642       break;
4643     }
4644   case TopPTR:
4645   case AnyNull:
4646   case NotNull:
4647     st->print(":%s", ptr_msg[_ptr]);
4648     if( _klass_is_exact ) st->print(":exact");
4649     break;
4650   default:
4651     break;
4652   }
4653 
4654   if( _offset != 0 ) {
4655     int header_size = objArrayOopDesc::header_size() * wordSize;
4656     if( _offset == OffsetTop )       st->print("+undefined");
4657     else if( _offset == OffsetBot )  st->print("+any");
4658     else if( _offset < header_size ) st->print("+%d", _offset);
4659     else {
4660       BasicType basic_elem_type = elem()->basic_type();
4661       int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
4662       int elem_size = type2aelembytes(basic_elem_type);
4663       st->print("[%d]", (_offset - array_base)/elem_size);
4664     }
4665   }
4666   st->print(" *");
4667   if (_instance_id == InstanceTop)
4668     st->print(",iid=top");
4669   else if (_instance_id != InstanceBot)
4670     st->print(",iid=%d",_instance_id);
4671 
4672   dump_inline_depth(st);
4673   dump_speculative(st);
4674 }
4675 #endif
4676 
4677 bool TypeAryPtr::empty(void) const {
4678   if (_ary->empty())       return true;
4679   return TypeOopPtr::empty();
4680 }
4681 
4682 //------------------------------add_offset-------------------------------------
4683 const TypePtr *TypeAryPtr::add_offset(intptr_t offset) const {
4684   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
4685 }
4686 
4687 const Type *TypeAryPtr::remove_speculative() const {
4688   if (_speculative == NULL) {
4689     return this;
4690   }
4691   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4692   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, NULL, _inline_depth);
4693 }
4694 
4695 const TypePtr *TypeAryPtr::with_inline_depth(int depth) const {
4696   if (!UseInlineDepthForSpeculativeTypes) {
4697     return this;
4698   }
4699   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, _speculative, depth);
4700 }
4701 
4702 const TypePtr *TypeAryPtr::with_instance_id(int instance_id) const {
4703   assert(is_known_instance(), "should be known");
4704   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
4705 }
4706 
4707 //=============================================================================
4708 
4709 //------------------------------hash-------------------------------------------
4710 // Type-specific hashing function.
4711 int TypeNarrowPtr::hash(void) const {
4712   return _ptrtype->hash() + 7;
4713 }
4714 
4715 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
4716   return _ptrtype->singleton();
4717 }
4718 
4719 bool TypeNarrowPtr::empty(void) const {
4720   return _ptrtype->empty();
4721 }
4722 
4723 intptr_t TypeNarrowPtr::get_con() const {
4724   return _ptrtype->get_con();
4725 }
4726 
4727 bool TypeNarrowPtr::eq( const Type *t ) const {
4728   const TypeNarrowPtr* tc = isa_same_narrowptr(t);
4729   if (tc != NULL) {
4730     if (_ptrtype->base() != tc->_ptrtype->base()) {
4731       return false;
4732     }
4733     return tc->_ptrtype->eq(_ptrtype);
4734   }
4735   return false;
4736 }
4737 
4738 const Type *TypeNarrowPtr::xdual() const {    // Compute dual right now.
4739   const TypePtr* odual = _ptrtype->dual()->is_ptr();
4740   return make_same_narrowptr(odual);
4741 }
4742 
4743 
4744 const Type *TypeNarrowPtr::filter_helper(const Type *kills, bool include_speculative) const {
4745   if (isa_same_narrowptr(kills)) {
4746     const Type* ft =_ptrtype->filter_helper(is_same_narrowptr(kills)->_ptrtype, include_speculative);
4747     if (ft->empty())
4748       return Type::TOP;           // Canonical empty value
4749     if (ft->isa_ptr()) {
4750       return make_hash_same_narrowptr(ft->isa_ptr());
4751     }
4752     return ft;
4753   } else if (kills->isa_ptr()) {
4754     const Type* ft = _ptrtype->join_helper(kills, include_speculative);
4755     if (ft->empty())
4756       return Type::TOP;           // Canonical empty value
4757     return ft;
4758   } else {
4759     return Type::TOP;
4760   }
4761 }
4762 
4763 //------------------------------xmeet------------------------------------------
4764 // Compute the MEET of two types.  It returns a new Type object.
4765 const Type *TypeNarrowPtr::xmeet( const Type *t ) const {
4766   // Perform a fast test for common case; meeting the same types together.
4767   if( this == t ) return this;  // Meeting same type-rep?
4768 
4769   if (t->base() == base()) {
4770     const Type* result = _ptrtype->xmeet(t->make_ptr());
4771     if (result->isa_ptr()) {
4772       return make_hash_same_narrowptr(result->is_ptr());
4773     }
4774     return result;
4775   }
4776 
4777   // Current "this->_base" is NarrowKlass or NarrowOop
4778   switch (t->base()) {          // switch on original type
4779 
4780   case Int:                     // Mixing ints & oops happens when javac
4781   case Long:                    // reuses local variables
4782   case FloatTop:
4783   case FloatCon:
4784   case FloatBot:
4785   case DoubleTop:
4786   case DoubleCon:
4787   case DoubleBot:
4788   case AnyPtr:
4789   case RawPtr:
4790   case OopPtr:
4791   case InstPtr:
4792   case AryPtr:
4793   case MetadataPtr:
4794   case KlassPtr:
4795   case InstKlassPtr:
4796   case AryKlassPtr:
4797   case NarrowOop:
4798   case NarrowKlass:
4799 
4800   case Bottom:                  // Ye Olde Default
4801     return Type::BOTTOM;
4802   case Top:
4803     return this;
4804 
4805   default:                      // All else is a mistake
4806     typerr(t);
4807 
4808   } // End of switch
4809 
4810   return this;
4811 }
4812 
4813 #ifndef PRODUCT
4814 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
4815   _ptrtype->dump2(d, depth, st);
4816 }
4817 #endif
4818 
4819 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
4820 const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
4821 
4822 
4823 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
4824   return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();
4825 }
4826 
4827 const Type* TypeNarrowOop::remove_speculative() const {
4828   return make(_ptrtype->remove_speculative()->is_ptr());
4829 }
4830 
4831 const Type* TypeNarrowOop::cleanup_speculative() const {
4832   return make(_ptrtype->cleanup_speculative()->is_ptr());
4833 }
4834 
4835 #ifndef PRODUCT
4836 void TypeNarrowOop::dump2( Dict & d, uint depth, outputStream *st ) const {
4837   st->print("narrowoop: ");
4838   TypeNarrowPtr::dump2(d, depth, st);
4839 }
4840 #endif
4841 
4842 const TypeNarrowKlass *TypeNarrowKlass::NULL_PTR;
4843 
4844 const TypeNarrowKlass* TypeNarrowKlass::make(const TypePtr* type) {
4845   return (const TypeNarrowKlass*)(new TypeNarrowKlass(type))->hashcons();
4846 }
4847 
4848 #ifndef PRODUCT
4849 void TypeNarrowKlass::dump2( Dict & d, uint depth, outputStream *st ) const {
4850   st->print("narrowklass: ");
4851   TypeNarrowPtr::dump2(d, depth, st);
4852 }
4853 #endif
4854 
4855 
4856 //------------------------------eq---------------------------------------------
4857 // Structural equality check for Type representations
4858 bool TypeMetadataPtr::eq( const Type *t ) const {
4859   const TypeMetadataPtr *a = (const TypeMetadataPtr*)t;
4860   ciMetadata* one = metadata();
4861   ciMetadata* two = a->metadata();
4862   if (one == NULL || two == NULL) {
4863     return (one == two) && TypePtr::eq(t);
4864   } else {
4865     return one->equals(two) && TypePtr::eq(t);
4866   }
4867 }
4868 
4869 //------------------------------hash-------------------------------------------
4870 // Type-specific hashing function.
4871 int TypeMetadataPtr::hash(void) const {
4872   return
4873     (metadata() ? metadata()->hash() : 0) +
4874     TypePtr::hash();
4875 }
4876 
4877 //------------------------------singleton--------------------------------------
4878 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
4879 // constants
4880 bool TypeMetadataPtr::singleton(void) const {
4881   // detune optimizer to not generate constant metadata + constant offset as a constant!
4882   // TopPTR, Null, AnyNull, Constant are all singletons
4883   return (_offset == 0) && !below_centerline(_ptr);
4884 }
4885 
4886 //------------------------------add_offset-------------------------------------
4887 const TypePtr *TypeMetadataPtr::add_offset( intptr_t offset ) const {
4888   return make( _ptr, _metadata, xadd_offset(offset));
4889 }
4890 
4891 //-----------------------------filter------------------------------------------
4892 // Do not allow interface-vs.-noninterface joins to collapse to top.
4893 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
4894   const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
4895   if (ft == NULL || ft->empty())
4896     return Type::TOP;           // Canonical empty value
4897   return ft;
4898 }
4899 
4900  //------------------------------get_con----------------------------------------
4901 intptr_t TypeMetadataPtr::get_con() const {
4902   assert( _ptr == Null || _ptr == Constant, "" );
4903   assert( _offset >= 0, "" );
4904 
4905   if (_offset != 0) {
4906     // After being ported to the compiler interface, the compiler no longer
4907     // directly manipulates the addresses of oops.  Rather, it only has a pointer
4908     // to a handle at compile time.  This handle is embedded in the generated
4909     // code and dereferenced at the time the nmethod is made.  Until that time,
4910     // it is not reasonable to do arithmetic with the addresses of oops (we don't
4911     // have access to the addresses!).  This does not seem to currently happen,
4912     // but this assertion here is to help prevent its occurence.
4913     tty->print_cr("Found oop constant with non-zero offset");
4914     ShouldNotReachHere();
4915   }
4916 
4917   return (intptr_t)metadata()->constant_encoding();
4918 }
4919 
4920 //------------------------------cast_to_ptr_type-------------------------------
4921 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
4922   if( ptr == _ptr ) return this;
4923   return make(ptr, metadata(), _offset);
4924 }
4925 
4926 //------------------------------meet-------------------------------------------
4927 // Compute the MEET of two types.  It returns a new Type object.
4928 const Type *TypeMetadataPtr::xmeet( const Type *t ) const {
4929   // Perform a fast test for common case; meeting the same types together.
4930   if( this == t ) return this;  // Meeting same type-rep?
4931 
4932   // Current "this->_base" is OopPtr
4933   switch (t->base()) {          // switch on original type
4934 
4935   case Int:                     // Mixing ints & oops happens when javac
4936   case Long:                    // reuses local variables
4937   case FloatTop:
4938   case FloatCon:
4939   case FloatBot:
4940   case DoubleTop:
4941   case DoubleCon:
4942   case DoubleBot:
4943   case NarrowOop:
4944   case NarrowKlass:
4945   case Bottom:                  // Ye Olde Default
4946     return Type::BOTTOM;
4947   case Top:
4948     return this;
4949 
4950   default:                      // All else is a mistake
4951     typerr(t);
4952 
4953   case AnyPtr: {
4954     // Found an AnyPtr type vs self-OopPtr type
4955     const TypePtr *tp = t->is_ptr();
4956     int offset = meet_offset(tp->offset());
4957     PTR ptr = meet_ptr(tp->ptr());
4958     switch (tp->ptr()) {
4959     case Null:
4960       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
4961       // else fall through:
4962     case TopPTR:
4963     case AnyNull: {
4964       return make(ptr, _metadata, offset);
4965     }
4966     case BotPTR:
4967     case NotNull:
4968       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
4969     default: typerr(t);
4970     }
4971   }
4972 
4973   case RawPtr:
4974   case KlassPtr:
4975   case InstKlassPtr:
4976   case AryKlassPtr:
4977   case OopPtr:
4978   case InstPtr:
4979   case AryPtr:
4980     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
4981 
4982   case MetadataPtr: {
4983     const TypeMetadataPtr *tp = t->is_metadataptr();
4984     int offset = meet_offset(tp->offset());
4985     PTR tptr = tp->ptr();
4986     PTR ptr = meet_ptr(tptr);
4987     ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
4988     if (tptr == TopPTR || _ptr == TopPTR ||
4989         metadata()->equals(tp->metadata())) {
4990       return make(ptr, md, offset);
4991     }
4992     // metadata is different
4993     if( ptr == Constant ) {  // Cannot be equal constants, so...
4994       if( tptr == Constant && _ptr != Constant)  return t;
4995       if( _ptr == Constant && tptr != Constant)  return this;
4996       ptr = NotNull;            // Fall down in lattice
4997     }
4998     return make(ptr, NULL, offset);
4999     break;
5000   }
5001   } // End of switch
5002   return this;                  // Return the double constant
5003 }
5004 
5005 
5006 //------------------------------xdual------------------------------------------
5007 // Dual of a pure metadata pointer.
5008 const Type *TypeMetadataPtr::xdual() const {
5009   return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
5010 }
5011 
5012 //------------------------------dump2------------------------------------------
5013 #ifndef PRODUCT
5014 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5015   st->print("metadataptr:%s", ptr_msg[_ptr]);
5016   if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata()));
5017   switch( _offset ) {
5018   case OffsetTop: st->print("+top"); break;
5019   case OffsetBot: st->print("+any"); break;
5020   case         0: break;
5021   default:        st->print("+%d",_offset); break;
5022   }
5023 }
5024 #endif
5025 
5026 
5027 //=============================================================================
5028 // Convenience common pre-built type.
5029 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
5030 
5031 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset):
5032   TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
5033 }
5034 
5035 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
5036   return make(Constant, m, 0);
5037 }
5038 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
5039   return make(Constant, m, 0);
5040 }
5041 
5042 //------------------------------make-------------------------------------------
5043 // Create a meta data constant
5044 const TypeMetadataPtr *TypeMetadataPtr::make(PTR ptr, ciMetadata* m, int offset) {
5045   assert(m == NULL || !m->is_klass(), "wrong type");
5046   return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
5047 }
5048 
5049 
5050 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
5051   const Type* elem = _ary->_elem;
5052   bool xk = klass_is_exact();
5053   if (elem->make_oopptr() != NULL) {
5054     elem = elem->make_oopptr()->as_klass_type(try_for_exact);
5055     if (elem->is_klassptr()->klass_is_exact()) {
5056       xk = true;
5057     }
5058   }
5059   return TypeAryKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, elem, klass(), 0);
5060 }
5061 
5062 const TypeKlassPtr* TypeKlassPtr::make(ciKlass *klass) {
5063   if (klass->is_instance_klass()) {
5064     return TypeInstKlassPtr::make(klass);
5065   }
5066   return TypeAryKlassPtr::make(klass);
5067 }
5068 
5069 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* klass, int offset) {
5070   if (klass->is_instance_klass()) {
5071     return TypeInstKlassPtr::make(ptr, klass, offset);
5072   }
5073   return TypeAryKlassPtr::make(ptr, klass, offset);
5074 }
5075 
5076 
5077 //------------------------------TypeKlassPtr-----------------------------------
5078 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, int offset)
5079   : TypePtr(t, ptr, offset), _klass(klass) {
5080 }
5081 
5082 //------------------------------eq---------------------------------------------
5083 // Structural equality check for Type representations
5084 bool TypeKlassPtr::eq(const Type *t) const {
5085   const TypeKlassPtr *p = t->is_klassptr();
5086   return
5087     TypePtr::eq(p);
5088 }
5089 
5090 //------------------------------hash-------------------------------------------
5091 // Type-specific hashing function.
5092 int TypeKlassPtr::hash(void) const {
5093   return TypePtr::hash();
5094 }
5095 
5096 //------------------------------singleton--------------------------------------
5097 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5098 // constants
5099 bool TypeKlassPtr::singleton(void) const {
5100   // detune optimizer to not generate constant klass + constant offset as a constant!
5101   // TopPTR, Null, AnyNull, Constant are all singletons
5102   return (_offset == 0) && !below_centerline(_ptr);
5103 }
5104 
5105 // Do not allow interface-vs.-noninterface joins to collapse to top.
5106 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
5107   // logic here mirrors the one from TypeOopPtr::filter. See comments
5108   // there.
5109   const Type* ft = join_helper(kills, include_speculative);
5110   const TypeKlassPtr* ftkp = ft->isa_instklassptr();
5111   const TypeKlassPtr* ktkp = kills->isa_instklassptr();
5112 
5113   if (ft->empty()) {
5114     if (!empty() && ktkp != NULL && ktkp->klass()->is_loaded() && ktkp->klass()->is_interface())
5115       return kills;             // Uplift to interface
5116 
5117     return Type::TOP;           // Canonical empty value
5118   }
5119 
5120   // Interface klass type could be exact in opposite to interface type,
5121   // return it here instead of incorrect Constant ptr J/L/Object (6894807).
5122   if (ftkp != NULL && ktkp != NULL &&
5123       ftkp->is_loaded() &&  ftkp->klass()->is_interface() &&
5124       !ftkp->klass_is_exact() && // Keep exact interface klass
5125       ktkp->is_loaded() && !ktkp->klass()->is_interface()) {
5126     return ktkp->cast_to_ptr_type(ftkp->ptr());
5127   }
5128 
5129   return ft;
5130 }
5131 
5132 //------------------------------get_con----------------------------------------
5133 intptr_t TypeKlassPtr::get_con() const {
5134   assert( _ptr == Null || _ptr == Constant, "" );
5135   assert( _offset >= 0, "" );
5136 
5137   if (_offset != 0) {
5138     // After being ported to the compiler interface, the compiler no longer
5139     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5140     // to a handle at compile time.  This handle is embedded in the generated
5141     // code and dereferenced at the time the nmethod is made.  Until that time,
5142     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5143     // have access to the addresses!).  This does not seem to currently happen,
5144     // but this assertion here is to help prevent its occurence.
5145     tty->print_cr("Found oop constant with non-zero offset");
5146     ShouldNotReachHere();
5147   }
5148 
5149   return (intptr_t)klass()->constant_encoding();
5150 }
5151 
5152 //------------------------------dump2------------------------------------------
5153 // Dump Klass Type
5154 #ifndef PRODUCT
5155 void TypeKlassPtr::dump2(Dict & d, uint depth, outputStream *st) const {
5156   switch(_ptr) {
5157   case Constant:
5158     st->print("precise ");
5159   case NotNull:
5160     {
5161       const char *name = klass()->name()->as_utf8();
5162       if (name) {
5163         st->print("%s: " INTPTR_FORMAT, name, p2i(klass()));
5164       } else {
5165         ShouldNotReachHere();
5166       }
5167     }
5168   case BotPTR:
5169     if (!WizardMode && !Verbose && _ptr != Constant) break;
5170   case TopPTR:
5171   case AnyNull:
5172     st->print(":%s", ptr_msg[_ptr]);
5173     if (_ptr == Constant) st->print(":exact");
5174     break;
5175   default:
5176     break;
5177   }
5178 
5179   if (_offset) {               // Dump offset, if any
5180     if (_offset == OffsetBot)      { st->print("+any"); }
5181     else if (_offset == OffsetTop) { st->print("+unknown"); }
5182     else                            { st->print("+%d", _offset); }
5183   }
5184 
5185   st->print(" *");
5186 }
5187 #endif
5188 
5189 //=============================================================================
5190 // Convenience common pre-built types.
5191 
5192 // Not-null object klass or below
5193 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
5194 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
5195 
5196 bool TypeInstKlassPtr::eq(const Type *t) const {
5197   const TypeKlassPtr *p = t->is_klassptr();
5198   return
5199     klass()->equals(p->klass()) &&
5200     TypeKlassPtr::eq(p);
5201 }
5202 
5203 int TypeInstKlassPtr::hash(void) const {
5204   return java_add((jint)klass()->hash(), TypeKlassPtr::hash());
5205 }
5206 
5207 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, int offset) {
5208   TypeInstKlassPtr *r =
5209     (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, offset))->hashcons();
5210 
5211   return r;
5212 }
5213 
5214 //------------------------------add_offset-------------------------------------
5215 // Access internals of klass object
5216 const TypePtr *TypeInstKlassPtr::add_offset( intptr_t offset ) const {
5217   return make( _ptr, klass(), xadd_offset(offset) );
5218 }
5219 
5220 const TypeKlassPtr *TypeInstKlassPtr::with_offset(intptr_t offset) const {
5221   return make(_ptr, klass(), offset);
5222 }
5223 
5224 //------------------------------cast_to_ptr_type-------------------------------
5225 const TypePtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
5226   assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
5227   if( ptr == _ptr ) return this;
5228   return make(ptr, _klass, _offset);
5229 }
5230 
5231 
5232 bool TypeInstKlassPtr::must_be_exact() const {
5233   if (!_klass->is_loaded())  return false;
5234   ciInstanceKlass* ik = _klass->as_instance_klass();
5235   if (ik->is_final())  return true;  // cannot clear xk
5236   return false;
5237 }
5238 
5239 //-----------------------------cast_to_exactness-------------------------------
5240 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
5241   if (klass_is_exact == (_ptr == Constant)) return this;
5242   if (must_be_exact()) return this;
5243   ciKlass* k = klass();
5244   return make(klass_is_exact ? Constant : NotNull, k, _offset);
5245 }
5246 
5247 
5248 //-----------------------------as_instance_type--------------------------------
5249 // Corresponding type for an instance of the given class.
5250 // It will be NotNull, and exact if and only if the klass type is exact.
5251 const TypeOopPtr* TypeInstKlassPtr::as_instance_type() const {
5252   ciKlass* k = klass();
5253   bool    xk = klass_is_exact();
5254   return TypeInstPtr::make(TypePtr::BotPTR, k, xk, NULL, 0);
5255 }
5256 
5257 //------------------------------xmeet------------------------------------------
5258 // Compute the MEET of two types, return a new Type object.
5259 const Type    *TypeInstKlassPtr::xmeet( const Type *t ) const {
5260   // Perform a fast test for common case; meeting the same types together.
5261   if( this == t ) return this;  // Meeting same type-rep?
5262 
5263   // Current "this->_base" is Pointer
5264   switch (t->base()) {          // switch on original type
5265 
5266   case Int:                     // Mixing ints & oops happens when javac
5267   case Long:                    // reuses local variables
5268   case FloatTop:
5269   case FloatCon:
5270   case FloatBot:
5271   case DoubleTop:
5272   case DoubleCon:
5273   case DoubleBot:
5274   case NarrowOop:
5275   case NarrowKlass:
5276   case Bottom:                  // Ye Olde Default
5277     return Type::BOTTOM;
5278   case Top:
5279     return this;
5280 
5281   default:                      // All else is a mistake
5282     typerr(t);
5283 
5284   case AnyPtr: {                // Meeting to AnyPtrs
5285     // Found an AnyPtr type vs self-KlassPtr type
5286     const TypePtr *tp = t->is_ptr();
5287     int offset = meet_offset(tp->offset());
5288     PTR ptr = meet_ptr(tp->ptr());
5289     switch (tp->ptr()) {
5290     case TopPTR:
5291       return this;
5292     case Null:
5293       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5294     case AnyNull:
5295       return make( ptr, klass(), offset );
5296     case BotPTR:
5297     case NotNull:
5298       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5299     default: typerr(t);
5300     }
5301   }
5302 
5303   case RawPtr:
5304   case MetadataPtr:
5305   case OopPtr:
5306   case AryPtr:                  // Meet with AryPtr
5307   case InstPtr:                 // Meet with InstPtr
5308     return TypePtr::BOTTOM;
5309 
5310   //
5311   //             A-top         }
5312   //           /   |   \       }  Tops
5313   //       B-top A-any C-top   }
5314   //          | /  |  \ |      }  Any-nulls
5315   //       B-any   |   C-any   }
5316   //          |    |    |
5317   //       B-con A-con C-con   } constants; not comparable across classes
5318   //          |    |    |
5319   //       B-not   |   C-not   }
5320   //          | \  |  / |      }  not-nulls
5321   //       B-bot A-not C-bot   }
5322   //           \   |   /       }  Bottoms
5323   //             A-bot         }
5324   //
5325 
5326   case InstKlassPtr: {  // Meet two KlassPtr types
5327     const TypeInstKlassPtr *tkls = t->is_instklassptr();
5328     int  off     = meet_offset(tkls->offset());
5329     PTR  ptr     = meet_ptr(tkls->ptr());
5330     ciKlass* tkls_klass = tkls->klass();
5331     ciKlass* this_klass  = klass();
5332     bool tkls_xk = tkls->klass_is_exact();
5333     bool this_xk  = klass_is_exact();
5334 
5335     ciKlass* res_klass = NULL;
5336     bool res_xk = false;
5337     switch(meet_instptr(ptr, this_klass, tkls_klass, this_xk, tkls_xk, this->_ptr, tkls->_ptr, res_klass, res_xk)) {
5338       case UNLOADED:
5339         ShouldNotReachHere();
5340       case SUBTYPE:
5341       case NOT_SUBTYPE:
5342       case LCA:
5343       case QUICK: {
5344         assert(res_xk == (ptr == Constant), "");
5345         const Type* res1 = make(ptr, res_klass, off);
5346         return res1;
5347       }
5348       default:
5349         ShouldNotReachHere();
5350     }
5351   } // End of case KlassPtr
5352   case AryKlassPtr: {                // All arrays inherit from Object class
5353     const TypeAryKlassPtr *tp = t->is_aryklassptr();
5354     int offset = meet_offset(tp->offset());
5355     PTR ptr = meet_ptr(tp->ptr());
5356 
5357     switch (ptr) {
5358     case TopPTR:
5359     case AnyNull:                // Fall 'down' to dual of object klass
5360       // For instances when a subclass meets a superclass we fall
5361       // below the centerline when the superclass is exact. We need to
5362       // do the same here.
5363       if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
5364         return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset);
5365       } else {
5366         // cannot subclass, so the meet has to fall badly below the centerline
5367         ptr = NotNull;
5368         return make(ptr, ciEnv::current()->Object_klass(), offset);
5369       }
5370     case Constant:
5371     case NotNull:
5372     case BotPTR:                // Fall down to object klass
5373       // LCA is object_klass, but if we subclass from the top we can do better
5374       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
5375         // If 'this' (InstPtr) is above the centerline and it is Object class
5376         // then we can subclass in the Java class hierarchy.
5377         // For instances when a subclass meets a superclass we fall
5378         // below the centerline when the superclass is exact. We need
5379         // to do the same here.
5380         if (klass()->equals(ciEnv::current()->Object_klass())) {
5381           // that is, tp's array type is a subtype of my klass
5382           return TypeAryKlassPtr::make(ptr,
5383                                        tp->elem(), tp->klass(), offset);
5384         }
5385       }
5386       // The other case cannot happen, since I cannot be a subtype of an array.
5387       // The meet falls down to Object class below centerline.
5388       if( ptr == Constant )
5389          ptr = NotNull;
5390       return make(ptr, ciEnv::current()->Object_klass(), offset);
5391     default: typerr(t);
5392     }
5393   }
5394 
5395   } // End of switch
5396   return this;                  // Return the double constant
5397 }
5398 
5399 //------------------------------xdual------------------------------------------
5400 // Dual: compute field-by-field dual
5401 const Type    *TypeInstKlassPtr::xdual() const {
5402   return new TypeInstKlassPtr(dual_ptr(), klass(), dual_offset());
5403 }
5404 
5405 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, int offset) {
5406   return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset))->hashcons();
5407 }
5408 
5409 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, ciKlass* klass, int offset) {
5410   if (klass->is_obj_array_klass()) {
5411     // Element is an object array. Recursively call ourself.
5412     ciKlass* eklass = klass->as_obj_array_klass()->element_klass();
5413     const TypeKlassPtr *etype = TypeKlassPtr::make(eklass)->cast_to_exactness(false);
5414     return TypeAryKlassPtr::make(ptr, etype, NULL, offset);
5415   } else if (klass->is_type_array_klass()) {
5416     // Element is an typeArray
5417     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
5418     return TypeAryKlassPtr::make(ptr, etype, klass, offset);
5419   } else {
5420     ShouldNotReachHere();
5421     return NULL;
5422   }
5423 }
5424 
5425 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass) {
5426   return TypeAryKlassPtr::make(Constant, klass, 0);
5427 }
5428 
5429 //------------------------------eq---------------------------------------------
5430 // Structural equality check for Type representations
5431 bool TypeAryKlassPtr::eq(const Type *t) const {
5432   const TypeAryKlassPtr *p = t->is_aryklassptr();
5433   return
5434     _elem == p->_elem &&  // Check array
5435     TypeKlassPtr::eq(p);  // Check sub-parts
5436 }
5437 
5438 //------------------------------hash-------------------------------------------
5439 // Type-specific hashing function.
5440 int TypeAryKlassPtr::hash(void) const {
5441   return (intptr_t)_elem + TypeKlassPtr::hash();
5442 }
5443 
5444 //----------------------compute_klass------------------------------------------
5445 // Compute the defining klass for this class
5446 ciKlass* TypeAryPtr::compute_klass(DEBUG_ONLY(bool verify)) const {
5447   // Compute _klass based on element type.
5448   ciKlass* k_ary = NULL;
5449   const TypeInstPtr *tinst;
5450   const TypeAryPtr *tary;
5451   const Type* el = elem();
5452   if (el->isa_narrowoop()) {
5453     el = el->make_ptr();
5454   }
5455 
5456   // Get element klass
5457   if ((tinst = el->isa_instptr()) != NULL) {
5458     // Compute array klass from element klass
5459     k_ary = ciObjArrayKlass::make(tinst->klass());
5460   } else if ((tary = el->isa_aryptr()) != NULL) {
5461     // Compute array klass from element klass
5462     ciKlass* k_elem = tary->klass();
5463     // If element type is something like bottom[], k_elem will be null.
5464     if (k_elem != NULL)
5465       k_ary = ciObjArrayKlass::make(k_elem);
5466   } else if ((el->base() == Type::Top) ||
5467              (el->base() == Type::Bottom)) {
5468     // element type of Bottom occurs from meet of basic type
5469     // and object; Top occurs when doing join on Bottom.
5470     // Leave k_ary at NULL.
5471   } else {
5472     // Cannot compute array klass directly from basic type,
5473     // since subtypes of TypeInt all have basic type T_INT.
5474 #ifdef ASSERT
5475     if (verify && el->isa_int()) {
5476       // Check simple cases when verifying klass.
5477       BasicType bt = T_ILLEGAL;
5478       if (el == TypeInt::BYTE) {
5479         bt = T_BYTE;
5480       } else if (el == TypeInt::SHORT) {
5481         bt = T_SHORT;
5482       } else if (el == TypeInt::CHAR) {
5483         bt = T_CHAR;
5484       } else if (el == TypeInt::INT) {
5485         bt = T_INT;
5486       } else {
5487         return _klass; // just return specified klass
5488       }
5489       return ciTypeArrayKlass::make(bt);
5490     }
5491 #endif
5492     assert(!el->isa_int(),
5493            "integral arrays must be pre-equipped with a class");
5494     // Compute array klass directly from basic type
5495     k_ary = ciTypeArrayKlass::make(el->basic_type());
5496   }
5497   return k_ary;
5498 }
5499 
5500 //------------------------------klass------------------------------------------
5501 // Return the defining klass for this class
5502 ciKlass* TypeAryPtr::klass() const {
5503   if( _klass ) return _klass;   // Return cached value, if possible
5504 
5505   // Oops, need to compute _klass and cache it
5506   ciKlass* k_ary = compute_klass();
5507 
5508   if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) {
5509     // The _klass field acts as a cache of the underlying
5510     // ciKlass for this array type.  In order to set the field,
5511     // we need to cast away const-ness.
5512     //
5513     // IMPORTANT NOTE: we *never* set the _klass field for the
5514     // type TypeAryPtr::OOPS.  This Type is shared between all
5515     // active compilations.  However, the ciKlass which represents
5516     // this Type is *not* shared between compilations, so caching
5517     // this value would result in fetching a dangling pointer.
5518     //
5519     // Recomputing the underlying ciKlass for each request is
5520     // a bit less efficient than caching, but calls to
5521     // TypeAryPtr::OOPS->klass() are not common enough to matter.
5522     ((TypeAryPtr*)this)->_klass = k_ary;
5523     if (UseCompressedOops && k_ary != NULL && k_ary->is_obj_array_klass() &&
5524         _offset != 0 && _offset != arrayOopDesc::length_offset_in_bytes()) {
5525       ((TypeAryPtr*)this)->_is_ptr_to_narrowoop = true;
5526     }
5527   }
5528   return k_ary;
5529 }
5530 
5531 
5532 //------------------------------add_offset-------------------------------------
5533 // Access internals of klass object
5534 const TypePtr *TypeAryKlassPtr::add_offset(intptr_t offset) const {
5535   return make(_ptr, elem(), klass(), xadd_offset(offset));
5536 }
5537 
5538 const TypeKlassPtr *TypeAryKlassPtr::with_offset(intptr_t offset) const {
5539   return make(_ptr, elem(), klass(), offset);
5540 }
5541 
5542 //------------------------------cast_to_ptr_type-------------------------------
5543 const TypePtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
5544   assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
5545   if (ptr == _ptr) return this;
5546   return make(ptr, elem(), _klass, _offset);
5547 }
5548 
5549 bool TypeAryKlassPtr::must_be_exact() const {
5550   if (_elem == Type::BOTTOM) return false;
5551   if (_elem == Type::TOP   ) return false;
5552   const TypeKlassPtr*  tk = _elem->isa_klassptr();
5553   if (!tk)             return true;   // a primitive type, like int
5554   return tk->must_be_exact();
5555 }
5556 
5557 
5558 //-----------------------------cast_to_exactness-------------------------------
5559 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
5560   if (must_be_exact()) return this;  // cannot clear xk
5561   ciKlass* k = _klass;
5562   const Type* elem = this->elem();
5563   if (elem->isa_klassptr() && !klass_is_exact) {
5564     elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
5565   }
5566   return make(klass_is_exact ? Constant : NotNull, elem, k, _offset);
5567 }
5568 
5569 
5570 //-----------------------------as_instance_type--------------------------------
5571 // Corresponding type for an instance of the given class.
5572 // It will be exact if and only if the klass type is exact.
5573 const TypeOopPtr* TypeAryKlassPtr::as_instance_type() const {
5574   ciKlass* k = klass();
5575   bool    xk = klass_is_exact();
5576   const Type* el = elem()->isa_klassptr() ? elem()->is_klassptr()->as_instance_type()->is_oopptr()->cast_to_exactness(false) : elem();
5577   return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS), k, xk, 0);
5578 }
5579 
5580 
5581 //------------------------------xmeet------------------------------------------
5582 // Compute the MEET of two types, return a new Type object.
5583 const Type    *TypeAryKlassPtr::xmeet( const Type *t ) const {
5584   // Perform a fast test for common case; meeting the same types together.
5585   if( this == t ) return this;  // Meeting same type-rep?
5586 
5587   // Current "this->_base" is Pointer
5588   switch (t->base()) {          // switch on original type
5589 
5590   case Int:                     // Mixing ints & oops happens when javac
5591   case Long:                    // reuses local variables
5592   case FloatTop:
5593   case FloatCon:
5594   case FloatBot:
5595   case DoubleTop:
5596   case DoubleCon:
5597   case DoubleBot:
5598   case NarrowOop:
5599   case NarrowKlass:
5600   case Bottom:                  // Ye Olde Default
5601     return Type::BOTTOM;
5602   case Top:
5603     return this;
5604 
5605   default:                      // All else is a mistake
5606     typerr(t);
5607 
5608   case AnyPtr: {                // Meeting to AnyPtrs
5609     // Found an AnyPtr type vs self-KlassPtr type
5610     const TypePtr *tp = t->is_ptr();
5611     int offset = meet_offset(tp->offset());
5612     PTR ptr = meet_ptr(tp->ptr());
5613     switch (tp->ptr()) {
5614     case TopPTR:
5615       return this;
5616     case Null:
5617       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5618     case AnyNull:
5619       return make( ptr, _elem, klass(), offset );
5620     case BotPTR:
5621     case NotNull:
5622       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5623     default: typerr(t);
5624     }
5625   }
5626 
5627   case RawPtr:
5628   case MetadataPtr:
5629   case OopPtr:
5630   case AryPtr:                  // Meet with AryPtr
5631   case InstPtr:                 // Meet with InstPtr
5632     return TypePtr::BOTTOM;
5633 
5634   //
5635   //             A-top         }
5636   //           /   |   \       }  Tops
5637   //       B-top A-any C-top   }
5638   //          | /  |  \ |      }  Any-nulls
5639   //       B-any   |   C-any   }
5640   //          |    |    |
5641   //       B-con A-con C-con   } constants; not comparable across classes
5642   //          |    |    |
5643   //       B-not   |   C-not   }
5644   //          | \  |  / |      }  not-nulls
5645   //       B-bot A-not C-bot   }
5646   //           \   |   /       }  Bottoms
5647   //             A-bot         }
5648   //
5649 
5650   case AryKlassPtr: {  // Meet two KlassPtr types
5651     const TypeAryKlassPtr *tap = t->is_aryklassptr();
5652     int off = meet_offset(tap->offset());
5653     const Type* elem = _elem->meet(tap->_elem);
5654 
5655     PTR ptr = meet_ptr(tap->ptr());
5656     ciKlass* res_klass = NULL;
5657     bool res_xk = false;
5658     meet_aryptr(ptr, elem, this->klass(), tap->klass(), this->klass_is_exact(), tap->klass_is_exact(), this->ptr(), tap->ptr(), res_klass, res_xk);
5659     assert(res_xk == (ptr == Constant), "");
5660     return make(ptr, elem, res_klass, off);
5661   } // End of case KlassPtr
5662   case InstKlassPtr: {
5663     const TypeInstKlassPtr *tp = t->is_instklassptr();
5664     int offset = meet_offset(tp->offset());
5665     PTR ptr = meet_ptr(tp->ptr());
5666 
5667     switch (ptr) {
5668     case TopPTR:
5669     case AnyNull:                // Fall 'down' to dual of object klass
5670       // For instances when a subclass meets a superclass we fall
5671       // below the centerline when the superclass is exact. We need to
5672       // do the same here.
5673       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
5674         return TypeAryKlassPtr::make(ptr, _elem, _klass, offset);
5675       } else {
5676         // cannot subclass, so the meet has to fall badly below the centerline
5677         ptr = NotNull;
5678         return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), offset);
5679       }
5680     case Constant:
5681     case NotNull:
5682     case BotPTR:                // Fall down to object klass
5683       // LCA is object_klass, but if we subclass from the top we can do better
5684       if (above_centerline(tp->ptr())) {
5685         // If 'tp'  is above the centerline and it is Object class
5686         // then we can subclass in the Java class hierarchy.
5687         // For instances when a subclass meets a superclass we fall
5688         // below the centerline when the superclass is exact. We need
5689         // to do the same here.
5690         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
5691           // that is, my array type is a subtype of 'tp' klass
5692           return make(ptr, _elem, _klass, offset);
5693         }
5694       }
5695       // The other case cannot happen, since t cannot be a subtype of an array.
5696       // The meet falls down to Object class below centerline.
5697       if (ptr == Constant)
5698          ptr = NotNull;
5699       return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), offset);
5700     default: typerr(t);
5701     }
5702   }
5703 
5704   } // End of switch
5705   return this;                  // Return the double constant
5706 }
5707 
5708 //------------------------------xdual------------------------------------------
5709 // Dual: compute field-by-field dual
5710 const Type    *TypeAryKlassPtr::xdual() const {
5711   return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset());
5712 }
5713 
5714 //------------------------------get_con----------------------------------------
5715 ciKlass* TypeAryKlassPtr::klass() const {
5716   if (_klass != NULL) {
5717     return _klass;
5718   }
5719   ciKlass* k = NULL;
5720   if (elem()->isa_klassptr()) {
5721     k = elem()->is_klassptr()->klass();
5722     if (k != NULL) {
5723       k = ciObjArrayKlass::make(k);
5724       ((TypeAryKlassPtr*)this)->_klass = k;
5725     }
5726   } else if ((elem()->base() == Type::Top) ||
5727              (elem()->base() == Type::Bottom)) {
5728   } else {
5729     k = ciTypeArrayKlass::make(elem()->basic_type());
5730   }
5731   return k;
5732 }
5733 
5734 //------------------------------dump2------------------------------------------
5735 // Dump Klass Type
5736 #ifndef PRODUCT
5737 void TypeAryKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5738   switch( _ptr ) {
5739   case Constant:
5740     st->print("precise ");
5741   case NotNull:
5742     {
5743       st->print("[");
5744       _elem->dump2(d, depth, st);
5745       st->print(": ");
5746     }
5747   case BotPTR:
5748     if( !WizardMode && !Verbose && _ptr != Constant ) break;
5749   case TopPTR:
5750   case AnyNull:
5751     st->print(":%s", ptr_msg[_ptr]);
5752     if( _ptr == Constant ) st->print(":exact");
5753     break;
5754   default:
5755     break;
5756   }
5757 
5758   if( _offset ) {               // Dump offset, if any
5759     if( _offset == OffsetBot )      { st->print("+any"); }
5760     else if( _offset == OffsetTop ) { st->print("+unknown"); }
5761     else                            { st->print("+%d", _offset); }
5762   }
5763 
5764   st->print(" *");
5765 }
5766 #endif
5767 
5768 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
5769   const Type* elem = this->elem();
5770   dims = 1;
5771   while (elem->isa_aryklassptr()) {
5772     elem = elem->is_aryklassptr()->elem();
5773     dims++;
5774   }
5775   return elem;
5776 }
5777 
5778 //=============================================================================
5779 // Convenience common pre-built types.
5780 
5781 //------------------------------make-------------------------------------------
5782 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
5783   return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();
5784 }
5785 
5786 //------------------------------make-------------------------------------------
5787 const TypeFunc *TypeFunc::make(ciMethod* method) {
5788   Compile* C = Compile::current();
5789   const TypeFunc* tf = C->last_tf(method); // check cache
5790   if (tf != NULL)  return tf;  // The hit rate here is almost 50%.
5791   const TypeTuple *domain;
5792   if (method->is_static()) {
5793     domain = TypeTuple::make_domain(NULL, method->signature());
5794   } else {
5795     domain = TypeTuple::make_domain(method->holder(), method->signature());
5796   }
5797   const TypeTuple *range  = TypeTuple::make_range(method->signature());
5798   tf = TypeFunc::make(domain, range);
5799   C->set_last_tf(method, tf);  // fill cache
5800   return tf;
5801 }
5802 
5803 //------------------------------meet-------------------------------------------
5804 // Compute the MEET of two types.  It returns a new Type object.
5805 const Type *TypeFunc::xmeet( const Type *t ) const {
5806   // Perform a fast test for common case; meeting the same types together.
5807   if( this == t ) return this;  // Meeting same type-rep?
5808 
5809   // Current "this->_base" is Func
5810   switch (t->base()) {          // switch on original type
5811 
5812   case Bottom:                  // Ye Olde Default
5813     return t;
5814 
5815   default:                      // All else is a mistake
5816     typerr(t);
5817 
5818   case Top:
5819     break;
5820   }
5821   return this;                  // Return the double constant
5822 }
5823 
5824 //------------------------------xdual------------------------------------------
5825 // Dual: compute field-by-field dual
5826 const Type *TypeFunc::xdual() const {
5827   return this;
5828 }
5829 
5830 //------------------------------eq---------------------------------------------
5831 // Structural equality check for Type representations
5832 bool TypeFunc::eq( const Type *t ) const {
5833   const TypeFunc *a = (const TypeFunc*)t;
5834   return _domain == a->_domain &&
5835     _range == a->_range;
5836 }
5837 
5838 //------------------------------hash-------------------------------------------
5839 // Type-specific hashing function.
5840 int TypeFunc::hash(void) const {
5841   return (intptr_t)_domain + (intptr_t)_range;
5842 }
5843 
5844 //------------------------------dump2------------------------------------------
5845 // Dump Function Type
5846 #ifndef PRODUCT
5847 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
5848   if( _range->cnt() <= Parms )
5849     st->print("void");
5850   else {
5851     uint i;
5852     for (i = Parms; i < _range->cnt()-1; i++) {
5853       _range->field_at(i)->dump2(d,depth,st);
5854       st->print("/");
5855     }
5856     _range->field_at(i)->dump2(d,depth,st);
5857   }
5858   st->print(" ");
5859   st->print("( ");
5860   if( !depth || d[this] ) {     // Check for recursive dump
5861     st->print("...)");
5862     return;
5863   }
5864   d.Insert((void*)this,(void*)this);    // Stop recursion
5865   if (Parms < _domain->cnt())
5866     _domain->field_at(Parms)->dump2(d,depth-1,st);
5867   for (uint i = Parms+1; i < _domain->cnt(); i++) {
5868     st->print(", ");
5869     _domain->field_at(i)->dump2(d,depth-1,st);
5870   }
5871   st->print(" )");
5872 }
5873 #endif
5874 
5875 //------------------------------singleton--------------------------------------
5876 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5877 // constants (Ldi nodes).  Singletons are integer, float or double constants
5878 // or a single symbol.
5879 bool TypeFunc::singleton(void) const {
5880   return false;                 // Never a singleton
5881 }
5882 
5883 bool TypeFunc::empty(void) const {
5884   return false;                 // Never empty
5885 }
5886 
5887 
5888 BasicType TypeFunc::return_type() const{
5889   if (range()->cnt() == TypeFunc::Parms) {
5890     return T_VOID;
5891   }
5892   return range()->field_at(TypeFunc::Parms)->basic_type();
5893 }