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