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