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