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