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