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