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