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