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