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