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