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