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