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