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