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