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