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 // Can a value type instance of this type be returned as multiple
1936 // returned values?
1937 static bool vt_can_be_returned_as_fields(ciValueKlass* vk) {
1938   if (vk == ciEnv::current()->___Value_klass()) {
1939     return false;
1940   }
1941 
1942   ResourceMark rm;
1943   uint args = vk->value_arg_slots() + 1 /* return vk as well */;
1944 
1945   BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, args);
1946   VMRegPair* regs = NEW_RESOURCE_ARRAY(VMRegPair, args);
1947 
1948   sig_bt[0] = T_METADATA;
1949   for (uint i = 0, j = 1; i < (uint)vk->nof_nonstatic_fields(); i++) {
1950     BasicType bt = vk->nonstatic_field_at(i)->layout_type();
1951     assert(i+j < args, "out of bounds access");
1952     sig_bt[i+j] = bt;
1953     if (bt == T_LONG || bt == T_DOUBLE) {
1954       j++;
1955       assert(i+j < args, "out of bounds access");
1956       sig_bt[i+j] = T_VOID;
1957     }
1958   }
1959 
1960   if (SharedRuntime::java_return_convention(sig_bt, regs, args) <= 0) {
1961     return false;
1962   }
1963 
1964   return true;
1965 }
1966 
1967 
1968 //------------------------------make-------------------------------------------
1969 // Make a TypeTuple from the range of a method signature
1970 const TypeTuple *TypeTuple::make_range(ciSignature* sig, bool ret_vt_fields) {
1971   ciType* return_type = sig->return_type();
1972   uint arg_cnt = 0;
1973   if (ret_vt_fields) {
1974     ret_vt_fields = return_type->is_valuetype() && vt_can_be_returned_as_fields((ciValueKlass*)return_type);
1975   }
1976   if (ret_vt_fields) {
1977     ciValueKlass* vk = (ciValueKlass*)return_type;
1978     arg_cnt = vk->value_arg_slots()+1;
1979   } else {
1980     arg_cnt = return_type->size();
1981   }
1982 
1983   const Type **field_array = fields(arg_cnt);
1984   switch (return_type->basic_type()) {
1985   case T_LONG:
1986     field_array[TypeFunc::Parms]   = TypeLong::LONG;
1987     field_array[TypeFunc::Parms+1] = Type::HALF;
1988     break;
1989   case T_DOUBLE:
1990     field_array[TypeFunc::Parms]   = Type::DOUBLE;
1991     field_array[TypeFunc::Parms+1] = Type::HALF;
1992     break;
1993   case T_OBJECT:
1994   case T_ARRAY:
1995   case T_BOOLEAN:
1996   case T_CHAR:
1997   case T_FLOAT:
1998   case T_BYTE:
1999   case T_SHORT:
2000   case T_INT:
2001     field_array[TypeFunc::Parms] = get_const_type(return_type);
2002     break;
2003   case T_VALUETYPE:
2004     if (ret_vt_fields) {
2005       ciValueKlass* vk = (ciValueKlass*)return_type;
2006       uint pos = TypeFunc::Parms;
2007       field_array[pos] = TypeKlassPtr::make(vk);
2008       pos++;
2009       collect_value_fields(vk, field_array, pos);
2010     } else {
2011       field_array[TypeFunc::Parms] = get_const_type(return_type);
2012     }
2013     break;
2014   case T_VOID:
2015     break;
2016   default:
2017     ShouldNotReachHere();
2018   }
2019   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2020 }
2021 
2022 // Make a TypeTuple from the domain of a method signature
2023 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig, bool vt_fields_as_args) {
2024   uint arg_cnt = sig->size();
2025 
2026   int vt_extra = 0;
2027   if (vt_fields_as_args) {
2028     for (int i = 0; i < sig->count(); i++) {
2029       ciType* type = sig->type_at(i);
2030       if (type->basic_type() == T_VALUETYPE && type != ciEnv::current()->___Value_klass()) {
2031         assert(type->is_valuetype(), "inconsistent type");
2032         ciValueKlass* vk = (ciValueKlass*)type;
2033         vt_extra += vk->value_arg_slots()-1;
2034       }
2035     }
2036     assert(((int)arg_cnt) + vt_extra >= 0, "negative number of actual arguments?");
2037   }
2038 
2039   uint pos = TypeFunc::Parms;
2040   const Type **field_array;
2041   if (recv != NULL) {
2042     arg_cnt++;
2043     bool vt_fields_for_recv = vt_fields_as_args && recv->is_valuetype() &&
2044       recv != ciEnv::current()->___Value_klass();
2045     if (vt_fields_for_recv) {
2046       ciValueKlass* vk = (ciValueKlass*)recv;
2047       vt_extra += vk->value_arg_slots()-1;
2048     }
2049     field_array = fields(arg_cnt + vt_extra);
2050     // Use get_const_type here because it respects UseUniqueSubclasses:
2051     if (vt_fields_for_recv) {
2052       ciValueKlass* vk = (ciValueKlass*)recv;
2053       collect_value_fields(vk, field_array, pos);
2054     } else {
2055       field_array[pos++] = get_const_type(recv)->join_speculative(TypePtr::NOTNULL);
2056     }
2057   } else {
2058     field_array = fields(arg_cnt + vt_extra);
2059   }
2060 
2061   int i = 0;
2062   while (pos < TypeFunc::Parms + arg_cnt + vt_extra) {
2063     ciType* type = sig->type_at(i);
2064 
2065     switch (type->basic_type()) {
2066     case T_LONG:
2067       field_array[pos++] = TypeLong::LONG;
2068       field_array[pos++] = Type::HALF;
2069       break;
2070     case T_DOUBLE:
2071       field_array[pos++] = Type::DOUBLE;
2072       field_array[pos++] = Type::HALF;
2073       break;
2074     case T_OBJECT:
2075     case T_ARRAY:
2076     case T_FLOAT:
2077     case T_INT:
2078       field_array[pos++] = get_const_type(type);
2079       break;
2080     case T_BOOLEAN:
2081     case T_CHAR:
2082     case T_BYTE:
2083     case T_SHORT:
2084       field_array[pos++] = TypeInt::INT;
2085       break;
2086     case T_VALUETYPE: {
2087       assert(type->is_valuetype(), "inconsistent type");
2088       if (vt_fields_as_args && type != ciEnv::current()->___Value_klass()) {
2089         ciValueKlass* vk = (ciValueKlass*)type;
2090         collect_value_fields(vk, field_array, pos);
2091       } else {
2092         field_array[pos++] = get_const_type(type);
2093       }
2094       break;
2095     }
2096     default:
2097       ShouldNotReachHere();
2098     }
2099     i++;
2100   }
2101   assert(pos == TypeFunc::Parms + arg_cnt + vt_extra, "wrong number of arguments");
2102 
2103   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt + vt_extra, field_array))->hashcons();
2104 }
2105 
2106 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2107   return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2108 }
2109 
2110 //------------------------------fields-----------------------------------------
2111 // Subroutine call type with space allocated for argument types
2112 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
2113 const Type **TypeTuple::fields( uint arg_cnt ) {
2114   const Type **flds = (const Type **)(Compile::current()->type_arena()->Amalloc_4((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
2115   flds[TypeFunc::Control  ] = Type::CONTROL;
2116   flds[TypeFunc::I_O      ] = Type::ABIO;
2117   flds[TypeFunc::Memory   ] = Type::MEMORY;
2118   flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
2119   flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
2120 
2121   return flds;
2122 }
2123 
2124 //------------------------------meet-------------------------------------------
2125 // Compute the MEET of two types.  It returns a new Type object.
2126 const Type *TypeTuple::xmeet( const Type *t ) const {
2127   // Perform a fast test for common case; meeting the same types together.
2128   if( this == t ) return this;  // Meeting same type-rep?
2129 
2130   // Current "this->_base" is Tuple
2131   switch (t->base()) {          // switch on original type
2132 
2133   case Bottom:                  // Ye Olde Default
2134     return t;
2135 
2136   default:                      // All else is a mistake
2137     typerr(t);
2138 
2139   case Tuple: {                 // Meeting 2 signatures?
2140     const TypeTuple *x = t->is_tuple();
2141     assert( _cnt == x->_cnt, "" );
2142     const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) ));
2143     for( uint i=0; i<_cnt; i++ )
2144       fields[i] = field_at(i)->xmeet( x->field_at(i) );
2145     return TypeTuple::make(_cnt,fields);
2146   }
2147   case Top:
2148     break;
2149   }
2150   return this;                  // Return the double constant
2151 }
2152 
2153 //------------------------------xdual------------------------------------------
2154 // Dual: compute field-by-field dual
2155 const Type *TypeTuple::xdual() const {
2156   const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) ));
2157   for( uint i=0; i<_cnt; i++ )
2158     fields[i] = _fields[i]->dual();
2159   return new TypeTuple(_cnt,fields);
2160 }
2161 
2162 //------------------------------eq---------------------------------------------
2163 // Structural equality check for Type representations
2164 bool TypeTuple::eq( const Type *t ) const {
2165   const TypeTuple *s = (const TypeTuple *)t;
2166   if (_cnt != s->_cnt)  return false;  // Unequal field counts
2167   for (uint i = 0; i < _cnt; i++)
2168     if (field_at(i) != s->field_at(i)) // POINTER COMPARE!  NO RECURSION!
2169       return false;             // Missed
2170   return true;
2171 }
2172 
2173 //------------------------------hash-------------------------------------------
2174 // Type-specific hashing function.
2175 int TypeTuple::hash(void) const {
2176   intptr_t sum = _cnt;
2177   for( uint i=0; i<_cnt; i++ )
2178     sum += (intptr_t)_fields[i];     // Hash on pointers directly
2179   return sum;
2180 }
2181 
2182 //------------------------------dump2------------------------------------------
2183 // Dump signature Type
2184 #ifndef PRODUCT
2185 void TypeTuple::dump2( Dict &d, uint depth, outputStream *st ) const {
2186   st->print("{");
2187   if( !depth || d[this] ) {     // Check for recursive print
2188     st->print("...}");
2189     return;
2190   }
2191   d.Insert((void*)this, (void*)this);   // Stop recursion
2192   if( _cnt ) {
2193     uint i;
2194     for( i=0; i<_cnt-1; i++ ) {
2195       st->print("%d:", i);
2196       _fields[i]->dump2(d, depth-1, st);
2197       st->print(", ");
2198     }
2199     st->print("%d:", i);
2200     _fields[i]->dump2(d, depth-1, st);
2201   }
2202   st->print("}");
2203 }
2204 #endif
2205 
2206 //------------------------------singleton--------------------------------------
2207 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2208 // constants (Ldi nodes).  Singletons are integer, float or double constants
2209 // or a single symbol.
2210 bool TypeTuple::singleton(void) const {
2211   return false;                 // Never a singleton
2212 }
2213 
2214 bool TypeTuple::empty(void) const {
2215   for( uint i=0; i<_cnt; i++ ) {
2216     if (_fields[i]->empty())  return true;
2217   }
2218   return false;
2219 }
2220 
2221 //=============================================================================
2222 // Convenience common pre-built types.
2223 
2224 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2225   // Certain normalizations keep us sane when comparing types.
2226   // We do not want arrayOop variables to differ only by the wideness
2227   // of their index types.  Pick minimum wideness, since that is the
2228   // forced wideness of small ranges anyway.
2229   if (size->_widen != Type::WidenMin)
2230     return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2231   else
2232     return size;
2233 }
2234 
2235 //------------------------------make-------------------------------------------
2236 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable) {
2237   if (UseCompressedOops && elem->isa_oopptr()) {
2238     elem = elem->make_narrowoop();
2239   }
2240   size = normalize_array_size(size);
2241   return (TypeAry*)(new TypeAry(elem,size,stable))->hashcons();
2242 }
2243 
2244 //------------------------------meet-------------------------------------------
2245 // Compute the MEET of two types.  It returns a new Type object.
2246 const Type *TypeAry::xmeet( const Type *t ) const {
2247   // Perform a fast test for common case; meeting the same types together.
2248   if( this == t ) return this;  // Meeting same type-rep?
2249 
2250   // Current "this->_base" is Ary
2251   switch (t->base()) {          // switch on original type
2252 
2253   case Bottom:                  // Ye Olde Default
2254     return t;
2255 
2256   default:                      // All else is a mistake
2257     typerr(t);
2258 
2259   case Array: {                 // Meeting 2 arrays?
2260     const TypeAry *a = t->is_ary();
2261     return TypeAry::make(_elem->meet_speculative(a->_elem),
2262                          _size->xmeet(a->_size)->is_int(),
2263                          _stable & a->_stable);
2264   }
2265   case Top:
2266     break;
2267   }
2268   return this;                  // Return the double constant
2269 }
2270 
2271 //------------------------------xdual------------------------------------------
2272 // Dual: compute field-by-field dual
2273 const Type *TypeAry::xdual() const {
2274   const TypeInt* size_dual = _size->dual()->is_int();
2275   size_dual = normalize_array_size(size_dual);
2276   return new TypeAry(_elem->dual(), size_dual, !_stable);
2277 }
2278 
2279 //------------------------------eq---------------------------------------------
2280 // Structural equality check for Type representations
2281 bool TypeAry::eq( const Type *t ) const {
2282   const TypeAry *a = (const TypeAry*)t;
2283   return _elem == a->_elem &&
2284     _stable == a->_stable &&
2285     _size == a->_size;
2286 }
2287 
2288 //------------------------------hash-------------------------------------------
2289 // Type-specific hashing function.
2290 int TypeAry::hash(void) const {
2291   return (intptr_t)_elem + (intptr_t)_size + (_stable ? 43 : 0);
2292 }
2293 
2294 /**
2295  * Return same type without a speculative part in the element
2296  */
2297 const Type* TypeAry::remove_speculative() const {
2298   return make(_elem->remove_speculative(), _size, _stable);
2299 }
2300 
2301 /**
2302  * Return same type with cleaned up speculative part of element
2303  */
2304 const Type* TypeAry::cleanup_speculative() const {
2305   return make(_elem->cleanup_speculative(), _size, _stable);
2306 }
2307 
2308 /**
2309  * Return same type but with a different inline depth (used for speculation)
2310  *
2311  * @param depth  depth to meet with
2312  */
2313 const TypePtr* TypePtr::with_inline_depth(int depth) const {
2314   if (!UseInlineDepthForSpeculativeTypes) {
2315     return this;
2316   }
2317   return make(AnyPtr, _ptr, _offset, _speculative, depth);
2318 }
2319 
2320 //----------------------interface_vs_oop---------------------------------------
2321 #ifdef ASSERT
2322 bool TypeAry::interface_vs_oop(const Type *t) const {
2323   const TypeAry* t_ary = t->is_ary();
2324   if (t_ary) {
2325     const TypePtr* this_ptr = _elem->make_ptr(); // In case we have narrow_oops
2326     const TypePtr*    t_ptr = t_ary->_elem->make_ptr();
2327     if(this_ptr != NULL && t_ptr != NULL) {
2328       return this_ptr->interface_vs_oop(t_ptr);
2329     }
2330   }
2331   return false;
2332 }
2333 #endif
2334 
2335 //------------------------------dump2------------------------------------------
2336 #ifndef PRODUCT
2337 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2338   if (_stable)  st->print("stable:");
2339   _elem->dump2(d, depth, st);
2340   st->print("[");
2341   _size->dump2(d, depth, st);
2342   st->print("]");
2343 }
2344 #endif
2345 
2346 //------------------------------singleton--------------------------------------
2347 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2348 // constants (Ldi nodes).  Singletons are integer, float or double constants
2349 // or a single symbol.
2350 bool TypeAry::singleton(void) const {
2351   return false;                 // Never a singleton
2352 }
2353 
2354 bool TypeAry::empty(void) const {
2355   return _elem->empty() || _size->empty();
2356 }
2357 
2358 //--------------------------ary_must_be_exact----------------------------------
2359 bool TypeAry::ary_must_be_exact() const {
2360   if (!UseExactTypes)       return false;
2361   // This logic looks at the element type of an array, and returns true
2362   // if the element type is either a primitive or a final instance class.
2363   // In such cases, an array built on this ary must have no subclasses.
2364   if (_elem == BOTTOM)      return false;  // general array not exact
2365   if (_elem == TOP   )      return false;  // inverted general array not exact
2366   const TypeOopPtr*  toop = NULL;
2367   if (UseCompressedOops && _elem->isa_narrowoop()) {
2368     toop = _elem->make_ptr()->isa_oopptr();
2369   } else {
2370     toop = _elem->isa_oopptr();
2371   }
2372   if (!toop)                return true;   // a primitive type, like int
2373   ciKlass* tklass = toop->klass();
2374   if (tklass == NULL)       return false;  // unloaded class
2375   if (!tklass->is_loaded()) return false;  // unloaded class
2376   const TypeInstPtr* tinst;
2377   if (_elem->isa_narrowoop())
2378     tinst = _elem->make_ptr()->isa_instptr();
2379   else
2380     tinst = _elem->isa_instptr();
2381   if (tinst)
2382     return tklass->as_instance_klass()->is_final();
2383   const TypeAryPtr*  tap;
2384   if (_elem->isa_narrowoop())
2385     tap = _elem->make_ptr()->isa_aryptr();
2386   else
2387     tap = _elem->isa_aryptr();
2388   if (tap)
2389     return tap->ary()->ary_must_be_exact();
2390   return false;
2391 }
2392 
2393 //==============================TypeValueType=======================================
2394 
2395 //------------------------------make-------------------------------------------
2396 const TypeValueType* TypeValueType::make(ciValueKlass* vk) {
2397   //assert(vk != ciEnv::current()->___Value_klass(), "sanity");
2398   return (TypeValueType*)(new TypeValueType(vk))->hashcons();
2399 }
2400 
2401 //------------------------------meet-------------------------------------------
2402 // Compute the MEET of two types.  It returns a new Type object.
2403 const Type* TypeValueType::xmeet(const Type* t) const {
2404   // Perform a fast test for common case; meeting the same types together.
2405   if(this == t) return this;  // Meeting same type-rep?
2406 
2407   // Current "this->_base" is ValueType
2408   switch (t->base()) {          // switch on original type
2409 
2410   case Top:
2411     break;
2412 
2413   case Bottom:
2414     return t;
2415 
2416   default:                      // All else is a mistake
2417     typerr(t);
2418 
2419   }
2420   return this;
2421 }
2422 
2423 //------------------------------xdual------------------------------------------
2424 const Type* TypeValueType::xdual() const {
2425   // FIXME
2426   return new TypeValueType(_vk);
2427 }
2428 
2429 //------------------------------eq---------------------------------------------
2430 // Structural equality check for Type representations
2431 bool TypeValueType::eq(const Type* t) const {
2432   const TypeValueType* vt = t->is_valuetype();
2433   return (_vk == vt->value_klass());
2434 }
2435 
2436 //------------------------------hash-------------------------------------------
2437 // Type-specific hashing function.
2438 int TypeValueType::hash(void) const {
2439   return (intptr_t)_vk;
2440 }
2441 
2442 //------------------------------singleton--------------------------------------
2443 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple constants.
2444 bool TypeValueType::singleton(void) const {
2445   // FIXME
2446   return false;
2447 }
2448 
2449 //------------------------------empty------------------------------------------
2450 // TRUE if Type is a type with no values, FALSE otherwise.
2451 bool TypeValueType::empty(void) const {
2452   // FIXME
2453   return false;
2454 }
2455 
2456 //------------------------------dump2------------------------------------------
2457 #ifndef PRODUCT
2458 void TypeValueType::dump2(Dict &d, uint depth, outputStream* st) const {
2459   st->print("valuetype[%d]:{", _vk->field_count());
2460   st->print("%s", _vk->field_count() != 0 ? _vk->field_type_by_index(0)->name() : "empty");
2461   for (int i = 1; i < _vk->field_count(); ++i) {
2462     st->print(", %s", _vk->field_type_by_index(i)->name());
2463   }
2464   st->print("}");
2465 }
2466 #endif
2467 
2468 //==============================TypeVect=======================================
2469 // Convenience common pre-built types.
2470 const TypeVect *TypeVect::VECTS = NULL; //  32-bit vectors
2471 const TypeVect *TypeVect::VECTD = NULL; //  64-bit vectors
2472 const TypeVect *TypeVect::VECTX = NULL; // 128-bit vectors
2473 const TypeVect *TypeVect::VECTY = NULL; // 256-bit vectors
2474 const TypeVect *TypeVect::VECTZ = NULL; // 512-bit vectors
2475 
2476 //------------------------------make-------------------------------------------
2477 const TypeVect* TypeVect::make(const Type *elem, uint length) {
2478   BasicType elem_bt = elem->array_element_basic_type();
2479   assert(is_java_primitive(elem_bt), "only primitive types in vector");
2480   assert(length > 1 && is_power_of_2(length), "vector length is power of 2");
2481   assert(Matcher::vector_size_supported(elem_bt, length), "length in range");
2482   int size = length * type2aelembytes(elem_bt);
2483   switch (Matcher::vector_ideal_reg(size)) {
2484   case Op_VecS:
2485     return (TypeVect*)(new TypeVectS(elem, length))->hashcons();
2486   case Op_RegL:
2487   case Op_VecD:
2488   case Op_RegD:
2489     return (TypeVect*)(new TypeVectD(elem, length))->hashcons();
2490   case Op_VecX:
2491     return (TypeVect*)(new TypeVectX(elem, length))->hashcons();
2492   case Op_VecY:
2493     return (TypeVect*)(new TypeVectY(elem, length))->hashcons();
2494   case Op_VecZ:
2495     return (TypeVect*)(new TypeVectZ(elem, length))->hashcons();
2496   }
2497  ShouldNotReachHere();
2498   return NULL;
2499 }
2500 
2501 //------------------------------meet-------------------------------------------
2502 // Compute the MEET of two types.  It returns a new Type object.
2503 const Type *TypeVect::xmeet( const Type *t ) const {
2504   // Perform a fast test for common case; meeting the same types together.
2505   if( this == t ) return this;  // Meeting same type-rep?
2506 
2507   // Current "this->_base" is Vector
2508   switch (t->base()) {          // switch on original type
2509 
2510   case Bottom:                  // Ye Olde Default
2511     return t;
2512 
2513   default:                      // All else is a mistake
2514     typerr(t);
2515 
2516   case VectorS:
2517   case VectorD:
2518   case VectorX:
2519   case VectorY:
2520   case VectorZ: {                // Meeting 2 vectors?
2521     const TypeVect* v = t->is_vect();
2522     assert(  base() == v->base(), "");
2523     assert(length() == v->length(), "");
2524     assert(element_basic_type() == v->element_basic_type(), "");
2525     return TypeVect::make(_elem->xmeet(v->_elem), _length);
2526   }
2527   case Top:
2528     break;
2529   }
2530   return this;
2531 }
2532 
2533 //------------------------------xdual------------------------------------------
2534 // Dual: compute field-by-field dual
2535 const Type *TypeVect::xdual() const {
2536   return new TypeVect(base(), _elem->dual(), _length);
2537 }
2538 
2539 //------------------------------eq---------------------------------------------
2540 // Structural equality check for Type representations
2541 bool TypeVect::eq(const Type *t) const {
2542   const TypeVect *v = t->is_vect();
2543   return (_elem == v->_elem) && (_length == v->_length);
2544 }
2545 
2546 //------------------------------hash-------------------------------------------
2547 // Type-specific hashing function.
2548 int TypeVect::hash(void) const {
2549   return (intptr_t)_elem + (intptr_t)_length;
2550 }
2551 
2552 //------------------------------singleton--------------------------------------
2553 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2554 // constants (Ldi nodes).  Vector is singleton if all elements are the same
2555 // constant value (when vector is created with Replicate code).
2556 bool TypeVect::singleton(void) const {
2557 // There is no Con node for vectors yet.
2558 //  return _elem->singleton();
2559   return false;
2560 }
2561 
2562 bool TypeVect::empty(void) const {
2563   return _elem->empty();
2564 }
2565 
2566 //------------------------------dump2------------------------------------------
2567 #ifndef PRODUCT
2568 void TypeVect::dump2(Dict &d, uint depth, outputStream *st) const {
2569   switch (base()) {
2570   case VectorS:
2571     st->print("vectors["); break;
2572   case VectorD:
2573     st->print("vectord["); break;
2574   case VectorX:
2575     st->print("vectorx["); break;
2576   case VectorY:
2577     st->print("vectory["); break;
2578   case VectorZ:
2579     st->print("vectorz["); break;
2580   default:
2581     ShouldNotReachHere();
2582   }
2583   st->print("%d]:{", _length);
2584   _elem->dump2(d, depth, st);
2585   st->print("}");
2586 }
2587 #endif
2588 
2589 
2590 //=============================================================================
2591 // Convenience common pre-built types.
2592 const TypePtr *TypePtr::NULL_PTR;
2593 const TypePtr *TypePtr::NOTNULL;
2594 const TypePtr *TypePtr::BOTTOM;
2595 
2596 //------------------------------meet-------------------------------------------
2597 // Meet over the PTR enum
2598 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2599   //              TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,
2600   { /* Top     */ TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,},
2601   { /* AnyNull */ AnyNull,   AnyNull,   Constant, BotPTR, NotNull, BotPTR,},
2602   { /* Constant*/ Constant,  Constant,  Constant, BotPTR, NotNull, BotPTR,},
2603   { /* Null    */ Null,      BotPTR,    BotPTR,   Null,   BotPTR,  BotPTR,},
2604   { /* NotNull */ NotNull,   NotNull,   NotNull,  BotPTR, NotNull, BotPTR,},
2605   { /* BotPTR  */ BotPTR,    BotPTR,    BotPTR,   BotPTR, BotPTR,  BotPTR,}
2606 };
2607 
2608 //------------------------------make-------------------------------------------
2609 const TypePtr* TypePtr::make(TYPES t, enum PTR ptr, Offset offset, const TypePtr* speculative, int inline_depth) {
2610   return (TypePtr*)(new TypePtr(t,ptr,offset, speculative, inline_depth))->hashcons();
2611 }
2612 
2613 //------------------------------cast_to_ptr_type-------------------------------
2614 const Type *TypePtr::cast_to_ptr_type(PTR ptr) const {
2615   assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2616   if( ptr == _ptr ) return this;
2617   return make(_base, ptr, _offset, _speculative, _inline_depth);
2618 }
2619 
2620 //------------------------------get_con----------------------------------------
2621 intptr_t TypePtr::get_con() const {
2622   assert( _ptr == Null, "" );
2623   return offset();
2624 }
2625 
2626 //------------------------------meet-------------------------------------------
2627 // Compute the MEET of two types.  It returns a new Type object.
2628 const Type *TypePtr::xmeet(const Type *t) const {
2629   const Type* res = xmeet_helper(t);
2630   if (res->isa_ptr() == NULL) {
2631     return res;
2632   }
2633 
2634   const TypePtr* res_ptr = res->is_ptr();
2635   if (res_ptr->speculative() != NULL) {
2636     // type->speculative() == NULL means that speculation is no better
2637     // than type, i.e. type->speculative() == type. So there are 2
2638     // ways to represent the fact that we have no useful speculative
2639     // data and we should use a single one to be able to test for
2640     // equality between types. Check whether type->speculative() ==
2641     // type and set speculative to NULL if it is the case.
2642     if (res_ptr->remove_speculative() == res_ptr->speculative()) {
2643       return res_ptr->remove_speculative();
2644     }
2645   }
2646 
2647   return res;
2648 }
2649 
2650 const Type *TypePtr::xmeet_helper(const Type *t) const {
2651   // Perform a fast test for common case; meeting the same types together.
2652   if( this == t ) return this;  // Meeting same type-rep?
2653 
2654   // Current "this->_base" is AnyPtr
2655   switch (t->base()) {          // switch on original type
2656   case Int:                     // Mixing ints & oops happens when javac
2657   case Long:                    // reuses local variables
2658   case FloatTop:
2659   case FloatCon:
2660   case FloatBot:
2661   case DoubleTop:
2662   case DoubleCon:
2663   case DoubleBot:
2664   case NarrowOop:
2665   case NarrowKlass:
2666   case Bottom:                  // Ye Olde Default
2667     return Type::BOTTOM;
2668   case Top:
2669     return this;
2670 
2671   case AnyPtr: {                // Meeting to AnyPtrs
2672     const TypePtr *tp = t->is_ptr();
2673     const TypePtr* speculative = xmeet_speculative(tp);
2674     int depth = meet_inline_depth(tp->inline_depth());
2675     return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2676   }
2677   case RawPtr:                  // For these, flip the call around to cut down
2678   case OopPtr:
2679   case InstPtr:                 // on the cases I have to handle.
2680   case ValueTypePtr:
2681   case AryPtr:
2682   case MetadataPtr:
2683   case KlassPtr:
2684     return t->xmeet(this);      // Call in reverse direction
2685   default:                      // All else is a mistake
2686     typerr(t);
2687 
2688   }
2689   return this;
2690 }
2691 
2692 //------------------------------meet_offset------------------------------------
2693 Type::Offset TypePtr::meet_offset(int offset) const {
2694   return _offset.meet(Offset(offset));
2695 }
2696 
2697 //------------------------------dual_offset------------------------------------
2698 Type::Offset TypePtr::dual_offset() const {
2699   return _offset.dual();
2700 }
2701 
2702 //------------------------------xdual------------------------------------------
2703 // Dual: compute field-by-field dual
2704 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2705   BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2706 };
2707 const Type *TypePtr::xdual() const {
2708   return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
2709 }
2710 
2711 //------------------------------xadd_offset------------------------------------
2712 Type::Offset TypePtr::xadd_offset(intptr_t offset) const {
2713   return _offset.add(offset);
2714 }
2715 
2716 //------------------------------add_offset-------------------------------------
2717 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2718   return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth);
2719 }
2720 
2721 //------------------------------eq---------------------------------------------
2722 // Structural equality check for Type representations
2723 bool TypePtr::eq( const Type *t ) const {
2724   const TypePtr *a = (const TypePtr*)t;
2725   return _ptr == a->ptr() && _offset == a->_offset && eq_speculative(a) && _inline_depth == a->_inline_depth;
2726 }
2727 
2728 //------------------------------hash-------------------------------------------
2729 // Type-specific hashing function.
2730 int TypePtr::hash(void) const {
2731   return java_add(java_add(_ptr, offset()), java_add( hash_speculative(), _inline_depth));
2732 ;
2733 }
2734 
2735 /**
2736  * Return same type without a speculative part
2737  */
2738 const Type* TypePtr::remove_speculative() const {
2739   if (_speculative == NULL) {
2740     return this;
2741   }
2742   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2743   return make(AnyPtr, _ptr, _offset, NULL, _inline_depth);
2744 }
2745 
2746 /**
2747  * Return same type but drop speculative part if we know we won't use
2748  * it
2749  */
2750 const Type* TypePtr::cleanup_speculative() const {
2751   if (speculative() == NULL) {
2752     return this;
2753   }
2754   const Type* no_spec = remove_speculative();
2755   // If this is NULL_PTR then we don't need the speculative type
2756   // (with_inline_depth in case the current type inline depth is
2757   // InlineDepthTop)
2758   if (no_spec == NULL_PTR->with_inline_depth(inline_depth())) {
2759     return no_spec;
2760   }
2761   if (above_centerline(speculative()->ptr())) {
2762     return no_spec;
2763   }
2764   const TypeOopPtr* spec_oopptr = speculative()->isa_oopptr();
2765   // If the speculative may be null and is an inexact klass then it
2766   // doesn't help
2767   if (speculative()->maybe_null() && (spec_oopptr == NULL || !spec_oopptr->klass_is_exact())) {
2768     return no_spec;
2769   }
2770   return this;
2771 }
2772 
2773 /**
2774  * dual of the speculative part of the type
2775  */
2776 const TypePtr* TypePtr::dual_speculative() const {
2777   if (_speculative == NULL) {
2778     return NULL;
2779   }
2780   return _speculative->dual()->is_ptr();
2781 }
2782 
2783 /**
2784  * meet of the speculative parts of 2 types
2785  *
2786  * @param other  type to meet with
2787  */
2788 const TypePtr* TypePtr::xmeet_speculative(const TypePtr* other) const {
2789   bool this_has_spec = (_speculative != NULL);
2790   bool other_has_spec = (other->speculative() != NULL);
2791 
2792   if (!this_has_spec && !other_has_spec) {
2793     return NULL;
2794   }
2795 
2796   // If we are at a point where control flow meets and one branch has
2797   // a speculative type and the other has not, we meet the speculative
2798   // type of one branch with the actual type of the other. If the
2799   // actual type is exact and the speculative is as well, then the
2800   // result is a speculative type which is exact and we can continue
2801   // speculation further.
2802   const TypePtr* this_spec = _speculative;
2803   const TypePtr* other_spec = other->speculative();
2804 
2805   if (!this_has_spec) {
2806     this_spec = this;
2807   }
2808 
2809   if (!other_has_spec) {
2810     other_spec = other;
2811   }
2812 
2813   return this_spec->meet(other_spec)->is_ptr();
2814 }
2815 
2816 /**
2817  * dual of the inline depth for this type (used for speculation)
2818  */
2819 int TypePtr::dual_inline_depth() const {
2820   return -inline_depth();
2821 }
2822 
2823 /**
2824  * meet of 2 inline depths (used for speculation)
2825  *
2826  * @param depth  depth to meet with
2827  */
2828 int TypePtr::meet_inline_depth(int depth) const {
2829   return MAX2(inline_depth(), depth);
2830 }
2831 
2832 /**
2833  * Are the speculative parts of 2 types equal?
2834  *
2835  * @param other  type to compare this one to
2836  */
2837 bool TypePtr::eq_speculative(const TypePtr* other) const {
2838   if (_speculative == NULL || other->speculative() == NULL) {
2839     return _speculative == other->speculative();
2840   }
2841 
2842   if (_speculative->base() != other->speculative()->base()) {
2843     return false;
2844   }
2845 
2846   return _speculative->eq(other->speculative());
2847 }
2848 
2849 /**
2850  * Hash of the speculative part of the type
2851  */
2852 int TypePtr::hash_speculative() const {
2853   if (_speculative == NULL) {
2854     return 0;
2855   }
2856 
2857   return _speculative->hash();
2858 }
2859 
2860 /**
2861  * add offset to the speculative part of the type
2862  *
2863  * @param offset  offset to add
2864  */
2865 const TypePtr* TypePtr::add_offset_speculative(intptr_t offset) const {
2866   if (_speculative == NULL) {
2867     return NULL;
2868   }
2869   return _speculative->add_offset(offset)->is_ptr();
2870 }
2871 
2872 /**
2873  * return exact klass from the speculative type if there's one
2874  */
2875 ciKlass* TypePtr::speculative_type() const {
2876   if (_speculative != NULL && _speculative->isa_oopptr()) {
2877     const TypeOopPtr* speculative = _speculative->join(this)->is_oopptr();
2878     if (speculative->klass_is_exact()) {
2879       return speculative->klass();
2880     }
2881   }
2882   return NULL;
2883 }
2884 
2885 /**
2886  * return true if speculative type may be null
2887  */
2888 bool TypePtr::speculative_maybe_null() const {
2889   if (_speculative != NULL) {
2890     const TypePtr* speculative = _speculative->join(this)->is_ptr();
2891     return speculative->maybe_null();
2892   }
2893   return true;
2894 }
2895 
2896 /**
2897  * Same as TypePtr::speculative_type() but return the klass only if
2898  * the speculative tells us is not null
2899  */
2900 ciKlass* TypePtr::speculative_type_not_null() const {
2901   if (speculative_maybe_null()) {
2902     return NULL;
2903   }
2904   return speculative_type();
2905 }
2906 
2907 /**
2908  * Check whether new profiling would improve speculative type
2909  *
2910  * @param   exact_kls    class from profiling
2911  * @param   inline_depth inlining depth of profile point
2912  *
2913  * @return  true if type profile is valuable
2914  */
2915 bool TypePtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
2916   // no profiling?
2917   if (exact_kls == NULL) {
2918     return false;
2919   }
2920   // no speculative type or non exact speculative type?
2921   if (speculative_type() == NULL) {
2922     return true;
2923   }
2924   // If the node already has an exact speculative type keep it,
2925   // unless it was provided by profiling that is at a deeper
2926   // inlining level. Profiling at a higher inlining depth is
2927   // expected to be less accurate.
2928   if (_speculative->inline_depth() == InlineDepthBottom) {
2929     return false;
2930   }
2931   assert(_speculative->inline_depth() != InlineDepthTop, "can't do the comparison");
2932   return inline_depth < _speculative->inline_depth();
2933 }
2934 
2935 /**
2936  * Check whether new profiling would improve ptr (= tells us it is non
2937  * null)
2938  *
2939  * @param   maybe_null true if profiling tells the ptr may be null
2940  *
2941  * @return  true if ptr profile is valuable
2942  */
2943 bool TypePtr::would_improve_ptr(bool maybe_null) const {
2944   // profiling doesn't tell us anything useful
2945   if (maybe_null) {
2946     return false;
2947   }
2948   // We already know this is not be null
2949   if (!this->maybe_null()) {
2950     return false;
2951   }
2952   // We already know the speculative type cannot be null
2953   if (!speculative_maybe_null()) {
2954     return false;
2955   }
2956   return true;
2957 }
2958 
2959 //------------------------------dump2------------------------------------------
2960 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
2961   "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR"
2962 };
2963 
2964 #ifndef PRODUCT
2965 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2966   if( _ptr == Null ) st->print("NULL");
2967   else st->print("%s *", ptr_msg[_ptr]);
2968   _offset.dump2(st);
2969   dump_inline_depth(st);
2970   dump_speculative(st);
2971 }
2972 
2973 /**
2974  *dump the speculative part of the type
2975  */
2976 void TypePtr::dump_speculative(outputStream *st) const {
2977   if (_speculative != NULL) {
2978     st->print(" (speculative=");
2979     _speculative->dump_on(st);
2980     st->print(")");
2981   }
2982 }
2983 
2984 /**
2985  *dump the inline depth of the type
2986  */
2987 void TypePtr::dump_inline_depth(outputStream *st) const {
2988   if (_inline_depth != InlineDepthBottom) {
2989     if (_inline_depth == InlineDepthTop) {
2990       st->print(" (inline_depth=InlineDepthTop)");
2991     } else {
2992       st->print(" (inline_depth=%d)", _inline_depth);
2993     }
2994   }
2995 }
2996 #endif
2997 
2998 //------------------------------singleton--------------------------------------
2999 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3000 // constants
3001 bool TypePtr::singleton(void) const {
3002   // TopPTR, Null, AnyNull, Constant are all singletons
3003   return (_offset != Offset::bottom) && !below_centerline(_ptr);
3004 }
3005 
3006 bool TypePtr::empty(void) const {
3007   return (_offset == Offset::top) || above_centerline(_ptr);
3008 }
3009 
3010 //=============================================================================
3011 // Convenience common pre-built types.
3012 const TypeRawPtr *TypeRawPtr::BOTTOM;
3013 const TypeRawPtr *TypeRawPtr::NOTNULL;
3014 
3015 //------------------------------make-------------------------------------------
3016 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
3017   assert( ptr != Constant, "what is the constant?" );
3018   assert( ptr != Null, "Use TypePtr for NULL" );
3019   return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons();
3020 }
3021 
3022 const TypeRawPtr *TypeRawPtr::make( address bits ) {
3023   assert( bits, "Use TypePtr for NULL" );
3024   return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
3025 }
3026 
3027 //------------------------------cast_to_ptr_type-------------------------------
3028 const Type *TypeRawPtr::cast_to_ptr_type(PTR ptr) const {
3029   assert( ptr != Constant, "what is the constant?" );
3030   assert( ptr != Null, "Use TypePtr for NULL" );
3031   assert( _bits==0, "Why cast a constant address?");
3032   if( ptr == _ptr ) return this;
3033   return make(ptr);
3034 }
3035 
3036 //------------------------------get_con----------------------------------------
3037 intptr_t TypeRawPtr::get_con() const {
3038   assert( _ptr == Null || _ptr == Constant, "" );
3039   return (intptr_t)_bits;
3040 }
3041 
3042 //------------------------------meet-------------------------------------------
3043 // Compute the MEET of two types.  It returns a new Type object.
3044 const Type *TypeRawPtr::xmeet( const Type *t ) const {
3045   // Perform a fast test for common case; meeting the same types together.
3046   if( this == t ) return this;  // Meeting same type-rep?
3047 
3048   // Current "this->_base" is RawPtr
3049   switch( t->base() ) {         // switch on original type
3050   case Bottom:                  // Ye Olde Default
3051     return t;
3052   case Top:
3053     return this;
3054   case AnyPtr:                  // Meeting to AnyPtrs
3055     break;
3056   case RawPtr: {                // might be top, bot, any/not or constant
3057     enum PTR tptr = t->is_ptr()->ptr();
3058     enum PTR ptr = meet_ptr( tptr );
3059     if( ptr == Constant ) {     // Cannot be equal constants, so...
3060       if( tptr == Constant && _ptr != Constant)  return t;
3061       if( _ptr == Constant && tptr != Constant)  return this;
3062       ptr = NotNull;            // Fall down in lattice
3063     }
3064     return make( ptr );
3065   }
3066 
3067   case OopPtr:
3068   case InstPtr:
3069   case ValueTypePtr:
3070   case AryPtr:
3071   case MetadataPtr:
3072   case KlassPtr:
3073     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3074   default:                      // All else is a mistake
3075     typerr(t);
3076   }
3077 
3078   // Found an AnyPtr type vs self-RawPtr type
3079   const TypePtr *tp = t->is_ptr();
3080   switch (tp->ptr()) {
3081   case TypePtr::TopPTR:  return this;
3082   case TypePtr::BotPTR:  return t;
3083   case TypePtr::Null:
3084     if( _ptr == TypePtr::TopPTR ) return t;
3085     return TypeRawPtr::BOTTOM;
3086   case TypePtr::NotNull: return TypePtr::make(AnyPtr, meet_ptr(TypePtr::NotNull), tp->meet_offset(0), tp->speculative(), tp->inline_depth());
3087   case TypePtr::AnyNull:
3088     if( _ptr == TypePtr::Constant) return this;
3089     return make( meet_ptr(TypePtr::AnyNull) );
3090   default: ShouldNotReachHere();
3091   }
3092   return this;
3093 }
3094 
3095 //------------------------------xdual------------------------------------------
3096 // Dual: compute field-by-field dual
3097 const Type *TypeRawPtr::xdual() const {
3098   return new TypeRawPtr( dual_ptr(), _bits );
3099 }
3100 
3101 //------------------------------add_offset-------------------------------------
3102 const TypePtr *TypeRawPtr::add_offset( intptr_t offset ) const {
3103   if( offset == OffsetTop ) return BOTTOM; // Undefined offset-> undefined pointer
3104   if( offset == OffsetBot ) return BOTTOM; // Unknown offset-> unknown pointer
3105   if( offset == 0 ) return this; // No change
3106   switch (_ptr) {
3107   case TypePtr::TopPTR:
3108   case TypePtr::BotPTR:
3109   case TypePtr::NotNull:
3110     return this;
3111   case TypePtr::Null:
3112   case TypePtr::Constant: {
3113     address bits = _bits+offset;
3114     if ( bits == 0 ) return TypePtr::NULL_PTR;
3115     return make( bits );
3116   }
3117   default:  ShouldNotReachHere();
3118   }
3119   return NULL;                  // Lint noise
3120 }
3121 
3122 //------------------------------eq---------------------------------------------
3123 // Structural equality check for Type representations
3124 bool TypeRawPtr::eq( const Type *t ) const {
3125   const TypeRawPtr *a = (const TypeRawPtr*)t;
3126   return _bits == a->_bits && TypePtr::eq(t);
3127 }
3128 
3129 //------------------------------hash-------------------------------------------
3130 // Type-specific hashing function.
3131 int TypeRawPtr::hash(void) const {
3132   return (intptr_t)_bits + TypePtr::hash();
3133 }
3134 
3135 //------------------------------dump2------------------------------------------
3136 #ifndef PRODUCT
3137 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3138   if( _ptr == Constant )
3139     st->print(INTPTR_FORMAT, p2i(_bits));
3140   else
3141     st->print("rawptr:%s", ptr_msg[_ptr]);
3142 }
3143 #endif
3144 
3145 //=============================================================================
3146 // Convenience common pre-built type.
3147 const TypeOopPtr *TypeOopPtr::BOTTOM;
3148 
3149 //------------------------------TypeOopPtr-------------------------------------
3150 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, Offset offset, Offset field_offset,
3151                        int instance_id, const TypePtr* speculative, int inline_depth)
3152   : TypePtr(t, ptr, offset, speculative, inline_depth),
3153     _const_oop(o), _klass(k),
3154     _klass_is_exact(xk),
3155     _is_ptr_to_narrowoop(false),
3156     _is_ptr_to_narrowklass(false),
3157     _is_ptr_to_boxed_value(false),
3158     _instance_id(instance_id) {
3159   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3160       (offset.get() > 0) && xk && (k != 0) && k->is_instance_klass()) {
3161     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset.get());
3162   }
3163 #ifdef _LP64
3164   if (this->offset() != 0) {
3165     if (this->offset() == oopDesc::klass_offset_in_bytes()) {
3166       _is_ptr_to_narrowklass = UseCompressedClassPointers;
3167     } else if (klass() == NULL) {
3168       // Array with unknown body type
3169       assert(this->isa_aryptr(), "only arrays without klass");
3170       _is_ptr_to_narrowoop = UseCompressedOops;
3171     } else if (UseCompressedOops && this->isa_aryptr() && this->offset() != arrayOopDesc::length_offset_in_bytes()) {
3172       if (klass()->is_obj_array_klass()) {
3173         _is_ptr_to_narrowoop = true;
3174       } else if (klass()->is_value_array_klass() && field_offset != Offset::top && field_offset != Offset::bottom) {
3175         // Check if the field of the value type array element contains oops
3176         ciValueKlass* vk = klass()->as_value_array_klass()->element_klass()->as_value_klass();
3177         int foffset = field_offset.get() + vk->first_field_offset();
3178         ciField* field = vk->get_field_by_offset(foffset, false);
3179         assert(field != NULL, "missing field");
3180         BasicType bt = field->layout_type();
3181         assert(bt != T_VALUETYPE, "should be flattened");
3182         _is_ptr_to_narrowoop = (bt == T_OBJECT || bt == T_ARRAY);
3183       }
3184     } else if (klass()->is_instance_klass()) {
3185       ciInstanceKlass* ik = klass()->as_instance_klass();
3186       ciField* field = NULL;
3187       if (this->isa_klassptr()) {
3188         // Perm objects don't use compressed references
3189       } else if (_offset == Offset::bottom || _offset == Offset::top) {
3190         // unsafe access
3191         _is_ptr_to_narrowoop = UseCompressedOops;
3192       } else { // exclude unsafe ops
3193         assert(this->isa_instptr() || this->isa_valuetypeptr(), "must be an instance ptr.");
3194 
3195         if (klass() == ciEnv::current()->Class_klass() &&
3196             (this->offset() == java_lang_Class::klass_offset_in_bytes() ||
3197              this->offset() == java_lang_Class::array_klass_offset_in_bytes())) {
3198           // Special hidden fields from the Class.
3199           assert(this->isa_instptr(), "must be an instance ptr.");
3200           _is_ptr_to_narrowoop = false;
3201         } else if (klass() == ciEnv::current()->Class_klass() &&
3202                    this->offset() >= InstanceMirrorKlass::offset_of_static_fields()) {
3203           // Static fields
3204           assert(o != NULL, "must be constant");
3205           ciInstanceKlass* k = o->as_instance()->java_lang_Class_klass()->as_instance_klass();
3206           ciField* field = k->get_field_by_offset(this->offset(), true);
3207           assert(field != NULL, "missing field");
3208           BasicType basic_elem_type = field->layout_type();
3209           _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||
3210                                                        basic_elem_type == T_ARRAY);
3211         } else {
3212           // Instance fields which contains a compressed oop references.
3213           field = ik->get_field_by_offset(this->offset(), false);
3214           if (field != NULL) {
3215             BasicType basic_elem_type = field->layout_type();
3216             _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||
3217                                                          basic_elem_type == T_ARRAY);
3218           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3219             // Compile::find_alias_type() cast exactness on all types to verify
3220             // that it does not affect alias type.
3221             _is_ptr_to_narrowoop = UseCompressedOops;
3222           } else {
3223             // Type for the copy start in LibraryCallKit::inline_native_clone().
3224             _is_ptr_to_narrowoop = UseCompressedOops;
3225           }
3226         }
3227       }
3228     }
3229   }
3230 #endif
3231 }
3232 
3233 //------------------------------make-------------------------------------------
3234 const TypeOopPtr *TypeOopPtr::make(PTR ptr, Offset offset, int instance_id,
3235                                    const TypePtr* speculative, int inline_depth) {
3236   assert(ptr != Constant, "no constant generic pointers");
3237   ciKlass*  k = Compile::current()->env()->Object_klass();
3238   bool      xk = false;
3239   ciObject* o = NULL;
3240   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, Offset::bottom, instance_id, speculative, inline_depth))->hashcons();
3241 }
3242 
3243 
3244 //------------------------------cast_to_ptr_type-------------------------------
3245 const Type *TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3246   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3247   if( ptr == _ptr ) return this;
3248   return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3249 }
3250 
3251 //-----------------------------cast_to_instance_id----------------------------
3252 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3253   // There are no instances of a general oop.
3254   // Return self unchanged.
3255   return this;
3256 }
3257 
3258 //-----------------------------cast_to_exactness-------------------------------
3259 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3260   // There is no such thing as an exact general oop.
3261   // Return self unchanged.
3262   return this;
3263 }
3264 
3265 
3266 //------------------------------as_klass_type----------------------------------
3267 // Return the klass type corresponding to this instance or array type.
3268 // It is the type that is loaded from an object of this type.
3269 const TypeKlassPtr* TypeOopPtr::as_klass_type() const {
3270   ciKlass* k = klass();
3271   bool    xk = klass_is_exact();
3272   if (k == NULL)
3273     return TypeKlassPtr::OBJECT;
3274   else
3275     return TypeKlassPtr::make(xk? Constant: NotNull, k, Offset(0));
3276 }
3277 
3278 //------------------------------meet-------------------------------------------
3279 // Compute the MEET of two types.  It returns a new Type object.
3280 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3281   // Perform a fast test for common case; meeting the same types together.
3282   if( this == t ) return this;  // Meeting same type-rep?
3283 
3284   // Current "this->_base" is OopPtr
3285   switch (t->base()) {          // switch on original type
3286 
3287   case Int:                     // Mixing ints & oops happens when javac
3288   case Long:                    // reuses local variables
3289   case FloatTop:
3290   case FloatCon:
3291   case FloatBot:
3292   case DoubleTop:
3293   case DoubleCon:
3294   case DoubleBot:
3295   case NarrowOop:
3296   case NarrowKlass:
3297   case Bottom:                  // Ye Olde Default
3298     return Type::BOTTOM;
3299   case Top:
3300     return this;
3301 
3302   default:                      // All else is a mistake
3303     typerr(t);
3304 
3305   case RawPtr:
3306   case MetadataPtr:
3307   case KlassPtr:
3308     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3309 
3310   case AnyPtr: {
3311     // Found an AnyPtr type vs self-OopPtr type
3312     const TypePtr *tp = t->is_ptr();
3313     Offset offset = meet_offset(tp->offset());
3314     PTR ptr = meet_ptr(tp->ptr());
3315     const TypePtr* speculative = xmeet_speculative(tp);
3316     int depth = meet_inline_depth(tp->inline_depth());
3317     switch (tp->ptr()) {
3318     case Null:
3319       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3320       // else fall through:
3321     case TopPTR:
3322     case AnyNull: {
3323       int instance_id = meet_instance_id(InstanceTop);
3324       return make(ptr, offset, instance_id, speculative, depth);
3325     }
3326     case BotPTR:
3327     case NotNull:
3328       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3329     default: typerr(t);
3330     }
3331   }
3332 
3333   case OopPtr: {                 // Meeting to other OopPtrs
3334     const TypeOopPtr *tp = t->is_oopptr();
3335     int instance_id = meet_instance_id(tp->instance_id());
3336     const TypePtr* speculative = xmeet_speculative(tp);
3337     int depth = meet_inline_depth(tp->inline_depth());
3338     return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3339   }
3340 
3341   case InstPtr:                  // For these, flip the call around to cut down
3342   case ValueTypePtr:
3343   case AryPtr:
3344     return t->xmeet(this);      // Call in reverse direction
3345 
3346   } // End of switch
3347   return this;                  // Return the double constant
3348 }
3349 
3350 
3351 //------------------------------xdual------------------------------------------
3352 // Dual of a pure heap pointer.  No relevant klass or oop information.
3353 const Type *TypeOopPtr::xdual() const {
3354   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3355   assert(const_oop() == NULL,             "no constants here");
3356   return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), Offset::bottom, dual_instance_id(), dual_speculative(), dual_inline_depth());
3357 }
3358 
3359 //--------------------------make_from_klass_common-----------------------------
3360 // Computes the element-type given a klass.
3361 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) {
3362   if (klass->is_valuetype()) {
3363     return TypeValueTypePtr::make(TypePtr::NotNull, klass->as_value_klass());
3364   } else if (klass->is_instance_klass()) {
3365     Compile* C = Compile::current();
3366     Dependencies* deps = C->dependencies();
3367     assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
3368     // Element is an instance
3369     bool klass_is_exact = false;
3370     if (klass->is_loaded()) {
3371       // Try to set klass_is_exact.
3372       ciInstanceKlass* ik = klass->as_instance_klass();
3373       klass_is_exact = ik->is_final();
3374       if (!klass_is_exact && klass_change
3375           && deps != NULL && UseUniqueSubclasses) {
3376         ciInstanceKlass* sub = ik->unique_concrete_subklass();
3377         if (sub != NULL) {
3378           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3379           klass = ik = sub;
3380           klass_is_exact = sub->is_final();
3381         }
3382       }
3383       if (!klass_is_exact && try_for_exact
3384           && deps != NULL && UseExactTypes) {
3385         if (!ik->is_interface() && !ik->has_subklass()) {
3386           // Add a dependence; if concrete subclass added we need to recompile
3387           deps->assert_leaf_type(ik);
3388           klass_is_exact = true;
3389         }
3390       }
3391     }
3392     return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, Offset(0));
3393   } else if (klass->is_obj_array_klass()) {
3394     // Element is an object or value array. Recursively call ourself.
3395     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), false, try_for_exact);
3396     bool xk = etype->klass_is_exact();
3397     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3398     // We used to pass NotNull in here, asserting that the sub-arrays
3399     // are all not-null.  This is not true in generally, as code can
3400     // slam NULLs down in the subarrays.
3401     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, Offset(0));
3402     return arr;
3403   } else if (klass->is_type_array_klass()) {
3404     // Element is an typeArray
3405     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3406     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3407     // We used to pass NotNull in here, asserting that the array pointer
3408     // is not-null. That was not true in general.
3409     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
3410     return arr;
3411   } else if (klass->is_value_array_klass()) {
3412     ciValueKlass* vk = klass->as_array_klass()->element_klass()->as_value_klass();
3413     const Type* etype = NULL;
3414     bool xk = false;
3415     if (vk->flatten_array()) {
3416       etype = TypeValueType::make(vk);
3417       xk = true;
3418     } else {
3419       const TypeOopPtr* etype_oop = TypeOopPtr::make_from_klass_common(vk, false, try_for_exact);
3420       xk = etype_oop->klass_is_exact();
3421       etype = etype_oop;
3422     }
3423     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3424     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, Offset(0));
3425     return arr;
3426   } else {
3427     ShouldNotReachHere();
3428     return NULL;
3429   }
3430 }
3431 
3432 //------------------------------make_from_constant-----------------------------
3433 // Make a java pointer from an oop constant
3434 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3435   assert(!o->is_null_object(), "null object not yet handled here.");
3436   ciKlass* klass = o->klass();
3437   if (klass->is_valuetype()) {
3438     // Element is a value type
3439     if (require_constant) {
3440       if (!o->can_be_constant())  return NULL;
3441     } else if (!o->should_be_constant()) {
3442       return TypeValueTypePtr::make(TypePtr::NotNull, klass->as_value_klass());
3443     }
3444     return TypeValueTypePtr::make(o);
3445   } else if (klass->is_instance_klass()) {
3446     // Element is an instance
3447     if (require_constant) {
3448       if (!o->can_be_constant())  return NULL;
3449     } else if (!o->should_be_constant()) {
3450       return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, Offset(0));
3451     }
3452     return TypeInstPtr::make(o);
3453   } else if (klass->is_obj_array_klass() || klass->is_value_array_klass()) {
3454     // Element is an object array. Recursively call ourself.
3455     const TypeOopPtr *etype =
3456       TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass());
3457     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3458     // We used to pass NotNull in here, asserting that the sub-arrays
3459     // are all not-null.  This is not true in generally, as code can
3460     // slam NULLs down in the subarrays.
3461     if (require_constant) {
3462       if (!o->can_be_constant())  return NULL;
3463     } else if (!o->should_be_constant()) {
3464       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3465     }
3466     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3467     return arr;
3468   } else if (klass->is_type_array_klass()) {
3469     // Element is an typeArray
3470     const Type* etype =
3471       (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3472     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3473     // We used to pass NotNull in here, asserting that the array pointer
3474     // is not-null. That was not true in general.
3475     if (require_constant) {
3476       if (!o->can_be_constant())  return NULL;
3477     } else if (!o->should_be_constant()) {
3478       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3479     }
3480     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3481     return arr;
3482   }
3483 
3484   fatal("unhandled object type");
3485   return NULL;
3486 }
3487 
3488 //------------------------------get_con----------------------------------------
3489 intptr_t TypeOopPtr::get_con() const {
3490   assert( _ptr == Null || _ptr == Constant, "" );
3491   assert(offset() >= 0, "");
3492 
3493   if (offset() != 0) {
3494     // After being ported to the compiler interface, the compiler no longer
3495     // directly manipulates the addresses of oops.  Rather, it only has a pointer
3496     // to a handle at compile time.  This handle is embedded in the generated
3497     // code and dereferenced at the time the nmethod is made.  Until that time,
3498     // it is not reasonable to do arithmetic with the addresses of oops (we don't
3499     // have access to the addresses!).  This does not seem to currently happen,
3500     // but this assertion here is to help prevent its occurence.
3501     tty->print_cr("Found oop constant with non-zero offset");
3502     ShouldNotReachHere();
3503   }
3504 
3505   return (intptr_t)const_oop()->constant_encoding();
3506 }
3507 
3508 
3509 //-----------------------------filter------------------------------------------
3510 // Do not allow interface-vs.-noninterface joins to collapse to top.
3511 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
3512 
3513   const Type* ft = join_helper(kills, include_speculative);
3514   const TypeInstPtr* ftip = ft->isa_instptr();
3515   const TypeInstPtr* ktip = kills->isa_instptr();
3516 
3517   if (ft->empty()) {
3518     // Check for evil case of 'this' being a class and 'kills' expecting an
3519     // interface.  This can happen because the bytecodes do not contain
3520     // enough type info to distinguish a Java-level interface variable
3521     // from a Java-level object variable.  If we meet 2 classes which
3522     // both implement interface I, but their meet is at 'j/l/O' which
3523     // doesn't implement I, we have no way to tell if the result should
3524     // be 'I' or 'j/l/O'.  Thus we'll pick 'j/l/O'.  If this then flows
3525     // into a Phi which "knows" it's an Interface type we'll have to
3526     // uplift the type.
3527     if (!empty()) {
3528       if (ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface()) {
3529         return kills;           // Uplift to interface
3530       }
3531       // Also check for evil cases of 'this' being a class array
3532       // and 'kills' expecting an array of interfaces.
3533       Type::get_arrays_base_elements(ft, kills, NULL, &ktip);
3534       if (ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface()) {
3535         return kills;           // Uplift to array of interface
3536       }
3537     }
3538 
3539     return Type::TOP;           // Canonical empty value
3540   }
3541 
3542   // If we have an interface-typed Phi or cast and we narrow to a class type,
3543   // the join should report back the class.  However, if we have a J/L/Object
3544   // class-typed Phi and an interface flows in, it's possible that the meet &
3545   // join report an interface back out.  This isn't possible but happens
3546   // because the type system doesn't interact well with interfaces.
3547   if (ftip != NULL && ktip != NULL &&
3548       ftip->is_loaded() &&  ftip->klass()->is_interface() &&
3549       ktip->is_loaded() && !ktip->klass()->is_interface()) {
3550     assert(!ftip->klass_is_exact(), "interface could not be exact");
3551     return ktip->cast_to_ptr_type(ftip->ptr());
3552   }
3553 
3554   return ft;
3555 }
3556 
3557 //------------------------------eq---------------------------------------------
3558 // Structural equality check for Type representations
3559 bool TypeOopPtr::eq( const Type *t ) const {
3560   const TypeOopPtr *a = (const TypeOopPtr*)t;
3561   if (_klass_is_exact != a->_klass_is_exact ||
3562       _instance_id != a->_instance_id)  return false;
3563   ciObject* one = const_oop();
3564   ciObject* two = a->const_oop();
3565   if (one == NULL || two == NULL) {
3566     return (one == two) && TypePtr::eq(t);
3567   } else {
3568     return one->equals(two) && TypePtr::eq(t);
3569   }
3570 }
3571 
3572 //------------------------------hash-------------------------------------------
3573 // Type-specific hashing function.
3574 int TypeOopPtr::hash(void) const {
3575   return
3576     java_add(java_add(const_oop() ? const_oop()->hash() : 0, _klass_is_exact),
3577              java_add(_instance_id, TypePtr::hash()));
3578 }
3579 
3580 //------------------------------dump2------------------------------------------
3581 #ifndef PRODUCT
3582 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3583   st->print("oopptr:%s", ptr_msg[_ptr]);
3584   if( _klass_is_exact ) st->print(":exact");
3585   if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
3586   _offset.dump2(st);
3587   if (_instance_id == InstanceTop)
3588     st->print(",iid=top");
3589   else if (_instance_id != InstanceBot)
3590     st->print(",iid=%d",_instance_id);
3591 
3592   dump_inline_depth(st);
3593   dump_speculative(st);
3594 }
3595 #endif
3596 
3597 //------------------------------singleton--------------------------------------
3598 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3599 // constants
3600 bool TypeOopPtr::singleton(void) const {
3601   // detune optimizer to not generate constant oop + constant offset as a constant!
3602   // TopPTR, Null, AnyNull, Constant are all singletons
3603   return (offset() == 0) && !below_centerline(_ptr);
3604 }
3605 
3606 //------------------------------add_offset-------------------------------------
3607 const TypePtr *TypeOopPtr::add_offset(intptr_t offset) const {
3608   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
3609 }
3610 
3611 /**
3612  * Return same type without a speculative part
3613  */
3614 const Type* TypeOopPtr::remove_speculative() const {
3615   if (_speculative == NULL) {
3616     return this;
3617   }
3618   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
3619   return make(_ptr, _offset, _instance_id, NULL, _inline_depth);
3620 }
3621 
3622 /**
3623  * Return same type but drop speculative part if we know we won't use
3624  * it
3625  */
3626 const Type* TypeOopPtr::cleanup_speculative() const {
3627   // If the klass is exact and the ptr is not null then there's
3628   // nothing that the speculative type can help us with
3629   if (klass_is_exact() && !maybe_null()) {
3630     return remove_speculative();
3631   }
3632   return TypePtr::cleanup_speculative();
3633 }
3634 
3635 /**
3636  * Return same type but with a different inline depth (used for speculation)
3637  *
3638  * @param depth  depth to meet with
3639  */
3640 const TypePtr* TypeOopPtr::with_inline_depth(int depth) const {
3641   if (!UseInlineDepthForSpeculativeTypes) {
3642     return this;
3643   }
3644   return make(_ptr, _offset, _instance_id, _speculative, depth);
3645 }
3646 
3647 //------------------------------meet_instance_id--------------------------------
3648 int TypeOopPtr::meet_instance_id( int instance_id ) const {
3649   // Either is 'TOP' instance?  Return the other instance!
3650   if( _instance_id == InstanceTop ) return  instance_id;
3651   if(  instance_id == InstanceTop ) return _instance_id;
3652   // If either is different, return 'BOTTOM' instance
3653   if( _instance_id != instance_id ) return InstanceBot;
3654   return _instance_id;
3655 }
3656 
3657 //------------------------------dual_instance_id--------------------------------
3658 int TypeOopPtr::dual_instance_id( ) const {
3659   if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM
3660   if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP
3661   return _instance_id;              // Map everything else into self
3662 }
3663 
3664 /**
3665  * Check whether new profiling would improve speculative type
3666  *
3667  * @param   exact_kls    class from profiling
3668  * @param   inline_depth inlining depth of profile point
3669  *
3670  * @return  true if type profile is valuable
3671  */
3672 bool TypeOopPtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
3673   // no way to improve an already exact type
3674   if (klass_is_exact()) {
3675     return false;
3676   }
3677   return TypePtr::would_improve_type(exact_kls, inline_depth);
3678 }
3679 
3680 //=============================================================================
3681 // Convenience common pre-built types.
3682 const TypeInstPtr *TypeInstPtr::NOTNULL;
3683 const TypeInstPtr *TypeInstPtr::BOTTOM;
3684 const TypeInstPtr *TypeInstPtr::MIRROR;
3685 const TypeInstPtr *TypeInstPtr::MARK;
3686 const TypeInstPtr *TypeInstPtr::KLASS;
3687 
3688 //------------------------------TypeInstPtr-------------------------------------
3689 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, Offset off,
3690                          int instance_id, const TypePtr* speculative, int inline_depth)
3691   : TypeOopPtr(InstPtr, ptr, k, xk, o, off, Offset::bottom, instance_id, speculative, inline_depth),
3692     _name(k->name()) {
3693    assert(k != NULL &&
3694           (k->is_loaded() || o == NULL),
3695           "cannot have constants with non-loaded klass");
3696 };
3697 
3698 //------------------------------make-------------------------------------------
3699 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
3700                                      ciKlass* k,
3701                                      bool xk,
3702                                      ciObject* o,
3703                                      Offset offset,
3704                                      int instance_id,
3705                                      const TypePtr* speculative,
3706                                      int inline_depth) {
3707   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
3708   // Either const_oop() is NULL or else ptr is Constant
3709   assert( (!o && ptr != Constant) || (o && ptr == Constant),
3710           "constant pointers must have a value supplied" );
3711   // Ptr is never Null
3712   assert( ptr != Null, "NULL pointers are not typed" );
3713 
3714   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3715   if (!UseExactTypes)  xk = false;
3716   if (ptr == Constant) {
3717     // Note:  This case includes meta-object constants, such as methods.
3718     xk = true;
3719   } else if (k->is_loaded()) {
3720     ciInstanceKlass* ik = k->as_instance_klass();
3721     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
3722     if (xk && ik->is_interface())  xk = false;  // no exact interface
3723   }
3724 
3725   // Now hash this baby
3726   TypeInstPtr *result =
3727     (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o ,offset, instance_id, speculative, inline_depth))->hashcons();
3728 
3729   return result;
3730 }
3731 
3732 /**
3733  *  Create constant type for a constant boxed value
3734  */
3735 const Type* TypeInstPtr::get_const_boxed_value() const {
3736   assert(is_ptr_to_boxed_value(), "should be called only for boxed value");
3737   assert((const_oop() != NULL), "should be called only for constant object");
3738   ciConstant constant = const_oop()->as_instance()->field_value_by_offset(offset());
3739   BasicType bt = constant.basic_type();
3740   switch (bt) {
3741     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
3742     case T_INT:      return TypeInt::make(constant.as_int());
3743     case T_CHAR:     return TypeInt::make(constant.as_char());
3744     case T_BYTE:     return TypeInt::make(constant.as_byte());
3745     case T_SHORT:    return TypeInt::make(constant.as_short());
3746     case T_FLOAT:    return TypeF::make(constant.as_float());
3747     case T_DOUBLE:   return TypeD::make(constant.as_double());
3748     case T_LONG:     return TypeLong::make(constant.as_long());
3749     default:         break;
3750   }
3751   fatal("Invalid boxed value type '%s'", type2name(bt));
3752   return NULL;
3753 }
3754 
3755 //------------------------------cast_to_ptr_type-------------------------------
3756 const Type *TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
3757   if( ptr == _ptr ) return this;
3758   // Reconstruct _sig info here since not a problem with later lazy
3759   // construction, _sig will show up on demand.
3760   return make(ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, _inline_depth);
3761 }
3762 
3763 
3764 //-----------------------------cast_to_exactness-------------------------------
3765 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
3766   if( klass_is_exact == _klass_is_exact ) return this;
3767   if (!UseExactTypes)  return this;
3768   if (!_klass->is_loaded())  return this;
3769   ciInstanceKlass* ik = _klass->as_instance_klass();
3770   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
3771   if( ik->is_interface() )              return this;  // cannot set xk
3772   return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id, _speculative, _inline_depth);
3773 }
3774 
3775 //-----------------------------cast_to_instance_id----------------------------
3776 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const {
3777   if( instance_id == _instance_id ) return this;
3778   return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id, _speculative, _inline_depth);
3779 }
3780 
3781 //------------------------------xmeet_unloaded---------------------------------
3782 // Compute the MEET of two InstPtrs when at least one is unloaded.
3783 // Assume classes are different since called after check for same name/class-loader
3784 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
3785     Offset off = meet_offset(tinst->offset());
3786     PTR ptr = meet_ptr(tinst->ptr());
3787     int instance_id = meet_instance_id(tinst->instance_id());
3788     const TypePtr* speculative = xmeet_speculative(tinst);
3789     int depth = meet_inline_depth(tinst->inline_depth());
3790 
3791     const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
3792     const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
3793     if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
3794       //
3795       // Meet unloaded class with java/lang/Object
3796       //
3797       // Meet
3798       //          |                     Unloaded Class
3799       //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
3800       //  ===================================================================
3801       //   TOP    | ..........................Unloaded......................|
3802       //  AnyNull |  U-AN    |................Unloaded......................|
3803       // Constant | ... O-NN .................................. |   O-BOT   |
3804       //  NotNull | ... O-NN .................................. |   O-BOT   |
3805       //  BOTTOM  | ........................Object-BOTTOM ..................|
3806       //
3807       assert(loaded->ptr() != TypePtr::Null, "insanity check");
3808       //
3809       if(      loaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
3810       else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make(ptr, unloaded->klass(), false, NULL, off, instance_id, speculative, depth); }
3811       else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
3812       else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
3813         if (unloaded->ptr() == TypePtr::BotPTR  ) { return TypeInstPtr::BOTTOM;  }
3814         else                                      { return TypeInstPtr::NOTNULL; }
3815       }
3816       else if( unloaded->ptr() == TypePtr::TopPTR )  { return unloaded; }
3817 
3818       return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr();
3819     }
3820 
3821     // Both are unloaded, not the same class, not Object
3822     // Or meet unloaded with a different loaded class, not java/lang/Object
3823     if( ptr != TypePtr::BotPTR ) {
3824       return TypeInstPtr::NOTNULL;
3825     }
3826     return TypeInstPtr::BOTTOM;
3827 }
3828 
3829 
3830 //------------------------------meet-------------------------------------------
3831 // Compute the MEET of two types.  It returns a new Type object.
3832 const Type *TypeInstPtr::xmeet_helper(const Type *t) const {
3833   // Perform a fast test for common case; meeting the same types together.
3834   if( this == t ) return this;  // Meeting same type-rep?
3835 
3836   // Current "this->_base" is Pointer
3837   switch (t->base()) {          // switch on original type
3838 
3839   case Int:                     // Mixing ints & oops happens when javac
3840   case Long:                    // reuses local variables
3841   case FloatTop:
3842   case FloatCon:
3843   case FloatBot:
3844   case DoubleTop:
3845   case DoubleCon:
3846   case DoubleBot:
3847   case NarrowOop:
3848   case NarrowKlass:
3849   case Bottom:                  // Ye Olde Default
3850     return Type::BOTTOM;
3851   case Top:
3852     return this;
3853 
3854   default:                      // All else is a mistake
3855     typerr(t);
3856 
3857   case MetadataPtr:
3858   case KlassPtr:
3859   case RawPtr: return TypePtr::BOTTOM;
3860 
3861   case AryPtr: {                // All arrays inherit from Object class
3862     const TypeAryPtr *tp = t->is_aryptr();
3863     Offset offset = meet_offset(tp->offset());
3864     PTR ptr = meet_ptr(tp->ptr());
3865     int instance_id = meet_instance_id(tp->instance_id());
3866     const TypePtr* speculative = xmeet_speculative(tp);
3867     int depth = meet_inline_depth(tp->inline_depth());
3868     switch (ptr) {
3869     case TopPTR:
3870     case AnyNull:                // Fall 'down' to dual of object klass
3871       // For instances when a subclass meets a superclass we fall
3872       // below the centerline when the superclass is exact. We need to
3873       // do the same here.
3874       if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
3875         return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, tp->field_offset(), instance_id, speculative, depth);
3876       } else {
3877         // cannot subclass, so the meet has to fall badly below the centerline
3878         ptr = NotNull;
3879         instance_id = InstanceBot;
3880         return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
3881       }
3882     case Constant:
3883     case NotNull:
3884     case BotPTR:                // Fall down to object klass
3885       // LCA is object_klass, but if we subclass from the top we can do better
3886       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
3887         // If 'this' (InstPtr) is above the centerline and it is Object class
3888         // then we can subclass in the Java class hierarchy.
3889         // For instances when a subclass meets a superclass we fall
3890         // below the centerline when the superclass is exact. We need
3891         // to do the same here.
3892         if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
3893           // that is, tp's array type is a subtype of my klass
3894           return TypeAryPtr::make(ptr, (ptr == Constant ? tp->const_oop() : NULL),
3895                                   tp->ary(), tp->klass(), tp->klass_is_exact(), offset, tp->field_offset(), instance_id, speculative, depth);
3896         }
3897       }
3898       // The other case cannot happen, since I cannot be a subtype of an array.
3899       // The meet falls down to Object class below centerline.
3900       if( ptr == Constant )
3901          ptr = NotNull;
3902       instance_id = InstanceBot;
3903       return make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
3904     default: typerr(t);
3905     }
3906   }
3907 
3908   case OopPtr: {                // Meeting to OopPtrs
3909     // Found a OopPtr type vs self-InstPtr type
3910     const TypeOopPtr *tp = t->is_oopptr();
3911     Offset offset = meet_offset(tp->offset());
3912     PTR ptr = meet_ptr(tp->ptr());
3913     switch (tp->ptr()) {
3914     case TopPTR:
3915     case AnyNull: {
3916       int instance_id = meet_instance_id(InstanceTop);
3917       const TypePtr* speculative = xmeet_speculative(tp);
3918       int depth = meet_inline_depth(tp->inline_depth());
3919       return make(ptr, klass(), klass_is_exact(),
3920                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth);
3921     }
3922     case NotNull:
3923     case BotPTR: {
3924       int instance_id = meet_instance_id(tp->instance_id());
3925       const TypePtr* speculative = xmeet_speculative(tp);
3926       int depth = meet_inline_depth(tp->inline_depth());
3927       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
3928     }
3929     default: typerr(t);
3930     }
3931   }
3932 
3933   case AnyPtr: {                // Meeting to AnyPtrs
3934     // Found an AnyPtr type vs self-InstPtr type
3935     const TypePtr *tp = t->is_ptr();
3936     Offset offset = meet_offset(tp->offset());
3937     PTR ptr = meet_ptr(tp->ptr());
3938     int instance_id = meet_instance_id(InstanceTop);
3939     const TypePtr* speculative = xmeet_speculative(tp);
3940     int depth = meet_inline_depth(tp->inline_depth());
3941     switch (tp->ptr()) {
3942     case Null:
3943       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3944       // else fall through to AnyNull
3945     case TopPTR:
3946     case AnyNull: {
3947       return make(ptr, klass(), klass_is_exact(),
3948                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth);
3949     }
3950     case NotNull:
3951     case BotPTR:
3952       return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
3953     default: typerr(t);
3954     }
3955   }
3956 
3957   /*
3958                  A-top         }
3959                /   |   \       }  Tops
3960            B-top A-any C-top   }
3961               | /  |  \ |      }  Any-nulls
3962            B-any   |   C-any   }
3963               |    |    |
3964            B-con A-con C-con   } constants; not comparable across classes
3965               |    |    |
3966            B-not   |   C-not   }
3967               | \  |  / |      }  not-nulls
3968            B-bot A-not C-bot   }
3969                \   |   /       }  Bottoms
3970                  A-bot         }
3971   */
3972 
3973   case InstPtr: {                // Meeting 2 Oops?
3974     // Found an InstPtr sub-type vs self-InstPtr type
3975     const TypeInstPtr *tinst = t->is_instptr();
3976     Offset off = meet_offset( tinst->offset() );
3977     PTR ptr = meet_ptr( tinst->ptr() );
3978     int instance_id = meet_instance_id(tinst->instance_id());
3979     const TypePtr* speculative = xmeet_speculative(tinst);
3980     int depth = meet_inline_depth(tinst->inline_depth());
3981 
3982     // Check for easy case; klasses are equal (and perhaps not loaded!)
3983     // If we have constants, then we created oops so classes are loaded
3984     // and we can handle the constants further down.  This case handles
3985     // both-not-loaded or both-loaded classes
3986     if (ptr != Constant && klass()->equals(tinst->klass()) && klass_is_exact() == tinst->klass_is_exact()) {
3987       return make(ptr, klass(), klass_is_exact(), NULL, off, instance_id, speculative, depth);
3988     }
3989 
3990     // Classes require inspection in the Java klass hierarchy.  Must be loaded.
3991     ciKlass* tinst_klass = tinst->klass();
3992     ciKlass* this_klass  = this->klass();
3993     bool tinst_xk = tinst->klass_is_exact();
3994     bool this_xk  = this->klass_is_exact();
3995     if (!tinst_klass->is_loaded() || !this_klass->is_loaded() ) {
3996       // One of these classes has not been loaded
3997       const TypeInstPtr *unloaded_meet = xmeet_unloaded(tinst);
3998 #ifndef PRODUCT
3999       if( PrintOpto && Verbose ) {
4000         tty->print("meet of unloaded classes resulted in: "); unloaded_meet->dump(); tty->cr();
4001         tty->print("  this == "); this->dump(); tty->cr();
4002         tty->print(" tinst == "); tinst->dump(); tty->cr();
4003       }
4004 #endif
4005       return unloaded_meet;
4006     }
4007 
4008     // Handle mixing oops and interfaces first.
4009     if( this_klass->is_interface() && !(tinst_klass->is_interface() ||
4010                                         tinst_klass == ciEnv::current()->Object_klass())) {
4011       ciKlass *tmp = tinst_klass; // Swap interface around
4012       tinst_klass = this_klass;
4013       this_klass = tmp;
4014       bool tmp2 = tinst_xk;
4015       tinst_xk = this_xk;
4016       this_xk = tmp2;
4017     }
4018     if (tinst_klass->is_interface() &&
4019         !(this_klass->is_interface() ||
4020           // Treat java/lang/Object as an honorary interface,
4021           // because we need a bottom for the interface hierarchy.
4022           this_klass == ciEnv::current()->Object_klass())) {
4023       // Oop meets interface!
4024 
4025       // See if the oop subtypes (implements) interface.
4026       ciKlass *k;
4027       bool xk;
4028       if( this_klass->is_subtype_of( tinst_klass ) ) {
4029         // Oop indeed subtypes.  Now keep oop or interface depending
4030         // on whether we are both above the centerline or either is
4031         // below the centerline.  If we are on the centerline
4032         // (e.g., Constant vs. AnyNull interface), use the constant.
4033         k  = below_centerline(ptr) ? tinst_klass : this_klass;
4034         // If we are keeping this_klass, keep its exactness too.
4035         xk = below_centerline(ptr) ? tinst_xk    : this_xk;
4036       } else {                  // Does not implement, fall to Object
4037         // Oop does not implement interface, so mixing falls to Object
4038         // just like the verifier does (if both are above the
4039         // centerline fall to interface)
4040         k = above_centerline(ptr) ? tinst_klass : ciEnv::current()->Object_klass();
4041         xk = above_centerline(ptr) ? tinst_xk : false;
4042         // Watch out for Constant vs. AnyNull interface.
4043         if (ptr == Constant)  ptr = NotNull;   // forget it was a constant
4044         instance_id = InstanceBot;
4045       }
4046       ciObject* o = NULL;  // the Constant value, if any
4047       if (ptr == Constant) {
4048         // Find out which constant.
4049         o = (this_klass == klass()) ? const_oop() : tinst->const_oop();
4050       }
4051       return make(ptr, k, xk, o, off, instance_id, speculative, depth);
4052     }
4053 
4054     // Either oop vs oop or interface vs interface or interface vs Object
4055 
4056     // !!! Here's how the symmetry requirement breaks down into invariants:
4057     // If we split one up & one down AND they subtype, take the down man.
4058     // If we split one up & one down AND they do NOT subtype, "fall hard".
4059     // If both are up and they subtype, take the subtype class.
4060     // If both are up and they do NOT subtype, "fall hard".
4061     // If both are down and they subtype, take the supertype class.
4062     // If both are down and they do NOT subtype, "fall hard".
4063     // Constants treated as down.
4064 
4065     // Now, reorder the above list; observe that both-down+subtype is also
4066     // "fall hard"; "fall hard" becomes the default case:
4067     // If we split one up & one down AND they subtype, take the down man.
4068     // If both are up and they subtype, take the subtype class.
4069 
4070     // If both are down and they subtype, "fall hard".
4071     // If both are down and they do NOT subtype, "fall hard".
4072     // If both are up and they do NOT subtype, "fall hard".
4073     // If we split one up & one down AND they do NOT subtype, "fall hard".
4074 
4075     // If a proper subtype is exact, and we return it, we return it exactly.
4076     // If a proper supertype is exact, there can be no subtyping relationship!
4077     // If both types are equal to the subtype, exactness is and-ed below the
4078     // centerline and or-ed above it.  (N.B. Constants are always exact.)
4079 
4080     // Check for subtyping:
4081     ciKlass *subtype = NULL;
4082     bool subtype_exact = false;
4083     if( tinst_klass->equals(this_klass) ) {
4084       subtype = this_klass;
4085       subtype_exact = below_centerline(ptr) ? (this_xk & tinst_xk) : (this_xk | tinst_xk);
4086     } else if( !tinst_xk && this_klass->is_subtype_of( tinst_klass ) ) {
4087       subtype = this_klass;     // Pick subtyping class
4088       subtype_exact = this_xk;
4089     } else if( !this_xk && tinst_klass->is_subtype_of( this_klass ) ) {
4090       subtype = tinst_klass;    // Pick subtyping class
4091       subtype_exact = tinst_xk;
4092     }
4093 
4094     if( subtype ) {
4095       if( above_centerline(ptr) ) { // both are up?
4096         this_klass = tinst_klass = subtype;
4097         this_xk = tinst_xk = subtype_exact;
4098       } else if( above_centerline(this ->_ptr) && !above_centerline(tinst->_ptr) ) {
4099         this_klass = tinst_klass; // tinst is down; keep down man
4100         this_xk = tinst_xk;
4101       } else if( above_centerline(tinst->_ptr) && !above_centerline(this ->_ptr) ) {
4102         tinst_klass = this_klass; // this is down; keep down man
4103         tinst_xk = this_xk;
4104       } else {
4105         this_xk = subtype_exact;  // either they are equal, or we'll do an LCA
4106       }
4107     }
4108 
4109     // Check for classes now being equal
4110     if (tinst_klass->equals(this_klass)) {
4111       // If the klasses are equal, the constants may still differ.  Fall to
4112       // NotNull if they do (neither constant is NULL; that is a special case
4113       // handled elsewhere).
4114       ciObject* o = NULL;             // Assume not constant when done
4115       ciObject* this_oop  = const_oop();
4116       ciObject* tinst_oop = tinst->const_oop();
4117       if( ptr == Constant ) {
4118         if (this_oop != NULL && tinst_oop != NULL &&
4119             this_oop->equals(tinst_oop) )
4120           o = this_oop;
4121         else if (above_centerline(this ->_ptr))
4122           o = tinst_oop;
4123         else if (above_centerline(tinst ->_ptr))
4124           o = this_oop;
4125         else
4126           ptr = NotNull;
4127       }
4128       return make(ptr, this_klass, this_xk, o, off, instance_id, speculative, depth);
4129     } // Else classes are not equal
4130 
4131     // Since klasses are different, we require a LCA in the Java
4132     // class hierarchy - which means we have to fall to at least NotNull.
4133     if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
4134       ptr = NotNull;
4135 
4136     instance_id = InstanceBot;
4137 
4138     // Now we find the LCA of Java classes
4139     ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
4140     return make(ptr, k, false, NULL, off, instance_id, speculative, depth);
4141   } // End of case InstPtr
4142 
4143   } // End of switch
4144   return this;                  // Return the double constant
4145 }
4146 
4147 
4148 //------------------------java_mirror_type--------------------------------------
4149 ciType* TypeInstPtr::java_mirror_type() const {
4150   // must be a singleton type
4151   if( const_oop() == NULL )  return NULL;
4152 
4153   // must be of type java.lang.Class
4154   if( klass() != ciEnv::current()->Class_klass() )  return NULL;
4155 
4156   return const_oop()->as_instance()->java_mirror_type();
4157 }
4158 
4159 
4160 //------------------------------xdual------------------------------------------
4161 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
4162 // inheritance mechanism.
4163 const Type *TypeInstPtr::xdual() const {
4164   return new TypeInstPtr(dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4165 }
4166 
4167 //------------------------------eq---------------------------------------------
4168 // Structural equality check for Type representations
4169 bool TypeInstPtr::eq( const Type *t ) const {
4170   const TypeInstPtr *p = t->is_instptr();
4171   return
4172     klass()->equals(p->klass()) &&
4173     TypeOopPtr::eq(p);          // Check sub-type stuff
4174 }
4175 
4176 //------------------------------hash-------------------------------------------
4177 // Type-specific hashing function.
4178 int TypeInstPtr::hash(void) const {
4179   int hash = java_add(klass()->hash(), TypeOopPtr::hash());
4180   return hash;
4181 }
4182 
4183 //------------------------------dump2------------------------------------------
4184 // Dump oop Type
4185 #ifndef PRODUCT
4186 void TypeInstPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4187   // Print the name of the klass.
4188   klass()->print_name_on(st);
4189 
4190   switch( _ptr ) {
4191   case Constant:
4192     // TO DO: Make CI print the hex address of the underlying oop.
4193     if (WizardMode || Verbose) {
4194       const_oop()->print_oop(st);
4195     }
4196   case BotPTR:
4197     if (!WizardMode && !Verbose) {
4198       if( _klass_is_exact ) st->print(":exact");
4199       break;
4200     }
4201   case TopPTR:
4202   case AnyNull:
4203   case NotNull:
4204     st->print(":%s", ptr_msg[_ptr]);
4205     if( _klass_is_exact ) st->print(":exact");
4206     break;
4207   }
4208 
4209   _offset.dump2(st);
4210 
4211   st->print(" *");
4212   if (_instance_id == InstanceTop)
4213     st->print(",iid=top");
4214   else if (_instance_id != InstanceBot)
4215     st->print(",iid=%d",_instance_id);
4216 
4217   dump_inline_depth(st);
4218   dump_speculative(st);
4219 }
4220 #endif
4221 
4222 //------------------------------add_offset-------------------------------------
4223 const TypePtr *TypeInstPtr::add_offset(intptr_t offset) const {
4224   return make(_ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset),
4225               _instance_id, add_offset_speculative(offset), _inline_depth);
4226 }
4227 
4228 const Type *TypeInstPtr::remove_speculative() const {
4229   if (_speculative == NULL) {
4230     return this;
4231   }
4232   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4233   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset,
4234               _instance_id, NULL, _inline_depth);
4235 }
4236 
4237 const TypePtr *TypeInstPtr::with_inline_depth(int depth) const {
4238   if (!UseInlineDepthForSpeculativeTypes) {
4239     return this;
4240   }
4241   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth);
4242 }
4243 
4244 //=============================================================================
4245 // Convenience common pre-built types.
4246 const TypeAryPtr *TypeAryPtr::RANGE;
4247 const TypeAryPtr *TypeAryPtr::OOPS;
4248 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
4249 const TypeAryPtr *TypeAryPtr::BYTES;
4250 const TypeAryPtr *TypeAryPtr::SHORTS;
4251 const TypeAryPtr *TypeAryPtr::CHARS;
4252 const TypeAryPtr *TypeAryPtr::INTS;
4253 const TypeAryPtr *TypeAryPtr::LONGS;
4254 const TypeAryPtr *TypeAryPtr::FLOATS;
4255 const TypeAryPtr *TypeAryPtr::DOUBLES;
4256 
4257 //------------------------------make-------------------------------------------
4258 const TypeAryPtr* TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4259                                    int instance_id, const TypePtr* speculative, int inline_depth) {
4260   assert(!(k == NULL && ary->_elem->isa_int()),
4261          "integral arrays must be pre-equipped with a class");
4262   if (!xk)  xk = ary->ary_must_be_exact();
4263   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
4264   if (!UseExactTypes)  xk = (ptr == Constant);
4265   return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, field_offset, instance_id, false, speculative, inline_depth))->hashcons();
4266 }
4267 
4268 //------------------------------make-------------------------------------------
4269 const TypeAryPtr* TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4270                                    int instance_id, const TypePtr* speculative, int inline_depth,
4271                                    bool is_autobox_cache) {
4272   assert(!(k == NULL && ary->_elem->isa_int()),
4273          "integral arrays must be pre-equipped with a class");
4274   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4275   if (!xk)  xk = (o != NULL) || ary->ary_must_be_exact();
4276   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
4277   if (!UseExactTypes)  xk = (ptr == Constant);
4278   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, field_offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4279 }
4280 
4281 //------------------------------cast_to_ptr_type-------------------------------
4282 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4283   if( ptr == _ptr ) return this;
4284   return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4285 }
4286 
4287 
4288 //-----------------------------cast_to_exactness-------------------------------
4289 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4290   if( klass_is_exact == _klass_is_exact ) return this;
4291   if (!UseExactTypes)  return this;
4292   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
4293   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4294 }
4295 
4296 //-----------------------------cast_to_instance_id----------------------------
4297 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const {
4298   if( instance_id == _instance_id ) return this;
4299   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth, _is_autobox_cache);
4300 }
4301 
4302 //-----------------------------narrow_size_type-------------------------------
4303 // Local cache for arrayOopDesc::max_array_length(etype),
4304 // which is kind of slow (and cached elsewhere by other users).
4305 static jint max_array_length_cache[T_CONFLICT+1];
4306 static jint max_array_length(BasicType etype) {
4307   jint& cache = max_array_length_cache[etype];
4308   jint res = cache;
4309   if (res == 0) {
4310     switch (etype) {
4311     case T_NARROWOOP:
4312       etype = T_OBJECT;
4313       break;
4314     case T_NARROWKLASS:
4315     case T_CONFLICT:
4316     case T_ILLEGAL:
4317     case T_VOID:
4318       etype = T_BYTE;           // will produce conservatively high value
4319     }
4320     cache = res = arrayOopDesc::max_array_length(etype);
4321   }
4322   return res;
4323 }
4324 
4325 // Narrow the given size type to the index range for the given array base type.
4326 // Return NULL if the resulting int type becomes empty.
4327 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const {
4328   jint hi = size->_hi;
4329   jint lo = size->_lo;
4330   jint min_lo = 0;
4331   jint max_hi = max_array_length(elem()->basic_type());
4332   //if (index_not_size)  --max_hi;     // type of a valid array index, FTR
4333   bool chg = false;
4334   if (lo < min_lo) {
4335     lo = min_lo;
4336     if (size->is_con()) {
4337       hi = lo;
4338     }
4339     chg = true;
4340   }
4341   if (hi > max_hi) {
4342     hi = max_hi;
4343     if (size->is_con()) {
4344       lo = hi;
4345     }
4346     chg = true;
4347   }
4348   // Negative length arrays will produce weird intermediate dead fast-path code
4349   if (lo > hi)
4350     return TypeInt::ZERO;
4351   if (!chg)
4352     return size;
4353   return TypeInt::make(lo, hi, Type::WidenMin);
4354 }
4355 
4356 //-------------------------------cast_to_size----------------------------------
4357 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4358   assert(new_size != NULL, "");
4359   new_size = narrow_size_type(new_size);
4360   if (new_size == size())  return this;
4361   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
4362   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4363 }
4364 
4365 //------------------------------cast_to_stable---------------------------------
4366 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
4367   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
4368     return this;
4369 
4370   const Type* elem = this->elem();
4371   const TypePtr* elem_ptr = elem->make_ptr();
4372 
4373   if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) {
4374     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
4375     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
4376   }
4377 
4378   const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
4379 
4380   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4381 }
4382 
4383 //-----------------------------stable_dimension--------------------------------
4384 int TypeAryPtr::stable_dimension() const {
4385   if (!is_stable())  return 0;
4386   int dim = 1;
4387   const TypePtr* elem_ptr = elem()->make_ptr();
4388   if (elem_ptr != NULL && elem_ptr->isa_aryptr())
4389     dim += elem_ptr->is_aryptr()->stable_dimension();
4390   return dim;
4391 }
4392 
4393 //----------------------cast_to_autobox_cache-----------------------------------
4394 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache(bool cache) const {
4395   if (is_autobox_cache() == cache)  return this;
4396   const TypeOopPtr* etype = elem()->make_oopptr();
4397   if (etype == NULL)  return this;
4398   // The pointers in the autobox arrays are always non-null.
4399   TypePtr::PTR ptr_type = cache ? TypePtr::NotNull : TypePtr::AnyNull;
4400   etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
4401   const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable());
4402   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, cache);
4403 }
4404 
4405 //------------------------------eq---------------------------------------------
4406 // Structural equality check for Type representations
4407 bool TypeAryPtr::eq( const Type *t ) const {
4408   const TypeAryPtr *p = t->is_aryptr();
4409   return
4410     _ary == p->_ary &&  // Check array
4411     TypeOopPtr::eq(p) &&// Check sub-parts
4412     _field_offset == p->_field_offset;
4413 }
4414 
4415 //------------------------------hash-------------------------------------------
4416 // Type-specific hashing function.
4417 int TypeAryPtr::hash(void) const {
4418   return (intptr_t)_ary + TypeOopPtr::hash() + _field_offset.get();
4419 }
4420 
4421 //------------------------------meet-------------------------------------------
4422 // Compute the MEET of two types.  It returns a new Type object.
4423 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
4424   // Perform a fast test for common case; meeting the same types together.
4425   if( this == t ) return this;  // Meeting same type-rep?
4426   // Current "this->_base" is Pointer
4427   switch (t->base()) {          // switch on original type
4428 
4429   // Mixing ints & oops happens when javac reuses local variables
4430   case Int:
4431   case Long:
4432   case FloatTop:
4433   case FloatCon:
4434   case FloatBot:
4435   case DoubleTop:
4436   case DoubleCon:
4437   case DoubleBot:
4438   case NarrowOop:
4439   case NarrowKlass:
4440   case Bottom:                  // Ye Olde Default
4441     return Type::BOTTOM;
4442   case Top:
4443     return this;
4444 
4445   default:                      // All else is a mistake
4446     typerr(t);
4447 
4448   case OopPtr: {                // Meeting to OopPtrs
4449     // Found a OopPtr type vs self-AryPtr type
4450     const TypeOopPtr *tp = t->is_oopptr();
4451     Offset offset = meet_offset(tp->offset());
4452     PTR ptr = meet_ptr(tp->ptr());
4453     int depth = meet_inline_depth(tp->inline_depth());
4454     const TypePtr* speculative = xmeet_speculative(tp);
4455     switch (tp->ptr()) {
4456     case TopPTR:
4457     case AnyNull: {
4458       int instance_id = meet_instance_id(InstanceTop);
4459       return make(ptr, (ptr == Constant ? const_oop() : NULL),
4460                   _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
4461     }
4462     case BotPTR:
4463     case NotNull: {
4464       int instance_id = meet_instance_id(tp->instance_id());
4465       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4466     }
4467     default: ShouldNotReachHere();
4468     }
4469   }
4470 
4471   case AnyPtr: {                // Meeting two AnyPtrs
4472     // Found an AnyPtr type vs self-AryPtr type
4473     const TypePtr *tp = t->is_ptr();
4474     Offset offset = meet_offset(tp->offset());
4475     PTR ptr = meet_ptr(tp->ptr());
4476     const TypePtr* speculative = xmeet_speculative(tp);
4477     int depth = meet_inline_depth(tp->inline_depth());
4478     switch (tp->ptr()) {
4479     case TopPTR:
4480       return this;
4481     case BotPTR:
4482     case NotNull:
4483       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4484     case Null:
4485       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4486       // else fall through to AnyNull
4487     case AnyNull: {
4488       int instance_id = meet_instance_id(InstanceTop);
4489       return make(ptr, (ptr == Constant ? const_oop() : NULL),
4490                   _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
4491     }
4492     default: ShouldNotReachHere();
4493     }
4494   }
4495 
4496   case MetadataPtr:
4497   case KlassPtr:
4498   case RawPtr: return TypePtr::BOTTOM;
4499 
4500   case AryPtr: {                // Meeting 2 references?
4501     const TypeAryPtr *tap = t->is_aryptr();
4502     Offset off = meet_offset(tap->offset());
4503     Offset field_off = meet_field_offset(tap->field_offset());
4504     const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
4505     PTR ptr = meet_ptr(tap->ptr());
4506     int instance_id = meet_instance_id(tap->instance_id());
4507     const TypePtr* speculative = xmeet_speculative(tap);
4508     int depth = meet_inline_depth(tap->inline_depth());
4509     ciKlass* lazy_klass = NULL;
4510     if (tary->_elem->isa_int()) {
4511       // Integral array element types have irrelevant lattice relations.
4512       // It is the klass that determines array layout, not the element type.
4513       if (_klass == NULL)
4514         lazy_klass = tap->_klass;
4515       else if (tap->_klass == NULL || tap->_klass == _klass) {
4516         lazy_klass = _klass;
4517       } else {
4518         // Something like byte[int+] meets char[int+].
4519         // This must fall to bottom, not (int[-128..65535])[int+].
4520         instance_id = InstanceBot;
4521         tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
4522       }
4523     } else // Non integral arrays.
4524       // Must fall to bottom if exact klasses in upper lattice
4525       // are not equal or super klass is exact.
4526       if ((above_centerline(ptr) || ptr == Constant) && klass() != tap->klass() &&
4527           // meet with top[] and bottom[] are processed further down:
4528           tap->_klass != NULL  && this->_klass != NULL   &&
4529           // both are exact and not equal:
4530           ((tap->_klass_is_exact && this->_klass_is_exact) ||
4531            // 'tap'  is exact and super or unrelated:
4532            (tap->_klass_is_exact && !tap->klass()->is_subtype_of(klass())) ||
4533            // 'this' is exact and super or unrelated:
4534            (this->_klass_is_exact && !klass()->is_subtype_of(tap->klass())))) {
4535       if (above_centerline(ptr)) {
4536         tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
4537       }
4538       return make(NotNull, NULL, tary, lazy_klass, false, off, field_off, InstanceBot, speculative, depth);
4539     }
4540 
4541     bool xk = false;
4542     switch (tap->ptr()) {
4543     case AnyNull:
4544     case TopPTR:
4545       // Compute new klass on demand, do not use tap->_klass
4546       if (below_centerline(this->_ptr)) {
4547         xk = this->_klass_is_exact;
4548       } else {
4549         xk = (tap->_klass_is_exact | this->_klass_is_exact);
4550       }
4551       return make(ptr, const_oop(), tary, lazy_klass, xk, off, field_off, instance_id, speculative, depth);
4552     case Constant: {
4553       ciObject* o = const_oop();
4554       if( _ptr == Constant ) {
4555         if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) {
4556           xk = (klass() == tap->klass());
4557           ptr = NotNull;
4558           o = NULL;
4559           instance_id = InstanceBot;
4560         } else {
4561           xk = true;
4562         }
4563       } else if(above_centerline(_ptr)) {
4564         o = tap->const_oop();
4565         xk = true;
4566       } else {
4567         // Only precise for identical arrays
4568         xk = this->_klass_is_exact && (klass() == tap->klass());
4569       }
4570       return TypeAryPtr::make(ptr, o, tary, lazy_klass, xk, off, field_off, instance_id, speculative, depth);
4571     }
4572     case NotNull:
4573     case BotPTR:
4574       // Compute new klass on demand, do not use tap->_klass
4575       if (above_centerline(this->_ptr))
4576             xk = tap->_klass_is_exact;
4577       else  xk = (tap->_klass_is_exact & this->_klass_is_exact) &&
4578               (klass() == tap->klass()); // Only precise for identical arrays
4579       return TypeAryPtr::make(ptr, NULL, tary, lazy_klass, xk, off, field_off, instance_id, speculative, depth);
4580     default: ShouldNotReachHere();
4581     }
4582   }
4583 
4584   // All arrays inherit from Object class
4585   case InstPtr: {
4586     const TypeInstPtr *tp = t->is_instptr();
4587     Offset offset = meet_offset(tp->offset());
4588     PTR ptr = meet_ptr(tp->ptr());
4589     int instance_id = meet_instance_id(tp->instance_id());
4590     const TypePtr* speculative = xmeet_speculative(tp);
4591     int depth = meet_inline_depth(tp->inline_depth());
4592     switch (ptr) {
4593     case TopPTR:
4594     case AnyNull:                // Fall 'down' to dual of object klass
4595       // For instances when a subclass meets a superclass we fall
4596       // below the centerline when the superclass is exact. We need to
4597       // do the same here.
4598       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
4599         return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
4600       } else {
4601         // cannot subclass, so the meet has to fall badly below the centerline
4602         ptr = NotNull;
4603         instance_id = InstanceBot;
4604         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
4605       }
4606     case Constant:
4607     case NotNull:
4608     case BotPTR:                // Fall down to object klass
4609       // LCA is object_klass, but if we subclass from the top we can do better
4610       if (above_centerline(tp->ptr())) {
4611         // If 'tp'  is above the centerline and it is Object class
4612         // then we can subclass in the Java class hierarchy.
4613         // For instances when a subclass meets a superclass we fall
4614         // below the centerline when the superclass is exact. We need
4615         // to do the same here.
4616         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
4617           // that is, my array type is a subtype of 'tp' klass
4618           return make(ptr, (ptr == Constant ? const_oop() : NULL),
4619                       _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
4620         }
4621       }
4622       // The other case cannot happen, since t cannot be a subtype of an array.
4623       // The meet falls down to Object class below centerline.
4624       if( ptr == Constant )
4625          ptr = NotNull;
4626       instance_id = InstanceBot;
4627       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative, depth);
4628     default: typerr(t);
4629     }
4630   }
4631   }
4632   return this;                  // Lint noise
4633 }
4634 
4635 //------------------------------xdual------------------------------------------
4636 // Dual: compute field-by-field dual
4637 const Type *TypeAryPtr::xdual() const {
4638   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());
4639 }
4640 
4641 Type::Offset TypeAryPtr::meet_field_offset(const Type::Offset offset) const {
4642   return _field_offset.meet(offset);
4643 }
4644 
4645 //------------------------------dual_offset------------------------------------
4646 Type::Offset TypeAryPtr::dual_field_offset() const {
4647   return _field_offset.dual();
4648 }
4649 
4650 //----------------------interface_vs_oop---------------------------------------
4651 #ifdef ASSERT
4652 bool TypeAryPtr::interface_vs_oop(const Type *t) const {
4653   const TypeAryPtr* t_aryptr = t->isa_aryptr();
4654   if (t_aryptr) {
4655     return _ary->interface_vs_oop(t_aryptr->_ary);
4656   }
4657   return false;
4658 }
4659 #endif
4660 
4661 //------------------------------dump2------------------------------------------
4662 #ifndef PRODUCT
4663 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4664   _ary->dump2(d,depth,st);
4665   switch( _ptr ) {
4666   case Constant:
4667     const_oop()->print(st);
4668     break;
4669   case BotPTR:
4670     if (!WizardMode && !Verbose) {
4671       if( _klass_is_exact ) st->print(":exact");
4672       break;
4673     }
4674   case TopPTR:
4675   case AnyNull:
4676   case NotNull:
4677     st->print(":%s", ptr_msg[_ptr]);
4678     if( _klass_is_exact ) st->print(":exact");
4679     break;
4680   }
4681 
4682   if (elem()->isa_valuetype()) {
4683     st->print("(");
4684     _field_offset.dump2(st);
4685     st->print(")");
4686   }
4687   if (offset() != 0) {
4688     int header_size = objArrayOopDesc::header_size() * wordSize;
4689     if( _offset == Offset::top )       st->print("+undefined");
4690     else if( _offset == Offset::bottom )  st->print("+any");
4691     else if( offset() < header_size ) st->print("+%d", offset());
4692     else {
4693       BasicType basic_elem_type = elem()->basic_type();
4694       int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
4695       int elem_size = type2aelembytes(basic_elem_type);
4696       st->print("[%d]", (offset() - array_base)/elem_size);
4697     }
4698   }
4699   st->print(" *");
4700   if (_instance_id == InstanceTop)
4701     st->print(",iid=top");
4702   else if (_instance_id != InstanceBot)
4703     st->print(",iid=%d",_instance_id);
4704 
4705   dump_inline_depth(st);
4706   dump_speculative(st);
4707 }
4708 #endif
4709 
4710 bool TypeAryPtr::empty(void) const {
4711   if (_ary->empty())       return true;
4712   return TypeOopPtr::empty();
4713 }
4714 
4715 //------------------------------add_offset-------------------------------------
4716 const TypePtr *TypeAryPtr::add_offset(intptr_t offset) const {
4717   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);
4718 }
4719 
4720 const Type *TypeAryPtr::remove_speculative() const {
4721   if (_speculative == NULL) {
4722     return this;
4723   }
4724   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4725   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);
4726 }
4727 
4728 const TypePtr *TypeAryPtr::with_inline_depth(int depth) const {
4729   if (!UseInlineDepthForSpeculativeTypes) {
4730     return this;
4731   }
4732   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, depth, _is_autobox_cache);
4733 }
4734 
4735 const TypeAryPtr* TypeAryPtr::with_field_offset(int offset) const {
4736   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);
4737 }
4738 
4739 const TypePtr* TypeAryPtr::with_field_offset_and_offset(intptr_t offset) const {
4740   if (offset != Type::OffsetBot) {
4741     const Type* elemtype = elem();
4742     if (elemtype->isa_valuetype()) {
4743       uint header = arrayOopDesc::base_offset_in_bytes(T_OBJECT);
4744       if (offset >= (intptr_t)header) {
4745         ciKlass* arytype_klass = klass();
4746         ciValueArrayKlass* vak = arytype_klass->as_value_array_klass();
4747         int shift = vak->log2_element_size();
4748         intptr_t field_offset = ((offset - header) & ((1 << shift) - 1));
4749 
4750         return with_field_offset(field_offset)->add_offset(offset - field_offset);
4751       }
4752     }
4753   }
4754   return add_offset(offset);
4755 }
4756 
4757 //=============================================================================
4758 
4759 
4760 //=============================================================================
4761 
4762 const TypeValueTypePtr* TypeValueTypePtr::NOTNULL;
4763 //------------------------------make-------------------------------------------
4764 const TypeValueTypePtr* TypeValueTypePtr::make(const TypeValueType* vt, PTR ptr, ciObject* o, Offset offset, int instance_id, const TypePtr* speculative, int inline_depth) {
4765   return (TypeValueTypePtr*)(new TypeValueTypePtr(vt, ptr, o, offset, instance_id, speculative, inline_depth))->hashcons();
4766 }
4767 
4768 const TypePtr* TypeValueTypePtr::add_offset(intptr_t offset) const {
4769   return make(_vt, _ptr, _const_oop, Offset(offset), _instance_id, _speculative, _inline_depth);
4770 }
4771 
4772 //------------------------------cast_to_ptr_type-------------------------------
4773 const Type* TypeValueTypePtr::cast_to_ptr_type(PTR ptr) const {
4774   if (ptr == _ptr) return this;
4775   return make(_vt, ptr, _const_oop, _offset, _instance_id, _speculative, _inline_depth);
4776 }
4777 
4778 //-----------------------------cast_to_instance_id----------------------------
4779 const TypeOopPtr* TypeValueTypePtr::cast_to_instance_id(int instance_id) const {
4780   if (instance_id == _instance_id) return this;
4781   return make(_vt, _ptr, _const_oop, _offset, instance_id, _speculative, _inline_depth);
4782 }
4783 
4784 //------------------------------meet-------------------------------------------
4785 // Compute the MEET of two types.  It returns a new Type object.
4786 const Type* TypeValueTypePtr::xmeet_helper(const Type* t) const {
4787   // Perform a fast test for common case; meeting the same types together.
4788   if (this == t) return this;  // Meeting same type-rep?
4789 
4790   switch (t->base()) {          // switch on original type
4791     case Int:                     // Mixing ints & oops happens when javac
4792     case Long:                    // reuses local variables
4793     case FloatTop:
4794     case FloatCon:
4795     case FloatBot:
4796     case DoubleTop:
4797     case DoubleCon:
4798     case DoubleBot:
4799     case NarrowOop:
4800     case NarrowKlass:
4801     case MetadataPtr:
4802     case KlassPtr:
4803     case RawPtr:
4804     case AryPtr:
4805     case InstPtr:
4806     case Bottom:                  // Ye Olde Default
4807       return Type::BOTTOM;
4808     case Top:
4809       return this;
4810 
4811     default:                      // All else is a mistake
4812       typerr(t);
4813 
4814     case OopPtr: {
4815       // Found a OopPtr type vs self-ValueTypePtr type
4816       const TypeOopPtr* tp = t->is_oopptr();
4817       Offset offset = meet_offset(tp->offset());
4818       PTR ptr = meet_ptr(tp->ptr());
4819       int instance_id = meet_instance_id(tp->instance_id());
4820       const TypePtr* speculative = xmeet_speculative(tp);
4821       int depth = meet_inline_depth(tp->inline_depth());
4822       switch (tp->ptr()) {
4823       case TopPTR:
4824       case AnyNull: {
4825         return make(_vt, ptr, NULL, offset, instance_id, speculative, depth);
4826       }
4827       case NotNull:
4828       case BotPTR: {
4829         return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4830       }
4831       default: typerr(t);
4832       }
4833     }
4834 
4835     case AnyPtr: {
4836       // Found an AnyPtr type vs self-ValueTypePtr type
4837       const TypePtr* tp = t->is_ptr();
4838       Offset offset = meet_offset(tp->offset());
4839       PTR ptr = meet_ptr(tp->ptr());
4840       int instance_id = meet_instance_id(InstanceTop);
4841       const TypePtr* speculative = xmeet_speculative(tp);
4842       int depth = meet_inline_depth(tp->inline_depth());
4843       switch (tp->ptr()) {
4844       case Null:
4845         if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4846         // else fall through to AnyNull
4847       case TopPTR:
4848       case AnyNull: {
4849         return make(_vt, ptr, NULL, offset, instance_id, speculative, depth);
4850       }
4851       case NotNull:
4852       case BotPTR:
4853         return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4854       default: typerr(t);
4855       }
4856     }
4857 
4858     case ValueTypePtr: {
4859       // Found an ValueTypePtr type vs self-ValueTypePtr type
4860       const TypeValueTypePtr* tp = t->is_valuetypeptr();
4861       Offset offset = meet_offset(tp->offset());
4862       PTR ptr = meet_ptr(tp->ptr());
4863       int instance_id = meet_instance_id(InstanceTop);
4864       const TypePtr* speculative = xmeet_speculative(tp);
4865       int depth = meet_inline_depth(tp->inline_depth());
4866       // Compute constant oop
4867       ciObject* o = NULL;
4868       ciObject* this_oop  = const_oop();
4869       ciObject* tp_oop = tp->const_oop();
4870       const TypeValueType* vt = NULL;
4871       if (_vt != tp->_vt) {
4872         ciKlass* __value_klass = ciEnv::current()->___Value_klass();
4873         assert(klass() == __value_klass || tp->klass() == __value_klass, "impossible meet");
4874         if (above_centerline(ptr)) {
4875           vt = klass() == __value_klass ? tp->_vt : _vt;
4876         } else if (above_centerline(this->_ptr) && !above_centerline(tp->_ptr)) {
4877           vt = tp->_vt;
4878         } else if (above_centerline(tp->_ptr) && !above_centerline(this->_ptr)) {
4879           vt = _vt;
4880         } else {
4881           vt = klass() == __value_klass ? _vt : tp->_vt;
4882         }
4883       } else {
4884         vt = _vt;
4885       }
4886       if (ptr == Constant) {
4887         if (this_oop != NULL && tp_oop != NULL &&
4888             this_oop->equals(tp_oop) ) {
4889           o = this_oop;
4890         } else if (above_centerline(this ->_ptr)) {
4891           o = tp_oop;
4892         } else if (above_centerline(tp ->_ptr)) {
4893           o = this_oop;
4894         } else {
4895           ptr = NotNull;
4896         }
4897       }
4898       return make(vt, ptr, o, offset, instance_id, speculative, depth);
4899     }
4900     }
4901 }
4902 
4903 // Dual: compute field-by-field dual
4904 const Type* TypeValueTypePtr::xdual() const {
4905   return new TypeValueTypePtr(_vt, dual_ptr(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4906 }
4907 
4908 //------------------------------eq---------------------------------------------
4909 // Structural equality check for Type representations
4910 bool TypeValueTypePtr::eq(const Type* t) const {
4911   const TypeValueTypePtr* p = t->is_valuetypeptr();
4912   return _vt->eq(p->value_type()) && TypeOopPtr::eq(p);
4913 }
4914 
4915 //------------------------------hash-------------------------------------------
4916 // Type-specific hashing function.
4917 int TypeValueTypePtr::hash(void) const {
4918   return java_add(_vt->hash(), TypeOopPtr::hash());
4919 }
4920 
4921 //------------------------------empty------------------------------------------
4922 // TRUE if Type is a type with no values, FALSE otherwise.
4923 bool TypeValueTypePtr::empty(void) const {
4924   // FIXME
4925   return false;
4926 }
4927 
4928 //------------------------------dump2------------------------------------------
4929 #ifndef PRODUCT
4930 void TypeValueTypePtr::dump2(Dict &d, uint depth, outputStream *st) const {
4931   st->print("valuetype* ");
4932   klass()->print_name_on(st);
4933   st->print(":%s", ptr_msg[_ptr]);
4934   _offset.dump2(st);
4935 }
4936 #endif
4937 
4938 //=============================================================================
4939 
4940 //------------------------------hash-------------------------------------------
4941 // Type-specific hashing function.
4942 int TypeNarrowPtr::hash(void) const {
4943   return _ptrtype->hash() + 7;
4944 }
4945 
4946 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
4947   return _ptrtype->singleton();
4948 }
4949 
4950 bool TypeNarrowPtr::empty(void) const {
4951   return _ptrtype->empty();
4952 }
4953 
4954 intptr_t TypeNarrowPtr::get_con() const {
4955   return _ptrtype->get_con();
4956 }
4957 
4958 bool TypeNarrowPtr::eq( const Type *t ) const {
4959   const TypeNarrowPtr* tc = isa_same_narrowptr(t);
4960   if (tc != NULL) {
4961     if (_ptrtype->base() != tc->_ptrtype->base()) {
4962       return false;
4963     }
4964     return tc->_ptrtype->eq(_ptrtype);
4965   }
4966   return false;
4967 }
4968 
4969 const Type *TypeNarrowPtr::xdual() const {    // Compute dual right now.
4970   const TypePtr* odual = _ptrtype->dual()->is_ptr();
4971   return make_same_narrowptr(odual);
4972 }
4973 
4974 
4975 const Type *TypeNarrowPtr::filter_helper(const Type *kills, bool include_speculative) const {
4976   if (isa_same_narrowptr(kills)) {
4977     const Type* ft =_ptrtype->filter_helper(is_same_narrowptr(kills)->_ptrtype, include_speculative);
4978     if (ft->empty())
4979       return Type::TOP;           // Canonical empty value
4980     if (ft->isa_ptr()) {
4981       return make_hash_same_narrowptr(ft->isa_ptr());
4982     }
4983     return ft;
4984   } else if (kills->isa_ptr()) {
4985     const Type* ft = _ptrtype->join_helper(kills, include_speculative);
4986     if (ft->empty())
4987       return Type::TOP;           // Canonical empty value
4988     return ft;
4989   } else {
4990     return Type::TOP;
4991   }
4992 }
4993 
4994 //------------------------------xmeet------------------------------------------
4995 // Compute the MEET of two types.  It returns a new Type object.
4996 const Type *TypeNarrowPtr::xmeet( const Type *t ) const {
4997   // Perform a fast test for common case; meeting the same types together.
4998   if( this == t ) return this;  // Meeting same type-rep?
4999 
5000   if (t->base() == base()) {
5001     const Type* result = _ptrtype->xmeet(t->make_ptr());
5002     if (result->isa_ptr()) {
5003       return make_hash_same_narrowptr(result->is_ptr());
5004     }
5005     return result;
5006   }
5007 
5008   // Current "this->_base" is NarrowKlass or NarrowOop
5009   switch (t->base()) {          // switch on original type
5010 
5011   case Int:                     // Mixing ints & oops happens when javac
5012   case Long:                    // reuses local variables
5013   case FloatTop:
5014   case FloatCon:
5015   case FloatBot:
5016   case DoubleTop:
5017   case DoubleCon:
5018   case DoubleBot:
5019   case AnyPtr:
5020   case RawPtr:
5021   case OopPtr:
5022   case InstPtr:
5023   case ValueTypePtr:
5024   case AryPtr:
5025   case MetadataPtr:
5026   case KlassPtr:
5027   case NarrowOop:
5028   case NarrowKlass:
5029 
5030   case Bottom:                  // Ye Olde Default
5031     return Type::BOTTOM;
5032   case Top:
5033     return this;
5034 
5035   default:                      // All else is a mistake
5036     typerr(t);
5037 
5038   } // End of switch
5039 
5040   return this;
5041 }
5042 
5043 #ifndef PRODUCT
5044 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5045   _ptrtype->dump2(d, depth, st);
5046 }
5047 #endif
5048 
5049 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
5050 const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
5051 
5052 
5053 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
5054   return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();
5055 }
5056 
5057 const Type* TypeNarrowOop::remove_speculative() const {
5058   return make(_ptrtype->remove_speculative()->is_ptr());
5059 }
5060 
5061 const Type* TypeNarrowOop::cleanup_speculative() const {
5062   return make(_ptrtype->cleanup_speculative()->is_ptr());
5063 }
5064 
5065 #ifndef PRODUCT
5066 void TypeNarrowOop::dump2( Dict & d, uint depth, outputStream *st ) const {
5067   st->print("narrowoop: ");
5068   TypeNarrowPtr::dump2(d, depth, st);
5069 }
5070 #endif
5071 
5072 const TypeNarrowKlass *TypeNarrowKlass::NULL_PTR;
5073 
5074 const TypeNarrowKlass* TypeNarrowKlass::make(const TypePtr* type) {
5075   return (const TypeNarrowKlass*)(new TypeNarrowKlass(type))->hashcons();
5076 }
5077 
5078 #ifndef PRODUCT
5079 void TypeNarrowKlass::dump2( Dict & d, uint depth, outputStream *st ) const {
5080   st->print("narrowklass: ");
5081   TypeNarrowPtr::dump2(d, depth, st);
5082 }
5083 #endif
5084 
5085 
5086 //------------------------------eq---------------------------------------------
5087 // Structural equality check for Type representations
5088 bool TypeMetadataPtr::eq( const Type *t ) const {
5089   const TypeMetadataPtr *a = (const TypeMetadataPtr*)t;
5090   ciMetadata* one = metadata();
5091   ciMetadata* two = a->metadata();
5092   if (one == NULL || two == NULL) {
5093     return (one == two) && TypePtr::eq(t);
5094   } else {
5095     return one->equals(two) && TypePtr::eq(t);
5096   }
5097 }
5098 
5099 //------------------------------hash-------------------------------------------
5100 // Type-specific hashing function.
5101 int TypeMetadataPtr::hash(void) const {
5102   return
5103     (metadata() ? metadata()->hash() : 0) +
5104     TypePtr::hash();
5105 }
5106 
5107 //------------------------------singleton--------------------------------------
5108 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5109 // constants
5110 bool TypeMetadataPtr::singleton(void) const {
5111   // detune optimizer to not generate constant metadata + constant offset as a constant!
5112   // TopPTR, Null, AnyNull, Constant are all singletons
5113   return (offset() == 0) && !below_centerline(_ptr);
5114 }
5115 
5116 //------------------------------add_offset-------------------------------------
5117 const TypePtr *TypeMetadataPtr::add_offset( intptr_t offset ) const {
5118   return make( _ptr, _metadata, xadd_offset(offset));
5119 }
5120 
5121 //-----------------------------filter------------------------------------------
5122 // Do not allow interface-vs.-noninterface joins to collapse to top.
5123 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
5124   const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
5125   if (ft == NULL || ft->empty())
5126     return Type::TOP;           // Canonical empty value
5127   return ft;
5128 }
5129 
5130  //------------------------------get_con----------------------------------------
5131 intptr_t TypeMetadataPtr::get_con() const {
5132   assert( _ptr == Null || _ptr == Constant, "" );
5133   assert(offset() >= 0, "");
5134 
5135   if (offset() != 0) {
5136     // After being ported to the compiler interface, the compiler no longer
5137     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5138     // to a handle at compile time.  This handle is embedded in the generated
5139     // code and dereferenced at the time the nmethod is made.  Until that time,
5140     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5141     // have access to the addresses!).  This does not seem to currently happen,
5142     // but this assertion here is to help prevent its occurence.
5143     tty->print_cr("Found oop constant with non-zero offset");
5144     ShouldNotReachHere();
5145   }
5146 
5147   return (intptr_t)metadata()->constant_encoding();
5148 }
5149 
5150 //------------------------------cast_to_ptr_type-------------------------------
5151 const Type *TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
5152   if( ptr == _ptr ) return this;
5153   return make(ptr, metadata(), _offset);
5154 }
5155 
5156 //------------------------------meet-------------------------------------------
5157 // Compute the MEET of two types.  It returns a new Type object.
5158 const Type *TypeMetadataPtr::xmeet( const Type *t ) const {
5159   // Perform a fast test for common case; meeting the same types together.
5160   if( this == t ) return this;  // Meeting same type-rep?
5161 
5162   // Current "this->_base" is OopPtr
5163   switch (t->base()) {          // switch on original type
5164 
5165   case Int:                     // Mixing ints & oops happens when javac
5166   case Long:                    // reuses local variables
5167   case FloatTop:
5168   case FloatCon:
5169   case FloatBot:
5170   case DoubleTop:
5171   case DoubleCon:
5172   case DoubleBot:
5173   case NarrowOop:
5174   case NarrowKlass:
5175   case Bottom:                  // Ye Olde Default
5176     return Type::BOTTOM;
5177   case Top:
5178     return this;
5179 
5180   default:                      // All else is a mistake
5181     typerr(t);
5182 
5183   case AnyPtr: {
5184     // Found an AnyPtr type vs self-OopPtr type
5185     const TypePtr *tp = t->is_ptr();
5186     Offset offset = meet_offset(tp->offset());
5187     PTR ptr = meet_ptr(tp->ptr());
5188     switch (tp->ptr()) {
5189     case Null:
5190       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5191       // else fall through:
5192     case TopPTR:
5193     case AnyNull: {
5194       return make(ptr, _metadata, offset);
5195     }
5196     case BotPTR:
5197     case NotNull:
5198       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5199     default: typerr(t);
5200     }
5201   }
5202 
5203   case RawPtr:
5204   case KlassPtr:
5205   case OopPtr:
5206   case InstPtr:
5207   case ValueTypePtr:
5208   case AryPtr:
5209     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
5210 
5211   case MetadataPtr: {
5212     const TypeMetadataPtr *tp = t->is_metadataptr();
5213     Offset offset = meet_offset(tp->offset());
5214     PTR tptr = tp->ptr();
5215     PTR ptr = meet_ptr(tptr);
5216     ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
5217     if (tptr == TopPTR || _ptr == TopPTR ||
5218         metadata()->equals(tp->metadata())) {
5219       return make(ptr, md, offset);
5220     }
5221     // metadata is different
5222     if( ptr == Constant ) {  // Cannot be equal constants, so...
5223       if( tptr == Constant && _ptr != Constant)  return t;
5224       if( _ptr == Constant && tptr != Constant)  return this;
5225       ptr = NotNull;            // Fall down in lattice
5226     }
5227     return make(ptr, NULL, offset);
5228     break;
5229   }
5230   } // End of switch
5231   return this;                  // Return the double constant
5232 }
5233 
5234 
5235 //------------------------------xdual------------------------------------------
5236 // Dual of a pure metadata pointer.
5237 const Type *TypeMetadataPtr::xdual() const {
5238   return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
5239 }
5240 
5241 //------------------------------dump2------------------------------------------
5242 #ifndef PRODUCT
5243 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5244   st->print("metadataptr:%s", ptr_msg[_ptr]);
5245   if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata()));
5246   switch (offset()) {
5247   case OffsetTop: st->print("+top"); break;
5248   case OffsetBot: st->print("+any"); break;
5249   case         0: break;
5250   default:        st->print("+%d",offset()); break;
5251   }
5252 }
5253 #endif
5254 
5255 
5256 //=============================================================================
5257 // Convenience common pre-built type.
5258 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
5259 
5260 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, Offset offset):
5261   TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
5262 }
5263 
5264 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
5265   return make(Constant, m, Offset(0));
5266 }
5267 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
5268   return make(Constant, m, Offset(0));
5269 }
5270 
5271 //------------------------------make-------------------------------------------
5272 // Create a meta data constant
5273 const TypeMetadataPtr* TypeMetadataPtr::make(PTR ptr, ciMetadata* m, Offset offset) {
5274   assert(m == NULL || !m->is_klass(), "wrong type");
5275   return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
5276 }
5277 
5278 
5279 //=============================================================================
5280 // Convenience common pre-built types.
5281 
5282 // Not-null object klass or below
5283 const TypeKlassPtr *TypeKlassPtr::OBJECT;
5284 const TypeKlassPtr *TypeKlassPtr::OBJECT_OR_NULL;
5285 
5286 //------------------------------TypeKlassPtr-----------------------------------
5287 TypeKlassPtr::TypeKlassPtr( PTR ptr, ciKlass* klass, Offset offset )
5288   : TypePtr(KlassPtr, ptr, offset), _klass(klass), _klass_is_exact(ptr == Constant) {
5289 }
5290 
5291 //------------------------------make-------------------------------------------
5292 // ptr to klass 'k', if Constant, or possibly to a sub-klass if not a Constant
5293 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* k, Offset offset) {
5294   assert( k != NULL, "Expect a non-NULL klass");
5295   assert(k->is_instance_klass() || k->is_array_klass(), "Incorrect type of klass oop");
5296   TypeKlassPtr *r =
5297     (TypeKlassPtr*)(new TypeKlassPtr(ptr, k, offset))->hashcons();
5298 
5299   return r;
5300 }
5301 
5302 //------------------------------eq---------------------------------------------
5303 // Structural equality check for Type representations
5304 bool TypeKlassPtr::eq( const Type *t ) const {
5305   const TypeKlassPtr *p = t->is_klassptr();
5306   return
5307     klass()->equals(p->klass()) &&
5308     TypePtr::eq(p);
5309 }
5310 
5311 //------------------------------hash-------------------------------------------
5312 // Type-specific hashing function.
5313 int TypeKlassPtr::hash(void) const {
5314   return java_add(klass()->hash(), TypePtr::hash());
5315 }
5316 
5317 //------------------------------singleton--------------------------------------
5318 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5319 // constants
5320 bool TypeKlassPtr::singleton(void) const {
5321   // detune optimizer to not generate constant klass + constant offset as a constant!
5322   // TopPTR, Null, AnyNull, Constant are all singletons
5323   return (offset() == 0) && !below_centerline(_ptr);
5324 }
5325 
5326 // Do not allow interface-vs.-noninterface joins to collapse to top.
5327 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
5328   // logic here mirrors the one from TypeOopPtr::filter. See comments
5329   // there.
5330   const Type* ft = join_helper(kills, include_speculative);
5331   const TypeKlassPtr* ftkp = ft->isa_klassptr();
5332   const TypeKlassPtr* ktkp = kills->isa_klassptr();
5333 
5334   if (ft->empty()) {
5335     if (!empty() && ktkp != NULL && ktkp->klass()->is_loaded() && ktkp->klass()->is_interface())
5336       return kills;             // Uplift to interface
5337 
5338     return Type::TOP;           // Canonical empty value
5339   }
5340 
5341   // Interface klass type could be exact in opposite to interface type,
5342   // return it here instead of incorrect Constant ptr J/L/Object (6894807).
5343   if (ftkp != NULL && ktkp != NULL &&
5344       ftkp->is_loaded() &&  ftkp->klass()->is_interface() &&
5345       !ftkp->klass_is_exact() && // Keep exact interface klass
5346       ktkp->is_loaded() && !ktkp->klass()->is_interface()) {
5347     return ktkp->cast_to_ptr_type(ftkp->ptr());
5348   }
5349 
5350   return ft;
5351 }
5352 
5353 //----------------------compute_klass------------------------------------------
5354 // Compute the defining klass for this class
5355 ciKlass* TypeAryPtr::compute_klass(DEBUG_ONLY(bool verify)) const {
5356   // Compute _klass based on element type.
5357   ciKlass* k_ary = NULL;
5358   const TypeAryPtr *tary;
5359   const Type* el = elem();
5360   if (el->isa_narrowoop()) {
5361     el = el->make_ptr();
5362   }
5363 
5364   // Get element klass
5365   if (el->isa_instptr() || el->isa_valuetypeptr()) {
5366     // Compute object array klass from element klass
5367     k_ary = ciArrayKlass::make(el->is_oopptr()->klass());
5368   } else if (el->isa_valuetype()) {
5369     k_ary = ciArrayKlass::make(el->is_valuetype()->value_klass());
5370   } else if ((tary = el->isa_aryptr()) != NULL) {
5371     // Compute array klass from element klass
5372     ciKlass* k_elem = tary->klass();
5373     // If element type is something like bottom[], k_elem will be null.
5374     if (k_elem != NULL)
5375       k_ary = ciObjArrayKlass::make(k_elem);
5376   } else if ((el->base() == Type::Top) ||
5377              (el->base() == Type::Bottom)) {
5378     // element type of Bottom occurs from meet of basic type
5379     // and object; Top occurs when doing join on Bottom.
5380     // Leave k_ary at NULL.
5381   } else {
5382     // Cannot compute array klass directly from basic type,
5383     // since subtypes of TypeInt all have basic type T_INT.
5384 #ifdef ASSERT
5385     if (verify && el->isa_int()) {
5386       // Check simple cases when verifying klass.
5387       BasicType bt = T_ILLEGAL;
5388       if (el == TypeInt::BYTE) {
5389         bt = T_BYTE;
5390       } else if (el == TypeInt::SHORT) {
5391         bt = T_SHORT;
5392       } else if (el == TypeInt::CHAR) {
5393         bt = T_CHAR;
5394       } else if (el == TypeInt::INT) {
5395         bt = T_INT;
5396       } else {
5397         return _klass; // just return specified klass
5398       }
5399       return ciTypeArrayKlass::make(bt);
5400     }
5401 #endif
5402     assert(!el->isa_int(),
5403            "integral arrays must be pre-equipped with a class");
5404     // Compute array klass directly from basic type
5405     k_ary = ciTypeArrayKlass::make(el->basic_type());
5406   }
5407   return k_ary;
5408 }
5409 
5410 //------------------------------klass------------------------------------------
5411 // Return the defining klass for this class
5412 ciKlass* TypeAryPtr::klass() const {
5413   if( _klass ) return _klass;   // Return cached value, if possible
5414 
5415   // Oops, need to compute _klass and cache it
5416   ciKlass* k_ary = compute_klass();
5417 
5418   if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) {
5419     // The _klass field acts as a cache of the underlying
5420     // ciKlass for this array type.  In order to set the field,
5421     // we need to cast away const-ness.
5422     //
5423     // IMPORTANT NOTE: we *never* set the _klass field for the
5424     // type TypeAryPtr::OOPS.  This Type is shared between all
5425     // active compilations.  However, the ciKlass which represents
5426     // this Type is *not* shared between compilations, so caching
5427     // this value would result in fetching a dangling pointer.
5428     //
5429     // Recomputing the underlying ciKlass for each request is
5430     // a bit less efficient than caching, but calls to
5431     // TypeAryPtr::OOPS->klass() are not common enough to matter.
5432     ((TypeAryPtr*)this)->_klass = k_ary;
5433     if (UseCompressedOops && k_ary != NULL && k_ary->is_obj_array_klass() &&
5434         offset() != 0 && offset() != arrayOopDesc::length_offset_in_bytes()) {
5435       ((TypeAryPtr*)this)->_is_ptr_to_narrowoop = true;
5436     }
5437   }
5438   return k_ary;
5439 }
5440 
5441 
5442 //------------------------------add_offset-------------------------------------
5443 // Access internals of klass object
5444 const TypePtr *TypeKlassPtr::add_offset( intptr_t offset ) const {
5445   return make( _ptr, klass(), xadd_offset(offset) );
5446 }
5447 
5448 //------------------------------cast_to_ptr_type-------------------------------
5449 const Type *TypeKlassPtr::cast_to_ptr_type(PTR ptr) const {
5450   assert(_base == KlassPtr, "subclass must override cast_to_ptr_type");
5451   if( ptr == _ptr ) return this;
5452   return make(ptr, _klass, _offset);
5453 }
5454 
5455 
5456 //-----------------------------cast_to_exactness-------------------------------
5457 const Type *TypeKlassPtr::cast_to_exactness(bool klass_is_exact) const {
5458   if( klass_is_exact == _klass_is_exact ) return this;
5459   if (!UseExactTypes)  return this;
5460   return make(klass_is_exact ? Constant : NotNull, _klass, _offset);
5461 }
5462 
5463 
5464 //-----------------------------as_instance_type--------------------------------
5465 // Corresponding type for an instance of the given class.
5466 // It will be NotNull, and exact if and only if the klass type is exact.
5467 const TypeOopPtr* TypeKlassPtr::as_instance_type() const {
5468   ciKlass* k = klass();
5469   bool    xk = klass_is_exact();
5470   //return TypeInstPtr::make(TypePtr::NotNull, k, xk, NULL, 0);
5471   const TypeOopPtr* toop = TypeOopPtr::make_from_klass_raw(k);
5472   guarantee(toop != NULL, "need type for given klass");
5473   toop = toop->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
5474   return toop->cast_to_exactness(xk)->is_oopptr();
5475 }
5476 
5477 
5478 //------------------------------xmeet------------------------------------------
5479 // Compute the MEET of two types, return a new Type object.
5480 const Type    *TypeKlassPtr::xmeet( const Type *t ) const {
5481   // Perform a fast test for common case; meeting the same types together.
5482   if( this == t ) return this;  // Meeting same type-rep?
5483 
5484   // Current "this->_base" is Pointer
5485   switch (t->base()) {          // switch on original type
5486 
5487   case Int:                     // Mixing ints & oops happens when javac
5488   case Long:                    // reuses local variables
5489   case FloatTop:
5490   case FloatCon:
5491   case FloatBot:
5492   case DoubleTop:
5493   case DoubleCon:
5494   case DoubleBot:
5495   case NarrowOop:
5496   case NarrowKlass:
5497   case Bottom:                  // Ye Olde Default
5498     return Type::BOTTOM;
5499   case Top:
5500     return this;
5501 
5502   default:                      // All else is a mistake
5503     typerr(t);
5504 
5505   case AnyPtr: {                // Meeting to AnyPtrs
5506     // Found an AnyPtr type vs self-KlassPtr type
5507     const TypePtr *tp = t->is_ptr();
5508     Offset offset = meet_offset(tp->offset());
5509     PTR ptr = meet_ptr(tp->ptr());
5510     switch (tp->ptr()) {
5511     case TopPTR:
5512       return this;
5513     case Null:
5514       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5515     case AnyNull:
5516       return make( ptr, klass(), offset );
5517     case BotPTR:
5518     case NotNull:
5519       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5520     default: typerr(t);
5521     }
5522   }
5523 
5524   case RawPtr:
5525   case MetadataPtr:
5526   case OopPtr:
5527   case AryPtr:                  // Meet with AryPtr
5528   case InstPtr:                 // Meet with InstPtr
5529   case ValueTypePtr:
5530     return TypePtr::BOTTOM;
5531 
5532   //
5533   //             A-top         }
5534   //           /   |   \       }  Tops
5535   //       B-top A-any C-top   }
5536   //          | /  |  \ |      }  Any-nulls
5537   //       B-any   |   C-any   }
5538   //          |    |    |
5539   //       B-con A-con C-con   } constants; not comparable across classes
5540   //          |    |    |
5541   //       B-not   |   C-not   }
5542   //          | \  |  / |      }  not-nulls
5543   //       B-bot A-not C-bot   }
5544   //           \   |   /       }  Bottoms
5545   //             A-bot         }
5546   //
5547 
5548   case KlassPtr: {  // Meet two KlassPtr types
5549     const TypeKlassPtr *tkls = t->is_klassptr();
5550     Offset  off  = meet_offset(tkls->offset());
5551     PTR  ptr     = meet_ptr(tkls->ptr());
5552 
5553     // Check for easy case; klasses are equal (and perhaps not loaded!)
5554     // If we have constants, then we created oops so classes are loaded
5555     // and we can handle the constants further down.  This case handles
5556     // not-loaded classes
5557     if( ptr != Constant && tkls->klass()->equals(klass()) ) {
5558       return make( ptr, klass(), off );
5559     }
5560 
5561     // Classes require inspection in the Java klass hierarchy.  Must be loaded.
5562     ciKlass* tkls_klass = tkls->klass();
5563     ciKlass* this_klass = this->klass();
5564     assert( tkls_klass->is_loaded(), "This class should have been loaded.");
5565     assert( this_klass->is_loaded(), "This class should have been loaded.");
5566 
5567     // If 'this' type is above the centerline and is a superclass of the
5568     // other, we can treat 'this' as having the same type as the other.
5569     if ((above_centerline(this->ptr())) &&
5570         tkls_klass->is_subtype_of(this_klass)) {
5571       this_klass = tkls_klass;
5572     }
5573     // If 'tinst' type is above the centerline and is a superclass of the
5574     // other, we can treat 'tinst' as having the same type as the other.
5575     if ((above_centerline(tkls->ptr())) &&
5576         this_klass->is_subtype_of(tkls_klass)) {
5577       tkls_klass = this_klass;
5578     }
5579 
5580     // Check for classes now being equal
5581     if (tkls_klass->equals(this_klass)) {
5582       // If the klasses are equal, the constants may still differ.  Fall to
5583       // NotNull if they do (neither constant is NULL; that is a special case
5584       // handled elsewhere).
5585       if( ptr == Constant ) {
5586         if (this->_ptr == Constant && tkls->_ptr == Constant &&
5587             this->klass()->equals(tkls->klass()));
5588         else if (above_centerline(this->ptr()));
5589         else if (above_centerline(tkls->ptr()));
5590         else
5591           ptr = NotNull;
5592       }
5593       return make( ptr, this_klass, off );
5594     } // Else classes are not equal
5595 
5596     // Since klasses are different, we require the LCA in the Java
5597     // class hierarchy - which means we have to fall to at least NotNull.
5598     if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
5599       ptr = NotNull;
5600     // Now we find the LCA of Java classes
5601     ciKlass* k = this_klass->least_common_ancestor(tkls_klass);
5602     return   make( ptr, k, off );
5603   } // End of case KlassPtr
5604 
5605   } // End of switch
5606   return this;                  // Return the double constant
5607 }
5608 
5609 //------------------------------xdual------------------------------------------
5610 // Dual: compute field-by-field dual
5611 const Type    *TypeKlassPtr::xdual() const {
5612   return new TypeKlassPtr( dual_ptr(), klass(), dual_offset() );
5613 }
5614 
5615 //------------------------------get_con----------------------------------------
5616 intptr_t TypeKlassPtr::get_con() const {
5617   assert( _ptr == Null || _ptr == Constant, "" );
5618   assert(offset() >= 0, "");
5619 
5620   if (offset() != 0) {
5621     // After being ported to the compiler interface, the compiler no longer
5622     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5623     // to a handle at compile time.  This handle is embedded in the generated
5624     // code and dereferenced at the time the nmethod is made.  Until that time,
5625     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5626     // have access to the addresses!).  This does not seem to currently happen,
5627     // but this assertion here is to help prevent its occurence.
5628     tty->print_cr("Found oop constant with non-zero offset");
5629     ShouldNotReachHere();
5630   }
5631 
5632   return (intptr_t)klass()->constant_encoding();
5633 }
5634 //------------------------------dump2------------------------------------------
5635 // Dump Klass Type
5636 #ifndef PRODUCT
5637 void TypeKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5638   switch( _ptr ) {
5639   case Constant:
5640     st->print("precise ");
5641   case NotNull:
5642     {
5643       const char *name = klass()->name()->as_utf8();
5644       if( name ) {
5645         st->print("klass %s: " INTPTR_FORMAT, name, p2i(klass()));
5646       } else {
5647         ShouldNotReachHere();
5648       }
5649     }
5650   case BotPTR:
5651     if( !WizardMode && !Verbose && !_klass_is_exact ) break;
5652   case TopPTR:
5653   case AnyNull:
5654     st->print(":%s", ptr_msg[_ptr]);
5655     if( _klass_is_exact ) st->print(":exact");
5656     break;
5657   }
5658 
5659   _offset.dump2(st);
5660 
5661   st->print(" *");
5662 }
5663 #endif
5664 
5665 
5666 
5667 //=============================================================================
5668 // Convenience common pre-built types.
5669 
5670 //------------------------------make-------------------------------------------
5671 const TypeFunc *TypeFunc::make(const TypeTuple *domain_sig, const TypeTuple* domain_cc,
5672                                const TypeTuple *range_sig, const TypeTuple *range_cc) {
5673   return (TypeFunc*)(new TypeFunc(domain_sig, domain_cc, range_sig, range_cc))->hashcons();
5674 }
5675 
5676 const TypeFunc *TypeFunc::make(const TypeTuple *domain, const TypeTuple *range) {
5677   return make(domain, domain, range, range);
5678 }
5679 
5680 //------------------------------make-------------------------------------------
5681 const TypeFunc *TypeFunc::make(ciMethod* method) {
5682   Compile* C = Compile::current();
5683   const TypeFunc* tf = C->last_tf(method); // check cache
5684   if (tf != NULL)  return tf;  // The hit rate here is almost 50%.
5685   const TypeTuple *domain_sig, *domain_cc;
5686   // Value type arguments are not passed by reference, instead each
5687   // field of the value type is passed as an argument. We maintain 2
5688   // views of the argument list here: one based on the signature (with
5689   // a value type argument as a single slot), one based on the actual
5690   // calling convention (with a value type argument as a list of its
5691   // fields).
5692   if (method->is_static()) {
5693     domain_sig = TypeTuple::make_domain(NULL, method->signature(), false);
5694     domain_cc = TypeTuple::make_domain(NULL, method->signature(), ValueTypePassFieldsAsArgs);
5695   } else {
5696     domain_sig = TypeTuple::make_domain(method->holder(), method->signature(), false);
5697     domain_cc = TypeTuple::make_domain(method->holder(), method->signature(), ValueTypePassFieldsAsArgs);
5698   }
5699   const TypeTuple *range_sig = TypeTuple::make_range(method->signature(), false);
5700   const TypeTuple *range_cc = TypeTuple::make_range(method->signature(), ValueTypeReturnedAsFields);
5701   tf = TypeFunc::make(domain_sig, domain_cc, range_sig, range_cc);
5702   C->set_last_tf(method, tf);  // fill cache
5703   return tf;
5704 }
5705 
5706 //------------------------------meet-------------------------------------------
5707 // Compute the MEET of two types.  It returns a new Type object.
5708 const Type *TypeFunc::xmeet( const Type *t ) const {
5709   // Perform a fast test for common case; meeting the same types together.
5710   if( this == t ) return this;  // Meeting same type-rep?
5711 
5712   // Current "this->_base" is Func
5713   switch (t->base()) {          // switch on original type
5714 
5715   case Bottom:                  // Ye Olde Default
5716     return t;
5717 
5718   default:                      // All else is a mistake
5719     typerr(t);
5720 
5721   case Top:
5722     break;
5723   }
5724   return this;                  // Return the double constant
5725 }
5726 
5727 //------------------------------xdual------------------------------------------
5728 // Dual: compute field-by-field dual
5729 const Type *TypeFunc::xdual() const {
5730   return this;
5731 }
5732 
5733 //------------------------------eq---------------------------------------------
5734 // Structural equality check for Type representations
5735 bool TypeFunc::eq( const Type *t ) const {
5736   const TypeFunc *a = (const TypeFunc*)t;
5737   return _domain_sig == a->_domain_sig &&
5738     _domain_cc == a->_domain_cc &&
5739     _range_sig == a->_range_sig &&
5740     _range_cc == a->_range_cc;
5741 }
5742 
5743 //------------------------------hash-------------------------------------------
5744 // Type-specific hashing function.
5745 int TypeFunc::hash(void) const {
5746   return (intptr_t)_domain_sig + (intptr_t)_domain_cc + (intptr_t)_range_sig + (intptr_t)_range_cc;
5747 }
5748 
5749 //------------------------------dump2------------------------------------------
5750 // Dump Function Type
5751 #ifndef PRODUCT
5752 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
5753   if( _range_sig->cnt() <= Parms )
5754     st->print("void");
5755   else {
5756     uint i;
5757     for (i = Parms; i < _range_sig->cnt()-1; i++) {
5758       _range_sig->field_at(i)->dump2(d,depth,st);
5759       st->print("/");
5760     }
5761     _range_sig->field_at(i)->dump2(d,depth,st);
5762   }
5763   st->print(" ");
5764   st->print("( ");
5765   if( !depth || d[this] ) {     // Check for recursive dump
5766     st->print("...)");
5767     return;
5768   }
5769   d.Insert((void*)this,(void*)this);    // Stop recursion
5770   if (Parms < _domain_sig->cnt())
5771     _domain_sig->field_at(Parms)->dump2(d,depth-1,st);
5772   for (uint i = Parms+1; i < _domain_sig->cnt(); i++) {
5773     st->print(", ");
5774     _domain_sig->field_at(i)->dump2(d,depth-1,st);
5775   }
5776   st->print(" )");
5777 }
5778 #endif
5779 
5780 //------------------------------singleton--------------------------------------
5781 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5782 // constants (Ldi nodes).  Singletons are integer, float or double constants
5783 // or a single symbol.
5784 bool TypeFunc::singleton(void) const {
5785   return false;                 // Never a singleton
5786 }
5787 
5788 bool TypeFunc::empty(void) const {
5789   return false;                 // Never empty
5790 }
5791 
5792 
5793 BasicType TypeFunc::return_type() const{
5794   if (range_sig()->cnt() == TypeFunc::Parms) {
5795     return T_VOID;
5796   }
5797   return range_sig()->field_at(TypeFunc::Parms)->basic_type();
5798 }