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