1 /*
   2  * Copyright (c) 1997, 2016, 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/brooksPointer.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 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 #endif
 890 
 891 //------------------------------singleton--------------------------------------
 892 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
 893 // constants (Ldi nodes).  Singletons are integer, float or double constants.
 894 bool Type::singleton(void) const {
 895   return _base == Top || _base == Half;
 896 }
 897 
 898 //------------------------------empty------------------------------------------
 899 // TRUE if Type is a type with no values, FALSE otherwise.
 900 bool Type::empty(void) const {
 901   switch (_base) {
 902   case DoubleTop:
 903   case FloatTop:
 904   case Top:
 905     return true;
 906 
 907   case Half:
 908   case Abio:
 909   case Return_Address:
 910   case Memory:
 911   case Bottom:
 912   case FloatBot:
 913   case DoubleBot:
 914     return false;  // never a singleton, therefore never empty
 915   }
 916 
 917   ShouldNotReachHere();
 918   return false;
 919 }
 920 
 921 //------------------------------dump_stats-------------------------------------
 922 // Dump collected statistics to stderr
 923 #ifndef PRODUCT
 924 void Type::dump_stats() {
 925   tty->print("Types made: %d\n", type_dict()->Size());
 926 }
 927 #endif
 928 
 929 //------------------------------typerr-----------------------------------------
 930 void Type::typerr( const Type *t ) const {
 931 #ifndef PRODUCT
 932   tty->print("\nError mixing types: ");
 933   dump();
 934   tty->print(" and ");
 935   t->dump();
 936   tty->print("\n");
 937 #endif
 938   ShouldNotReachHere();
 939 }
 940 
 941 
 942 //=============================================================================
 943 // Convenience common pre-built types.
 944 const TypeF *TypeF::ZERO;       // Floating point zero
 945 const TypeF *TypeF::ONE;        // Floating point one
 946 
 947 //------------------------------make-------------------------------------------
 948 // Create a float constant
 949 const TypeF *TypeF::make(float f) {
 950   return (TypeF*)(new TypeF(f))->hashcons();
 951 }
 952 
 953 //------------------------------meet-------------------------------------------
 954 // Compute the MEET of two types.  It returns a new Type object.
 955 const Type *TypeF::xmeet( const Type *t ) const {
 956   // Perform a fast test for common case; meeting the same types together.
 957   if( this == t ) return this;  // Meeting same type-rep?
 958 
 959   // Current "this->_base" is FloatCon
 960   switch (t->base()) {          // Switch on original type
 961   case AnyPtr:                  // Mixing with oops happens when javac
 962   case RawPtr:                  // reuses local variables
 963   case OopPtr:
 964   case InstPtr:
 965   case AryPtr:
 966   case MetadataPtr:
 967   case KlassPtr:
 968   case NarrowOop:
 969   case NarrowKlass:
 970   case Int:
 971   case Long:
 972   case DoubleTop:
 973   case DoubleCon:
 974   case DoubleBot:
 975   case Bottom:                  // Ye Olde Default
 976     return Type::BOTTOM;
 977 
 978   case FloatBot:
 979     return t;
 980 
 981   default:                      // All else is a mistake
 982     typerr(t);
 983 
 984   case FloatCon:                // Float-constant vs Float-constant?
 985     if( jint_cast(_f) != jint_cast(t->getf()) )         // unequal constants?
 986                                 // must compare bitwise as positive zero, negative zero and NaN have
 987                                 // all the same representation in C++
 988       return FLOAT;             // Return generic float
 989                                 // Equal constants
 990   case Top:
 991   case FloatTop:
 992     break;                      // Return the float constant
 993   }
 994   return this;                  // Return the float constant
 995 }
 996 
 997 //------------------------------xdual------------------------------------------
 998 // Dual: symmetric
 999 const Type *TypeF::xdual() const {
1000   return this;
1001 }
1002 
1003 //------------------------------eq---------------------------------------------
1004 // Structural equality check for Type representations
1005 bool TypeF::eq(const Type *t) const {
1006   // Bitwise comparison to distinguish between +/-0. These values must be treated
1007   // as different to be consistent with C1 and the interpreter.
1008   return (jint_cast(_f) == jint_cast(t->getf()));
1009 }
1010 
1011 //------------------------------hash-------------------------------------------
1012 // Type-specific hashing function.
1013 int TypeF::hash(void) const {
1014   return *(int*)(&_f);
1015 }
1016 
1017 //------------------------------is_finite--------------------------------------
1018 // Has a finite value
1019 bool TypeF::is_finite() const {
1020   return g_isfinite(getf()) != 0;
1021 }
1022 
1023 //------------------------------is_nan-----------------------------------------
1024 // Is not a number (NaN)
1025 bool TypeF::is_nan()    const {
1026   return g_isnan(getf()) != 0;
1027 }
1028 
1029 //------------------------------dump2------------------------------------------
1030 // Dump float constant Type
1031 #ifndef PRODUCT
1032 void TypeF::dump2( Dict &d, uint depth, outputStream *st ) const {
1033   Type::dump2(d,depth, st);
1034   st->print("%f", _f);
1035 }
1036 #endif
1037 
1038 //------------------------------singleton--------------------------------------
1039 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
1040 // constants (Ldi nodes).  Singletons are integer, float or double constants
1041 // or a single symbol.
1042 bool TypeF::singleton(void) const {
1043   return true;                  // Always a singleton
1044 }
1045 
1046 bool TypeF::empty(void) const {
1047   return false;                 // always exactly a singleton
1048 }
1049 
1050 //=============================================================================
1051 // Convenience common pre-built types.
1052 const TypeD *TypeD::ZERO;       // Floating point zero
1053 const TypeD *TypeD::ONE;        // Floating point one
1054 
1055 //------------------------------make-------------------------------------------
1056 const TypeD *TypeD::make(double d) {
1057   return (TypeD*)(new TypeD(d))->hashcons();
1058 }
1059 
1060 //------------------------------meet-------------------------------------------
1061 // Compute the MEET of two types.  It returns a new Type object.
1062 const Type *TypeD::xmeet( const Type *t ) const {
1063   // Perform a fast test for common case; meeting the same types together.
1064   if( this == t ) return this;  // Meeting same type-rep?
1065 
1066   // Current "this->_base" is DoubleCon
1067   switch (t->base()) {          // Switch on original type
1068   case AnyPtr:                  // Mixing with oops happens when javac
1069   case RawPtr:                  // reuses local variables
1070   case OopPtr:
1071   case InstPtr:
1072   case AryPtr:
1073   case MetadataPtr:
1074   case KlassPtr:
1075   case NarrowOop:
1076   case NarrowKlass:
1077   case Int:
1078   case Long:
1079   case FloatTop:
1080   case FloatCon:
1081   case FloatBot:
1082   case Bottom:                  // Ye Olde Default
1083     return Type::BOTTOM;
1084 
1085   case DoubleBot:
1086     return t;
1087 
1088   default:                      // All else is a mistake
1089     typerr(t);
1090 
1091   case DoubleCon:               // Double-constant vs Double-constant?
1092     if( jlong_cast(_d) != jlong_cast(t->getd()) )       // unequal constants? (see comment in TypeF::xmeet)
1093       return DOUBLE;            // Return generic double
1094   case Top:
1095   case DoubleTop:
1096     break;
1097   }
1098   return this;                  // Return the double constant
1099 }
1100 
1101 //------------------------------xdual------------------------------------------
1102 // Dual: symmetric
1103 const Type *TypeD::xdual() const {
1104   return this;
1105 }
1106 
1107 //------------------------------eq---------------------------------------------
1108 // Structural equality check for Type representations
1109 bool TypeD::eq(const Type *t) const {
1110   // Bitwise comparison to distinguish between +/-0. These values must be treated
1111   // as different to be consistent with C1 and the interpreter.
1112   return (jlong_cast(_d) == jlong_cast(t->getd()));
1113 }
1114 
1115 //------------------------------hash-------------------------------------------
1116 // Type-specific hashing function.
1117 int TypeD::hash(void) const {
1118   return *(int*)(&_d);
1119 }
1120 
1121 //------------------------------is_finite--------------------------------------
1122 // Has a finite value
1123 bool TypeD::is_finite() const {
1124   return g_isfinite(getd()) != 0;
1125 }
1126 
1127 //------------------------------is_nan-----------------------------------------
1128 // Is not a number (NaN)
1129 bool TypeD::is_nan()    const {
1130   return g_isnan(getd()) != 0;
1131 }
1132 
1133 //------------------------------dump2------------------------------------------
1134 // Dump double constant Type
1135 #ifndef PRODUCT
1136 void TypeD::dump2( Dict &d, uint depth, outputStream *st ) const {
1137   Type::dump2(d,depth,st);
1138   st->print("%f", _d);
1139 }
1140 #endif
1141 
1142 //------------------------------singleton--------------------------------------
1143 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
1144 // constants (Ldi nodes).  Singletons are integer, float or double constants
1145 // or a single symbol.
1146 bool TypeD::singleton(void) const {
1147   return true;                  // Always a singleton
1148 }
1149 
1150 bool TypeD::empty(void) const {
1151   return false;                 // always exactly a singleton
1152 }
1153 
1154 //=============================================================================
1155 // Convience common pre-built types.
1156 const TypeInt *TypeInt::MINUS_1;// -1
1157 const TypeInt *TypeInt::ZERO;   // 0
1158 const TypeInt *TypeInt::ONE;    // 1
1159 const TypeInt *TypeInt::BOOL;   // 0 or 1, FALSE or TRUE.
1160 const TypeInt *TypeInt::CC;     // -1,0 or 1, condition codes
1161 const TypeInt *TypeInt::CC_LT;  // [-1]  == MINUS_1
1162 const TypeInt *TypeInt::CC_GT;  // [1]   == ONE
1163 const TypeInt *TypeInt::CC_EQ;  // [0]   == ZERO
1164 const TypeInt *TypeInt::CC_LE;  // [-1,0]
1165 const TypeInt *TypeInt::CC_GE;  // [0,1] == BOOL (!)
1166 const TypeInt *TypeInt::BYTE;   // Bytes, -128 to 127
1167 const TypeInt *TypeInt::UBYTE;  // Unsigned Bytes, 0 to 255
1168 const TypeInt *TypeInt::CHAR;   // Java chars, 0-65535
1169 const TypeInt *TypeInt::SHORT;  // Java shorts, -32768-32767
1170 const TypeInt *TypeInt::POS;    // Positive 32-bit integers or zero
1171 const TypeInt *TypeInt::POS1;   // Positive 32-bit integers
1172 const TypeInt *TypeInt::INT;    // 32-bit integers
1173 const TypeInt *TypeInt::SYMINT; // symmetric range [-max_jint..max_jint]
1174 const TypeInt *TypeInt::TYPE_DOMAIN; // alias for TypeInt::INT
1175 
1176 //------------------------------TypeInt----------------------------------------
1177 TypeInt::TypeInt( jint lo, jint hi, int w ) : Type(Int), _lo(lo), _hi(hi), _widen(w) {
1178 }
1179 
1180 //------------------------------make-------------------------------------------
1181 const TypeInt *TypeInt::make( jint lo ) {
1182   return (TypeInt*)(new TypeInt(lo,lo,WidenMin))->hashcons();
1183 }
1184 
1185 static int normalize_int_widen( jint lo, jint hi, int w ) {
1186   // Certain normalizations keep us sane when comparing types.
1187   // The 'SMALLINT' covers constants and also CC and its relatives.
1188   if (lo <= hi) {
1189     if (((juint)hi - lo) <= SMALLINT)  w = Type::WidenMin;
1190     if (((juint)hi - lo) >= max_juint) w = Type::WidenMax; // TypeInt::INT
1191   } else {
1192     if (((juint)lo - hi) <= SMALLINT)  w = Type::WidenMin;
1193     if (((juint)lo - hi) >= max_juint) w = Type::WidenMin; // dual TypeInt::INT
1194   }
1195   return w;
1196 }
1197 
1198 const TypeInt *TypeInt::make( jint lo, jint hi, int w ) {
1199   w = normalize_int_widen(lo, hi, w);
1200   return (TypeInt*)(new TypeInt(lo,hi,w))->hashcons();
1201 }
1202 
1203 //------------------------------meet-------------------------------------------
1204 // Compute the MEET of two types.  It returns a new Type representation object
1205 // with reference count equal to the number of Types pointing at it.
1206 // Caller should wrap a Types around it.
1207 const Type *TypeInt::xmeet( const Type *t ) const {
1208   // Perform a fast test for common case; meeting the same types together.
1209   if( this == t ) return this;  // Meeting same type?
1210 
1211   // Currently "this->_base" is a TypeInt
1212   switch (t->base()) {          // Switch on original type
1213   case AnyPtr:                  // Mixing with oops happens when javac
1214   case RawPtr:                  // reuses local variables
1215   case OopPtr:
1216   case InstPtr:
1217   case AryPtr:
1218   case MetadataPtr:
1219   case KlassPtr:
1220   case NarrowOop:
1221   case NarrowKlass:
1222   case Long:
1223   case FloatTop:
1224   case FloatCon:
1225   case FloatBot:
1226   case DoubleTop:
1227   case DoubleCon:
1228   case DoubleBot:
1229   case Bottom:                  // Ye Olde Default
1230     return Type::BOTTOM;
1231   default:                      // All else is a mistake
1232     typerr(t);
1233   case Top:                     // No change
1234     return this;
1235   case Int:                     // Int vs Int?
1236     break;
1237   }
1238 
1239   // Expand covered set
1240   const TypeInt *r = t->is_int();
1241   return make( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) );
1242 }
1243 
1244 //------------------------------xdual------------------------------------------
1245 // Dual: reverse hi & lo; flip widen
1246 const Type *TypeInt::xdual() const {
1247   int w = normalize_int_widen(_hi,_lo, WidenMax-_widen);
1248   return new TypeInt(_hi,_lo,w);
1249 }
1250 
1251 //------------------------------widen------------------------------------------
1252 // Only happens for optimistic top-down optimizations.
1253 const Type *TypeInt::widen( const Type *old, const Type* limit ) const {
1254   // Coming from TOP or such; no widening
1255   if( old->base() != Int ) return this;
1256   const TypeInt *ot = old->is_int();
1257 
1258   // If new guy is equal to old guy, no widening
1259   if( _lo == ot->_lo && _hi == ot->_hi )
1260     return old;
1261 
1262   // If new guy contains old, then we widened
1263   if( _lo <= ot->_lo && _hi >= ot->_hi ) {
1264     // New contains old
1265     // If new guy is already wider than old, no widening
1266     if( _widen > ot->_widen ) return this;
1267     // If old guy was a constant, do not bother
1268     if (ot->_lo == ot->_hi)  return this;
1269     // Now widen new guy.
1270     // Check for widening too far
1271     if (_widen == WidenMax) {
1272       int max = max_jint;
1273       int min = min_jint;
1274       if (limit->isa_int()) {
1275         max = limit->is_int()->_hi;
1276         min = limit->is_int()->_lo;
1277       }
1278       if (min < _lo && _hi < max) {
1279         // If neither endpoint is extremal yet, push out the endpoint
1280         // which is closer to its respective limit.
1281         if (_lo >= 0 ||                 // easy common case
1282             (juint)(_lo - min) >= (juint)(max - _hi)) {
1283           // Try to widen to an unsigned range type of 31 bits:
1284           return make(_lo, max, WidenMax);
1285         } else {
1286           return make(min, _hi, WidenMax);
1287         }
1288       }
1289       return TypeInt::INT;
1290     }
1291     // Returned widened new guy
1292     return make(_lo,_hi,_widen+1);
1293   }
1294 
1295   // If old guy contains new, then we probably widened too far & dropped to
1296   // bottom.  Return the wider fellow.
1297   if ( ot->_lo <= _lo && ot->_hi >= _hi )
1298     return old;
1299 
1300   //fatal("Integer value range is not subset");
1301   //return this;
1302   return TypeInt::INT;
1303 }
1304 
1305 //------------------------------narrow---------------------------------------
1306 // Only happens for pessimistic optimizations.
1307 const Type *TypeInt::narrow( const Type *old ) const {
1308   if (_lo >= _hi)  return this;   // already narrow enough
1309   if (old == NULL)  return this;
1310   const TypeInt* ot = old->isa_int();
1311   if (ot == NULL)  return this;
1312   jint olo = ot->_lo;
1313   jint ohi = ot->_hi;
1314 
1315   // If new guy is equal to old guy, no narrowing
1316   if (_lo == olo && _hi == ohi)  return old;
1317 
1318   // If old guy was maximum range, allow the narrowing
1319   if (olo == min_jint && ohi == max_jint)  return this;
1320 
1321   if (_lo < olo || _hi > ohi)
1322     return this;                // doesn't narrow; pretty wierd
1323 
1324   // The new type narrows the old type, so look for a "death march".
1325   // See comments on PhaseTransform::saturate.
1326   juint nrange = _hi - _lo;
1327   juint orange = ohi - olo;
1328   if (nrange < max_juint - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
1329     // Use the new type only if the range shrinks a lot.
1330     // We do not want the optimizer computing 2^31 point by point.
1331     return old;
1332   }
1333 
1334   return this;
1335 }
1336 
1337 //-----------------------------filter------------------------------------------
1338 const Type *TypeInt::filter_helper(const Type *kills, bool include_speculative) const {
1339   const TypeInt* ft = join_helper(kills, include_speculative)->isa_int();
1340   if (ft == NULL || ft->empty())
1341     return Type::TOP;           // Canonical empty value
1342   if (ft->_widen < this->_widen) {
1343     // Do not allow the value of kill->_widen to affect the outcome.
1344     // The widen bits must be allowed to run freely through the graph.
1345     ft = TypeInt::make(ft->_lo, ft->_hi, this->_widen);
1346   }
1347   return ft;
1348 }
1349 
1350 //------------------------------eq---------------------------------------------
1351 // Structural equality check for Type representations
1352 bool TypeInt::eq( const Type *t ) const {
1353   const TypeInt *r = t->is_int(); // Handy access
1354   return r->_lo == _lo && r->_hi == _hi && r->_widen == _widen;
1355 }
1356 
1357 //------------------------------hash-------------------------------------------
1358 // Type-specific hashing function.
1359 int TypeInt::hash(void) const {
1360   return _lo+_hi+_widen+(int)Type::Int;
1361 }
1362 
1363 //------------------------------is_finite--------------------------------------
1364 // Has a finite value
1365 bool TypeInt::is_finite() const {
1366   return true;
1367 }
1368 
1369 //------------------------------dump2------------------------------------------
1370 // Dump TypeInt
1371 #ifndef PRODUCT
1372 static const char* intname(char* buf, jint n) {
1373   if (n == min_jint)
1374     return "min";
1375   else if (n < min_jint + 10000)
1376     sprintf(buf, "min+" INT32_FORMAT, n - min_jint);
1377   else if (n == max_jint)
1378     return "max";
1379   else if (n > max_jint - 10000)
1380     sprintf(buf, "max-" INT32_FORMAT, max_jint - n);
1381   else
1382     sprintf(buf, INT32_FORMAT, n);
1383   return buf;
1384 }
1385 
1386 void TypeInt::dump2( Dict &d, uint depth, outputStream *st ) const {
1387   char buf[40], buf2[40];
1388   if (_lo == min_jint && _hi == max_jint)
1389     st->print("int");
1390   else if (is_con())
1391     st->print("int:%s", intname(buf, get_con()));
1392   else if (_lo == BOOL->_lo && _hi == BOOL->_hi)
1393     st->print("bool");
1394   else if (_lo == BYTE->_lo && _hi == BYTE->_hi)
1395     st->print("byte");
1396   else if (_lo == CHAR->_lo && _hi == CHAR->_hi)
1397     st->print("char");
1398   else if (_lo == SHORT->_lo && _hi == SHORT->_hi)
1399     st->print("short");
1400   else if (_hi == max_jint)
1401     st->print("int:>=%s", intname(buf, _lo));
1402   else if (_lo == min_jint)
1403     st->print("int:<=%s", intname(buf, _hi));
1404   else
1405     st->print("int:%s..%s", intname(buf, _lo), intname(buf2, _hi));
1406 
1407   if (_widen != 0 && this != TypeInt::INT)
1408     st->print(":%.*s", _widen, "wwww");
1409 }
1410 #endif
1411 
1412 //------------------------------singleton--------------------------------------
1413 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
1414 // constants.
1415 bool TypeInt::singleton(void) const {
1416   return _lo >= _hi;
1417 }
1418 
1419 bool TypeInt::empty(void) const {
1420   return _lo > _hi;
1421 }
1422 
1423 //=============================================================================
1424 // Convenience common pre-built types.
1425 const TypeLong *TypeLong::MINUS_1;// -1
1426 const TypeLong *TypeLong::ZERO; // 0
1427 const TypeLong *TypeLong::ONE;  // 1
1428 const TypeLong *TypeLong::POS;  // >=0
1429 const TypeLong *TypeLong::LONG; // 64-bit integers
1430 const TypeLong *TypeLong::INT;  // 32-bit subrange
1431 const TypeLong *TypeLong::UINT; // 32-bit unsigned subrange
1432 const TypeLong *TypeLong::TYPE_DOMAIN; // alias for TypeLong::LONG
1433 
1434 //------------------------------TypeLong---------------------------------------
1435 TypeLong::TypeLong( jlong lo, jlong hi, int w ) : Type(Long), _lo(lo), _hi(hi), _widen(w) {
1436 }
1437 
1438 //------------------------------make-------------------------------------------
1439 const TypeLong *TypeLong::make( jlong lo ) {
1440   return (TypeLong*)(new TypeLong(lo,lo,WidenMin))->hashcons();
1441 }
1442 
1443 static int normalize_long_widen( jlong lo, jlong hi, int w ) {
1444   // Certain normalizations keep us sane when comparing types.
1445   // The 'SMALLINT' covers constants.
1446   if (lo <= hi) {
1447     if (((julong)hi - lo) <= SMALLINT)   w = Type::WidenMin;
1448     if (((julong)hi - lo) >= max_julong) w = Type::WidenMax; // TypeLong::LONG
1449   } else {
1450     if (((julong)lo - hi) <= SMALLINT)   w = Type::WidenMin;
1451     if (((julong)lo - hi) >= max_julong) w = Type::WidenMin; // dual TypeLong::LONG
1452   }
1453   return w;
1454 }
1455 
1456 const TypeLong *TypeLong::make( jlong lo, jlong hi, int w ) {
1457   w = normalize_long_widen(lo, hi, w);
1458   return (TypeLong*)(new TypeLong(lo,hi,w))->hashcons();
1459 }
1460 
1461 
1462 //------------------------------meet-------------------------------------------
1463 // Compute the MEET of two types.  It returns a new Type representation object
1464 // with reference count equal to the number of Types pointing at it.
1465 // Caller should wrap a Types around it.
1466 const Type *TypeLong::xmeet( const Type *t ) const {
1467   // Perform a fast test for common case; meeting the same types together.
1468   if( this == t ) return this;  // Meeting same type?
1469 
1470   // Currently "this->_base" is a TypeLong
1471   switch (t->base()) {          // Switch on original type
1472   case AnyPtr:                  // Mixing with oops happens when javac
1473   case RawPtr:                  // reuses local variables
1474   case OopPtr:
1475   case InstPtr:
1476   case AryPtr:
1477   case MetadataPtr:
1478   case KlassPtr:
1479   case NarrowOop:
1480   case NarrowKlass:
1481   case Int:
1482   case FloatTop:
1483   case FloatCon:
1484   case FloatBot:
1485   case DoubleTop:
1486   case DoubleCon:
1487   case DoubleBot:
1488   case Bottom:                  // Ye Olde Default
1489     return Type::BOTTOM;
1490   default:                      // All else is a mistake
1491     typerr(t);
1492   case Top:                     // No change
1493     return this;
1494   case Long:                    // Long vs Long?
1495     break;
1496   }
1497 
1498   // Expand covered set
1499   const TypeLong *r = t->is_long(); // Turn into a TypeLong
1500   return make( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) );
1501 }
1502 
1503 //------------------------------xdual------------------------------------------
1504 // Dual: reverse hi & lo; flip widen
1505 const Type *TypeLong::xdual() const {
1506   int w = normalize_long_widen(_hi,_lo, WidenMax-_widen);
1507   return new TypeLong(_hi,_lo,w);
1508 }
1509 
1510 //------------------------------widen------------------------------------------
1511 // Only happens for optimistic top-down optimizations.
1512 const Type *TypeLong::widen( const Type *old, const Type* limit ) const {
1513   // Coming from TOP or such; no widening
1514   if( old->base() != Long ) return this;
1515   const TypeLong *ot = old->is_long();
1516 
1517   // If new guy is equal to old guy, no widening
1518   if( _lo == ot->_lo && _hi == ot->_hi )
1519     return old;
1520 
1521   // If new guy contains old, then we widened
1522   if( _lo <= ot->_lo && _hi >= ot->_hi ) {
1523     // New contains old
1524     // If new guy is already wider than old, no widening
1525     if( _widen > ot->_widen ) return this;
1526     // If old guy was a constant, do not bother
1527     if (ot->_lo == ot->_hi)  return this;
1528     // Now widen new guy.
1529     // Check for widening too far
1530     if (_widen == WidenMax) {
1531       jlong max = max_jlong;
1532       jlong min = min_jlong;
1533       if (limit->isa_long()) {
1534         max = limit->is_long()->_hi;
1535         min = limit->is_long()->_lo;
1536       }
1537       if (min < _lo && _hi < max) {
1538         // If neither endpoint is extremal yet, push out the endpoint
1539         // which is closer to its respective limit.
1540         if (_lo >= 0 ||                 // easy common case
1541             (julong)(_lo - min) >= (julong)(max - _hi)) {
1542           // Try to widen to an unsigned range type of 32/63 bits:
1543           if (max >= max_juint && _hi < max_juint)
1544             return make(_lo, max_juint, WidenMax);
1545           else
1546             return make(_lo, max, WidenMax);
1547         } else {
1548           return make(min, _hi, WidenMax);
1549         }
1550       }
1551       return TypeLong::LONG;
1552     }
1553     // Returned widened new guy
1554     return make(_lo,_hi,_widen+1);
1555   }
1556 
1557   // If old guy contains new, then we probably widened too far & dropped to
1558   // bottom.  Return the wider fellow.
1559   if ( ot->_lo <= _lo && ot->_hi >= _hi )
1560     return old;
1561 
1562   //  fatal("Long value range is not subset");
1563   // return this;
1564   return TypeLong::LONG;
1565 }
1566 
1567 //------------------------------narrow----------------------------------------
1568 // Only happens for pessimistic optimizations.
1569 const Type *TypeLong::narrow( const Type *old ) const {
1570   if (_lo >= _hi)  return this;   // already narrow enough
1571   if (old == NULL)  return this;
1572   const TypeLong* ot = old->isa_long();
1573   if (ot == NULL)  return this;
1574   jlong olo = ot->_lo;
1575   jlong ohi = ot->_hi;
1576 
1577   // If new guy is equal to old guy, no narrowing
1578   if (_lo == olo && _hi == ohi)  return old;
1579 
1580   // If old guy was maximum range, allow the narrowing
1581   if (olo == min_jlong && ohi == max_jlong)  return this;
1582 
1583   if (_lo < olo || _hi > ohi)
1584     return this;                // doesn't narrow; pretty wierd
1585 
1586   // The new type narrows the old type, so look for a "death march".
1587   // See comments on PhaseTransform::saturate.
1588   julong nrange = _hi - _lo;
1589   julong orange = ohi - olo;
1590   if (nrange < max_julong - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
1591     // Use the new type only if the range shrinks a lot.
1592     // We do not want the optimizer computing 2^31 point by point.
1593     return old;
1594   }
1595 
1596   return this;
1597 }
1598 
1599 //-----------------------------filter------------------------------------------
1600 const Type *TypeLong::filter_helper(const Type *kills, bool include_speculative) const {
1601   const TypeLong* ft = join_helper(kills, include_speculative)->isa_long();
1602   if (ft == NULL || ft->empty())
1603     return Type::TOP;           // Canonical empty value
1604   if (ft->_widen < this->_widen) {
1605     // Do not allow the value of kill->_widen to affect the outcome.
1606     // The widen bits must be allowed to run freely through the graph.
1607     ft = TypeLong::make(ft->_lo, ft->_hi, this->_widen);
1608   }
1609   return ft;
1610 }
1611 
1612 //------------------------------eq---------------------------------------------
1613 // Structural equality check for Type representations
1614 bool TypeLong::eq( const Type *t ) const {
1615   const TypeLong *r = t->is_long(); // Handy access
1616   return r->_lo == _lo &&  r->_hi == _hi  && r->_widen == _widen;
1617 }
1618 
1619 //------------------------------hash-------------------------------------------
1620 // Type-specific hashing function.
1621 int TypeLong::hash(void) const {
1622   return (int)(_lo+_hi+_widen+(int)Type::Long);
1623 }
1624 
1625 //------------------------------is_finite--------------------------------------
1626 // Has a finite value
1627 bool TypeLong::is_finite() const {
1628   return true;
1629 }
1630 
1631 //------------------------------dump2------------------------------------------
1632 // Dump TypeLong
1633 #ifndef PRODUCT
1634 static const char* longnamenear(jlong x, const char* xname, char* buf, jlong n) {
1635   if (n > x) {
1636     if (n >= x + 10000)  return NULL;
1637     sprintf(buf, "%s+" JLONG_FORMAT, xname, n - x);
1638   } else if (n < x) {
1639     if (n <= x - 10000)  return NULL;
1640     sprintf(buf, "%s-" JLONG_FORMAT, xname, x - n);
1641   } else {
1642     return xname;
1643   }
1644   return buf;
1645 }
1646 
1647 static const char* longname(char* buf, jlong n) {
1648   const char* str;
1649   if (n == min_jlong)
1650     return "min";
1651   else if (n < min_jlong + 10000)
1652     sprintf(buf, "min+" JLONG_FORMAT, n - min_jlong);
1653   else if (n == max_jlong)
1654     return "max";
1655   else if (n > max_jlong - 10000)
1656     sprintf(buf, "max-" JLONG_FORMAT, max_jlong - n);
1657   else if ((str = longnamenear(max_juint, "maxuint", buf, n)) != NULL)
1658     return str;
1659   else if ((str = longnamenear(max_jint, "maxint", buf, n)) != NULL)
1660     return str;
1661   else if ((str = longnamenear(min_jint, "minint", buf, n)) != NULL)
1662     return str;
1663   else
1664     sprintf(buf, JLONG_FORMAT, n);
1665   return buf;
1666 }
1667 
1668 void TypeLong::dump2( Dict &d, uint depth, outputStream *st ) const {
1669   char buf[80], buf2[80];
1670   if (_lo == min_jlong && _hi == max_jlong)
1671     st->print("long");
1672   else if (is_con())
1673     st->print("long:%s", longname(buf, get_con()));
1674   else if (_hi == max_jlong)
1675     st->print("long:>=%s", longname(buf, _lo));
1676   else if (_lo == min_jlong)
1677     st->print("long:<=%s", longname(buf, _hi));
1678   else
1679     st->print("long:%s..%s", longname(buf, _lo), longname(buf2, _hi));
1680 
1681   if (_widen != 0 && this != TypeLong::LONG)
1682     st->print(":%.*s", _widen, "wwww");
1683 }
1684 #endif
1685 
1686 //------------------------------singleton--------------------------------------
1687 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
1688 // constants
1689 bool TypeLong::singleton(void) const {
1690   return _lo >= _hi;
1691 }
1692 
1693 bool TypeLong::empty(void) const {
1694   return _lo > _hi;
1695 }
1696 
1697 //=============================================================================
1698 // Convenience common pre-built types.
1699 const TypeTuple *TypeTuple::IFBOTH;     // Return both arms of IF as reachable
1700 const TypeTuple *TypeTuple::IFFALSE;
1701 const TypeTuple *TypeTuple::IFTRUE;
1702 const TypeTuple *TypeTuple::IFNEITHER;
1703 const TypeTuple *TypeTuple::LOOPBODY;
1704 const TypeTuple *TypeTuple::MEMBAR;
1705 const TypeTuple *TypeTuple::STORECONDITIONAL;
1706 const TypeTuple *TypeTuple::START_I2C;
1707 const TypeTuple *TypeTuple::INT_PAIR;
1708 const TypeTuple *TypeTuple::LONG_PAIR;
1709 const TypeTuple *TypeTuple::INT_CC_PAIR;
1710 const TypeTuple *TypeTuple::LONG_CC_PAIR;
1711 
1712 
1713 //------------------------------make-------------------------------------------
1714 // Make a TypeTuple from the range of a method signature
1715 const TypeTuple *TypeTuple::make_range(ciSignature* sig) {
1716   ciType* return_type = sig->return_type();
1717   uint total_fields = TypeFunc::Parms + return_type->size();
1718   const Type **field_array = fields(total_fields);
1719   switch (return_type->basic_type()) {
1720   case T_LONG:
1721     field_array[TypeFunc::Parms]   = TypeLong::LONG;
1722     field_array[TypeFunc::Parms+1] = Type::HALF;
1723     break;
1724   case T_DOUBLE:
1725     field_array[TypeFunc::Parms]   = Type::DOUBLE;
1726     field_array[TypeFunc::Parms+1] = Type::HALF;
1727     break;
1728   case T_OBJECT:
1729   case T_ARRAY:
1730   case T_BOOLEAN:
1731   case T_CHAR:
1732   case T_FLOAT:
1733   case T_BYTE:
1734   case T_SHORT:
1735   case T_INT:
1736     field_array[TypeFunc::Parms] = get_const_type(return_type);
1737     break;
1738   case T_VOID:
1739     break;
1740   default:
1741     ShouldNotReachHere();
1742   }
1743   return (TypeTuple*)(new TypeTuple(total_fields,field_array))->hashcons();
1744 }
1745 
1746 // Make a TypeTuple from the domain of a method signature
1747 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig) {
1748   uint total_fields = TypeFunc::Parms + sig->size();
1749 
1750   uint pos = TypeFunc::Parms;
1751   const Type **field_array;
1752   if (recv != NULL) {
1753     total_fields++;
1754     field_array = fields(total_fields);
1755     // Use get_const_type here because it respects UseUniqueSubclasses:
1756     field_array[pos++] = get_const_type(recv)->join_speculative(TypePtr::NOTNULL);
1757   } else {
1758     field_array = fields(total_fields);
1759   }
1760 
1761   int i = 0;
1762   while (pos < total_fields) {
1763     ciType* type = sig->type_at(i);
1764 
1765     switch (type->basic_type()) {
1766     case T_LONG:
1767       field_array[pos++] = TypeLong::LONG;
1768       field_array[pos++] = Type::HALF;
1769       break;
1770     case T_DOUBLE:
1771       field_array[pos++] = Type::DOUBLE;
1772       field_array[pos++] = Type::HALF;
1773       break;
1774     case T_OBJECT:
1775     case T_ARRAY:
1776     case T_FLOAT:
1777     case T_INT:
1778       field_array[pos++] = get_const_type(type);
1779       break;
1780     case T_BOOLEAN:
1781     case T_CHAR:
1782     case T_BYTE:
1783     case T_SHORT:
1784       field_array[pos++] = TypeInt::INT;
1785       break;
1786     default:
1787       ShouldNotReachHere();
1788     }
1789     i++;
1790   }
1791   return (TypeTuple*)(new TypeTuple(total_fields,field_array))->hashcons();
1792 }
1793 
1794 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
1795   return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
1796 }
1797 
1798 //------------------------------fields-----------------------------------------
1799 // Subroutine call type with space allocated for argument types
1800 const Type **TypeTuple::fields( uint arg_cnt ) {
1801   const Type **flds = (const Type **)(Compile::current()->type_arena()->Amalloc_4((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
1802   flds[TypeFunc::Control  ] = Type::CONTROL;
1803   flds[TypeFunc::I_O      ] = Type::ABIO;
1804   flds[TypeFunc::Memory   ] = Type::MEMORY;
1805   flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
1806   flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
1807 
1808   return flds;
1809 }
1810 
1811 //------------------------------meet-------------------------------------------
1812 // Compute the MEET of two types.  It returns a new Type object.
1813 const Type *TypeTuple::xmeet( const Type *t ) const {
1814   // Perform a fast test for common case; meeting the same types together.
1815   if( this == t ) return this;  // Meeting same type-rep?
1816 
1817   // Current "this->_base" is Tuple
1818   switch (t->base()) {          // switch on original type
1819 
1820   case Bottom:                  // Ye Olde Default
1821     return t;
1822 
1823   default:                      // All else is a mistake
1824     typerr(t);
1825 
1826   case Tuple: {                 // Meeting 2 signatures?
1827     const TypeTuple *x = t->is_tuple();
1828     assert( _cnt == x->_cnt, "" );
1829     const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) ));
1830     for( uint i=0; i<_cnt; i++ )
1831       fields[i] = field_at(i)->xmeet( x->field_at(i) );
1832     return TypeTuple::make(_cnt,fields);
1833   }
1834   case Top:
1835     break;
1836   }
1837   return this;                  // Return the double constant
1838 }
1839 
1840 //------------------------------xdual------------------------------------------
1841 // Dual: compute field-by-field dual
1842 const Type *TypeTuple::xdual() const {
1843   const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) ));
1844   for( uint i=0; i<_cnt; i++ )
1845     fields[i] = _fields[i]->dual();
1846   return new TypeTuple(_cnt,fields);
1847 }
1848 
1849 //------------------------------eq---------------------------------------------
1850 // Structural equality check for Type representations
1851 bool TypeTuple::eq( const Type *t ) const {
1852   const TypeTuple *s = (const TypeTuple *)t;
1853   if (_cnt != s->_cnt)  return false;  // Unequal field counts
1854   for (uint i = 0; i < _cnt; i++)
1855     if (field_at(i) != s->field_at(i)) // POINTER COMPARE!  NO RECURSION!
1856       return false;             // Missed
1857   return true;
1858 }
1859 
1860 //------------------------------hash-------------------------------------------
1861 // Type-specific hashing function.
1862 int TypeTuple::hash(void) const {
1863   intptr_t sum = _cnt;
1864   for( uint i=0; i<_cnt; i++ )
1865     sum += (intptr_t)_fields[i];     // Hash on pointers directly
1866   return sum;
1867 }
1868 
1869 //------------------------------dump2------------------------------------------
1870 // Dump signature Type
1871 #ifndef PRODUCT
1872 void TypeTuple::dump2( Dict &d, uint depth, outputStream *st ) const {
1873   st->print("{");
1874   if( !depth || d[this] ) {     // Check for recursive print
1875     st->print("...}");
1876     return;
1877   }
1878   d.Insert((void*)this, (void*)this);   // Stop recursion
1879   if( _cnt ) {
1880     uint i;
1881     for( i=0; i<_cnt-1; i++ ) {
1882       st->print("%d:", i);
1883       _fields[i]->dump2(d, depth-1, st);
1884       st->print(", ");
1885     }
1886     st->print("%d:", i);
1887     _fields[i]->dump2(d, depth-1, st);
1888   }
1889   st->print("}");
1890 }
1891 #endif
1892 
1893 //------------------------------singleton--------------------------------------
1894 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
1895 // constants (Ldi nodes).  Singletons are integer, float or double constants
1896 // or a single symbol.
1897 bool TypeTuple::singleton(void) const {
1898   return false;                 // Never a singleton
1899 }
1900 
1901 bool TypeTuple::empty(void) const {
1902   for( uint i=0; i<_cnt; i++ ) {
1903     if (_fields[i]->empty())  return true;
1904   }
1905   return false;
1906 }
1907 
1908 //=============================================================================
1909 // Convenience common pre-built types.
1910 
1911 inline const TypeInt* normalize_array_size(const TypeInt* size) {
1912   // Certain normalizations keep us sane when comparing types.
1913   // We do not want arrayOop variables to differ only by the wideness
1914   // of their index types.  Pick minimum wideness, since that is the
1915   // forced wideness of small ranges anyway.
1916   if (size->_widen != Type::WidenMin)
1917     return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
1918   else
1919     return size;
1920 }
1921 
1922 //------------------------------make-------------------------------------------
1923 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable) {
1924   if (UseCompressedOops && elem->isa_oopptr()) {
1925     elem = elem->make_narrowoop();
1926   }
1927   size = normalize_array_size(size);
1928   return (TypeAry*)(new TypeAry(elem,size,stable))->hashcons();
1929 }
1930 
1931 //------------------------------meet-------------------------------------------
1932 // Compute the MEET of two types.  It returns a new Type object.
1933 const Type *TypeAry::xmeet( const Type *t ) const {
1934   // Perform a fast test for common case; meeting the same types together.
1935   if( this == t ) return this;  // Meeting same type-rep?
1936 
1937   // Current "this->_base" is Ary
1938   switch (t->base()) {          // switch on original type
1939 
1940   case Bottom:                  // Ye Olde Default
1941     return t;
1942 
1943   default:                      // All else is a mistake
1944     typerr(t);
1945 
1946   case Array: {                 // Meeting 2 arrays?
1947     const TypeAry *a = t->is_ary();
1948     return TypeAry::make(_elem->meet_speculative(a->_elem),
1949                          _size->xmeet(a->_size)->is_int(),
1950                          _stable & a->_stable);
1951   }
1952   case Top:
1953     break;
1954   }
1955   return this;                  // Return the double constant
1956 }
1957 
1958 //------------------------------xdual------------------------------------------
1959 // Dual: compute field-by-field dual
1960 const Type *TypeAry::xdual() const {
1961   const TypeInt* size_dual = _size->dual()->is_int();
1962   size_dual = normalize_array_size(size_dual);
1963   return new TypeAry(_elem->dual(), size_dual, !_stable);
1964 }
1965 
1966 //------------------------------eq---------------------------------------------
1967 // Structural equality check for Type representations
1968 bool TypeAry::eq( const Type *t ) const {
1969   const TypeAry *a = (const TypeAry*)t;
1970   return _elem == a->_elem &&
1971     _stable == a->_stable &&
1972     _size == a->_size;
1973 }
1974 
1975 //------------------------------hash-------------------------------------------
1976 // Type-specific hashing function.
1977 int TypeAry::hash(void) const {
1978   return (intptr_t)_elem + (intptr_t)_size + (_stable ? 43 : 0);
1979 }
1980 
1981 /**
1982  * Return same type without a speculative part in the element
1983  */
1984 const Type* TypeAry::remove_speculative() const {
1985   return make(_elem->remove_speculative(), _size, _stable);
1986 }
1987 
1988 //----------------------interface_vs_oop---------------------------------------
1989 #ifdef ASSERT
1990 bool TypeAry::interface_vs_oop(const Type *t) const {
1991   const TypeAry* t_ary = t->is_ary();
1992   if (t_ary) {
1993     const TypePtr* this_ptr = _elem->make_ptr(); // In case we have narrow_oops
1994     const TypePtr*    t_ptr = t_ary->_elem->make_ptr();
1995     if(this_ptr != NULL && t_ptr != NULL) {
1996       return this_ptr->interface_vs_oop(t_ptr);
1997     }
1998   }
1999   return false;
2000 }
2001 #endif
2002 
2003 //------------------------------dump2------------------------------------------
2004 #ifndef PRODUCT
2005 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2006   if (_stable)  st->print("stable:");
2007   _elem->dump2(d, depth, st);
2008   st->print("[");
2009   _size->dump2(d, depth, st);
2010   st->print("]");
2011 }
2012 #endif
2013 
2014 //------------------------------singleton--------------------------------------
2015 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2016 // constants (Ldi nodes).  Singletons are integer, float or double constants
2017 // or a single symbol.
2018 bool TypeAry::singleton(void) const {
2019   return false;                 // Never a singleton
2020 }
2021 
2022 bool TypeAry::empty(void) const {
2023   return _elem->empty() || _size->empty();
2024 }
2025 
2026 //--------------------------ary_must_be_exact----------------------------------
2027 bool TypeAry::ary_must_be_exact() const {
2028   if (!UseExactTypes)       return false;
2029   // This logic looks at the element type of an array, and returns true
2030   // if the element type is either a primitive or a final instance class.
2031   // In such cases, an array built on this ary must have no subclasses.
2032   if (_elem == BOTTOM)      return false;  // general array not exact
2033   if (_elem == TOP   )      return false;  // inverted general array not exact
2034   const TypeOopPtr*  toop = NULL;
2035   if (UseCompressedOops && _elem->isa_narrowoop()) {
2036     toop = _elem->make_ptr()->isa_oopptr();
2037   } else {
2038     toop = _elem->isa_oopptr();
2039   }
2040   if (!toop)                return true;   // a primitive type, like int
2041   ciKlass* tklass = toop->klass();
2042   if (tklass == NULL)       return false;  // unloaded class
2043   if (!tklass->is_loaded()) return false;  // unloaded class
2044   const TypeInstPtr* tinst;
2045   if (_elem->isa_narrowoop())
2046     tinst = _elem->make_ptr()->isa_instptr();
2047   else
2048     tinst = _elem->isa_instptr();
2049   if (tinst)
2050     return tklass->as_instance_klass()->is_final();
2051   const TypeAryPtr*  tap;
2052   if (_elem->isa_narrowoop())
2053     tap = _elem->make_ptr()->isa_aryptr();
2054   else
2055     tap = _elem->isa_aryptr();
2056   if (tap)
2057     return tap->ary()->ary_must_be_exact();
2058   return false;
2059 }
2060 
2061 //==============================TypeVect=======================================
2062 // Convenience common pre-built types.
2063 const TypeVect *TypeVect::VECTS = NULL; //  32-bit vectors
2064 const TypeVect *TypeVect::VECTD = NULL; //  64-bit vectors
2065 const TypeVect *TypeVect::VECTX = NULL; // 128-bit vectors
2066 const TypeVect *TypeVect::VECTY = NULL; // 256-bit vectors
2067 
2068 //------------------------------make-------------------------------------------
2069 const TypeVect* TypeVect::make(const Type *elem, uint length) {
2070   BasicType elem_bt = elem->array_element_basic_type();
2071   assert(is_java_primitive(elem_bt), "only primitive types in vector");
2072   assert(length > 1 && is_power_of_2(length), "vector length is power of 2");
2073   assert(Matcher::vector_size_supported(elem_bt, length), "length in range");
2074   int size = length * type2aelembytes(elem_bt);
2075   switch (Matcher::vector_ideal_reg(size)) {
2076   case Op_VecS:
2077     return (TypeVect*)(new TypeVectS(elem, length))->hashcons();
2078   case Op_RegL:
2079   case Op_VecD:
2080   case Op_RegD:
2081     return (TypeVect*)(new TypeVectD(elem, length))->hashcons();
2082   case Op_VecX:
2083     return (TypeVect*)(new TypeVectX(elem, length))->hashcons();
2084   case Op_VecY:
2085     return (TypeVect*)(new TypeVectY(elem, length))->hashcons();
2086   }
2087  ShouldNotReachHere();
2088   return NULL;
2089 }
2090 
2091 //------------------------------meet-------------------------------------------
2092 // Compute the MEET of two types.  It returns a new Type object.
2093 const Type *TypeVect::xmeet( const Type *t ) const {
2094   // Perform a fast test for common case; meeting the same types together.
2095   if( this == t ) return this;  // Meeting same type-rep?
2096 
2097   // Current "this->_base" is Vector
2098   switch (t->base()) {          // switch on original type
2099 
2100   case Bottom:                  // Ye Olde Default
2101     return t;
2102 
2103   default:                      // All else is a mistake
2104     typerr(t);
2105 
2106   case VectorS:
2107   case VectorD:
2108   case VectorX:
2109   case VectorY: {                // Meeting 2 vectors?
2110     const TypeVect* v = t->is_vect();
2111     assert(  base() == v->base(), "");
2112     assert(length() == v->length(), "");
2113     assert(element_basic_type() == v->element_basic_type(), "");
2114     return TypeVect::make(_elem->xmeet(v->_elem), _length);
2115   }
2116   case Top:
2117     break;
2118   }
2119   return this;
2120 }
2121 
2122 //------------------------------xdual------------------------------------------
2123 // Dual: compute field-by-field dual
2124 const Type *TypeVect::xdual() const {
2125   return new TypeVect(base(), _elem->dual(), _length);
2126 }
2127 
2128 //------------------------------eq---------------------------------------------
2129 // Structural equality check for Type representations
2130 bool TypeVect::eq(const Type *t) const {
2131   const TypeVect *v = t->is_vect();
2132   return (_elem == v->_elem) && (_length == v->_length);
2133 }
2134 
2135 //------------------------------hash-------------------------------------------
2136 // Type-specific hashing function.
2137 int TypeVect::hash(void) const {
2138   return (intptr_t)_elem + (intptr_t)_length;
2139 }
2140 
2141 //------------------------------singleton--------------------------------------
2142 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2143 // constants (Ldi nodes).  Vector is singleton if all elements are the same
2144 // constant value (when vector is created with Replicate code).
2145 bool TypeVect::singleton(void) const {
2146 // There is no Con node for vectors yet.
2147 //  return _elem->singleton();
2148   return false;
2149 }
2150 
2151 bool TypeVect::empty(void) const {
2152   return _elem->empty();
2153 }
2154 
2155 //------------------------------dump2------------------------------------------
2156 #ifndef PRODUCT
2157 void TypeVect::dump2(Dict &d, uint depth, outputStream *st) const {
2158   switch (base()) {
2159   case VectorS:
2160     st->print("vectors["); break;
2161   case VectorD:
2162     st->print("vectord["); break;
2163   case VectorX:
2164     st->print("vectorx["); break;
2165   case VectorY:
2166     st->print("vectory["); break;
2167   default:
2168     ShouldNotReachHere();
2169   }
2170   st->print("%d]:{", _length);
2171   _elem->dump2(d, depth, st);
2172   st->print("}");
2173 }
2174 #endif
2175 
2176 
2177 //=============================================================================
2178 // Convenience common pre-built types.
2179 const TypePtr *TypePtr::NULL_PTR;
2180 const TypePtr *TypePtr::NOTNULL;
2181 const TypePtr *TypePtr::BOTTOM;
2182 
2183 //------------------------------meet-------------------------------------------
2184 // Meet over the PTR enum
2185 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2186   //              TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,
2187   { /* Top     */ TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,},
2188   { /* AnyNull */ AnyNull,   AnyNull,   Constant, BotPTR, NotNull, BotPTR,},
2189   { /* Constant*/ Constant,  Constant,  Constant, BotPTR, NotNull, BotPTR,},
2190   { /* Null    */ Null,      BotPTR,    BotPTR,   Null,   BotPTR,  BotPTR,},
2191   { /* NotNull */ NotNull,   NotNull,   NotNull,  BotPTR, NotNull, BotPTR,},
2192   { /* BotPTR  */ BotPTR,    BotPTR,    BotPTR,   BotPTR, BotPTR,  BotPTR,}
2193 };
2194 
2195 //------------------------------make-------------------------------------------
2196 const TypePtr *TypePtr::make( TYPES t, enum PTR ptr, int offset ) {
2197   return (TypePtr*)(new TypePtr(t,ptr,offset))->hashcons();
2198 }
2199 
2200 //------------------------------cast_to_ptr_type-------------------------------
2201 const Type *TypePtr::cast_to_ptr_type(PTR ptr) const {
2202   assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2203   if( ptr == _ptr ) return this;
2204   return make(_base, ptr, _offset);
2205 }
2206 
2207 //------------------------------get_con----------------------------------------
2208 intptr_t TypePtr::get_con() const {
2209   assert( _ptr == Null, "" );
2210   return _offset;
2211 }
2212 
2213 //------------------------------meet-------------------------------------------
2214 // Compute the MEET of two types.  It returns a new Type object.
2215 const Type *TypePtr::xmeet( const Type *t ) const {
2216   // Perform a fast test for common case; meeting the same types together.
2217   if( this == t ) return this;  // Meeting same type-rep?
2218 
2219   // Current "this->_base" is AnyPtr
2220   switch (t->base()) {          // switch on original type
2221   case Int:                     // Mixing ints & oops happens when javac
2222   case Long:                    // reuses local variables
2223   case FloatTop:
2224   case FloatCon:
2225   case FloatBot:
2226   case DoubleTop:
2227   case DoubleCon:
2228   case DoubleBot:
2229   case NarrowOop:
2230   case NarrowKlass:
2231   case Bottom:                  // Ye Olde Default
2232     return Type::BOTTOM;
2233   case Top:
2234     return this;
2235 
2236   case AnyPtr: {                // Meeting to AnyPtrs
2237     const TypePtr *tp = t->is_ptr();
2238     return make( AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()) );
2239   }
2240   case RawPtr:                  // For these, flip the call around to cut down
2241   case OopPtr:
2242   case InstPtr:                 // on the cases I have to handle.
2243   case AryPtr:
2244   case MetadataPtr:
2245   case KlassPtr:
2246     return t->xmeet(this);      // Call in reverse direction
2247   default:                      // All else is a mistake
2248     typerr(t);
2249 
2250   }
2251   return this;
2252 }
2253 
2254 //------------------------------meet_offset------------------------------------
2255 int TypePtr::meet_offset( int offset ) const {
2256   // Either is 'TOP' offset?  Return the other offset!
2257   if( _offset == OffsetTop ) return offset;
2258   if( offset == OffsetTop ) return _offset;
2259   // If either is different, return 'BOTTOM' offset
2260   if( _offset != offset ) return OffsetBot;
2261   return _offset;
2262 }
2263 
2264 //------------------------------dual_offset------------------------------------
2265 int TypePtr::dual_offset( ) const {
2266   if( _offset == OffsetTop ) return OffsetBot;// Map 'TOP' into 'BOTTOM'
2267   if( _offset == OffsetBot ) return OffsetTop;// Map 'BOTTOM' into 'TOP'
2268   return _offset;               // Map everything else into self
2269 }
2270 
2271 //------------------------------xdual------------------------------------------
2272 // Dual: compute field-by-field dual
2273 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2274   BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2275 };
2276 const Type *TypePtr::xdual() const {
2277   return new TypePtr( AnyPtr, dual_ptr(), dual_offset() );
2278 }
2279 
2280 //------------------------------xadd_offset------------------------------------
2281 int TypePtr::xadd_offset( intptr_t offset ) const {
2282   // Adding to 'TOP' offset?  Return 'TOP'!
2283   if( _offset == OffsetTop || offset == OffsetTop ) return OffsetTop;
2284   // Adding to 'BOTTOM' offset?  Return 'BOTTOM'!
2285   if( _offset == OffsetBot || offset == OffsetBot ) return OffsetBot;
2286   // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
2287   offset += (intptr_t)_offset;
2288   if (offset != (int)offset || offset == OffsetTop) return OffsetBot;
2289 
2290   // assert( _offset >= 0 && _offset+offset >= 0, "" );
2291   // It is possible to construct a negative offset during PhaseCCP
2292 
2293   return (int)offset;        // Sum valid offsets
2294 }
2295 
2296 //------------------------------add_offset-------------------------------------
2297 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2298   return make( AnyPtr, _ptr, xadd_offset(offset) );
2299 }
2300 
2301 //------------------------------eq---------------------------------------------
2302 // Structural equality check for Type representations
2303 bool TypePtr::eq( const Type *t ) const {
2304   const TypePtr *a = (const TypePtr*)t;
2305   return _ptr == a->ptr() && _offset == a->offset();
2306 }
2307 
2308 //------------------------------hash-------------------------------------------
2309 // Type-specific hashing function.
2310 int TypePtr::hash(void) const {
2311   return _ptr + _offset;
2312 }
2313 
2314 //------------------------------dump2------------------------------------------
2315 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
2316   "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR"
2317 };
2318 
2319 #ifndef PRODUCT
2320 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2321   if( _ptr == Null ) st->print("NULL");
2322   else st->print("%s *", ptr_msg[_ptr]);
2323   if( _offset == OffsetTop ) st->print("+top");
2324   else if( _offset == OffsetBot ) st->print("+bot");
2325   else if( _offset ) st->print("+%d", _offset);
2326 }
2327 #endif
2328 
2329 //------------------------------singleton--------------------------------------
2330 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2331 // constants
2332 bool TypePtr::singleton(void) const {
2333   // TopPTR, Null, AnyNull, Constant are all singletons
2334   return (_offset != OffsetBot) && !below_centerline(_ptr);
2335 }
2336 
2337 bool TypePtr::empty(void) const {
2338   return (_offset == OffsetTop) || above_centerline(_ptr);
2339 }
2340 
2341 //=============================================================================
2342 // Convenience common pre-built types.
2343 const TypeRawPtr *TypeRawPtr::BOTTOM;
2344 const TypeRawPtr *TypeRawPtr::NOTNULL;
2345 
2346 //------------------------------make-------------------------------------------
2347 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
2348   assert( ptr != Constant, "what is the constant?" );
2349   assert( ptr != Null, "Use TypePtr for NULL" );
2350   return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons();
2351 }
2352 
2353 const TypeRawPtr *TypeRawPtr::make( address bits ) {
2354   assert( bits, "Use TypePtr for NULL" );
2355   return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
2356 }
2357 
2358 //------------------------------cast_to_ptr_type-------------------------------
2359 const Type *TypeRawPtr::cast_to_ptr_type(PTR ptr) const {
2360   assert( ptr != Constant, "what is the constant?" );
2361   assert( ptr != Null, "Use TypePtr for NULL" );
2362   assert( _bits==0, "Why cast a constant address?");
2363   if( ptr == _ptr ) return this;
2364   return make(ptr);
2365 }
2366 
2367 //------------------------------get_con----------------------------------------
2368 intptr_t TypeRawPtr::get_con() const {
2369   assert( _ptr == Null || _ptr == Constant, "" );
2370   return (intptr_t)_bits;
2371 }
2372 
2373 //------------------------------meet-------------------------------------------
2374 // Compute the MEET of two types.  It returns a new Type object.
2375 const Type *TypeRawPtr::xmeet( const Type *t ) const {
2376   // Perform a fast test for common case; meeting the same types together.
2377   if( this == t ) return this;  // Meeting same type-rep?
2378 
2379   // Current "this->_base" is RawPtr
2380   switch( t->base() ) {         // switch on original type
2381   case Bottom:                  // Ye Olde Default
2382     return t;
2383   case Top:
2384     return this;
2385   case AnyPtr:                  // Meeting to AnyPtrs
2386     break;
2387   case RawPtr: {                // might be top, bot, any/not or constant
2388     enum PTR tptr = t->is_ptr()->ptr();
2389     enum PTR ptr = meet_ptr( tptr );
2390     if( ptr == Constant ) {     // Cannot be equal constants, so...
2391       if( tptr == Constant && _ptr != Constant)  return t;
2392       if( _ptr == Constant && tptr != Constant)  return this;
2393       ptr = NotNull;            // Fall down in lattice
2394     }
2395     return make( ptr );
2396   }
2397 
2398   case OopPtr:
2399   case InstPtr:
2400   case AryPtr:
2401   case MetadataPtr:
2402   case KlassPtr:
2403     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
2404   default:                      // All else is a mistake
2405     typerr(t);
2406   }
2407 
2408   // Found an AnyPtr type vs self-RawPtr type
2409   const TypePtr *tp = t->is_ptr();
2410   switch (tp->ptr()) {
2411   case TypePtr::TopPTR:  return this;
2412   case TypePtr::BotPTR:  return t;
2413   case TypePtr::Null:
2414     if( _ptr == TypePtr::TopPTR ) return t;
2415     return TypeRawPtr::BOTTOM;
2416   case TypePtr::NotNull: return TypePtr::make( AnyPtr, meet_ptr(TypePtr::NotNull), tp->meet_offset(0) );
2417   case TypePtr::AnyNull:
2418     if( _ptr == TypePtr::Constant) return this;
2419     return make( meet_ptr(TypePtr::AnyNull) );
2420   default: ShouldNotReachHere();
2421   }
2422   return this;
2423 }
2424 
2425 //------------------------------xdual------------------------------------------
2426 // Dual: compute field-by-field dual
2427 const Type *TypeRawPtr::xdual() const {
2428   return new TypeRawPtr( dual_ptr(), _bits );
2429 }
2430 
2431 //------------------------------add_offset-------------------------------------
2432 const TypePtr *TypeRawPtr::add_offset( intptr_t offset ) const {
2433   if( offset == OffsetTop ) return BOTTOM; // Undefined offset-> undefined pointer
2434   if( offset == OffsetBot ) return BOTTOM; // Unknown offset-> unknown pointer
2435   if( offset == 0 ) return this; // No change
2436   switch (_ptr) {
2437   case TypePtr::TopPTR:
2438   case TypePtr::BotPTR:
2439   case TypePtr::NotNull:
2440     return this;
2441   case TypePtr::Null:
2442   case TypePtr::Constant: {
2443     address bits = _bits+offset;
2444     if ( bits == 0 ) return TypePtr::NULL_PTR;
2445     return make( bits );
2446   }
2447   default:  ShouldNotReachHere();
2448   }
2449   return NULL;                  // Lint noise
2450 }
2451 
2452 //------------------------------eq---------------------------------------------
2453 // Structural equality check for Type representations
2454 bool TypeRawPtr::eq( const Type *t ) const {
2455   const TypeRawPtr *a = (const TypeRawPtr*)t;
2456   return _bits == a->_bits && TypePtr::eq(t);
2457 }
2458 
2459 //------------------------------hash-------------------------------------------
2460 // Type-specific hashing function.
2461 int TypeRawPtr::hash(void) const {
2462   return (intptr_t)_bits + TypePtr::hash();
2463 }
2464 
2465 //------------------------------dump2------------------------------------------
2466 #ifndef PRODUCT
2467 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2468   if( _ptr == Constant )
2469     st->print(INTPTR_FORMAT, _bits);
2470   else
2471     st->print("rawptr:%s", ptr_msg[_ptr]);
2472 }
2473 #endif
2474 
2475 //=============================================================================
2476 // Convenience common pre-built type.
2477 const TypeOopPtr *TypeOopPtr::BOTTOM;
2478 
2479 //------------------------------TypeOopPtr-------------------------------------
2480 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id, const TypeOopPtr* speculative, int inline_depth)
2481   : TypePtr(t, ptr, offset),
2482     _const_oop(o), _klass(k),
2483     _klass_is_exact(xk),
2484     _is_ptr_to_narrowoop(false),
2485     _is_ptr_to_narrowklass(false),
2486     _is_ptr_to_boxed_value(false),
2487     _instance_id(instance_id),
2488     _speculative(speculative),
2489     _inline_depth(inline_depth){
2490   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
2491       (offset > 0) && xk && (k != 0) && k->is_instance_klass()) {
2492     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset);
2493   }
2494 #ifdef _LP64
2495   if (_offset != 0) {
2496     if (_offset == oopDesc::klass_offset_in_bytes()) {
2497       _is_ptr_to_narrowklass = UseCompressedClassPointers;
2498     } else if (UseShenandoahGC && _offset == BrooksPointer::byte_offset()) {
2499       // Shenandoah doesn't support compressed forwarding pointers
2500     } else if (klass() == NULL) {
2501       // Array with unknown body type
2502       assert(this->isa_aryptr(), "only arrays without klass");
2503       _is_ptr_to_narrowoop = UseCompressedOops;
2504     } else if (this->isa_aryptr()) {
2505       _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() &&
2506                              _offset != arrayOopDesc::length_offset_in_bytes());
2507     } else if (klass()->is_instance_klass()) {
2508       ciInstanceKlass* ik = klass()->as_instance_klass();
2509       ciField* field = NULL;
2510       if (this->isa_klassptr()) {
2511         // Perm objects don't use compressed references
2512       } else if (_offset == OffsetBot || _offset == OffsetTop) {
2513         // unsafe access
2514         _is_ptr_to_narrowoop = UseCompressedOops;
2515       } else { // exclude unsafe ops
2516         assert(this->isa_instptr(), "must be an instance ptr.");
2517 
2518         if (klass() == ciEnv::current()->Class_klass() &&
2519             (_offset == java_lang_Class::klass_offset_in_bytes() ||
2520              _offset == java_lang_Class::array_klass_offset_in_bytes())) {
2521           // Special hidden fields from the Class.
2522           assert(this->isa_instptr(), "must be an instance ptr.");
2523           _is_ptr_to_narrowoop = false;
2524         } else if (klass() == ciEnv::current()->Class_klass() &&
2525                    _offset >= InstanceMirrorKlass::offset_of_static_fields() &&
2526                    !UseShenandoahGC) {
2527           // Static fields
2528           assert(o != NULL, "must be constant");
2529           ciInstanceKlass* k = o->as_instance()->java_lang_Class_klass()->as_instance_klass();
2530           ciField* field = k->get_field_by_offset(_offset, true);
2531           assert(field != NULL, "missing field");
2532           BasicType basic_elem_type = field->layout_type();
2533           _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||
2534                                                        basic_elem_type == T_ARRAY);
2535         } else {
2536           // Instance fields which contains a compressed oop references.
2537           field = ik->get_field_by_offset(_offset, false);
2538           if (field != NULL) {
2539             BasicType basic_elem_type = field->layout_type();
2540             _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||
2541                                                          basic_elem_type == T_ARRAY);
2542           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
2543             // Compile::find_alias_type() cast exactness on all types to verify
2544             // that it does not affect alias type.
2545             _is_ptr_to_narrowoop = UseCompressedOops;
2546           } else {
2547             // Type for the copy start in LibraryCallKit::inline_native_clone().
2548             _is_ptr_to_narrowoop = UseCompressedOops;
2549           }
2550         }
2551       }
2552     }
2553   }
2554 #endif
2555 }
2556 
2557 //------------------------------make-------------------------------------------
2558 const TypeOopPtr *TypeOopPtr::make(PTR ptr,
2559                                    int offset, int instance_id, const TypeOopPtr* speculative, int inline_depth) {
2560   assert(ptr != Constant, "no constant generic pointers");
2561   ciKlass*  k = Compile::current()->env()->Object_klass();
2562   bool      xk = false;
2563   ciObject* o = NULL;
2564   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, instance_id, speculative, inline_depth))->hashcons();
2565 }
2566 
2567 
2568 //------------------------------cast_to_ptr_type-------------------------------
2569 const Type *TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
2570   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
2571   if( ptr == _ptr ) return this;
2572   return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
2573 }
2574 
2575 //-----------------------------cast_to_instance_id----------------------------
2576 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
2577   // There are no instances of a general oop.
2578   // Return self unchanged.
2579   return this;
2580 }
2581 
2582 const TypeOopPtr *TypeOopPtr::cast_to_nonconst() const {
2583   return this;
2584 }
2585 
2586 //-----------------------------cast_to_exactness-------------------------------
2587 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
2588   // There is no such thing as an exact general oop.
2589   // Return self unchanged.
2590   return this;
2591 }
2592 
2593 
2594 //------------------------------as_klass_type----------------------------------
2595 // Return the klass type corresponding to this instance or array type.
2596 // It is the type that is loaded from an object of this type.
2597 const TypeKlassPtr* TypeOopPtr::as_klass_type() const {
2598   ciKlass* k = klass();
2599   bool    xk = klass_is_exact();
2600   if (k == NULL)
2601     return TypeKlassPtr::OBJECT;
2602   else
2603     return TypeKlassPtr::make(xk? Constant: NotNull, k, 0);
2604 }
2605 
2606 const Type *TypeOopPtr::xmeet(const Type *t) const {
2607   const Type* res = xmeet_helper(t);
2608   if (res->isa_oopptr() == NULL) {
2609     return res;
2610   }
2611 
2612   const TypeOopPtr* res_oopptr = res->is_oopptr();
2613   if (res_oopptr->speculative() != NULL) {
2614     // type->speculative() == NULL means that speculation is no better
2615     // than type, i.e. type->speculative() == type. So there are 2
2616     // ways to represent the fact that we have no useful speculative
2617     // data and we should use a single one to be able to test for
2618     // equality between types. Check whether type->speculative() ==
2619     // type and set speculative to NULL if it is the case.
2620     if (res_oopptr->remove_speculative() == res_oopptr->speculative()) {
2621       return res_oopptr->remove_speculative();
2622     }
2623   }
2624 
2625   return res;
2626 }
2627 
2628 //------------------------------meet-------------------------------------------
2629 // Compute the MEET of two types.  It returns a new Type object.
2630 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
2631   // Perform a fast test for common case; meeting the same types together.
2632   if( this == t ) return this;  // Meeting same type-rep?
2633 
2634   // Current "this->_base" is OopPtr
2635   switch (t->base()) {          // switch on original type
2636 
2637   case Int:                     // Mixing ints & oops happens when javac
2638   case Long:                    // reuses local variables
2639   case FloatTop:
2640   case FloatCon:
2641   case FloatBot:
2642   case DoubleTop:
2643   case DoubleCon:
2644   case DoubleBot:
2645   case NarrowOop:
2646   case NarrowKlass:
2647   case Bottom:                  // Ye Olde Default
2648     return Type::BOTTOM;
2649   case Top:
2650     return this;
2651 
2652   default:                      // All else is a mistake
2653     typerr(t);
2654 
2655   case RawPtr:
2656   case MetadataPtr:
2657   case KlassPtr:
2658     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
2659 
2660   case AnyPtr: {
2661     // Found an AnyPtr type vs self-OopPtr type
2662     const TypePtr *tp = t->is_ptr();
2663     int offset = meet_offset(tp->offset());
2664     PTR ptr = meet_ptr(tp->ptr());
2665     switch (tp->ptr()) {
2666     case Null:
2667       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset);
2668       // else fall through:
2669     case TopPTR:
2670     case AnyNull: {
2671       int instance_id = meet_instance_id(InstanceTop);
2672       const TypeOopPtr* speculative = _speculative;
2673       return make(ptr, offset, instance_id, speculative, _inline_depth);
2674     }
2675     case BotPTR:
2676     case NotNull:
2677       return TypePtr::make(AnyPtr, ptr, offset);
2678     default: typerr(t);
2679     }
2680   }
2681 
2682   case OopPtr: {                 // Meeting to other OopPtrs
2683     const TypeOopPtr *tp = t->is_oopptr();
2684     int instance_id = meet_instance_id(tp->instance_id());
2685     const TypeOopPtr* speculative = xmeet_speculative(tp);
2686     int depth = meet_inline_depth(tp->inline_depth());
2687     return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
2688   }
2689 
2690   case InstPtr:                  // For these, flip the call around to cut down
2691   case AryPtr:
2692     return t->xmeet(this);      // Call in reverse direction
2693 
2694   } // End of switch
2695   return this;                  // Return the double constant
2696 }
2697 
2698 
2699 //------------------------------xdual------------------------------------------
2700 // Dual of a pure heap pointer.  No relevant klass or oop information.
2701 const Type *TypeOopPtr::xdual() const {
2702   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
2703   assert(const_oop() == NULL,             "no constants here");
2704   return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
2705 }
2706 
2707 //--------------------------make_from_klass_common-----------------------------
2708 // Computes the element-type given a klass.
2709 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) {
2710   if (klass->is_instance_klass()) {
2711     Compile* C = Compile::current();
2712     Dependencies* deps = C->dependencies();
2713     assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
2714     // Element is an instance
2715     bool klass_is_exact = false;
2716     if (klass->is_loaded()) {
2717       // Try to set klass_is_exact.
2718       ciInstanceKlass* ik = klass->as_instance_klass();
2719       klass_is_exact = ik->is_final();
2720       if (!klass_is_exact && klass_change
2721           && deps != NULL && UseUniqueSubclasses) {
2722         ciInstanceKlass* sub = ik->unique_concrete_subklass();
2723         if (sub != NULL) {
2724           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
2725           klass = ik = sub;
2726           klass_is_exact = sub->is_final();
2727         }
2728       }
2729       if (!klass_is_exact && try_for_exact
2730           && deps != NULL && UseExactTypes) {
2731         if (!ik->is_interface() && !ik->has_subklass()) {
2732           // Add a dependence; if concrete subclass added we need to recompile
2733           deps->assert_leaf_type(ik);
2734           klass_is_exact = true;
2735         }
2736       }
2737     }
2738     return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, 0);
2739   } else if (klass->is_obj_array_klass()) {
2740     // Element is an object array. Recursively call ourself.
2741     const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(klass->as_obj_array_klass()->element_klass(), false, try_for_exact);
2742     bool xk = etype->klass_is_exact();
2743     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
2744     // We used to pass NotNull in here, asserting that the sub-arrays
2745     // are all not-null.  This is not true in generally, as code can
2746     // slam NULLs down in the subarrays.
2747     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, 0);
2748     return arr;
2749   } else if (klass->is_type_array_klass()) {
2750     // Element is an typeArray
2751     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
2752     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
2753     // We used to pass NotNull in here, asserting that the array pointer
2754     // is not-null. That was not true in general.
2755     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, 0);
2756     return arr;
2757   } else {
2758     ShouldNotReachHere();
2759     return NULL;
2760   }
2761 }
2762 
2763 //------------------------------make_from_constant-----------------------------
2764 // Make a java pointer from an oop constant
2765 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o,
2766                                                  bool require_constant,
2767                                                  bool is_autobox_cache) {
2768   assert(!o->is_null_object(), "null object not yet handled here.");
2769   ciKlass* klass = o->klass();
2770   if (klass->is_instance_klass()) {
2771     // Element is an instance
2772     if (require_constant) {
2773       if (!o->can_be_constant())  return NULL;
2774     } else if (!o->should_be_constant()) {
2775       return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, 0);
2776     }
2777     return TypeInstPtr::make(o);
2778   } else if (klass->is_obj_array_klass()) {
2779     // Element is an object array. Recursively call ourself.
2780     const TypeOopPtr *etype =
2781       TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass());
2782     if (is_autobox_cache) {
2783       // The pointers in the autobox arrays are always non-null.
2784       etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
2785     }
2786     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
2787     // We used to pass NotNull in here, asserting that the sub-arrays
2788     // are all not-null.  This is not true in generally, as code can
2789     // slam NULLs down in the subarrays.
2790     if (require_constant) {
2791       if (!o->can_be_constant())  return NULL;
2792     } else if (!o->should_be_constant()) {
2793       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
2794     }
2795     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0, InstanceBot, NULL, InlineDepthBottom, is_autobox_cache);
2796     return arr;
2797   } else if (klass->is_type_array_klass()) {
2798     // Element is an typeArray
2799     const Type* etype =
2800       (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
2801     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
2802     // We used to pass NotNull in here, asserting that the array pointer
2803     // is not-null. That was not true in general.
2804     if (require_constant) {
2805       if (!o->can_be_constant())  return NULL;
2806     } else if (!o->should_be_constant()) {
2807       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
2808     }
2809     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
2810     return arr;
2811   }
2812 
2813   fatal("unhandled object type");
2814   return NULL;
2815 }
2816 
2817 //------------------------------get_con----------------------------------------
2818 intptr_t TypeOopPtr::get_con() const {
2819   assert( _ptr == Null || _ptr == Constant, "" );
2820   assert( _offset >= 0, "" );
2821 
2822   if (_offset != 0) {
2823     // After being ported to the compiler interface, the compiler no longer
2824     // directly manipulates the addresses of oops.  Rather, it only has a pointer
2825     // to a handle at compile time.  This handle is embedded in the generated
2826     // code and dereferenced at the time the nmethod is made.  Until that time,
2827     // it is not reasonable to do arithmetic with the addresses of oops (we don't
2828     // have access to the addresses!).  This does not seem to currently happen,
2829     // but this assertion here is to help prevent its occurence.
2830     tty->print_cr("Found oop constant with non-zero offset");
2831     ShouldNotReachHere();
2832   }
2833 
2834   return (intptr_t)const_oop()->constant_encoding();
2835 }
2836 
2837 
2838 //-----------------------------filter------------------------------------------
2839 // Do not allow interface-vs.-noninterface joins to collapse to top.
2840 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
2841 
2842   const Type* ft = join_helper(kills, include_speculative);
2843   const TypeInstPtr* ftip = ft->isa_instptr();
2844   const TypeInstPtr* ktip = kills->isa_instptr();
2845 
2846   if (ft->empty()) {
2847     // Check for evil case of 'this' being a class and 'kills' expecting an
2848     // interface.  This can happen because the bytecodes do not contain
2849     // enough type info to distinguish a Java-level interface variable
2850     // from a Java-level object variable.  If we meet 2 classes which
2851     // both implement interface I, but their meet is at 'j/l/O' which
2852     // doesn't implement I, we have no way to tell if the result should
2853     // be 'I' or 'j/l/O'.  Thus we'll pick 'j/l/O'.  If this then flows
2854     // into a Phi which "knows" it's an Interface type we'll have to
2855     // uplift the type.
2856     if (!empty()) {
2857       if (ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface()) {
2858         return kills;           // Uplift to interface
2859       }
2860       // Also check for evil cases of 'this' being a class array
2861       // and 'kills' expecting an array of interfaces.
2862       Type::get_arrays_base_elements(ft, kills, NULL, &ktip);
2863       if (ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface()) {
2864         return kills;           // Uplift to array of interface
2865       }
2866     }
2867 
2868     return Type::TOP;           // Canonical empty value
2869   }
2870 
2871   // If we have an interface-typed Phi or cast and we narrow to a class type,
2872   // the join should report back the class.  However, if we have a J/L/Object
2873   // class-typed Phi and an interface flows in, it's possible that the meet &
2874   // join report an interface back out.  This isn't possible but happens
2875   // because the type system doesn't interact well with interfaces.
2876   if (ftip != NULL && ktip != NULL &&
2877       ftip->is_loaded() &&  ftip->klass()->is_interface() &&
2878       ktip->is_loaded() && !ktip->klass()->is_interface()) {
2879     // Happens in a CTW of rt.jar, 320-341, no extra flags
2880     assert(!ftip->klass_is_exact(), "interface could not be exact");
2881     return ktip->cast_to_ptr_type(ftip->ptr());
2882   }
2883 
2884   return ft;
2885 }
2886 
2887 //------------------------------eq---------------------------------------------
2888 // Structural equality check for Type representations
2889 bool TypeOopPtr::eq( const Type *t ) const {
2890   const TypeOopPtr *a = (const TypeOopPtr*)t;
2891   if (_klass_is_exact != a->_klass_is_exact ||
2892       _instance_id != a->_instance_id ||
2893       !eq_speculative(a) ||
2894       _inline_depth != a->_inline_depth)  return false;
2895   ciObject* one = const_oop();
2896   ciObject* two = a->const_oop();
2897   if (one == NULL || two == NULL) {
2898     return (one == two) && TypePtr::eq(t);
2899   } else {
2900     return one->equals(two) && TypePtr::eq(t);
2901   }
2902 }
2903 
2904 //------------------------------hash-------------------------------------------
2905 // Type-specific hashing function.
2906 int TypeOopPtr::hash(void) const {
2907   return
2908     (const_oop() ? const_oop()->hash() : 0) +
2909     _klass_is_exact +
2910     _instance_id +
2911     hash_speculative() +
2912     _inline_depth +
2913     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 = 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 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 }