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