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