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