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     // [V? has a subtype: [V. So eventhough V is final, [V? is not exact.
2369     if (tklass->as_instance_klass()->is_final()) {
2370       if (tinst->is_valuetypeptr() && (tinst->ptr() == TypePtr::BotPTR || tinst->ptr() == TypePtr::TopPTR)) {
2371         return false;
2372       }
2373       return true;
2374     }
2375     return false;
2376   }
2377   const TypeAryPtr*  tap;
2378   if (_elem->isa_narrowoop())
2379     tap = _elem->make_ptr()->isa_aryptr();
2380   else
2381     tap = _elem->isa_aryptr();
2382   if (tap)
2383     return tap->ary()->ary_must_be_exact();
2384   return false;
2385 }
2386 
2387 //==============================TypeValueType=======================================
2388 
2389 //------------------------------make-------------------------------------------
2390 const TypeValueType* TypeValueType::make(ciValueKlass* vk, bool larval) {
2391   return (TypeValueType*)(new TypeValueType(vk, larval))->hashcons();
2392 }
2393 
2394 //------------------------------meet-------------------------------------------
2395 // Compute the MEET of two types.  It returns a new Type object.
2396 const Type* TypeValueType::xmeet(const Type* t) const {
2397   // Perform a fast test for common case; meeting the same types together.
2398   if(this == t) return this;  // Meeting same type-rep?
2399 
2400   // Current "this->_base" is ValueType
2401   switch (t->base()) {          // switch on original type
2402 
2403   case Int:
2404   case Long:
2405   case FloatTop:
2406   case FloatCon:
2407   case FloatBot:
2408   case DoubleTop:
2409   case DoubleCon:
2410   case DoubleBot:
2411   case NarrowKlass:
2412   case Bottom:
2413     return Type::BOTTOM;
2414 
2415   case OopPtr:
2416   case MetadataPtr:
2417   case KlassPtr:
2418   case RawPtr:
2419     return TypePtr::BOTTOM;
2420 
2421   case Top:
2422     return this;
2423 
2424   case NarrowOop: {
2425     const Type* res = t->make_ptr()->xmeet(this);
2426     if (res->isa_ptr()) {
2427       return res->make_narrowoop();
2428     }
2429     return res;
2430   }
2431 
2432   case AryPtr:
2433   case InstPtr: {
2434     return t->xmeet(this);
2435   }
2436 
2437   case ValueType: {
2438     // All value types inherit from Object
2439     const TypeValueType* other = t->is_valuetype();
2440     if (_vk == other->_vk) {
2441       if (_larval == other->_larval ||
2442           !_larval) {
2443         return this;
2444       } else {
2445         return t;
2446       }
2447     }
2448     return TypeInstPtr::NOTNULL;
2449   }
2450 
2451   default:                      // All else is a mistake
2452     typerr(t);
2453 
2454   }
2455   return this;
2456 }
2457 
2458 //------------------------------xdual------------------------------------------
2459 const Type* TypeValueType::xdual() const {
2460   return this;
2461 }
2462 
2463 //------------------------------eq---------------------------------------------
2464 // Structural equality check for Type representations
2465 bool TypeValueType::eq(const Type* t) const {
2466   const TypeValueType* vt = t->is_valuetype();
2467   return (_vk == vt->value_klass() && _larval == vt->larval());
2468 }
2469 
2470 //------------------------------hash-------------------------------------------
2471 // Type-specific hashing function.
2472 int TypeValueType::hash(void) const {
2473   return (intptr_t)_vk;
2474 }
2475 
2476 //------------------------------singleton--------------------------------------
2477 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple constants.
2478 bool TypeValueType::singleton(void) const {
2479   return false;
2480 }
2481 
2482 //------------------------------empty------------------------------------------
2483 // TRUE if Type is a type with no values, FALSE otherwise.
2484 bool TypeValueType::empty(void) const {
2485   return false;
2486 }
2487 
2488 //------------------------------dump2------------------------------------------
2489 #ifndef PRODUCT
2490 void TypeValueType::dump2(Dict &d, uint depth, outputStream* st) const {
2491   int count = _vk->nof_declared_nonstatic_fields();
2492   st->print("valuetype[%d]:{", count);
2493   st->print("%s", count != 0 ? _vk->declared_nonstatic_field_at(0)->type()->name() : "empty");
2494   for (int i = 1; i < count; ++i) {
2495     st->print(", %s", _vk->declared_nonstatic_field_at(i)->type()->name());
2496   }
2497   st->print("}%s", _larval?" : larval":"");
2498 }
2499 #endif
2500 
2501 //==============================TypeVect=======================================
2502 // Convenience common pre-built types.
2503 const TypeVect *TypeVect::VECTS = NULL; //  32-bit vectors
2504 const TypeVect *TypeVect::VECTD = NULL; //  64-bit vectors
2505 const TypeVect *TypeVect::VECTX = NULL; // 128-bit vectors
2506 const TypeVect *TypeVect::VECTY = NULL; // 256-bit vectors
2507 const TypeVect *TypeVect::VECTZ = NULL; // 512-bit vectors
2508 
2509 //------------------------------make-------------------------------------------
2510 const TypeVect* TypeVect::make(const Type *elem, uint length) {
2511   BasicType elem_bt = elem->array_element_basic_type();
2512   assert(is_java_primitive(elem_bt), "only primitive types in vector");
2513   assert(length > 1 && is_power_of_2(length), "vector length is power of 2");
2514   assert(Matcher::vector_size_supported(elem_bt, length), "length in range");
2515   int size = length * type2aelembytes(elem_bt);
2516   switch (Matcher::vector_ideal_reg(size)) {
2517   case Op_VecS:
2518     return (TypeVect*)(new TypeVectS(elem, length))->hashcons();
2519   case Op_RegL:
2520   case Op_VecD:
2521   case Op_RegD:
2522     return (TypeVect*)(new TypeVectD(elem, length))->hashcons();
2523   case Op_VecX:
2524     return (TypeVect*)(new TypeVectX(elem, length))->hashcons();
2525   case Op_VecY:
2526     return (TypeVect*)(new TypeVectY(elem, length))->hashcons();
2527   case Op_VecZ:
2528     return (TypeVect*)(new TypeVectZ(elem, length))->hashcons();
2529   }
2530  ShouldNotReachHere();
2531   return NULL;
2532 }
2533 
2534 //------------------------------meet-------------------------------------------
2535 // Compute the MEET of two types.  It returns a new Type object.
2536 const Type *TypeVect::xmeet( const Type *t ) const {
2537   // Perform a fast test for common case; meeting the same types together.
2538   if( this == t ) return this;  // Meeting same type-rep?
2539 
2540   // Current "this->_base" is Vector
2541   switch (t->base()) {          // switch on original type
2542 
2543   case Bottom:                  // Ye Olde Default
2544     return t;
2545 
2546   default:                      // All else is a mistake
2547     typerr(t);
2548 
2549   case VectorS:
2550   case VectorD:
2551   case VectorX:
2552   case VectorY:
2553   case VectorZ: {                // Meeting 2 vectors?
2554     const TypeVect* v = t->is_vect();
2555     assert(  base() == v->base(), "");
2556     assert(length() == v->length(), "");
2557     assert(element_basic_type() == v->element_basic_type(), "");
2558     return TypeVect::make(_elem->xmeet(v->_elem), _length);
2559   }
2560   case Top:
2561     break;
2562   }
2563   return this;
2564 }
2565 
2566 //------------------------------xdual------------------------------------------
2567 // Dual: compute field-by-field dual
2568 const Type *TypeVect::xdual() const {
2569   return new TypeVect(base(), _elem->dual(), _length);
2570 }
2571 
2572 //------------------------------eq---------------------------------------------
2573 // Structural equality check for Type representations
2574 bool TypeVect::eq(const Type *t) const {
2575   const TypeVect *v = t->is_vect();
2576   return (_elem == v->_elem) && (_length == v->_length);
2577 }
2578 
2579 //------------------------------hash-------------------------------------------
2580 // Type-specific hashing function.
2581 int TypeVect::hash(void) const {
2582   return (intptr_t)_elem + (intptr_t)_length;
2583 }
2584 
2585 //------------------------------singleton--------------------------------------
2586 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2587 // constants (Ldi nodes).  Vector is singleton if all elements are the same
2588 // constant value (when vector is created with Replicate code).
2589 bool TypeVect::singleton(void) const {
2590 // There is no Con node for vectors yet.
2591 //  return _elem->singleton();
2592   return false;
2593 }
2594 
2595 bool TypeVect::empty(void) const {
2596   return _elem->empty();
2597 }
2598 
2599 //------------------------------dump2------------------------------------------
2600 #ifndef PRODUCT
2601 void TypeVect::dump2(Dict &d, uint depth, outputStream *st) const {
2602   switch (base()) {
2603   case VectorS:
2604     st->print("vectors["); break;
2605   case VectorD:
2606     st->print("vectord["); break;
2607   case VectorX:
2608     st->print("vectorx["); break;
2609   case VectorY:
2610     st->print("vectory["); break;
2611   case VectorZ:
2612     st->print("vectorz["); break;
2613   default:
2614     ShouldNotReachHere();
2615   }
2616   st->print("%d]:{", _length);
2617   _elem->dump2(d, depth, st);
2618   st->print("}");
2619 }
2620 #endif
2621 
2622 
2623 //=============================================================================
2624 // Convenience common pre-built types.
2625 const TypePtr *TypePtr::NULL_PTR;
2626 const TypePtr *TypePtr::NOTNULL;
2627 const TypePtr *TypePtr::BOTTOM;
2628 
2629 //------------------------------meet-------------------------------------------
2630 // Meet over the PTR enum
2631 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2632   //              TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,
2633   { /* Top     */ TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,},
2634   { /* AnyNull */ AnyNull,   AnyNull,   Constant, BotPTR, NotNull, BotPTR,},
2635   { /* Constant*/ Constant,  Constant,  Constant, BotPTR, NotNull, BotPTR,},
2636   { /* Null    */ Null,      BotPTR,    BotPTR,   Null,   BotPTR,  BotPTR,},
2637   { /* NotNull */ NotNull,   NotNull,   NotNull,  BotPTR, NotNull, BotPTR,},
2638   { /* BotPTR  */ BotPTR,    BotPTR,    BotPTR,   BotPTR, BotPTR,  BotPTR,}
2639 };
2640 
2641 //------------------------------make-------------------------------------------
2642 const TypePtr* TypePtr::make(TYPES t, enum PTR ptr, Offset offset, const TypePtr* speculative, int inline_depth) {
2643   return (TypePtr*)(new TypePtr(t,ptr,offset, speculative, inline_depth))->hashcons();
2644 }
2645 
2646 //------------------------------cast_to_ptr_type-------------------------------
2647 const Type *TypePtr::cast_to_ptr_type(PTR ptr) const {
2648   assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2649   if( ptr == _ptr ) return this;
2650   return make(_base, ptr, _offset, _speculative, _inline_depth);
2651 }
2652 
2653 //------------------------------get_con----------------------------------------
2654 intptr_t TypePtr::get_con() const {
2655   assert( _ptr == Null, "" );
2656   return offset();
2657 }
2658 
2659 //------------------------------meet-------------------------------------------
2660 // Compute the MEET of two types.  It returns a new Type object.
2661 const Type *TypePtr::xmeet(const Type *t) const {
2662   const Type* res = xmeet_helper(t);
2663   if (res->isa_ptr() == NULL) {
2664     return res;
2665   }
2666 
2667   const TypePtr* res_ptr = res->is_ptr();
2668   if (res_ptr->speculative() != NULL) {
2669     // type->speculative() == NULL means that speculation is no better
2670     // than type, i.e. type->speculative() == type. So there are 2
2671     // ways to represent the fact that we have no useful speculative
2672     // data and we should use a single one to be able to test for
2673     // equality between types. Check whether type->speculative() ==
2674     // type and set speculative to NULL if it is the case.
2675     if (res_ptr->remove_speculative() == res_ptr->speculative()) {
2676       return res_ptr->remove_speculative();
2677     }
2678   }
2679 
2680   return res;
2681 }
2682 
2683 const Type *TypePtr::xmeet_helper(const Type *t) const {
2684   // Perform a fast test for common case; meeting the same types together.
2685   if( this == t ) return this;  // Meeting same type-rep?
2686 
2687   // Current "this->_base" is AnyPtr
2688   switch (t->base()) {          // switch on original type
2689   case Int:                     // Mixing ints & oops happens when javac
2690   case Long:                    // reuses local variables
2691   case FloatTop:
2692   case FloatCon:
2693   case FloatBot:
2694   case DoubleTop:
2695   case DoubleCon:
2696   case DoubleBot:
2697   case NarrowOop:
2698   case NarrowKlass:
2699   case Bottom:                  // Ye Olde Default
2700     return Type::BOTTOM;
2701   case Top:
2702     return this;
2703 
2704   case AnyPtr: {                // Meeting to AnyPtrs
2705     const TypePtr *tp = t->is_ptr();
2706     const TypePtr* speculative = xmeet_speculative(tp);
2707     int depth = meet_inline_depth(tp->inline_depth());
2708     return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2709   }
2710   case RawPtr:                  // For these, flip the call around to cut down
2711   case OopPtr:
2712   case InstPtr:                 // on the cases I have to handle.
2713   case AryPtr:
2714   case MetadataPtr:
2715   case KlassPtr:
2716     return t->xmeet(this);      // Call in reverse direction
2717   default:                      // All else is a mistake
2718     typerr(t);
2719 
2720   }
2721   return this;
2722 }
2723 
2724 //------------------------------meet_offset------------------------------------
2725 Type::Offset TypePtr::meet_offset(int offset) const {
2726   return _offset.meet(Offset(offset));
2727 }
2728 
2729 //------------------------------dual_offset------------------------------------
2730 Type::Offset TypePtr::dual_offset() const {
2731   return _offset.dual();
2732 }
2733 
2734 //------------------------------xdual------------------------------------------
2735 // Dual: compute field-by-field dual
2736 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2737   BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2738 };
2739 const Type *TypePtr::xdual() const {
2740   return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
2741 }
2742 
2743 //------------------------------xadd_offset------------------------------------
2744 Type::Offset TypePtr::xadd_offset(intptr_t offset) const {
2745   return _offset.add(offset);
2746 }
2747 
2748 //------------------------------add_offset-------------------------------------
2749 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2750   return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth);
2751 }
2752 
2753 //------------------------------eq---------------------------------------------
2754 // Structural equality check for Type representations
2755 bool TypePtr::eq( const Type *t ) const {
2756   const TypePtr *a = (const TypePtr*)t;
2757   return _ptr == a->ptr() && _offset == a->_offset && eq_speculative(a) && _inline_depth == a->_inline_depth;
2758 }
2759 
2760 //------------------------------hash-------------------------------------------
2761 // Type-specific hashing function.
2762 int TypePtr::hash(void) const {
2763   return java_add(java_add((jint)_ptr, (jint)offset()), java_add((jint)hash_speculative(), (jint)_inline_depth));
2764 ;
2765 }
2766 
2767 /**
2768  * Return same type without a speculative part
2769  */
2770 const Type* TypePtr::remove_speculative() const {
2771   if (_speculative == NULL) {
2772     return this;
2773   }
2774   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2775   return make(AnyPtr, _ptr, _offset, NULL, _inline_depth);
2776 }
2777 
2778 /**
2779  * Return same type but drop speculative part if we know we won't use
2780  * it
2781  */
2782 const Type* TypePtr::cleanup_speculative() const {
2783   if (speculative() == NULL) {
2784     return this;
2785   }
2786   const Type* no_spec = remove_speculative();
2787   // If this is NULL_PTR then we don't need the speculative type
2788   // (with_inline_depth in case the current type inline depth is
2789   // InlineDepthTop)
2790   if (no_spec == NULL_PTR->with_inline_depth(inline_depth())) {
2791     return no_spec;
2792   }
2793   if (above_centerline(speculative()->ptr())) {
2794     return no_spec;
2795   }
2796   const TypeOopPtr* spec_oopptr = speculative()->isa_oopptr();
2797   // If the speculative may be null and is an inexact klass then it
2798   // doesn't help
2799   if (speculative() != TypePtr::NULL_PTR && speculative()->maybe_null() &&
2800       (spec_oopptr == NULL || !spec_oopptr->klass_is_exact())) {
2801     return no_spec;
2802   }
2803   return this;
2804 }
2805 
2806 /**
2807  * dual of the speculative part of the type
2808  */
2809 const TypePtr* TypePtr::dual_speculative() const {
2810   if (_speculative == NULL) {
2811     return NULL;
2812   }
2813   return _speculative->dual()->is_ptr();
2814 }
2815 
2816 /**
2817  * meet of the speculative parts of 2 types
2818  *
2819  * @param other  type to meet with
2820  */
2821 const TypePtr* TypePtr::xmeet_speculative(const TypePtr* other) const {
2822   bool this_has_spec = (_speculative != NULL);
2823   bool other_has_spec = (other->speculative() != NULL);
2824 
2825   if (!this_has_spec && !other_has_spec) {
2826     return NULL;
2827   }
2828 
2829   // If we are at a point where control flow meets and one branch has
2830   // a speculative type and the other has not, we meet the speculative
2831   // type of one branch with the actual type of the other. If the
2832   // actual type is exact and the speculative is as well, then the
2833   // result is a speculative type which is exact and we can continue
2834   // speculation further.
2835   const TypePtr* this_spec = _speculative;
2836   const TypePtr* other_spec = other->speculative();
2837 
2838   if (!this_has_spec) {
2839     this_spec = this;
2840   }
2841 
2842   if (!other_has_spec) {
2843     other_spec = other;
2844   }
2845 
2846   return this_spec->meet(other_spec)->is_ptr();
2847 }
2848 
2849 /**
2850  * dual of the inline depth for this type (used for speculation)
2851  */
2852 int TypePtr::dual_inline_depth() const {
2853   return -inline_depth();
2854 }
2855 
2856 /**
2857  * meet of 2 inline depths (used for speculation)
2858  *
2859  * @param depth  depth to meet with
2860  */
2861 int TypePtr::meet_inline_depth(int depth) const {
2862   return MAX2(inline_depth(), depth);
2863 }
2864 
2865 /**
2866  * Are the speculative parts of 2 types equal?
2867  *
2868  * @param other  type to compare this one to
2869  */
2870 bool TypePtr::eq_speculative(const TypePtr* other) const {
2871   if (_speculative == NULL || other->speculative() == NULL) {
2872     return _speculative == other->speculative();
2873   }
2874 
2875   if (_speculative->base() != other->speculative()->base()) {
2876     return false;
2877   }
2878 
2879   return _speculative->eq(other->speculative());
2880 }
2881 
2882 /**
2883  * Hash of the speculative part of the type
2884  */
2885 int TypePtr::hash_speculative() const {
2886   if (_speculative == NULL) {
2887     return 0;
2888   }
2889 
2890   return _speculative->hash();
2891 }
2892 
2893 /**
2894  * add offset to the speculative part of the type
2895  *
2896  * @param offset  offset to add
2897  */
2898 const TypePtr* TypePtr::add_offset_speculative(intptr_t offset) const {
2899   if (_speculative == NULL) {
2900     return NULL;
2901   }
2902   return _speculative->add_offset(offset)->is_ptr();
2903 }
2904 
2905 /**
2906  * return exact klass from the speculative type if there's one
2907  */
2908 ciKlass* TypePtr::speculative_type() const {
2909   if (_speculative != NULL && _speculative->isa_oopptr()) {
2910     const TypeOopPtr* speculative = _speculative->join(this)->is_oopptr();
2911     if (speculative->klass_is_exact()) {
2912       return speculative->klass();
2913     }
2914   }
2915   return NULL;
2916 }
2917 
2918 /**
2919  * return true if speculative type may be null
2920  */
2921 bool TypePtr::speculative_maybe_null() const {
2922   if (_speculative != NULL) {
2923     const TypePtr* speculative = _speculative->join(this)->is_ptr();
2924     return speculative->maybe_null();
2925   }
2926   return true;
2927 }
2928 
2929 bool TypePtr::speculative_always_null() const {
2930   if (_speculative != NULL) {
2931     const TypePtr* speculative = _speculative->join(this)->is_ptr();
2932     return speculative == TypePtr::NULL_PTR;
2933   }
2934   return false;
2935 }
2936 
2937 /**
2938  * Same as TypePtr::speculative_type() but return the klass only if
2939  * the speculative tells us is not null
2940  */
2941 ciKlass* TypePtr::speculative_type_not_null() const {
2942   if (speculative_maybe_null()) {
2943     return NULL;
2944   }
2945   return speculative_type();
2946 }
2947 
2948 /**
2949  * Check whether new profiling would improve speculative type
2950  *
2951  * @param   exact_kls    class from profiling
2952  * @param   inline_depth inlining depth of profile point
2953  *
2954  * @return  true if type profile is valuable
2955  */
2956 bool TypePtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
2957   // no profiling?
2958   if (exact_kls == NULL) {
2959     return false;
2960   }
2961   if (speculative() == TypePtr::NULL_PTR) {
2962     return false;
2963   }
2964   // no speculative type or non exact speculative type?
2965   if (speculative_type() == NULL) {
2966     return true;
2967   }
2968   // If the node already has an exact speculative type keep it,
2969   // unless it was provided by profiling that is at a deeper
2970   // inlining level. Profiling at a higher inlining depth is
2971   // expected to be less accurate.
2972   if (_speculative->inline_depth() == InlineDepthBottom) {
2973     return false;
2974   }
2975   assert(_speculative->inline_depth() != InlineDepthTop, "can't do the comparison");
2976   return inline_depth < _speculative->inline_depth();
2977 }
2978 
2979 /**
2980  * Check whether new profiling would improve ptr (= tells us it is non
2981  * null)
2982  *
2983  * @param   ptr_kind always null or not null?
2984  *
2985  * @return  true if ptr profile is valuable
2986  */
2987 bool TypePtr::would_improve_ptr(ProfilePtrKind ptr_kind) const {
2988   // profiling doesn't tell us anything useful
2989   if (ptr_kind != ProfileAlwaysNull && ptr_kind != ProfileNeverNull) {
2990     return false;
2991   }
2992   // We already know this is not null
2993   if (!this->maybe_null()) {
2994     return false;
2995   }
2996   // We already know the speculative type cannot be null
2997   if (!speculative_maybe_null()) {
2998     return false;
2999   }
3000   // We already know this is always null
3001   if (this == TypePtr::NULL_PTR) {
3002     return false;
3003   }
3004   // We already know the speculative type is always null
3005   if (speculative_always_null()) {
3006     return false;
3007   }
3008   if (ptr_kind == ProfileAlwaysNull && speculative() != NULL && speculative()->isa_oopptr()) {
3009     return false;
3010   }
3011   return true;
3012 }
3013 
3014 //------------------------------dump2------------------------------------------
3015 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
3016   "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR"
3017 };
3018 
3019 #ifndef PRODUCT
3020 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3021   if( _ptr == Null ) st->print("NULL");
3022   else st->print("%s *", ptr_msg[_ptr]);
3023   _offset.dump2(st);
3024   dump_inline_depth(st);
3025   dump_speculative(st);
3026 }
3027 
3028 /**
3029  *dump the speculative part of the type
3030  */
3031 void TypePtr::dump_speculative(outputStream *st) const {
3032   if (_speculative != NULL) {
3033     st->print(" (speculative=");
3034     _speculative->dump_on(st);
3035     st->print(")");
3036   }
3037 }
3038 
3039 /**
3040  *dump the inline depth of the type
3041  */
3042 void TypePtr::dump_inline_depth(outputStream *st) const {
3043   if (_inline_depth != InlineDepthBottom) {
3044     if (_inline_depth == InlineDepthTop) {
3045       st->print(" (inline_depth=InlineDepthTop)");
3046     } else {
3047       st->print(" (inline_depth=%d)", _inline_depth);
3048     }
3049   }
3050 }
3051 #endif
3052 
3053 //------------------------------singleton--------------------------------------
3054 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3055 // constants
3056 bool TypePtr::singleton(void) const {
3057   // TopPTR, Null, AnyNull, Constant are all singletons
3058   return (_offset != Offset::bottom) && !below_centerline(_ptr);
3059 }
3060 
3061 bool TypePtr::empty(void) const {
3062   return (_offset == Offset::top) || above_centerline(_ptr);
3063 }
3064 
3065 //=============================================================================
3066 // Convenience common pre-built types.
3067 const TypeRawPtr *TypeRawPtr::BOTTOM;
3068 const TypeRawPtr *TypeRawPtr::NOTNULL;
3069 
3070 //------------------------------make-------------------------------------------
3071 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
3072   assert( ptr != Constant, "what is the constant?" );
3073   assert( ptr != Null, "Use TypePtr for NULL" );
3074   return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons();
3075 }
3076 
3077 const TypeRawPtr *TypeRawPtr::make( address bits ) {
3078   assert( bits, "Use TypePtr for NULL" );
3079   return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
3080 }
3081 
3082 //------------------------------cast_to_ptr_type-------------------------------
3083 const Type *TypeRawPtr::cast_to_ptr_type(PTR ptr) const {
3084   assert( ptr != Constant, "what is the constant?" );
3085   assert( ptr != Null, "Use TypePtr for NULL" );
3086   assert( _bits==0, "Why cast a constant address?");
3087   if( ptr == _ptr ) return this;
3088   return make(ptr);
3089 }
3090 
3091 //------------------------------get_con----------------------------------------
3092 intptr_t TypeRawPtr::get_con() const {
3093   assert( _ptr == Null || _ptr == Constant, "" );
3094   return (intptr_t)_bits;
3095 }
3096 
3097 //------------------------------meet-------------------------------------------
3098 // Compute the MEET of two types.  It returns a new Type object.
3099 const Type *TypeRawPtr::xmeet( const Type *t ) const {
3100   // Perform a fast test for common case; meeting the same types together.
3101   if( this == t ) return this;  // Meeting same type-rep?
3102 
3103   // Current "this->_base" is RawPtr
3104   switch( t->base() ) {         // switch on original type
3105   case Bottom:                  // Ye Olde Default
3106     return t;
3107   case Top:
3108     return this;
3109   case AnyPtr:                  // Meeting to AnyPtrs
3110     break;
3111   case RawPtr: {                // might be top, bot, any/not or constant
3112     enum PTR tptr = t->is_ptr()->ptr();
3113     enum PTR ptr = meet_ptr( tptr );
3114     if( ptr == Constant ) {     // Cannot be equal constants, so...
3115       if( tptr == Constant && _ptr != Constant)  return t;
3116       if( _ptr == Constant && tptr != Constant)  return this;
3117       ptr = NotNull;            // Fall down in lattice
3118     }
3119     return make( ptr );
3120   }
3121 
3122   case OopPtr:
3123   case InstPtr:
3124   case AryPtr:
3125   case MetadataPtr:
3126   case KlassPtr:
3127     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3128   default:                      // All else is a mistake
3129     typerr(t);
3130   }
3131 
3132   // Found an AnyPtr type vs self-RawPtr type
3133   const TypePtr *tp = t->is_ptr();
3134   switch (tp->ptr()) {
3135   case TypePtr::TopPTR:  return this;
3136   case TypePtr::BotPTR:  return t;
3137   case TypePtr::Null:
3138     if( _ptr == TypePtr::TopPTR ) return t;
3139     return TypeRawPtr::BOTTOM;
3140   case TypePtr::NotNull: return TypePtr::make(AnyPtr, meet_ptr(TypePtr::NotNull), tp->meet_offset(0), tp->speculative(), tp->inline_depth());
3141   case TypePtr::AnyNull:
3142     if( _ptr == TypePtr::Constant) return this;
3143     return make( meet_ptr(TypePtr::AnyNull) );
3144   default: ShouldNotReachHere();
3145   }
3146   return this;
3147 }
3148 
3149 //------------------------------xdual------------------------------------------
3150 // Dual: compute field-by-field dual
3151 const Type *TypeRawPtr::xdual() const {
3152   return new TypeRawPtr( dual_ptr(), _bits );
3153 }
3154 
3155 //------------------------------add_offset-------------------------------------
3156 const TypePtr *TypeRawPtr::add_offset( intptr_t offset ) const {
3157   if( offset == OffsetTop ) return BOTTOM; // Undefined offset-> undefined pointer
3158   if( offset == OffsetBot ) return BOTTOM; // Unknown offset-> unknown pointer
3159   if( offset == 0 ) return this; // No change
3160   switch (_ptr) {
3161   case TypePtr::TopPTR:
3162   case TypePtr::BotPTR:
3163   case TypePtr::NotNull:
3164     return this;
3165   case TypePtr::Null:
3166   case TypePtr::Constant: {
3167     address bits = _bits+offset;
3168     if ( bits == 0 ) return TypePtr::NULL_PTR;
3169     return make( bits );
3170   }
3171   default:  ShouldNotReachHere();
3172   }
3173   return NULL;                  // Lint noise
3174 }
3175 
3176 //------------------------------eq---------------------------------------------
3177 // Structural equality check for Type representations
3178 bool TypeRawPtr::eq( const Type *t ) const {
3179   const TypeRawPtr *a = (const TypeRawPtr*)t;
3180   return _bits == a->_bits && TypePtr::eq(t);
3181 }
3182 
3183 //------------------------------hash-------------------------------------------
3184 // Type-specific hashing function.
3185 int TypeRawPtr::hash(void) const {
3186   return (intptr_t)_bits + TypePtr::hash();
3187 }
3188 
3189 //------------------------------dump2------------------------------------------
3190 #ifndef PRODUCT
3191 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3192   if( _ptr == Constant )
3193     st->print(INTPTR_FORMAT, p2i(_bits));
3194   else
3195     st->print("rawptr:%s", ptr_msg[_ptr]);
3196 }
3197 #endif
3198 
3199 //=============================================================================
3200 // Convenience common pre-built type.
3201 const TypeOopPtr *TypeOopPtr::BOTTOM;
3202 
3203 //------------------------------TypeOopPtr-------------------------------------
3204 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, Offset offset, Offset field_offset,
3205                        int instance_id, const TypePtr* speculative, int inline_depth)
3206   : TypePtr(t, ptr, offset, speculative, inline_depth),
3207     _const_oop(o), _klass(k),
3208     _klass_is_exact(xk),
3209     _is_ptr_to_narrowoop(false),
3210     _is_ptr_to_narrowklass(false),
3211     _is_ptr_to_boxed_value(false),
3212     _instance_id(instance_id) {
3213   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3214       (offset.get() > 0) && xk && (k != 0) && k->is_instance_klass()) {
3215     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset.get());
3216   }
3217 #ifdef _LP64
3218   if (this->offset() > 0 || this->offset() == Type::OffsetTop || this->offset() == Type::OffsetBot) {
3219     if (this->offset() == oopDesc::klass_offset_in_bytes()) {
3220       _is_ptr_to_narrowklass = UseCompressedClassPointers;
3221     } else if (klass() == NULL) {
3222       // Array with unknown body type
3223       assert(this->isa_aryptr(), "only arrays without klass");
3224       _is_ptr_to_narrowoop = UseCompressedOops;
3225     } else if (UseCompressedOops && this->isa_aryptr() && this->offset() != arrayOopDesc::length_offset_in_bytes()) {
3226       if (klass()->is_obj_array_klass()) {
3227         _is_ptr_to_narrowoop = true;
3228       } else if (klass()->is_value_array_klass() && field_offset != Offset::top && field_offset != Offset::bottom) {
3229         // Check if the field of the value type array element contains oops
3230         ciValueKlass* vk = klass()->as_value_array_klass()->element_klass()->as_value_klass();
3231         int foffset = field_offset.get() + vk->first_field_offset();
3232         ciField* field = vk->get_field_by_offset(foffset, false);
3233         assert(field != NULL, "missing field");
3234         BasicType bt = field->layout_type();
3235         _is_ptr_to_narrowoop = (bt == T_OBJECT || bt == T_ARRAY || T_VALUETYPE);
3236       }
3237     } else if (klass()->is_instance_klass()) {
3238       if (this->isa_klassptr()) {
3239         // Perm objects don't use compressed references
3240       } else if (_offset == Offset::bottom || _offset == Offset::top) {
3241         // unsafe access
3242         _is_ptr_to_narrowoop = UseCompressedOops;
3243       } else { // exclude unsafe ops
3244         assert(this->isa_instptr(), "must be an instance ptr.");
3245         if (klass() == ciEnv::current()->Class_klass() &&
3246             (this->offset() == java_lang_Class::klass_offset_in_bytes() ||
3247              this->offset() == java_lang_Class::array_klass_offset_in_bytes())) {
3248           // Special hidden fields from the Class.
3249           assert(this->isa_instptr(), "must be an instance ptr.");
3250           _is_ptr_to_narrowoop = false;
3251         } else if (klass() == ciEnv::current()->Class_klass() &&
3252                    this->offset() >= InstanceMirrorKlass::offset_of_static_fields()) {
3253           // Static fields
3254           assert(o != NULL, "must be constant");
3255           ciInstanceKlass* ik = o->as_instance()->java_lang_Class_klass()->as_instance_klass();
3256           BasicType basic_elem_type;
3257           if (ik->is_valuetype() && this->offset() == ik->as_value_klass()->default_value_offset()) {
3258             // Special hidden field that contains the oop of the default value type
3259             basic_elem_type = T_VALUETYPE;
3260           } else {
3261             ciField* field = ik->get_field_by_offset(this->offset(), true);
3262             assert(field != NULL, "missing field");
3263             basic_elem_type = field->layout_type();
3264           }
3265           _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||
3266                                                        basic_elem_type == T_VALUETYPE ||
3267                                                        basic_elem_type == T_ARRAY);
3268         } else {
3269           // Instance fields which contains a compressed oop references.
3270           ciInstanceKlass* ik = klass()->as_instance_klass();
3271           ciField* field = ik->get_field_by_offset(this->offset(), false);
3272           if (field != NULL) {
3273             BasicType basic_elem_type = field->layout_type();
3274             _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||
3275                                                          basic_elem_type == T_VALUETYPE ||
3276                                                          basic_elem_type == T_ARRAY);
3277           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3278             // Compile::find_alias_type() cast exactness on all types to verify
3279             // that it does not affect alias type.
3280             _is_ptr_to_narrowoop = UseCompressedOops;
3281           } else {
3282             // Type for the copy start in LibraryCallKit::inline_native_clone().
3283             _is_ptr_to_narrowoop = UseCompressedOops;
3284           }
3285         }
3286       }
3287     }
3288   }
3289 #endif
3290 }
3291 
3292 //------------------------------make-------------------------------------------
3293 const TypeOopPtr *TypeOopPtr::make(PTR ptr, Offset offset, int instance_id,
3294                                    const TypePtr* speculative, int inline_depth) {
3295   assert(ptr != Constant, "no constant generic pointers");
3296   ciKlass*  k = Compile::current()->env()->Object_klass();
3297   bool      xk = false;
3298   ciObject* o = NULL;
3299   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, Offset::bottom, instance_id, speculative, inline_depth))->hashcons();
3300 }
3301 
3302 
3303 //------------------------------cast_to_ptr_type-------------------------------
3304 const Type *TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3305   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3306   if( ptr == _ptr ) return this;
3307   return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3308 }
3309 
3310 //-----------------------------cast_to_instance_id----------------------------
3311 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3312   // There are no instances of a general oop.
3313   // Return self unchanged.
3314   return this;
3315 }
3316 
3317 const TypeOopPtr *TypeOopPtr::cast_to_nonconst() const {
3318   return this;
3319 }
3320 
3321 //-----------------------------cast_to_exactness-------------------------------
3322 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3323   // There is no such thing as an exact general oop.
3324   // Return self unchanged.
3325   return this;
3326 }
3327 
3328 
3329 //------------------------------as_klass_type----------------------------------
3330 // Return the klass type corresponding to this instance or array type.
3331 // It is the type that is loaded from an object of this type.
3332 const TypeKlassPtr* TypeOopPtr::as_klass_type() const {
3333   ciKlass* k = klass();
3334   bool    xk = klass_is_exact();
3335   if (k == NULL)
3336     return TypeKlassPtr::OBJECT;
3337   else
3338     return TypeKlassPtr::make(xk? Constant: NotNull, k, Offset(0));
3339 }
3340 
3341 //------------------------------meet-------------------------------------------
3342 // Compute the MEET of two types.  It returns a new Type object.
3343 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3344   // Perform a fast test for common case; meeting the same types together.
3345   if( this == t ) return this;  // Meeting same type-rep?
3346 
3347   // Current "this->_base" is OopPtr
3348   switch (t->base()) {          // switch on original type
3349 
3350   case Int:                     // Mixing ints & oops happens when javac
3351   case Long:                    // reuses local variables
3352   case FloatTop:
3353   case FloatCon:
3354   case FloatBot:
3355   case DoubleTop:
3356   case DoubleCon:
3357   case DoubleBot:
3358   case NarrowOop:
3359   case NarrowKlass:
3360   case Bottom:                  // Ye Olde Default
3361     return Type::BOTTOM;
3362   case Top:
3363     return this;
3364 
3365   default:                      // All else is a mistake
3366     typerr(t);
3367 
3368   case RawPtr:
3369   case MetadataPtr:
3370   case KlassPtr:
3371     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3372 
3373   case AnyPtr: {
3374     // Found an AnyPtr type vs self-OopPtr type
3375     const TypePtr *tp = t->is_ptr();
3376     Offset offset = meet_offset(tp->offset());
3377     PTR ptr = meet_ptr(tp->ptr());
3378     const TypePtr* speculative = xmeet_speculative(tp);
3379     int depth = meet_inline_depth(tp->inline_depth());
3380     switch (tp->ptr()) {
3381     case Null:
3382       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3383       // else fall through:
3384     case TopPTR:
3385     case AnyNull: {
3386       int instance_id = meet_instance_id(InstanceTop);
3387       return make(ptr, offset, instance_id, speculative, depth);
3388     }
3389     case BotPTR:
3390     case NotNull:
3391       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3392     default: typerr(t);
3393     }
3394   }
3395 
3396   case OopPtr: {                 // Meeting to other OopPtrs
3397     const TypeOopPtr *tp = t->is_oopptr();
3398     int instance_id = meet_instance_id(tp->instance_id());
3399     const TypePtr* speculative = xmeet_speculative(tp);
3400     int depth = meet_inline_depth(tp->inline_depth());
3401     return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3402   }
3403 
3404   case InstPtr:                  // For these, flip the call around to cut down
3405   case AryPtr:
3406     return t->xmeet(this);      // Call in reverse direction
3407 
3408   } // End of switch
3409   return this;                  // Return the double constant
3410 }
3411 
3412 
3413 //------------------------------xdual------------------------------------------
3414 // Dual of a pure heap pointer.  No relevant klass or oop information.
3415 const Type *TypeOopPtr::xdual() const {
3416   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3417   assert(const_oop() == NULL,             "no constants here");
3418   return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), Offset::bottom, dual_instance_id(), dual_speculative(), dual_inline_depth());
3419 }
3420 
3421 //--------------------------make_from_klass_common-----------------------------
3422 // Computes the element-type given a klass.
3423 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) {
3424   if (klass->is_instance_klass() || klass->is_valuetype()) {
3425     Compile* C = Compile::current();
3426     Dependencies* deps = C->dependencies();
3427     assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
3428     // Element is an instance
3429     bool klass_is_exact = false;
3430     if (klass->is_loaded()) {
3431       // Try to set klass_is_exact.
3432       ciInstanceKlass* ik = klass->as_instance_klass();
3433       klass_is_exact = ik->is_final();
3434       if (!klass_is_exact && klass_change
3435           && deps != NULL && UseUniqueSubclasses) {
3436         ciInstanceKlass* sub = ik->unique_concrete_subklass();
3437         if (sub != NULL) {
3438           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3439           klass = ik = sub;
3440           klass_is_exact = sub->is_final();
3441         }
3442       }
3443       if (!klass_is_exact && try_for_exact
3444           && deps != NULL && UseExactTypes) {
3445         if (!ik->is_interface() && !ik->has_subklass()) {
3446           // Add a dependence; if concrete subclass added we need to recompile
3447           deps->assert_leaf_type(ik);
3448           klass_is_exact = true;
3449         }
3450       }
3451     }
3452     return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, Offset(0));
3453   } else if (klass->is_obj_array_klass()) {
3454     // Element is an object or value array. Recursively call ourself.
3455     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), false, try_for_exact);
3456     bool null_free = klass->is_loaded() && klass->as_array_klass()->storage_properties().is_null_free();
3457     if (null_free && etype->is_valuetypeptr()) {
3458       etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3459     }
3460     // [V? has a subtype: [V. So eventhough V is final, [V? is not exact.
3461     bool xk = etype->klass_is_exact() && (!etype->is_valuetypeptr() || null_free);
3462     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3463     // We used to pass NotNull in here, asserting that the sub-arrays
3464     // are all not-null.  This is not true in generally, as code can
3465     // slam NULLs down in the subarrays.
3466     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, Offset(0));
3467     return arr;
3468   } else if (klass->is_type_array_klass()) {
3469     // Element is an typeArray
3470     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3471     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3472     // We used to pass NotNull in here, asserting that the array pointer
3473     // is not-null. That was not true in general.
3474     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
3475     return arr;
3476   } else if (klass->is_value_array_klass()) {
3477     ciValueKlass* vk = klass->as_array_klass()->element_klass()->as_value_klass();
3478     const TypeAry* arr0 = TypeAry::make(TypeValueType::make(vk), TypeInt::POS);
3479     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
3480     return arr;
3481   } else {
3482     ShouldNotReachHere();
3483     return NULL;
3484   }
3485 }
3486 
3487 //------------------------------make_from_constant-----------------------------
3488 // Make a java pointer from an oop constant
3489 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3490   assert(!o->is_null_object(), "null object not yet handled here.");
3491 
3492   const bool make_constant = require_constant || o->should_be_constant();
3493 
3494   ciKlass* klass = o->klass();
3495   if (klass->is_instance_klass() || klass->is_valuetype()) {
3496     // Element is an instance or value type
3497     if (make_constant) {
3498       return TypeInstPtr::make(o);
3499     } else {
3500       return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, Offset(0));
3501     }
3502   } else if (klass->is_obj_array_klass()) {
3503     // Element is an object array. Recursively call ourself.
3504     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass());
3505     bool null_free = klass->is_loaded() && klass->as_array_klass()->storage_properties().is_null_free();
3506     if (null_free && etype->is_valuetypeptr()) {
3507       etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3508     }
3509     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3510     // We used to pass NotNull in here, asserting that the sub-arrays
3511     // are all not-null.  This is not true in generally, as code can
3512     // slam NULLs down in the subarrays.
3513     if (make_constant) {
3514       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3515     } else {
3516       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3517     }
3518   } else if (klass->is_type_array_klass()) {
3519     // Element is an typeArray
3520     const Type* etype =
3521       (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3522     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3523     // We used to pass NotNull in here, asserting that the array pointer
3524     // is not-null. That was not true in general.
3525     if (make_constant) {
3526       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3527     } else {
3528       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3529     }
3530   } else if (klass->is_value_array_klass()) {
3531     ciValueKlass* vk = klass->as_array_klass()->element_klass()->as_value_klass();
3532     const TypeAry* arr0 = TypeAry::make(TypeValueType::make(vk), TypeInt::make(o->as_array()->length()));
3533     // We used to pass NotNull in here, asserting that the sub-arrays
3534     // are all not-null.  This is not true in generally, as code can
3535     // slam NULLs down in the subarrays.
3536     if (make_constant) {
3537       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3538     } else {
3539       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3540     }
3541   }
3542 
3543   fatal("unhandled object type");
3544   return NULL;
3545 }
3546 
3547 //------------------------------get_con----------------------------------------
3548 intptr_t TypeOopPtr::get_con() const {
3549   assert( _ptr == Null || _ptr == Constant, "" );
3550   assert(offset() >= 0, "");
3551 
3552   if (offset() != 0) {
3553     // After being ported to the compiler interface, the compiler no longer
3554     // directly manipulates the addresses of oops.  Rather, it only has a pointer
3555     // to a handle at compile time.  This handle is embedded in the generated
3556     // code and dereferenced at the time the nmethod is made.  Until that time,
3557     // it is not reasonable to do arithmetic with the addresses of oops (we don't
3558     // have access to the addresses!).  This does not seem to currently happen,
3559     // but this assertion here is to help prevent its occurence.
3560     tty->print_cr("Found oop constant with non-zero offset");
3561     ShouldNotReachHere();
3562   }
3563 
3564   return (intptr_t)const_oop()->constant_encoding();
3565 }
3566 
3567 
3568 //-----------------------------filter------------------------------------------
3569 // Do not allow interface-vs.-noninterface joins to collapse to top.
3570 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
3571 
3572   const Type* ft = join_helper(kills, include_speculative);
3573   const TypeInstPtr* ftip = ft->isa_instptr();
3574   const TypeInstPtr* ktip = kills->isa_instptr();
3575 
3576   if (ft->empty()) {
3577     // Check for evil case of 'this' being a class and 'kills' expecting an
3578     // interface.  This can happen because the bytecodes do not contain
3579     // enough type info to distinguish a Java-level interface variable
3580     // from a Java-level object variable.  If we meet 2 classes which
3581     // both implement interface I, but their meet is at 'j/l/O' which
3582     // doesn't implement I, we have no way to tell if the result should
3583     // be 'I' or 'j/l/O'.  Thus we'll pick 'j/l/O'.  If this then flows
3584     // into a Phi which "knows" it's an Interface type we'll have to
3585     // uplift the type.
3586     if (!empty()) {
3587       if (ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface()) {
3588         return kills;           // Uplift to interface
3589       }
3590       // Also check for evil cases of 'this' being a class array
3591       // and 'kills' expecting an array of interfaces.
3592       Type::get_arrays_base_elements(ft, kills, NULL, &ktip);
3593       if (ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface()) {
3594         return kills;           // Uplift to array of interface
3595       }
3596     }
3597 
3598     return Type::TOP;           // Canonical empty value
3599   }
3600 
3601   // If we have an interface-typed Phi or cast and we narrow to a class type,
3602   // the join should report back the class.  However, if we have a J/L/Object
3603   // class-typed Phi and an interface flows in, it's possible that the meet &
3604   // join report an interface back out.  This isn't possible but happens
3605   // because the type system doesn't interact well with interfaces.
3606   if (ftip != NULL && ktip != NULL &&
3607       ftip->is_loaded() &&  ftip->klass()->is_interface() &&
3608       ktip->is_loaded() && !ktip->klass()->is_interface()) {
3609     assert(!ftip->klass_is_exact(), "interface could not be exact");
3610     return ktip->cast_to_ptr_type(ftip->ptr());
3611   }
3612 
3613   return ft;
3614 }
3615 
3616 //------------------------------eq---------------------------------------------
3617 // Structural equality check for Type representations
3618 bool TypeOopPtr::eq( const Type *t ) const {
3619   const TypeOopPtr *a = (const TypeOopPtr*)t;
3620   if (_klass_is_exact != a->_klass_is_exact ||
3621       _instance_id != a->_instance_id)  return false;
3622   ciObject* one = const_oop();
3623   ciObject* two = a->const_oop();
3624   if (one == NULL || two == NULL) {
3625     return (one == two) && TypePtr::eq(t);
3626   } else {
3627     return one->equals(two) && TypePtr::eq(t);
3628   }
3629 }
3630 
3631 //------------------------------hash-------------------------------------------
3632 // Type-specific hashing function.
3633 int TypeOopPtr::hash(void) const {
3634   return
3635     java_add(java_add((jint)(const_oop() ? const_oop()->hash() : 0), (jint)_klass_is_exact),
3636              java_add((jint)_instance_id, (jint)TypePtr::hash()));
3637 }
3638 
3639 //------------------------------dump2------------------------------------------
3640 #ifndef PRODUCT
3641 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3642   st->print("oopptr:%s", ptr_msg[_ptr]);
3643   if( _klass_is_exact ) st->print(":exact");
3644   if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
3645   _offset.dump2(st);
3646   if (_instance_id == InstanceTop)
3647     st->print(",iid=top");
3648   else if (_instance_id != InstanceBot)
3649     st->print(",iid=%d",_instance_id);
3650 
3651   dump_inline_depth(st);
3652   dump_speculative(st);
3653 }
3654 #endif
3655 
3656 //------------------------------singleton--------------------------------------
3657 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3658 // constants
3659 bool TypeOopPtr::singleton(void) const {
3660   // detune optimizer to not generate constant oop + constant offset as a constant!
3661   // TopPTR, Null, AnyNull, Constant are all singletons
3662   return (offset() == 0) && !below_centerline(_ptr);
3663 }
3664 
3665 //------------------------------add_offset-------------------------------------
3666 const TypePtr *TypeOopPtr::add_offset(intptr_t offset) const {
3667   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
3668 }
3669 
3670 /**
3671  * Return same type without a speculative part
3672  */
3673 const Type* TypeOopPtr::remove_speculative() const {
3674   if (_speculative == NULL) {
3675     return this;
3676   }
3677   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
3678   return make(_ptr, _offset, _instance_id, NULL, _inline_depth);
3679 }
3680 
3681 /**
3682  * Return same type but drop speculative part if we know we won't use
3683  * it
3684  */
3685 const Type* TypeOopPtr::cleanup_speculative() const {
3686   // If the klass is exact and the ptr is not null then there's
3687   // nothing that the speculative type can help us with
3688   if (klass_is_exact() && !maybe_null()) {
3689     return remove_speculative();
3690   }
3691   return TypePtr::cleanup_speculative();
3692 }
3693 
3694 /**
3695  * Return same type but with a different inline depth (used for speculation)
3696  *
3697  * @param depth  depth to meet with
3698  */
3699 const TypePtr* TypeOopPtr::with_inline_depth(int depth) const {
3700   if (!UseInlineDepthForSpeculativeTypes) {
3701     return this;
3702   }
3703   return make(_ptr, _offset, _instance_id, _speculative, depth);
3704 }
3705 
3706 //------------------------------with_instance_id--------------------------------
3707 const TypePtr* TypeOopPtr::with_instance_id(int instance_id) const {
3708   assert(_instance_id != -1, "should be known");
3709   return make(_ptr, _offset, instance_id, _speculative, _inline_depth);
3710 }
3711 
3712 //------------------------------meet_instance_id--------------------------------
3713 int TypeOopPtr::meet_instance_id( int instance_id ) const {
3714   // Either is 'TOP' instance?  Return the other instance!
3715   if( _instance_id == InstanceTop ) return  instance_id;
3716   if(  instance_id == InstanceTop ) return _instance_id;
3717   // If either is different, return 'BOTTOM' instance
3718   if( _instance_id != instance_id ) return InstanceBot;
3719   return _instance_id;
3720 }
3721 
3722 //------------------------------dual_instance_id--------------------------------
3723 int TypeOopPtr::dual_instance_id( ) const {
3724   if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM
3725   if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP
3726   return _instance_id;              // Map everything else into self
3727 }
3728 
3729 /**
3730  * Check whether new profiling would improve speculative type
3731  *
3732  * @param   exact_kls    class from profiling
3733  * @param   inline_depth inlining depth of profile point
3734  *
3735  * @return  true if type profile is valuable
3736  */
3737 bool TypeOopPtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
3738   // no way to improve an already exact type
3739   if (klass_is_exact()) {
3740     return false;
3741   }
3742   return TypePtr::would_improve_type(exact_kls, inline_depth);
3743 }
3744 
3745 //=============================================================================
3746 // Convenience common pre-built types.
3747 const TypeInstPtr *TypeInstPtr::NOTNULL;
3748 const TypeInstPtr *TypeInstPtr::BOTTOM;
3749 const TypeInstPtr *TypeInstPtr::MIRROR;
3750 const TypeInstPtr *TypeInstPtr::MARK;
3751 const TypeInstPtr *TypeInstPtr::KLASS;
3752 
3753 //------------------------------TypeInstPtr-------------------------------------
3754 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, Offset off,
3755                          int instance_id, const TypePtr* speculative, int inline_depth)
3756   : TypeOopPtr(InstPtr, ptr, k, xk, o, off, Offset::bottom, instance_id, speculative, inline_depth),
3757     _name(k->name()) {
3758    assert(k != NULL &&
3759           (k->is_loaded() || o == NULL),
3760           "cannot have constants with non-loaded klass");
3761 };
3762 
3763 //------------------------------make-------------------------------------------
3764 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
3765                                      ciKlass* k,
3766                                      bool xk,
3767                                      ciObject* o,
3768                                      Offset offset,
3769                                      int instance_id,
3770                                      const TypePtr* speculative,
3771                                      int inline_depth) {
3772   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
3773   // Either const_oop() is NULL or else ptr is Constant
3774   assert( (!o && ptr != Constant) || (o && ptr == Constant),
3775           "constant pointers must have a value supplied" );
3776   // Ptr is never Null
3777   assert( ptr != Null, "NULL pointers are not typed" );
3778 
3779   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3780   if (!UseExactTypes)  xk = false;
3781   if (ptr == Constant) {
3782     // Note:  This case includes meta-object constants, such as methods.
3783     xk = true;
3784   } else if (k->is_loaded()) {
3785     ciInstanceKlass* ik = k->as_instance_klass();
3786     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
3787     if (xk && ik->is_interface())  xk = false;  // no exact interface
3788   }
3789 
3790   // Now hash this baby
3791   TypeInstPtr *result =
3792     (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o ,offset, instance_id, speculative, inline_depth))->hashcons();
3793 
3794   return result;
3795 }
3796 
3797 /**
3798  *  Create constant type for a constant boxed value
3799  */
3800 const Type* TypeInstPtr::get_const_boxed_value() const {
3801   assert(is_ptr_to_boxed_value(), "should be called only for boxed value");
3802   assert((const_oop() != NULL), "should be called only for constant object");
3803   ciConstant constant = const_oop()->as_instance()->field_value_by_offset(offset());
3804   BasicType bt = constant.basic_type();
3805   switch (bt) {
3806     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
3807     case T_INT:      return TypeInt::make(constant.as_int());
3808     case T_CHAR:     return TypeInt::make(constant.as_char());
3809     case T_BYTE:     return TypeInt::make(constant.as_byte());
3810     case T_SHORT:    return TypeInt::make(constant.as_short());
3811     case T_FLOAT:    return TypeF::make(constant.as_float());
3812     case T_DOUBLE:   return TypeD::make(constant.as_double());
3813     case T_LONG:     return TypeLong::make(constant.as_long());
3814     default:         break;
3815   }
3816   fatal("Invalid boxed value type '%s'", type2name(bt));
3817   return NULL;
3818 }
3819 
3820 //------------------------------cast_to_ptr_type-------------------------------
3821 const Type *TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
3822   if( ptr == _ptr ) return this;
3823   // Reconstruct _sig info here since not a problem with later lazy
3824   // construction, _sig will show up on demand.
3825   return make(ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, _inline_depth);
3826 }
3827 
3828 
3829 //-----------------------------cast_to_exactness-------------------------------
3830 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
3831   if( klass_is_exact == _klass_is_exact ) return this;
3832   if (!UseExactTypes)  return this;
3833   if (!_klass->is_loaded())  return this;
3834   ciInstanceKlass* ik = _klass->as_instance_klass();
3835   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
3836   if( ik->is_interface() )              return this;  // cannot set xk
3837   return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id, _speculative, _inline_depth);
3838 }
3839 
3840 //-----------------------------cast_to_instance_id----------------------------
3841 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const {
3842   if( instance_id == _instance_id ) return this;
3843   return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id, _speculative, _inline_depth);
3844 }
3845 
3846 const TypeOopPtr *TypeInstPtr::cast_to_nonconst() const {
3847   if (const_oop() == NULL) return this;
3848   return make(NotNull, klass(), _klass_is_exact, NULL, _offset, _instance_id, _speculative, _inline_depth);
3849 }
3850 
3851 //------------------------------xmeet_unloaded---------------------------------
3852 // Compute the MEET of two InstPtrs when at least one is unloaded.
3853 // Assume classes are different since called after check for same name/class-loader
3854 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
3855     Offset off = meet_offset(tinst->offset());
3856     PTR ptr = meet_ptr(tinst->ptr());
3857     int instance_id = meet_instance_id(tinst->instance_id());
3858     const TypePtr* speculative = xmeet_speculative(tinst);
3859     int depth = meet_inline_depth(tinst->inline_depth());
3860 
3861     const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
3862     const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
3863     if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
3864       //
3865       // Meet unloaded class with java/lang/Object
3866       //
3867       // Meet
3868       //          |                     Unloaded Class
3869       //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
3870       //  ===================================================================
3871       //   TOP    | ..........................Unloaded......................|
3872       //  AnyNull |  U-AN    |................Unloaded......................|
3873       // Constant | ... O-NN .................................. |   O-BOT   |
3874       //  NotNull | ... O-NN .................................. |   O-BOT   |
3875       //  BOTTOM  | ........................Object-BOTTOM ..................|
3876       //
3877       assert(loaded->ptr() != TypePtr::Null, "insanity check");
3878       //
3879       if(      loaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
3880       else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make(ptr, unloaded->klass(), false, NULL, off, instance_id, speculative, depth); }
3881       else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
3882       else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
3883         if (unloaded->ptr() == TypePtr::BotPTR  ) { return TypeInstPtr::BOTTOM;  }
3884         else                                      { return TypeInstPtr::NOTNULL; }
3885       }
3886       else if( unloaded->ptr() == TypePtr::TopPTR )  { return unloaded; }
3887 
3888       return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr();
3889     }
3890 
3891     // Both are unloaded, not the same class, not Object
3892     // Or meet unloaded with a different loaded class, not java/lang/Object
3893     if( ptr != TypePtr::BotPTR ) {
3894       return TypeInstPtr::NOTNULL;
3895     }
3896     return TypeInstPtr::BOTTOM;
3897 }
3898 
3899 
3900 //------------------------------meet-------------------------------------------
3901 // Compute the MEET of two types.  It returns a new Type object.
3902 const Type *TypeInstPtr::xmeet_helper(const Type *t) const {
3903   // Perform a fast test for common case; meeting the same types together.
3904   if( this == t ) return this;  // Meeting same type-rep?
3905 
3906   // Current "this->_base" is Pointer
3907   switch (t->base()) {          // switch on original type
3908 
3909   case Int:                     // Mixing ints & oops happens when javac
3910   case Long:                    // reuses local variables
3911   case FloatTop:
3912   case FloatCon:
3913   case FloatBot:
3914   case DoubleTop:
3915   case DoubleCon:
3916   case DoubleBot:
3917   case NarrowOop:
3918   case NarrowKlass:
3919   case Bottom:                  // Ye Olde Default
3920     return Type::BOTTOM;
3921   case Top:
3922     return this;
3923 
3924   default:                      // All else is a mistake
3925     typerr(t);
3926 
3927   case MetadataPtr:
3928   case KlassPtr:
3929   case RawPtr: return TypePtr::BOTTOM;
3930 
3931   case AryPtr: {                // All arrays inherit from Object class
3932     const TypeAryPtr *tp = t->is_aryptr();
3933     Offset offset = meet_offset(tp->offset());
3934     PTR ptr = meet_ptr(tp->ptr());
3935     int instance_id = meet_instance_id(tp->instance_id());
3936     const TypePtr* speculative = xmeet_speculative(tp);
3937     int depth = meet_inline_depth(tp->inline_depth());
3938     switch (ptr) {
3939     case TopPTR:
3940     case AnyNull:                // Fall 'down' to dual of object klass
3941       // For instances when a subclass meets a superclass we fall
3942       // below the centerline when the superclass is exact. We need to
3943       // do the same here.
3944       if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
3945         return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, tp->field_offset(), instance_id, speculative, depth);
3946       } else {
3947         // cannot subclass, so the meet has to fall badly below the centerline
3948         ptr = NotNull;
3949         instance_id = InstanceBot;
3950         return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
3951       }
3952     case Constant:
3953     case NotNull:
3954     case BotPTR:                // Fall down to object klass
3955       // LCA is object_klass, but if we subclass from the top we can do better
3956       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
3957         // If 'this' (InstPtr) is above the centerline and it is Object class
3958         // then we can subclass in the Java class hierarchy.
3959         // For instances when a subclass meets a superclass we fall
3960         // below the centerline when the superclass is exact. We need
3961         // to do the same here.
3962         if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
3963           // that is, tp's array type is a subtype of my klass
3964           return TypeAryPtr::make(ptr, (ptr == Constant ? tp->const_oop() : NULL),
3965                                   tp->ary(), tp->klass(), tp->klass_is_exact(), offset, tp->field_offset(), instance_id, speculative, depth);
3966         }
3967       }
3968       // The other case cannot happen, since I cannot be a subtype of an array.
3969       // The meet falls down to Object class below centerline.
3970       if( ptr == Constant )
3971          ptr = NotNull;
3972       instance_id = InstanceBot;
3973       return make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
3974     default: typerr(t);
3975     }
3976   }
3977 
3978   case OopPtr: {                // Meeting to OopPtrs
3979     // Found a OopPtr type vs self-InstPtr type
3980     const TypeOopPtr *tp = t->is_oopptr();
3981     Offset offset = meet_offset(tp->offset());
3982     PTR ptr = meet_ptr(tp->ptr());
3983     switch (tp->ptr()) {
3984     case TopPTR:
3985     case AnyNull: {
3986       int instance_id = meet_instance_id(InstanceTop);
3987       const TypePtr* speculative = xmeet_speculative(tp);
3988       int depth = meet_inline_depth(tp->inline_depth());
3989       return make(ptr, klass(), klass_is_exact(),
3990                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth);
3991     }
3992     case NotNull:
3993     case BotPTR: {
3994       int instance_id = meet_instance_id(tp->instance_id());
3995       const TypePtr* speculative = xmeet_speculative(tp);
3996       int depth = meet_inline_depth(tp->inline_depth());
3997       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
3998     }
3999     default: typerr(t);
4000     }
4001   }
4002 
4003   case AnyPtr: {                // Meeting to AnyPtrs
4004     // Found an AnyPtr type vs self-InstPtr type
4005     const TypePtr *tp = t->is_ptr();
4006     Offset offset = meet_offset(tp->offset());
4007     PTR ptr = meet_ptr(tp->ptr());
4008     int instance_id = meet_instance_id(InstanceTop);
4009     const TypePtr* speculative = xmeet_speculative(tp);
4010     int depth = meet_inline_depth(tp->inline_depth());
4011     switch (tp->ptr()) {
4012     case Null:
4013       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4014       // else fall through to AnyNull
4015     case TopPTR:
4016     case AnyNull: {
4017       return make(ptr, klass(), klass_is_exact(),
4018                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth);
4019     }
4020     case NotNull:
4021     case BotPTR:
4022       return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4023     default: typerr(t);
4024     }
4025   }
4026 
4027   /*
4028                  A-top         }
4029                /   |   \       }  Tops
4030            B-top A-any C-top   }
4031               | /  |  \ |      }  Any-nulls
4032            B-any   |   C-any   }
4033               |    |    |
4034            B-con A-con C-con   } constants; not comparable across classes
4035               |    |    |
4036            B-not   |   C-not   }
4037               | \  |  / |      }  not-nulls
4038            B-bot A-not C-bot   }
4039                \   |   /       }  Bottoms
4040                  A-bot         }
4041   */
4042 
4043   case InstPtr: {                // Meeting 2 Oops?
4044     // Found an InstPtr sub-type vs self-InstPtr type
4045     const TypeInstPtr *tinst = t->is_instptr();
4046     Offset off = meet_offset( tinst->offset() );
4047     PTR ptr = meet_ptr( tinst->ptr() );
4048     int instance_id = meet_instance_id(tinst->instance_id());
4049     const TypePtr* speculative = xmeet_speculative(tinst);
4050     int depth = meet_inline_depth(tinst->inline_depth());
4051 
4052     // Check for easy case; klasses are equal (and perhaps not loaded!)
4053     // If we have constants, then we created oops so classes are loaded
4054     // and we can handle the constants further down.  This case handles
4055     // both-not-loaded or both-loaded classes
4056     if (ptr != Constant && klass()->equals(tinst->klass()) && klass_is_exact() == tinst->klass_is_exact()) {
4057       return make(ptr, klass(), klass_is_exact(), NULL, off, instance_id, speculative, depth);
4058     }
4059 
4060     // Classes require inspection in the Java klass hierarchy.  Must be loaded.
4061     ciKlass* tinst_klass = tinst->klass();
4062     ciKlass* this_klass  = this->klass();
4063     bool tinst_xk = tinst->klass_is_exact();
4064     bool this_xk  = this->klass_is_exact();
4065     if (!tinst_klass->is_loaded() || !this_klass->is_loaded() ) {
4066       // One of these classes has not been loaded
4067       const TypeInstPtr *unloaded_meet = xmeet_unloaded(tinst);
4068 #ifndef PRODUCT
4069       if( PrintOpto && Verbose ) {
4070         tty->print("meet of unloaded classes resulted in: "); unloaded_meet->dump(); tty->cr();
4071         tty->print("  this == "); this->dump(); tty->cr();
4072         tty->print(" tinst == "); tinst->dump(); tty->cr();
4073       }
4074 #endif
4075       return unloaded_meet;
4076     }
4077 
4078     // Handle mixing oops and interfaces first.
4079     if( this_klass->is_interface() && !(tinst_klass->is_interface() ||
4080                                         tinst_klass == ciEnv::current()->Object_klass())) {
4081       ciKlass *tmp = tinst_klass; // Swap interface around
4082       tinst_klass = this_klass;
4083       this_klass = tmp;
4084       bool tmp2 = tinst_xk;
4085       tinst_xk = this_xk;
4086       this_xk = tmp2;
4087     }
4088     if (tinst_klass->is_interface() &&
4089         !(this_klass->is_interface() ||
4090           // Treat java/lang/Object as an honorary interface,
4091           // because we need a bottom for the interface hierarchy.
4092           this_klass == ciEnv::current()->Object_klass())) {
4093       // Oop meets interface!
4094 
4095       // See if the oop subtypes (implements) interface.
4096       ciKlass *k;
4097       bool xk;
4098       if( this_klass->is_subtype_of( tinst_klass ) ) {
4099         // Oop indeed subtypes.  Now keep oop or interface depending
4100         // on whether we are both above the centerline or either is
4101         // below the centerline.  If we are on the centerline
4102         // (e.g., Constant vs. AnyNull interface), use the constant.
4103         k  = below_centerline(ptr) ? tinst_klass : this_klass;
4104         // If we are keeping this_klass, keep its exactness too.
4105         xk = below_centerline(ptr) ? tinst_xk    : this_xk;
4106       } else {                  // Does not implement, fall to Object
4107         // Oop does not implement interface, so mixing falls to Object
4108         // just like the verifier does (if both are above the
4109         // centerline fall to interface)
4110         k = above_centerline(ptr) ? tinst_klass : ciEnv::current()->Object_klass();
4111         xk = above_centerline(ptr) ? tinst_xk : false;
4112         // Watch out for Constant vs. AnyNull interface.
4113         if (ptr == Constant)  ptr = NotNull;   // forget it was a constant
4114         instance_id = InstanceBot;
4115       }
4116       ciObject* o = NULL;  // the Constant value, if any
4117       if (ptr == Constant) {
4118         // Find out which constant.
4119         o = (this_klass == klass()) ? const_oop() : tinst->const_oop();
4120       }
4121       return make(ptr, k, xk, o, off, instance_id, speculative, depth);
4122     }
4123 
4124     // Either oop vs oop or interface vs interface or interface vs Object
4125 
4126     // !!! Here's how the symmetry requirement breaks down into invariants:
4127     // If we split one up & one down AND they subtype, take the down man.
4128     // If we split one up & one down AND they do NOT subtype, "fall hard".
4129     // If both are up and they subtype, take the subtype class.
4130     // If both are up and they do NOT subtype, "fall hard".
4131     // If both are down and they subtype, take the supertype class.
4132     // If both are down and they do NOT subtype, "fall hard".
4133     // Constants treated as down.
4134 
4135     // Now, reorder the above list; observe that both-down+subtype is also
4136     // "fall hard"; "fall hard" becomes the default case:
4137     // If we split one up & one down AND they subtype, take the down man.
4138     // If both are up and they subtype, take the subtype class.
4139 
4140     // If both are down and they subtype, "fall hard".
4141     // If both are down and they do NOT subtype, "fall hard".
4142     // If both are up and they do NOT subtype, "fall hard".
4143     // If we split one up & one down AND they do NOT subtype, "fall hard".
4144 
4145     // If a proper subtype is exact, and we return it, we return it exactly.
4146     // If a proper supertype is exact, there can be no subtyping relationship!
4147     // If both types are equal to the subtype, exactness is and-ed below the
4148     // centerline and or-ed above it.  (N.B. Constants are always exact.)
4149 
4150     // Check for subtyping:
4151     ciKlass *subtype = NULL;
4152     bool subtype_exact = false;
4153     if( tinst_klass->equals(this_klass) ) {
4154       subtype = this_klass;
4155       subtype_exact = below_centerline(ptr) ? (this_xk & tinst_xk) : (this_xk | tinst_xk);
4156     } else if( !tinst_xk && this_klass->is_subtype_of( tinst_klass ) ) {
4157       subtype = this_klass;     // Pick subtyping class
4158       subtype_exact = this_xk;
4159     } else if( !this_xk && tinst_klass->is_subtype_of( this_klass ) ) {
4160       subtype = tinst_klass;    // Pick subtyping class
4161       subtype_exact = tinst_xk;
4162     }
4163 
4164     if( subtype ) {
4165       if( above_centerline(ptr) ) { // both are up?
4166         this_klass = tinst_klass = subtype;
4167         this_xk = tinst_xk = subtype_exact;
4168       } else if( above_centerline(this ->_ptr) && !above_centerline(tinst->_ptr) ) {
4169         this_klass = tinst_klass; // tinst is down; keep down man
4170         this_xk = tinst_xk;
4171       } else if( above_centerline(tinst->_ptr) && !above_centerline(this ->_ptr) ) {
4172         tinst_klass = this_klass; // this is down; keep down man
4173         tinst_xk = this_xk;
4174       } else {
4175         this_xk = subtype_exact;  // either they are equal, or we'll do an LCA
4176       }
4177     }
4178 
4179     // Check for classes now being equal
4180     if (tinst_klass->equals(this_klass)) {
4181       // If the klasses are equal, the constants may still differ.  Fall to
4182       // NotNull if they do (neither constant is NULL; that is a special case
4183       // handled elsewhere).
4184       ciObject* o = NULL;             // Assume not constant when done
4185       ciObject* this_oop  = const_oop();
4186       ciObject* tinst_oop = tinst->const_oop();
4187       if( ptr == Constant ) {
4188         if (this_oop != NULL && tinst_oop != NULL &&
4189             this_oop->equals(tinst_oop) )
4190           o = this_oop;
4191         else if (above_centerline(this ->_ptr))
4192           o = tinst_oop;
4193         else if (above_centerline(tinst ->_ptr))
4194           o = this_oop;
4195         else
4196           ptr = NotNull;
4197       }
4198       return make(ptr, this_klass, this_xk, o, off, instance_id, speculative, depth);
4199     } // Else classes are not equal
4200 
4201     // Since klasses are different, we require a LCA in the Java
4202     // class hierarchy - which means we have to fall to at least NotNull.
4203     if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
4204       ptr = NotNull;
4205 
4206     instance_id = InstanceBot;
4207 
4208     // Now we find the LCA of Java classes
4209     ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
4210     return make(ptr, k, false, NULL, off, instance_id, speculative, depth);
4211   } // End of case InstPtr
4212 
4213   case ValueType: {
4214     const TypeValueType* tv = t->is_valuetype();
4215     if (above_centerline(ptr())) {
4216       if (tv->value_klass()->is_subtype_of(_klass)) {
4217         return t;
4218       } else {
4219         return TypeInstPtr::make(NotNull, _klass);
4220       }
4221     } else {
4222       PTR ptr = this->_ptr;
4223       if (ptr == Constant) {
4224         ptr = NotNull;
4225       }
4226       if (tv->value_klass()->is_subtype_of(_klass)) {
4227         return TypeInstPtr::make(ptr, _klass);
4228       } else {
4229         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass());
4230       }
4231     }
4232   }
4233 
4234   } // End of switch
4235   return this;                  // Return the double constant
4236 }
4237 
4238 
4239 //------------------------java_mirror_type--------------------------------------
4240 ciType* TypeInstPtr::java_mirror_type(bool* is_val_type) const {
4241   // must be a singleton type
4242   if( const_oop() == NULL )  return NULL;
4243 
4244   // must be of type java.lang.Class
4245   if( klass() != ciEnv::current()->Class_klass() )  return NULL;
4246 
4247   return const_oop()->as_instance()->java_mirror_type(is_val_type);
4248 }
4249 
4250 
4251 //------------------------------xdual------------------------------------------
4252 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
4253 // inheritance mechanism.
4254 const Type *TypeInstPtr::xdual() const {
4255   return new TypeInstPtr(dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4256 }
4257 
4258 //------------------------------eq---------------------------------------------
4259 // Structural equality check for Type representations
4260 bool TypeInstPtr::eq( const Type *t ) const {
4261   const TypeInstPtr *p = t->is_instptr();
4262   return
4263     klass()->equals(p->klass()) &&
4264     TypeOopPtr::eq(p);          // Check sub-type stuff
4265 }
4266 
4267 //------------------------------hash-------------------------------------------
4268 // Type-specific hashing function.
4269 int TypeInstPtr::hash(void) const {
4270   int hash = java_add((jint)klass()->hash(), (jint)TypeOopPtr::hash());
4271   return hash;
4272 }
4273 
4274 //------------------------------dump2------------------------------------------
4275 // Dump oop Type
4276 #ifndef PRODUCT
4277 void TypeInstPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4278   // Print the name of the klass.
4279   klass()->print_name_on(st);
4280 
4281   switch( _ptr ) {
4282   case Constant:
4283     // TO DO: Make CI print the hex address of the underlying oop.
4284     if (WizardMode || Verbose) {
4285       const_oop()->print_oop(st);
4286     }
4287   case BotPTR:
4288     if (!WizardMode && !Verbose) {
4289       if( _klass_is_exact ) st->print(":exact");
4290       break;
4291     }
4292   case TopPTR:
4293   case AnyNull:
4294   case NotNull:
4295     st->print(":%s", ptr_msg[_ptr]);
4296     if( _klass_is_exact ) st->print(":exact");
4297     break;
4298   default:
4299     break;
4300   }
4301 
4302   _offset.dump2(st);
4303 
4304   st->print(" *");
4305   if (_instance_id == InstanceTop)
4306     st->print(",iid=top");
4307   else if (_instance_id != InstanceBot)
4308     st->print(",iid=%d",_instance_id);
4309 
4310   dump_inline_depth(st);
4311   dump_speculative(st);
4312 }
4313 #endif
4314 
4315 //------------------------------add_offset-------------------------------------
4316 const TypePtr *TypeInstPtr::add_offset(intptr_t offset) const {
4317   return make(_ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset),
4318               _instance_id, add_offset_speculative(offset), _inline_depth);
4319 }
4320 
4321 const Type *TypeInstPtr::remove_speculative() const {
4322   if (_speculative == NULL) {
4323     return this;
4324   }
4325   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4326   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset,
4327               _instance_id, NULL, _inline_depth);
4328 }
4329 
4330 const TypePtr *TypeInstPtr::with_inline_depth(int depth) const {
4331   if (!UseInlineDepthForSpeculativeTypes) {
4332     return this;
4333   }
4334   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth);
4335 }
4336 
4337 const TypePtr *TypeInstPtr::with_instance_id(int instance_id) const {
4338   assert(is_known_instance(), "should be known");
4339   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, instance_id, _speculative, _inline_depth);
4340 }
4341 
4342 //=============================================================================
4343 // Convenience common pre-built types.
4344 const TypeAryPtr *TypeAryPtr::RANGE;
4345 const TypeAryPtr *TypeAryPtr::OOPS;
4346 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
4347 const TypeAryPtr *TypeAryPtr::BYTES;
4348 const TypeAryPtr *TypeAryPtr::SHORTS;
4349 const TypeAryPtr *TypeAryPtr::CHARS;
4350 const TypeAryPtr *TypeAryPtr::INTS;
4351 const TypeAryPtr *TypeAryPtr::LONGS;
4352 const TypeAryPtr *TypeAryPtr::FLOATS;
4353 const TypeAryPtr *TypeAryPtr::DOUBLES;
4354 
4355 //------------------------------make-------------------------------------------
4356 const TypeAryPtr* TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4357                                    int instance_id, const TypePtr* speculative, int inline_depth) {
4358   assert(!(k == NULL && ary->_elem->isa_int()),
4359          "integral arrays must be pre-equipped with a class");
4360   if (!xk) xk = ary->ary_must_be_exact();
4361   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
4362   if (!UseExactTypes)  xk = (ptr == Constant);
4363   return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, field_offset, instance_id, false, speculative, inline_depth))->hashcons();
4364 }
4365 
4366 //------------------------------make-------------------------------------------
4367 const TypeAryPtr* TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4368                                    int instance_id, const TypePtr* speculative, int inline_depth,
4369                                    bool is_autobox_cache) {
4370   assert(!(k == NULL && ary->_elem->isa_int()),
4371          "integral arrays must be pre-equipped with a class");
4372   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4373   if (!xk)  xk = (o != NULL) || ary->ary_must_be_exact();
4374   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
4375   if (!UseExactTypes)  xk = (ptr == Constant);
4376   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, field_offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4377 }
4378 
4379 //------------------------------cast_to_ptr_type-------------------------------
4380 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4381   if( ptr == _ptr ) return this;
4382   return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4383 }
4384 
4385 
4386 //-----------------------------cast_to_exactness-------------------------------
4387 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4388   if( klass_is_exact == _klass_is_exact ) return this;
4389   if (!UseExactTypes)  return this;
4390   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
4391   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4392 }
4393 
4394 //-----------------------------cast_to_instance_id----------------------------
4395 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const {
4396   if( instance_id == _instance_id ) return this;
4397   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth, _is_autobox_cache);
4398 }
4399 
4400 const TypeOopPtr *TypeAryPtr::cast_to_nonconst() const {
4401   if (const_oop() == NULL) return this;
4402   return make(NotNull, NULL, _ary, klass(), _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth);
4403 }
4404 
4405 
4406 //-----------------------------narrow_size_type-------------------------------
4407 // Local cache for arrayOopDesc::max_array_length(etype),
4408 // which is kind of slow (and cached elsewhere by other users).
4409 static jint max_array_length_cache[T_CONFLICT+1];
4410 static jint max_array_length(BasicType etype) {
4411   jint& cache = max_array_length_cache[etype];
4412   jint res = cache;
4413   if (res == 0) {
4414     switch (etype) {
4415     case T_NARROWOOP:
4416       etype = T_OBJECT;
4417       break;
4418     case T_NARROWKLASS:
4419     case T_CONFLICT:
4420     case T_ILLEGAL:
4421     case T_VOID:
4422       etype = T_BYTE;           // will produce conservatively high value
4423       break;
4424     default:
4425       break;
4426     }
4427     cache = res = arrayOopDesc::max_array_length(etype);
4428   }
4429   return res;
4430 }
4431 
4432 // Narrow the given size type to the index range for the given array base type.
4433 // Return NULL if the resulting int type becomes empty.
4434 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const {
4435   jint hi = size->_hi;
4436   jint lo = size->_lo;
4437   jint min_lo = 0;
4438   jint max_hi = max_array_length(elem()->basic_type());
4439   //if (index_not_size)  --max_hi;     // type of a valid array index, FTR
4440   bool chg = false;
4441   if (lo < min_lo) {
4442     lo = min_lo;
4443     if (size->is_con()) {
4444       hi = lo;
4445     }
4446     chg = true;
4447   }
4448   if (hi > max_hi) {
4449     hi = max_hi;
4450     if (size->is_con()) {
4451       lo = hi;
4452     }
4453     chg = true;
4454   }
4455   // Negative length arrays will produce weird intermediate dead fast-path code
4456   if (lo > hi)
4457     return TypeInt::ZERO;
4458   if (!chg)
4459     return size;
4460   return TypeInt::make(lo, hi, Type::WidenMin);
4461 }
4462 
4463 //-------------------------------cast_to_size----------------------------------
4464 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4465   assert(new_size != NULL, "");
4466   new_size = narrow_size_type(new_size);
4467   if (new_size == size())  return this;
4468   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
4469   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4470 }
4471 
4472 //------------------------------cast_to_stable---------------------------------
4473 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
4474   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
4475     return this;
4476 
4477   const Type* elem = this->elem();
4478   const TypePtr* elem_ptr = elem->make_ptr();
4479 
4480   if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) {
4481     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
4482     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
4483   }
4484 
4485   const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
4486 
4487   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4488 }
4489 
4490 //-----------------------------stable_dimension--------------------------------
4491 int TypeAryPtr::stable_dimension() const {
4492   if (!is_stable())  return 0;
4493   int dim = 1;
4494   const TypePtr* elem_ptr = elem()->make_ptr();
4495   if (elem_ptr != NULL && elem_ptr->isa_aryptr())
4496     dim += elem_ptr->is_aryptr()->stable_dimension();
4497   return dim;
4498 }
4499 
4500 //----------------------cast_to_autobox_cache-----------------------------------
4501 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache(bool cache) const {
4502   if (is_autobox_cache() == cache)  return this;
4503   const TypeOopPtr* etype = elem()->make_oopptr();
4504   if (etype == NULL)  return this;
4505   // The pointers in the autobox arrays are always non-null.
4506   TypePtr::PTR ptr_type = cache ? TypePtr::NotNull : TypePtr::AnyNull;
4507   etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
4508   const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable());
4509   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, cache);
4510 }
4511 
4512 //------------------------------eq---------------------------------------------
4513 // Structural equality check for Type representations
4514 bool TypeAryPtr::eq( const Type *t ) const {
4515   const TypeAryPtr *p = t->is_aryptr();
4516   return
4517     _ary == p->_ary &&  // Check array
4518     TypeOopPtr::eq(p) &&// Check sub-parts
4519     _field_offset == p->_field_offset;
4520 }
4521 
4522 //------------------------------hash-------------------------------------------
4523 // Type-specific hashing function.
4524 int TypeAryPtr::hash(void) const {
4525   return (intptr_t)_ary + TypeOopPtr::hash() + _field_offset.get();
4526 }
4527 
4528 //------------------------------meet-------------------------------------------
4529 // Compute the MEET of two types.  It returns a new Type object.
4530 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
4531   // Perform a fast test for common case; meeting the same types together.
4532   if( this == t ) return this;  // Meeting same type-rep?
4533   // Current "this->_base" is Pointer
4534   switch (t->base()) {          // switch on original type
4535 
4536   // Mixing ints & oops happens when javac reuses local variables
4537   case Int:
4538   case Long:
4539   case FloatTop:
4540   case FloatCon:
4541   case FloatBot:
4542   case DoubleTop:
4543   case DoubleCon:
4544   case DoubleBot:
4545   case NarrowOop:
4546   case NarrowKlass:
4547   case Bottom:                  // Ye Olde Default
4548     return Type::BOTTOM;
4549   case Top:
4550     return this;
4551 
4552   default:                      // All else is a mistake
4553     typerr(t);
4554 
4555   case OopPtr: {                // Meeting to OopPtrs
4556     // Found a OopPtr type vs self-AryPtr type
4557     const TypeOopPtr *tp = t->is_oopptr();
4558     Offset offset = meet_offset(tp->offset());
4559     PTR ptr = meet_ptr(tp->ptr());
4560     int depth = meet_inline_depth(tp->inline_depth());
4561     const TypePtr* speculative = xmeet_speculative(tp);
4562     switch (tp->ptr()) {
4563     case TopPTR:
4564     case AnyNull: {
4565       int instance_id = meet_instance_id(InstanceTop);
4566       return make(ptr, (ptr == Constant ? const_oop() : NULL),
4567                   _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
4568     }
4569     case BotPTR:
4570     case NotNull: {
4571       int instance_id = meet_instance_id(tp->instance_id());
4572       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4573     }
4574     default: ShouldNotReachHere();
4575     }
4576   }
4577 
4578   case AnyPtr: {                // Meeting two AnyPtrs
4579     // Found an AnyPtr type vs self-AryPtr type
4580     const TypePtr *tp = t->is_ptr();
4581     Offset offset = meet_offset(tp->offset());
4582     PTR ptr = meet_ptr(tp->ptr());
4583     const TypePtr* speculative = xmeet_speculative(tp);
4584     int depth = meet_inline_depth(tp->inline_depth());
4585     switch (tp->ptr()) {
4586     case TopPTR:
4587       return this;
4588     case BotPTR:
4589     case NotNull:
4590       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4591     case Null:
4592       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4593       // else fall through to AnyNull
4594     case AnyNull: {
4595       int instance_id = meet_instance_id(InstanceTop);
4596       return make(ptr, (ptr == Constant ? const_oop() : NULL),
4597                   _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
4598     }
4599     default: ShouldNotReachHere();
4600     }
4601   }
4602 
4603   case MetadataPtr:
4604   case KlassPtr:
4605   case RawPtr: return TypePtr::BOTTOM;
4606 
4607   case AryPtr: {                // Meeting 2 references?
4608     const TypeAryPtr *tap = t->is_aryptr();
4609     Offset off = meet_offset(tap->offset());
4610     Offset field_off = meet_field_offset(tap->field_offset());
4611     const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
4612     PTR ptr = meet_ptr(tap->ptr());
4613     int instance_id = meet_instance_id(tap->instance_id());
4614     const TypePtr* speculative = xmeet_speculative(tap);
4615     int depth = meet_inline_depth(tap->inline_depth());
4616     ciKlass* lazy_klass = NULL;
4617     if (tary->_elem->isa_int()) {
4618       // Integral array element types have irrelevant lattice relations.
4619       // It is the klass that determines array layout, not the element type.
4620       if (_klass == NULL)
4621         lazy_klass = tap->_klass;
4622       else if (tap->_klass == NULL || tap->_klass == _klass) {
4623         lazy_klass = _klass;
4624       } else {
4625         // Something like byte[int+] meets char[int+].
4626         // This must fall to bottom, not (int[-128..65535])[int+].
4627         instance_id = InstanceBot;
4628         tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
4629       }
4630     } else if (klass() != NULL && tap->klass() != NULL &&
4631                klass()->as_array_klass()->storage_properties().value() != tap->klass()->as_array_klass()->storage_properties().value()) {
4632       // Meeting value type arrays with conflicting storage properties
4633       if (tary->_elem->isa_valuetype()) {
4634         // Result is flattened
4635         off = Offset(elem()->isa_valuetype() ? offset() : tap->offset());
4636         field_off = elem()->isa_valuetype() ? field_offset() : tap->field_offset();
4637       } else if (tary->_elem->make_oopptr() != NULL && tary->_elem->make_oopptr()->isa_instptr() && below_centerline(ptr)) {
4638         // Result is non-flattened
4639         off = Offset(flattened_offset()).meet(Offset(tap->flattened_offset()));
4640         field_off = Offset::bottom;
4641       }
4642     } else // Non integral arrays.
4643       // Must fall to bottom if exact klasses in upper lattice
4644       // are not equal or super klass is exact.
4645       if ((above_centerline(ptr) || ptr == Constant) && klass() != tap->klass() &&
4646           // meet with top[] and bottom[] are processed further down:
4647           tap->_klass != NULL && this->_klass != NULL &&
4648           // both are exact and not equal:
4649           ((tap->_klass_is_exact && this->_klass_is_exact) ||
4650            // 'tap' is exact and super or unrelated:
4651            (tap->_klass_is_exact && !tap->klass()->is_subtype_of(klass())) ||
4652            // 'this' is exact and super or unrelated:
4653            (this->_klass_is_exact && !klass()->is_subtype_of(tap->klass())))) {
4654       if (above_centerline(ptr)) {
4655         tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
4656       }
4657       return make(NotNull, NULL, tary, lazy_klass, false, off, field_off, InstanceBot, speculative, depth);
4658     }
4659 
4660     bool xk = false;
4661     switch (tap->ptr()) {
4662     case AnyNull:
4663     case TopPTR:
4664       // Compute new klass on demand, do not use tap->_klass
4665       if (below_centerline(this->_ptr)) {
4666         xk = this->_klass_is_exact;
4667       } else {
4668         xk = (tap->_klass_is_exact | this->_klass_is_exact);
4669       }
4670       return make(ptr, const_oop(), tary, lazy_klass, xk, off, field_off, instance_id, speculative, depth);
4671     case Constant: {
4672       ciObject* o = const_oop();
4673       if( _ptr == Constant ) {
4674         if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) {
4675           xk = (klass() == tap->klass());
4676           ptr = NotNull;
4677           o = NULL;
4678           instance_id = InstanceBot;
4679         } else {
4680           xk = true;
4681         }
4682       } else if(above_centerline(_ptr)) {
4683         o = tap->const_oop();
4684         xk = true;
4685       } else {
4686         // Only precise for identical arrays
4687         xk = this->_klass_is_exact && (klass() == tap->klass());
4688       }
4689       return TypeAryPtr::make(ptr, o, tary, lazy_klass, xk, off, field_off, instance_id, speculative, depth);
4690     }
4691     case NotNull:
4692     case BotPTR:
4693       // Compute new klass on demand, do not use tap->_klass
4694       if (above_centerline(this->_ptr))
4695             xk = tap->_klass_is_exact;
4696       else  xk = (tap->_klass_is_exact & this->_klass_is_exact) &&
4697               (klass() == tap->klass()); // Only precise for identical arrays
4698       return TypeAryPtr::make(ptr, NULL, tary, lazy_klass, xk, off, field_off, instance_id, speculative, depth);
4699     default: ShouldNotReachHere();
4700     }
4701   }
4702 
4703   // All arrays inherit from Object class
4704   case InstPtr: {
4705     const TypeInstPtr *tp = t->is_instptr();
4706     Offset offset = meet_offset(tp->offset());
4707     PTR ptr = meet_ptr(tp->ptr());
4708     int instance_id = meet_instance_id(tp->instance_id());
4709     const TypePtr* speculative = xmeet_speculative(tp);
4710     int depth = meet_inline_depth(tp->inline_depth());
4711     switch (ptr) {
4712     case TopPTR:
4713     case AnyNull:                // Fall 'down' to dual of object klass
4714       // For instances when a subclass meets a superclass we fall
4715       // below the centerline when the superclass is exact. We need to
4716       // do the same here.
4717       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
4718         return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
4719       } else {
4720         // cannot subclass, so the meet has to fall badly below the centerline
4721         ptr = NotNull;
4722         instance_id = InstanceBot;
4723         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
4724       }
4725     case Constant:
4726     case NotNull:
4727     case BotPTR:                // Fall down to object klass
4728       // LCA is object_klass, but if we subclass from the top we can do better
4729       if (above_centerline(tp->ptr())) {
4730         // If 'tp'  is above the centerline and it is Object class
4731         // then we can subclass in the Java class hierarchy.
4732         // For instances when a subclass meets a superclass we fall
4733         // below the centerline when the superclass is exact. We need
4734         // to do the same here.
4735         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
4736           // that is, my array type is a subtype of 'tp' klass
4737           return make(ptr, (ptr == Constant ? const_oop() : NULL),
4738                       _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
4739         }
4740       }
4741       // The other case cannot happen, since t cannot be a subtype of an array.
4742       // The meet falls down to Object class below centerline.
4743       if( ptr == Constant )
4744          ptr = NotNull;
4745       instance_id = InstanceBot;
4746       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
4747     default: typerr(t);
4748     }
4749   }
4750 
4751   case ValueType: {
4752     // All value types inherit from Object
4753     PTR ptr = this->_ptr;
4754     if (ptr == Constant) {
4755       ptr = NotNull;
4756     }
4757     return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass());
4758   }
4759 
4760   }
4761   return this;                  // Lint noise
4762 }
4763 
4764 //------------------------------xdual------------------------------------------
4765 // Dual: compute field-by-field dual
4766 const Type *TypeAryPtr::xdual() const {
4767   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());
4768 }
4769 
4770 Type::Offset TypeAryPtr::meet_field_offset(const Type::Offset offset) const {
4771   return _field_offset.meet(offset);
4772 }
4773 
4774 //------------------------------dual_offset------------------------------------
4775 Type::Offset TypeAryPtr::dual_field_offset() const {
4776   return _field_offset.dual();
4777 }
4778 
4779 //----------------------interface_vs_oop---------------------------------------
4780 #ifdef ASSERT
4781 bool TypeAryPtr::interface_vs_oop(const Type *t) const {
4782   const TypeAryPtr* t_aryptr = t->isa_aryptr();
4783   if (t_aryptr) {
4784     return _ary->interface_vs_oop(t_aryptr->_ary);
4785   }
4786   return false;
4787 }
4788 #endif
4789 
4790 //------------------------------dump2------------------------------------------
4791 #ifndef PRODUCT
4792 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4793   _ary->dump2(d,depth,st);
4794   switch( _ptr ) {
4795   case Constant:
4796     const_oop()->print(st);
4797     break;
4798   case BotPTR:
4799     if (!WizardMode && !Verbose) {
4800       if( _klass_is_exact ) st->print(":exact");
4801       break;
4802     }
4803   case TopPTR:
4804   case AnyNull:
4805   case NotNull:
4806     st->print(":%s", ptr_msg[_ptr]);
4807     if( _klass_is_exact ) st->print(":exact");
4808     break;
4809   default:
4810     break;
4811   }
4812 
4813   if (elem()->isa_valuetype()) {
4814     st->print("(");
4815     _field_offset.dump2(st);
4816     st->print(")");
4817   }
4818   if (offset() != 0) {
4819     int header_size = objArrayOopDesc::header_size() * wordSize;
4820     if( _offset == Offset::top )       st->print("+undefined");
4821     else if( _offset == Offset::bottom )  st->print("+any");
4822     else if( offset() < header_size ) st->print("+%d", offset());
4823     else {
4824       BasicType basic_elem_type = elem()->basic_type();
4825       int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
4826       int elem_size = type2aelembytes(basic_elem_type);
4827       st->print("[%d]", (offset() - array_base)/elem_size);
4828     }
4829   }
4830   st->print(" *");
4831   if (_instance_id == InstanceTop)
4832     st->print(",iid=top");
4833   else if (_instance_id != InstanceBot)
4834     st->print(",iid=%d",_instance_id);
4835 
4836   dump_inline_depth(st);
4837   dump_speculative(st);
4838 }
4839 #endif
4840 
4841 bool TypeAryPtr::empty(void) const {
4842   if (_ary->empty())       return true;
4843   return TypeOopPtr::empty();
4844 }
4845 
4846 //------------------------------add_offset-------------------------------------
4847 const TypePtr *TypeAryPtr::add_offset(intptr_t offset) const {
4848   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);
4849 }
4850 
4851 const Type *TypeAryPtr::remove_speculative() const {
4852   if (_speculative == NULL) {
4853     return this;
4854   }
4855   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4856   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);
4857 }
4858 
4859 const TypePtr *TypeAryPtr::with_inline_depth(int depth) const {
4860   if (!UseInlineDepthForSpeculativeTypes) {
4861     return this;
4862   }
4863   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, depth, _is_autobox_cache);
4864 }
4865 
4866 const TypeAryPtr* TypeAryPtr::with_field_offset(int offset) const {
4867   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);
4868 }
4869 
4870 const TypePtr* TypeAryPtr::add_field_offset_and_offset(intptr_t offset) const {
4871   int adj = 0;
4872   if (offset != Type::OffsetBot && offset != Type::OffsetTop) {
4873     const Type* elemtype = elem();
4874     if (elemtype->isa_valuetype()) {
4875       if (_offset.get() != OffsetBot && _offset.get() != OffsetTop) {
4876         adj = _offset.get();
4877         offset += _offset.get();
4878       }
4879       uint header = arrayOopDesc::base_offset_in_bytes(T_OBJECT);
4880       if (_field_offset.get() != OffsetBot && _field_offset.get() != OffsetTop) {
4881         offset += _field_offset.get();
4882         if (_offset.get() == OffsetBot || _offset.get() == OffsetTop) {
4883           offset += header;
4884         }
4885       }
4886       if (offset >= (intptr_t)header || offset < 0) {
4887         // Try to get the field of the value type array element we are pointing to
4888         ciKlass* arytype_klass = klass();
4889         ciValueArrayKlass* vak = arytype_klass->as_value_array_klass();
4890         ciValueKlass* vk = vak->element_klass()->as_value_klass();
4891         int shift = vak->log2_element_size();
4892         int mask = (1 << shift) - 1;
4893         intptr_t field_offset = ((offset - header) & mask);
4894         ciField* field = vk->get_field_by_offset(field_offset + vk->first_field_offset(), false);
4895         if (field == NULL) {
4896           // This may happen with nested AddP(base, AddP(base, base, offset), longcon(16))
4897           return add_offset(offset);
4898         } else {
4899           return with_field_offset(field_offset)->add_offset(offset - field_offset - adj);
4900         }
4901       }
4902     }
4903   }
4904   return add_offset(offset - adj);
4905 }
4906 
4907 // Return offset incremented by field_offset for flattened value type arrays
4908 const int TypeAryPtr::flattened_offset() const {
4909   int offset = _offset.get();
4910   if (offset != Type::OffsetBot && offset != Type::OffsetTop &&
4911       _field_offset != Offset::bottom && _field_offset != Offset::top) {
4912     offset += _field_offset.get();
4913   }
4914   return offset;
4915 }
4916 
4917 const TypePtr *TypeAryPtr::with_instance_id(int instance_id) const {
4918   assert(is_known_instance(), "should be known");
4919   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth);
4920 }
4921 
4922 //=============================================================================
4923 
4924 
4925 //------------------------------hash-------------------------------------------
4926 // Type-specific hashing function.
4927 int TypeNarrowPtr::hash(void) const {
4928   return _ptrtype->hash() + 7;
4929 }
4930 
4931 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
4932   return _ptrtype->singleton();
4933 }
4934 
4935 bool TypeNarrowPtr::empty(void) const {
4936   return _ptrtype->empty();
4937 }
4938 
4939 intptr_t TypeNarrowPtr::get_con() const {
4940   return _ptrtype->get_con();
4941 }
4942 
4943 bool TypeNarrowPtr::eq( const Type *t ) const {
4944   const TypeNarrowPtr* tc = isa_same_narrowptr(t);
4945   if (tc != NULL) {
4946     if (_ptrtype->base() != tc->_ptrtype->base()) {
4947       return false;
4948     }
4949     return tc->_ptrtype->eq(_ptrtype);
4950   }
4951   return false;
4952 }
4953 
4954 const Type *TypeNarrowPtr::xdual() const {    // Compute dual right now.
4955   const TypePtr* odual = _ptrtype->dual()->is_ptr();
4956   return make_same_narrowptr(odual);
4957 }
4958 
4959 
4960 const Type *TypeNarrowPtr::filter_helper(const Type *kills, bool include_speculative) const {
4961   if (isa_same_narrowptr(kills)) {
4962     const Type* ft =_ptrtype->filter_helper(is_same_narrowptr(kills)->_ptrtype, include_speculative);
4963     if (ft->empty())
4964       return Type::TOP;           // Canonical empty value
4965     if (ft->isa_ptr()) {
4966       return make_hash_same_narrowptr(ft->isa_ptr());
4967     }
4968     return ft;
4969   } else if (kills->isa_ptr()) {
4970     const Type* ft = _ptrtype->join_helper(kills, include_speculative);
4971     if (ft->empty())
4972       return Type::TOP;           // Canonical empty value
4973     return ft;
4974   } else {
4975     return Type::TOP;
4976   }
4977 }
4978 
4979 //------------------------------xmeet------------------------------------------
4980 // Compute the MEET of two types.  It returns a new Type object.
4981 const Type *TypeNarrowPtr::xmeet( const Type *t ) const {
4982   // Perform a fast test for common case; meeting the same types together.
4983   if( this == t ) return this;  // Meeting same type-rep?
4984 
4985   if (t->base() == base()) {
4986     const Type* result = _ptrtype->xmeet(t->make_ptr());
4987     if (result->isa_ptr()) {
4988       return make_hash_same_narrowptr(result->is_ptr());
4989     }
4990     return result;
4991   }
4992 
4993   // Current "this->_base" is NarrowKlass or NarrowOop
4994   switch (t->base()) {          // switch on original type
4995 
4996   case Int:                     // Mixing ints & oops happens when javac
4997   case Long:                    // reuses local variables
4998   case FloatTop:
4999   case FloatCon:
5000   case FloatBot:
5001   case DoubleTop:
5002   case DoubleCon:
5003   case DoubleBot:
5004   case AnyPtr:
5005   case RawPtr:
5006   case OopPtr:
5007   case InstPtr:
5008   case AryPtr:
5009   case MetadataPtr:
5010   case KlassPtr:
5011   case NarrowOop:
5012   case NarrowKlass:
5013   case Bottom:                  // Ye Olde Default
5014     return Type::BOTTOM;
5015   case Top:
5016     return this;
5017 
5018   case ValueType:
5019     return t->xmeet(this);
5020 
5021   default:                      // All else is a mistake
5022     typerr(t);
5023 
5024   } // End of switch
5025 
5026   return this;
5027 }
5028 
5029 #ifndef PRODUCT
5030 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5031   _ptrtype->dump2(d, depth, st);
5032 }
5033 #endif
5034 
5035 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
5036 const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
5037 
5038 
5039 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
5040   return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();
5041 }
5042 
5043 const Type* TypeNarrowOop::remove_speculative() const {
5044   return make(_ptrtype->remove_speculative()->is_ptr());
5045 }
5046 
5047 const Type* TypeNarrowOop::cleanup_speculative() const {
5048   return make(_ptrtype->cleanup_speculative()->is_ptr());
5049 }
5050 
5051 #ifndef PRODUCT
5052 void TypeNarrowOop::dump2( Dict & d, uint depth, outputStream *st ) const {
5053   st->print("narrowoop: ");
5054   TypeNarrowPtr::dump2(d, depth, st);
5055 }
5056 #endif
5057 
5058 const TypeNarrowKlass *TypeNarrowKlass::NULL_PTR;
5059 
5060 const TypeNarrowKlass* TypeNarrowKlass::make(const TypePtr* type) {
5061   return (const TypeNarrowKlass*)(new TypeNarrowKlass(type))->hashcons();
5062 }
5063 
5064 #ifndef PRODUCT
5065 void TypeNarrowKlass::dump2( Dict & d, uint depth, outputStream *st ) const {
5066   st->print("narrowklass: ");
5067   TypeNarrowPtr::dump2(d, depth, st);
5068 }
5069 #endif
5070 
5071 
5072 //------------------------------eq---------------------------------------------
5073 // Structural equality check for Type representations
5074 bool TypeMetadataPtr::eq( const Type *t ) const {
5075   const TypeMetadataPtr *a = (const TypeMetadataPtr*)t;
5076   ciMetadata* one = metadata();
5077   ciMetadata* two = a->metadata();
5078   if (one == NULL || two == NULL) {
5079     return (one == two) && TypePtr::eq(t);
5080   } else {
5081     return one->equals(two) && TypePtr::eq(t);
5082   }
5083 }
5084 
5085 //------------------------------hash-------------------------------------------
5086 // Type-specific hashing function.
5087 int TypeMetadataPtr::hash(void) const {
5088   return
5089     (metadata() ? metadata()->hash() : 0) +
5090     TypePtr::hash();
5091 }
5092 
5093 //------------------------------singleton--------------------------------------
5094 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5095 // constants
5096 bool TypeMetadataPtr::singleton(void) const {
5097   // detune optimizer to not generate constant metadata + constant offset as a constant!
5098   // TopPTR, Null, AnyNull, Constant are all singletons
5099   return (offset() == 0) && !below_centerline(_ptr);
5100 }
5101 
5102 //------------------------------add_offset-------------------------------------
5103 const TypePtr *TypeMetadataPtr::add_offset( intptr_t offset ) const {
5104   return make( _ptr, _metadata, xadd_offset(offset));
5105 }
5106 
5107 //-----------------------------filter------------------------------------------
5108 // Do not allow interface-vs.-noninterface joins to collapse to top.
5109 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
5110   const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
5111   if (ft == NULL || ft->empty())
5112     return Type::TOP;           // Canonical empty value
5113   return ft;
5114 }
5115 
5116  //------------------------------get_con----------------------------------------
5117 intptr_t TypeMetadataPtr::get_con() const {
5118   assert( _ptr == Null || _ptr == Constant, "" );
5119   assert(offset() >= 0, "");
5120 
5121   if (offset() != 0) {
5122     // After being ported to the compiler interface, the compiler no longer
5123     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5124     // to a handle at compile time.  This handle is embedded in the generated
5125     // code and dereferenced at the time the nmethod is made.  Until that time,
5126     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5127     // have access to the addresses!).  This does not seem to currently happen,
5128     // but this assertion here is to help prevent its occurence.
5129     tty->print_cr("Found oop constant with non-zero offset");
5130     ShouldNotReachHere();
5131   }
5132 
5133   return (intptr_t)metadata()->constant_encoding();
5134 }
5135 
5136 //------------------------------cast_to_ptr_type-------------------------------
5137 const Type *TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
5138   if( ptr == _ptr ) return this;
5139   return make(ptr, metadata(), _offset);
5140 }
5141 
5142 //------------------------------meet-------------------------------------------
5143 // Compute the MEET of two types.  It returns a new Type object.
5144 const Type *TypeMetadataPtr::xmeet( const Type *t ) const {
5145   // Perform a fast test for common case; meeting the same types together.
5146   if( this == t ) return this;  // Meeting same type-rep?
5147 
5148   // Current "this->_base" is OopPtr
5149   switch (t->base()) {          // switch on original type
5150 
5151   case Int:                     // Mixing ints & oops happens when javac
5152   case Long:                    // reuses local variables
5153   case FloatTop:
5154   case FloatCon:
5155   case FloatBot:
5156   case DoubleTop:
5157   case DoubleCon:
5158   case DoubleBot:
5159   case NarrowOop:
5160   case NarrowKlass:
5161   case Bottom:                  // Ye Olde Default
5162     return Type::BOTTOM;
5163   case Top:
5164     return this;
5165 
5166   default:                      // All else is a mistake
5167     typerr(t);
5168 
5169   case AnyPtr: {
5170     // Found an AnyPtr type vs self-OopPtr type
5171     const TypePtr *tp = t->is_ptr();
5172     Offset offset = meet_offset(tp->offset());
5173     PTR ptr = meet_ptr(tp->ptr());
5174     switch (tp->ptr()) {
5175     case Null:
5176       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5177       // else fall through:
5178     case TopPTR:
5179     case AnyNull: {
5180       return make(ptr, _metadata, offset);
5181     }
5182     case BotPTR:
5183     case NotNull:
5184       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5185     default: typerr(t);
5186     }
5187   }
5188 
5189   case RawPtr:
5190   case KlassPtr:
5191   case OopPtr:
5192   case InstPtr:
5193   case AryPtr:
5194     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
5195 
5196   case MetadataPtr: {
5197     const TypeMetadataPtr *tp = t->is_metadataptr();
5198     Offset offset = meet_offset(tp->offset());
5199     PTR tptr = tp->ptr();
5200     PTR ptr = meet_ptr(tptr);
5201     ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
5202     if (tptr == TopPTR || _ptr == TopPTR ||
5203         metadata()->equals(tp->metadata())) {
5204       return make(ptr, md, offset);
5205     }
5206     // metadata is different
5207     if( ptr == Constant ) {  // Cannot be equal constants, so...
5208       if( tptr == Constant && _ptr != Constant)  return t;
5209       if( _ptr == Constant && tptr != Constant)  return this;
5210       ptr = NotNull;            // Fall down in lattice
5211     }
5212     return make(ptr, NULL, offset);
5213     break;
5214   }
5215   } // End of switch
5216   return this;                  // Return the double constant
5217 }
5218 
5219 
5220 //------------------------------xdual------------------------------------------
5221 // Dual of a pure metadata pointer.
5222 const Type *TypeMetadataPtr::xdual() const {
5223   return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
5224 }
5225 
5226 //------------------------------dump2------------------------------------------
5227 #ifndef PRODUCT
5228 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5229   st->print("metadataptr:%s", ptr_msg[_ptr]);
5230   if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata()));
5231   switch (offset()) {
5232   case OffsetTop: st->print("+top"); break;
5233   case OffsetBot: st->print("+any"); break;
5234   case         0: break;
5235   default:        st->print("+%d",offset()); break;
5236   }
5237 }
5238 #endif
5239 
5240 
5241 //=============================================================================
5242 // Convenience common pre-built type.
5243 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
5244 
5245 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, Offset offset):
5246   TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
5247 }
5248 
5249 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
5250   return make(Constant, m, Offset(0));
5251 }
5252 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
5253   return make(Constant, m, Offset(0));
5254 }
5255 
5256 //------------------------------make-------------------------------------------
5257 // Create a meta data constant
5258 const TypeMetadataPtr* TypeMetadataPtr::make(PTR ptr, ciMetadata* m, Offset offset) {
5259   assert(m == NULL || !m->is_klass(), "wrong type");
5260   return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
5261 }
5262 
5263 
5264 //=============================================================================
5265 // Convenience common pre-built types.
5266 
5267 // Not-null object klass or below
5268 const TypeKlassPtr *TypeKlassPtr::OBJECT;
5269 const TypeKlassPtr *TypeKlassPtr::OBJECT_OR_NULL;
5270 
5271 //------------------------------TypeKlassPtr-----------------------------------
5272 TypeKlassPtr::TypeKlassPtr( PTR ptr, ciKlass* klass, Offset offset )
5273   : TypePtr(KlassPtr, ptr, offset), _klass(klass), _klass_is_exact(ptr == Constant) {
5274 }
5275 
5276 //------------------------------make-------------------------------------------
5277 // ptr to klass 'k', if Constant, or possibly to a sub-klass if not a Constant
5278 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* k, Offset offset) {
5279   assert(k == NULL || k->is_instance_klass() || k->is_array_klass(), "Incorrect type of klass oop");
5280   return (TypeKlassPtr*)(new TypeKlassPtr(ptr, k, offset))->hashcons();
5281 }
5282 
5283 //------------------------------eq---------------------------------------------
5284 // Structural equality check for Type representations
5285 bool TypeKlassPtr::eq( const Type *t ) const {
5286   const TypeKlassPtr *p = t->is_klassptr();
5287   return klass() == p->klass() && TypePtr::eq(p);
5288 }
5289 
5290 //------------------------------hash-------------------------------------------
5291 // Type-specific hashing function.
5292 int TypeKlassPtr::hash(void) const {
5293   return java_add(klass() != NULL ? klass()->hash() : (jint)0, (jint)TypePtr::hash());
5294 }
5295 
5296 //------------------------------singleton--------------------------------------
5297 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5298 // constants
5299 bool TypeKlassPtr::singleton(void) const {
5300   // detune optimizer to not generate constant klass + constant offset as a constant!
5301   // TopPTR, Null, AnyNull, Constant are all singletons
5302   return (offset() == 0) && !below_centerline(_ptr);
5303 }
5304 
5305 // Do not allow interface-vs.-noninterface joins to collapse to top.
5306 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
5307   // logic here mirrors the one from TypeOopPtr::filter. See comments
5308   // there.
5309   const Type* ft = join_helper(kills, include_speculative);
5310   const TypeKlassPtr* ftkp = ft->isa_klassptr();
5311   const TypeKlassPtr* ktkp = kills->isa_klassptr();
5312 
5313   if (ft->empty()) {
5314     if (!empty() && ktkp != NULL && ktkp->is_loaded() && ktkp->klass()->is_interface())
5315       return kills;             // Uplift to interface
5316 
5317     return Type::TOP;           // Canonical empty value
5318   }
5319 
5320   // Interface klass type could be exact in opposite to interface type,
5321   // return it here instead of incorrect Constant ptr J/L/Object (6894807).
5322   if (ftkp != NULL && ktkp != NULL &&
5323       ftkp->is_loaded() &&  ftkp->klass()->is_interface() &&
5324       !ftkp->klass_is_exact() && // Keep exact interface klass
5325       ktkp->is_loaded() && !ktkp->klass()->is_interface()) {
5326     return ktkp->cast_to_ptr_type(ftkp->ptr());
5327   }
5328 
5329   return ft;
5330 }
5331 
5332 //----------------------compute_klass------------------------------------------
5333 // Compute the defining klass for this class
5334 ciKlass* TypeAryPtr::compute_klass(DEBUG_ONLY(bool verify)) const {
5335   // Compute _klass based on element type.
5336   ciKlass* k_ary = NULL;
5337   const TypeAryPtr *tary;
5338   const Type* el = elem();
5339   if (el->isa_narrowoop()) {
5340     el = el->make_ptr();
5341   }
5342 
5343   // Get element klass
5344   if (el->isa_instptr()) {
5345     // Compute object array klass from element klass
5346     bool null_free = el->is_valuetypeptr() && el->isa_instptr()->ptr() != TypePtr::TopPTR && !el->isa_instptr()->maybe_null();
5347     k_ary = ciArrayKlass::make(el->is_oopptr()->klass(), null_free);
5348   } else if (el->isa_valuetype()) {
5349     k_ary = ciArrayKlass::make(el->value_klass(), /* null_free */ true);
5350   } else if ((tary = el->isa_aryptr()) != NULL) {
5351     // Compute array klass from element klass
5352     ciKlass* k_elem = tary->klass();
5353     // If element type is something like bottom[], k_elem will be null.
5354     if (k_elem != NULL)
5355       k_ary = ciObjArrayKlass::make(k_elem);
5356   } else if ((el->base() == Type::Top) ||
5357              (el->base() == Type::Bottom)) {
5358     // element type of Bottom occurs from meet of basic type
5359     // and object; Top occurs when doing join on Bottom.
5360     // Leave k_ary at NULL.
5361   } else {
5362     // Cannot compute array klass directly from basic type,
5363     // since subtypes of TypeInt all have basic type T_INT.
5364 #ifdef ASSERT
5365     if (verify && el->isa_int()) {
5366       // Check simple cases when verifying klass.
5367       BasicType bt = T_ILLEGAL;
5368       if (el == TypeInt::BYTE) {
5369         bt = T_BYTE;
5370       } else if (el == TypeInt::SHORT) {
5371         bt = T_SHORT;
5372       } else if (el == TypeInt::CHAR) {
5373         bt = T_CHAR;
5374       } else if (el == TypeInt::INT) {
5375         bt = T_INT;
5376       } else {
5377         return _klass; // just return specified klass
5378       }
5379       return ciTypeArrayKlass::make(bt);
5380     }
5381 #endif
5382     assert(!el->isa_int(),
5383            "integral arrays must be pre-equipped with a class");
5384     // Compute array klass directly from basic type
5385     k_ary = ciTypeArrayKlass::make(el->basic_type());
5386   }
5387   return k_ary;
5388 }
5389 
5390 //------------------------------klass------------------------------------------
5391 // Return the defining klass for this class
5392 ciKlass* TypeAryPtr::klass() const {
5393   if( _klass ) return _klass;   // Return cached value, if possible
5394 
5395   // Oops, need to compute _klass and cache it
5396   ciKlass* k_ary = compute_klass();
5397 
5398   if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) {
5399     // The _klass field acts as a cache of the underlying
5400     // ciKlass for this array type.  In order to set the field,
5401     // we need to cast away const-ness.
5402     //
5403     // IMPORTANT NOTE: we *never* set the _klass field for the
5404     // type TypeAryPtr::OOPS.  This Type is shared between all
5405     // active compilations.  However, the ciKlass which represents
5406     // this Type is *not* shared between compilations, so caching
5407     // this value would result in fetching a dangling pointer.
5408     //
5409     // Recomputing the underlying ciKlass for each request is
5410     // a bit less efficient than caching, but calls to
5411     // TypeAryPtr::OOPS->klass() are not common enough to matter.
5412     ((TypeAryPtr*)this)->_klass = k_ary;
5413     if (UseCompressedOops && k_ary != NULL && k_ary->is_obj_array_klass() &&
5414         offset() != 0 && offset() != arrayOopDesc::length_offset_in_bytes()) {
5415       ((TypeAryPtr*)this)->_is_ptr_to_narrowoop = true;
5416     }
5417   }
5418   return k_ary;
5419 }
5420 
5421 
5422 //------------------------------add_offset-------------------------------------
5423 // Access internals of klass object
5424 const TypePtr *TypeKlassPtr::add_offset( intptr_t offset ) const {
5425   return make( _ptr, klass(), xadd_offset(offset) );
5426 }
5427 
5428 //------------------------------cast_to_ptr_type-------------------------------
5429 const Type *TypeKlassPtr::cast_to_ptr_type(PTR ptr) const {
5430   assert(_base == KlassPtr, "subclass must override cast_to_ptr_type");
5431   if( ptr == _ptr ) return this;
5432   return make(ptr, _klass, _offset);
5433 }
5434 
5435 
5436 //-----------------------------cast_to_exactness-------------------------------
5437 const Type *TypeKlassPtr::cast_to_exactness(bool klass_is_exact) const {
5438   if( klass_is_exact == _klass_is_exact ) return this;
5439   if (!UseExactTypes)  return this;
5440   return make(klass_is_exact ? Constant : NotNull, _klass, _offset);
5441 }
5442 
5443 
5444 //-----------------------------as_instance_type--------------------------------
5445 // Corresponding type for an instance of the given class.
5446 // It will be NotNull, and exact if and only if the klass type is exact.
5447 const TypeOopPtr* TypeKlassPtr::as_instance_type() const {
5448   ciKlass* k = klass();
5449   assert(k != NULL, "klass should not be NULL");
5450   bool    xk = klass_is_exact();
5451   //return TypeInstPtr::make(TypePtr::NotNull, k, xk, NULL, 0);
5452   const TypeOopPtr* toop = TypeOopPtr::make_from_klass_raw(k);
5453   guarantee(toop != NULL, "need type for given klass");
5454   toop = toop->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
5455   return toop->cast_to_exactness(xk)->is_oopptr();
5456 }
5457 
5458 
5459 //------------------------------xmeet------------------------------------------
5460 // Compute the MEET of two types, return a new Type object.
5461 const Type    *TypeKlassPtr::xmeet( const Type *t ) const {
5462   // Perform a fast test for common case; meeting the same types together.
5463   if( this == t ) return this;  // Meeting same type-rep?
5464 
5465   // Current "this->_base" is Pointer
5466   switch (t->base()) {          // switch on original type
5467 
5468   case Int:                     // Mixing ints & oops happens when javac
5469   case Long:                    // reuses local variables
5470   case FloatTop:
5471   case FloatCon:
5472   case FloatBot:
5473   case DoubleTop:
5474   case DoubleCon:
5475   case DoubleBot:
5476   case NarrowOop:
5477   case NarrowKlass:
5478   case Bottom:                  // Ye Olde Default
5479     return Type::BOTTOM;
5480   case Top:
5481     return this;
5482 
5483   default:                      // All else is a mistake
5484     typerr(t);
5485 
5486   case AnyPtr: {                // Meeting to AnyPtrs
5487     // Found an AnyPtr type vs self-KlassPtr type
5488     const TypePtr *tp = t->is_ptr();
5489     Offset offset = meet_offset(tp->offset());
5490     PTR ptr = meet_ptr(tp->ptr());
5491     switch (tp->ptr()) {
5492     case TopPTR:
5493       return this;
5494     case Null:
5495       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5496     case AnyNull:
5497       return make( ptr, klass(), offset );
5498     case BotPTR:
5499     case NotNull:
5500       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5501     default: typerr(t);
5502     }
5503   }
5504 
5505   case RawPtr:
5506   case MetadataPtr:
5507   case OopPtr:
5508   case AryPtr:                  // Meet with AryPtr
5509   case InstPtr:                 // Meet with InstPtr
5510     return TypePtr::BOTTOM;
5511 
5512   //
5513   //             A-top         }
5514   //           /   |   \       }  Tops
5515   //       B-top A-any C-top   }
5516   //          | /  |  \ |      }  Any-nulls
5517   //       B-any   |   C-any   }
5518   //          |    |    |
5519   //       B-con A-con C-con   } constants; not comparable across classes
5520   //          |    |    |
5521   //       B-not   |   C-not   }
5522   //          | \  |  / |      }  not-nulls
5523   //       B-bot A-not C-bot   }
5524   //           \   |   /       }  Bottoms
5525   //             A-bot         }
5526   //
5527 
5528   case KlassPtr: {  // Meet two KlassPtr types
5529     const TypeKlassPtr *tkls = t->is_klassptr();
5530     Offset  off  = meet_offset(tkls->offset());
5531     PTR  ptr     = meet_ptr(tkls->ptr());
5532 
5533     if (klass() == NULL || tkls->klass() == NULL) {
5534       ciKlass* k = NULL;
5535       if (ptr == Constant) {
5536         k = (klass() == NULL) ? tkls->klass() : klass();
5537       }
5538       return make(ptr, k, off);
5539     }
5540 
5541     // Check for easy case; klasses are equal (and perhaps not loaded!)
5542     // If we have constants, then we created oops so classes are loaded
5543     // and we can handle the constants further down.  This case handles
5544     // not-loaded classes
5545     if( ptr != Constant && tkls->klass()->equals(klass()) ) {
5546       return make( ptr, klass(), off );
5547     }
5548 
5549     // Classes require inspection in the Java klass hierarchy.  Must be loaded.
5550     ciKlass* tkls_klass = tkls->klass();
5551     ciKlass* this_klass = this->klass();
5552     assert( tkls_klass->is_loaded(), "This class should have been loaded.");
5553     assert( this_klass->is_loaded(), "This class should have been loaded.");
5554 
5555     // If 'this' type is above the centerline and is a superclass of the
5556     // other, we can treat 'this' as having the same type as the other.
5557     if ((above_centerline(this->ptr())) &&
5558         tkls_klass->is_subtype_of(this_klass)) {
5559       this_klass = tkls_klass;
5560     }
5561     // If 'tinst' type is above the centerline and is a superclass of the
5562     // other, we can treat 'tinst' as having the same type as the other.
5563     if ((above_centerline(tkls->ptr())) &&
5564         this_klass->is_subtype_of(tkls_klass)) {
5565       tkls_klass = this_klass;
5566     }
5567 
5568     // Check for classes now being equal
5569     if (tkls_klass->equals(this_klass)) {
5570       // If the klasses are equal, the constants may still differ.  Fall to
5571       // NotNull if they do (neither constant is NULL; that is a special case
5572       // handled elsewhere).
5573       if( ptr == Constant ) {
5574         if (this->_ptr == Constant && tkls->_ptr == Constant &&
5575             this->klass()->equals(tkls->klass()));
5576         else if (above_centerline(this->ptr()));
5577         else if (above_centerline(tkls->ptr()));
5578         else
5579           ptr = NotNull;
5580       }
5581       return make( ptr, this_klass, off );
5582     } // Else classes are not equal
5583 
5584     // Since klasses are different, we require the LCA in the Java
5585     // class hierarchy - which means we have to fall to at least NotNull.
5586     if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
5587       ptr = NotNull;
5588     // Now we find the LCA of Java classes
5589     ciKlass* k = this_klass->least_common_ancestor(tkls_klass);
5590     return   make( ptr, k, off );
5591   } // End of case KlassPtr
5592 
5593   } // End of switch
5594   return this;                  // Return the double constant
5595 }
5596 
5597 //------------------------------xdual------------------------------------------
5598 // Dual: compute field-by-field dual
5599 const Type    *TypeKlassPtr::xdual() const {
5600   return new TypeKlassPtr( dual_ptr(), klass(), dual_offset() );
5601 }
5602 
5603 //------------------------------get_con----------------------------------------
5604 intptr_t TypeKlassPtr::get_con() const {
5605   assert( _ptr == Null || _ptr == Constant, "" );
5606   assert(offset() >= 0, "");
5607 
5608   if (offset() != 0) {
5609     // After being ported to the compiler interface, the compiler no longer
5610     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5611     // to a handle at compile time.  This handle is embedded in the generated
5612     // code and dereferenced at the time the nmethod is made.  Until that time,
5613     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5614     // have access to the addresses!).  This does not seem to currently happen,
5615     // but this assertion here is to help prevent its occurence.
5616     tty->print_cr("Found oop constant with non-zero offset");
5617     ShouldNotReachHere();
5618   }
5619 
5620   return (intptr_t)klass()->constant_encoding();
5621 }
5622 //------------------------------dump2------------------------------------------
5623 // Dump Klass Type
5624 #ifndef PRODUCT
5625 void TypeKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5626   switch( _ptr ) {
5627   case Constant:
5628     st->print("precise ");
5629   case NotNull:
5630     {
5631       if (klass() != NULL) {
5632         const char* name = klass()->name()->as_utf8();
5633         st->print("klass %s: " INTPTR_FORMAT, name, p2i(klass()));
5634       } else {
5635         st->print("klass BOTTOM");
5636       }
5637     }
5638   case BotPTR:
5639     if( !WizardMode && !Verbose && !_klass_is_exact ) break;
5640   case TopPTR:
5641   case AnyNull:
5642     st->print(":%s", ptr_msg[_ptr]);
5643     if( _klass_is_exact ) st->print(":exact");
5644     break;
5645   default:
5646     break;
5647   }
5648 
5649   _offset.dump2(st);
5650 
5651   st->print(" *");
5652 }
5653 #endif
5654 
5655 
5656 
5657 //=============================================================================
5658 // Convenience common pre-built types.
5659 
5660 //------------------------------make-------------------------------------------
5661 const TypeFunc *TypeFunc::make(const TypeTuple *domain_sig, const TypeTuple* domain_cc,
5662                                const TypeTuple *range_sig, const TypeTuple *range_cc) {
5663   return (TypeFunc*)(new TypeFunc(domain_sig, domain_cc, range_sig, range_cc))->hashcons();
5664 }
5665 
5666 const TypeFunc *TypeFunc::make(const TypeTuple *domain, const TypeTuple *range) {
5667   return make(domain, domain, range, range);
5668 }
5669 
5670 //------------------------------make-------------------------------------------
5671 const TypeFunc *TypeFunc::make(ciMethod* method) {
5672   Compile* C = Compile::current();
5673   const TypeFunc* tf = C->last_tf(method); // check cache
5674   if (tf != NULL)  return tf;  // The hit rate here is almost 50%.
5675   // Value types are not passed/returned by reference, instead each field of
5676   // the value type is passed/returned as an argument. We maintain two views of
5677   // the argument/return list here: one based on the signature (with a value
5678   // type argument/return as a single slot), one based on the actual calling
5679   // convention (with a value type argument/return as a list of its fields).
5680   const TypeTuple* domain_sig = TypeTuple::make_domain(method, false);
5681   const TypeTuple* domain_cc = TypeTuple::make_domain(method, method->has_scalarized_args());
5682   const TypeTuple* range_sig = TypeTuple::make_range(method->signature(), false);
5683   const TypeTuple* range_cc = TypeTuple::make_range(method->signature(), ValueTypeReturnedAsFields);
5684   tf = TypeFunc::make(domain_sig, domain_cc, range_sig, range_cc);
5685   C->set_last_tf(method, tf);  // fill cache
5686   return tf;
5687 }
5688 
5689 //------------------------------meet-------------------------------------------
5690 // Compute the MEET of two types.  It returns a new Type object.
5691 const Type *TypeFunc::xmeet( const Type *t ) const {
5692   // Perform a fast test for common case; meeting the same types together.
5693   if( this == t ) return this;  // Meeting same type-rep?
5694 
5695   // Current "this->_base" is Func
5696   switch (t->base()) {          // switch on original type
5697 
5698   case Bottom:                  // Ye Olde Default
5699     return t;
5700 
5701   default:                      // All else is a mistake
5702     typerr(t);
5703 
5704   case Top:
5705     break;
5706   }
5707   return this;                  // Return the double constant
5708 }
5709 
5710 //------------------------------xdual------------------------------------------
5711 // Dual: compute field-by-field dual
5712 const Type *TypeFunc::xdual() const {
5713   return this;
5714 }
5715 
5716 //------------------------------eq---------------------------------------------
5717 // Structural equality check for Type representations
5718 bool TypeFunc::eq( const Type *t ) const {
5719   const TypeFunc *a = (const TypeFunc*)t;
5720   return _domain_sig == a->_domain_sig &&
5721     _domain_cc == a->_domain_cc &&
5722     _range_sig == a->_range_sig &&
5723     _range_cc == a->_range_cc;
5724 }
5725 
5726 //------------------------------hash-------------------------------------------
5727 // Type-specific hashing function.
5728 int TypeFunc::hash(void) const {
5729   return (intptr_t)_domain_sig + (intptr_t)_domain_cc + (intptr_t)_range_sig + (intptr_t)_range_cc;
5730 }
5731 
5732 //------------------------------dump2------------------------------------------
5733 // Dump Function Type
5734 #ifndef PRODUCT
5735 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
5736   if( _range_sig->cnt() <= Parms )
5737     st->print("void");
5738   else {
5739     uint i;
5740     for (i = Parms; i < _range_sig->cnt()-1; i++) {
5741       _range_sig->field_at(i)->dump2(d,depth,st);
5742       st->print("/");
5743     }
5744     _range_sig->field_at(i)->dump2(d,depth,st);
5745   }
5746   st->print(" ");
5747   st->print("( ");
5748   if( !depth || d[this] ) {     // Check for recursive dump
5749     st->print("...)");
5750     return;
5751   }
5752   d.Insert((void*)this,(void*)this);    // Stop recursion
5753   if (Parms < _domain_sig->cnt())
5754     _domain_sig->field_at(Parms)->dump2(d,depth-1,st);
5755   for (uint i = Parms+1; i < _domain_sig->cnt(); i++) {
5756     st->print(", ");
5757     _domain_sig->field_at(i)->dump2(d,depth-1,st);
5758   }
5759   st->print(" )");
5760 }
5761 #endif
5762 
5763 //------------------------------singleton--------------------------------------
5764 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5765 // constants (Ldi nodes).  Singletons are integer, float or double constants
5766 // or a single symbol.
5767 bool TypeFunc::singleton(void) const {
5768   return false;                 // Never a singleton
5769 }
5770 
5771 bool TypeFunc::empty(void) const {
5772   return false;                 // Never empty
5773 }
5774 
5775 
5776 BasicType TypeFunc::return_type() const{
5777   if (range_sig()->cnt() == TypeFunc::Parms) {
5778     return T_VOID;
5779   }
5780   return range_sig()->field_at(TypeFunc::Parms)->basic_type();
5781 }