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