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