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