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