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