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,
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 (this->isa_aryptr()) {
3021       _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() &&
3022                               this->offset() != arrayOopDesc::length_offset_in_bytes());
3023     } else if (klass()->is_instance_klass()) {
3024       ciInstanceKlass* ik = klass()->as_instance_klass();
3025       ciField* field = NULL;
3026       if (this->isa_klassptr()) {
3027         // Perm objects don't use compressed references
3028       } else if (_offset == Offset::bottom || _offset == Offset::top) {
3029         // unsafe access
3030         _is_ptr_to_narrowoop = UseCompressedOops;
3031       } else { // exclude unsafe ops
3032         assert(this->isa_instptr() || this->isa_valuetypeptr(), "must be an instance ptr.");
3033 
3034         if (klass() == ciEnv::current()->Class_klass() &&
3035             (this->offset() == java_lang_Class::klass_offset_in_bytes() ||
3036              this->offset() == java_lang_Class::array_klass_offset_in_bytes())) {
3037           // Special hidden fields from the Class.
3038           assert(this->isa_instptr(), "must be an instance ptr.");
3039           _is_ptr_to_narrowoop = false;
3040         } else if (klass() == ciEnv::current()->Class_klass() &&
3041                    this->offset() >= InstanceMirrorKlass::offset_of_static_fields()) {
3042           // Static fields
3043           assert(o != NULL, "must be constant");
3044           ciInstanceKlass* k = o->as_instance()->java_lang_Class_klass()->as_instance_klass();
3045           ciField* field = k->get_field_by_offset(this->offset(), true);
3046           assert(field != NULL, "missing field");
3047           BasicType basic_elem_type = field->layout_type();
3048           _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||
3049                                                        basic_elem_type == T_ARRAY);
3050         } else {
3051           // Instance fields which contains a compressed oop references.
3052           field = ik->get_field_by_offset(this->offset(), false);
3053           if (field != NULL) {
3054             BasicType basic_elem_type = field->layout_type();
3055             _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||
3056                                                          basic_elem_type == T_ARRAY);
3057           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3058             // Compile::find_alias_type() cast exactness on all types to verify
3059             // that it does not affect alias type.
3060             _is_ptr_to_narrowoop = UseCompressedOops;
3061           } else {
3062             // Type for the copy start in LibraryCallKit::inline_native_clone().
3063             _is_ptr_to_narrowoop = UseCompressedOops;
3064           }
3065         }
3066       }
3067     }
3068   }
3069 #endif
3070 }
3071 
3072 //------------------------------make-------------------------------------------
3073 const TypeOopPtr *TypeOopPtr::make(PTR ptr, Offset offset, int instance_id,
3074                                    const TypePtr* speculative, int inline_depth) {
3075   assert(ptr != Constant, "no constant generic pointers");
3076   ciKlass*  k = Compile::current()->env()->Object_klass();
3077   bool      xk = false;
3078   ciObject* o = NULL;
3079   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, instance_id, speculative, inline_depth))->hashcons();
3080 }
3081 
3082 
3083 //------------------------------cast_to_ptr_type-------------------------------
3084 const Type *TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3085   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3086   if( ptr == _ptr ) return this;
3087   return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3088 }
3089 
3090 //-----------------------------cast_to_instance_id----------------------------
3091 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3092   // There are no instances of a general oop.
3093   // Return self unchanged.
3094   return this;
3095 }
3096 
3097 //-----------------------------cast_to_exactness-------------------------------
3098 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3099   // There is no such thing as an exact general oop.
3100   // Return self unchanged.
3101   return this;
3102 }
3103 
3104 
3105 //------------------------------as_klass_type----------------------------------
3106 // Return the klass type corresponding to this instance or array type.
3107 // It is the type that is loaded from an object of this type.
3108 const TypeKlassPtr* TypeOopPtr::as_klass_type() const {
3109   ciKlass* k = klass();
3110   bool    xk = klass_is_exact();
3111   if (k == NULL)
3112     return TypeKlassPtr::OBJECT;
3113   else
3114     return TypeKlassPtr::make(xk? Constant: NotNull, k, Offset(0));
3115 }
3116 
3117 //------------------------------meet-------------------------------------------
3118 // Compute the MEET of two types.  It returns a new Type object.
3119 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3120   // Perform a fast test for common case; meeting the same types together.
3121   if( this == t ) return this;  // Meeting same type-rep?
3122 
3123   // Current "this->_base" is OopPtr
3124   switch (t->base()) {          // switch on original type
3125 
3126   case Int:                     // Mixing ints & oops happens when javac
3127   case Long:                    // reuses local variables
3128   case FloatTop:
3129   case FloatCon:
3130   case FloatBot:
3131   case DoubleTop:
3132   case DoubleCon:
3133   case DoubleBot:
3134   case NarrowOop:
3135   case NarrowKlass:
3136   case Bottom:                  // Ye Olde Default
3137     return Type::BOTTOM;
3138   case Top:
3139     return this;
3140 
3141   default:                      // All else is a mistake
3142     typerr(t);
3143 
3144   case RawPtr:
3145   case MetadataPtr:
3146   case KlassPtr:
3147     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3148 
3149   case AnyPtr: {
3150     // Found an AnyPtr type vs self-OopPtr type
3151     const TypePtr *tp = t->is_ptr();
3152     Offset offset = meet_offset(tp->offset());
3153     PTR ptr = meet_ptr(tp->ptr());
3154     const TypePtr* speculative = xmeet_speculative(tp);
3155     int depth = meet_inline_depth(tp->inline_depth());
3156     switch (tp->ptr()) {
3157     case Null:
3158       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3159       // else fall through:
3160     case TopPTR:
3161     case AnyNull: {
3162       int instance_id = meet_instance_id(InstanceTop);
3163       return make(ptr, offset, instance_id, speculative, depth);
3164     }
3165     case BotPTR:
3166     case NotNull:
3167       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3168     default: typerr(t);
3169     }
3170   }
3171 
3172   case OopPtr: {                 // Meeting to other OopPtrs
3173     const TypeOopPtr *tp = t->is_oopptr();
3174     int instance_id = meet_instance_id(tp->instance_id());
3175     const TypePtr* speculative = xmeet_speculative(tp);
3176     int depth = meet_inline_depth(tp->inline_depth());
3177     return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3178   }
3179 
3180   case InstPtr:                  // For these, flip the call around to cut down
3181   case ValueTypePtr:
3182   case AryPtr:
3183     return t->xmeet(this);      // Call in reverse direction
3184 
3185   } // End of switch
3186   return this;                  // Return the double constant
3187 }
3188 
3189 
3190 //------------------------------xdual------------------------------------------
3191 // Dual of a pure heap pointer.  No relevant klass or oop information.
3192 const Type *TypeOopPtr::xdual() const {
3193   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3194   assert(const_oop() == NULL,             "no constants here");
3195   return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
3196 }
3197 
3198 //--------------------------make_from_klass_common-----------------------------
3199 // Computes the element-type given a klass.
3200 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) {
3201   if (klass->is_valuetype()) {
3202     return TypeValueTypePtr::make(TypePtr::NotNull, klass->as_value_klass());
3203   } else if (klass->is_instance_klass()) {
3204     Compile* C = Compile::current();
3205     Dependencies* deps = C->dependencies();
3206     assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
3207     // Element is an instance
3208     bool klass_is_exact = false;
3209     if (klass->is_loaded()) {
3210       // Try to set klass_is_exact.
3211       ciInstanceKlass* ik = klass->as_instance_klass();
3212       klass_is_exact = ik->is_final();
3213       if (!klass_is_exact && klass_change
3214           && deps != NULL && UseUniqueSubclasses) {
3215         ciInstanceKlass* sub = ik->unique_concrete_subklass();
3216         if (sub != NULL) {
3217           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3218           klass = ik = sub;
3219           klass_is_exact = sub->is_final();
3220         }
3221       }
3222       if (!klass_is_exact && try_for_exact
3223           && deps != NULL && UseExactTypes) {
3224         if (!ik->is_interface() && !ik->has_subklass()) {
3225           // Add a dependence; if concrete subclass added we need to recompile
3226           deps->assert_leaf_type(ik);
3227           klass_is_exact = true;
3228         }
3229       }
3230     }
3231     return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, Offset(0));
3232   } else if (klass->is_obj_array_klass()) {
3233     // Element is an object or value array. Recursively call ourself.
3234     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), false, try_for_exact);
3235     bool xk = etype->klass_is_exact();
3236     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3237     // We used to pass NotNull in here, asserting that the sub-arrays
3238     // are all not-null.  This is not true in generally, as code can
3239     // slam NULLs down in the subarrays.
3240     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, Offset(0));
3241     return arr;
3242   } else if (klass->is_type_array_klass()) {
3243     // Element is an typeArray
3244     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3245     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3246     // We used to pass NotNull in here, asserting that the array pointer
3247     // is not-null. That was not true in general.
3248     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
3249     return arr;
3250   } else if (klass->is_value_array_klass()) {
3251     ciValueKlass* vk = klass->as_array_klass()->element_klass()->as_value_klass();
3252     const Type* etype = NULL;
3253     bool xk = false;
3254     if (vk->flatten_array()) {
3255       etype = TypeValueType::make(vk);
3256       xk = true;
3257     } else {
3258       const TypeOopPtr* etype_oop = TypeOopPtr::make_from_klass_common(vk, false, try_for_exact);
3259       xk = etype_oop->klass_is_exact();
3260       etype = etype_oop;
3261     }
3262     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3263     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, Offset(0));
3264     return arr;
3265   } else {
3266     ShouldNotReachHere();
3267     return NULL;
3268   }
3269 }
3270 
3271 //------------------------------make_from_constant-----------------------------
3272 // Make a java pointer from an oop constant
3273 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3274   assert(!o->is_null_object(), "null object not yet handled here.");
3275   ciKlass* klass = o->klass();
3276   if (klass->is_valuetype()) {
3277     // Element is a value type
3278     if (require_constant) {
3279       if (!o->can_be_constant())  return NULL;
3280     } else if (!o->should_be_constant()) {
3281       return TypeValueTypePtr::make(TypePtr::NotNull, klass->as_value_klass());
3282     }
3283     return TypeValueTypePtr::make(o);
3284   } else if (klass->is_instance_klass()) {
3285     // Element is an instance
3286     if (require_constant) {
3287       if (!o->can_be_constant())  return NULL;
3288     } else if (!o->should_be_constant()) {
3289       return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, Offset(0));
3290     }
3291     return TypeInstPtr::make(o);
3292   } else if (klass->is_obj_array_klass() || klass->is_value_array_klass()) {
3293     // Element is an object array. Recursively call ourself.
3294     const TypeOopPtr *etype =
3295       TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass());
3296     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3297     // We used to pass NotNull in here, asserting that the sub-arrays
3298     // are all not-null.  This is not true in generally, as code can
3299     // slam NULLs down in the subarrays.
3300     if (require_constant) {
3301       if (!o->can_be_constant())  return NULL;
3302     } else if (!o->should_be_constant()) {
3303       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3304     }
3305     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3306     return arr;
3307   } else if (klass->is_type_array_klass()) {
3308     // Element is an typeArray
3309     const Type* etype =
3310       (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3311     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3312     // We used to pass NotNull in here, asserting that the array pointer
3313     // is not-null. That was not true in general.
3314     if (require_constant) {
3315       if (!o->can_be_constant())  return NULL;
3316     } else if (!o->should_be_constant()) {
3317       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3318     }
3319     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3320     return arr;
3321   }
3322 
3323   fatal("unhandled object type");
3324   return NULL;
3325 }
3326 
3327 //------------------------------get_con----------------------------------------
3328 intptr_t TypeOopPtr::get_con() const {
3329   assert( _ptr == Null || _ptr == Constant, "" );
3330   assert(offset() >= 0, "");
3331 
3332   if (offset() != 0) {
3333     // After being ported to the compiler interface, the compiler no longer
3334     // directly manipulates the addresses of oops.  Rather, it only has a pointer
3335     // to a handle at compile time.  This handle is embedded in the generated
3336     // code and dereferenced at the time the nmethod is made.  Until that time,
3337     // it is not reasonable to do arithmetic with the addresses of oops (we don't
3338     // have access to the addresses!).  This does not seem to currently happen,
3339     // but this assertion here is to help prevent its occurence.
3340     tty->print_cr("Found oop constant with non-zero offset");
3341     ShouldNotReachHere();
3342   }
3343 
3344   return (intptr_t)const_oop()->constant_encoding();
3345 }
3346 
3347 
3348 //-----------------------------filter------------------------------------------
3349 // Do not allow interface-vs.-noninterface joins to collapse to top.
3350 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
3351 
3352   const Type* ft = join_helper(kills, include_speculative);
3353   const TypeInstPtr* ftip = ft->isa_instptr();
3354   const TypeInstPtr* ktip = kills->isa_instptr();
3355 
3356   if (ft->empty()) {
3357     // Check for evil case of 'this' being a class and 'kills' expecting an
3358     // interface.  This can happen because the bytecodes do not contain
3359     // enough type info to distinguish a Java-level interface variable
3360     // from a Java-level object variable.  If we meet 2 classes which
3361     // both implement interface I, but their meet is at 'j/l/O' which
3362     // doesn't implement I, we have no way to tell if the result should
3363     // be 'I' or 'j/l/O'.  Thus we'll pick 'j/l/O'.  If this then flows
3364     // into a Phi which "knows" it's an Interface type we'll have to
3365     // uplift the type.
3366     if (!empty()) {
3367       if (ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface()) {
3368         return kills;           // Uplift to interface
3369       }
3370       // Also check for evil cases of 'this' being a class array
3371       // and 'kills' expecting an array of interfaces.
3372       Type::get_arrays_base_elements(ft, kills, NULL, &ktip);
3373       if (ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface()) {
3374         return kills;           // Uplift to array of interface
3375       }
3376     }
3377 
3378     return Type::TOP;           // Canonical empty value
3379   }
3380 
3381   // If we have an interface-typed Phi or cast and we narrow to a class type,
3382   // the join should report back the class.  However, if we have a J/L/Object
3383   // class-typed Phi and an interface flows in, it's possible that the meet &
3384   // join report an interface back out.  This isn't possible but happens
3385   // because the type system doesn't interact well with interfaces.
3386   if (ftip != NULL && ktip != NULL &&
3387       ftip->is_loaded() &&  ftip->klass()->is_interface() &&
3388       ktip->is_loaded() && !ktip->klass()->is_interface()) {
3389     assert(!ftip->klass_is_exact(), "interface could not be exact");
3390     return ktip->cast_to_ptr_type(ftip->ptr());
3391   }
3392 
3393   return ft;
3394 }
3395 
3396 //------------------------------eq---------------------------------------------
3397 // Structural equality check for Type representations
3398 bool TypeOopPtr::eq( const Type *t ) const {
3399   const TypeOopPtr *a = (const TypeOopPtr*)t;
3400   if (_klass_is_exact != a->_klass_is_exact ||
3401       _instance_id != a->_instance_id)  return false;
3402   ciObject* one = const_oop();
3403   ciObject* two = a->const_oop();
3404   if (one == NULL || two == NULL) {
3405     return (one == two) && TypePtr::eq(t);
3406   } else {
3407     return one->equals(two) && TypePtr::eq(t);
3408   }
3409 }
3410 
3411 //------------------------------hash-------------------------------------------
3412 // Type-specific hashing function.
3413 int TypeOopPtr::hash(void) const {
3414   return
3415     java_add(java_add(const_oop() ? const_oop()->hash() : 0, _klass_is_exact),
3416              java_add(_instance_id, TypePtr::hash()));
3417 }
3418 
3419 //------------------------------dump2------------------------------------------
3420 #ifndef PRODUCT
3421 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3422   st->print("oopptr:%s", ptr_msg[_ptr]);
3423   if( _klass_is_exact ) st->print(":exact");
3424   if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
3425   _offset.dump2(st);
3426   if (_instance_id == InstanceTop)
3427     st->print(",iid=top");
3428   else if (_instance_id != InstanceBot)
3429     st->print(",iid=%d",_instance_id);
3430 
3431   dump_inline_depth(st);
3432   dump_speculative(st);
3433 }
3434 #endif
3435 
3436 //------------------------------singleton--------------------------------------
3437 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3438 // constants
3439 bool TypeOopPtr::singleton(void) const {
3440   // detune optimizer to not generate constant oop + constant offset as a constant!
3441   // TopPTR, Null, AnyNull, Constant are all singletons
3442   return (offset() == 0) && !below_centerline(_ptr);
3443 }
3444 
3445 //------------------------------add_offset-------------------------------------
3446 const TypePtr *TypeOopPtr::add_offset(intptr_t offset) const {
3447   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
3448 }
3449 
3450 /**
3451  * Return same type without a speculative part
3452  */
3453 const Type* TypeOopPtr::remove_speculative() const {
3454   if (_speculative == NULL) {
3455     return this;
3456   }
3457   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
3458   return make(_ptr, _offset, _instance_id, NULL, _inline_depth);
3459 }
3460 
3461 /**
3462  * Return same type but drop speculative part if we know we won't use
3463  * it
3464  */
3465 const Type* TypeOopPtr::cleanup_speculative() const {
3466   // If the klass is exact and the ptr is not null then there's
3467   // nothing that the speculative type can help us with
3468   if (klass_is_exact() && !maybe_null()) {
3469     return remove_speculative();
3470   }
3471   return TypePtr::cleanup_speculative();
3472 }
3473 
3474 /**
3475  * Return same type but with a different inline depth (used for speculation)
3476  *
3477  * @param depth  depth to meet with
3478  */
3479 const TypePtr* TypeOopPtr::with_inline_depth(int depth) const {
3480   if (!UseInlineDepthForSpeculativeTypes) {
3481     return this;
3482   }
3483   return make(_ptr, _offset, _instance_id, _speculative, depth);
3484 }
3485 
3486 //------------------------------meet_instance_id--------------------------------
3487 int TypeOopPtr::meet_instance_id( int instance_id ) const {
3488   // Either is 'TOP' instance?  Return the other instance!
3489   if( _instance_id == InstanceTop ) return  instance_id;
3490   if(  instance_id == InstanceTop ) return _instance_id;
3491   // If either is different, return 'BOTTOM' instance
3492   if( _instance_id != instance_id ) return InstanceBot;
3493   return _instance_id;
3494 }
3495 
3496 //------------------------------dual_instance_id--------------------------------
3497 int TypeOopPtr::dual_instance_id( ) const {
3498   if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM
3499   if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP
3500   return _instance_id;              // Map everything else into self
3501 }
3502 
3503 /**
3504  * Check whether new profiling would improve speculative type
3505  *
3506  * @param   exact_kls    class from profiling
3507  * @param   inline_depth inlining depth of profile point
3508  *
3509  * @return  true if type profile is valuable
3510  */
3511 bool TypeOopPtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
3512   // no way to improve an already exact type
3513   if (klass_is_exact()) {
3514     return false;
3515   }
3516   return TypePtr::would_improve_type(exact_kls, inline_depth);
3517 }
3518 
3519 //=============================================================================
3520 // Convenience common pre-built types.
3521 const TypeInstPtr *TypeInstPtr::NOTNULL;
3522 const TypeInstPtr *TypeInstPtr::BOTTOM;
3523 const TypeInstPtr *TypeInstPtr::MIRROR;
3524 const TypeInstPtr *TypeInstPtr::MARK;
3525 const TypeInstPtr *TypeInstPtr::KLASS;
3526 
3527 //------------------------------TypeInstPtr-------------------------------------
3528 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, Offset off,
3529                          int instance_id, const TypePtr* speculative, int inline_depth)
3530   : TypeOopPtr(InstPtr, ptr, k, xk, o, off, instance_id, speculative, inline_depth),
3531     _name(k->name()) {
3532    assert(k != NULL &&
3533           (k->is_loaded() || o == NULL),
3534           "cannot have constants with non-loaded klass");
3535 };
3536 
3537 //------------------------------make-------------------------------------------
3538 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
3539                                      ciKlass* k,
3540                                      bool xk,
3541                                      ciObject* o,
3542                                      Offset offset,
3543                                      int instance_id,
3544                                      const TypePtr* speculative,
3545                                      int inline_depth) {
3546   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
3547   // Either const_oop() is NULL or else ptr is Constant
3548   assert( (!o && ptr != Constant) || (o && ptr == Constant),
3549           "constant pointers must have a value supplied" );
3550   // Ptr is never Null
3551   assert( ptr != Null, "NULL pointers are not typed" );
3552 
3553   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3554   if (!UseExactTypes)  xk = false;
3555   if (ptr == Constant) {
3556     // Note:  This case includes meta-object constants, such as methods.
3557     xk = true;
3558   } else if (k->is_loaded()) {
3559     ciInstanceKlass* ik = k->as_instance_klass();
3560     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
3561     if (xk && ik->is_interface())  xk = false;  // no exact interface
3562   }
3563 
3564   // Now hash this baby
3565   TypeInstPtr *result =
3566     (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o ,offset, instance_id, speculative, inline_depth))->hashcons();
3567 
3568   return result;
3569 }
3570 
3571 /**
3572  *  Create constant type for a constant boxed value
3573  */
3574 const Type* TypeInstPtr::get_const_boxed_value() const {
3575   assert(is_ptr_to_boxed_value(), "should be called only for boxed value");
3576   assert((const_oop() != NULL), "should be called only for constant object");
3577   ciConstant constant = const_oop()->as_instance()->field_value_by_offset(offset());
3578   BasicType bt = constant.basic_type();
3579   switch (bt) {
3580     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
3581     case T_INT:      return TypeInt::make(constant.as_int());
3582     case T_CHAR:     return TypeInt::make(constant.as_char());
3583     case T_BYTE:     return TypeInt::make(constant.as_byte());
3584     case T_SHORT:    return TypeInt::make(constant.as_short());
3585     case T_FLOAT:    return TypeF::make(constant.as_float());
3586     case T_DOUBLE:   return TypeD::make(constant.as_double());
3587     case T_LONG:     return TypeLong::make(constant.as_long());
3588     default:         break;
3589   }
3590   fatal("Invalid boxed value type '%s'", type2name(bt));
3591   return NULL;
3592 }
3593 
3594 //------------------------------cast_to_ptr_type-------------------------------
3595 const Type *TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
3596   if( ptr == _ptr ) return this;
3597   // Reconstruct _sig info here since not a problem with later lazy
3598   // construction, _sig will show up on demand.
3599   return make(ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, _inline_depth);
3600 }
3601 
3602 
3603 //-----------------------------cast_to_exactness-------------------------------
3604 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
3605   if( klass_is_exact == _klass_is_exact ) return this;
3606   if (!UseExactTypes)  return this;
3607   if (!_klass->is_loaded())  return this;
3608   ciInstanceKlass* ik = _klass->as_instance_klass();
3609   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
3610   if( ik->is_interface() )              return this;  // cannot set xk
3611   return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id, _speculative, _inline_depth);
3612 }
3613 
3614 //-----------------------------cast_to_instance_id----------------------------
3615 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const {
3616   if( instance_id == _instance_id ) return this;
3617   return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id, _speculative, _inline_depth);
3618 }
3619 
3620 //------------------------------xmeet_unloaded---------------------------------
3621 // Compute the MEET of two InstPtrs when at least one is unloaded.
3622 // Assume classes are different since called after check for same name/class-loader
3623 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
3624     Offset off = meet_offset(tinst->offset());
3625     PTR ptr = meet_ptr(tinst->ptr());
3626     int instance_id = meet_instance_id(tinst->instance_id());
3627     const TypePtr* speculative = xmeet_speculative(tinst);
3628     int depth = meet_inline_depth(tinst->inline_depth());
3629 
3630     const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
3631     const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
3632     if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
3633       //
3634       // Meet unloaded class with java/lang/Object
3635       //
3636       // Meet
3637       //          |                     Unloaded Class
3638       //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
3639       //  ===================================================================
3640       //   TOP    | ..........................Unloaded......................|
3641       //  AnyNull |  U-AN    |................Unloaded......................|
3642       // Constant | ... O-NN .................................. |   O-BOT   |
3643       //  NotNull | ... O-NN .................................. |   O-BOT   |
3644       //  BOTTOM  | ........................Object-BOTTOM ..................|
3645       //
3646       assert(loaded->ptr() != TypePtr::Null, "insanity check");
3647       //
3648       if(      loaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
3649       else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make(ptr, unloaded->klass(), false, NULL, off, instance_id, speculative, depth); }
3650       else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
3651       else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
3652         if (unloaded->ptr() == TypePtr::BotPTR  ) { return TypeInstPtr::BOTTOM;  }
3653         else                                      { return TypeInstPtr::NOTNULL; }
3654       }
3655       else if( unloaded->ptr() == TypePtr::TopPTR )  { return unloaded; }
3656 
3657       return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr();
3658     }
3659 
3660     // Both are unloaded, not the same class, not Object
3661     // Or meet unloaded with a different loaded class, not java/lang/Object
3662     if( ptr != TypePtr::BotPTR ) {
3663       return TypeInstPtr::NOTNULL;
3664     }
3665     return TypeInstPtr::BOTTOM;
3666 }
3667 
3668 
3669 //------------------------------meet-------------------------------------------
3670 // Compute the MEET of two types.  It returns a new Type object.
3671 const Type *TypeInstPtr::xmeet_helper(const Type *t) const {
3672   // Perform a fast test for common case; meeting the same types together.
3673   if( this == t ) return this;  // Meeting same type-rep?
3674 
3675   // Current "this->_base" is Pointer
3676   switch (t->base()) {          // switch on original type
3677 
3678   case Int:                     // Mixing ints & oops happens when javac
3679   case Long:                    // reuses local variables
3680   case FloatTop:
3681   case FloatCon:
3682   case FloatBot:
3683   case DoubleTop:
3684   case DoubleCon:
3685   case DoubleBot:
3686   case NarrowOop:
3687   case NarrowKlass:
3688   case Bottom:                  // Ye Olde Default
3689     return Type::BOTTOM;
3690   case Top:
3691     return this;
3692 
3693   default:                      // All else is a mistake
3694     typerr(t);
3695 
3696   case MetadataPtr:
3697   case KlassPtr:
3698   case RawPtr: return TypePtr::BOTTOM;
3699 
3700   case AryPtr: {                // All arrays inherit from Object class
3701     const TypeAryPtr *tp = t->is_aryptr();
3702     Offset offset = meet_offset(tp->offset());
3703     PTR ptr = meet_ptr(tp->ptr());
3704     int instance_id = meet_instance_id(tp->instance_id());
3705     const TypePtr* speculative = xmeet_speculative(tp);
3706     int depth = meet_inline_depth(tp->inline_depth());
3707     switch (ptr) {
3708     case TopPTR:
3709     case AnyNull:                // Fall 'down' to dual of object klass
3710       // For instances when a subclass meets a superclass we fall
3711       // below the centerline when the superclass is exact. We need to
3712       // do the same here.
3713       if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
3714         return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, tp->_field_offset, instance_id, speculative, depth);
3715       } else {
3716         // cannot subclass, so the meet has to fall badly below the centerline
3717         ptr = NotNull;
3718         instance_id = InstanceBot;
3719         return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
3720       }
3721     case Constant:
3722     case NotNull:
3723     case BotPTR:                // Fall down to object klass
3724       // LCA is object_klass, but if we subclass from the top we can do better
3725       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
3726         // If 'this' (InstPtr) is above the centerline and it is Object class
3727         // then we can subclass in the Java class hierarchy.
3728         // For instances when a subclass meets a superclass we fall
3729         // below the centerline when the superclass is exact. We need
3730         // to do the same here.
3731         if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
3732           // that is, tp's array type is a subtype of my klass
3733           return TypeAryPtr::make(ptr, (ptr == Constant ? tp->const_oop() : NULL),
3734                                   tp->ary(), tp->klass(), tp->klass_is_exact(), offset, tp->_field_offset, instance_id, speculative, depth);
3735         }
3736       }
3737       // The other case cannot happen, since I cannot be a subtype of an array.
3738       // The meet falls down to Object class below centerline.
3739       if( ptr == Constant )
3740          ptr = NotNull;
3741       instance_id = InstanceBot;
3742       return make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
3743     default: typerr(t);
3744     }
3745   }
3746 
3747   case OopPtr: {                // Meeting to OopPtrs
3748     // Found a OopPtr type vs self-InstPtr type
3749     const TypeOopPtr *tp = t->is_oopptr();
3750     Offset offset = meet_offset(tp->offset());
3751     PTR ptr = meet_ptr(tp->ptr());
3752     switch (tp->ptr()) {
3753     case TopPTR:
3754     case AnyNull: {
3755       int instance_id = meet_instance_id(InstanceTop);
3756       const TypePtr* speculative = xmeet_speculative(tp);
3757       int depth = meet_inline_depth(tp->inline_depth());
3758       return make(ptr, klass(), klass_is_exact(),
3759                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth);
3760     }
3761     case NotNull:
3762     case BotPTR: {
3763       int instance_id = meet_instance_id(tp->instance_id());
3764       const TypePtr* speculative = xmeet_speculative(tp);
3765       int depth = meet_inline_depth(tp->inline_depth());
3766       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
3767     }
3768     default: typerr(t);
3769     }
3770   }
3771 
3772   case AnyPtr: {                // Meeting to AnyPtrs
3773     // Found an AnyPtr type vs self-InstPtr type
3774     const TypePtr *tp = t->is_ptr();
3775     Offset offset = meet_offset(tp->offset());
3776     PTR ptr = meet_ptr(tp->ptr());
3777     int instance_id = meet_instance_id(InstanceTop);
3778     const TypePtr* speculative = xmeet_speculative(tp);
3779     int depth = meet_inline_depth(tp->inline_depth());
3780     switch (tp->ptr()) {
3781     case Null:
3782       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3783       // else fall through to AnyNull
3784     case TopPTR:
3785     case AnyNull: {
3786       return make(ptr, klass(), klass_is_exact(),
3787                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth);
3788     }
3789     case NotNull:
3790     case BotPTR:
3791       return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
3792     default: typerr(t);
3793     }
3794   }
3795 
3796   /*
3797                  A-top         }
3798                /   |   \       }  Tops
3799            B-top A-any C-top   }
3800               | /  |  \ |      }  Any-nulls
3801            B-any   |   C-any   }
3802               |    |    |
3803            B-con A-con C-con   } constants; not comparable across classes
3804               |    |    |
3805            B-not   |   C-not   }
3806               | \  |  / |      }  not-nulls
3807            B-bot A-not C-bot   }
3808                \   |   /       }  Bottoms
3809                  A-bot         }
3810   */
3811 
3812   case InstPtr: {                // Meeting 2 Oops?
3813     // Found an InstPtr sub-type vs self-InstPtr type
3814     const TypeInstPtr *tinst = t->is_instptr();
3815     Offset off = meet_offset( tinst->offset() );
3816     PTR ptr = meet_ptr( tinst->ptr() );
3817     int instance_id = meet_instance_id(tinst->instance_id());
3818     const TypePtr* speculative = xmeet_speculative(tinst);
3819     int depth = meet_inline_depth(tinst->inline_depth());
3820 
3821     // Check for easy case; klasses are equal (and perhaps not loaded!)
3822     // If we have constants, then we created oops so classes are loaded
3823     // and we can handle the constants further down.  This case handles
3824     // both-not-loaded or both-loaded classes
3825     if (ptr != Constant && klass()->equals(tinst->klass()) && klass_is_exact() == tinst->klass_is_exact()) {
3826       return make(ptr, klass(), klass_is_exact(), NULL, off, instance_id, speculative, depth);
3827     }
3828 
3829     // Classes require inspection in the Java klass hierarchy.  Must be loaded.
3830     ciKlass* tinst_klass = tinst->klass();
3831     ciKlass* this_klass  = this->klass();
3832     bool tinst_xk = tinst->klass_is_exact();
3833     bool this_xk  = this->klass_is_exact();
3834     if (!tinst_klass->is_loaded() || !this_klass->is_loaded() ) {
3835       // One of these classes has not been loaded
3836       const TypeInstPtr *unloaded_meet = xmeet_unloaded(tinst);
3837 #ifndef PRODUCT
3838       if( PrintOpto && Verbose ) {
3839         tty->print("meet of unloaded classes resulted in: "); unloaded_meet->dump(); tty->cr();
3840         tty->print("  this == "); this->dump(); tty->cr();
3841         tty->print(" tinst == "); tinst->dump(); tty->cr();
3842       }
3843 #endif
3844       return unloaded_meet;
3845     }
3846 
3847     // Handle mixing oops and interfaces first.
3848     if( this_klass->is_interface() && !(tinst_klass->is_interface() ||
3849                                         tinst_klass == ciEnv::current()->Object_klass())) {
3850       ciKlass *tmp = tinst_klass; // Swap interface around
3851       tinst_klass = this_klass;
3852       this_klass = tmp;
3853       bool tmp2 = tinst_xk;
3854       tinst_xk = this_xk;
3855       this_xk = tmp2;
3856     }
3857     if (tinst_klass->is_interface() &&
3858         !(this_klass->is_interface() ||
3859           // Treat java/lang/Object as an honorary interface,
3860           // because we need a bottom for the interface hierarchy.
3861           this_klass == ciEnv::current()->Object_klass())) {
3862       // Oop meets interface!
3863 
3864       // See if the oop subtypes (implements) interface.
3865       ciKlass *k;
3866       bool xk;
3867       if( this_klass->is_subtype_of( tinst_klass ) ) {
3868         // Oop indeed subtypes.  Now keep oop or interface depending
3869         // on whether we are both above the centerline or either is
3870         // below the centerline.  If we are on the centerline
3871         // (e.g., Constant vs. AnyNull interface), use the constant.
3872         k  = below_centerline(ptr) ? tinst_klass : this_klass;
3873         // If we are keeping this_klass, keep its exactness too.
3874         xk = below_centerline(ptr) ? tinst_xk    : this_xk;
3875       } else {                  // Does not implement, fall to Object
3876         // Oop does not implement interface, so mixing falls to Object
3877         // just like the verifier does (if both are above the
3878         // centerline fall to interface)
3879         k = above_centerline(ptr) ? tinst_klass : ciEnv::current()->Object_klass();
3880         xk = above_centerline(ptr) ? tinst_xk : false;
3881         // Watch out for Constant vs. AnyNull interface.
3882         if (ptr == Constant)  ptr = NotNull;   // forget it was a constant
3883         instance_id = InstanceBot;
3884       }
3885       ciObject* o = NULL;  // the Constant value, if any
3886       if (ptr == Constant) {
3887         // Find out which constant.
3888         o = (this_klass == klass()) ? const_oop() : tinst->const_oop();
3889       }
3890       return make(ptr, k, xk, o, off, instance_id, speculative, depth);
3891     }
3892 
3893     // Either oop vs oop or interface vs interface or interface vs Object
3894 
3895     // !!! Here's how the symmetry requirement breaks down into invariants:
3896     // If we split one up & one down AND they subtype, take the down man.
3897     // If we split one up & one down AND they do NOT subtype, "fall hard".
3898     // If both are up and they subtype, take the subtype class.
3899     // If both are up and they do NOT subtype, "fall hard".
3900     // If both are down and they subtype, take the supertype class.
3901     // If both are down and they do NOT subtype, "fall hard".
3902     // Constants treated as down.
3903 
3904     // Now, reorder the above list; observe that both-down+subtype is also
3905     // "fall hard"; "fall hard" becomes the default case:
3906     // If we split one up & one down AND they subtype, take the down man.
3907     // If both are up and they subtype, take the subtype class.
3908 
3909     // If both are down and they subtype, "fall hard".
3910     // If both are down and they do NOT subtype, "fall hard".
3911     // If both are up and they do NOT subtype, "fall hard".
3912     // If we split one up & one down AND they do NOT subtype, "fall hard".
3913 
3914     // If a proper subtype is exact, and we return it, we return it exactly.
3915     // If a proper supertype is exact, there can be no subtyping relationship!
3916     // If both types are equal to the subtype, exactness is and-ed below the
3917     // centerline and or-ed above it.  (N.B. Constants are always exact.)
3918 
3919     // Check for subtyping:
3920     ciKlass *subtype = NULL;
3921     bool subtype_exact = false;
3922     if( tinst_klass->equals(this_klass) ) {
3923       subtype = this_klass;
3924       subtype_exact = below_centerline(ptr) ? (this_xk & tinst_xk) : (this_xk | tinst_xk);
3925     } else if( !tinst_xk && this_klass->is_subtype_of( tinst_klass ) ) {
3926       subtype = this_klass;     // Pick subtyping class
3927       subtype_exact = this_xk;
3928     } else if( !this_xk && tinst_klass->is_subtype_of( this_klass ) ) {
3929       subtype = tinst_klass;    // Pick subtyping class
3930       subtype_exact = tinst_xk;
3931     }
3932 
3933     if( subtype ) {
3934       if( above_centerline(ptr) ) { // both are up?
3935         this_klass = tinst_klass = subtype;
3936         this_xk = tinst_xk = subtype_exact;
3937       } else if( above_centerline(this ->_ptr) && !above_centerline(tinst->_ptr) ) {
3938         this_klass = tinst_klass; // tinst is down; keep down man
3939         this_xk = tinst_xk;
3940       } else if( above_centerline(tinst->_ptr) && !above_centerline(this ->_ptr) ) {
3941         tinst_klass = this_klass; // this is down; keep down man
3942         tinst_xk = this_xk;
3943       } else {
3944         this_xk = subtype_exact;  // either they are equal, or we'll do an LCA
3945       }
3946     }
3947 
3948     // Check for classes now being equal
3949     if (tinst_klass->equals(this_klass)) {
3950       // If the klasses are equal, the constants may still differ.  Fall to
3951       // NotNull if they do (neither constant is NULL; that is a special case
3952       // handled elsewhere).
3953       ciObject* o = NULL;             // Assume not constant when done
3954       ciObject* this_oop  = const_oop();
3955       ciObject* tinst_oop = tinst->const_oop();
3956       if( ptr == Constant ) {
3957         if (this_oop != NULL && tinst_oop != NULL &&
3958             this_oop->equals(tinst_oop) )
3959           o = this_oop;
3960         else if (above_centerline(this ->_ptr))
3961           o = tinst_oop;
3962         else if (above_centerline(tinst ->_ptr))
3963           o = this_oop;
3964         else
3965           ptr = NotNull;
3966       }
3967       return make(ptr, this_klass, this_xk, o, off, instance_id, speculative, depth);
3968     } // Else classes are not equal
3969 
3970     // Since klasses are different, we require a LCA in the Java
3971     // class hierarchy - which means we have to fall to at least NotNull.
3972     if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
3973       ptr = NotNull;
3974 
3975     instance_id = InstanceBot;
3976 
3977     // Now we find the LCA of Java classes
3978     ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
3979     return make(ptr, k, false, NULL, off, instance_id, speculative, depth);
3980   } // End of case InstPtr
3981 
3982   } // End of switch
3983   return this;                  // Return the double constant
3984 }
3985 
3986 
3987 //------------------------java_mirror_type--------------------------------------
3988 ciType* TypeInstPtr::java_mirror_type() const {
3989   // must be a singleton type
3990   if( const_oop() == NULL )  return NULL;
3991 
3992   // must be of type java.lang.Class
3993   if( klass() != ciEnv::current()->Class_klass() )  return NULL;
3994 
3995   return const_oop()->as_instance()->java_mirror_type();
3996 }
3997 
3998 
3999 //------------------------------xdual------------------------------------------
4000 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
4001 // inheritance mechanism.
4002 const Type *TypeInstPtr::xdual() const {
4003   return new TypeInstPtr(dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4004 }
4005 
4006 //------------------------------eq---------------------------------------------
4007 // Structural equality check for Type representations
4008 bool TypeInstPtr::eq( const Type *t ) const {
4009   const TypeInstPtr *p = t->is_instptr();
4010   return
4011     klass()->equals(p->klass()) &&
4012     TypeOopPtr::eq(p);          // Check sub-type stuff
4013 }
4014 
4015 //------------------------------hash-------------------------------------------
4016 // Type-specific hashing function.
4017 int TypeInstPtr::hash(void) const {
4018   int hash = java_add(klass()->hash(), TypeOopPtr::hash());
4019   return hash;
4020 }
4021 
4022 //------------------------------dump2------------------------------------------
4023 // Dump oop Type
4024 #ifndef PRODUCT
4025 void TypeInstPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4026   // Print the name of the klass.
4027   klass()->print_name_on(st);
4028 
4029   switch( _ptr ) {
4030   case Constant:
4031     // TO DO: Make CI print the hex address of the underlying oop.
4032     if (WizardMode || Verbose) {
4033       const_oop()->print_oop(st);
4034     }
4035   case BotPTR:
4036     if (!WizardMode && !Verbose) {
4037       if( _klass_is_exact ) st->print(":exact");
4038       break;
4039     }
4040   case TopPTR:
4041   case AnyNull:
4042   case NotNull:
4043     st->print(":%s", ptr_msg[_ptr]);
4044     if( _klass_is_exact ) st->print(":exact");
4045     break;
4046   }
4047 
4048   _offset.dump2(st);
4049 
4050   st->print(" *");
4051   if (_instance_id == InstanceTop)
4052     st->print(",iid=top");
4053   else if (_instance_id != InstanceBot)
4054     st->print(",iid=%d",_instance_id);
4055 
4056   dump_inline_depth(st);
4057   dump_speculative(st);
4058 }
4059 #endif
4060 
4061 //------------------------------add_offset-------------------------------------
4062 const TypePtr *TypeInstPtr::add_offset(intptr_t offset) const {
4063   return make(_ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset),
4064               _instance_id, add_offset_speculative(offset), _inline_depth);
4065 }
4066 
4067 const Type *TypeInstPtr::remove_speculative() const {
4068   if (_speculative == NULL) {
4069     return this;
4070   }
4071   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4072   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset,
4073               _instance_id, NULL, _inline_depth);
4074 }
4075 
4076 const TypePtr *TypeInstPtr::with_inline_depth(int depth) const {
4077   if (!UseInlineDepthForSpeculativeTypes) {
4078     return this;
4079   }
4080   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth);
4081 }
4082 
4083 //=============================================================================
4084 // Convenience common pre-built types.
4085 const TypeAryPtr *TypeAryPtr::RANGE;
4086 const TypeAryPtr *TypeAryPtr::OOPS;
4087 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
4088 const TypeAryPtr *TypeAryPtr::BYTES;
4089 const TypeAryPtr *TypeAryPtr::SHORTS;
4090 const TypeAryPtr *TypeAryPtr::CHARS;
4091 const TypeAryPtr *TypeAryPtr::INTS;
4092 const TypeAryPtr *TypeAryPtr::LONGS;
4093 const TypeAryPtr *TypeAryPtr::FLOATS;
4094 const TypeAryPtr *TypeAryPtr::DOUBLES;
4095 
4096 //------------------------------make-------------------------------------------
4097 const TypeAryPtr* TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4098                                    int instance_id, const TypePtr* speculative, int inline_depth) {
4099   assert(!(k == NULL && ary->_elem->isa_int()),
4100          "integral arrays must be pre-equipped with a class");
4101   if (!xk)  xk = ary->ary_must_be_exact();
4102   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
4103   if (!UseExactTypes)  xk = (ptr == Constant);
4104   return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, field_offset, instance_id, false, speculative, inline_depth))->hashcons();
4105 }
4106 
4107 //------------------------------make-------------------------------------------
4108 const TypeAryPtr* TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4109                                    int instance_id, const TypePtr* speculative, int inline_depth,
4110                                    bool is_autobox_cache) {
4111   assert(!(k == NULL && ary->_elem->isa_int()),
4112          "integral arrays must be pre-equipped with a class");
4113   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4114   if (!xk)  xk = (o != NULL) || ary->ary_must_be_exact();
4115   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
4116   if (!UseExactTypes)  xk = (ptr == Constant);
4117   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, field_offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4118 }
4119 
4120 //------------------------------cast_to_ptr_type-------------------------------
4121 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4122   if( ptr == _ptr ) return this;
4123   return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4124 }
4125 
4126 
4127 //-----------------------------cast_to_exactness-------------------------------
4128 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4129   if( klass_is_exact == _klass_is_exact ) return this;
4130   if (!UseExactTypes)  return this;
4131   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
4132   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4133 }
4134 
4135 //-----------------------------cast_to_instance_id----------------------------
4136 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const {
4137   if( instance_id == _instance_id ) return this;
4138   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth, _is_autobox_cache);
4139 }
4140 
4141 //-----------------------------narrow_size_type-------------------------------
4142 // Local cache for arrayOopDesc::max_array_length(etype),
4143 // which is kind of slow (and cached elsewhere by other users).
4144 static jint max_array_length_cache[T_CONFLICT+1];
4145 static jint max_array_length(BasicType etype) {
4146   jint& cache = max_array_length_cache[etype];
4147   jint res = cache;
4148   if (res == 0) {
4149     switch (etype) {
4150     case T_NARROWOOP:
4151       etype = T_OBJECT;
4152       break;
4153     case T_NARROWKLASS:
4154     case T_CONFLICT:
4155     case T_ILLEGAL:
4156     case T_VOID:
4157       etype = T_BYTE;           // will produce conservatively high value
4158     }
4159     cache = res = arrayOopDesc::max_array_length(etype);
4160   }
4161   return res;
4162 }
4163 
4164 // Narrow the given size type to the index range for the given array base type.
4165 // Return NULL if the resulting int type becomes empty.
4166 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const {
4167   jint hi = size->_hi;
4168   jint lo = size->_lo;
4169   jint min_lo = 0;
4170   jint max_hi = max_array_length(elem()->basic_type());
4171   //if (index_not_size)  --max_hi;     // type of a valid array index, FTR
4172   bool chg = false;
4173   if (lo < min_lo) {
4174     lo = min_lo;
4175     if (size->is_con()) {
4176       hi = lo;
4177     }
4178     chg = true;
4179   }
4180   if (hi > max_hi) {
4181     hi = max_hi;
4182     if (size->is_con()) {
4183       lo = hi;
4184     }
4185     chg = true;
4186   }
4187   // Negative length arrays will produce weird intermediate dead fast-path code
4188   if (lo > hi)
4189     return TypeInt::ZERO;
4190   if (!chg)
4191     return size;
4192   return TypeInt::make(lo, hi, Type::WidenMin);
4193 }
4194 
4195 //-------------------------------cast_to_size----------------------------------
4196 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4197   assert(new_size != NULL, "");
4198   new_size = narrow_size_type(new_size);
4199   if (new_size == size())  return this;
4200   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
4201   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4202 }
4203 
4204 //------------------------------cast_to_stable---------------------------------
4205 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
4206   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
4207     return this;
4208 
4209   const Type* elem = this->elem();
4210   const TypePtr* elem_ptr = elem->make_ptr();
4211 
4212   if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) {
4213     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
4214     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
4215   }
4216 
4217   const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
4218 
4219   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4220 }
4221 
4222 //-----------------------------stable_dimension--------------------------------
4223 int TypeAryPtr::stable_dimension() const {
4224   if (!is_stable())  return 0;
4225   int dim = 1;
4226   const TypePtr* elem_ptr = elem()->make_ptr();
4227   if (elem_ptr != NULL && elem_ptr->isa_aryptr())
4228     dim += elem_ptr->is_aryptr()->stable_dimension();
4229   return dim;
4230 }
4231 
4232 //----------------------cast_to_autobox_cache-----------------------------------
4233 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache(bool cache) const {
4234   if (is_autobox_cache() == cache)  return this;
4235   const TypeOopPtr* etype = elem()->make_oopptr();
4236   if (etype == NULL)  return this;
4237   // The pointers in the autobox arrays are always non-null.
4238   TypePtr::PTR ptr_type = cache ? TypePtr::NotNull : TypePtr::AnyNull;
4239   etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
4240   const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable());
4241   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, cache);
4242 }
4243 
4244 //------------------------------eq---------------------------------------------
4245 // Structural equality check for Type representations
4246 bool TypeAryPtr::eq( const Type *t ) const {
4247   const TypeAryPtr *p = t->is_aryptr();
4248   return
4249     _ary == p->_ary &&  // Check array
4250     TypeOopPtr::eq(p) &&// Check sub-parts
4251     _field_offset == p->_field_offset;
4252 }
4253 
4254 //------------------------------hash-------------------------------------------
4255 // Type-specific hashing function.
4256 int TypeAryPtr::hash(void) const {
4257   return (intptr_t)_ary + TypeOopPtr::hash() + field_offset();
4258 }
4259 
4260 //------------------------------meet-------------------------------------------
4261 // Compute the MEET of two types.  It returns a new Type object.
4262 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
4263   // Perform a fast test for common case; meeting the same types together.
4264   if( this == t ) return this;  // Meeting same type-rep?
4265   // Current "this->_base" is Pointer
4266   switch (t->base()) {          // switch on original type
4267 
4268   // Mixing ints & oops happens when javac reuses local variables
4269   case Int:
4270   case Long:
4271   case FloatTop:
4272   case FloatCon:
4273   case FloatBot:
4274   case DoubleTop:
4275   case DoubleCon:
4276   case DoubleBot:
4277   case NarrowOop:
4278   case NarrowKlass:
4279   case Bottom:                  // Ye Olde Default
4280     return Type::BOTTOM;
4281   case Top:
4282     return this;
4283 
4284   default:                      // All else is a mistake
4285     typerr(t);
4286 
4287   case OopPtr: {                // Meeting to OopPtrs
4288     // Found a OopPtr type vs self-AryPtr type
4289     const TypeOopPtr *tp = t->is_oopptr();
4290     Offset offset = meet_offset(tp->offset());
4291     PTR ptr = meet_ptr(tp->ptr());
4292     int depth = meet_inline_depth(tp->inline_depth());
4293     const TypePtr* speculative = xmeet_speculative(tp);
4294     switch (tp->ptr()) {
4295     case TopPTR:
4296     case AnyNull: {
4297       int instance_id = meet_instance_id(InstanceTop);
4298       return make(ptr, (ptr == Constant ? const_oop() : NULL),
4299                   _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
4300     }
4301     case BotPTR:
4302     case NotNull: {
4303       int instance_id = meet_instance_id(tp->instance_id());
4304       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4305     }
4306     default: ShouldNotReachHere();
4307     }
4308   }
4309 
4310   case AnyPtr: {                // Meeting two AnyPtrs
4311     // Found an AnyPtr type vs self-AryPtr type
4312     const TypePtr *tp = t->is_ptr();
4313     Offset offset = meet_offset(tp->offset());
4314     PTR ptr = meet_ptr(tp->ptr());
4315     const TypePtr* speculative = xmeet_speculative(tp);
4316     int depth = meet_inline_depth(tp->inline_depth());
4317     switch (tp->ptr()) {
4318     case TopPTR:
4319       return this;
4320     case BotPTR:
4321     case NotNull:
4322       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4323     case Null:
4324       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4325       // else fall through to AnyNull
4326     case AnyNull: {
4327       int instance_id = meet_instance_id(InstanceTop);
4328       return make(ptr, (ptr == Constant ? const_oop() : NULL),
4329                   _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
4330     }
4331     default: ShouldNotReachHere();
4332     }
4333   }
4334 
4335   case MetadataPtr:
4336   case KlassPtr:
4337   case RawPtr: return TypePtr::BOTTOM;
4338 
4339   case AryPtr: {                // Meeting 2 references?
4340     const TypeAryPtr *tap = t->is_aryptr();
4341     Offset off = meet_offset(tap->offset());
4342     Offset field_off = meet_field_offset(tap->field_offset());
4343     const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
4344     PTR ptr = meet_ptr(tap->ptr());
4345     int instance_id = meet_instance_id(tap->instance_id());
4346     const TypePtr* speculative = xmeet_speculative(tap);
4347     int depth = meet_inline_depth(tap->inline_depth());
4348     ciKlass* lazy_klass = NULL;
4349     if (tary->_elem->isa_int()) {
4350       // Integral array element types have irrelevant lattice relations.
4351       // It is the klass that determines array layout, not the element type.
4352       if (_klass == NULL)
4353         lazy_klass = tap->_klass;
4354       else if (tap->_klass == NULL || tap->_klass == _klass) {
4355         lazy_klass = _klass;
4356       } else {
4357         // Something like byte[int+] meets char[int+].
4358         // This must fall to bottom, not (int[-128..65535])[int+].
4359         instance_id = InstanceBot;
4360         tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
4361       }
4362     } else // Non integral arrays.
4363       // Must fall to bottom if exact klasses in upper lattice
4364       // are not equal or super klass is exact.
4365       if ((above_centerline(ptr) || ptr == Constant) && klass() != tap->klass() &&
4366           // meet with top[] and bottom[] are processed further down:
4367           tap->_klass != NULL  && this->_klass != NULL   &&
4368           // both are exact and not equal:
4369           ((tap->_klass_is_exact && this->_klass_is_exact) ||
4370            // 'tap'  is exact and super or unrelated:
4371            (tap->_klass_is_exact && !tap->klass()->is_subtype_of(klass())) ||
4372            // 'this' is exact and super or unrelated:
4373            (this->_klass_is_exact && !klass()->is_subtype_of(tap->klass())))) {
4374       if (above_centerline(ptr)) {
4375         tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
4376       }
4377       return make(NotNull, NULL, tary, lazy_klass, false, off, field_off, InstanceBot, speculative, depth);
4378     }
4379 
4380     bool xk = false;
4381     switch (tap->ptr()) {
4382     case AnyNull:
4383     case TopPTR:
4384       // Compute new klass on demand, do not use tap->_klass
4385       if (below_centerline(this->_ptr)) {
4386         xk = this->_klass_is_exact;
4387       } else {
4388         xk = (tap->_klass_is_exact | this->_klass_is_exact);
4389       }
4390       return make(ptr, const_oop(), tary, lazy_klass, xk, off, field_off, instance_id, speculative, depth);
4391     case Constant: {
4392       ciObject* o = const_oop();
4393       if( _ptr == Constant ) {
4394         if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) {
4395           xk = (klass() == tap->klass());
4396           ptr = NotNull;
4397           o = NULL;
4398           instance_id = InstanceBot;
4399         } else {
4400           xk = true;
4401         }
4402       } else if(above_centerline(_ptr)) {
4403         o = tap->const_oop();
4404         xk = true;
4405       } else {
4406         // Only precise for identical arrays
4407         xk = this->_klass_is_exact && (klass() == tap->klass());
4408       }
4409       return TypeAryPtr::make(ptr, o, tary, lazy_klass, xk, off, field_off, instance_id, speculative, depth);
4410     }
4411     case NotNull:
4412     case BotPTR:
4413       // Compute new klass on demand, do not use tap->_klass
4414       if (above_centerline(this->_ptr))
4415             xk = tap->_klass_is_exact;
4416       else  xk = (tap->_klass_is_exact & this->_klass_is_exact) &&
4417               (klass() == tap->klass()); // Only precise for identical arrays
4418       return TypeAryPtr::make(ptr, NULL, tary, lazy_klass, xk, off, field_off, instance_id, speculative, depth);
4419     default: ShouldNotReachHere();
4420     }
4421   }
4422 
4423   // All arrays inherit from Object class
4424   case InstPtr: {
4425     const TypeInstPtr *tp = t->is_instptr();
4426     Offset offset = meet_offset(tp->offset());
4427     PTR ptr = meet_ptr(tp->ptr());
4428     int instance_id = meet_instance_id(tp->instance_id());
4429     const TypePtr* speculative = xmeet_speculative(tp);
4430     int depth = meet_inline_depth(tp->inline_depth());
4431     switch (ptr) {
4432     case TopPTR:
4433     case AnyNull:                // Fall 'down' to dual of object klass
4434       // For instances when a subclass meets a superclass we fall
4435       // below the centerline when the superclass is exact. We need to
4436       // do the same here.
4437       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
4438         return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
4439       } else {
4440         // cannot subclass, so the meet has to fall badly below the centerline
4441         ptr = NotNull;
4442         instance_id = InstanceBot;
4443         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative, depth);
4444       }
4445     case Constant:
4446     case NotNull:
4447     case BotPTR:                // Fall down to object klass
4448       // LCA is object_klass, but if we subclass from the top we can do better
4449       if (above_centerline(tp->ptr())) {
4450         // If 'tp'  is above the centerline and it is Object class
4451         // then we can subclass in the Java class hierarchy.
4452         // For instances when a subclass meets a superclass we fall
4453         // below the centerline when the superclass is exact. We need
4454         // to do the same here.
4455         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
4456           // that is, my array type is a subtype of 'tp' klass
4457           return make(ptr, (ptr == Constant ? const_oop() : NULL),
4458                       _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
4459         }
4460       }
4461       // The other case cannot happen, since t cannot be a subtype of an array.
4462       // The meet falls down to Object class below centerline.
4463       if( ptr == Constant )
4464          ptr = NotNull;
4465       instance_id = InstanceBot;
4466       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative, depth);
4467     default: typerr(t);
4468     }
4469   }
4470   }
4471   return this;                  // Lint noise
4472 }
4473 
4474 //------------------------------xdual------------------------------------------
4475 // Dual: compute field-by-field dual
4476 const Type *TypeAryPtr::xdual() const {
4477   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());
4478 }
4479 
4480 Type::Offset TypeAryPtr::meet_field_offset(int field_offset) const {
4481   return _field_offset.meet(Offset(field_offset));
4482 }
4483 
4484 //------------------------------dual_offset------------------------------------
4485 Type::Offset TypeAryPtr::dual_field_offset() const {
4486   return _field_offset.dual();
4487 }
4488 
4489 //----------------------interface_vs_oop---------------------------------------
4490 #ifdef ASSERT
4491 bool TypeAryPtr::interface_vs_oop(const Type *t) const {
4492   const TypeAryPtr* t_aryptr = t->isa_aryptr();
4493   if (t_aryptr) {
4494     return _ary->interface_vs_oop(t_aryptr->_ary);
4495   }
4496   return false;
4497 }
4498 #endif
4499 
4500 //------------------------------dump2------------------------------------------
4501 #ifndef PRODUCT
4502 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4503   _ary->dump2(d,depth,st);
4504   switch( _ptr ) {
4505   case Constant:
4506     const_oop()->print(st);
4507     break;
4508   case BotPTR:
4509     if (!WizardMode && !Verbose) {
4510       if( _klass_is_exact ) st->print(":exact");
4511       break;
4512     }
4513   case TopPTR:
4514   case AnyNull:
4515   case NotNull:
4516     st->print(":%s", ptr_msg[_ptr]);
4517     if( _klass_is_exact ) st->print(":exact");
4518     break;
4519   }
4520 
4521   if (elem()->isa_valuetype()) {
4522     st->print("(");
4523     _field_offset.dump2(st);
4524     st->print(")");
4525   }
4526   if (offset() != 0) {
4527     int header_size = objArrayOopDesc::header_size() * wordSize;
4528     if( _offset == Offset::top )       st->print("+undefined");
4529     else if( _offset == Offset::bottom )  st->print("+any");
4530     else if( offset() < header_size ) st->print("+%d", offset());
4531     else {
4532       BasicType basic_elem_type = elem()->basic_type();
4533       int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
4534       int elem_size = type2aelembytes(basic_elem_type);
4535       st->print("[%d]", (offset() - array_base)/elem_size);
4536     }
4537   }
4538   st->print(" *");
4539   if (_instance_id == InstanceTop)
4540     st->print(",iid=top");
4541   else if (_instance_id != InstanceBot)
4542     st->print(",iid=%d",_instance_id);
4543 
4544   dump_inline_depth(st);
4545   dump_speculative(st);
4546 }
4547 #endif
4548 
4549 bool TypeAryPtr::empty(void) const {
4550   if (_ary->empty())       return true;
4551   return TypeOopPtr::empty();
4552 }
4553 
4554 //------------------------------add_offset-------------------------------------
4555 const TypePtr *TypeAryPtr::add_offset(intptr_t offset) const {
4556   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);
4557 }
4558 
4559 const Type *TypeAryPtr::remove_speculative() const {
4560   if (_speculative == NULL) {
4561     return this;
4562   }
4563   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4564   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);
4565 }
4566 
4567 const TypePtr *TypeAryPtr::with_inline_depth(int depth) const {
4568   if (!UseInlineDepthForSpeculativeTypes) {
4569     return this;
4570   }
4571   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, depth, _is_autobox_cache);
4572 }
4573 
4574 const TypeAryPtr* TypeAryPtr::with_field_offset(int offset) const {
4575   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);
4576 }
4577 
4578 const TypePtr* TypeAryPtr::with_field_offset_and_offset(intptr_t offset) const {
4579   if (offset != Type::OffsetBot) {
4580     const Type* elemtype = elem();
4581     if (elemtype->isa_valuetype()) {
4582       uint header = arrayOopDesc::base_offset_in_bytes(T_OBJECT);
4583       if (offset >= (intptr_t)header) {
4584         ciKlass* arytype_klass = klass();
4585         ciValueArrayKlass* vak = arytype_klass->as_value_array_klass();
4586         int shift = vak->log2_element_size();
4587         intptr_t field_offset = ((offset - header) & ((1 << shift) - 1));
4588 
4589         return with_field_offset(field_offset)->add_offset(offset - field_offset);
4590       }
4591     }
4592   }
4593   return add_offset(offset);
4594 }
4595 
4596 //=============================================================================
4597 
4598 
4599 //=============================================================================
4600 
4601 //------------------------------make-------------------------------------------
4602 const TypeValueTypePtr* TypeValueTypePtr::make(const TypeValueType* vt, PTR ptr, ciObject* o, Offset offset, int instance_id, const TypePtr* speculative, int inline_depth) {
4603   return (TypeValueTypePtr*)(new TypeValueTypePtr(vt, ptr, o, offset, instance_id, speculative, inline_depth))->hashcons();
4604 }
4605 
4606 const TypePtr* TypeValueTypePtr::add_offset(intptr_t offset) const {
4607   return make(_vt, _ptr, _const_oop, Offset(offset), _instance_id, _speculative, _inline_depth);
4608 }
4609 
4610 //------------------------------cast_to_ptr_type-------------------------------
4611 const Type* TypeValueTypePtr::cast_to_ptr_type(PTR ptr) const {
4612   if (ptr == _ptr) return this;
4613   return make(_vt, ptr, _const_oop, _offset, _instance_id, _speculative, _inline_depth);
4614 }
4615 
4616 //-----------------------------cast_to_instance_id----------------------------
4617 const TypeOopPtr* TypeValueTypePtr::cast_to_instance_id(int instance_id) const {
4618   if (instance_id == _instance_id) return this;
4619   return make(_vt, _ptr, _const_oop, _offset, instance_id, _speculative, _inline_depth);
4620 }
4621 
4622 //------------------------------meet-------------------------------------------
4623 // Compute the MEET of two types.  It returns a new Type object.
4624 const Type* TypeValueTypePtr::xmeet_helper(const Type* t) const {
4625   // Perform a fast test for common case; meeting the same types together.
4626   if (this == t) return this;  // Meeting same type-rep?
4627 
4628   switch (t->base()) {          // switch on original type
4629     case Int:                     // Mixing ints & oops happens when javac
4630     case Long:                    // reuses local variables
4631     case FloatTop:
4632     case FloatCon:
4633     case FloatBot:
4634     case DoubleTop:
4635     case DoubleCon:
4636     case DoubleBot:
4637     case NarrowOop:
4638     case NarrowKlass:
4639     case MetadataPtr:
4640     case KlassPtr:
4641     case RawPtr:
4642     case AryPtr:
4643     case InstPtr:
4644     case Bottom:                  // Ye Olde Default
4645       return Type::BOTTOM;
4646     case Top:
4647       return this;
4648 
4649     default:                      // All else is a mistake
4650       typerr(t);
4651 
4652     case OopPtr: {
4653       // Found a OopPtr type vs self-ValueTypePtr type
4654       const TypeOopPtr* tp = t->is_oopptr();
4655       Offset offset = meet_offset(tp->offset());
4656       PTR ptr = meet_ptr(tp->ptr());
4657       int instance_id = meet_instance_id(tp->instance_id());
4658       const TypePtr* speculative = xmeet_speculative(tp);
4659       int depth = meet_inline_depth(tp->inline_depth());
4660       switch (tp->ptr()) {
4661       case TopPTR:
4662       case AnyNull: {
4663         return make(_vt, ptr, NULL, offset, instance_id, speculative, depth);
4664       }
4665       case NotNull:
4666       case BotPTR: {
4667         return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4668       }
4669       default: typerr(t);
4670       }
4671     }
4672 
4673     case AnyPtr: {
4674       // Found an AnyPtr type vs self-ValueTypePtr type
4675       const TypePtr* tp = t->is_ptr();
4676       Offset offset = meet_offset(tp->offset());
4677       PTR ptr = meet_ptr(tp->ptr());
4678       int instance_id = meet_instance_id(InstanceTop);
4679       const TypePtr* speculative = xmeet_speculative(tp);
4680       int depth = meet_inline_depth(tp->inline_depth());
4681       switch (tp->ptr()) {
4682       case Null:
4683         if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4684         // else fall through to AnyNull
4685       case TopPTR:
4686       case AnyNull: {
4687         return make(_vt, ptr, NULL, offset, instance_id, speculative, depth);
4688       }
4689       case NotNull:
4690       case BotPTR:
4691         return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4692       default: typerr(t);
4693       }
4694     }
4695 
4696     case ValueTypePtr: {
4697       // Found an ValueTypePtr type vs self-ValueTypePtr type
4698       const TypeValueTypePtr* tp = t->is_valuetypeptr();
4699       Offset offset = meet_offset(tp->offset());
4700       PTR ptr = meet_ptr(tp->ptr());
4701       int instance_id = meet_instance_id(InstanceTop);
4702       const TypePtr* speculative = xmeet_speculative(tp);
4703       int depth = meet_inline_depth(tp->inline_depth());
4704       // Compute constant oop
4705       ciObject* o = NULL;
4706       ciObject* this_oop  = const_oop();
4707       ciObject* tp_oop = tp->const_oop();
4708       if (ptr == Constant) {
4709         if (this_oop != NULL && tp_oop != NULL &&
4710             this_oop->equals(tp_oop) ) {
4711           o = this_oop;
4712         } else if (above_centerline(this ->_ptr)) {
4713           o = tp_oop;
4714         } else if (above_centerline(tp ->_ptr)) {
4715           o = this_oop;
4716         } else {
4717           ptr = NotNull;
4718         }
4719       }
4720       return make(_vt, ptr, o, offset, instance_id, speculative, depth);
4721     }
4722     }
4723 }
4724 
4725 // Dual: compute field-by-field dual
4726 const Type* TypeValueTypePtr::xdual() const {
4727   return new TypeValueTypePtr(_vt, dual_ptr(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4728 }
4729 
4730 //------------------------------eq---------------------------------------------
4731 // Structural equality check for Type representations
4732 bool TypeValueTypePtr::eq(const Type* t) const {
4733   const TypeValueTypePtr* p = t->is_valuetypeptr();
4734   return _vt->eq(p->value_type()) && TypeOopPtr::eq(p);
4735 }
4736 
4737 //------------------------------hash-------------------------------------------
4738 // Type-specific hashing function.
4739 int TypeValueTypePtr::hash(void) const {
4740   return java_add(_vt->hash(), TypeOopPtr::hash());
4741 }
4742 
4743 //------------------------------empty------------------------------------------
4744 // TRUE if Type is a type with no values, FALSE otherwise.
4745 bool TypeValueTypePtr::empty(void) const {
4746   // FIXME
4747   return false;
4748 }
4749 
4750 //------------------------------dump2------------------------------------------
4751 #ifndef PRODUCT
4752 void TypeValueTypePtr::dump2(Dict &d, uint depth, outputStream *st) const {
4753   st->print("valuetype* ");
4754   klass()->print_name_on(st);
4755   st->print(":%s", ptr_msg[_ptr]);
4756   _offset.dump2(st);
4757 }
4758 #endif
4759 
4760 //=============================================================================
4761 
4762 //------------------------------hash-------------------------------------------
4763 // Type-specific hashing function.
4764 int TypeNarrowPtr::hash(void) const {
4765   return _ptrtype->hash() + 7;
4766 }
4767 
4768 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
4769   return _ptrtype->singleton();
4770 }
4771 
4772 bool TypeNarrowPtr::empty(void) const {
4773   return _ptrtype->empty();
4774 }
4775 
4776 intptr_t TypeNarrowPtr::get_con() const {
4777   return _ptrtype->get_con();
4778 }
4779 
4780 bool TypeNarrowPtr::eq( const Type *t ) const {
4781   const TypeNarrowPtr* tc = isa_same_narrowptr(t);
4782   if (tc != NULL) {
4783     if (_ptrtype->base() != tc->_ptrtype->base()) {
4784       return false;
4785     }
4786     return tc->_ptrtype->eq(_ptrtype);
4787   }
4788   return false;
4789 }
4790 
4791 const Type *TypeNarrowPtr::xdual() const {    // Compute dual right now.
4792   const TypePtr* odual = _ptrtype->dual()->is_ptr();
4793   return make_same_narrowptr(odual);
4794 }
4795 
4796 
4797 const Type *TypeNarrowPtr::filter_helper(const Type *kills, bool include_speculative) const {
4798   if (isa_same_narrowptr(kills)) {
4799     const Type* ft =_ptrtype->filter_helper(is_same_narrowptr(kills)->_ptrtype, include_speculative);
4800     if (ft->empty())
4801       return Type::TOP;           // Canonical empty value
4802     if (ft->isa_ptr()) {
4803       return make_hash_same_narrowptr(ft->isa_ptr());
4804     }
4805     return ft;
4806   } else if (kills->isa_ptr()) {
4807     const Type* ft = _ptrtype->join_helper(kills, include_speculative);
4808     if (ft->empty())
4809       return Type::TOP;           // Canonical empty value
4810     return ft;
4811   } else {
4812     return Type::TOP;
4813   }
4814 }
4815 
4816 //------------------------------xmeet------------------------------------------
4817 // Compute the MEET of two types.  It returns a new Type object.
4818 const Type *TypeNarrowPtr::xmeet( const Type *t ) const {
4819   // Perform a fast test for common case; meeting the same types together.
4820   if( this == t ) return this;  // Meeting same type-rep?
4821 
4822   if (t->base() == base()) {
4823     const Type* result = _ptrtype->xmeet(t->make_ptr());
4824     if (result->isa_ptr()) {
4825       return make_hash_same_narrowptr(result->is_ptr());
4826     }
4827     return result;
4828   }
4829 
4830   // Current "this->_base" is NarrowKlass or NarrowOop
4831   switch (t->base()) {          // switch on original type
4832 
4833   case Int:                     // Mixing ints & oops happens when javac
4834   case Long:                    // reuses local variables
4835   case FloatTop:
4836   case FloatCon:
4837   case FloatBot:
4838   case DoubleTop:
4839   case DoubleCon:
4840   case DoubleBot:
4841   case AnyPtr:
4842   case RawPtr:
4843   case OopPtr:
4844   case InstPtr:
4845   case ValueTypePtr:
4846   case AryPtr:
4847   case MetadataPtr:
4848   case KlassPtr:
4849   case NarrowOop:
4850   case NarrowKlass:
4851 
4852   case Bottom:                  // Ye Olde Default
4853     return Type::BOTTOM;
4854   case Top:
4855     return this;
4856 
4857   default:                      // All else is a mistake
4858     typerr(t);
4859 
4860   } // End of switch
4861 
4862   return this;
4863 }
4864 
4865 #ifndef PRODUCT
4866 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
4867   _ptrtype->dump2(d, depth, st);
4868 }
4869 #endif
4870 
4871 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
4872 const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
4873 
4874 
4875 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
4876   return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();
4877 }
4878 
4879 const Type* TypeNarrowOop::remove_speculative() const {
4880   return make(_ptrtype->remove_speculative()->is_ptr());
4881 }
4882 
4883 const Type* TypeNarrowOop::cleanup_speculative() const {
4884   return make(_ptrtype->cleanup_speculative()->is_ptr());
4885 }
4886 
4887 #ifndef PRODUCT
4888 void TypeNarrowOop::dump2( Dict & d, uint depth, outputStream *st ) const {
4889   st->print("narrowoop: ");
4890   TypeNarrowPtr::dump2(d, depth, st);
4891 }
4892 #endif
4893 
4894 const TypeNarrowKlass *TypeNarrowKlass::NULL_PTR;
4895 
4896 const TypeNarrowKlass* TypeNarrowKlass::make(const TypePtr* type) {
4897   return (const TypeNarrowKlass*)(new TypeNarrowKlass(type))->hashcons();
4898 }
4899 
4900 #ifndef PRODUCT
4901 void TypeNarrowKlass::dump2( Dict & d, uint depth, outputStream *st ) const {
4902   st->print("narrowklass: ");
4903   TypeNarrowPtr::dump2(d, depth, st);
4904 }
4905 #endif
4906 
4907 
4908 //------------------------------eq---------------------------------------------
4909 // Structural equality check for Type representations
4910 bool TypeMetadataPtr::eq( const Type *t ) const {
4911   const TypeMetadataPtr *a = (const TypeMetadataPtr*)t;
4912   ciMetadata* one = metadata();
4913   ciMetadata* two = a->metadata();
4914   if (one == NULL || two == NULL) {
4915     return (one == two) && TypePtr::eq(t);
4916   } else {
4917     return one->equals(two) && TypePtr::eq(t);
4918   }
4919 }
4920 
4921 //------------------------------hash-------------------------------------------
4922 // Type-specific hashing function.
4923 int TypeMetadataPtr::hash(void) const {
4924   return
4925     (metadata() ? metadata()->hash() : 0) +
4926     TypePtr::hash();
4927 }
4928 
4929 //------------------------------singleton--------------------------------------
4930 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
4931 // constants
4932 bool TypeMetadataPtr::singleton(void) const {
4933   // detune optimizer to not generate constant metadata + constant offset as a constant!
4934   // TopPTR, Null, AnyNull, Constant are all singletons
4935   return (offset() == 0) && !below_centerline(_ptr);
4936 }
4937 
4938 //------------------------------add_offset-------------------------------------
4939 const TypePtr *TypeMetadataPtr::add_offset( intptr_t offset ) const {
4940   return make( _ptr, _metadata, xadd_offset(offset));
4941 }
4942 
4943 //-----------------------------filter------------------------------------------
4944 // Do not allow interface-vs.-noninterface joins to collapse to top.
4945 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
4946   const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
4947   if (ft == NULL || ft->empty())
4948     return Type::TOP;           // Canonical empty value
4949   return ft;
4950 }
4951 
4952  //------------------------------get_con----------------------------------------
4953 intptr_t TypeMetadataPtr::get_con() const {
4954   assert( _ptr == Null || _ptr == Constant, "" );
4955   assert(offset() >= 0, "");
4956 
4957   if (offset() != 0) {
4958     // After being ported to the compiler interface, the compiler no longer
4959     // directly manipulates the addresses of oops.  Rather, it only has a pointer
4960     // to a handle at compile time.  This handle is embedded in the generated
4961     // code and dereferenced at the time the nmethod is made.  Until that time,
4962     // it is not reasonable to do arithmetic with the addresses of oops (we don't
4963     // have access to the addresses!).  This does not seem to currently happen,
4964     // but this assertion here is to help prevent its occurence.
4965     tty->print_cr("Found oop constant with non-zero offset");
4966     ShouldNotReachHere();
4967   }
4968 
4969   return (intptr_t)metadata()->constant_encoding();
4970 }
4971 
4972 //------------------------------cast_to_ptr_type-------------------------------
4973 const Type *TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
4974   if( ptr == _ptr ) return this;
4975   return make(ptr, metadata(), _offset);
4976 }
4977 
4978 //------------------------------meet-------------------------------------------
4979 // Compute the MEET of two types.  It returns a new Type object.
4980 const Type *TypeMetadataPtr::xmeet( const Type *t ) const {
4981   // Perform a fast test for common case; meeting the same types together.
4982   if( this == t ) return this;  // Meeting same type-rep?
4983 
4984   // Current "this->_base" is OopPtr
4985   switch (t->base()) {          // switch on original type
4986 
4987   case Int:                     // Mixing ints & oops happens when javac
4988   case Long:                    // reuses local variables
4989   case FloatTop:
4990   case FloatCon:
4991   case FloatBot:
4992   case DoubleTop:
4993   case DoubleCon:
4994   case DoubleBot:
4995   case NarrowOop:
4996   case NarrowKlass:
4997   case Bottom:                  // Ye Olde Default
4998     return Type::BOTTOM;
4999   case Top:
5000     return this;
5001 
5002   default:                      // All else is a mistake
5003     typerr(t);
5004 
5005   case AnyPtr: {
5006     // Found an AnyPtr type vs self-OopPtr type
5007     const TypePtr *tp = t->is_ptr();
5008     Offset offset = meet_offset(tp->offset());
5009     PTR ptr = meet_ptr(tp->ptr());
5010     switch (tp->ptr()) {
5011     case Null:
5012       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5013       // else fall through:
5014     case TopPTR:
5015     case AnyNull: {
5016       return make(ptr, _metadata, offset);
5017     }
5018     case BotPTR:
5019     case NotNull:
5020       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5021     default: typerr(t);
5022     }
5023   }
5024 
5025   case RawPtr:
5026   case KlassPtr:
5027   case OopPtr:
5028   case InstPtr:
5029   case ValueTypePtr:
5030   case AryPtr:
5031     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
5032 
5033   case MetadataPtr: {
5034     const TypeMetadataPtr *tp = t->is_metadataptr();
5035     Offset offset = meet_offset(tp->offset());
5036     PTR tptr = tp->ptr();
5037     PTR ptr = meet_ptr(tptr);
5038     ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
5039     if (tptr == TopPTR || _ptr == TopPTR ||
5040         metadata()->equals(tp->metadata())) {
5041       return make(ptr, md, offset);
5042     }
5043     // metadata is different
5044     if( ptr == Constant ) {  // Cannot be equal constants, so...
5045       if( tptr == Constant && _ptr != Constant)  return t;
5046       if( _ptr == Constant && tptr != Constant)  return this;
5047       ptr = NotNull;            // Fall down in lattice
5048     }
5049     return make(ptr, NULL, offset);
5050     break;
5051   }
5052   } // End of switch
5053   return this;                  // Return the double constant
5054 }
5055 
5056 
5057 //------------------------------xdual------------------------------------------
5058 // Dual of a pure metadata pointer.
5059 const Type *TypeMetadataPtr::xdual() const {
5060   return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
5061 }
5062 
5063 //------------------------------dump2------------------------------------------
5064 #ifndef PRODUCT
5065 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5066   st->print("metadataptr:%s", ptr_msg[_ptr]);
5067   if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata()));
5068   switch (offset()) {
5069   case OffsetTop: st->print("+top"); break;
5070   case OffsetBot: st->print("+any"); break;
5071   case         0: break;
5072   default:        st->print("+%d",offset()); break;
5073   }
5074 }
5075 #endif
5076 
5077 
5078 //=============================================================================
5079 // Convenience common pre-built type.
5080 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
5081 
5082 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, Offset offset):
5083   TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
5084 }
5085 
5086 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
5087   return make(Constant, m, Offset(0));
5088 }
5089 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
5090   return make(Constant, m, Offset(0));
5091 }
5092 
5093 //------------------------------make-------------------------------------------
5094 // Create a meta data constant
5095 const TypeMetadataPtr* TypeMetadataPtr::make(PTR ptr, ciMetadata* m, Offset offset) {
5096   assert(m == NULL || !m->is_klass(), "wrong type");
5097   return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
5098 }
5099 
5100 
5101 //=============================================================================
5102 // Convenience common pre-built types.
5103 
5104 // Not-null object klass or below
5105 const TypeKlassPtr *TypeKlassPtr::OBJECT;
5106 const TypeKlassPtr *TypeKlassPtr::OBJECT_OR_NULL;
5107 
5108 //------------------------------TypeKlassPtr-----------------------------------
5109 TypeKlassPtr::TypeKlassPtr( PTR ptr, ciKlass* klass, Offset offset )
5110   : TypePtr(KlassPtr, ptr, offset), _klass(klass), _klass_is_exact(ptr == Constant) {
5111 }
5112 
5113 //------------------------------make-------------------------------------------
5114 // ptr to klass 'k', if Constant, or possibly to a sub-klass if not a Constant
5115 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* k, Offset offset) {
5116   assert( k != NULL, "Expect a non-NULL klass");
5117   assert(k->is_instance_klass() || k->is_array_klass(), "Incorrect type of klass oop");
5118   TypeKlassPtr *r =
5119     (TypeKlassPtr*)(new TypeKlassPtr(ptr, k, offset))->hashcons();
5120 
5121   return r;
5122 }
5123 
5124 //------------------------------eq---------------------------------------------
5125 // Structural equality check for Type representations
5126 bool TypeKlassPtr::eq( const Type *t ) const {
5127   const TypeKlassPtr *p = t->is_klassptr();
5128   return
5129     klass()->equals(p->klass()) &&
5130     TypePtr::eq(p);
5131 }
5132 
5133 //------------------------------hash-------------------------------------------
5134 // Type-specific hashing function.
5135 int TypeKlassPtr::hash(void) const {
5136   return java_add(klass()->hash(), TypePtr::hash());
5137 }
5138 
5139 //------------------------------singleton--------------------------------------
5140 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5141 // constants
5142 bool TypeKlassPtr::singleton(void) const {
5143   // detune optimizer to not generate constant klass + constant offset as a constant!
5144   // TopPTR, Null, AnyNull, Constant are all singletons
5145   return (offset() == 0) && !below_centerline(_ptr);
5146 }
5147 
5148 // Do not allow interface-vs.-noninterface joins to collapse to top.
5149 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
5150   // logic here mirrors the one from TypeOopPtr::filter. See comments
5151   // there.
5152   const Type* ft = join_helper(kills, include_speculative);
5153   const TypeKlassPtr* ftkp = ft->isa_klassptr();
5154   const TypeKlassPtr* ktkp = kills->isa_klassptr();
5155 
5156   if (ft->empty()) {
5157     if (!empty() && ktkp != NULL && ktkp->klass()->is_loaded() && ktkp->klass()->is_interface())
5158       return kills;             // Uplift to interface
5159 
5160     return Type::TOP;           // Canonical empty value
5161   }
5162 
5163   // Interface klass type could be exact in opposite to interface type,
5164   // return it here instead of incorrect Constant ptr J/L/Object (6894807).
5165   if (ftkp != NULL && ktkp != NULL &&
5166       ftkp->is_loaded() &&  ftkp->klass()->is_interface() &&
5167       !ftkp->klass_is_exact() && // Keep exact interface klass
5168       ktkp->is_loaded() && !ktkp->klass()->is_interface()) {
5169     return ktkp->cast_to_ptr_type(ftkp->ptr());
5170   }
5171 
5172   return ft;
5173 }
5174 
5175 //----------------------compute_klass------------------------------------------
5176 // Compute the defining klass for this class
5177 ciKlass* TypeAryPtr::compute_klass(DEBUG_ONLY(bool verify)) const {
5178   // Compute _klass based on element type.
5179   ciKlass* k_ary = NULL;
5180   const TypeAryPtr *tary;
5181   const Type* el = elem();
5182   if (el->isa_narrowoop()) {
5183     el = el->make_ptr();
5184   }
5185 
5186   // Get element klass
5187   if (el->isa_instptr() || el->isa_valuetypeptr()) {
5188     // Compute object array klass from element klass
5189     k_ary = ciArrayKlass::make(el->is_oopptr()->klass());
5190   } else if (el->isa_valuetype()) {
5191     k_ary = ciArrayKlass::make(el->is_valuetype()->value_klass());
5192   } else if ((tary = el->isa_aryptr()) != NULL) {
5193     // Compute array klass from element klass
5194     ciKlass* k_elem = tary->klass();
5195     // If element type is something like bottom[], k_elem will be null.
5196     if (k_elem != NULL)
5197       k_ary = ciObjArrayKlass::make(k_elem);
5198   } else if ((el->base() == Type::Top) ||
5199              (el->base() == Type::Bottom)) {
5200     // element type of Bottom occurs from meet of basic type
5201     // and object; Top occurs when doing join on Bottom.
5202     // Leave k_ary at NULL.
5203   } else {
5204     // Cannot compute array klass directly from basic type,
5205     // since subtypes of TypeInt all have basic type T_INT.
5206 #ifdef ASSERT
5207     if (verify && el->isa_int()) {
5208       // Check simple cases when verifying klass.
5209       BasicType bt = T_ILLEGAL;
5210       if (el == TypeInt::BYTE) {
5211         bt = T_BYTE;
5212       } else if (el == TypeInt::SHORT) {
5213         bt = T_SHORT;
5214       } else if (el == TypeInt::CHAR) {
5215         bt = T_CHAR;
5216       } else if (el == TypeInt::INT) {
5217         bt = T_INT;
5218       } else {
5219         return _klass; // just return specified klass
5220       }
5221       return ciTypeArrayKlass::make(bt);
5222     }
5223 #endif
5224     assert(!el->isa_int(),
5225            "integral arrays must be pre-equipped with a class");
5226     // Compute array klass directly from basic type
5227     k_ary = ciTypeArrayKlass::make(el->basic_type());
5228   }
5229   return k_ary;
5230 }
5231 
5232 //------------------------------klass------------------------------------------
5233 // Return the defining klass for this class
5234 ciKlass* TypeAryPtr::klass() const {
5235   if( _klass ) return _klass;   // Return cached value, if possible
5236 
5237   // Oops, need to compute _klass and cache it
5238   ciKlass* k_ary = compute_klass();
5239 
5240   if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) {
5241     // The _klass field acts as a cache of the underlying
5242     // ciKlass for this array type.  In order to set the field,
5243     // we need to cast away const-ness.
5244     //
5245     // IMPORTANT NOTE: we *never* set the _klass field for the
5246     // type TypeAryPtr::OOPS.  This Type is shared between all
5247     // active compilations.  However, the ciKlass which represents
5248     // this Type is *not* shared between compilations, so caching
5249     // this value would result in fetching a dangling pointer.
5250     //
5251     // Recomputing the underlying ciKlass for each request is
5252     // a bit less efficient than caching, but calls to
5253     // TypeAryPtr::OOPS->klass() are not common enough to matter.
5254     ((TypeAryPtr*)this)->_klass = k_ary;
5255     if (UseCompressedOops && k_ary != NULL && k_ary->is_obj_array_klass() &&
5256         offset() != 0 && offset() != arrayOopDesc::length_offset_in_bytes()) {
5257       ((TypeAryPtr*)this)->_is_ptr_to_narrowoop = true;
5258     }
5259   }
5260   return k_ary;
5261 }
5262 
5263 
5264 //------------------------------add_offset-------------------------------------
5265 // Access internals of klass object
5266 const TypePtr *TypeKlassPtr::add_offset( intptr_t offset ) const {
5267   return make( _ptr, klass(), xadd_offset(offset) );
5268 }
5269 
5270 //------------------------------cast_to_ptr_type-------------------------------
5271 const Type *TypeKlassPtr::cast_to_ptr_type(PTR ptr) const {
5272   assert(_base == KlassPtr, "subclass must override cast_to_ptr_type");
5273   if( ptr == _ptr ) return this;
5274   return make(ptr, _klass, _offset);
5275 }
5276 
5277 
5278 //-----------------------------cast_to_exactness-------------------------------
5279 const Type *TypeKlassPtr::cast_to_exactness(bool klass_is_exact) const {
5280   if( klass_is_exact == _klass_is_exact ) return this;
5281   if (!UseExactTypes)  return this;
5282   return make(klass_is_exact ? Constant : NotNull, _klass, _offset);
5283 }
5284 
5285 
5286 //-----------------------------as_instance_type--------------------------------
5287 // Corresponding type for an instance of the given class.
5288 // It will be NotNull, and exact if and only if the klass type is exact.
5289 const TypeOopPtr* TypeKlassPtr::as_instance_type() const {
5290   ciKlass* k = klass();
5291   bool    xk = klass_is_exact();
5292   //return TypeInstPtr::make(TypePtr::NotNull, k, xk, NULL, 0);
5293   const TypeOopPtr* toop = TypeOopPtr::make_from_klass_raw(k);
5294   guarantee(toop != NULL, "need type for given klass");
5295   toop = toop->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
5296   return toop->cast_to_exactness(xk)->is_oopptr();
5297 }
5298 
5299 
5300 //------------------------------xmeet------------------------------------------
5301 // Compute the MEET of two types, return a new Type object.
5302 const Type    *TypeKlassPtr::xmeet( const Type *t ) const {
5303   // Perform a fast test for common case; meeting the same types together.
5304   if( this == t ) return this;  // Meeting same type-rep?
5305 
5306   // Current "this->_base" is Pointer
5307   switch (t->base()) {          // switch on original type
5308 
5309   case Int:                     // Mixing ints & oops happens when javac
5310   case Long:                    // reuses local variables
5311   case FloatTop:
5312   case FloatCon:
5313   case FloatBot:
5314   case DoubleTop:
5315   case DoubleCon:
5316   case DoubleBot:
5317   case NarrowOop:
5318   case NarrowKlass:
5319   case Bottom:                  // Ye Olde Default
5320     return Type::BOTTOM;
5321   case Top:
5322     return this;
5323 
5324   default:                      // All else is a mistake
5325     typerr(t);
5326 
5327   case AnyPtr: {                // Meeting to AnyPtrs
5328     // Found an AnyPtr type vs self-KlassPtr type
5329     const TypePtr *tp = t->is_ptr();
5330     Offset offset = meet_offset(tp->offset());
5331     PTR ptr = meet_ptr(tp->ptr());
5332     switch (tp->ptr()) {
5333     case TopPTR:
5334       return this;
5335     case Null:
5336       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5337     case AnyNull:
5338       return make( ptr, klass(), offset );
5339     case BotPTR:
5340     case NotNull:
5341       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5342     default: typerr(t);
5343     }
5344   }
5345 
5346   case RawPtr:
5347   case MetadataPtr:
5348   case OopPtr:
5349   case AryPtr:                  // Meet with AryPtr
5350   case InstPtr:                 // Meet with InstPtr
5351   case ValueTypePtr:
5352     return TypePtr::BOTTOM;
5353 
5354   //
5355   //             A-top         }
5356   //           /   |   \       }  Tops
5357   //       B-top A-any C-top   }
5358   //          | /  |  \ |      }  Any-nulls
5359   //       B-any   |   C-any   }
5360   //          |    |    |
5361   //       B-con A-con C-con   } constants; not comparable across classes
5362   //          |    |    |
5363   //       B-not   |   C-not   }
5364   //          | \  |  / |      }  not-nulls
5365   //       B-bot A-not C-bot   }
5366   //           \   |   /       }  Bottoms
5367   //             A-bot         }
5368   //
5369 
5370   case KlassPtr: {  // Meet two KlassPtr types
5371     const TypeKlassPtr *tkls = t->is_klassptr();
5372     Offset  off  = meet_offset(tkls->offset());
5373     PTR  ptr     = meet_ptr(tkls->ptr());
5374 
5375     // Check for easy case; klasses are equal (and perhaps not loaded!)
5376     // If we have constants, then we created oops so classes are loaded
5377     // and we can handle the constants further down.  This case handles
5378     // not-loaded classes
5379     if( ptr != Constant && tkls->klass()->equals(klass()) ) {
5380       return make( ptr, klass(), off );
5381     }
5382 
5383     // Classes require inspection in the Java klass hierarchy.  Must be loaded.
5384     ciKlass* tkls_klass = tkls->klass();
5385     ciKlass* this_klass = this->klass();
5386     assert( tkls_klass->is_loaded(), "This class should have been loaded.");
5387     assert( this_klass->is_loaded(), "This class should have been loaded.");
5388 
5389     // If 'this' type is above the centerline and is a superclass of the
5390     // other, we can treat 'this' as having the same type as the other.
5391     if ((above_centerline(this->ptr())) &&
5392         tkls_klass->is_subtype_of(this_klass)) {
5393       this_klass = tkls_klass;
5394     }
5395     // If 'tinst' type is above the centerline and is a superclass of the
5396     // other, we can treat 'tinst' as having the same type as the other.
5397     if ((above_centerline(tkls->ptr())) &&
5398         this_klass->is_subtype_of(tkls_klass)) {
5399       tkls_klass = this_klass;
5400     }
5401 
5402     // Check for classes now being equal
5403     if (tkls_klass->equals(this_klass)) {
5404       // If the klasses are equal, the constants may still differ.  Fall to
5405       // NotNull if they do (neither constant is NULL; that is a special case
5406       // handled elsewhere).
5407       if( ptr == Constant ) {
5408         if (this->_ptr == Constant && tkls->_ptr == Constant &&
5409             this->klass()->equals(tkls->klass()));
5410         else if (above_centerline(this->ptr()));
5411         else if (above_centerline(tkls->ptr()));
5412         else
5413           ptr = NotNull;
5414       }
5415       return make( ptr, this_klass, off );
5416     } // Else classes are not equal
5417 
5418     // Since klasses are different, we require the LCA in the Java
5419     // class hierarchy - which means we have to fall to at least NotNull.
5420     if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
5421       ptr = NotNull;
5422     // Now we find the LCA of Java classes
5423     ciKlass* k = this_klass->least_common_ancestor(tkls_klass);
5424     return   make( ptr, k, off );
5425   } // End of case KlassPtr
5426 
5427   } // End of switch
5428   return this;                  // Return the double constant
5429 }
5430 
5431 //------------------------------xdual------------------------------------------
5432 // Dual: compute field-by-field dual
5433 const Type    *TypeKlassPtr::xdual() const {
5434   return new TypeKlassPtr( dual_ptr(), klass(), dual_offset() );
5435 }
5436 
5437 //------------------------------get_con----------------------------------------
5438 intptr_t TypeKlassPtr::get_con() const {
5439   assert( _ptr == Null || _ptr == Constant, "" );
5440   assert(offset() >= 0, "");
5441 
5442   if (offset() != 0) {
5443     // After being ported to the compiler interface, the compiler no longer
5444     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5445     // to a handle at compile time.  This handle is embedded in the generated
5446     // code and dereferenced at the time the nmethod is made.  Until that time,
5447     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5448     // have access to the addresses!).  This does not seem to currently happen,
5449     // but this assertion here is to help prevent its occurence.
5450     tty->print_cr("Found oop constant with non-zero offset");
5451     ShouldNotReachHere();
5452   }
5453 
5454   return (intptr_t)klass()->constant_encoding();
5455 }
5456 //------------------------------dump2------------------------------------------
5457 // Dump Klass Type
5458 #ifndef PRODUCT
5459 void TypeKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5460   switch( _ptr ) {
5461   case Constant:
5462     st->print("precise ");
5463   case NotNull:
5464     {
5465       const char *name = klass()->name()->as_utf8();
5466       if( name ) {
5467         st->print("klass %s: " INTPTR_FORMAT, name, p2i(klass()));
5468       } else {
5469         ShouldNotReachHere();
5470       }
5471     }
5472   case BotPTR:
5473     if( !WizardMode && !Verbose && !_klass_is_exact ) break;
5474   case TopPTR:
5475   case AnyNull:
5476     st->print(":%s", ptr_msg[_ptr]);
5477     if( _klass_is_exact ) st->print(":exact");
5478     break;
5479   }
5480 
5481   _offset.dump2(st);
5482 
5483   st->print(" *");
5484 }
5485 #endif
5486 
5487 
5488 
5489 //=============================================================================
5490 // Convenience common pre-built types.
5491 
5492 //------------------------------make-------------------------------------------
5493 const TypeFunc *TypeFunc::make( const TypeTuple *domain_sig, const TypeTuple* domain_cc, const TypeTuple *range ) {
5494   return (TypeFunc*)(new TypeFunc(domain_sig, domain_cc, range))->hashcons();
5495 }
5496 
5497 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
5498   return make(domain, domain, range);
5499 }
5500 
5501 //------------------------------make-------------------------------------------
5502 const TypeFunc *TypeFunc::make(ciMethod* method) {
5503   Compile* C = Compile::current();
5504   const TypeFunc* tf = C->last_tf(method); // check cache
5505   if (tf != NULL)  return tf;  // The hit rate here is almost 50%.
5506   const TypeTuple *domain_sig, *domain_cc;
5507   // Value type arguments are not passed by reference, instead each
5508   // field of the value type is passed as an argument. We maintain 2
5509   // views of the argument list here: one based on the signature (with
5510   // a value type argument as a single slot), one based on the actual
5511   // calling convention (with a value type argument as a list of its
5512   // fields).
5513   if (method->is_static()) {
5514     domain_sig = TypeTuple::make_domain(NULL, method->signature(), false);
5515     domain_cc = TypeTuple::make_domain(NULL, method->signature(), ValueTypePassFieldsAsArgs);
5516   } else {
5517     domain_sig = TypeTuple::make_domain(method->holder(), method->signature(), false);
5518     domain_cc = TypeTuple::make_domain(method->holder(), method->signature(), ValueTypePassFieldsAsArgs);
5519   }
5520   const TypeTuple *range  = TypeTuple::make_range(method->signature());
5521   tf = TypeFunc::make(domain_sig, domain_cc, range);
5522   C->set_last_tf(method, tf);  // fill cache
5523   return tf;
5524 }
5525 
5526 //------------------------------meet-------------------------------------------
5527 // Compute the MEET of two types.  It returns a new Type object.
5528 const Type *TypeFunc::xmeet( const Type *t ) const {
5529   // Perform a fast test for common case; meeting the same types together.
5530   if( this == t ) return this;  // Meeting same type-rep?
5531 
5532   // Current "this->_base" is Func
5533   switch (t->base()) {          // switch on original type
5534 
5535   case Bottom:                  // Ye Olde Default
5536     return t;
5537 
5538   default:                      // All else is a mistake
5539     typerr(t);
5540 
5541   case Top:
5542     break;
5543   }
5544   return this;                  // Return the double constant
5545 }
5546 
5547 //------------------------------xdual------------------------------------------
5548 // Dual: compute field-by-field dual
5549 const Type *TypeFunc::xdual() const {
5550   return this;
5551 }
5552 
5553 //------------------------------eq---------------------------------------------
5554 // Structural equality check for Type representations
5555 bool TypeFunc::eq( const Type *t ) const {
5556   const TypeFunc *a = (const TypeFunc*)t;
5557   return _domain_sig == a->_domain_sig &&
5558     _domain_cc == a->_domain_cc &&
5559     _range == a->_range;
5560 }
5561 
5562 //------------------------------hash-------------------------------------------
5563 // Type-specific hashing function.
5564 int TypeFunc::hash(void) const {
5565   return (intptr_t)_domain_sig + (intptr_t)_domain_cc + (intptr_t)_range;
5566 }
5567 
5568 //------------------------------dump2------------------------------------------
5569 // Dump Function Type
5570 #ifndef PRODUCT
5571 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
5572   if( _range->cnt() <= Parms )
5573     st->print("void");
5574   else {
5575     uint i;
5576     for (i = Parms; i < _range->cnt()-1; i++) {
5577       _range->field_at(i)->dump2(d,depth,st);
5578       st->print("/");
5579     }
5580     _range->field_at(i)->dump2(d,depth,st);
5581   }
5582   st->print(" ");
5583   st->print("( ");
5584   if( !depth || d[this] ) {     // Check for recursive dump
5585     st->print("...)");
5586     return;
5587   }
5588   d.Insert((void*)this,(void*)this);    // Stop recursion
5589   if (Parms < _domain_sig->cnt())
5590     _domain_sig->field_at(Parms)->dump2(d,depth-1,st);
5591   for (uint i = Parms+1; i < _domain_sig->cnt(); i++) {
5592     st->print(", ");
5593     _domain_sig->field_at(i)->dump2(d,depth-1,st);
5594   }
5595   st->print(" )");
5596 }
5597 #endif
5598 
5599 //------------------------------singleton--------------------------------------
5600 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5601 // constants (Ldi nodes).  Singletons are integer, float or double constants
5602 // or a single symbol.
5603 bool TypeFunc::singleton(void) const {
5604   return false;                 // Never a singleton
5605 }
5606 
5607 bool TypeFunc::empty(void) const {
5608   return false;                 // Never empty
5609 }
5610 
5611 
5612 BasicType TypeFunc::return_type() const{
5613   if (range()->cnt() == TypeFunc::Parms) {
5614     return T_VOID;
5615   }
5616   return range()->field_at(TypeFunc::Parms)->basic_type();
5617 }