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