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